Commit fa5af45b authored by Christophe Geuzaine's avatar Christophe Geuzaine

little api to reclassify mesh vertices on entities (to make importing meshes easier)

parent 927a4567
Pipeline #1218 passed with stage
in 35 minutes and 38 seconds
......@@ -848,6 +848,12 @@ void gmsh::model::mesh::setVertices(const int dim, const int tag,
}
}
void gmsh::model::mesh::reclassifyVertices()
{
if(!_isInitialized()){ throw -1; }
GModel::current()->pruneMeshVertexAssociations();
}
template<class T>
static void _addElements(int dim, int tag, const std::vector<MElement*> &src,
std::vector<T*> &dst)
......
......@@ -1451,7 +1451,6 @@ int GModel::deleteMeshPartitions()
#endif
}
int GModel::partitionMesh(int numPart)
{
#if defined(HAVE_MESH) && (defined(HAVE_METIS))
......@@ -1624,10 +1623,9 @@ void GModel::_createGeometryOfDiscreteEntities(bool force)
void GModel::_associateEntityWithMeshVertices()
{
// loop on regions, then on faces, edges and vertices and store the
// entity pointer in the the elements' vertices (this way we
// associate the entity of lowest geometrical degree with each
// vertex)
// loop on regions, then on faces, edges and vertices and store the entity
// pointer in the the elements' vertices (this way we associate the entity of
// lowest geometrical degree with each vertex)
for(riter it = firstRegion(); it != lastRegion(); ++it){
_associateEntityWithElementVertices(*it, (*it)->tetrahedra);
_associateEntityWithElementVertices(*it, (*it)->hexahedra);
......
......@@ -10,8 +10,6 @@
#include "Numeric.h"
#include "Context.h"
#define SQU(a) ((a)*(a))
static void InterpolateCatmullRom(Vertex *v[4], double t, Vertex &V)
{
V.lc = (1 - t) * v[1]->lc + t * v[2]->lc;
......@@ -620,13 +618,16 @@ static Vertex TransfiniteTriB(Vertex c1, Vertex c1b, Vertex c2,
return V;
}
#define SQU(a) ((a)*(a))
static void TransfiniteSph(Vertex S, Vertex center, Vertex *T)
{
double r = sqrt(SQU(S.Pos.X - center.Pos.X) + SQU(S.Pos.Y - center.Pos.Y)
+ SQU(S.Pos.Z - center.Pos.Z));
double s = sqrt(SQU(T->Pos.X - center.Pos.X) + SQU(T->Pos.Y - center.Pos.Y)
+ SQU(T->Pos.Z - center.Pos.Z));
double r = sqrt(SQU(S.Pos.X - center.Pos.X) +
SQU(S.Pos.Y - center.Pos.Y) +
SQU(S.Pos.Z - center.Pos.Z));
double s = sqrt(SQU(T->Pos.X - center.Pos.X) +
SQU(T->Pos.Y - center.Pos.Y) +
SQU(T->Pos.Z - center.Pos.Z));
double dirx = (T->Pos.X - center.Pos.X) / s;
double diry = (T->Pos.Y - center.Pos.Y) / s;
......@@ -902,10 +903,10 @@ Vertex InterpolateSurface(Surface *s, double u, double v, int derivee, int u_v)
return Vertex(p.x(), p.y(), p.z());
}
// Warning: we use the exact extrusion formula so we can create
// exact surfaces of revolution. This WILL fail if the surface is
// transformed after the extrusion: in that case set the
// exactExtrusion option to 0 to use the normal code path
// Warning: we use the exact extrusion formula so we can create exact surfaces
// of revolution. This WILL fail if the surface is transformed after the
// extrusion: in that case set the exactExtrusion option to 0 to use the
// normal code path
if(CTX::instance()->geom.exactExtrusion && s->Extrude &&
s->Extrude->geo.Mode == EXTRUDED_ENTITY && s->Typ != MSH_SURF_PLAN)
return InterpolateExtrudedSurface(s, u, v);
......
......@@ -161,6 +161,9 @@ mesh.add('setVertices',doc,None,iint('dim'),iint('tag'),ivectorint('vertexTags')
doc = '''Sets the mesh elements of the entity of dimension `dim' and `tag' tag. `types' 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 `types'; 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 `types'; each entry is a vector of length equal to the number of elements of the give type times the number of vertices per element, that contains the vertex tags of all the elements of the given type, concatenated.'''
mesh.add('setElements',doc,None,iint('dim'),iint('tag'),ivectorint('types'),ivectorvectorint('elementTags'),ivectorvectorint('vertexTags'))
doc = '''Redistribute all mesh vertices on their associated geometrical entity, based on the mesh elements. Can be used when importing mesh vertices in bulk (e.g. by associating them all to a single volume), to reclassify them correctly on model surfaces, curves, etc.'''
mesh.add('reclassifyVertices',doc,None)
doc = '''Gets the coordinates and the parametric coordinates (if any) of the mesh vertex with tag `tag'. This is a useful by inefficient way of accessing mesh vertex data, as it relies on a cache stored in the model. For large meshes all the vertices in the model should be numbered in a continuous sequence of tags from 1 to N to maintain reasonnable performance (in this case the internal cache is based on a vector; otherwise it uses a map).'''
mesh.add('getVertex',doc,None,iint('vertexTag'),ovectordouble('coord'),ovectordouble('parametricCoord'))
......
......@@ -234,15 +234,15 @@ 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);
// 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.
// contains the MSH types of the elements (e.g. `2' for 3-node triangles: see
// `getElementProperties' to obtain the properties for a given element type).
// `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,
......@@ -340,6 +340,12 @@ namespace gmsh { // Top-level functions
const std::vector<std::vector<int> > & elementTags,
const std::vector<std::vector<int> > & vertexTags);
// Redistribute all mesh vertices on their associated geometrical entity,
// based on the mesh elements. Can be used when importing mesh vertices in
// bulk (e.g. by associating them all to a single volume), to reclassify them
// correctly on model surfaces, curves, etc.
GMSH_API void reclassifyVertices();
// Gets the coordinates and the parametric coordinates (if any) of the mesh
// vertex with tag `tag'. This is a useful by inefficient way of accessing
// mesh vertex data, as it relies on a cache stored in the model. For large
......
......@@ -782,8 +782,8 @@ 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); the
`getElementInfo' function can be used to get information about these types.
contains the MSH types of the elements (e.g. `2' for 3-node triangles: see
`getElementProperties' to obtain the properties for a given element type).
`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
......@@ -1033,6 +1033,22 @@ class model:
"gmshModelMeshSetElements returned non-zero error code : ",
ierr.value)
@staticmethod
def reclassifyVertices():
"""
Redistribute all mesh vertices on their associated geometrical entity,
based on the mesh elements. Can be used when importing mesh vertices in
bulk (e.g. by associating them all to a single volume), to reclassify them
correctly on model surfaces, curves, etc.
"""
ierr = c_int()
lib.gmshModelMeshReclassifyVertices(
byref(ierr))
if ierr.value != 0 :
raise ValueError(
"gmshModelMeshReclassifyVertices returned non-zero error code : ",
ierr.value)
@staticmethod
def getVertex(vertexTag):
"""
......
......@@ -429,6 +429,13 @@ void gmshModelMeshSetElements(const int dim,const int tag,int * types, size_t ty
} catch(int api_ierr_) {if (ierr) *ierr = api_ierr_;}
}
void gmshModelMeshReclassifyVertices(int * ierr){
if(ierr) *ierr = 0;
try {
gmsh::model::mesh::reclassifyVertices();
} catch(int api_ierr_) {if (ierr) *ierr = api_ierr_;}
}
void gmshModelMeshGetVertex(const int vertexTag,double ** coord, size_t * coord_n,double ** parametricCoord, size_t * parametricCoord_n,int * ierr){
if(ierr) *ierr = 0;
try {
......
......@@ -247,8 +247,8 @@ 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); the
* `getElementInfo' function can be used to get information about these types.
* contains the MSH types of the elements (e.g. `2' for 3-node triangles: see
* `getElementProperties' to obtain the properties for a given element type).
* `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
......@@ -360,6 +360,12 @@ GMSH_API void gmshModelMeshSetElements(const int dim,
const int ** vertexTags, const size_t * vertexTags_n, size_t vertexTags_nn,
int * ierr);
/* Redistribute all mesh vertices on their associated geometrical entity,
* based on the mesh elements. Can be used when importing mesh vertices in
* bulk (e.g. by associating them all to a single volume), to reclassify them
* correctly on model surfaces, curves, etc. */
GMSH_API void gmshModelMeshReclassifyVertices(int * ierr);
/* Gets the coordinates and the parametric coordinates (if any) of the mesh
* vertex with tag `tag'. This is a useful by inefficient way of accessing
* mesh vertex data, as it relies on a cache stored in the model. For large
......
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