Hi All, I tried to implement this approach in my problem, and encountered some problems. To keep this post more general, I posted the pseudo code, and point out the problem. I could also send the actual code in private if someone is willing to take a look at it.
Basically, I have two 2D gmsh created irregular mesh that connected to each other. I am trying to "copy" the value from the boundary of mesh_1, into the mesh_2. Please note that mesh_1 and mesh_2 both share this boundary. After playing around the gmsh, I found that I could draw two fields together. However, when I actually created the surface, I only created the surface corresponding to mesh_1 and mesh_2 mesh_1 = Gmsh2D('' ........ Line Loop(9) = {6,7, 8,5}; Line Loop(10) = {-6,-5,9}; Plane Surface (11) = {9}; Physical Surface("flowinglayer") = {11}; Physical Line("Bottom_Left") = {5}; Physical Line("Bottom_Right") = {6}; ''' % locals()) mesh_2 = Gmsh2D(''' ......... Line Loop(9) = {6,7, 8,5}; Line Loop(10) = {-6,-5,9}; Plane Surface (12) = {10}; Physical Surface("bulkflow") = {12}; Physical Line("Bottom_Left") = {5}; Physical Line("Bottom_Right") = {6}; ''' % locals()) As you could see, mesh_1 only corresponding to line loop 9, mesh_2 only corresponding to line loop 10. The reason I do this is it allows the mesh between the interface of the mesh_1 and mesh_2 to mesh properly. Then I created variable to transfer data, as suggested by Ian. inlet_BC_value = Variable(value = 0.5, array = numerix.zeros((1,102))) phi_2.constrain(inlet_BC_value, where = mesh_2.exteriorFaces & mesh_2.physicalFaces["Bottom_Right"]) Finally, solve the equation and update this "inlet_BC_value" for step in range(steps): res_1 = 1000 res_2 = 1000 inlet_BC_value_new = phi_1.faceValue[(mesh_1.exteriorFaces & mesh_1.physicalFaces["Bottom_Right"]).value] inlet_BC_value.value = np.float64(inlet_BC_value_new) while np.maximum(res_1,res_2) > 1e-4: res_1 = eq_1.sweep(var=phi_1,dt=timeStepDuration) res_2 = eq_2.sweep(var=phi_2,dt=timeStepDuration) # doctest: +GMSH phi_1.updateOld() phi_2.updateOld() viewer_1.plot() viewer_2.plot() print step On Wed, Oct 12, 2016 at 11:14 PM, Zhekai Deng < zhekaideng2...@u.northwestern.edu> wrote: > I see. Thanks for clarifying it ! I will implement this over the weekend > and to see how it works out. Thank you. > > Best, > > Zhekai > > On Wed, Oct 12, 2016 at 8:15 AM, Campbell, Ian < > i.campbel...@imperial.ac.uk> wrote: > >> 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> 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] *On Behalf >> Of *Zhekai Deng >> *Sent:* 04 October 2016 03:29 >> *To:* 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 >> 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 ] >> >> >
_______________________________________________ fipy mailing list fipy@nist.gov http://www.ctcms.nist.gov/fipy [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]