Problem using mix of periodic and non-periodic BCs

21 views
Skip to first unread message

Nils Winkler

unread,
Apr 17, 2024, 9:33:24 AM4/17/24
to fipy
Hi,

I am using fipy to deal with a system of three coupled nonlinear partial differential equations. Two dependent parameters have Naumann BCs and one periodic BCs. Is it possible to implement these at the same time? 

Using only a periodic mesh with internal BCs for the Naumann BC does not work because the respective two dependent parameters are not continuous at the boundary. 
Can one somehow combine a periodic with a normal mesh? Or is it possible to use a normal mesh and impose periodic boundary conditions internally?

Thank you very much in advance.


Nils

Daniel Wheeler

unread,
Apr 17, 2024, 10:19:16 AM4/17/24
to Nils Winkler, fipy
Yes, you can do that. You'll have to define the dependent variables
across both the domains and map the variable values over at each sweep
/ timestep so there will be some overhead.

--
Daniel Wheeler

Nils Winkler

unread,
Apr 18, 2024, 3:31:38 AM4/18/24
to fipy, Daniel Wheeler, fipy, Nils Winkler
Oh great. Do you happen to have example code? I am not sure how to properly do that.

Daniel Wheeler

unread,
Apr 19, 2024, 10:41:35 AM4/19/24
to Nils Winkler, fipy
Here's an example. It's trivial, but it just demonstrates solving a
variable on one grid and then using that variable to set the value of
the diffusion coefficient for an equation on a different grid.
Obviously, if the domains don't overlap then you need to take care of
the mapping and interpolation between the grids.

~~~
from fipy import CellVariable, Grid1D, DiffusionTerm, Viewer, TransientTerm

nx = 100
dt = 1e-3
Lx = 1.0
steps = 1000

mesh0 = Grid1D(nx=nx, Lx=Lx)
mesh1 = Grid1D(nx=nx, Lx=Lx)

v0 = CellVariable(mesh=mesh0, value=0., hasOld=True)
v0.constrain(1e-1, where=mesh0.facesLeft)
v0.constrain(10., where=mesh0.facesRight)

v1 = CellVariable(mesh=mesh1, value=0., hasOld=True)
v1.constrain(0., where=mesh1.facesLeft)
diff_coeff = CellVariable(mesh=mesh1, value=0.)

eqn0 = TransientTerm() == DiffusionTerm()
eqn1 = TransientTerm() == DiffusionTerm(diff_coeff) + 1.

viewer = Viewer(v1)

for i in range(steps):
v0.updateOld()
v1.updateOld()
eqn0.solve(v0, dt=dt)
diff_coeff[:] = v0
eqn1.solve(v1, dt=dt)
viewer.plot()

input("stopped")
--
Daniel Wheeler

Nils Winkler

unread,
Apr 21, 2024, 5:23:24 AM4/21/24
to fipy, Daniel Wheeler, fipy, Nils Winkler
Awesome. Thanks a lot!
Reply all
Reply to author
Forward
0 new messages