1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Computational Physics - M. Jensen Episode 2 Part 8 docx

20 248 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 20
Dung lượng 209,54 KB

Nội dung

16.2. DIFFUSION EQUATION 309 ENDDO ! write out for t = 0 t = 0 . DO i =1 , ndim WRITE(6 , ) t , i h , v( i ) ENDDO ! setup the mat rix to be inve r t e d a = 0 . ; u =0. DO i =1 , ndim 1 a ( i , i ) =1.+2. f a c t o r a ( i , i +1)= fa c t o r a ( i +1 , i )= f a c t o r ENDDO a ( ndim , ndim ) = 1 . + 2 . f a c t o r ! now i n v e r t the matrix CALL matinv ( a , ndim , det ) DO i = 1 , m DO l =1 , ndim u ( l ) = DOT_PRODUCT( a ( l , : ) , v ( : ) ) ENDDO v = u t = i k DO j =1 , ndim WRITE(6 , ) t , j h , v ( j ) ENDDO ENDDO DEALLOCATE ( a ) ; DEALLOCATE ( u , v) END SUBROUTINE solve_1dim_equation END MODULE one_dim_heat_equation PROGRAM heat_eq_1dm USE one_dim_heat_equation IMPLICIT NONE INTERFACE DOUBLE PRECISION FUNCTION f u n c t i o n _ i n i t i a l ( x ) IMPLICIT NONE DOUBLE PRECISION, INTENT( IN) : : x END FUNCTION f u n c t i o n _ i n i t i a l END INTERFACE CALL i n i t i a l i s e OPEN(UNIT=6 , FILE=’ heat . dat ’ ) CALL solve_1dim_equation ( f u n c t i o n _ i n i t i a l ) 310 CHAPTER 16. PARTIAL DIFFERENTIAL EQUATIONS CLOSE(6) END PROGRAM heat_eq_1dm DOUBLE PRECISION FUNCTION f u n c t i o n _ i n i t i a l ( x ) IMPLICIT NONE DOUBLE PRECISION, INTENT( IN) : : x f u n c t i o n _ i n i t i a l = SIN ( x ) END FUNCTION f u n c t i o n _ i n i t i a l 16.2.4 Crank-Nicolson scheme It is possible to combine the implicit and explicit methods in a slightly more general approach. Introducing a parameter (the so-called -rule) we can set up an equation (16.46) which for yields the forward formula for the first derivative and the explicit scheme, while yields the backward formula and the implicit scheme. These two schemes are called the backward and forward Euler schemes, respectively. For we obtain a new scheme after its inventors, Crank and Nicolson. This scheme yields a truncation in time which goes like and it is stable for all possible combinations of and . Using our previous definition of we can rewrite the latter equation as (16.47) or in matrix-vector form as (16.48) where the vector is the same as defined in the implicit case while the matrix is (16.49) 16.2.5 Non-linear terms and implementation of the Crank-Nicoloson scheme 16.3 Laplace’s and Poisson’s equations Laplace’s equation reads (16.50) 16.3. LAPLACE’S AND POISSON’S EQUATIONS 311 with possible boundary conditions on the border. There is no time-dependence. Choosing equally many steps in both directions we have a quadratic or rectangular grid, depend- ing on whether we choose equal steps lengths or not in the and the directions. Here we set and obtain a discretized version (16.51) and (16.52) which we rewrite as (16.53) and (16.54) which gives when inserted in Laplace’s equation (16.55) This is our final numerical scheme for solving Laplace’s equation. Poisson’s equation adds only a minor complication to the above equation since in this case we have and we need only to add a discretized version of resulting in (16.56) It is fairly straightforward to extend this equation to the three-dimensional case. Whether we solve Eq. (16.55) or Eq. (16.56), the solution strategy remains the same. We know the values of at or and at or but we cannot start at one of the boundaries and work our way into and across the system since Eq. (16.55) requires the knowledge of at all of the neighbouring points in order to calculate at any given point. The way we solve these equations is based on an iterative scheme called the relaxation method. Its steps are rather simple. We start with an initial guess for where all values are known. To obtain a new solution we solve Eq. (16.55) or Eq. (16.56) in order to obtain a new solution . Most likely this solution will not be a solution to Eq. (16.55). This solution is in turn used to obtain a new and improved . We continue this process till we obtain a result which satisfies some specific convergence criterion. A simple example may help in visualizing this method. We consider a condensator with parallel plates separated at a distance resulting in e.g., the voltage differences and . These are our boundary conditions and we ask what is the voltage between the plates? To solve this problem numerically we provide below a Fortran 90/95 program which solves iteratively Eq. (16.55). 312 CHAPTER 16. PARTIAL DIFFERENTIAL EQUATIONS programs/chap16/program2.f90 ! Program to solve the 2 dim Laplace equation usi ng i t e r a t i o n . ! No time dependence . ! I n i t i a l co n d i t i o n s are read i n by the fu n c t i o n i n i t i a l i s e ! such as number of s t ep s in the x d i r e c tion , y di r e c t i on , ! xmin and xmax , ymin and ymax . Here we employ a square l a t t i c e ! with equal number of s t e ps in x and y d i r e c t i o n s ! Note the s t r u c t u re of t h i s module , i t c ontains vari o us ! su b r o u t i n es for i n i t i a l i s a t i o n of the problem and s o l u t i o n ! of the PDE with a given i n i t i a l f u nc t io n f or u ( x , y ) MODULE two_dim_laplace_equatio n DOUBLE PRECISION, PRIVATE : : xmin , xmax , ymin , ymax INTEGER, PRIVATE : : ndim , i t e r a t i o n s DOUBLE PRECISION, ALLOCATABLE, DIMENSION( : , : ) , PRIVATE : : u , u_temp CONTAINS ! t h i s f u n c t io n reads i n the s i z e of l a t t i c e , xmin , xmax , ! ymin and ymax and the number of i t e r a t i o n s SUBROUTINE i n i t i a l i s e IMPLICIT NONE WRITE( , ) ’ read in number of mesh points in x and y d i r e c t i o n ’ READ( , ) ndim WRITE( , ) ’ read in xmin and xmax ’ READ( , ) xmin , xmax WRITE( , ) ’ read in ymin and ymax ’ READ( , ) ymin , ymax WRITE( , ) ’ read in max number of i t e r a t i o n s ’ READ( , ) i t e r a t i o n s END SUBROUTINE i n i t i a l i s e SUBROUTINE solv e _2dimlap lace_eq uation ( func ) DOUBLE PRECISION : : h , x , y , pi , length , d i f f INTEGER : : i , j , l INTERFACE DOUBLE PRECISION FUNCTION func ( argument ) IMPLICIT NONE DOUBLE PRECISION, INTENT(IN ) : : argument 16.3. LAPLACE’S AND POISSON’S EQUATIONS 313 END FUNCTION func END INTERFACE ! d e f i ne the step s i z e h = ( xmax xmin ) /FLOAT( ndim +1) length = xmax xmin ! a l l o c a t e space f o r the vect o r u and the temporary vector to ! be upgraded in every i t e r a t i o n ALLOCATE ( u ( ndim , ndim ) ) ALLOCATE ( u_temp ( ndim , ndim ) ) pi = ACOS( 1.) ! s e t up of i n i t i a l c o n d i t i ons at t = 0 and boundary condition s u = 0 . DO i =1 , ndim x = i h pi / l e ngth u ( i , 1 ) = func ( x ) u ( i , ndim ) = func ( x ) ENDDO ! i t e r a t i o n algorithm s t a r t s here i t e r a t i o n s = 0 DO WHILE ( ( i t e r a t i o n s <= 20) . OR . ( d i f f > 0 . 00001) ) u_temp = u ; d i f f = 0 . DO j = 2 , ndim 1 DO l = 2 , ndim 1 u ( j , l ) = 0 . 2 5 ( u_temp ( j +1 , l )+u_temp ( j 1, l ) + & u_temp ( j , l +1)+u_temp ( j , l 1) ) d i f f = d i f f + ABS( u_temp ( i , j ) u ( i , j ) ) ENDDO ENDDO i t e r a t i o n s = i t e r a t i o n s + 1 d i f f = d i f f / ( ndim +1) 2 ENDDO ! write out r e s u l t s DO j = 1 , ndim DO l = 1 , ndim WRITE(6 , ) j h , l h , u ( j , l ) ENDDO ENDDO DEALLOCATE ( u , u_temp ) END SUBROUTINE solv e _2dimlap lace_eq u a t io n END MODULE two_dim_lapla ce_equatio n PROGRAM laplace_eq_2dim USE two_dim_laplace_equation 314 CHAPTER 16. PARTIAL DIFFERENTIAL EQUATIONS IMPLICIT NONE INTERFACE DOUBLE PRECISION FUNCTION f u n c t i o n _ i n i t i a l ( x ) IMPLICIT NONE DOUBLE PRECISION, INTENT(IN ) : : x END FUNCTION f u n c t i o n _ i n i t i a l END INTERFACE CALL i n i t i a l i s e OPEN(UNIT=6 , FILE=’ la p l a c e . dat ’ ) CALL sol v e_2dimla place_eq u a t ion ( f u n c t i o n _ i n i t i a l ) CLOSE(6) END PROGRAM laplace_eq_2dim DOUBLE PRECISION FUNCTION f u n c t i o n _ i n i t i a l ( x ) IMPLICIT NONE DOUBLE PRECISION, INTENT(IN ) : : x f u n c t i o n _ i n i t i a l = 100 SIN ( x ) END FUNCTION f u n c t i o n _ i n i t i a l The important part of the algorithm is applied in the function which sets up the two-dimensional Laplace equation. There we have a do-while statement which tests the difference between the temporary vector and the solution . Moreover, we have fixed the number of iterations to be at most . This is sufficient for the above problem, but for more general applications you need to test the convergence of the algorithm. 16.4 Wave equation in two dimensions The -dimensional wave equation reads (16.57) with and we have assumed that we operate with dimensionless variables. Possible boundary and initial conditions with are (16.58) 16.4. WAVE EQUATION IN TWO DIMENSIONS 315 We discretize again time and position, (16.59) and (16.60) which we rewrite as (16.61) and (16.62) resulting in (16.63) If we assume that all values at times and are known, the only unknown variable is and the last equation yields thus an explicit scheme for updating this quantity. Wehave thus an explicit finite difference scheme for computing the wave function . The only additional complication in our case is the initial condition given by the first derivative in time, namely . The discretized version of this first derivative is given by (16.64) and at it reduces to (16.65) implying that . If we insert this condition in Eq. (16.63) we arrive at a special formula for the first time step (16.66) We need seemingly two different equations, one for the first time step given by Eq. (16.66) and one for all other time-steps given by Eq. (16.63). However, it suffices to use Eq. (16.63) for all times as long as we provide using (16.67) in our setup of the initial conditions. The situation is rather similar for the -dimensional case, except that we now need to discretize the spatial -coordinate as well. Our equations will now depend on three variables whose discretized versions are now (16.68) 316 CHAPTER 16. PARTIAL DIFFERENTIAL EQUATIONS and we will let and for the sake of simplicity. The equation with initial and boundary conditions reads now (16.69) We have now the following discretized partial derivatives (16.70) and (16.71) and (16.72) which we merge into the discretized -dimensional wave equation as (16.73) where again we have an explicit scheme with as the only unknown quantity. It is easy to account for different step lengths for and . The partial derivative is treated in much the same way as for the one-dimensional case, except that we now have an additional index due to the extra spatial dimension, viz., we need to compute through (16.74) in our setup of the initial conditions. 16.4.1 Program for the wave equation and applications 16.5 Inclusion of non-linear terms in the wave equation Part II Advanced topics 317 [...]... · ´ ´Êµ   µ ´Ê µ Ä Ì ¾ In this equation we have introduced the so-called force-term Eq (19 .8) (19.10) , given by ´ ´Êµ ¾Ö ´ÌÊʵ µ Ì (19.11) and is commonly referred to as the “quantum force” The local energy Ä is defined as previously ¾ Ì µ   ½Êµ Ö ¾ ´Êµ · Î ´Êµ Ì ´Êµ Ì´ ÄÊ (19. 12) 19 .2 OTHER QUANTUM MONTE CARLO TECHNIQUES AND SYSTEMS 325 and is computed, as in the VMC method, with respect to the trial...Chapter 17 Modelling phase transitions 17.1 Methods to classify phase transition 17.1.1 The histogram method 17.1 .2 Multi-histogram method 17 .2 Renormalization group approach 319 Chapter 18 Hydrodynamic models 321 Chapter 19 Diffusion Monte Carlo methods We discuss implementations and the underlying theory for diffusion Monte Carlo methods 19.1 Diffusion Monte... the Slater determinant is computationally involved Furthermore, techniques to improve the variance have also not been discussed We defer these topics, together with a discussion of other Monte Carlo methods such as Green’s function Monte Carlo, path integral Monte Carlo and Lattice methods to a more advanced course on computational Physics Chapter 20 Finite element method 327 ... into branching and diffusion parts, can be written as   ´Ê Ê¼   ´Ê¼ µ¾ ¾ ʼ Ê (19.13) ´ µ ´ µ ´ µ 19 .2 Other Quantum Monte Carlo techniques and systems In our discussion, the emphasis has been on variational methods, since they are rather intuitive and one can simulate physical systems with rather simple trial wave functions We have also not dealt with problems arising in many-fermion systems, where both... diffusing particles (or “walkers”), and the term Î Ê   Ì is a rate term describing a potentialdependent increase or decrease in the particle density The above equation may be transformed into a form suitable for Monte Carlo methods, but this leads to a very inefficient algorithm The potential Î Ê is unbounded in coulombic systems and hence the rate term Î Ê   Ì can diverge Large fluctuations in the particle... (19 .2) , then we obtain ½ ´ µ ´Æ µ ½  ¯ Æ (19.5) Hence any initial state, , that is not orthogonal to the ground state ¼ will evolve to the ground state in the long time limit, that is Ð Ñ ´Æ µ ½ 323 ¼  ¯¼ ¼ (19.6) 324 CHAPTER 19 DIFFUSION MONTE CARLO METHODS This derivation shares many formal similarities with that given for the variational principle discussed in the previous sections However in the DMC... Ñ ´Ê Æ µ ½ ¼  ¯¼ ¼ ´Êµ (19.7) ¯¼ , the long-time limit of Eq (19.7) By introducing a constant offset to the energy, Ì can be kept finite If the Hamiltonian is separated into the kinetic energy and potential terms, the imaginary time Schrödinger equation, takes on a form similar to a diffusion equation, namely    ´Ê µ Æ ½   ¾ Ö¾ ´Ê µ · ´Î ´Êµ   Ì µ ´Ê µ (19 .8) This equation is a diffusion equation where... expanded in eigenstates of the Hamiltonian ½ where (19 .2) ¯ À (19.3) ¯ being an eigenstate of À A formal solution of the imaginary time Schrödinger equation is ´ µ ´ ½·Æ µ  À Æ ´ ½µ (19.4) · where the state ½ evolves from an imaginary time ½ to a later time ½ Æ If the initial state is expanded in energy ordered eigenstates, following Eq (19 .2) , then we obtain ½ ´ µ ´Æ µ ½  ¯ Æ (19.5) Hence any initial... interpretation to Eq (19.10) The right hand side of the importance sampled DMC equation consists, from left to right, of diffusion, drift and rate terms The problematic potential dependent rate term of the non-importance sampled method is replaced by a term dependent on the difference between the local energy of the guiding wave function and the trial energy The trial energy is initially chosen to be the VMC... method for obtaining wave functions that accurately approximate ground state wave functions locally The trial wave function may be also constructed to minimise the number of divergences in , unlike the non-importance sampled method where divergences in the coulomb interactions are always present To be of use however, the importance sampled DMC method of Eq (19.10) must be transformed into a form suitable . The histogram method 17.1 .2 Multi-histogram method 17 .2 Renormalization group approach 319 Chapter 18 Hydrodynamic models 321 Chapter 19 Diffusion Monte Carlo methods We discuss implementations. matrix-vector form as (16. 48) where the vector is the same as defined in the implicit case while the matrix is (16.49) 16 .2. 5 Non-linear terms and implementation of the Crank-Nicoloson scheme 16.3. s <= 20 ) . OR . ( d i f f > 0 . 00001) ) u_temp = u ; d i f f = 0 . DO j = 2 , ndim 1 DO l = 2 , ndim 1 u ( j , l ) = 0 . 2 5 ( u_temp ( j +1 , l )+u_temp ( j 1, l ) + & u_temp ( j ,

Ngày đăng: 07/08/2014, 12:22

TỪ KHÓA LIÊN QUAN