Commit 4463c437 authored by Christophe Geuzaine's avatar Christophe Geuzaine

new getElementProperties api to get name, dimension, order, etc. for a given element type

parent 9b001f1d
Pipeline #1194 passed with stage
in 35 minutes 31 seconds
This diff is collapsed.
......@@ -137,9 +137,12 @@ mesh.add('getLastVertexError',doc,None,ovectorint('vertexTags'))
doc = '''Gets the mesh vertices of the entity of dimension `dim' and `tag' tag. If `tag' < 0, gets the vertices for all entities of dimension `dim'. If `dim' and `tag' are negative, gets all the vertices in the mesh. `vertexTags' contains the vertex tags (their unique, strictly positive identification numbers). `coord' is a vector of length 3 times the length of `vertexTags' that contains the (x, y, z) coordinates of the vertices, concatenated. If `dim' >= 0, `parametricCoord' contains the parametric coordinates of the vertices, if available. The length of `parametricCoord' can be 0 or `dim' times the length of `vertexTags'.'''
mesh.add('getVertices',doc,None,ovectorint('vertexTags'),ovectordouble('coord'),ovectordouble('parametricCoord'),iint('dim', '-1'),iint('tag', '-1'))
doc = '''Gets the mesh elements of the entity of dimension `dim' and `tag' tag. If `tag' < 0, gets the elements for all entities of dimension `dim'. If `dim' and `tag' are negative, gets all the elements in the mesh. `elementTypes' contains the MSH types of the elements (e.g. `2' for 3-node triangles: see the Gmsh reference manual). `elementTags' is a vector of the same length as `elementTypes'; each entry is a vector containing the tags (unique, strictly positive identifiers) of the elements of the corresponding type. `vertexTags' is also a vector of the same length as `elementTypes'; each entry is a vector of length equal to the number of elements of the given type times the number of vertices for this type of element, that contains the vertex tags of all the elements of the given type, concatenated.'''
doc = '''Gets the mesh elements of the entity of dimension `dim' and `tag' tag. If `tag' < 0, gets the elements for all entities of dimension `dim'. If `dim' and `tag' are negative, gets all the elements in the mesh. `elementTypes' contains the MSH types of the elements (e.g. `2' for 3-node triangles); the `getElementInfo' function can be used to get information about these types. `elementTags' is a vector of the same length as `elementTypes'; each entry is a vector containing the tags (unique, strictly positive identifiers) of the elements of the corresponding type. `vertexTags' is also a vector of the same length as `elementTypes'; each entry is a vector of length equal to the number of elements of the given type times the number of vertices for this type of element, that contains the vertex tags of all the elements of the given type, concatenated.'''
mesh.add('getElements',doc,None,ovectorint('elementTypes'),ovectorvectorint('elementTags'),ovectorvectorint('vertexTags'),iint('dim', '-1'),iint('tag', '-1'))
doc = '''Gets the properties of an element of type `elementType': its name (`elementName'), dimension (`dim'), order (`order'), number of vertices (`numVertices') and parametric coordinates of vertices (`parametricCoord' vector, of length `dim' times `numVertices').'''
mesh.add('getElementProperties',doc,None,iint('elementType'),ostring('elementName'),oint('dim'),oint('order'),oint('numVertices'),ovectordouble('parametricCoord'))
doc = '''Gets the integration data for mesh elements of the entity of dimension `dim' and `tag' tag. The data is returned by element type and by element, in the same order as the data returned by `getElements'. `integrationType' specifies the type of integration (e.g. \"Gauss4\") and `functionSpaceType' specifies the function space (e.g. \"IsoParametric\"). `integrationPoints' contains for each element type a vector (of length 4 times the number of integration points) containing the parametric coordinates (u, v, w) and the weight associated to the integration points. `integrationData' contains for each element type a vector (of size 13 times the number of integration points) containing the (x, y, z) coordinates of the integration point, the determinant of the Jacobian and the 9 entries (by row) of the 3x3 Jacobian matrix. If `functionSpaceType' is provided, `functionSpaceNumComponents' returns the number of components returned by the evaluation of a basis function in the space and `functionSpaceData' contains for each element type the evaluation of the basis functions at the integration points.'''
mesh.add('getIntegrationData',doc,None,istring('integrationType'),istring('functionSpaceType'),ovectorvectordouble('integrationPoints'),ovectorvectordouble('integrationData'),oint('functionSpaceNumComponents'),ovectorvectordouble('functionSpaceData'),iint('dim', '-1'),iint('tag', '-1'))
......
......@@ -234,20 +234,32 @@ namespace gmsh { // Top-level functions
// Gets the mesh elements of the entity of dimension `dim' and `tag' tag. If
// `tag' < 0, gets the elements for all entities of dimension `dim'. If `dim'
// and `tag' are negative, gets all the elements in the mesh. `elementTypes'
// contains the MSH types of the elements (e.g. `2' for 3-node triangles: see
// the Gmsh reference manual). `elementTags' is a vector of the same length
// as `elementTypes'; each entry is a vector containing the tags (unique,
// strictly positive identifiers) of the elements of the corresponding type.
// `vertexTags' is also a vector of the same length as `elementTypes'; each
// entry is a vector of length equal to the number of elements of the given
// type times the number of vertices for this type of element, that contains
// the vertex tags of all the elements of the given type, concatenated.
// contains the MSH types of the elements (e.g. `2' for 3-node triangles);
// the `getElementInfo' function can be used to get information about these
// types. `elementTags' is a vector of the same length as `elementTypes';
// each entry is a vector containing the tags (unique, strictly positive
// identifiers) of the elements of the corresponding type. `vertexTags' is
// also a vector of the same length as `elementTypes'; each entry is a vector
// of length equal to the number of elements of the given type times the
// number of vertices for this type of element, that contains the vertex tags
// of all the elements of the given type, concatenated.
GMSH_API void getElements(std::vector<int> & elementTypes,
std::vector<std::vector<int> > & elementTags,
std::vector<std::vector<int> > & vertexTags,
const int dim = -1,
const int tag = -1);
// Gets the properties of an element of type `elementType': its name
// (`elementName'), dimension (`dim'), order (`order'), number of vertices
// (`numVertices') and parametric coordinates of vertices (`parametricCoord'
// vector, of length `dim' times `numVertices').
GMSH_API void getElementProperties(const int elementType,
std::string & elementName,
int & dim,
int & order,
int & numVertices,
std::vector<double> & parametricCoord);
// Gets the integration data for mesh elements of the entity of dimension
// `dim' and `tag' tag. The data is returned by element type and by element,
// in the same order as the data returned by `getElements'. `integrationType'
......
......@@ -782,14 +782,15 @@ class model:
Gets the mesh elements of the entity of dimension `dim' and `tag' tag. If
`tag' < 0, gets the elements for all entities of dimension `dim'. If `dim'
and `tag' are negative, gets all the elements in the mesh. `elementTypes'
contains the MSH types of the elements (e.g. `2' for 3-node triangles: see
the Gmsh reference manual). `elementTags' is a vector of the same length as
`elementTypes'; each entry is a vector containing the tags (unique,
strictly positive identifiers) of the elements of the corresponding type.
`vertexTags' is also a vector of the same length as `elementTypes'; each
entry is a vector of length equal to the number of elements of the given
type times the number of vertices for this type of element, that contains
the vertex tags of all the elements of the given type, concatenated.
contains the MSH types of the elements (e.g. `2' for 3-node triangles); the
`getElementInfo' function can be used to get information about these types.
`elementTags' is a vector of the same length as `elementTypes'; each entry
is a vector containing the tags (unique, strictly positive identifiers) of
the elements of the corresponding type. `vertexTags' is also a vector of
the same length as `elementTypes'; each entry is a vector of length equal
to the number of elements of the given type times the number of vertices
for this type of element, that contains the vertex tags of all the elements
of the given type, concatenated.
return elementTypes, elementTags, vertexTags
"""
......@@ -813,6 +814,41 @@ class model:
_ovectorvectorint(api_elementTags_,api_elementTags_n_,api_elementTags_nn_),
_ovectorvectorint(api_vertexTags_,api_vertexTags_n_,api_vertexTags_nn_))
@staticmethod
def getElementProperties(elementType):
"""
Gets the properties of an element of type `elementType': its name
(`elementName'), dimension (`dim'), order (`order'), number of vertices
(`numVertices') and parametric coordinates of vertices (`parametricCoord'
vector, of length `dim' times `numVertices').
return elementName, dim, order, numVertices, parametricCoord
"""
api_elementName_ = c_char_p()
api_dim_ = c_int()
api_order_ = c_int()
api_numVertices_ = c_int()
api_parametricCoord_, api_parametricCoord_n_ = POINTER(c_double)(), c_size_t()
ierr = c_int()
lib.gmshModelMeshGetElementProperties(
c_int(elementType),
byref(api_elementName_),
byref(api_dim_),
byref(api_order_),
byref(api_numVertices_),
byref(api_parametricCoord_),byref(api_parametricCoord_n_),
byref(ierr))
if ierr.value != 0 :
raise ValueError(
"gmshModelMeshGetElementProperties returned non-zero error code : ",
ierr.value)
return (
_ostring(api_elementName_),
api_dim_.value,
api_order_.value,
api_numVertices_.value,
_ovectordouble(api_parametricCoord_,api_parametricCoord_n_.value))
@staticmethod
def getIntegrationData(integrationType,functionSpaceType,dim=-1,tag=-1):
"""
......
......@@ -358,6 +358,17 @@ void gmshModelMeshGetElements(int ** elementTypes, size_t * elementTypes_n,int *
} catch(int api_ierr_) {if (ierr) *ierr = api_ierr_;}
}
void gmshModelMeshGetElementProperties(const int elementType,char ** elementName,int * dim,int * order,int * numVertices,double ** parametricCoord, size_t * parametricCoord_n,int * ierr){
if(ierr) *ierr = 0;
try {
std::string api_elementName_;
std::vector<double> api_parametricCoord_;
gmsh::model::mesh::getElementProperties(elementType,api_elementName_,*dim,*order,*numVertices,api_parametricCoord_);
*elementName = _strdup(api_elementName_.c_str());
vector2ptr(api_parametricCoord_,parametricCoord,parametricCoord_n);
} catch(int api_ierr_) {if (ierr) *ierr = api_ierr_;}
}
void gmshModelMeshGetIntegrationData(const char * integrationType,const char * functionSpaceType,double *** integrationPoints, size_t ** integrationPoints_n, size_t *integrationPoints_nn,double *** integrationData, size_t ** integrationData_n, size_t *integrationData_nn,int * functionSpaceNumComponents,double *** functionSpaceData, size_t ** functionSpaceData_n, size_t *functionSpaceData_nn,const int dim,const int tag,int * ierr){
if(ierr) *ierr = 0;
try {
......
......@@ -247,14 +247,15 @@ GMSH_API void gmshModelMeshGetVertices(int ** vertexTags, size_t * vertexTags_n,
/* Gets the mesh elements of the entity of dimension `dim' and `tag' tag. If
* `tag' < 0, gets the elements for all entities of dimension `dim'. If `dim'
* and `tag' are negative, gets all the elements in the mesh. `elementTypes'
* contains the MSH types of the elements (e.g. `2' for 3-node triangles: see
* the Gmsh reference manual). `elementTags' is a vector of the same length as
* `elementTypes'; each entry is a vector containing the tags (unique,
* strictly positive identifiers) of the elements of the corresponding type.
* `vertexTags' is also a vector of the same length as `elementTypes'; each
* entry is a vector of length equal to the number of elements of the given
* type times the number of vertices for this type of element, that contains
* the vertex tags of all the elements of the given type, concatenated. */
* contains the MSH types of the elements (e.g. `2' for 3-node triangles); the
* `getElementInfo' function can be used to get information about these types.
* `elementTags' is a vector of the same length as `elementTypes'; each entry
* is a vector containing the tags (unique, strictly positive identifiers) of
* the elements of the corresponding type. `vertexTags' is also a vector of
* the same length as `elementTypes'; each entry is a vector of length equal
* to the number of elements of the given type times the number of vertices
* for this type of element, that contains the vertex tags of all the elements
* of the given type, concatenated. */
GMSH_API void gmshModelMeshGetElements(int ** elementTypes, size_t * elementTypes_n,
int *** elementTags, size_t ** elementTags_n, size_t *elementTags_nn,
int *** vertexTags, size_t ** vertexTags_n, size_t *vertexTags_nn,
......@@ -262,6 +263,18 @@ GMSH_API void gmshModelMeshGetElements(int ** elementTypes, size_t * elementType
const int tag,
int * ierr);
/* Gets the properties of an element of type `elementType': its name
* (`elementName'), dimension (`dim'), order (`order'), number of vertices
* (`numVertices') and parametric coordinates of vertices (`parametricCoord'
* vector, of length `dim' times `numVertices'). */
GMSH_API void gmshModelMeshGetElementProperties(const int elementType,
char ** elementName,
int * dim,
int * order,
int * numVertices,
double ** parametricCoord, size_t * parametricCoord_n,
int * ierr);
/* Gets the integration data for mesh elements of the entity of dimension
* `dim' and `tag' tag. The data is returned by element type and by element,
* in the same order as the data returned by `getElements'. `integrationType'
......
......@@ -32,6 +32,13 @@ int main(int argc, char **argv)
int numElem = 0;
for(unsigned int i = 0; i < elemTags.size(); i++)
numElem += elemTags[i].size();
for(unsigned int i = 0; i < elemTypes.size(); i++){
std::string name;
int d, order, numv;
std::vector<double> param;
gmsh::model::mesh::getElementProperties(elemTypes[i], name, d, order, numv, param);
std::cout << "found " << name << " on entity (" << dim << "," << tag << ")\n";
}
std::cout << vertexTags.size() << " mesh vertices and "
<< numElem << " mesh elements on entity ("
<< dim << "," << tag << ")\n";
......
......@@ -19,6 +19,9 @@ for e in entities:
elemTypes, elemTags, elemVertexTags = gmsh.model.mesh.getElements(e[0], e[1])
# report some statistics
numElem = sum(len(i) for i in elemTags)
for t in elemTypes:
name, dim, order, numv, _ = gmsh.model.mesh.getElementProperties(t)
print "found " + name + " on entity " + str(e)
print str(len(vertexTags)) + " mesh vertices " + str(numElem),\
"mesh elements on entity " + str(e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment