首页 > 解决方案 > 对 u(x,t) 数组应用周期性边界条件

问题描述

所以我认为我错误地应用了周期性边界条件。这是 Lax Wendroff 方法

def LW_hflux_eq(a,c,delt,delx,u0,flux):
  x = np.linspace(0,L,round(L/delx))
  t = np.linspace(0,(L/a)/4,round(((L/a)/4)/delt))

  u_arr = np.zeros((len(x),len(t)+1))

  # Intial Condition
  u_arr[:,0] = u0 


  countx = np.arange(1,len(x)-1)
  countt = np.arange(0,len(t))

  #Lax-Wendroff (no limiter)
  for l in countt:
      for j in countx:
          u_arr[j,l+1] = u_arr[j,l] - c*(u_arr[j,l]+(((1-c)/2)*(u_arr[j+1,l]-u_arr[j,l])*flux) - (u_arr[j-1,l]+((1-c)/2)*(u_arr[j,l]-u_arr[j-1,l])*flux))
    u_arr[-1,l+1] = u_arr[-2,l] 
    u_arr[0,l+1] = u_arr[-1,l]    
return u_arr

返回前的最后两行是 PBC。我这样做正确吗?应用此功能时,我遇到了奇怪的错误。试图找到它的根本原因。

谢谢!

标签: functionnumpyfor-loop

解决方案


推荐阅读