omega_h
Reliable mesh adaptation
Omega_h_adapt.hpp
1 #ifndef OMEGA_H_ADAPT_HPP
2 #define OMEGA_H_ADAPT_HPP
3 
4 #include <map>
5 
6 #include <Omega_h_config.h>
7 #include <Omega_h_compare.hpp>
8 #include <Omega_h_defines.hpp>
9 #include <Omega_h_mark.hpp>
10 
11 namespace Omega_h {
12 
13 class Mesh;
14 
26 struct UserTransfer {
27  virtual ~UserTransfer() = default;
28  virtual void out_of_line_virtual_method();
29 
50  virtual void refine(Mesh& old_mesh, Mesh& new_mesh, LOs keys2edges,
51  LOs keys2midverts, Int prod_dim, LOs keys2prods, LOs prods2new_ents,
52  LOs same_ents2old_ents, LOs same_ents2new_ents) = 0;
53 
74  virtual void coarsen(Mesh& old_mesh, Mesh& new_mesh, LOs keys2verts,
75  Adj keys2doms, Int prod_dim, LOs prods2new_ents, LOs same_ents2old_ents,
76  LOs same_ents2new_ents) = 0;
77 
96  virtual void swap(Mesh& old_mesh, Mesh& new_mesh, Int prod_dim,
97  LOs keys2edges, LOs keys2prods, LOs prods2new_ents,
98  LOs same_ents2old_ents, LOs same_ents2new_ents) = 0;
99 
115  virtual void swap_copy_verts(Mesh& old_mesh, Mesh& new_mesh) = 0;
116 
117 
133  virtual void snap(Mesh& mesh, const Reals& old_coords, const Reals& warp) = 0;
134 };
135 
136 struct TransferOpts {
137  TransferOpts();
138  std::map<std::string, Omega_h_Transfer> type_map; // "density" -> CONSERVE
139  std::map<std::string, std::string> integral_map; // "density" -> "mass"
140  std::map<std::string, std::string>
141  velocity_density_map; // "velocity" -> "density"
142  std::map<std::string, std::string>
143  velocity_momentum_map; // "velocity" -> "momentum"
144  std::map<std::string, VarCompareOpts>
145  integral_diffuse_map; // "mass" -> tolerance
146  std::shared_ptr<UserTransfer> user_xfer;
147  void validate(Mesh* mesh) const;
148 };
149 
150 enum Verbosity { SILENT, EACH_ADAPT, EACH_REBUILD, EXTRA_STATS };
151 
152 #ifdef OMEGA_H_USE_EGADS
153 struct Egads;
154 #endif
155 
156 struct AdaptOpts {
157  AdaptOpts() = default;
158  AdaptOpts(Int dim); // sets defaults
159  AdaptOpts(Mesh* mesh); // calls above
160  Real min_length_desired;
161  Real max_length_desired;
162  Real max_length_allowed;
163  Real min_quality_allowed;
164  Real min_quality_desired;
165  Int nsliver_layers;
166  Verbosity verbosity;
167  Real length_histogram_min;
168  Real length_histogram_max;
169  Int nlength_histogram_bins;
170  Int nquality_histogram_bins;
171 #ifdef OMEGA_H_USE_EGADS
172  Egads* egads_model;
173  bool should_smooth_snap;
174  Real snap_smooth_tolerance;
175  bool allow_snap_failure;
176 #endif
177  bool should_refine;
178  bool should_coarsen;
179  bool should_swap;
180  bool should_coarsen_slivers;
181  bool should_prevent_coarsen_flip;
182  TransferOpts xfer_opts;
183 };
184 
185 Real min_fixable_quality(Mesh* mesh, AdaptOpts const& opts);
186 
187 /* returns false if the mesh was not modified. */
188 bool adapt(Mesh* mesh, AdaptOpts const& opts);
189 
190 bool print_adapt_status(Mesh* mesh, AdaptOpts const& opts);
191 void print_adapt_histograms(Mesh* mesh, AdaptOpts const& opts);
192 
193 void fix_momentum_velocity_verts(
194  Mesh* mesh, std::vector<ClassPair> const& class_pairs, Int comp);
195 
196 bool warp_to_limit(Mesh* mesh, AdaptOpts const& opts,
197  bool exit_on_stall = false, Int max_niters = 40);
198 bool approach_metric(Mesh* mesh, AdaptOpts const& opts, Real min_step = 1e-4);
199 
200 struct MetricSource {
201  Omega_h_Source type;
202  Real knob;
203  std::string tag_name;
204  Omega_h_Isotropy isotropy;
205  Omega_h_Scales scales;
206  MetricSource() = default;
207  MetricSource(Omega_h_Source type_, Real knob_ = 1.0,
208  std::string const& tag_name_ = "",
209  Omega_h_Isotropy isotropy_ = OMEGA_H_ANISOTROPIC,
210  Omega_h_Scales scales_ = OMEGA_H_SCALES);
211 };
212 
213 struct MetricInput {
214  MetricInput();
215  bool verbose;
216  std::vector<MetricSource> sources;
217  bool should_limit_lengths;
218  Real max_length;
219  Real min_length;
220  bool should_limit_gradation;
221  Real max_gradation_rate;
222  Real gradation_convergence_tolerance;
223  bool should_limit_element_count;
224  Real max_element_count;
225  Real min_element_count;
226  Real element_count_over_relaxation;
227  Int nsmoothing_steps;
228  void add_source(MetricSource const& src);
229 };
230 
231 Reals generate_metrics(Mesh* mesh, MetricInput const& input);
232 void add_metric_tag(
233  Mesh* mesh, Reals metrics, std::string const& name = "metric");
234 void generate_metric_tag(Mesh* mesh, MetricInput const& input);
235 void generate_target_metric_tag(Mesh* mesh, MetricInput const& input);
236 void add_implied_metric_tag(Mesh* mesh);
237 void add_implied_isos_tag(Mesh* mesh);
238 void add_implied_metric_based_on_target(Mesh* mesh);
239 
240 void fix(Mesh* mesh, AdaptOpts const& adapt_opts, Omega_h_Isotropy isotropy,
241  bool verbose);
242 void fix_for_given_metric(
243  Mesh* mesh, AdaptOpts const& adapt_opts, bool verbose);
244 
245 void grade_fix_adapt(
246  Mesh* mesh, AdaptOpts const& opts, Reals target_metric, bool verbose);
247 
248 void add_rcField_transferMap(AdaptOpts *opts, std::string const &name,
249  Omega_h_Transfer const transfer);
250 void add_rcField_integralMap(AdaptOpts *opts, std::string const &name,
251  std::string const &map);
252 
253 } // namespace Omega_h
254 
255 #endif
Definition: Omega_h_mesh.hpp:35
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_adapt.hpp:156
Definition: Omega_h_adj.hpp:11
Definition: Omega_h_egads.cpp:83
Definition: Omega_h_adapt.hpp:213
Definition: Omega_h_adapt.hpp:200
Definition: Omega_h_adapt.hpp:136
Application hook for custom field transfer during mesh adaptation.
Definition: Omega_h_adapt.hpp:26
virtual void swap(Mesh &old_mesh, Mesh &new_mesh, Int prod_dim, LOs keys2edges, LOs keys2prods, LOs prods2new_ents, LOs same_ents2old_ents, LOs same_ents2new_ents)=0
Transfer fields during edge/face swaps.
virtual void swap_copy_verts(Mesh &old_mesh, Mesh &new_mesh)=0
Transfer vertex fields during swaps when custom processing needed.
virtual void refine(Mesh &old_mesh, Mesh &new_mesh, LOs keys2edges, LOs keys2midverts, Int prod_dim, LOs keys2prods, LOs prods2new_ents, LOs same_ents2old_ents, LOs same_ents2new_ents)=0
Transfer fields during edge refinement.
virtual void coarsen(Mesh &old_mesh, Mesh &new_mesh, LOs keys2verts, Adj keys2doms, Int prod_dim, LOs prods2new_ents, LOs same_ents2old_ents, LOs same_ents2new_ents)=0
Transfer fields during edge collapse/coarsening.
virtual void snap(Mesh &mesh, const Reals &old_coords, const Reals &warp)=0
Transfer fields during vertex snap.
Definition: Omega_h_rbtree.hpp:1039