• Tidak ada hasil yang ditemukan

Thư viện số Văn Lang: Finite Difference Computing with PDEs: A Modern Software Approach

N/A
N/A
Nguyễn Gia Hào

Academic year: 2023

Membagikan "Thư viện số Văn Lang: Finite Difference Computing with PDEs: A Modern Software Approach"

Copied!
117
0
0

Teks penuh

The simplest expression of the computational algorithm using the Forward Euler method and clear Python loops. We see that the curves have sawtooth waves at the beginning of the simulation.

Fig. 3.1 Forward Euler scheme for F D 0:5
Fig. 3.1 Forward Euler scheme for F D 0:5

Implicit Methods for the 1D Diffusion Equation

  • Backward Euler Scheme
  • Sparse Matrix Implementation
  • Crank-Nicolson Scheme
  • The Unifying Rule For the equation
  • Experiments
  • The Laplace and Poisson Equation

All experiments show two characteristic properties of the inverse Euler scheme: 1) it is always stable and 2) it always gives a smooth, decaying solution. The above result means that the inverse Euler scheme can directly solve the boundary equation and thus produce a solution to the 1D Laplace equation.

Fig. 3.3 Forward Euler scheme for F D 0:51
Fig. 3.3 Forward Euler scheme for F D 0:51

Analysis of Schemes for the Diffusion Equation

  • Properties of the Solution
  • Analysis of Discrete Equations
  • Analysis of the Finite Difference Schemes
  • Analysis of the Forward Euler Scheme
  • Analysis of the Backward Euler Scheme
  • Analysis of the Crank-Nicolson Scheme
  • Summary of Accuracy of Amplification Factors
  • Analysis of the 2D Diffusion Equation
  • Explanation of Numerical Artifacts

Truncation Error The derivation of the truncation error for the backward Euler scheme is almost identical to that of the forward Euler scheme. The behavior of the solution generated by forward Euler discretization in time (and space-centered differences) is summarized at the end of Section 3.1.5.

Fig. 3.7 Crank-Nicolson scheme for F D 10
Fig. 3.7 Crank-Nicolson scheme for F D 10

Exercises

If we look at Figure 3.4, which has a very similar initial condition, we see that the curves are indeed smooth. Turning our attention to the Backward Euler scheme and the experiments in Figure 3.5, we see that even the discontinuous initial condition yields smooth solutions for F D0:5 (and in fact all other F values).

Explore symmetry in a 1D problem

Figure 3.1 has unexpected features: you would expect the solution to the diffusion equation to be smooth, but the graphs in Figure 3.1 contain non-smooth noise. Fluctuations in time with an amplitude of .14F /n disappear for F 14 , so even a discontinuous initial condition always leads to smooth solutions in Figure 3.2, where F D 14 .

Experiment with open boundary conditions in 1D

Boundary condition ux.0; t / D 0 can be implemented in two ways: 1) with a symmetric standard finite difference ŒD2xuni D0, or 2) with a one-sided difference ŒDCuD0ni D0. If you use a Forward Euler scheme, choose a discretization parameter D t D x2 and assume that the error goes as E hr.

Simulate a diffused Gaussian peak in 2D/3D

The integral of the initial pulse is 1. c) Another idea for an artificial boundary condition atx DLis to use a cooling law. where q is an unknown heat transfer coefficient and uS is the ambient temperature in the medium outside Œ0; L. Note that to argue datuS is approximately u.L; t /give dieux D0state of the previous subexercise which is qualitatively wrong for larget.).

Examine stability of a diffusion model with a source term Consider a diffusion equation with a linear u term

Diffusion in Heterogeneous Media

  • Discretization
  • Stationary Solution
  • Axi-Symmetric Diffusion
  • Spherically-Symmetric Diffusion

These utilities represent not only piecewise constant functions, but also smoothed versions of them where the discontinuities can be ironed out in a controlled manner. Below we draw .x/ together with ˛.x/ (which works well as long as max˛.x/ is of the same size as maxuD max.U0; UL/). We assume axial symmetry such that it is just a function of randt, with the radial distance from the central axis of the tube to a point.

With such axissymmetry it is advantageous to enter cylindrical coordinates r,andz, in the direction of the tube and.r; / are polar coordinates in a cross section. The finite difference approximation requires the discretized version of the PDE for D0 (just as we use the PDE on the boundary when implementing Neumann conditions). 2.uni uni1/ : To complete the discretization we need a schedule in time, but that can be done the same way as before and does not interfere with the discretization in space.

Since the PDE in spherical coordinates has the same form as the PDE in Sec. Discretization in Cartesian coordinates A spherically symmetric spatial derivative can be transformed into a Cartesian counterpart by introducing

Figure 3.12 shows the case where
Figure 3.12 shows the case where

Diffusion in 2D

  • Discretization
  • Algorithm for Setting Up the Coefficient Matrix
  • Implementation with a Dense Coefficient Matrix
  • Verification: Exact Numerical Solution
  • Verification: Convergence Rates
  • Implementation with a Sparse Coefficient Matrix
  • The Jacobi Iterative Method
  • Implementation of the Jacobi Method
  • Test Problem: Diffusion of a Sine Hill
  • The Relaxed Jacobi Method and Its Relation to the Forward Euler Method
  • The Gauss-Seidel and SOR Methods
  • Scalar Implementation of the SOR Method
  • Vectorized Implementation of the SOR Method
  • Direct Versus Iterative Methods
  • The Conjugate Gradient Method
  • What Is the Recommended Method for Solving Linear Systems?

Therefore, we need to number the unknowns with one index, not two, as used in the grid. LetAp;q be the value of element.p; q/in the coefficient matrix A, where and qnow correspond to the numbering of the unknowns in the system of equations. As an alternative, we can leave the boundary grid points outside the matrix system.

The arrays are vectorized representations of the mesh points such that vectorized function evaluations can be invoked. That is, we can calculate the error due to iterative solution of the linear system and see if it matches the convergence tolerance used in the method. An appropriate value of the tolerance is then103, such that the error in the Jacobi method does not become larger than the discretization error.

The idea here is to introduce u__ for already calculated values ​​(u) in the Gauss-Seidel/SOR version of the implementation, or only values ​​from the previous iteration (u_) in the case of the Jacobi method. The vectorization (and parallelization) strategy of the Gauss-Seidel method is to use a special numbering of the mesh points, the so-called red-black numbering: every other. Nevertheless, the matrix formulation of the Jacobi and SOR methods has been important for analyzing their convergence behavior.

That is, the efficiency of the Jacobi method deteriorates rapidly with increasing mesh resolution, and SOR is much preferable (even if the optimal one! remains an open question).

Fig. 3.14 3x2 2D mesh
Fig. 3.14 3x2 2D mesh

Random Walk

  • Random Walk in 1D
  • Statistical Considerations
  • Equivalence with Diffusion
  • Implementation of Multiple Walks
  • Demonstration of Multiple Walks
  • Ascii Visualization of 1D Random Walk
  • Random Walk as a Stochastic Equation
  • Random Walk in 2D
  • Random Walk in Any Number of Space Dimensions
  • Multiple Random Walks in Any Number of Space Dimensions As we did in 1D, we extend one single walk to a number of walks ( num_walks in

The simplicity of the random walk algorithm makes it particularly attractive for solving diffusion equations on massively parallel computers. Vectorization is the obvious technique here: we use numpy to draw all the random numbers at once, then design vector operations to get rid of the loop over (k) steps. Since the seed is the same, the plot on the left is just an enlargement of the first 1000 steps in the plot on the right.

However, the number of walks is usually much larger than N, due to the need for accurate statistics. Figure 3.18 shows the effect of the number of walks on the expectation, which should approach zero. Figure 3.19 presents the corresponding estimate of the position variance, which should increase linearly with the number of steps.

It does, seemingly very accurately, but note that the scale on their axis is much larger than expected, so irregularities due to the stochastic nature of the process become much less apparent in the variance plots. We get rid of the loops in the previous function and arrive at the following vectorized code.

Fig. 3.16 Ensemble of 4 random walks, each with 200 steps
Fig. 3.16 Ensemble of 4 random walks, each with 200 steps

Applications

  • Diffusion of a Substance
  • Heat Conduction
  • Porous Media Flow
  • Potential Fluid Flow
  • Streamlines for 2D Fluid Flow
  • The Potential of an Electric Field
  • Development of Flow Between Two Flat Plates
  • Flow in a Straight Tube
  • Tribology: Thin Film Fluid Flow
  • Propagation of Electrical Signals in the Brain

Here Fick's law comes to the rescue: it models how the fluxq of the substance is related to the concentrationc. Adding this to the integral statement of the (simplified) first law of thermodynamics, and continuing the derivation, leads to the PDE. In a solid medium k depends on the material of the medium, and in multi-material media one must consider it as spatially dependent.

In many cases the last term withu can be neglected, an assumption that decouples the equation above from a model of deformation of the medium. Furthermore, 0 must be replaced by an electrical permittivity function.r/. Each point on the boundary must be accompanied by either a Dirichlet condition '.r/D'D.r/ or a Neumann condition@'.r/@n D'N.r/. 3.8.7 Development of flow between two flat plates. The geometric constraints of flow between two flat plates impose constraints on the velocity, uDu.x; t /i, and the z component of the Navier-Stokes equations collapses into a diffusion equation: z2 C%fz; if the component is off in the z direction.

We consider two solid surfaces whose distance is described by a gap functionh.x; y/. The space between these surfaces is filled with a fluid with dynamic viscosity. Let Ui CVj be the relative velocity of the two surfaces and p the pressure in the liquid.

Exercises

We can make a model of how electrical signals propagate along the neuron fibers that receive synaptic inputs in the brain. The boundary conditions are often taken as V D0 at short circuit or open end, @V =@xD0 at sealed end or.

Stabilizing the Crank-Nicolson method by Rannacher time stepping

Energy estimates for diffusion problems

The quantificationjjujjL2 or 12jjujjL2 is known as the energy of the solution, although it is not the physical energy of the system. The estimate (3.136) says that the “size of u” is never larger than that of the initial condition, or more precisely, the area under the u-curve decreases with time. Use (3.145) to deduce that the energy must be zero for all times and therefore that u1 Du2, which proves that the solution is unique.. where @u@n Dn ru,n is the outer unit perpendicular to the boundary@˝ of the domain ˝. e).

Show that if we have homogeneous Neumann conditions on the boundary,@u=@nD0, the area under the surface remains constant in time. Choose some functionf andI and check that (3.145) holds whenever zero Dirichlet conditions are used. Iterate over the sameI functions and check that (3.146) holds when using zero Neumann conditions. g) Make a list of some possible errors in the code, such as string indexing errors, failure to set the correct boundary conditions, evaluating a term at a wrong time level, and the like.

For each of the errors, check whether the verification tests from the previous sub-exercise pass or fail. This investigation shows how robust the energy estimates and the estimate (3.146) are in pointing out errors in the implementation.

Splitting methods and preconditioning

Idx f) Write a code in 1D, 2D or 3D that can solve a diffusion equation with a source termf, initial conditionI and zero Dirichlet or Neumann conditions on the entire boundary. Show that if we apply the simple iteration method (3.147) to the preconditioned system M1AuDM1b, we arrive at the Jacobi method by choosing M DD(the diagonal of A) as preconditioner and the SOR method by choosing M D!1DCL( L being the lower triangular part of A). . This equivalence shows that we can apply one iteration of the Jacobi or SOR method as a preconditioner.

Oscillating surface temperature of the earth

Oscillating and pulsating flow in tubes

Scaling a welding problem

Here the temperature, % is the density of the material, c is a heat capacity, k is the thermal conductivity, f is the heat source of the welding equipment, and uses the initial constant (room temperature) temperature in the material. If each of the three terms in the PDE is equally important, we can find this by requiring that the coefficients in the scaled PDE all equal one. Also use scaled quantities in the arguments to the exponential function inf and show that . fNDe12ˇ2.Nxt /N2;.

This is not always the case when ucis is based on a scale involving a source term, as we have in a) and b). However, from the scaled PDE we realize that if we replace fN with ıfN, where is a dimensionless factor, this corresponds to replacing ucby uc=ı. So, if we observe datuN 1=ıin simulations, we can just replacefN by ıfNin the scaled PDE.

Make a function run (gamma, beta=10, delta=40, scaling=1, animate=False) . that runs the model with the given,ˇ, andıparameters and an indicator scaling that is 1 for the scaling in a) and 2 for the scaling in b).

Implement a Forward Euler scheme for axi-symmetric diffusion

Advection-Dominated Equations

One-Dimensional Time-Dependent Advection Equations We consider the pure advection model

Gambar

Fig. 3.1 Forward Euler scheme for F D 0:5
Fig. 3.2 Forward Euler scheme for F D 0:25
Fig. 3.3 Forward Euler scheme for F D 0:51
Fig. 3.4 Forward Euler scheme for F D 0:5
+7

Referensi

Dokumen terkait

Contents 4.4 Setting multiple Dirichlet, Neumann, and Robin conditions.. 98 4.5 Generating meshes with