NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
NucMeshGeo.C
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 #include "NucMesh/NucMeshGeo.H"
30 
31 #include <unordered_set>
32 
33 #include <TopExp_Explorer.hxx>
34 #include <TopoDS_Compound.hxx>
35 #include <TopoDS_Shape.hxx>
36 
37 #include <SMESH_Gen.hxx>
38 #include <SMESH_Mesh.hxx>
39 #include <StdMeshers_Adaptive1D.hxx>
40 #include <StdMeshers_MEFISTO_2D.hxx>
41 #include <StdMeshers_Regular_1D.hxx>
42 
44 
45 namespace NEM {
46 namespace NUCMESH {
47 
48 std::unique_ptr<SMESH_Mesh> NucMeshGeo::computeMesh(SMESH_Gen &generator) {
49  std::unique_ptr<SMESH_Mesh> mesh{generator.CreateMesh(false)};
50  std::vector<std::unique_ptr<SMESH_Hypothesis>> hypotheses;
51  auto compound = this->buildCompound();
52  mesh->ShapeToMesh(compound);
53  {
54  auto edgeAlgId = generator.GetANewId();
55  hypotheses.emplace_back(new StdMeshers_Regular_1D{edgeAlgId, &generator});
56  mesh->AddHypothesis(compound, edgeAlgId);
57  auto edgeHypId = generator.GetANewId();
58  hypotheses.emplace_back(
59  new StdMeshers_Adaptive1D{edgeHypId, &generator});
60  mesh->AddHypothesis(compound, edgeHypId);
61  }
62  {
63  auto faceAlgId = generator.GetANewId();
64  hypotheses.emplace_back(new StdMeshers_MEFISTO_2D{faceAlgId, &generator});
65  mesh->AddHypothesis(compound, faceAlgId);
66  }
67  std::unordered_set<TopoDS_Shape, ShapeMapHasher_Hash, ShapeMapHasher_KeyEqual>
68  generated_shapes;
69  for (auto &shape : map_) {
70  if (!isChild(shape.first)) {
71  static constexpr std::array<TopAbs_ShapeEnum, 4> shapeTypes{
72  TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID};
73  for (auto &shapeType : shapeTypes) {
74  for (TopExp_Explorer explorer{shape.first, shapeType}; explorer.More();
75  explorer.Next()) {
76  auto &subShape = explorer.Current();
77  auto findIter = map_.find(subShape);
78  if (findIter != map_.end() &&
79  generated_shapes.find(subShape) == generated_shapes.end()) {
80  if (auto nmData =
81  dynamic_cast<NucMeshShapeData *>(findIter->second.get())) {
82  nmData->setupAlgos(explorer.Current(), generator, *mesh,
83  hypotheses);
84  }
85  generated_shapes.emplace(subShape);
86  }
87  }
88  }
89  }
90  }
91  generator.Compute(*mesh, compound);
92  return mesh;
93 }
94 
95 } // namespace NUCMESH
96 } // namespace NEM
static constexpr auto shapeType
Definition: NucMeshJson.H:81
bool isChild(const TopoDS_Shape &shape) const
Definition: GeoManager.C:190
std::shared_ptr< meshBase > mesh
std::unique_ptr< SMESH_Mesh > computeMesh(SMESH_Gen &generator)
Construct a mesh using the shapes in the map and their ShapeData.
Definition: NucMeshGeo.C:48
TopoDS_Compound buildCompound() const
Create a compound from shapes present in the map that have same dimension as the instance.
Definition: GeoManager.C:145