30 #include <gmsh/Context.h> 31 #include <gmsh/CreateFile.h> 32 #include <gmsh/MHexahedron.h> 33 #include <gmsh/MLine.h> 34 #include <gmsh/MPoint.h> 35 #include <gmsh/MPrism.h> 36 #include <gmsh/MPyramid.h> 37 #include <gmsh/MQuadrangle.h> 38 #include <gmsh/MTetrahedron.h> 39 #include <gmsh/MTriangle.h> 43 #include <vtkIdList.h> 44 #include <vtkUnstructuredGrid.h> 49 GModel::_storeElementsInEntities(map);
53 GModel::_associateEntityWithMeshVertices(force);
57 GModel::_storeVerticesInEntities(vertices);
61 int dim, std::map<
int, std::map<int, std::string>> &map) {
62 GModel::_storePhysicalTagsInEntities(dim, map);
69 std::cout <<
"gmshMesh constructed" << std::endl;
79 numPoints = dataSet->GetNumberOfPoints();
80 numCells = dataSet->GetNumberOfCells();
81 std::cout <<
"Number of points: " << numPoints << std::endl;
82 std::cout <<
"Number of cells: " << numCells << std::endl;
83 std::cout <<
"gmshMesh constructed" << std::endl;
89 std::cout <<
"gmshMesh destroyed" << std::endl;
96 std::cout <<
"gmshMesh constructed" << std::endl;
101 GModel _gmshGModel = GModel();
102 _gmshGModel.load(fname);
104 vtkSmartPointer<vtkUnstructuredGrid> dataSet_tmp =
108 std::vector<GEntity *> entities;
109 _gmshGModel.getEntities(entities);
115 std::map<long int, vtkIdType> gmshIndex2vtkId;
116 for (
const auto &entity : entities)
117 for (
const auto &mesh_vertex : entity->mesh_vertices) {
120 gmshIndex2vtkId[mesh_vertex->getIndex()] = points->GetNumberOfPoints();
122 points->InsertNextPoint(mesh_vertex->point());
140 dataSet_tmp->SetPoints(points);
143 std::size_t numMeshElements = 0;
144 for (
const auto &entity : entities)
145 numMeshElements += entity->getNumMeshElements();
146 dataSet_tmp->Allocate(numMeshElements);
149 const char **typeName =
nullptr;
150 std::vector<const char **> unsupportedTypesList{};
151 std::size_t numUnsupportedElements = 0;
152 for (
const auto &entity : entities) {
153 for (
int j = 0; j != entity->getNumMeshElements(); ++j) {
155 if (entity->getMeshElement(j)->getTypeForVTK()) {
158 idList->Allocate(entity->getMeshElement(j)->getNumVertices());
160 for (std::size_t k = 0;
161 k != entity->getMeshElement(j)->getNumVertices(); ++k)
162 idList->InsertNextId(
166 [entity->getMeshElement(j)->getVertex(k)->getIndex()]);
168 dataSet_tmp->InsertNextCell(entity->getMeshElement(j)->getTypeForVTK(),
171 ++numUnsupportedElements;
172 MElement::getInfoMSH(entity->getMeshElement(j)->getTypeForMSH(),
174 unsupportedTypesList.emplace_back(typeName);
179 if (numUnsupportedElements) {
180 std::cerr <<
"WARNING: " << numUnsupportedElements
181 <<
" unsupported Gmsh elements detected of the following types:";
182 for (
const auto &unsupportedType : unsupportedTypesList) {
183 std::cerr <<
" \"" << unsupportedType <<
"\"";
185 std::cerr << std::endl;
192 dataSet = dataSet_tmp;
194 numPoints = dataSet->GetNumberOfPoints();
195 numCells = dataSet->GetNumberOfCells();
196 std::cout <<
"Number of points: " << numPoints << std::endl;
197 std::cout <<
"Number of cells: " << numCells << std::endl;
200 write(fname, 4.1,
false);
208 std::vector<MVertex *> vertices(numPoints);
211 for (
nemId_t i = 0; i != numPoints; ++i) {
212 dataSet->GetPoint(i, xyz);
213 vertices[i] =
new MVertex(xyz[0], xyz[1], xyz[2]);
217 std::map<int, std::vector<MElement *>> elements[8];
219 for (
nemId_t i = 0; i != numCells; ++i) {
222 int type = dataSet->GetCellType(i);
224 dataSet->GetCellPoints(i, idList);
226 std::vector<MVertex *> cell(idList->GetNumberOfIds());
227 for (vtkIdType j = 0; j != idList->GetNumberOfIds(); ++j) {
228 cell[j] = vertices[idList->GetId(j)];
235 elements[0][1].push_back(
new MPoint(cell));
239 elements[1][1].push_back(
new MLine(cell));
242 elements[2][1].push_back(
new MTriangle(cell));
245 elements[3][1].push_back(
new MQuadrangle(cell));
248 elements[4][1].push_back(
new MTetrahedron(cell));
251 elements[5][1].push_back(
new MHexahedron(cell));
254 elements[6][1].push_back(
new MPrism(cell));
257 elements[7][1].push_back(
new MPyramid(cell));
261 elements[1][1].push_back(
new MLine3(cell));
264 elements[2][1].push_back(
new MTriangle6(cell));
267 elements[3][1].push_back(
new MQuadrangle8(cell));
270 elements[3][1].push_back(
new MQuadrangle9(cell));
273 elements[4][1].push_back(
new MTetrahedron10(cell));
276 elements[5][1].push_back(
new MHexahedron20(cell));
279 elements[5][1].push_back(
new MHexahedron27(cell));
282 Msg::Error(
"Unknown type of cell %d", type);
289 for (
auto &&element : elements)
298 _nemosysGModel.renumberMeshVertices();
299 _nemosysGModel.renumberMeshElements();
309 _nemosysGModel.writeMSH(
310 fname, mshFileVersion, binary
313 std::cout <<
"gmshMesh saved to " << fname << std::endl;
317 return std::vector<double>();
320 return std::vector<std::vector<double>>();
323 return std::map<nemId_t, std::vector<double>>();
326 return std::vector<std::vector<double>>();
330 return vtkSmartPointer<vtkDataSet>();
333 return std::vector<double>();
336 return std::vector<double>();
340 return std::vector<nemId_t>();
std::vector< std::vector< double > > getCellVec(nemId_t id) const override
get vector of coords of cell with id
vtkSmartPointer< vtkDataSet > extractSurface() override
extract the surface mesh
std::vector< double > getCellLengths() const override
get diameter of circumsphere of each cell
int getCellType() const override
get cell type as an integer assumes all elements are the same type
std::vector< std::vector< double > > getVertCrds() const override
get 3 vecs with x,y and z coords
A brief description of meshBase.
void report() const override
generate a report of the mesh
void read(const std::string &fname)
abstract read method reserved for derived classes
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
void storeVerticesInEntities(std::vector< MVertex *> &vertices)
void storePhysicalTagsInEntities(int dim, std::map< int, std::map< int, std::string >> &map)
void inspectEdges(const std::string &ofname) const override
get edge lengths of dataSet
std::vector< double > getPoint(nemId_t id) const override
get point with id
vtkSmartPointer< vtkDataSet > getDataSet() const
get this meshes' dataSet
virtual void write() const
write the mesh to file named after the private var 'filename'.
std::map< nemId_t, std::vector< double > > getCell(nemId_t id) const override
get cell with id
std::vector< nemId_t > getConnectivities() const override
get connectivities.
std::vector< double > getCellCenter(nemId_t cellID) const override
get center of a cell
std::vector< vtkIdType > points
points given by id in .inp file
void storeElementsInEntities(std::map< int, std::vector< MElement *>> &map)
virtual void report() const
generate a report of the mesh
void associateEntityWithMeshVertices(bool force=false)