Re: Assign FaceVariable value based on submesh ID

2017-05-22 Thread Zhekai Deng
Hi Jon,

Thank you. It works perfectly.

Best,

Zhekai

On Sun, May 21, 2017 at 12:13 PM, Guyer, Jonathan E. Dr. (Fed) <
jonathan.gu...@nist.gov> wrote:

> Zhekai -
>
> Thank you for the explanation. You're right, I answered a much simpler
> question than you were asking.
>
> The following should do what you want:
>
> velocityVector = fp.FaceVariable(mesh=mesh, rank=1)
> topFaces = fp.numerix.unique(mesh.cellFaceIDs[...,
> mesh.physicalCells["top"].value].flatten().filled())
> velocityVector[0, topFaces] = velocityX_Top[..., topFaces]
> velocityVector[1, topFaces] = velocityY_Top[..., topFaces]
>
> This obtains all of the faces that surround each of the cells in "top",
> rearranges them into a long list, removes any empty values (different cells
> can have different numbers of faces), and then removes duplicates. The
> result is a list of the faceIDs for all the faces that bound all of the
> cells in "top".
>
>
> Alternatively,
>
> topFaces = (mesh.physicalCells["top"].faceValue != 0.).value
>
> This obtains the face-evaluated average of whether a cell is in "top".
> This relies on the fact that True and False can be treated pretty
> interchangeably with 1. and 0.. The result is a boolean mask which is True
> for all the faces that bound all of the cells in "top".
>
> - Jon
>
> > On May 12, 2017, at 12:13 PM, Zhekai Deng  northwestern.edu> wrote:
> >
> > Hi Jon,
> >
> > Thanks for answering that. However, I am afraid I am not fully
> understand how "physicalFaces" field for gmsh mesh could help me resolve
> this one.
> >
> > The "physicalFaces" field, If I understand correctly, is giving me the
> Physical Line (not Physical Surface) that I specified in gmsh. Thus, this
> is giving me the faces index on that specific line I specified in gmsh.
> What I want to achieve is that is there any function that takes sub-domain
> name as input (in my case "Physical Surface("top")) give me all the faces
> in this domain (not just faces on one line).
> >
> > If I just use mesh.physicalFaces["Top"], it will just return error
> because "Top" in my case is a "Physical Surface" not a "Physical Line".
> >
> > Any help will be appreciated. Thanks.
> >
> > Zhekai
> >
> > On Fri, May 12, 2017 at 8:54 AM, Guyer, Jonathan E. Dr. (Fed) <
> jonathan.gu...@nist.gov> wrote:
> > There is also a .physicalFaces field defined for a gmsh mesh.
> >
> > > On May 11, 2017, at 6:39 PM, Zhekai Deng  northwestern.edu> wrote:
> > >
> > > Hi All,
> > >
> > > I wonder is there any way to specify the FaceVariable based on the
> naming from gmsh ?  For example, I name my sub domain in gmsh as "top" and
> "bottom". In Fipy, I would like to do something similar to following:
> > >
> > > velocityX_Top = (1-Epsilon*Epsilon)/(Epsilon*Epsilon)*(yFace +
> Epsilon*np.sqrt(1-xFace*xFace))
> > > velocityY_Top = (1-Epsilon*Epsilon)/Epsilon*(
> xFace*yFace)/(np.sqrt(1-xFace*xFace))
> > > velocityX_Bottom = yFace
> > > velocityY_Bottom = -xFace
> > >
> > > velocityVector = FaceVariable(mesh=mesh.physicalCells["top"], rank=1)
> > > velocityVector[0] = velocityX_Top
> > > velocityVector[1] = velocityY_Top
> > >
> > > velocityVector = FaceVariable(mesh=mesh.physicalCells["bottom"],
> rank=1)
> > > velocityVector[0] = velocityX_Bottom
> > > velocityVector[1] = velocityY_Bottom
> > >
> > > I think it gives me error because the mesh.physicalCells is cell
> index, not face index. But is there any way I could do get all face index
> using sub domain ID?
> > >
> > > I have attached the complete and minimal code to demonstrate what I
> try to achieve.
> > >
> > > Thanks!
> > >
> > > 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 ]
>
>
> ___
> 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: Complex conjugates in FiPY

2017-05-22 Thread Daniel Wheeler
On Sat, May 20, 2017 at 5:02 AM, Sergio Manzetti
 wrote:
>
> Dear Daniel, I am wondering if you can clarify a small. thing.
>
> In the given script, phi is set as e^ix, and the numerical simulation treats 
> the given PDE. Is phi tested for wether it is a result of the given PDE in 
> this script ? Or does the script do something else?

I'm not quite sure what you're asking, but I'm sure that the script
below does not work as you intend it to work.

> #!/usr/bin/env python
> # testing a non-complex variant of the NLSE
>
> import numpy
> import cmath as math
> from fipy import *
> from fipy import numerix
>
> nx = 50
> dx = 1. / float(nx)
>
> mesh = Grid1D(nx=nx,dx=dx)
> X = mesh.cellCenters[0]
>
> phi = CellVariable(mesh=mesh, name="Solution")
> phi.setValue(0.5-0.5*numerix.exp((1j*X)))

At this point your script is broken, "phi.value.imag" is all zero
while "(0.5-0.5*numerix.exp((1j*X))).value.imag" is non-zero. The type
of the CellVariable is wrong initially and the type doesn't change
when the value is reset.

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