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.
OmegahRefineDriver.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 "Mesh/geoMeshFactory.H"
33 #include "Mesh/oshGeoMesh.H"
34 
35 namespace NEM {
36 namespace DRV {
37 
39  Omega_h_Transfer method)
40  : arrayName(std::move(arrayName)), method(method) {}
41 
43  : integralName(std::move(integralName)) {
44  // Default values from Omega_h::VarCompareOpts::defaults()
45  this->type = "Relative";
46  this->tolerance = 1e-6;
47  this->floor = 0.;
48 }
49 
51  std::vector<NEM::SRV::omegahRefineMetricSource> sources)
52  : MetricSources(std::move(sources)) {}
53 
55  : RefineDriver(std::move(files)), opts_(std::move(opts)) {}
56 
58  : OmegahRefineDriver({{}, {}}, Opts{{}}) {}
59 
61  return opts_;
62 }
63 
64 void OmegahRefineDriver::setOpts(Opts opts) { this->opts_ = std::move(opts); }
65 
67  auto inMesh = vtkSmartPointer<NEM::MSH::geoMeshBase>::Take(
69  if (this->opts_.reconstructGeo) {
70  inMesh->reconstructGeo();
71  }
72  vtkSmartPointer<NEM::MSH::oshGeoMesh> osh_mesh =
74  osh_mesh->takeGeoMesh(inMesh);
75 
76  // Pass through omegahRefineSrv
77  vtkSmartPointer<NEM::SRV::omegahRefineSrv> orSrv =
79  orSrv->AddInputDataObject(osh_mesh);
80 
81  // Set metric input options
82  if (this->opts_.Verbose) orSrv->SetVerbose(this->opts_.Verbose.value());
83  for (const auto &ms : this->opts_.MetricSources)
84  orSrv->AddMetricSource(ms.type, ms.knob, ms.tag_name, ms.isotropy,
85  ms.scales);
86  if (this->opts_.ShouldLimitLengths)
87  orSrv->SetShouldLimitLengths(this->opts_.ShouldLimitLengths.value());
88  if (this->opts_.MaxLength) orSrv->SetMaxLength(this->opts_.MaxLength.value());
89  if (this->opts_.MinLength) orSrv->SetMinLength(this->opts_.MinLength.value());
90  if (this->opts_.ShouldLimitGradation)
91  orSrv->SetShouldLimitGradation(this->opts_.ShouldLimitGradation.value());
92  if (this->opts_.MaxGradationRate)
93  orSrv->SetMaxGradationRate(this->opts_.MaxGradationRate.value());
95  orSrv->SetGradationConvergenceTolerance(
96  this->opts_.GradationConvergenceTolerance.value());
98  orSrv->SetShouldLimitElementCount(
99  this->opts_.ShouldLimitElementCount.value());
100  if (this->opts_.MaxElementCount)
101  orSrv->SetMaxElementCount(this->opts_.MaxElementCount.value());
102  if (this->opts_.MinElementCount)
103  orSrv->SetMinElementCount(this->opts_.MinElementCount.value());
105  orSrv->SetElementCountOverRelaxation(
106  this->opts_.ElementCountOverRelaxation.value());
107  if (this->opts_.NsmoothingSteps)
108  orSrv->SetNsmoothingSteps(this->opts_.NsmoothingSteps.value());
109 
110  // Set adapt options
111  if (this->opts_.MinLengthDesired)
112  orSrv->SetMinLengthDesired(this->opts_.MinLengthDesired.value());
113  if (this->opts_.MaxLengthDesired)
114  orSrv->SetMaxLengthDesired(this->opts_.MaxLengthDesired.value());
115  if (this->opts_.MaxLengthAllowed)
116  orSrv->SetMaxLengthAllowed(this->opts_.MaxLengthAllowed.value());
117  if (this->opts_.MinQualityAllowed)
118  orSrv->SetMinQualityAllowed(this->opts_.MinQualityAllowed.value());
119  if (this->opts_.MinQualityDesired)
120  orSrv->SetMinQualityDesired(this->opts_.MinQualityDesired.value());
121  if (this->opts_.NsliverLayers)
122  orSrv->SetNsliverLayers(this->opts_.NsliverLayers.value());
123  if (this->opts_.Verbosity) orSrv->SetVerbosity(this->opts_.Verbosity.value());
124  if (this->opts_.LengthHistogramMin)
125  orSrv->SetLengthHistogramMin(this->opts_.LengthHistogramMin.value());
126  if (this->opts_.LengthHistogramMax)
127  orSrv->SetLengthHistogramMax(this->opts_.LengthHistogramMax.value());
128  if (this->opts_.NlengthHistogramBins)
129  orSrv->SetNlengthHistogramBins(this->opts_.NlengthHistogramBins.value());
130  if (this->opts_.NqualityHistogramBins)
131  orSrv->SetNqualityHistogramBins(this->opts_.NqualityHistogramBins.value());
132  if (this->opts_.ShouldRefine)
133  orSrv->SetShouldRefine(this->opts_.ShouldRefine.value());
134  if (this->opts_.ShouldCoarsen)
135  orSrv->SetShouldCoarsen(this->opts_.ShouldCoarsen.value());
136  if (this->opts_.ShouldSwap)
137  orSrv->SetShouldSwap(this->opts_.ShouldSwap.value());
138  if (this->opts_.ShouldCoarsenSlivers)
139  orSrv->SetShouldCoarsenSlivers(this->opts_.ShouldCoarsenSlivers.value());
141  orSrv->SetShouldPreventCoarsenFlip(
142  this->opts_.ShouldPreventCoarsenFlip.value());
143 
144  // Add transfer options
145  for (const auto &xfer : this->opts_.TransferOpts) {
146  if (xfer.integralName) {
147  orSrv->AddTransferOpts(xfer.arrayName, xfer.method,
148  xfer.integralName.value());
149  } else {
150  orSrv->AddTransferOpts(xfer.arrayName, xfer.method);
151  }
152  }
153  for (const auto &xfer : this->opts_.TransferOptsIntegralDiffuse)
154  orSrv->AddTransferOptsIntegralDiffuse(xfer.integralName, xfer.type,
155  xfer.tolerance, xfer.floor);
156 
157  orSrv->Update();
158 
159  // Populate the output mesh
160  auto outMesh = vtkSmartPointer<NEM::MSH::geoMeshBase>::Take(
162  outMesh->takeGeoMesh(orSrv->GetOutput());
163  outMesh->write(this->files_.outputMeshFile);
164 }
165 
166 } // namespace DRV
167 } // namespace NEM
jsoncons::optional< bool > ShouldLimitElementCount
std::vector< VarCompare > TransferOptsIntegralDiffuse
std::string outputMeshFile
Definition: NemDriver.H:91
jsoncons::optional< Omega_h::Real > MaxLengthDesired
jsoncons::optional< bool > ShouldLimitGradation
jsoncons::optional< Omega_h::Int > NqualityHistogramBins
jsoncons::optional< Omega_h::Real > MinQualityAllowed
geoMeshBase * Read(const std::string &fileName)
Read a mesh from file.
jsoncons::optional< Omega_h::Real > LengthHistogramMax
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
jsoncons::optional< bool > ShouldRefine
jsoncons::optional< std::string > Verbosity
jsoncons::optional< Omega_h::Real > MinQualityDesired
jsoncons::optional< Omega_h::Real > MinElementCount
STL namespace.
jsoncons::optional< Omega_h::Int > NlengthHistogramBins
jsoncons::optional< bool > ShouldSwap
jsoncons::optional< Omega_h::Real > MaxLengthAllowed
jsoncons::optional< bool > ShouldCoarsenSlivers
jsoncons::optional< bool > ShouldCoarsen
std::string type
NONE, RELATIVE, or ABSOLUTE comparison of data.
jsoncons::optional< bool > ShouldLimitLengths
jsoncons::optional< Omega_h::Real > MinLength
void execute() const override
Run the workflow represented by the driver.
jsoncons::optional< Omega_h::Real > GradationConvergenceTolerance
jsoncons::optional< Omega_h::Real > MaxGradationRate
std::string inputMeshFile
Definition: NemDriver.H:90
jsoncons::optional< bool > Verbose
const Opts & getOpts() const
Omega_h::Real floor
RELATIVE: values below floor snap to 0.0.
Omega_h::Real tolerance
tolerance threshold for comparison
std::vector< Transfer > TransferOpts
jsoncons::optional< Omega_h::Real > MaxElementCount
jsoncons::optional< Omega_h::Int > NsliverLayers
jsoncons::optional< Omega_h::Real > LengthHistogramMin
jsoncons::optional< Omega_h::Real > MinLengthDesired
std::vector< NEM::SRV::omegahRefineMetricSource > MetricSources
jsoncons::optional< Omega_h::Real > MaxLength
jsoncons::optional< Omega_h::Real > ElementCountOverRelaxation
jsoncons::optional< std::string > integralName
jsoncons::optional< Omega_h::Int > NsmoothingSteps
jsoncons::optional< bool > ShouldPreventCoarsenFlip
std::array< vtkIdType, 2 > sources