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.
omegahRefineSrv.H
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 #ifndef NEMOSYS_OMEGAHREFINESRV_H_
30 #define NEMOSYS_OMEGAHREFINESRV_H_
31 
32 #include "Services/srvBase.H"
33 
34 #include <map>
35 #include <string>
36 #include <utility>
37 #include <vector>
38 
39 #include <Omega_h_defines.hpp>
40 
41 namespace NEM {
42 namespace SRV {
43 
44 /**
45  * Store variables to create Omega_h's MetricSource object used to define
46  * metrics for refinement
47  */
48 struct NEMOSYS_EXPORT omegahRefineMetricSource {
49  omegahRefineMetricSource() = default;
50  omegahRefineMetricSource(Omega_h_Source type, Omega_h::Real knob,
51  std::string tag_name, Omega_h_Isotropy isotropy,
52  Omega_h_Scales scales)
53  : type(type), knob(knob), tag_name(std::move(tag_name)),
54  isotropy(isotropy), scales(scales) {}
55  /**
56  * @brief type of source, e.g., by variation, by gradient
57  */
58  Omega_h_Source type{OMEGA_H_IMPLIED};
59  /**
60  * @brief extra parameter depending on source type
61  */
62  Omega_h::Real knob{1.};
63  /**
64  * @brief name of field defining the source
65  */
66  std::string tag_name{};
67  /**
68  * @brief controls the conversion of anisotropic metrics to isotropic ones
69  */
70  Omega_h_Isotropy isotropy{OMEGA_H_ANISOTROPIC};
71  /**
72  * @brief determines whether a metric is allowed to be scaled to satisfy an
73  * element count constraint
74  */
75  Omega_h_Scales scales{OMEGA_H_SCALES};
76 };
77 
78 /**
79  * Store variables to create Omega_h's VarCompareOpts object used to define
80  * integral diffuse map during conservative data transfer
81  */
83  std::string type; ///< NONE, RELATIVE, or ABSOLUTE comparison of data
84  Omega_h::Real tolerance; ///< tolerance threshold for comparison
85  Omega_h::Real floor; ///< RELATIVE: values below floor snap to 0.0
86 };
87 
88 /**
89  * @class omegahRefineSrv
90  * @brief A service to use the Omega_h library for refinement
91  */
92 class NEMOSYS_EXPORT omegahRefineSrv : public srvBase {
93  public:
94  static omegahRefineSrv *New();
95  vtkTypeMacro(omegahRefineSrv, srvBase)
96 
97  /** @defgroup metric Metric Input
98  * Metric Input Parameters
99  * @{
100  */
101 
102  //@{
103  /**
104  * Turn off the verbosity of Omega_h metric generation.
105  */
106  vtkSetMacro(Verbose, bool);
107  vtkGetMacro(Verbose, bool);
108  vtkBooleanMacro(Verbose, bool);
109  //@}
110 
111  //@{
112  /**
113  * Add a source to the metric input.
114  */
115  void AddMetricSource(Omega_h_Source type, Omega_h::Real knob = 1.0,
116  std::string tag_name = "",
117  Omega_h_Isotropy isotropy = OMEGA_H_ANISOTROPIC,
118  Omega_h_Scales scales = OMEGA_H_SCALES) {
119  omegahRefineMetricSource orms{type, knob, std::move(tag_name), isotropy,
120  scales};
121  MetricSources.push_back(orms);
122  }
123  //@}
124 
125  //@{
126  /**
127  * Specify if the metrics should limit the edge lengths. Default is off.
128  */
129  vtkSetMacro(ShouldLimitLengths, bool);
130  vtkGetMacro(ShouldLimitLengths, bool);
131  vtkBooleanMacro(ShouldLimitLengths, bool);
132  //@}
133 
134  //@{
135  /**
136  * Specify the maximum length of the edges allowed by the metrics.
137  */
138  vtkSetMacro(MaxLength, Omega_h::Real);
139  vtkGetMacro(MaxLength, Omega_h::Real);
140  //@}
141 
142  //@{
143  /**
144  * Specify the minimum length of the edges allowed by the metrics.
145  */
146  vtkSetMacro(MinLength, Omega_h::Real);
147  vtkGetMacro(MinLength, Omega_h::Real);
148  //@}
149 
150  //@{
151  /**
152  * Specify if the metrics should limit the gradation rate. Default is off.
153  */
154  vtkSetMacro(ShouldLimitGradation, bool);
155  vtkGetMacro(ShouldLimitGradation, bool);
156  vtkBooleanMacro(ShouldLimitGradation, bool);
157  //@}
158 
159  //@{
160  /**
161  * Specify the maximum gradation rate allowed by the metrics.
162  */
163  vtkSetMacro(MaxGradationRate, Omega_h::Real);
164  vtkGetMacro(MaxGradationRate, Omega_h::Real);
165  //@}
166 
167  //@{
168  /**
169  * Specify the tolerance used when limiting the gradation rate in the metrics.
170  */
171  vtkSetMacro(GradationConvergenceTolerance, Omega_h::Real);
172  vtkGetMacro(GradationConvergenceTolerance, Omega_h::Real);
173  //@}
174 
175  //@{
176  /**
177  * Specify if the metrics should limit the element count.
178  */
179  vtkSetMacro(ShouldLimitElementCount, bool);
180  vtkGetMacro(ShouldLimitElementCount, bool);
181  vtkBooleanMacro(ShouldLimitElementCount, bool);
182  //@}
183 
184  //@{
185  /**
186  * Specify the maximum element count allowed by the metrics.
187  */
188  vtkSetMacro(MaxElementCount, Omega_h::Real);
189  vtkGetMacro(MaxElementCount, Omega_h::Real);
190  //@}
191 
192  //@{
193  /**
194  * Specify the minimum element count allowed by the metrics.
195  */
196  vtkSetMacro(MinElementCount, Omega_h::Real);
197  vtkGetMacro(MinElementCount, Omega_h::Real);
198  //@}
199 
200  //@{
201  /**
202  * Specify the over relaxation tolerance when limiting the element count.
203  */
204  vtkSetMacro(ElementCountOverRelaxation, Omega_h::Real);
205  vtkGetMacro(ElementCountOverRelaxation, Omega_h::Real);
206  //@}
207 
208  //@{
209  /**
210  * Specify the number of smoothing steps when generating the metric.
211  */
212  vtkSetMacro(NsmoothingSteps, Omega_h::Int);
213  vtkGetMacro(NsmoothingSteps, Omega_h::Int);
214  //@}
215 
216  /** @} */ // end of metric
217 
218  /** @defgroup adapt Adaptation Options
219  * @{
220  */
221 
222  //@{
223  /**
224  * Specify the minimum desired length.
225  */
226  vtkSetMacro(MinLengthDesired, Omega_h::Real);
227  vtkGetMacro(MinLengthDesired, Omega_h::Real);
228  //@}
229 
230  //@{
231  /**
232  * Specify the maximum desired length.
233  */
234  vtkSetMacro(MaxLengthDesired, Omega_h::Real);
235  vtkGetMacro(MaxLengthDesired, Omega_h::Real);
236  //@}
237 
238  //@{
239  /**
240  * Specify the maximum allowed length.
241  */
242  vtkSetMacro(MaxLengthAllowed, Omega_h::Real);
243  vtkGetMacro(MaxLengthAllowed, Omega_h::Real);
244  //@}
245 
246  //@{
247  /**
248  * Specify the minimum allowed length.
249  */
250  vtkSetMacro(MinQualityAllowed, Omega_h::Real);
251  vtkGetMacro(MinQualityAllowed, Omega_h::Real);
252  //@}
253 
254  //@{
255  /**
256  * Specify the minimum desired quality.
257  */
258  vtkSetMacro(MinQualityDesired, Omega_h::Real);
259  vtkGetMacro(MinQualityDesired, Omega_h::Real);
260  //@}
261 
262  //@{
263  /**
264  * Specify the number of sliver layers.
265  */
266  vtkSetMacro(NsliverLayers, Omega_h::Int);
267  vtkGetMacro(NsliverLayers, Omega_h::Int);
268  //@}
269 
270  //@{
271  /**
272  * Specify the verbosity of the adaptation method. Options are:
273  * - Silent
274  * - Each Adapt : after each adaptation step
275  * - Each Rebuild : also after each rebuild between steps
276  * - Extra Stats : all the above and detailed histogram with stats
277  */
278  vtkSetMacro(Verbosity, const std::string &);
279  vtkGetMacro(Verbosity, const std::string &);
280  //@}
281 
282  //@{
283  /**
284  * Specify the minimum depth of the length histogram.
285  */
286  vtkSetMacro(LengthHistogramMin, Omega_h::Real);
287  vtkGetMacro(LengthHistogramMin, Omega_h::Real);
288  //@}
289 
290  //@{
291  /**
292  * Specify the maximum depth of the length histogram.
293  */
294  vtkSetMacro(LengthHistogramMax, Omega_h::Real);
295  vtkGetMacro(LengthHistogramMax, Omega_h::Real);
296  //@}
297 
298  //@{
299  /**
300  * Specify the number of bins in the length histogram.
301  */
302  vtkSetMacro(NlengthHistogramBins, Omega_h::Int);
303  vtkGetMacro(NlengthHistogramBins, Omega_h::Int);
304  //@}
305 
306  //@{
307  /**
308  * Specify the number of bins in the quality histogram.
309  */
310  vtkSetMacro(NqualityHistogramBins, Omega_h::Int);
311  vtkGetMacro(NqualityHistogramBins, Omega_h::Int);
312  //@}
313 
314  //@{
315  /**
316  * Specify if adapt should refine elements. Default is true.
317  */
318  vtkSetMacro(ShouldRefine, bool);
319  vtkGetMacro(ShouldRefine, bool);
320  vtkBooleanMacro(ShouldRefine, bool);
321  //@}
322 
323  //@{
324  /**
325  * Specify if adapt should coarsen elements. Default is true.
326  */
327  vtkSetMacro(ShouldCoarsen, bool);
328  vtkGetMacro(ShouldCoarsen, bool);
329  vtkBooleanMacro(ShouldCoarsen, bool);
330  //@}
331 
332  //@{
333  /**
334  * Specify if adapt should swap elements. Default is true.
335  */
336  vtkSetMacro(ShouldSwap, bool);
337  vtkGetMacro(ShouldSwap, bool);
338  vtkBooleanMacro(ShouldSwap, bool);
339  //@}
340 
341  //@{
342  /**
343  * Specify if adapt should coarsen slivers. Default is true.
344  */
345  vtkSetMacro(ShouldCoarsenSlivers, bool);
346  vtkGetMacro(ShouldCoarsenSlivers, bool);
347  vtkBooleanMacro(ShouldCoarsenSlivers, bool);
348  //@}
349 
350  //@{
351  /**
352  * Specify if adapt should prevent coarsen flips. Default is false.
353  */
354  vtkSetMacro(ShouldPreventCoarsenFlip, bool);
355  vtkGetMacro(ShouldPreventCoarsenFlip, bool);
356  vtkBooleanMacro(ShouldPreventCoarsenFlip, bool);
357  //@}
358 
359  /** @} */ // end of adapt
360 
361  /** @defgroup transfer Transfer Options
362  * @{
363  */
364 
365  /**
366  * Add a field to be transferred.
367  *
368  * When using "Conserve" transfer, specify the name of the integral.
369  * E.g., "density" -> "mass". See Daniel Ibanez's thesis for details on the
370  * methods. Note if no transfer opts are added, tags are transferred using
371  * OMEGA_H_INHERIT, OMEGA_H_LINEAR_INTERP, or OMEGA_H_POINTWISE depending on
372  * dimensions and type.
373  */
374  void AddTransferOpts(const std::string &name, Omega_h_Transfer method,
375  const std::string &integral_name = "") {
376  TransferOptsTypeMap[name] = method;
377  if (!integral_name.empty()) TransferOptsIntegralMap[name] = integral_name;
378  }
379  /**
380  * When specifying integral quantities, set tolerances.
381  */
382  void AddTransferOptsIntegralDiffuse(const std::string &integral_name,
383  const std::string &type,
384  Omega_h::Real tolerance,
385  Omega_h::Real floor) {
386  TransferOptsIntegralDiffuseMap[integral_name] = {type, tolerance, floor};
387  }
388 
389  /** @} */ // end of transfer
390 
391  protected:
392  omegahRefineSrv();
393  ~omegahRefineSrv() override;
394 
395  int RequestData(vtkInformation *request, vtkInformationVector **inputVector,
396  vtkInformationVector *outputVector) override;
397 
398  // see algorithm for more info
399  int FillInputPortInformation(int port, vtkInformation *info) override;
400  int FillOutputPortInformation(int port, vtkInformation *info) override;
401 
402  private:
403  // Metric Input options
404  bool Verbose{true};
405  std::vector<omegahRefineMetricSource> MetricSources;
406  bool ShouldLimitLengths{false};
407  Omega_h::Real MaxLength{-1.0};
408  Omega_h::Real MinLength{-1.0};
409  bool ShouldLimitGradation{false};
410  Omega_h::Real MaxGradationRate{-1.0};
411  Omega_h::Real GradationConvergenceTolerance{-1.0};
412  bool ShouldLimitElementCount{false};
413  Omega_h::Real MaxElementCount{-1.0};
414  Omega_h::Real MinElementCount{-1.0};
415  Omega_h::Real ElementCountOverRelaxation{-1.0};
416  Omega_h::Int NsmoothingSteps{-1};
417 
418  // Adapt Opts
419  Omega_h::Real MinLengthDesired{-1.0};
420  Omega_h::Real MaxLengthDesired{-1.0};
421  Omega_h::Real MaxLengthAllowed{-1.0};
422  Omega_h::Real MinQualityAllowed{-1.0};
423  Omega_h::Real MinQualityDesired{-1.0};
424  Omega_h::Int NsliverLayers{-1};
425  std::string Verbosity{"Each Rebuild"};
426  Omega_h::Real LengthHistogramMin{-1.0};
427  Omega_h::Real LengthHistogramMax{-1.0};
428  Omega_h::Int NlengthHistogramBins{-1};
429  Omega_h::Int NqualityHistogramBins{-1};
430  bool ShouldRefine{true};
431  bool ShouldCoarsen{true};
432  bool ShouldSwap{true};
433  bool ShouldCoarsenSlivers{true};
434  bool ShouldPreventCoarsenFlip{false};
435 
436  // Transfer Opts
437  std::map<std::string, Omega_h_Transfer> TransferOptsTypeMap;
438  std::map<std::string, std::string> TransferOptsIntegralMap;
439  std::map<std::string, omegahRefineVarCompareOpts>
441 };
442 
443 } // namespace SRV
444 } // namespace NEM
445 
446 #endif // NEMOSYS_OMEGAHREFINESRV_H_
std::vector< omegahRefineMetricSource > MetricSources
std::map< std::string, omegahRefineVarCompareOpts > TransferOptsIntegralDiffuseMap
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
std::map< std::string, std::string > TransferOptsIntegralMap
STL namespace.
void AddTransferOpts(const std::string &name, Omega_h_Transfer method, const std::string &integral_name="")
Add a field to be transferred.
std::string type
NONE, RELATIVE, or ABSOLUTE comparison of data.
std::map< std::string, Omega_h_Transfer > TransferOptsTypeMap
omegahRefineMetricSource(Omega_h_Source type, Omega_h::Real knob, std::string tag_name, Omega_h_Isotropy isotropy, Omega_h_Scales scales)
Omega_h::Real floor
RELATIVE: values below floor snap to 0.0.
Omega_h::Real tolerance
tolerance threshold for comparison
A service to use the Omega_h library for refinement.
abstract class for services acting on geoMeshBase
Definition: srvBase.H:53
Store variables to create Omega_h&#39;s VarCompareOpts object used to define integral diffuse map during ...
void AddTransferOptsIntegralDiffuse(const std::string &integral_name, const std::string &type, Omega_h::Real tolerance, Omega_h::Real floor)
When specifying integral quantities, set tolerances.
Store variables to create Omega_h&#39;s MetricSource object used to define metrics for refinement...