Dear Zhekai,

My October 11th post to this list affects my recommendation to you from October 
4th. You'll probably be fine if you aren't running your simulation for long, 
but if you are running it for long periods, it will likely become cripplingly 
slow. I've implemented the corrected version below for you, which should not 
have a memory leak because of the method of updating the boundary condition.

I hope that helps.

Best regards,


-          Ian

phi_1_initial, phi_2_initial = 0.0, 0.0
D1, D2 = 1.5, 1.75

dx_1 = [0.03806023, 0.10838638, 0.16221167, 0.19134172, 0.19134172, 0.16221167, 
0.10838638, 0.03806023]
dx_2 = [0.03806023, 0.10838638, 0.16221167, 0.19134172, 0.19134172, 0.16221167, 
0.10838638, 0.03806023]

mesh_1 = Grid1D(dx=dx_1, Lx=1.0)
mesh_2 = Grid1D(dx=dx_2, Lx=1.0)

phi_1 = CellVariable(mesh_1, value=phi_1_initial)
phi_2 = CellVariable(mesh_2, value=phi_2_initial)

eq_1 = TransientTerm() == ExplicitDiffusionTerm(coeff=D1)
eq_2 = TransientTerm() == ExplicitDiffusionTerm(coeff=D2)

phi_1.faceGrad.constrain(0.5, where=mesh_1.facesLeft)
phi_1.constrain(1.0, where=mesh_1.facesRight)
inlet_BC_value = Variable()
phi_2.faceGrad.constrain(inlet_BC_value, where=mesh_2.facesLeft)
phi_2.faceGrad.constrain(-0.5, where=mesh_2.facesRight)

timeStepDuration = 0.9 * min(dx_1)**2 / (2 * max(D1, D2))
steps = 100
viewer = Viewer(vars=(phi_1, phi_2))

for step in range(steps):
    eq_1.solve(var=phi_1, dt = timeStepDuration)
    inlet_BC_value_new = phi_1.faceValue[mesh_2.faceCenters == 1.0]     # 
Acquire the data
    inlet_BC_value.setValue(float(inlet_BC_value_new))                          
          # Apply that data on the 2nd mesh
    eq_2.solve(var=phi_2, dt = timeStepDuration)
    viewer.plot()


From: fipy-boun...@nist.gov [mailto:fipy-boun...@nist.gov] On Behalf Of Zhekai 
Deng
Sent: 05 October 2016 05:20
To: fipy@nist.gov
Subject: Re: how to set up data transfer between two adjacent nonuniform meshs

Hi Ian,

Thank you very much for the example and pointing out the additional reference. 
Those are very useful informations. This approach seems intuitive and easy to 
incorporate into the code. I will try to incorporate it into my own code.  
Thanks again.

Best,

Zhekai

On Tue, Oct 4, 2016 at 5:23 AM, Campbell, Ian 
<i.campbel...@imperial.ac.uk<mailto:i.campbel...@imperial.ac.uk>> wrote:
Hi Zhekai,

There is.

Try the following, where as you suggest, the interpolated value at the 
right-most face of mesh_1 is used. That (outward flowing) flux value is then 
copied to the inlet boundary condition (Neumann/flux) for mesh_2. A diffusion 
equation with a different coefficient for your solution variable phi is defined 
on the 2nd mesh - this should work if you change the equation further. Both 
meshes are non-uniform and of unit length.

I don't know from your question what type or magnitude boundary conditions 
you're interested in on the other faces, but nonetheless, you can see in the 
figures produced from the code below that the outlet flux on the right-most 
face of mesh_1 is equal to the inlet flux on the left-most face of mesh_2. 
There's likely a cleaner way to do this, by updating the value of the boundary 
condition for mesh_2 rather than re-defining it, but this is a start.

An additional reference for you, here is Dr. Guyer's suitably-named Gist: 
https://gist.github.com/guyer/bb199559c00f6047d466daa18554d83d

Let us know if that works for you.

Best,


-          Ian

phi_1_initial, phi_2_initial = 0.0, 0.0
D1, D2 = 1.5, 1.75
inlet_BC_value_init = 2.0

dx_1 = [0.03806023, 0.10838638, 0.16221167, 0.19134172, 0.19134172, 0.16221167, 
0.10838638, 0.03806023]
dx_2 = [0.03806023, 0.10838638, 0.16221167, 0.19134172, 0.19134172, 0.16221167, 
0.10838638, 0.03806023]

mesh_1 = Grid1D(dx=dx_1, Lx=1.0)
mesh_2 = Grid1D(dx=dx_2, Lx=1.0)

phi_1 = CellVariable(mesh_1, value=phi_1_initial)
phi_2 = CellVariable(mesh_2, value=phi_2_initial)

eq_1 = TransientTerm() == ExplicitDiffusionTerm(coeff=D1)
eq_2 = TransientTerm() == ExplicitDiffusionTerm(coeff=D2)

# Boundary Conditions
phi_1.faceGrad.constrain(0.5, where=mesh_1.facesLeft)
phi_1.constrain(1.0, where=mesh_1.facesRight)
phi_2.faceGrad.constrain(inlet_BC_value_init, where=mesh_2.facesLeft)
phi_2.faceGrad.constrain(-0.5, where=mesh_2.facesRight)

timeStepDuration = 0.9 * min(dx_1)**2 / (2 * max(D1, D2))
steps = 100
viewer = Viewer(vars=(phi_1, phi_2))

for step in range(steps):
    eq_1.solve(var=phi_1, dt = timeStepDuration)
    inlet_BC_value = phi_1.faceValue[mesh_2.faceCenters == 1.0]         # 
Acquire the data
    phi_2.faceGrad.constrain(inlet_BC_value, where=mesh_2.facesLeft)    # Apply 
that data on the 2nd mesh
    eq_2.solve(var=phi_2, dt = timeStepDuration)
    viewer.plot()

From: fipy-boun...@nist.gov<mailto:fipy-boun...@nist.gov> 
[mailto:fipy-boun...@nist.gov<mailto:fipy-boun...@nist.gov>] On Behalf Of 
Zhekai Deng
Sent: 04 October 2016 03:29
To: fipy@nist.gov<mailto:fipy@nist.gov>
Subject: how to set up data transfer between two adjacent nonuniform meshs

Hello All,

I wonder is there any way to allow the data share on the two nonuniform mesh's 
interface ? To explain this, let's say I have two meshes, mesh_1 and mesh_2. 
Different equations govern the mesh_1 and mesh_2, and solution variable on both 
meshes is phi.  I would like the outlet (on the right face) on mesh_1 served as 
inlet(on the left face) on mesh_2.

I tired to concatenate two mesh. If they are uniform, this works fine. However, 
if two does not share the exact the same face (for example, one is uniform, and 
another is nonuniform), there seems to be problem. .

Thus, I wonder is there any way to "interpolate" the phi.facevalue on mesh_1 
outlet face, and apply this interpolation value into the inlet of mesh_2?


Best,

Zhekai

_______________________________________________
fipy mailing list
fipy@nist.gov<mailto:fipy@nist.gov>
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

_______________________________________________
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to