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 
15 struct UserTransfer {
16  virtual ~UserTransfer() = default;
17  virtual void out_of_line_virtual_method();
18  virtual void refine(Mesh& old_mesh, Mesh& new_mesh, LOs keys2edges,
19  LOs keys2midverts, Int prod_dim, LOs keys2prods, LOs prods2new_ents,
20  LOs same_ents2old_ents, LOs same_ents2new_ents) = 0;
21  virtual void coarsen(Mesh& old_mesh, Mesh& new_mesh, LOs keys2verts,
22  Adj keys2doms, Int prod_dim, LOs prods2new_ents, LOs same_ents2old_ents,
23  LOs same_ents2new_ents) = 0;
24  virtual void swap(Mesh& old_mesh, Mesh& new_mesh, Int prod_dim,
25  LOs keys2edges, LOs keys2prods, LOs prods2new_ents,
26  LOs same_ents2old_ents, LOs same_ents2new_ents) = 0;
27  virtual void swap_copy_verts(Mesh& old_mesh, Mesh& new_mesh) = 0;
28 };
29 
30 struct TransferOpts {
31  TransferOpts();
32  std::map<std::string, Omega_h_Transfer> type_map; // "density" -> CONSERVE
33  std::map<std::string, std::string> integral_map; // "density" -> "mass"
34  std::map<std::string, std::string>
35  velocity_density_map; // "velocity" -> "density"
36  std::map<std::string, std::string>
37  velocity_momentum_map; // "velocity" -> "momentum"
38  std::map<std::string, VarCompareOpts>
39  integral_diffuse_map; // "mass" -> tolerance
40  std::shared_ptr<UserTransfer> user_xfer;
41  void validate(Mesh* mesh) const;
42 };
43 
44 enum Verbosity { SILENT, EACH_ADAPT, EACH_REBUILD, EXTRA_STATS };
45 
46 #ifdef OMEGA_H_USE_EGADS
47 struct Egads;
48 #endif
49 
50 struct AdaptOpts {
51  AdaptOpts() = default;
52  AdaptOpts(Int dim); // sets defaults
53  AdaptOpts(Mesh* mesh); // calls above
54  Real min_length_desired;
55  Real max_length_desired;
56  Real max_length_allowed;
57  Real min_quality_allowed;
58  Real min_quality_desired;
59  Int nsliver_layers;
60  Verbosity verbosity;
61  Real length_histogram_min;
62  Real length_histogram_max;
63  Int nlength_histogram_bins;
64  Int nquality_histogram_bins;
65 #ifdef OMEGA_H_USE_EGADS
66  Egads* egads_model;
67  bool should_smooth_snap;
68  Real snap_smooth_tolerance;
69  bool allow_snap_failure;
70 #endif
71  bool should_refine;
72  bool should_coarsen;
73  bool should_swap;
74  bool should_coarsen_slivers;
75  bool should_prevent_coarsen_flip;
76  TransferOpts xfer_opts;
77 };
78 
79 Real min_fixable_quality(Mesh* mesh, AdaptOpts const& opts);
80 
81 /* returns false if the mesh was not modified. */
82 bool adapt(Mesh* mesh, AdaptOpts const& opts);
83 
84 bool print_adapt_status(Mesh* mesh, AdaptOpts const& opts);
85 void print_adapt_histograms(Mesh* mesh, AdaptOpts const& opts);
86 
87 void fix_momentum_velocity_verts(
88  Mesh* mesh, std::vector<ClassPair> const& class_pairs, Int comp);
89 
90 bool warp_to_limit(Mesh* mesh, AdaptOpts const& opts,
91  bool exit_on_stall = false, Int max_niters = 40);
92 bool approach_metric(Mesh* mesh, AdaptOpts const& opts, Real min_step = 1e-4);
93 
94 struct MetricSource {
95  Omega_h_Source type;
96  Real knob;
97  std::string tag_name;
98  Omega_h_Isotropy isotropy;
99  Omega_h_Scales scales;
100  MetricSource() = default;
101  MetricSource(Omega_h_Source type_, Real knob_ = 1.0,
102  std::string const& tag_name_ = "",
103  Omega_h_Isotropy isotropy_ = OMEGA_H_ANISOTROPIC,
104  Omega_h_Scales scales_ = OMEGA_H_SCALES);
105 };
106 
107 struct MetricInput {
108  MetricInput();
109  bool verbose;
110  std::vector<MetricSource> sources;
111  bool should_limit_lengths;
112  Real max_length;
113  Real min_length;
114  bool should_limit_gradation;
115  Real max_gradation_rate;
116  Real gradation_convergence_tolerance;
117  bool should_limit_element_count;
118  Real max_element_count;
119  Real min_element_count;
120  Real element_count_over_relaxation;
121  Int nsmoothing_steps;
122  void add_source(MetricSource const& src);
123 };
124 
125 Reals generate_metrics(Mesh* mesh, MetricInput const& input);
126 void add_metric_tag(
127  Mesh* mesh, Reals metrics, std::string const& name = "metric");
128 void generate_metric_tag(Mesh* mesh, MetricInput const& input);
129 void generate_target_metric_tag(Mesh* mesh, MetricInput const& input);
130 void add_implied_metric_tag(Mesh* mesh);
131 void add_implied_isos_tag(Mesh* mesh);
132 void add_implied_metric_based_on_target(Mesh* mesh);
133 
134 void fix(Mesh* mesh, AdaptOpts const& adapt_opts, Omega_h_Isotropy isotropy,
135  bool verbose);
136 void fix_for_given_metric(
137  Mesh* mesh, AdaptOpts const& adapt_opts, bool verbose);
138 
139 void grade_fix_adapt(
140  Mesh* mesh, AdaptOpts const& opts, Reals target_metric, bool verbose);
141 
142 void add_rcField_transferMap(AdaptOpts *opts, std::string const &name,
143  Omega_h_Transfer const transfer);
144 void add_rcField_integralMap(AdaptOpts *opts, std::string const &name,
145  std::string const &map);
146 
147 } // namespace Omega_h
148 
149 #endif
Definition: Omega_h_mesh.hpp:35
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_adapt.hpp:50
Definition: Omega_h_adj.hpp:11
Definition: Omega_h_egads.cpp:83
Definition: Omega_h_adapt.hpp:107
Definition: Omega_h_adapt.hpp:94
Definition: Omega_h_adapt.hpp:30
Definition: Omega_h_adapt.hpp:15
Definition: Omega_h_rbtree.hpp:1039