-
Following #1086, I am solving: where:
Using fiPy as: # ###### load mesh
mesh = Gmsh2D(os.path.join(f"{name}.geo_unrolled"), communicator=serialComm)
yz_meshface = np.array(mesh.faceCenters)
yz_meshcell = np.array(mesh.cellCenters)
# ###### define variables
phi = CellVariable(name=r"$\phi$", mesh=mesh, value=0.8, hasOld=sweep)
velocity = FaceVariable(name="vel", mesh=mesh, rank=1)
yz_meshface = np.array(mesh.faceCenters)
velocity[0, :] = U * MODEL_DFLT.compute_v(yz_meshface[0, :], yz_meshface[1, :])
velocity[1, :] = U * MODEL_DFLT.compute_w(yz_meshface[0, :], yz_meshface[1, :])
diffcoeff = FaceVariable(name="D", mesh=mesh, value=D)
segcoeff = CellVariable(name="F", mesh=mesh, rank=1)
segcoeff[0, :] = 0
segcoeff[1, :] = F
# ###### define equation
eq = TransientTerm(var=phi) + VanLeerConvectionTerm(coeff=segcoeff * (1 - phi), var=phi) + VanLeerConvectionTerm(
coeff=velocity, var=phi
) == DiffusionTerm(coeff=diffcoeff, var=phi) and the temporal loop: while res >= stop_condition:
print(step)
if sweep:
phi.updateOld()
for sweep in range(sweep_number):
res_sweep = eq.sweep(var=phi, dt=timestep)
print(f"res_sweep = {res_sweep:1.2e}")
else:
eq.solve(var=phi, dt=timestep)
res = np.abs(phi.value - phi_old).max()
print(f"res_dt = {res:1.2e}")
phi_old = np.copy(phi.value)
step += 1 This leads to excellent results. However, defining the entire first ConvectionTerm coefficient outside as: segcoeff = CellVariable(name="F", mesh=mesh, rank=1)
segcoeff[0, :] = 0
segcoeff[1, :] = F* (1 - phi) # <------------- Here
# ###### define equation
eq = TransientTerm(var=phi) + VanLeerConvectionTerm(coeff=segcoeff , var=phi) + VanLeerConvectionTerm(
coeff=velocity, var=phi
) == DiffusionTerm(coeff=diffcoeff, var=phi) induces completely different (and wrong) results.
EDIT: looking through the examples talking about anisotropy, found that I could do something like: seg_prefact = (u_z * d_av / (pi_d * d_av + p)) * (phi_m - phi) * (phi_m - lamb * phi)
# seg_prefact = phi_m - phi
seg_vec = Variable(value=[0, -1])
seg_coeff = seg_prefact * seg_vec Is there a difference between using
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yay!
When you write segcoeff[1, :] = F* (1 - phi) you are assigning the instantaneous value of that expression to
Exactly. Assembling coefficients is illustrated in:
For fixed orientations, a
Multiplying a scalar
The bit in the FAQ could perhaps be written more clearly. DiffusionTerm([[[5, 0], [0, 1]]]) represents a 2nd order anisotropic diffusion term for a 2D field: DiffusionTerm([[5, 1]]) (a list containing a list containing two values) represents the same 2nd order anisotropic diffusion term. DiffusionTerm([5, 1]) (a list containing two values) represents the 4th order isotropic diffusion term: Although supported, we no longer recommend the use of higher order diffusion expressions. The same result can be obtained by factoring higher order PDEs into a coupling of 2nd order PDEs. |
Beta Was this translation helpful? Give feedback.
Yay!
When you write
you are assigning the instantaneous value of that expression to
segcoeff[1, :]
; it won't update asphi
changes.