Tony S Yu | 10 Jul 00:43
Favicon

Setting boundary conditions on interior cells


This is probably a bad idea, but I want to set a boundary condition on  
an interior cell. Alternatively, I would just have a rectangular mesh  
with some of the nodes masked off (kind of like a step on one of the  
rectangle's sides). The problem with changing the mesh in this manner  
is that this boundary condition needs to move in time.

My first thought was to force a cell to a given value by repeatedly  
resetting its value inside the solution loop. But, since the diffusion  
terms use the face values (not cell values) in the solution, I'm not  
getting the value back. The next (bad) idea I had was to set the face  
values, but I didn't see a way of doing this.

Is there a way of setting a boundary condition on an interior cell?

Thanks,
-Tony

Test script:
~~~~~~~~~~~~~~~
from fipy import *

dt = 0.001
# material properties
D = 1.
c0 = 1.
c_sink = 0.
# spacial parameters
nx = ny = 3
dx = dy = 1.
(Continue reading)

Daniel Wheeler | 10 Jul 17:22
Gravatar

Re: Setting boundary conditions on interior cells


On Wed, Jul 9, 2008 at 6:45 PM, Tony S Yu <tonyyu@...> wrote:
>
> This is probably a bad idea, but I want to set a boundary condition on an
> interior cell. Alternatively, I would just have a rectangular mesh with some
> of the nodes masked off (kind of like a step on one of the rectangle's
> sides). The problem with changing the mesh in this manner is that this
> boundary condition needs to move in time.

As you may have noticed the boundary condition objects do not work on
internal faces. However this does not seem to be your issue. You
should be able to set the value of a cell internally, either by
continually resetting the value or by having a source in the equation.
Looking at the script below, the value is reset and then the equation
is solved. There us no reason that the value should still be zero
after solve(). Resetting at every sweep or time step has its
limitations, bu the values are decreasing as you would expect.

In general, if one has an internal moving boundary condition, it is
probably best to use a secondary variable that defines the position of
the interface and then make any internal boundary conditions dependent
on this variable. This is basically what happens in phase field and
level set problems.

> My first thought was to force a cell to a given value by repeatedly
> resetting its value inside the solution loop. But, since the diffusion terms
> use the face values (not cell values) in the solution, I'm not getting the
> value back. The next (bad) idea I had was to set the face values, but I
> didn't see a way of doing this.
>
(Continue reading)

Tony S Yu | 10 Jul 19:02
Favicon

Re: Setting boundary conditions on interior cells


On Jul 10, 2008, at 11:22 AM, Daniel Wheeler wrote:

>
> On Wed, Jul 9, 2008 at 6:45 PM, Tony S Yu <tonyyu@...> wrote:
>>
>> This is probably a bad idea, but I want to set a boundary condition  
>> on an
>> interior cell. Alternatively, I would just have a rectangular mesh  
>> with some
>> of the nodes masked off (kind of like a step on one of the  
>> rectangle's
>> sides). The problem with changing the mesh in this manner is that  
>> this
>> boundary condition needs to move in time.
>
> As you may have noticed the boundary condition objects do not work on
> internal faces. However this does not seem to be your issue. You
> should be able to set the value of a cell internally, either by
> continually resetting the value or by having a source in the equation.
> Looking at the script below, the value is reset and then the equation
> is solved. There us no reason that the value should still be zero
> after solve(). Resetting at every sweep or time step has its
> limitations, bu the values are decreasing as you would expect.
>
> In general, if one has an internal moving boundary condition, it is
> probably best to use a secondary variable that defines the position of
> the interface and then make any internal boundary conditions dependent
> on this variable. This is basically what happens in phase field and
> level set problems.
(Continue reading)

Jonathan Guyer | 10 Jul 19:30
Favicon

Re: Setting boundary conditions on interior cells


On Jul 10, 2008, at 1:02 PM, Tony S Yu wrote:

> Thanks, this solution works as you suggest. However, I don't  
> understand the math. It looks like the last term is what I would  
> normally consider to be a source/sink, with the magnitude of the  
> term being proportional to the flux into/out-of the system. But, I  
> don't understand how ImplicitSourceTerm works (I looked at the  
> docstring, but I'm still confused).
>
> I don't want to waste your time, but if you could point me to a good  
> reference on this type of source term, I would be very grateful.

An ImplicitSourceTerm is simply a source that is proportional to the  
solved variable.

There's a brief discussion of sources in Section 3.3 of http://www.ctcms.nist.gov/fipy/download/fipy.pdf

In that notation, S0 corresponds to our _ExplictSourceTerm  (c_sink *  
large_value in this case) and S1*phiP is our ImplicitSourceTerm (with  
coeff=S1, so ImplicitSourceTerm(large_value) represents large_value *  
phi in your case).

Daniel Wheeler | 10 Jul 19:44
Gravatar

Re: Setting boundary conditions on interior cells


On Thu, Jul 10, 2008 at 1:02 PM, Tony S Yu <tonyyu@...> wrote:
>
>
> Thanks, this solution works as you suggest. However, I don't understand the
> math.

There is not really much to it. It just fixed one cell to have a
permanent value..

> It looks like the last term is what I would normally consider to be a
> source/sink, with the magnitude of the term being proportional to the flux
> into/out-of the system.

This is similar. Essentially, the cell is being removed from the
calculation and acting as a fixed value boundary condition for its
neighboring cells. The boundary condition is at the cell center rather
than the faces.

> But, I don't understand how ImplicitSourceTerm works
> (I looked at the docstring, but I'm still confused).

ImplicitSourceTerm(coeff) adds "coeff * cellVolume" to the diagonal of
the matrix. If you have a source "a * phi" for example, where phi is
the variable that you are solving for, then you would write
ImplicitSourceTerm(a). The  phi is included implicitly.

> I don't want to waste your time, but if you could point me to a good
> reference on this type of source term, I would be very grateful.

(Continue reading)


Gmane