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.
NucMeshSrv.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 "Services/NucMeshSrv.H"
30 
31 #include <vtkInformation.h>
32 #include <vtkInformationVector.h>
33 
34 #include <SMESH_ControlsDef.hxx>
35 #include <SMESH_Group.hxx>
36 #include <SMESH_Mesh.hxx>
37 #include <SMESH_MeshEditor.hxx>
38 #include <SMESH_TypeDefs.hxx>
39 #include <SMESHDS_GroupBase.hxx>
40 #include <SMESHDS_Mesh.hxx>
41 
42 #include "Mesh/smeshGeoMesh.H"
43 #include "Mesh/smeshUtils.H"
44 #include "NucMesh/NucMeshGeo.H"
45 #include "NucMesh/ShapeBase.H"
46 
47 namespace NEM {
48 namespace SRV {
49 
51 
53  this->SetNumberOfInputPorts(0);
54  this->SetNumberOfOutputPorts(1);
55 }
56 
57 void NucMeshSrv::SetConfiguration(const NucMeshConf &configuration) {
58  conf_ = configuration;
59  this->Modified();
60 }
61 
63 
64 int NucMeshSrv::FillOutputPortInformation(int port, vtkInformation *info) {
65  if (port == 0) {
66  info->Set(vtkDataObject::DATA_TYPE_NAME(), "smeshGeoMesh");
67  return 1;
68  } else {
69  return 0;
70  }
71 }
72 
73 int NucMeshSrv::RequestData(vtkInformation *request,
74  vtkInformationVector **inputVector,
75  vtkInformationVector *outputVector) {
77  for (auto &pattern : conf_.geometryAndMesh) {
78  if (pattern) {
79  NEM::NUCMESH::ShapeBase::mergeGeo(geo, pattern->createGeo());
80  }
81  }
82  auto mesh = geo.computeMesh(*this->conf_.generator);
83  std::array<TIDSortedElemSet, 2> elems_nodes;
84  {
85  auto elemContainer =
86  NEM::MSH::containerWrapper(mesh->GetMeshDS()->elementsIterator());
87  std::copy(elemContainer.begin(), elemContainer.end(),
88  std::inserter(elems_nodes[0], elems_nodes[0].end()));
89  auto nodesContainer =
90  NEM::MSH::containerWrapper(mesh->GetMeshDS()->nodesIterator());
91  std::copy(nodesContainer.begin(), nodesContainer.end(),
92  std::inserter(elems_nodes[1], elems_nodes[1].end()));
93  }
94  if (!conf_.extrudeSteps.empty()) {
95  std::set<int> groupsToRemove;
96  // Remove all old face groups
97  for (auto group : NEM::MSH::containerWrapper(mesh->GetGroups())) {
98  if (group->GetGroupDS()->GetType() == SMDSAbs_Face) {
99  groupsToRemove.emplace(group->GetID());
100  }
101  }
102  const std::string bottomName = "Bottom";
103  mesh->AddGroup(SMDSAbs_Face, bottomName.c_str(), -1,
104  mesh->GetShapeToMesh());
105  Handle(TColStd_HSequenceOfReal)
106  extrudeStepsSeq{new TColStd_HSequenceOfReal{}};
107  for (const auto &step : conf_.extrudeSteps) {
108  extrudeStepsSeq->Append(step);
109  }
110  SMESH_MeshEditor::ExtrusParam extrusParam{
111  gp_Dir{gp_XYZ(0, 0, 1)}, extrudeStepsSeq,
112  SMESH_MeshEditor::EXTRUSION_FLAG_BOUNDARY |
113  SMESH_MeshEditor::EXTRUSION_FLAG_GROUPS};
114  SMESH_MeshEditor::TTElemOfElemListMap newElems;
115  SMESH_MeshEditor editor{mesh.get()};
116  auto newGroups =
117  editor.ExtrusionSweep(elems_nodes.data(), extrusParam, newElems);
118  for (auto &newGroupID : *newGroups) {
119  auto group = mesh->GetGroup(newGroupID);
120  auto type = group->GetGroupDS()->GetType();
121  if (type == SMDSAbs_Volume) {
122  // Remove "Bottom_extruded"
123  const std::string tempAllExtruded = bottomName + "_extruded";
124  if (tempAllExtruded.compare(0, tempAllExtruded.size(),
125  group->GetName()) == 0) {
126  groupsToRemove.emplace(group->GetID());
127  }
128  } else if (type == SMDSAbs_Face) {
129  const std::string tempAllTop = bottomName + "_top";
130  if (tempAllTop.compare(0, tempAllTop.size(), group->GetName()) == 0) {
131  group->SetName("Top");
132  } else {
133  std::string groupName = group->GetName();
134  const std::string suffix = "_top";
135  // If ends in _top, remove it (but keep the extruded side sets)
136  if (groupName.size() > suffix.size() &&
137  groupName.compare(groupName.size() - suffix.size(), suffix.size(),
138  suffix) == 0) {
139  groupsToRemove.emplace(group->GetID());
140  }
141  }
142  }
143  }
144  for (auto &groupID : groupsToRemove) { mesh->RemoveGroup(groupID); }
145  }
146 
147  MSH::smeshGeoMesh *output = MSH::smeshGeoMesh::SafeDownCast(
148  outputVector->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
149  output->setSMeshMesh(std::move(mesh), std::move(conf_.generator));
150  return 1;
151 }
152 
153 } // namespace SRV
154 } // namespace NEM
std::vector< std::shared_ptr< NEM::NUCMESH::ShapeBase > > geometryAndMesh
Geometry and mesh.
Definition: NucMeshSrv.H:54
vtkTypeMacro(NucMeshSrv, srvBase) protected int FillOutputPortInformation(int port, vtkInformation *info) override
Definition: NucMeshSrv.C:64
void setSMeshMesh(std::unique_ptr< SMESH_Mesh > &&mesh, std::shared_ptr< SMESH_Gen > gen)
Definition: smeshGeoMesh.C:142
vtkStandardNewMacro(NucMeshSrv)
Definition: NucMeshSrv.C:50
std::shared_ptr< meshBase > mesh
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)=0
This is called by the superclass.
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
const NucMeshConf & GetConfiguration() const
Definition: NucMeshSrv.C:62
SM_StdContainerWrapperFromIter< typename std::decay< PtrSMDSIterator >::type, VALUE, EqualVALUE > containerWrapper(PtrSMDSIterator &&iter)
Definition: smeshUtils.H:57
std::vector< double > extrudeSteps
Extrude the final 2d mesh along the z-axis.
Definition: NucMeshSrv.H:60
void SetConfiguration(const NucMeshConf &configuration)
Definition: NucMeshSrv.C:57
static void mergeGeo(NEM::GEO::GeoManager &keepGeo, NEM::GEO::GeoManager &&removeGeo)
Merge two 2d NEM::GEO::GeoManager objects by cutting shapes in removeGeo from shapes in keepGeo and s...
Definition: ShapeBase.C:66
NucMeshConf conf_
Definition: NucMeshSrv.H:104
std::shared_ptr< SMESH_Gen > generator
Definition: NucMeshSrv.H:89