returning the results for particular cells/elements


105
views
1
4 months ago by
hey y'all

I'm solving a heat transfer equation and I only want to get the results at specific locations. I use a 3D cubic mesh (BoxMesh) and I don't need all the data really. However I use Vector().get_local() to get all temperature values but also couldn't figure our what cell is associated with what value, because it just gives me a vector of values. I thought I might try to map the values to location manually but I couldn't figure out the location and index of each cell. For instance, I have 480,000 cells in my mesh, so I get 480,000 temperature values at each iteration but i don't know how to find the location of each cell.

So my question is, is there a way to know the location of each index so I manually go and say the first value in my vector is for this cell and the second is for this other cell and so on. OR instead of even saying all the amount of data, is there a way to only return and save the values at specified location and cell?
Community: FEniCS Project

2 Answers


2
4 months ago by
If you just want the temperature at specific points, you can evaluate it directly, as in the following example:

from dolfin import *
mesh = UnitSquareMesh(10,10)
V = FunctionSpace(mesh,"Lagrange",1)

# Get some function with nontrivial values:
u = interpolate(Expression("sin(x[0])",degree=1),V)

# Evaluate it at a specified location:
specified_location = Point(0.1,0.2)
print(u(specified_location))
​
Just tried it and it worked. I can't thank you enough
written 4 months ago by Ashraf El Gaaly  
1
4 months ago by
I only know the syntax for C++, but you can also access/learn the mapping of the vector object (the dofs) to vertex locations, first by using:
mesh->coordinates();
This is an array of double pairs (for square mesh), which returns spatial location for each vertex number.  Thus, you learn the mapping of vertex numbering to spatial (physical) location.
Now, you secondly decode the  Vector().get_local() vector (dof) indices to vertex number above using:
vertex_to_dof_map(*V);
or vice-versa:
dof_to_vertex_map(*V);
If you search these terms you should find more information and/or the correct Python syntax.
Please login to add an answer/comment or follow this question.

Similar posts:
Search »