Re: [firedrake] vector function point-wise initialisation
Dear TJ, It isn't really intended that you get direct access to basis coefficients like this in Firedrake, and even if the grid is structured there is no particular order in which you can expect the basis coefficients to appear. The best plan is to subclass Expression and give it an eval method that takes in the coordinates of a point and returns the value (you will need to search your array for this), as documented here: http://firedrakeproject.org/interpolation.html#python-expression-classes This will not be very efficient but does the job. all the best --cjc On 5 May 2016 at 18:52, Sun, Tianjiao <tianjiao.sun14@imperial.ac.uk> wrote:
Thanks Colin.
What I was trying to set up is an image, so nx and ny are the number of pixels in each direction (I'm trying a pretty simplistic formulation as you can see...) The function g here will be things like the image gradient function, which I have only the numerical values but not the expression.
So I guess my question is how to get topological information about basis functions, in particular, for a rectangular mesh with degree 1 Lagrange element, are the basis functions arranged in a specific order? (so that I can use something like g.vector().set_local() to set the values).
Many thanks, -TJ
On 05/05/16 18:34, Colin Cotter wrote:
Dear TJ, If you want to initialise from a known function then you should do this by interpolating an Expression into a Function. Note that your mesh initialisation is probably not what you intended either, please check the doc-string for RectangleMesh.
all the best --cjc
On 5 May 2016 at 18:31, Sun, Tianjiao <tianjiao.sun14@imperial.ac.uk> wrote:
Dear team,
I have a beginner question about function initialisation in Firedrake.
I have the follow simple mesh and function space, and I want to initialise function g with values from numpy arrays (gx, gy). I'm not sure which way should I align the data in the constructor, i.e. should I concatenate gx, gy or interleave them?
mesh = RectangleMesh(nx-1,ny-1,nx,ny) V = VectorFunctionSpace(mesh, "CG", 1)
# g = Function(V, np.concatenate((gx, gy), axis=0))) ???
Many thanks, -TJ
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- http://www.imperial.ac.uk/people/colin.cotter
www.cambridge.org/9781107663916
_______________________________________________ firedrake mailing listfiredrake@imperial.ac.ukhttps://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- http://www.imperial.ac.uk/people/colin.cotter www.cambridge.org/9781107663916
Thanks Colin - it does the trick. -TJ On 05/05/16 19:36, Colin Cotter wrote:
Dear TJ, It isn't really intended that you get direct access to basis coefficients like this in Firedrake, and even if the grid is structured there is no particular order in which you can expect the basis coefficients to appear. The best plan is to subclass Expression and give it an eval method that takes in the coordinates of a point and returns the value (you will need to search your array for this), as documented here: http://firedrakeproject.org/interpolation.html#python-expression-classes
This will not be very efficient but does the job.
all the best --cjc
On 5 May 2016 at 18:52, Sun, Tianjiao <tianjiao.sun14@imperial.ac.uk <mailto:tianjiao.sun14@imperial.ac.uk>> wrote:
Thanks Colin.
What I was trying to set up is an image, so nx and ny are the number of pixels in each direction (I'm trying a pretty simplistic formulation as you can see...) The function g here will be things like the image gradient function, which I have only the numerical values but not the expression.
So I guess my question is how to get topological information about basis functions, in particular, for a rectangular mesh with degree 1 Lagrange element, are the basis functions arranged in a specific order? (so that I can use something like g.vector().set_local() to set the values).
Many thanks, -TJ
On 05/05/16 18:34, Colin Cotter wrote:
Dear TJ, If you want to initialise from a known function then you should do this by interpolating an Expression into a Function. Note that your mesh initialisation is probably not what you intended either, please check the doc-string for RectangleMesh.
all the best --cjc
On 5 May 2016 at 18:31, Sun, Tianjiao <tianjiao.sun14@imperial.ac.uk <mailto:tianjiao.sun14@imperial.ac.uk>> wrote:
Dear team,
I have a beginner question about function initialisation in Firedrake.
I have the follow simple mesh and function space, and I want to initialise function g with values from numpy arrays (gx, gy). I'm not sure which way should I align the data in the constructor, i.e. should I concatenate gx, gy or interleave them?
mesh = RectangleMesh(nx-1,ny-1,nx,ny) V = VectorFunctionSpace(mesh, "CG", 1)
# g = Function(V, np.concatenate((gx, gy), axis=0))) ???
Many thanks, -TJ
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk <mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- http://www.imperial.ac.uk/people/colin.cotter
www.cambridge.org/9781107663916 <http://www.cambridge.org/9781107663916>
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk <mailto:firedrake@imperial.ac.uk> https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- http://www.imperial.ac.uk/people/colin.cotter
www.cambridge.org/9781107663916 <http://www.cambridge.org/9781107663916>
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
participants (2)
-
Colin Cotter
-
Tianjiao Sun