嗨,我在下面有一个代码,可以解决给定 Dirichlet 边界条件的非线性耦合 PDE。但是我需要实现周期性边界条件。周期性边界条件困扰着我,我应该在代码中添加什么来强制执行周期性边界条件?谢谢您的帮助。
笔记,和. 这是耦合方程,下面我提供我的代码
在哪里.
这些是初始条件,但现在我需要施加周期性边界条件。这些在数学上可以写成和, 同样适用于.
我的代码如下
program coupledPDE
integer, parameter :: n = 10, A = 20 !total number of position and time steps, respectively
real, parameter :: h = 0.1, k = 0.05 !step size for position and time respectively , x goes from 0 to 1, t goes from 0 to 1 also.
real, dimension(0:n) :: u,v,w,f,g,d !these variables store my solutions.
integer:: i,m !loop indices for space and time respectively
real:: t,R,x,c1,c2,c3,eta,a,b
R=(k/h)**2.
a=1.0
b=1.0
c1=(2.+a*k**2.-2.0*R)/(1+k/2.)
c2=R/(1.+k/2.)
c3=(1.0-k/2.)/(1.0+k/2.)
c4=b*k**2./(1+k/2.)
u=0.0 !Boundary conditions, need to make periodic..
f=0.0 !boundary conditions, but not correct.
do i = 0,n+1
x = real(i)*h
w(i) = z(x) !u(x,0)
d(i) = z(x) !f(x,0)
end do
do i=1,n !discretization for 1st time step only, as usual for hyperbolic PDE's
v(i) = (c1/(1.+c3))*w(i) + (c2/(1.+c3))*(w(i+1)+w(i-1)) -(c4/(1.+c3))*w(i)*((w(i))**2.+(d(i))**2.) !\partial_t u(x,0)=0
g(i) = (c1/(1.+c3))*d(i) + (c2/(1.+c3))*(d(i+1)+d(i-1)) -(c4/(1.+c3))*d(i)*((w(i))**2.+(d(i))**2.) !\partial_t f(x,0)=0
end do
do m=1,A
do i=1,n-1 !Discretization equation for all times after the 1st step
u(i)=c1*v(i)+c2*(v(i+1)+v(i-1))-c3*w(i)-c4*v(i)*((v(i))**2.+(g(i))**2.)
f(i)=c1*g(i)+c2*(g(i+1)+g(i-1))-c3*d(i)-c4*g(i)*((v(i))**2.+(g(i))**2.)
end do
write(*,*)'check if u-f=0', u-f !this should be zero
print*, "the values of f(x,t+k) for all m=",m
print "(//3x,i5,//(3(3x,e22.14)))",m,f,u
end do
end program coupledPDE
function z(x)
real, intent(in) :: x
real :: pi
pi=4.0*atan(1.0)
z = sin(pi*x)
end function z
感谢您的阅读,我是新来的,所以如果我应该以更适当的方式重新格式化我的问题,请告诉我。