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.
SurfacePackMeshDriver.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 "Geometry/rocPack.H"
32 
33 namespace NEM {
34 namespace DRV {
35 
36 SurfacePackMeshDriver::Files::Files(std::string rocpackFile,
37  std::string outputMeshFile)
38  : rocpackFile(std::move(rocpackFile)),
39  outputMeshFile(std::move(outputMeshFile)) {}
40 
42  jsoncons::optional<Periodic3DOpts> periodic3DOpts)
43  : periodic3DOpts(std::move(periodic3DOpts)) {}
44 
46  : files_(std::move(files)), opts_(std::move(opts)) {}
47 
49  : SurfacePackMeshDriver({{}, {}}, Opts{{}}) {}
50 
52  return files_;
53 }
54 
56  this->files_ = std::move(files);
57 }
58 
60  return opts_;
61 }
62 
64  if (opts.periodic3DOpts.has_value()) {
65  const auto &periodic3DOpts = opts.periodic3DOpts.value();
66  if (!(opts.meshAlgorithm == 1 || opts.meshAlgorithm == 4 ||
67  opts.meshAlgorithm == 7 || opts.meshAlgorithm == 9 ||
68  opts.meshAlgorithm == 10)) {
69  std::cerr << "Valid choices for 3D meshing algorithm are "
70  << " 1 (Delunay), 4 (Frontal), 7 (MMG3D), 9 (R-Tree), 10 (HXT)"
71  << std::endl;
72  throw;
73  }
74  if (!(periodic3DOpts.elemOrder == 1 || periodic3DOpts.elemOrder == 2)) {
75  std::cerr << "Only element orders 1 and 2 are supported!" << std::endl;
76  throw;
77  }
78  } else {
79  if (opts.meshAlgorithm == 1 || opts.meshAlgorithm == 2 ||
80  opts.meshAlgorithm == 5 || opts.meshAlgorithm == 6 ||
81  opts.meshAlgorithm == 7 || opts.meshAlgorithm == 8 ||
82  opts.meshAlgorithm == 9) {
83  } else {
84  std::cerr
85  << "Valid choices for 2D meshing algorithm are "
86  << " 1 (MeshAdapt), 2 (Automatic), 5 (Delunay), "
87  << " 6 (Frontal Delunay), 7 (BAMG), 8 (Frontal Delunay for Quads)"
88  << " 9 (Packing of Parallelograms)." << std::endl;
89  throw;
90  }
91  }
92  this->opts_ = std::move(opts);
93 }
94 
95 // TODO
96 // 1. Some implementation to improve mesh if mesh is not of desired
97 // quality.
99  auto *objrocPck = new NEM::GEO::rocPack(this->files_.rocpackFile,
100  this->files_.outputMeshFile);
101 
102  if (this->opts_.upperThreshold.has_value() ||
103  this->opts_.lowerThreshold.has_value())
104  objrocPck->applyFilter(this->opts_.upperThreshold.value_or(0.),
105  this->opts_.lowerThreshold.value_or(0.));
106 
107  objrocPck->setMeshingAlgorithm(this->opts_.meshAlgorithm);
108 
109  if (this->opts_.preserveSize) objrocPck->setSizePreservation();
110 
111  if (this->opts_.refineLevel.has_value())
112  objrocPck->assignRefinement(this->opts_.refineLevel.value());
113 
114  if (this->opts_.removeBoundaryPacks) objrocPck->removeBoundaryVolumes();
115 
116  if (this->opts_.scaleValue.has_value())
117  objrocPck->shrinkVolumes(this->opts_.scaleValue.value());
118 
119  if (this->opts_.meshSize.has_value())
120  objrocPck->setMeshSize(this->opts_.meshSize.value());
121 
122  if (this->opts_.enableDefaultOut) objrocPck->enableDefOuts();
123 
124  // Create periodic mesh
125  if (this->opts_.periodic3DOpts.has_value()) {
126  const auto &periodic3D = this->opts_.periodic3DOpts.value();
127  if (periodic3D.customDomain && periodic3D.setPeriodicGeo) {
128  std::cerr
129  << "WARNING!! -> Cannot make geometry periodic using custom bounds."
130  << " using remove geometries on boundary option instead for meshing!"
131  << std::endl;
132  }
133  objrocPck->translateAll(periodic3D.transferMesh[0],
134  periodic3D.transferMesh[1],
135  periodic3D.transferMesh[2]);
136 
137  objrocPck->setElementOrder(periodic3D.elemOrder);
138 
139  if (periodic3D.createCohesive) {
140  objrocPck->sanityCheckOn();
141  objrocPck->enableCohesiveElements();
142  }
143 
144  switch (periodic3D.physGrpOptions) {
145  case PhysGrpOpts::MULTI: objrocPck->enablePhysicalGrps(); break;
146  case PhysGrpOpts::TWO: objrocPck->enableTwoPhysGrps(); break;
147  case PhysGrpOpts::PER_SHAPE:
148  objrocPck->enablePhysicalGroupsPerShape();
149  break;
150  case PhysGrpOpts::NONE: break;
151  }
152 
153  if (periodic3D.enablePatches) objrocPck->enableSurfacePatches();
154 
155  if (periodic3D.setPeriodicGeo) objrocPck->setPeriodicGeometry();
156 
157  if (periodic3D.customDomain) {
158  const auto &customDomain = periodic3D.customDomain.value();
159  objrocPck->setCustomDomain(
160  {customDomain.initial[0], customDomain.initial[1],
161  customDomain.initial[2], customDomain.length[0],
162  customDomain.length[1], customDomain.length[2]});
163  objrocPck->removeBoundaryVolumes();
164  objrocPck->setPeriodicMesh();
165  objrocPck->rocPack2Periodic3D();
166  } else {
167  objrocPck->setPeriodicGeometry();
168  objrocPck->setPeriodicMesh();
169  objrocPck->rocPack2Periodic3D();
170  }
171 
172  } else { // Generate STL only
173  objrocPck->rocPack2Surf();
174  }
175 
176  if (objrocPck) delete objrocPck;
177 }
178 
179 } // namespace DRV
180 } // namespace NEM
bool enableDefaultOut
Enable default output formats.
jsoncons::optional< Periodic3DOpts > periodic3DOpts
If periodic3D has value, then options for the 3D mesh.
This class converts Rockpack output file into periodic geometry and writes into STL, VTK, .MSH, and ExodusII file format.
Definition: rocPack.H:77
void execute() const override
Run the workflow represented by the driver.
jsoncons::optional< double > upperThreshold
Upper threshold for filtering (w.r.t mean)
STL namespace.
jsoncons::optional< int > refineLevel
Refinement applied to original mesh.
int meshAlgorithm
Meshing algorithm of choice.
jsoncons::optional< double > scaleValue
Value of scaling between 0 to 1 with 1 being no scaling.
jsoncons::optional< double > lowerThreshold
Lower threshold for filtering (w.r.t mean)
jsoncons::optional< double > meshSize
Mesh size.
bool preserveSize
Boolean for preserving pack sizes instead of packing fraction.
bool removeBoundaryPacks
Boolean for removal of volumes intersecting boundary.