Re: Periodic BC

2016-09-14 Thread Daniel Wheeler
On Wed, Sep 14, 2016 at 4:12 AM, Francisco Vega Reyes  wrote:
>
> Hi again,
>
> is there a way to implement periodic boundry conditions in fipy?

Yes, it's done with the mesh class rather than a constraint. A few examples,

http://stackoverflow.com/questions/36177369/fipy-simple-convection


https://github.com/usnistgov/fipy/blob/64f7866c8dbe50e2c36adfd23c464a53e4a2b763/examples/diffusion/steadyState/mesh1D/inputPeriodic.py

Hope that helps.

-- 
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: Periodic BC

2016-09-14 Thread Francisco Vega Reyes

Hi again,

is there a way to implement periodic boundry conditions in fipy?

for instance: field(x=L)==field(x=-L)

Thanks

Francisco

El mar, 17-05-2016 a las 09:44 -0400, Daniel Wheeler escribió:
> Hi Francisco,
> 
> In FiPy, it is necessary to add both a TransientTerm and a source term
> for terms such as,
> 
> density (times) (\partial f[x]/\partial t)
> 
> So, the code will look something like this,
> 
> TransientTerm(var=var, coeff=density) - field * (density - density.old) / 
> dt
> 
> There may be ways to improve the convergence with implicit sources,
> but I haven't investigated that. For example, the "field * density.old
> / dt" part could become implicit in "field" and the the "field *
> density / dt" could be implicit for "density" and coupled with an
> equation solving for density.
> 
> Cheers,
> 
> Daniel
> 
> On Mon, May 16, 2016 at 1:30 PM, Francisco Vega Reyes  wrote:
> > Hello,
> >
> > a very common term in the Navier-Stokes equations for a gas is of the form:
> >
> > density (times) (\partial f[x]/\partial t),
> >
> > where f[x] is a hydrodynamic field (for instance, temperature). however, it 
> > appears in the Fipy manual that the transient terms that express time 
> > derivatives have no multiplying coefficients. I’d like to solve the 
> > transient Navier Stokes equations for a gas without having to divide the 
> > whole balance equations by density, which is of course also an unknown.
> >
> > How can I express then a term of the form above in Fipy?
> >
> > Thank you very much,
> >
> >
> > Dr. Francisco Vega Reyes
> >
> > Departamento de Física,
> > Universidad de Extremadura,
> > 06071 Badajoz, Spain
> >
> > fv...@unex.es
> >
> >
> >
> >
> >
> > ___
> > 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: Error Condition Re: periodic BC on gmsh

2011-01-13 Thread Jonathan Guyer

Forwarding a question that was erroneously bumped from the list.

On Jan 12, 2011, at 4:34 PM, Changsoo Kim  wrote:

> Is there an option to assign a periodic boundary condition on a mesh created 
> from Gmsh? I want to impose a periodic BC along x-direction (only), I know we 
> can use "PeriodicGrid2DLeftRight", but not on the mesh from Gmsh. Any 
> thoughts?

In principle, you can call mesh._connectFaces(faces0, faces1) on any mesh. 
faces0 and faces1 are lists of face IDs. The problem is getting those lists of 
IDs and making sure that they're in the right order.

To get the list of IDs, you can do things like

 X, Y = mesh.getFaceCenters()
 facesLeft = mesh.getExteriorFaces() & numerix.isclose(X, Xleft, atol=1e-10)
 facesRight = mesh.getExteriorFaces() & numerix.isclose(X, Xright, atol=1e-10)
 faces0 = numerix.nonzero(facesLeft)[0]
 faces1 = numerix.nonzero(facesRight)[0]

There is no guarantee, though, that faces0 are lined up with faces1, or even 
that the faces are the same size (they must match up exactly).

You might be able to do something with sorting the IDs on the corresponding Y 
values, obtained with Y[faces0]

but you still need to be sure that gmsh is generating faces that can match.

Here's a script that illustrates it. This requires the tip of trunk (r4101) 
because I had to relax a check on matching orientations.

The banding that appears is a viewer artifact.



from fipy import *

# make triangulated mesh in a square domain
mesh = Gmsh2D('''
  cellSize = 0.2;
  Point(1) = {0, 0, 0, cellSize};
  Point(2) = {10., 0, 0, cellSize};
  Point(3) = {10., 10., 0, cellSize};
  Point(4) = {0., 10., 0, cellSize};
  Line(1) = {1, 2};
  Line(2) = {2, 3};
  Line(3) = {3, 4};
  Line(4) = {4, 1};
  Line Loop(1) = {1, 2, 3, 4};
  Plane Surface(1) = {1};
  ''' % locals())
  
x, y = mesh.getCellCenters()
X, Y = mesh.getFaceCenters()

# get the left and right faces
facesLeft = mesh.getExteriorFaces() & numerix.isclose(X, 0., atol=1e-10)
facesRight = mesh.getExteriorFaces() & numerix.isclose(X, 10., atol=1e-10)

# get the IDs of the faces
faces0 = numerix.nonzero(facesLeft)[0]
faces1 = numerix.nonzero(facesRight)[0]

# sort the IDs of the faces in ascending Y
faces0 = faces0[argsort(Y[faces0])]
faces1 = faces1[argsort(Y[faces1])]

# connect the faces
mesh._connectFaces(faces0=faces0, faces1=faces1)

var = CellVariable(mesh=mesh)

# make a circular seed
var.setValue(((x - 5.)**2 + (y - 5.)**2 <= 2**2) * 1.)

viewer = Viewer(vars=var, datamin=0., datamax=1.)
viewer.plot()

# calculate the maximum timestep
dx = numerix.sqrt(mesh.getCellVolumes().min())
speed = 1.0
cfl = 0.5
dt = cfl * dx / speed

# advect the circle
eq = TransientTerm() + VanLeerConvectionTerm(coeff = [[speed], [0.]])

for step in range(1000.):
eq.solve(var, dt=dt)
viewer.plot()