Re: FW: how to set up data transfer between two adjacent nonuniform meshs

2016-10-25 Thread Daniel Wheeler
On Tue, Oct 25, 2016 at 12:59 PM, Zhekai Deng
 wrote:
> Thanks for the tip. Right now, my code looks like following, where
> Outlet_BC_value_new is being updated every time,  so does the
> Outlet_BC_value. It is my understanding that every timestep,
> Outlet_BC_value_new is being over-write with new interpolated value, and
> being assign to the Variable, which automatically update it with the phi
> constrain. Is this somewhat similar to what you are suggesting for the cache
> the memory space ?

Yes, however, profile first to see if it is relevant in your case.

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


Re: FW: how to set up data transfer between two adjacent nonuniform meshs

2016-10-25 Thread Zhekai Deng
Thanks for the tip. Right now, my code looks like following, where
Outlet_BC_value_new is being updated every time,  so does the
Outlet_BC_value. It is my understanding that every timestep,
Outlet_BC_value_new is being over-write with new interpolated value, and
being assign to the Variable, which automatically update it with the phi
constrain. Is this somewhat similar to what you are suggesting for the
cache the memory space ?


Outlet_BC_value = Variable(value = 0.5, array = numerix.zeros((1,102)))

phi.constrain(Outlet_BC_value, where = mesh_2.exteriorFaces &
mesh_2.physicalFaces["Right"])


if for step in range(steps):

 Outlet_BC_value_new = scipy.interpolate.griddata(points, values,
(xFace_2[a], yFace_2[a]), method='nearest')

 Outlet_BC_value.setValue(Outlet_BC_value_new)

 #Then solve equation


Best,


Zhekai

On Tue, Oct 25, 2016 at 11:44 AM, Daniel Wheeler 
wrote:

> On Tue, Oct 25, 2016 at 12:34 PM, Zhekai Deng
>  wrote:
> > Thank you. I implemented as you suggested and it works very good now.
> This
> > approach seems also applicable for the mesh that are not aligned in the
> > interface.
>
> Exactly. One thing though, it is probably a good idea to cache the
> mapping from one grid to the other as this is expensive to calculate
> (especially of you do this at every time step or sweep). We provided
> this functionality in FiPY, I'm not sure if Scipy lets you do that.
>
> --
> Daniel Wheeler
> ___
> 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 ]


Re: FW: how to set up data transfer between two adjacent nonuniform meshs

2016-10-25 Thread Daniel Wheeler
On Tue, Oct 25, 2016 at 12:34 PM, Zhekai Deng
 wrote:
> Thank you. I implemented as you suggested and it works very good now. This
> approach seems also applicable for the mesh that are not aligned in the
> interface.

Exactly. One thing though, it is probably a good idea to cache the
mapping from one grid to the other as this is expensive to calculate
(especially of you do this at every time step or sweep). We provided
this functionality in FiPY, I'm not sure if Scipy lets you do that.

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


Re: FW: how to set up data transfer between two adjacent nonuniform meshs

2016-10-25 Thread Zhekai Deng
Thank you. I implemented as you suggested and it works very good now. This
approach seems also applicable for the mesh that are not aligned in the
interface.

Best,

Zhekai

On Mon, Oct 24, 2016 at 9:00 AM, Daniel Wheeler 
wrote:

> On Mon, Oct 24, 2016 at 12:20 AM, Zhekai Deng
>  wrote:
> >
> > This is not a issue if mesh system is 1D, and boundary cell is just 1. Or
> > maybe on the rectangular mesh system. However, does any one has any idea
> to
> > how to transfer it properly ?
>
> Hi Zhekai; I haven't read through everything but I would guess that
> you need to interpolate from one mesh to another. To do that you can
> use one of Scipy's inerpolation functions such as
>
> https://docs.scipy.org/doc/scipy-0.14.0/reference/
> generated/scipy.interpolate.griddata.html
>
> We also built that capability into FiPy, but it's probably better to
> use Scipy's interpolation at this point.
>
> https://github.com/usnistgov/fipy/blob/develop/fipy/
> variables/cellVariable.py#L167
>
> If the mesh points are aligned, it is still a good idea to use the
> interpolation approach as it removes the issue of worrying about mesh
> ordering.
>
> --
> Daniel Wheeler
> ___
> 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 ]


Re: FW: how to set up data transfer between two adjacent nonuniform meshs

2016-10-24 Thread Daniel Wheeler
On Mon, Oct 24, 2016 at 12:20 AM, Zhekai Deng
 wrote:
>
> This is not a issue if mesh system is 1D, and boundary cell is just 1. Or
> maybe on the rectangular mesh system. However, does any one has any idea to
> how to transfer it properly ?

Hi Zhekai; I haven't read through everything but I would guess that
you need to interpolate from one mesh to another. To do that you can
use one of Scipy's inerpolation functions such as


https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.griddata.html

We also built that capability into FiPy, but it's probably better to
use Scipy's interpolation at this point.


https://github.com/usnistgov/fipy/blob/develop/fipy/variables/cellVariable.py#L167

If the mesh points are aligned, it is still a good idea to use the
interpolation approach as it removes the issue of worrying about mesh
ordering.

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


Re: FW: how to set up data transfer between two adjacent nonuniform meshs

2016-10-23 Thread Zhekai Deng
Sorry, I accidentally hit the "send" button. So I am just going to continue
with previous email. The problem with above approach is that while it
transfer the data successfully, the data is not in the right spatial
position. This could be because the order which fipy name in mesh_1 is
different from mesh_2. So this inlet_BC_value_new might have the position
index from mesh_1, but mesh_2 does not use the same index to order the
cell. Consequently, the data, when it is transferred to mesh_2, is at
different position.

This is not a issue if mesh system is 1D, and boundary cell is just 1. Or
maybe on the rectangular mesh system. However, does any one has any idea to
how to transfer it properly ?

Also, the reason I initialized this Variable has 102 element is that I
checked on the boundary, there is 102 cells. I realized I f I don't
initialized with correct dimension, then I can't acquire data in the
solving step.

inlet_BC_value = Variable(value = 0.5, array = numerix.zeros((1,102)))


PS. Thanks Ian for providing the example before.


Any suggestion is appreciated.


Best,


Zhekai


On Sun, Oct 23, 2016 at 11:10 PM, Zhekai Deng <
zhekaideng2...@u.northwestern.edu> wrote:

> 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  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.cons

Re: FW: how to set up data transfer between two adjacent nonuniform meshs

2016-10-23 Thread Zhekai Deng
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...@imper

Re: FW: how to set up data transfer between two adjacent nonuniform meshs

2016-10-12 Thread Zhekai Deng
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 
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 
> 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 t

FW: how to set up data transfer between two adjacent nonuniform meshs

2016-10-12 Thread Campbell, Ian
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 
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] 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