[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
parameters_grid_refinement.cpp
1 #include <algorithm>
2 #include <string>
3 
4 #include <deal.II/base/utilities.h>
5 
6 #include "parameters_grid_refinement.h"
7 
8 namespace PHiLiP {
9 
10 namespace Parameters {
11 
12 void GridRefinementParam::declare_parameters(dealii::ParameterHandler &prm)
13 {
14  // prm.enter_subsection("grid refinement");
15  // {
16  prm.declare_entry("refinement_steps", "3",
17  dealii::Patterns::Integer(),
18  "Number of iterations to be performed");
19 
20  prm.declare_entry("refinement_method", "uniform",
21  dealii::Patterns::Selection(
22  " uniform | "
23  " fixed_fraction | "
24  " continuous"),
25  "Enum of refinement methods."
26  "Choices are "
27  " <uniform | "
28  " fixed_fraction | "
29  " continuous>.");
30 
31  prm.declare_entry("refinement_type", "h",
32  dealii::Patterns::Selection(
33  " h | "
34  " p | "
35  " hp"),
36  "Enum of refinement types."
37  "Choices are "
38  " <h | "
39  " p | "
40  " hp>.");
41 
42  prm.declare_entry("anisotropic", "false",
43  dealii::Patterns::Bool(),
44  "Inidcates whether the refinement should be done anisotropically.");
45 
46  prm.declare_entry("anisotropic_ratio_max", "1.0e+12",
47  dealii::Patterns::Double(1.0, dealii::Patterns::Double::max_double_value),
48  "maximum anisotropic ratio for continuous size field targets.");
49 
50  prm.declare_entry("anisotropic_ratio_min", "1.0e-12",
51  dealii::Patterns::Double(dealii::Patterns::Double::min_double_value, 1.0),
52  "miniumum anistropic ratio for continuous size field targets.");
53 
54  prm.declare_entry("anisotropic_threshold_ratio", "3.0",
55  dealii::Patterns::Double(1.0, dealii::Patterns::Double::max_double_value),
56  "Threshold for flagging cells with anisotropic refinement.");
57 
58  prm.declare_entry("anisotropic_indicator", "jump_based",
59  dealii::Patterns::Selection(
60  " jump_based | "
61  " reconstruction_based"),
62  "Enum of anisotropic indicators (unused for isotropic refinement)."
63  "Choices are "
64  " <jump_based | "
65  " reconstruction_based>.");
66 
67  prm.declare_entry("error_indicator", "error_based",
68  dealii::Patterns::Selection(
69  " error_based | "
70  " hessian_based | "
71  " residual_based | "
72  " adjoint_based"),
73  "Enum of error indicators (unused for uniform refinement)."
74  "Choices are "
75  " <error_based | "
76  " hessian_based | "
77  " residual_based | "
78  " adjoint_based>.");
79 
80  prm.declare_entry("output_type", "msh_out",
81  dealii::Patterns::Selection(
82  " gmsh_out | "
83  " msh_out"),
84  "Enum of output data types (for interface with mesh generators)."
85  "Choices are "
86  " <gmsh_out | "
87  " msh_out>.");
88 
89  prm.declare_entry("output_data_type", "size_field",
90  dealii::Patterns::Selection(
91  " size_field | "
92  " frame_field | "
93  " metric_field"),
94  "Enum of output data types of refinement indicator (used for msh_out only currently)."
95  "Choices are "
96  " <size_field | "
97  " frame_field | "
98  " metric_field>.");
99 
100  prm.declare_entry("norm_Lq", "2.0",
101  dealii::Patterns::Double(1.0, dealii::Patterns::Double::max_double_value),
102  "Degree of q for use in the Lq norm of some indicators.");
103 
104  prm.declare_entry("refinement_fraction", "0.3",
105  dealii::Patterns::Double(0.0, 1.0),
106  "Fraction of elements to undergo refinement for fixed_fraction method.");
107 
108  prm.declare_entry("coarsening_fraction", "0.03",
109  dealii::Patterns::Double(0.0, 1.0),
110  "Fraction of elements to undergo coarsening for fixed_fraction method.");
111 
112  prm.declare_entry("r_max", "20",
113  dealii::Patterns::Double(1.0, dealii::Patterns::Double::max_double_value),
114  "Maximum refinement factor for adjoint-based size-field (from log DWR).");
115 
116  prm.declare_entry("c_max", "4",
117  dealii::Patterns::Double(1.0, dealii::Patterns::Double::max_double_value),
118  "Maximum coarsening factor for adjoint-based size-field (from log DWR).");
119 
120  prm.declare_entry("complexity_scale", "2.0",
121  dealii::Patterns::Double(),
122  "Scaling factor multiplying previous complexity.");
123 
124  prm.declare_entry("complexity_add", "0.0",
125  dealii::Patterns::Double(),
126  "Constant added to the complexity at each step.");
127 
128  prm.declare_entry("complexity_vector", "[]",
129  dealii::Patterns::Anything(),
130  "Stores an initial vector of values for complexity targets. "
131  "Will iterate over and then switch to scaling and adding. "
132  "Formatted in square brackets and seperated by commas, eg. \"[1000,2000]\"");
133 
134  prm.declare_entry("exit_after_refine", "false",
135  dealii::Patterns::Bool(),
136  "Option to exit after call to the grid refinement (for debugging mesh write).");
137 
138  // }
139  // prm.leave_subsection();
140 }
141 
142 void GridRefinementParam::parse_parameters(dealii::ParameterHandler &prm)
143 {
144  // prm.enter_subsection("grid refinement");
145  {
146  refinement_steps = prm.get_integer("refinement_steps");
147 
148  const std::string refinement_method_string = prm.get("refinement_method");
149  if(refinement_method_string == "uniform") {refinement_method = RefinementMethod::uniform;}
150  else if(refinement_method_string == "fixed_fraction"){refinement_method = RefinementMethod::fixed_fraction;}
151  else if(refinement_method_string == "continuous") {refinement_method = RefinementMethod::continuous;}
152 
153  const std::string refinement_type_string = prm.get("refinement_type");
154  if(refinement_type_string == "h") {refinement_type = RefinementType::h;}
155  else if(refinement_type_string == "p") {refinement_type = RefinementType::p;}
156  else if(refinement_type_string == "hp"){refinement_type = RefinementType::hp;}
157 
158  anisotropic = prm.get_bool("anisotropic");
159 
160  anisotropic_ratio_max = prm.get_double("anisotropic_ratio_max");
161  anisotropic_ratio_min = prm.get_double("anisotropic_ratio_min");
162 
163  anisotropic_threshold_ratio = prm.get_double("anisotropic_threshold_ratio");
164 
165  const std::string anisotropic_indicator_string = prm.get("anisotropic_indicator");
166  if(anisotropic_indicator_string == "jump_based") {anisotropic_indicator = AnisoIndicator::jump_based;}
167  else if(anisotropic_indicator_string == "reconstruction_based"){anisotropic_indicator = AnisoIndicator::reconstruction_based;}
168 
169  const std::string error_indicator_string = prm.get("error_indicator");
170  if(error_indicator_string == "error_based") {error_indicator = ErrorIndicator::error_based;}
171  else if(error_indicator_string == "hessian_based") {error_indicator = ErrorIndicator::hessian_based;}
172  else if(error_indicator_string == "residual_based"){error_indicator = ErrorIndicator::residual_based;}
173  else if(error_indicator_string == "adjoint_based") {error_indicator = ErrorIndicator::adjoint_based;}
174 
175  const std::string output_type_string = prm.get("output_type");
176  if(output_type_string == "gmsh_out") {output_type = OutputType::gmsh_out;}
177  else if(output_type_string == "msh_out") {output_type = OutputType::msh_out;}
178 
179  const std::string output_data_type_string = prm.get("output_data_type");
180  if(output_data_type_string == "size_field") {output_data_type = OutputDataType::size_field;}
181  else if(output_data_type_string == "frame_field") {output_data_type = OutputDataType::frame_field;}
182  else if(output_data_type_string == "metric_field") {output_data_type = OutputDataType::metric_field;}
183 
184  norm_Lq = prm.get_double("norm_Lq");
185  refinement_fraction = prm.get_double("refinement_fraction");
186  coarsening_fraction = prm.get_double("coarsening_fraction");
187 
188  r_max = prm.get_double("r_max");
189  c_max = prm.get_double("c_max");
190 
191  complexity_scale = prm.get_double("complexity_scale");
192  complexity_add = prm.get_double("complexity_add");
193 
194  std::string complexity_string = prm.get("complexity_vector");
195 
196  // remove formatting
197  std::string removeChars = "[]";
198  for(unsigned int i = 0; i < removeChars.length(); ++i)
199  complexity_string.erase(std::remove(complexity_string.begin(), complexity_string.end(), removeChars.at(i)), complexity_string.end());
200  std::vector<std::string> complexity_string_vector = dealii::Utilities::split_string_list(complexity_string);
201 
202  // pushing into a vector
203  for(auto entry : complexity_string_vector)
204  complexity_vector.push_back(dealii::Utilities::string_to_int(entry));
205 
206  exit_after_refine = prm.get_bool("exit_after_refine");
207  }
208  // prm.leave_subsection();
209 }
210 
211 } // Parameters namespace
212 
213 } // PHiLiP namespace
RefinementType refinement_type
Selected type of refinement to be performed.
double r_max
refinement factor for log DWR size field
Files for the baseline physics.
Definition: ADTypes.hpp:10
AnisoIndicator anisotropic_indicator
Selected anisotropic splitting indicator.
double coarsening_fraction
coarsening fraction for fixed-fraction methods
ErrorIndicator error_indicator
Selected error indicator type.
bool anisotropic
Flag for performing anisotropic refinement.
void parse_parameters(dealii::ParameterHandler &prm)
Parses input file and sets the variables.
double anisotropic_threshold_ratio
threshold value in anisotropic indicator to enable anisotropic splitting
RefinementMethod refinement_method
Selected method of refinement.
double norm_Lq
Lq norm exponent selection.
unsigned int refinement_steps
Number of refinement steps to be performed.
double complexity_add
additive constant to complexity between grid refinement iterations
bool exit_after_refine
Flag to exit after call to refinement.
OutputDataType output_data_type
Selected data storage type.
double anisotropic_ratio_max
Maximum anisotropic ratio for continuous size field targets.
double refinement_fraction
refinement fraction for fixed-fraction methods
static void declare_parameters(dealii::ParameterHandler &prm)
Declares the possible variables and sets the defaults.
double anisotropic_ratio_min
Minimum anisotropic ratio for continuous zie field targets.
std::vector< double > complexity_vector
Vector of complexities to be used for initial continuous grid refinement iterations.
double complexity_scale
multiplier to complexity between grid refinement iterations
OutputType output_type
Selected file output type.
double c_max
coarsening factor for log DWR size field