Fipy 在求解时间步长之间更改 CellValue

如何解决Fipy 在求解时间步长之间更改 CellValue

我想将网格(偏微分方程)与复杂的混合反应器(常微分方程)连接起来。我想取一点值,求解 ODE,然后重新输入网格中的值(将在其中求解 PDE)。

Clang

但是,我看到 .setValue 之后的变量没有用于新的迭代。我知道由于扩散而存在一些差异,但我认为这是不正确的:

 # Geometry
Lx = 2   # meters
Ly = 2    # meters
nx = 101 #int((Lx / 0.05) + 1) # nodes
ny = 101 #int((Ly / 0.05) + 1)

# Build the mesh:
mesh = Grid2D(Lx = Lx,Ly = Ly,nx = nx,ny = ny)
X,Y = mesh.cellCenters
xx,yy = mesh.faceCenters

C0_DO = 10. #mg/L # dissolved Oxygen initial concentration
C0_OM = 5.
T0 = 28. #mg/L # # Temperature
print(f'DO saturation concentration: {calc_DOsat(T0)} mg/L')

# dissolved oxygen:
C_DO = CellVariable(name="concentration_DO",mesh=mesh,value=C0_DO,#hasOld=True
                 )

# Temperature
T = CellVariable(name="temperature",value=T0,#hasOld=True
                 )

C_OM = CellVariable(name="concentration_OM",value=C0_OM,#hasOld=True
                 )

# Transport parameters (diffusion constants)

# dissolved oxygen diffusion constant
D_DO = 2. #m2/s
D_DO = FaceVariable(name='DO_diff',value=D_DO) # This is necessary to set a fixed-flux boundary condition
D_DO.constrain(0.,mesh.exteriorFaces) # This is necessary to set a fixed-flux boundary condition


D_OM = 2.

# Reaction and source terms

O_R = 1. # Re-aeration temperature correction factor (-)
Y_R = 1. #reaeration_rate() # Re-aeration rate (1/day)
DOsat = (14.652 - 0.41022 * T + 0.007991 * T ** 2 - 0.000077774 * T ** 3) # Oxygen saturation concentration (mg/L)
xi_SOD = 0.1 # Sediment Oxygen Demand (BC) (1/day)

# Oxygen transport-reaction
eqDO = (TransientTerm(var = C_DO) == # Transient term
        DiffusionTerm(coeff = D_DO,var = C_DO) # Diffusion term
        + (mesh.facesTop * (Y_R * (O_R ** (T.faceValue - 20)) * ((14.652 - 0.41022 * T.faceValue + 0.007991 * T.faceValue ** 2 - 0.000077774 * T.faceValue ** 3) - C_DO.faceValue))).divergence #Top Boundary Condition (fixed-flux)
        + (mesh.facesBottom * (xi_SOD * C_DO.faceValue)).divergence # Bottom Boundary Condition (fixed-flux)
        )

eqOM = (TransientTerm(var = C_OM) == # Transient term
        DiffusionTerm(coeff = D_OM,var = C_OM) # Diffusion term
        )

eqTOT = eqDO & eqOM


    def reactor_model(C,t):
      k1 = 0.5
      k2 = 0.1
    
      C1 = C[0]
      C2 = C[1]
    
      dC1dt = -k1 * C1
      dC2dt = -k1 * C1
    
      dCdt = [dC1dt,dC2dt]
      
      return dCdt



  # PDESolver hyperparameters
steps = 10
sweeps = 2
dt = 1e-1
reactor_act = True

t = time.time()
for step in range(steps):
  C_DO.updateOld()
  C_OM.updateOld()
  
  for sweep in range(sweeps):
    eqTOT.sweep(dt=dt)

  if reactor_act:
    # Reactor
    r_in = [C_DO([(Lx/2),(0)]).mean(),# dissolved Oxygen reactor input
            C_OM([(Lx/2),(0)]).mean()  # Organic Matter reactor input
            ]

    print('Reactor input:',r_in)

    # solve ODE
    C = odeint(reactor_model,r_in,np.linspace(0,dt,10))
    r_out = C[-1]

    print('Reactor output:',r_out)

    # Reinput ODE
    C_DO.setValue(r_out[0],where=(Y >= Ly - mesh.dy / 2 ) & (X <= (Lx/2 + mesh.dx / 2)) & (X > (Lx/2 - mesh.dx / 2)))
    C_OM.setValue(r_out[1],where=(Y >= Ly - mesh.dy / 2 ) & (X <= (Lx/2 + mesh.dx / 2)) & (X > (Lx/2 - mesh.dx / 2)))
  
    C_DO.setValue(r_out[0],where=(Y <= mesh.dy / 2 ) & (X <= (Lx/2 + mesh.dx / 2)) & (X > (Lx/2 - mesh.dx / 2)))
    C_OM.setValue(r_out[1],where=(Y <= mesh.dy / 2 ) & (X <= (Lx/2 + mesh.dx / 2)) & (X > (Lx/2 - mesh.dx / 2)))

elapsed = time.time() - t
print('Calculation completed')
print(f'Runtime: {elapsed/60} minutes')

enter image description here

有什么方法可以在迭代之间更改 CellValues 吗?

谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?