The way we solve these equations is based on an iterative scheme called the relaxation method.. 16.4.1 Program for the2 + 1wave equation and applications 16.5 Inclusion of non-linear ter
Trang 116.2 DIFFUSION EQUATION 309
ENDDO
! w r i t e o u t f o r t = 0
t = 0
DO i = 1 , ndim
WRITE( 6 ,) t , ih , v ( i )
ENDDO
! s e t u p t h e m a t r i x t o be i n v e r t e d
a = 0 ; u = 0
a ( i , i ) = 1 + 2 f a c t o r
a ( i , i + 1 )= f a 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 t h e m a t r i x
CALL m a t i n v ( a , ndim , d e t )
DO l = 1 , ndim
u ( l ) = DOT_PRODUCT( a ( l , : ) , v ( : ) )
ENDDO
v = u
t = ik
DO j = 1 , ndim
WRITE( 6 ,) t , jh , v ( j )
ENDDO
ENDDO
DEALLOCATE ( a ) ; DEALLOCATE ( u , v )
END SUBROUTINE s o l v e _ 1 d i m _ e q u a t i o n
END MODULE o n e _ d i m _ h e a t _ e q u a t i o n
PROGRAM h e a t _ e q _ 1 d m
USE o n e _ d i m _ h e a t _ e q u a t i o n
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= ’ h e a t d a t ’ )
CALL s o l v e _ 1 d i m _ e q u a t i o n ( f u n c t i o n _ i n i t i a l )
Trang 2310 CHAPTER 16 PARTIAL DIFFERENTIAL EQUATIONS CLOSE( 6 )
END PROGRAM h e a t _ e q _ 1 d m
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
x
2
(u
i 1;j
2u i;j + u i+1;j ) +
1
x 2 (u i+1;j 1
2u i;j 1 + u
i 1;j 1 ) = 1
t (u i;j u i;j 1 ) ;
(16.46) which for = 0yields the forward formula for the first derivative and the explicit scheme, while
= 1yields the backward formula and the implicit scheme These two schemes are called the backward and forward Euler schemes, respectively For = 1=2we obtain a new scheme after its inventors, Crank and Nicolson This scheme yields a truncation in time which goes likeO(t
2 )
and it is stable for all possible combinations oftandx
Using our previous definition of = t=x
2
we can rewrite the latter equation as
u
i 1;j
+ (2 + 2 ) u
i;j u i+1;j
= u
i 1;j 1 + (2 2 ) u
i;j 1 + u i+1;j 1
; (16.47)
or in matrix-vector form as
2
^
I + 2
^ B
V j
=
2
^
I 2
^ B
V
j 1
where the vectorV
j is the same as defined in the implicit case while the matrix ^
B is
^
B = 0
B B
2 1 0 0 : :
1 2 1 0 : : : : : : : : : :
0 : : 0 : : 2
1
C C A
(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
2
(16.50)
Trang 316.3 LAPLACE’S AND POISSON’S EQUATIONS 311
with possible boundary conditionsu(x; y) = g (x; y)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 thexand theydirections Here we set
x = y = hand obtain a discretized version
u xx
u(x + h; y) 2u(x; y) + u(x h; y)
h 2
and
u y
u(x; y + h) 2u(x; y) + u(x; y h)
h 2
which we rewrite as
u xx
u i+1;j
2u i;j + u
i 1;j h
2
and
u y
u i;j+1
2u i;j + u i;j 1 h
2
which gives when inserted in Laplace’s equation
u i;j
= 1 4 [u i;j+1 + u i;j 1 + u i+1;j + u
i 1;j
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
u xx + u y
= (x);
and we need only to add a discretized version of(x)resulting in
u i;j
= 1 4 [u i;j+1 + u i;j 1 + u i+1;j + u
i 1;j
℄ + i;j
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
uati = 0ori = n + 1and atj = 0orj = n + 1but we cannot start at one of the boundaries and work our way into and across the system since Eq (16.55) requires the knowledge ofuat all
of the neighbouring points in order to calculateuat 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 u
(0) i;j 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 solutionu
(1) i;j
Most likely this solution will not be a solution to Eq (16.55) This solution is
in turn used to obtain a new and improvedu
(2) i;j 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 L resulting in e.g., the voltage differences u(x; 0) = 100sin(2x=L) and u(x; 1) = 100sin(2x=L) These are our boundary conditions and we ask what is the voltage u between the plates? To solve this problem numerically we provide below a Fortran 90/95 program which solves iteratively Eq (16.55)
Trang 4312 CHAPTER 16 PARTIAL DIFFERENTIAL EQUATIONS
programs/chap16/program2.f90
! Program t o s o l v e t h e 2 dim L a p l a c e e q u a t i o n u s i n g i t e r a t i o n
! No t i m e d e p e n d e n c e
! I n i t i a l c o n d i t i o n s a r e r e a d i n by t h e f u n c t i o n i n i t i a l i s e
! s u c h a s number o f s t e p s i n t h e x d i r e c t i o n , y d i r e c t i o n ,
! xm in and xmax , ym in and ymax Here we e m p l o y a s q u a r e l a t t i c e
! w i t h e q u a l number o f s t e p s i n x and y d i r e c t i o n s
! N o t e t h e s t r u c t u r e o f t h i s module , i t c o n t a i n s v a r i o u s
! s u b r o u t i n e s f o r i n i t i a l i s a t i o n o f t h e p r o b l e m and s o l u t i o n
! o f t h e PDE w i t h a g i v e n i n i t i a l f u n c t i o n f o r u ( x , y )
MODULE t w o _ d i m _ l a p l a c e _ e q u a t i o 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_tem p
CONTAINS
! t h i s f u n c t i o n r e a d s i n t h e s i z e o f l a t t i c e , xmin , xmax ,
! ym in and ymax and t h e number o f 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 i n number o f mesh p o i n t s i n x and y d i r e c t i o n
’
READ( ,) ndim
WRITE( ,) ’ read i n xmin and xmax ’
READ( ,) xmin , xmax
WRITE( ,) ’ read i n ymin and ymax ’
READ( ,) ymin , ymax
WRITE( ,) ’ read i n max number o f 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 s o l v e _ 2 d i m l a p l a c e _ e q u a t i o n ( f u n c )
DOUBLE PRECISION : : h , x , y , p i , l e n g t h , d i f f
INTEGER : : i , j , l
INTERFACE
DOUBLE PRECISION FUNCTION f u n c ( a r g u m e n t )
IMPLICIT NONE DOUBLE PRECISION, INTENT(IN) : : a r g u m e n t
Trang 516.3 LAPLACE’S AND POISSON’S EQUATIONS 313
END FUNCTION f u n c
END INTERFACE
! d e f i n e t h e s t e p s i z e
h = ( xmax xmin ) / FLOAT( ndim + 1 )
l e n g t h = xmax xmin
! a l l o c a t e s p a c e f o r t h e v e c t o r u and t h e t e m p o r a r y v e c t o r t o
! be u p g r a d e d i n e v e r y i t e r a t i o n
ALLOCATE ( u ( ndim , ndim ) )
ALLOCATE ( u_tem p ( ndim , ndim ) )
p i = ACOS( 1 )
! s e t up o f i n i t i a l c o n d i t i o n s a t t = 0 and b o u n d a r y c o n d i t i o n s
u = 0
DO i = 1 , ndim
x = ihp i / l e n g t h
u ( i , 1 ) = f u n c ( x )
u ( i , ndim ) = f u n c ( x )
ENDDO
! i t e r a t i o n a l g o r i t h m s t a r t s h e r e
i t e r a t i o n s = 0
DO WHILE ( ( i t e r a t i o n s < = 2 0 ) OR ( d i f f > 0 0 0 0 0 1 ) )
u_tem p = u ; d i f f = 0
u ( j , l ) = 0 2 5( u_tem p ( j + 1 , l ) + u_tem p ( j 1 , l ) + &
u_tem p ( j , l + 1 ) + u_tem p ( j , l 1) )
d i f f = d i f f + ABS( u_tem p ( 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
! w r i t e o u t r e s u l t s
DO j = 1 , ndim
DO l = 1 , ndim
WRITE( 6 ,) jh , lh , u ( j , l )
ENDDO
ENDDO
DEALLOCATE ( u , u_tem p )
END SUBROUTINE s o l v e _ 2 d i m l a p l a c e _ e q u a t i o n
END MODULE t w o _ d i m _ l a p l a c e _ e q u a t i o n
PROGRAM l a p l a c e _ e q _ 2 d i m
USE t w o _ d i m _ l a p l a c e _ e q u a t i o n
Trang 6314 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= ’ l a p l a c e d a t ’ )
CALL s o l v e _ 2 d i m l a p l a c e _ e q u a t i o n ( f u n c t i o n _ i n i t i a l )
CLOSE( 6 )
END PROGRAM l a p l a c e _ e q _ 2 d i m
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 = 1 0 0SIN ( 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 solutionu
i;j Moreover, we have fixed the number of iterations to be at most20 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
The1 + 1-dimensional wave equation reads
2 u
x 2
=
2 u
t
withu = u(x; t)and we have assumed that we operate with dimensionless variables Possible boundary and initial conditions withL = 1are
8
>
<
>
:
u xx
= u tt
x 2 [0; 1℄; t > 0 u(x; 0) = g(x) x 2 [0; 1℄
u(0; t) = u(1; t) = 0 t > 0
Trang 716.4 WAVE EQUATION IN TWO DIMENSIONS 315
We discretize again time and position,
u xx
u(x + x; t) 2u(x; t) + u(x x; t)
x 2
and
u tt
u(x; t + t) 2u(x; t) + u(x; t t)
t 2
which we rewrite as
u xx
u i+1;j
2u i;j + u
i 1;j
x 2
and
u tt
u i;j+1
2u i;j + u i;j 1
t 2
resulting in
u i;j+1
= 2u i;j u i;j 1 +
t
x 2 (u i+1;j
2u i;j + u
i 1;j ) : (16.63)
If we assume that all values at timest = j andt = j 1are known, the only unknown variable
isu
i;j+1and the last equation yields thus an explicit scheme for updating this quantity Wehave thus an explicit finite difference scheme for computing the wave functionu The only additional complication in our case is the initial condition given by the first derivative in time, namely
u=tj
t=0
= 0 The discretized version of this first derivative is given by
u t
u(x i
; t j + t) u(x
i
; t j
t) 2t
and att =it reduces to
u t
u i;+1 u i; 1 2t
implying that u
i;+1
= u i; 1 If we insert this condition in Eq (16.63) we arrive at a special formula for the first time step
u i;1
= u i;0 +
t 2x 2 (u i+1;0
2u i;0 + u
i 1;0 ) : (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 provideu(i; 1)using
u i; 1
= u i;0 +
t 2x 2 (u i+1;0
2u i;0 + u
i 1;0 ) ; (16.67)
in our setup of the initial conditions
The situation is rather similar for the 2 + 1-dimensional case, except that we now need to discretize the spatial y-coordinate as well Our equations will now depend on three variables whose discretized versions are now
8
<
:
t l
= lt l 0 x
i
= ix 1 i n
x
Trang 8316 CHAPTER 16 PARTIAL DIFFERENTIAL EQUATIONS
and we will letx = y = handn
x
= n
y for the sake of simplicity The equation with initial and boundary conditions reads now
8
>
<
>
:
u xx + u y
= u tt
x; y 2 [0; 1℄; t > 0 u(x; y; 0) = g(x; y) x; y 2 [0; 1℄
u(0; 0; t) = u(1; 1; t) = 0 t > 0
u=tj
t=0
= 0 x; y 2 [0; 1℄
We have now the following discretized partial derivatives
u xx
u l i+1;j
2u l i;j + u l
i 1;j h
2
and
u y
u l i;j+1
2u l i;j + u l i;j 1 h
2
and
u tt
u
l +1 i;j 2u l i;j + u
l 1 i;j
t 2
which we merge into the discretized2 + 1-dimensional wave equation as
u
l +1
i;j
= 2u l i;j u
l 1 i;j +
t h 2 u l i+1;j
4u l i;j + u l
i 1;j + u l i;j+1 + u l i;j 1
; (16.73) where again we have an explicit scheme with u
l +1 i;j as the only unknown quantity It is easy to account for different step lengths forxandy 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 computeu
1 i;j
through
u 1 i;j
= u 0 i;j +
t 2h 2 u 0 i+1;j
4u 0 i;0 + u 0
i 1;j + u 0 i;j+1 + u 0 i;j 1
; (16.74)
in our setup of the initial conditions
16.4.1 Program for the2 + 1wave equation and applications
16.5 Inclusion of non-linear terms in the wave equation
Trang 9Part II
Advanced topics
317
Trang 11Chapter 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
Trang 13Chapter 18
Hydrodynamic models
321
Trang 15Chapter 19
Diffusion Monte Carlo methods
We discuss implementations and the underlying theory for diffusion Monte Carlo methods
19.1 Diffusion Monte Carlo
The DMC method is based on rewriting the Schrödinger equation in imaginary time, by defining
= it The imaginary time Schrödinger equation is then
= b
where we have omitted the dependence on and the spatial variables in The wave function
is again expanded in eigenstates of the Hamiltonian
= 1 X i i
i
where
b H
i
= i
i
i being an eigenstate of b
H A formal solution of the imaginary time Schrödinger equation is
(
1 + Æ ) = e
b
H Æ
(
1
where the state (
1 )evolves from an imaginary time
1to a later time
1 + Æ If the initial state
(
1
)is expanded in energy ordered eigenstates, following Eq (19.2), then we obtain
(Æ ) =
1 X i i e
i Æ
i
Hence any initial state, , that is not orthogonal to the ground state
0 will evolve to the ground state in the long time limit, that is
lim
!1 (Æ) =
0 e
0
323
Trang 16324 CHAPTER 19 DIFFUSION MONTE CARLO METHODS
This derivation shares many formal similarities with that given for the variational principle dis-cussed in the previous sections However in the DMC method the imaginary time evolution results in excited states decaying exponentially fast, whereas in the VMC method any excited state contributions remain and contribute to the VMC energy
The DMC method is a realisation of the above derivation in position space Including the spatial variables as well, the above equation reads
lim
!1 (R; Æ ) =
0 e
0
By introducing a constant offset to the energy, E
T
=
0, the long-time limit of Eq (19.7) 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
(R; )
=
"
N X i 1 2 r 2 i (R; )
#
+ (V (R) E
T ) (R; ): (19.8)
This equation is a diffusion equation where the wave function may be interpreted as the density
of diffusing particles (or “walkers”), and the termV (R) E
T is a rate term describing a potential-dependent 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 V (R)is unbounded in coulombic systems and hence the rate term V (R) E
T
can diverge Large fluctuations in the particle density then result and give impractically large statistical errors
These fluctuations may be substantially reduced by the incorporation of importance sampling
in the algorithm Importance sampling is essential for DMC methods, if the simulation is to
be efficient A trial or guiding wave function T
(R), which closely approximates the ground state wave function is introduced This is where typically the VMC result would enter, see also discussion below A new distribution is defined as
f(R; ) =
T
which is also a solution of the Schrödinger equation when (R; ) is a solution Eq (19.8) consequently modified to
f (R; )
= 1 2
r [r F (R)℄ f(R; ) + (E
L (R) E
T )f (R; ): (19.10)
In this equation we have introduced the so-called force-termF, given by
F (R) =
2r T (R)
T (R)
and is commonly referred to as the “quantum force” The local energyE
Lis defined as previously
E L R) =
1 r 2 T (R) + V (R)
T (R); (19.12)