Simplest way to access cell2vertex array from mesh
Hi all, Sorry for simple questions again, what is the simplest way to access cell to vertex data from a mesh. I am going around in circles! I am looking at the “pyop2” example of computing midpoints of cells I.e. vertices = op2.Set(num_vertices) cells = op2.Set(num_cells) cell2vertex = op2.Map(cells, vertices, 3, […]) So I need the data from the mesh to replace […] Thanks Tim Dr Tim Dodwell Senior Lecturer in Engineering Mathematics Rm 221 - Harrison Building College of Engineering, Mathematics & Physical Sciences University of Exeter Exeter Devon EX4 4PY mail: t.dodwell(at)exeter.ac.uk<http://exeter.ac.uk/> tel: +44 (0)1392 725899 mob: +44 (0)7745 622870 web: http://emps.exeter.ac.uk/engineering/staff/td336 Papers and Pre-prints: @Research-Gate<https://www.researchgate.net/profile/Timothy_Dodwell> Citations: @Google-Scholar<https://scholar.google.co.uk/citations?user=lPpjRfUAAAAJ&hl=en>
Hi Tim,
On 4 Sep 2017, at 22:57, Dodwell, Timothy <T.Dodwell@exeter.ac.uk> wrote:
Hi all,
Sorry for simple questions again, what is the simplest way to access cell to vertex data from a mesh. I am going around in circles!
I am looking at the “pyop2” example of computing midpoints of cells
If you have a firedrake Function, or FunctionSpace, you can access the map from cells to function space nodes with the cell_node_map() method: So for cells to vertices you can do: V = FunctionSpace(mesh, "CG", 1) cell2vertex = V.cell_node_map() However, to step back a bit, what is it that you would like to achieve once you have this map? Needing to access the values in user code is often (though not always) an indicator that you've missed how to specify something symbolically (as a whole-mesh operation): most of the time doing finite elements in Firedrake you shouldn't need to know about this level of the implementation. Cheers, Lawrence
Hi Lawrence, Thanks for you email. I am setting up a Multilevel Monte Carlos Algorithm for porous flow within a log-normal random permeability field (truncated KL expansion), so Perm(x,y) = exp(\sum xi_i * phi_i(x,y)), xi ~N(0,1) and phi_i(x,y) some scaled eigenfunction of covariance operator. I was defining the perm field as piecewise constant function, and trying to assign values at midpoints. But like you said why don’t I just define it as a function (which I probably want to do for each phi_i as used for each random sample!) Cheers Tim Dr Tim Dodwell Senior Lecturer in Engineering Mathematics Rm 221 - Harrison Building College of Engineering, Mathematics & Physical Sciences University of Exeter Exeter Devon EX4 4PY mail: t.dodwell(at)exeter.ac.uk <http://exeter.ac.uk/> tel: +44 (0)1392 725899 mob: +44 (0)7745 622870 web: http://emps.exeter.ac.uk/engineering/staff/td336 Papers and Pre-prints: @Research-Gate <https://www.researchgate.net/profile/Timothy_Dodwell> Citations: @Google-Scholar <https://scholar.google.co.uk/citations?user=lPpjRfUAAAAJ&hl=en> On 05/09/2017, 08:47, "firedrake-bounces@imperial.ac.uk on behalf of Lawrence Mitchell" <firedrake-bounces@imperial.ac.uk on behalf of lawrence.mitchell@imperial.ac.uk> wrote:
Hi Tim,
On 4 Sep 2017, at 22:57, Dodwell, Timothy <T.Dodwell@exeter.ac.uk> wrote:
Hi all,
Sorry for simple questions again, what is the simplest way to access cell to vertex data from a mesh. I am going around in circles!
I am looking at the “pyop2” example of computing midpoints of cells
If you have a firedrake Function, or FunctionSpace, you can access the map from cells to function space nodes with the cell_node_map() method:
So for cells to vertices you can do:
V = FunctionSpace(mesh, "CG", 1)
cell2vertex = V.cell_node_map()
However, to step back a bit, what is it that you would like to achieve once you have this map? Needing to access the values in user code is often (though not always) an indicator that you've missed how to specify something symbolically (as a whole-mesh operation): most of the time doing finite elements in Firedrake you shouldn't need to know about this level of the implementation.
Cheers,
Lawrence _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
On 05/09/17 08:59, Dodwell, Timothy wrote:
Hi Lawrence,
Thanks for you email.
I am setting up a Multilevel Monte Carlos Algorithm for porous flow within a log-normal random permeability field (truncated KL expansion), so
Perm(x,y) = exp(\sum xi_i * phi_i(x,y)), xi ~N(0,1) and phi_i(x,y) some scaled eigenfunction of covariance operator.
I was defining the perm field as piecewise constant function, and trying to assign values at midpoints. But like you said why don’t I just define it as a function (which I probably want to do for each phi_i as used for each random sample!) Yeah, so let's assume you've computed the phis and stored them in a list of Functions, then you could write:
phis = [phi1, phi2, phi3, ...] xis = [xi1, xi2, xi3, ...] expr = exp(sum(xi*phi for xi, phi in zip(xis, phis))) perm = interpolate(expr, FunctionSpace(mesh, "DG", 0)) I think this is what you want. This evaluates expr at the nodes of the target function space and interpolates it there. Naturally this value changes if you change the definition of the nodes (the node for the DG0 space happens to be at the barycentre of the cell, but it need not be). You could also project if you wanted an L2 optimal approximation. Lawrence
participants (2)
- 
                
                Dodwell, Timothy
- 
                
                Lawrence Mitchell