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 
118 struct TransferOpts {
119  TransferOpts();
120  std::map<std::string, Omega_h_Transfer> type_map; // "density" -> CONSERVE
121  std::map<std::string, std::string> integral_map; // "density" -> "mass"
122  std::map<std::string, std::string>
123  velocity_density_map; // "velocity" -> "density"
124  std::map<std::string, std::string>
125  velocity_momentum_map; // "velocity" -> "momentum"
126  std::map<std::string, VarCompareOpts>
127  integral_diffuse_map; // "mass" -> tolerance
128  std::shared_ptr<UserTransfer> user_xfer;
129  void validate(Mesh* mesh) const;
130 };
131 
132 enum Verbosity { SILENT, EACH_ADAPT, EACH_REBUILD, EXTRA_STATS };
133 
134 #ifdef OMEGA_H_USE_EGADS
135 struct Egads;
136 #endif
137 
138 struct AdaptOpts {
139  AdaptOpts() = default;
140  AdaptOpts(Int dim); // sets defaults
141  AdaptOpts(Mesh* mesh); // calls above
142  Real min_length_desired;
143  Real max_length_desired;
144  Real max_length_allowed;
145  Real min_quality_allowed;
146  Real min_quality_desired;
147  Int nsliver_layers;
148  Verbosity verbosity;
149  Real length_histogram_min;
150  Real length_histogram_max;
151  Int nlength_histogram_bins;
152  Int nquality_histogram_bins;
153 #ifdef OMEGA_H_USE_EGADS
154  Egads* egads_model;
155  bool should_smooth_snap;
156  Real snap_smooth_tolerance;
157  bool allow_snap_failure;
158 #endif
159  bool should_refine;
160  bool should_coarsen;
161  bool should_swap;
162  bool should_coarsen_slivers;
163  bool should_prevent_coarsen_flip;
164  TransferOpts xfer_opts;
165 };
166 
167 Real min_fixable_quality(Mesh* mesh, AdaptOpts const& opts);
168 
169 /* returns false if the mesh was not modified. */
170 bool adapt(Mesh* mesh, AdaptOpts const& opts);
171 
172 bool print_adapt_status(Mesh* mesh, AdaptOpts const& opts);
173 void print_adapt_histograms(Mesh* mesh, AdaptOpts const& opts);
174 
175 void fix_momentum_velocity_verts(
176  Mesh* mesh, std::vector<ClassPair> const& class_pairs, Int comp);
177 
178 bool warp_to_limit(Mesh* mesh, AdaptOpts const& opts,
179  bool exit_on_stall = false, Int max_niters = 40);
180 bool approach_metric(Mesh* mesh, AdaptOpts const& opts, Real min_step = 1e-4);
181 
182 struct MetricSource {
183  Omega_h_Source type;
184  Real knob;
185  std::string tag_name;
186  Omega_h_Isotropy isotropy;
187  Omega_h_Scales scales;
188  MetricSource() = default;
189  MetricSource(Omega_h_Source type_, Real knob_ = 1.0,
190  std::string const& tag_name_ = "",
191  Omega_h_Isotropy isotropy_ = OMEGA_H_ANISOTROPIC,
192  Omega_h_Scales scales_ = OMEGA_H_SCALES);
193 };
194 
195 struct MetricInput {
196  MetricInput();
197  bool verbose;
198  std::vector<MetricSource> sources;
199  bool should_limit_lengths;
200  Real max_length;
201  Real min_length;
202  bool should_limit_gradation;
203  Real max_gradation_rate;
204  Real gradation_convergence_tolerance;
205  bool should_limit_element_count;
206  Real max_element_count;
207  Real min_element_count;
208  Real element_count_over_relaxation;
209  Int nsmoothing_steps;
210  void add_source(MetricSource const& src);
211 };
212 
213 Reals generate_metrics(Mesh* mesh, MetricInput const& input);
214 void add_metric_tag(
215  Mesh* mesh, Reals metrics, std::string const& name = "metric");
216 void generate_metric_tag(Mesh* mesh, MetricInput const& input);
217 void generate_target_metric_tag(Mesh* mesh, MetricInput const& input);
218 void add_implied_metric_tag(Mesh* mesh);
219 void add_implied_isos_tag(Mesh* mesh);
220 void add_implied_metric_based_on_target(Mesh* mesh);
221 
222 void fix(Mesh* mesh, AdaptOpts const& adapt_opts, Omega_h_Isotropy isotropy,
223  bool verbose);
224 void fix_for_given_metric(
225  Mesh* mesh, AdaptOpts const& adapt_opts, bool verbose);
226 
227 void grade_fix_adapt(
228  Mesh* mesh, AdaptOpts const& opts, Reals target_metric, bool verbose);
229 
230 void add_rcField_transferMap(AdaptOpts *opts, std::string const &name,
231  Omega_h_Transfer const transfer);
232 void add_rcField_integralMap(AdaptOpts *opts, std::string const &name,
233  std::string const &map);
234 
235 } // namespace Omega_h
236 
237 #endif
Definition: Omega_h_mesh.hpp:35
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_adapt.hpp:138
Definition: Omega_h_adj.hpp:11
Definition: Omega_h_egads.cpp:83
Definition: Omega_h_adapt.hpp:195
Definition: Omega_h_adapt.hpp:182
Definition: Omega_h_adapt.hpp:118
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.
Definition: Omega_h_rbtree.hpp:1039