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.
NucMeshShapeData.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 *******************************************************************************/
30 
31 #include <SMESHDS_GroupBase.hxx>
32 #include <SMESHDS_GroupOnFilter.hxx>
33 #include <SMESHDS_GroupOnGeom.hxx>
34 #include <SMESH_ControlsDef.hxx>
35 #include <SMESH_Gen.hxx>
36 #include <SMESH_Group.hxx>
37 #include <SMESH_HypoFilter.hxx>
38 #include <SMESH_Mesh.hxx>
39 #include <StdMeshers_NumberOfSegments.hxx>
40 #include <StdMeshers_Quadrangle_2D.hxx>
41 #include <StdMeshers_Regular_1D.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <TopoDS_Shape.hxx>
44 #ifdef HAVE_NGEN
45 # include <NETGENPlugin_NETGEN_2D_ONLY.hxx>
46 # include <StdMeshers_QuadranglePreference.hxx>
47 #else
48 # include <iostream>
49 #endif
50 
51 #include "Mesh/smeshUtils.H"
52 
53 namespace NEM {
54 namespace NUCMESH {
55 
57  const TopoDS_Shape &shape, SMESH_Gen &generator, SMESH_Mesh &mesh,
58  std::vector<std::unique_ptr<SMESH_Hypothesis>> &generatedHyps) const {
59  if (!groupName.empty()) {
60  bool addedToGroup = false;
61  int oldGroup = -1;
62  bool removeOldGroup = false;
63  for (auto group : NEM::MSH::containerWrapper(mesh.GetGroups())) {
64  auto groupDS = group->GetGroupDS();
65  if (groupName == group->GetName() && groupDS &&
66  type == group->GetGroupDS()->GetType()) {
67  if (auto otherGeomGroup =
68  dynamic_cast<SMESHDS_GroupOnGeom *>(groupDS)) {
69  auto otherPred = boost::make_shared<SMESH::Controls::BelongToGeom>();
70  otherPred->SetGeom(otherGeomGroup->GetShape());
71  otherPred->SetType(type);
72  auto thisPred = boost::make_shared<SMESH::Controls::BelongToGeom>();
73  thisPred->SetGeom(shape);
74  thisPred->SetType(type);
75  auto disjunction = boost::make_shared<SMESH::Controls::LogicalOR>();
76  disjunction->SetPredicate1(otherPred);
77  disjunction->SetPredicate2(thisPred);
78  mesh.AddGroup(type, groupName.c_str(), -1, TopoDS_Shape{},
79  disjunction);
80  addedToGroup = true;
81  oldGroup = group->GetID();
82  removeOldGroup = true;
83  break;
84  } else if (auto otherFilterGroup =
85  dynamic_cast<SMESHDS_GroupOnFilter *>(groupDS)) {
86  auto otherPred = otherFilterGroup->GetPredicate();
87  auto thisPred = boost::make_shared<SMESH::Controls::BelongToGeom>();
88  thisPred->SetGeom(shape);
89  thisPred->SetType(type);
90  auto disjunction = boost::make_shared<SMESH::Controls::LogicalOR>();
91  disjunction->SetPredicate1(otherPred);
92  disjunction->SetPredicate2(thisPred);
93  otherFilterGroup->SetPredicate(disjunction);
94  addedToGroup = true;
95  break;
96  }
97  }
98  }
99  if (!addedToGroup) { mesh.AddGroup(type, groupName.c_str(), -1, shape); }
100  if (removeOldGroup && oldGroup >= 0) { mesh.RemoveGroup(oldGroup); }
101  }
102 }
103 
104 EdgeSegments::EdgeSegments(std::string groupName, int numSegments)
105  : CRTPBase(std::move(groupName)), numSegments_(numSegments) {}
106 
108  const TopoDS_Shape &shape, SMESH_Gen &generator, SMESH_Mesh &mesh,
109  std::vector<std::unique_ptr<SMESH_Hypothesis>> &generatedHyps) const {
110  this->SideSetEdge::setupAlgos(shape, generator, mesh, generatedHyps);
111  auto hypId = generator.GetANewId();
112  auto hypothesis = new StdMeshers_NumberOfSegments{hypId, &generator};
113  hypothesis->SetNumberOfSegments(numSegments_);
114  generatedHyps.emplace_back(hypothesis);
115  mesh.AddHypothesis(shape, hypId);
116  std::list<const SMESHDS_Hypothesis *> algos;
117  SMESH_HypoFilter filter(SMESH_HypoFilter::IsAlgo());
118  filter.And(SMESH_HypoFilter::IsApplicableTo(shape));
119  mesh.GetHypotheses(mesh.GetShapeToMesh(), filter, algos, false);
120  int algoId = -1;
121  for (auto &hyp : algos) {
122  if (auto algo = dynamic_cast<const SMESH_Algo *>(hyp)) {
123  // The method is not virtual, and doesn't allow us to modify algo, so
124  // const_cast should be safe
125  auto allowed_hyps =
126  const_cast<SMESH_Algo *>(algo)->GetCompatibleHypothesis();
127  if (std::find(allowed_hyps.begin(), allowed_hyps.end(),
128  hypothesis->GetName()) != allowed_hyps.end()) {
129  algoId = algo->GetID();
130  }
131  }
132  }
133  if (algoId < 0) {
134  algoId = generator.GetANewId();
135  auto algo = new StdMeshers_Regular_1D{algoId, &generator};
136  generatedHyps.emplace_back(algo);
137  }
138  mesh.AddHypothesis(shape, algoId);
139 }
140 
142  const TopoDS_Shape &shape, SMESH_Gen &generator, SMESH_Mesh &mesh,
143  std::vector<std::unique_ptr<SMESH_Hypothesis>> &generatedHyps) const {
144  this->GroupData::setupAlgos(shape, generator, mesh, generatedHyps);
145 }
146 
148  const TopoDS_Shape &shape, SMESH_Gen &generator, SMESH_Mesh &mesh,
149  std::vector<std::unique_ptr<SMESH_Hypothesis>> &generatedHyps) const {
150  this->GroupData::setupAlgos(shape, generator, mesh, generatedHyps);
151  int numEdges = 0;
152  for (TopExp_Explorer explorer{shape, TopAbs_EDGE}; explorer.More();
153  explorer.Next()) {
154  ++numEdges;
155  }
156  if (numEdges == 4) {
157  auto algId = generator.GetANewId();
158  auto alg = new StdMeshers_Quadrangle_2D{algId, &generator};
159  mesh.AddHypothesis(shape, algId);
160  generatedHyps.emplace_back(alg);
161  } else {
162 #ifdef HAVE_NGEN
163  auto algId = generator.GetANewId();
164  auto alg = new NETGENPlugin_NETGEN_2D_ONLY{algId, &generator};
165  mesh.AddHypothesis(shape, algId);
166  generatedHyps.emplace_back(alg);
167  auto hypId = generator.GetANewId();
168  auto hyp = new StdMeshers_QuadranglePreference{hypId, &generator};
169  mesh.AddHypothesis(shape, hypId);
170  generatedHyps.emplace_back(hyp);
171 #else
172  std::cerr << "Cannot generate quad-dominant mesh on general faces "
173  "without Netgen\n";
174 #endif
175  }
176 }
177 
178 } // namespace NUCMESH
179 } // namespace NEM
void setupAlgos(const TopoDS_Shape &shape, SMESH_Gen &generator, SMESH_Mesh &mesh, std::vector< std::unique_ptr< SMESH_Hypothesis >> &generatedHyps) const override
Method that is called when a GeoManager instance tries to mesh shape.
SMDSAbs_ElementType type
void setupAlgos(const TopoDS_Shape &shape, SMESH_Gen &generator, SMESH_Mesh &mesh, std::vector< std::unique_ptr< SMESH_Hypothesis >> &generatedHyps) const override
Method that is called when a GeoManager instance tries to mesh shape.
void setupAlgos(const TopoDS_Shape &shape, SMESH_Gen &generator, SMESH_Mesh &mesh, std::vector< std::unique_ptr< SMESH_Hypothesis >> &generatedHyps) const override
Method that is called when a GeoManager instance tries to mesh shape.
STL namespace.
EdgeSegments(std::string groupName, int numSegments)
void setupAlgos(const TopoDS_Shape &shape, SMESH_Gen &generator, SMESH_Mesh &mesh, std::vector< std::unique_ptr< SMESH_Hypothesis >> &generatedHyps) const override
Method that is called when a GeoManager instance tries to mesh shape.
std::shared_ptr< meshBase > mesh
void setupAlgos(const TopoDS_Shape &shape, SMESH_Gen &generator, SMESH_Mesh &mesh, std::vector< std::unique_ptr< SMESH_Hypothesis >> &generatedHyps) const override
Method that is called when a GeoManager instance tries to mesh shape.
SM_StdContainerWrapperFromIter< typename std::decay< PtrSMDSIterator >::type, VALUE, EqualVALUE > containerWrapper(PtrSMDSIterator &&iter)
Definition: smeshUtils.H:57