如何编程周期性边界条件?

计算科学 pde 有限差分 数值分析 边界条件 正则
2021-12-01 00:14:54

嗨,我在下面有一个代码,可以解决给定 Dirichlet 边界条件的非线性耦合 PDE。但是我需要实现周期性边界条件。周期性边界条件困扰着我,我应该在代码中添加什么来强制执行周期性边界条件?谢谢您的帮助。

笔记,t0x[0,1]. 这是耦合方程,下面我提供我的代码

t2u(x,t)+tu(x,t)au(x,t)x2u(x,t)+bu(u2+f2)=0t2f(x,t)+tf(x,t)af(x,t)x2f(x,t)+bf(u2+f2)=0u(x,0)=f(x,0)=z(x), tu(x,0)=tf(x,0)=0
在哪里a,b>0.

这些是初始条件,但现在我需要施加周期性边界条件。这些在数学上可以写成u(0,t)=u(1,t)xu(0,t)=xu(1,t), 同样适用于f(x,t).

我的代码如下

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

感谢您的阅读,我是新来的,所以如果我应该以更适当的方式重新格式化我的问题,请告诉我。

1个回答

通常,您会添加“保护单元”,即(对于 u)u(-1) 和 u(n+1) 以及您的符号。在每个集成步骤之前:

u(n+1) = u(0)
u(-1) = u(n)

其他变量也是如此。如果使用高阶导数,还可以定义 u(-2) 和 u(n+2) 等。