On 09/06/2012 10:11 AM, Alec Kalinin wrote:
Hello SfePy devels,
Could you, please, explain me some SfePy internals?
Sure!
(1) Question 1. Surface processing.
As I see in examples the 3D meshes contains only volume elements (tetrahedra) and no surface elements (triangles). But in problem solution pipeline we need to apply essential boundary conditions on surface nodes and need to evaluate some surface integrals, for example, for Neumann boundary conditions. How does SfePy working with surfaces?
Every integration occurs over a region, and every term "knows" whether it corresponds to a volume or surface integral or something else. So defining the regions is crucial here.
For essential boundary conditions, yes, we can take only the far nodes in tetrahedra. But for the surface integrals we need the surface elements -- triangles. Does SfePy extract boundary triangles from volume tetrahedra?
Yes - each region contains a set of vertices, and also the edges, face, and cells that are completely defined by the vertices in the region. So if a region contains just a single vertex of a face, that face is not a part of the region, if it contains all vertices of a face, that face belongs to the region.
Then the term chooses, depending on its integration kind (volume, surface, ...) the correct entities from the region.
(2) Question 2. Dimensions of the SfePy arrays.
Consider the postprocesing hook: def post_process(out, pb, state, extend = False): electric_field = pb.evaluate('ev_grad.2.Omega(u)', mode='el_avg') print electric_field.shape
flux = pb.evaluate('d_surface_flux.2.Gamma(m.K, u)', mode='el_avg') print flux.shape
In my example shapes are: electric_field: (5235, 1, 3, 1) flux: (3898, 1, 1, 1)
Could you explain me why the variables are 4-dimensional arrays. My understanding is following: the surface?
- 1st dimension is the number of the tetrahedra element. 5235 is the total number of the volume element. By what is 3898? Is it a number of the tetrahedra which are contains in boundary or is it a number of triangles on
It is the number of the entities of the region. If you integrate over a whole volume domain, it's the number of elements. If you integrate over a surface region, it's the number of faces.
Then, to save it for visualization, one usually wants to extend the data over the whole mesh...
- The 3d dimension is the dimension of variable. The grad is a 3 dimensional vector, the flux is a scalar. But what are the 2nd and 4th dimensions?
The scheme is (n_entities, n_qp, n_row, n_col) - n_qp = number of quadrature points = 1 if the value is integrated, >= 1 for 'qp' term evaluation mode. So it is an array of 2d tensors/matrices of shape (n_row, n_col) over all elements/faces/edges and quadrature points in a region. The same data structure (4d array) is used internally in the C term evaluation functions in sfepy/terms/extmods/
Does it help? Feel free to ask more!
r.