PRISMS-PF Manual v3.0-pre
Loading...
Searching...
No Matches
userInputParameters.h
1// Class to load in the user input from parameters.h and the variable definition
2// part of equations.h
3
4#ifndef INCLUDE_USERINPUTPARAMETERS_H_
5#define INCLUDE_USERINPUTPARAMETERS_H_
6
7#include <deal.II/base/conditional_ostream.h>
8#include <deal.II/base/point.h>
9#include <deal.II/lac/la_parallel_vector.h>
10#include <deal.II/lac/vector.h>
11
12#include <boost/algorithm/string.hpp>
13#include <boost/algorithm/string/predicate.hpp>
14#include <boost/unordered_map.hpp>
15#include <boost/variant.hpp>
16
17#include <core/boundary_conditions/varBCs.h>
18#include <core/exceptions.h>
19#include <core/inputFileReader.h>
20#include <core/model_variables.h>
21#include <core/refinement/RefinementCriterion.h>
22#include <core/solvers/SolverParameters.h>
23#include <core/variableAttributes.h>
24#include <nucleation/nucleationParameters.h>
25#include <unordered_map>
26#include <vector>
27
28template <int dim>
29using InputVariant = boost::variant<double,
30 int,
31 bool,
32 dealii::Tensor<1, dim>,
33 dealii::Tensor<2, dim>,
34 dealii::Tensor<2, 2 * dim - 1 + dim / 3>>;
35
36enum elasticityModel
37{
38 ISOTROPIC,
39 TRANSVERSE,
40 ORTHOTROPIC,
41 ANISOTROPIC,
42 ANISOTROPIC2D
43};
44
45template <int dim>
47{
48public:
53 userInputParameters(inputFileReader &input_file_reader,
54 dealii::ParameterHandler &parameter_handler);
55
59 void
60 load_BC_list(const std::vector<std::string> &list_of_BCs);
61
66 void
67 assign_boundary_conditions(std::vector<std::string> &boundary_condition_list,
68 varBCs<dim> &boundary_condition);
69
76 [[nodiscard]] double
77 get_model_constant_double(const std::string &constant_name) const
78 {
79 Assert(model_constants.find(constant_name) != model_constants.end(),
80 dealii::ExcMessage(
81 "PRISMS-PF Error: Mismatch between constants in parameters.prm and "
82 "customPDE.h. The constant that you attempted to access was " +
83 constant_name + "."));
84
85 return boost::get<double>(model_constants.at(constant_name));
86 };
87
94 [[nodiscard]] int
95 get_model_constant_int(const std::string &constant_name) const
96 {
97 Assert(model_constants.find(constant_name) != model_constants.end(),
98 dealii::ExcMessage(
99 "PRISMS-PF Error: Mismatch between constants in parameters.prm and "
100 "customPDE.h. The constant that you attempted to access was " +
101 constant_name + "."));
102
103 return boost::get<int>(model_constants.at(constant_name));
104 };
105
112 [[nodiscard]] bool
113 get_model_constant_bool(const std::string &constant_name) const
114 {
115 Assert(model_constants.find(constant_name) != model_constants.end(),
116 dealii::ExcMessage(
117 "PRISMS-PF Error: Mismatch between constants in parameters.prm and "
118 "customPDE.h. The constant that you attempted to access was " +
119 constant_name + "."));
120
121 return boost::get<bool>(model_constants.at(constant_name));
122 };
123
130 [[nodiscard]] dealii::Tensor<1, dim>
131 get_model_constant_rank_1_tensor(const std::string &constant_name) const
132 {
133 Assert(model_constants.find(constant_name) != model_constants.end(),
134 dealii::ExcMessage(
135 "PRISMS-PF Error: Mismatch between constants in parameters.prm and "
136 "customPDE.h. The constant that you attempted to access was " +
137 constant_name + "."));
138
139 return boost::get<dealii::Tensor<1, dim>>(model_constants.at(constant_name));
140 };
141
148 [[nodiscard]] dealii::Tensor<2, dim>
149 get_model_constant_rank_2_tensor(const std::string &constant_name) const
150 {
151 Assert(model_constants.find(constant_name) != model_constants.end(),
152 dealii::ExcMessage(
153 "PRISMS-PF Error: Mismatch between constants in parameters.prm and "
154 "customPDE.h. The constant that you attempted to access was " +
155 constant_name + "."));
156
157 return boost::get<dealii::Tensor<2, dim>>(model_constants.at(constant_name));
158 };
159
166 [[nodiscard]] dealii::Tensor<2, 2 * dim - 1 + dim / 3>
167 get_model_constant_elasticity_tensor(const std::string &constant_name) const
168 {
169 Assert(model_constants.find(constant_name) != model_constants.end(),
170 dealii::ExcMessage(
171 "PRISMS-PF Error: Mismatch between constants in parameters.prm and "
172 "customPDE.h. The constant that you attempted to access was " +
173 constant_name + "."));
174
175 return boost::get<dealii::Tensor<2, 2 * dim - 1 + dim / 3>>(
176 model_constants.at(constant_name));
177 };
178
179 // Method to load in the variable attributes
180 void
181 loadVariableAttributes();
182
183 // Nucleation attribute methods
184 [[nodiscard]] std::vector<double>
185 get_nucleus_semiaxes(unsigned int var_index) const
186 {
187 return nucleation_parameters_list[nucleation_parameters_list_index.at(var_index)]
188 .semiaxes;
189 };
190
191 [[nodiscard]] std::vector<double>
192 get_nucleus_freeze_semiaxes(unsigned int var_index) const
193 {
194 return nucleation_parameters_list[nucleation_parameters_list_index.at(var_index)]
195 .freeze_semiaxes;
196 };
197
198 [[nodiscard]] std::vector<double>
199 get_nucleus_rotation(unsigned int var_index) const
200 {
201 return nucleation_parameters_list[nucleation_parameters_list_index.at(var_index)]
202 .ellipsoid_rotation;
203 };
204
205 [[nodiscard]] double
206 get_no_nucleation_border_thickness(unsigned int var_index) const
207 {
208 return nucleation_parameters_list[nucleation_parameters_list_index.at(var_index)]
209 .no_nucleation_border_thickness;
210 };
211
212 [[nodiscard]] double
213 get_nucleus_hold_time(unsigned int var_index) const
214 {
215 return nucleation_parameters_list[nucleation_parameters_list_index.at(var_index)]
216 .hold_time;
217 };
218
219 dealii::Tensor<2, dim, double>
220 get_nucleus_rotation_matrix(unsigned int var_index) const
221 {
222 return nucleation_parameters_list[nucleation_parameters_list_index.at(var_index)]
223 .rotation_matrix;
224 };
225
226 // Meshing parameters
227 std::vector<double> domain_size;
228 std::vector<unsigned int> subdivisions;
229 unsigned int refine_factor;
230 unsigned int degree;
231
232 // Mesh refinement parameters
233 bool h_adaptivity;
234 unsigned int max_refinement_level;
235 unsigned int min_refinement_level;
236 unsigned int skip_remeshing_steps;
237 std::vector<RefinementCriterion> refinement_criteria;
238
239 // Output parameters
240 unsigned int skip_print_steps;
241 std::string output_file_type;
242 bool output_vtu_per_process;
243 std::string output_file_name;
244 std::vector<unsigned int> outputTimeStepList;
245 bool print_timing_with_output;
246
247 // Time step parameters
248 double dtValue;
249 double finalTime;
250 unsigned int totalIncrements;
251
252 // Elliptic solver parameters
253 LinearSolverParameters linear_solver_parameters;
254
255 // Nonlinear solver parameters
256 NonlinearSolverParameters nonlinear_solver_parameters;
257
258 // Pinning point parameters
259 boost::unordered_map<unsigned int, dealii::Point<dim>> pinned_point;
260
261 // Variable inputs (I might be able to leave some/all of these in
262 // variable_attributes)
263 const AttributesList &var_attributes;
264 const AttributesList &pp_attributes;
265
266 // Variables needed to calculate the RHS
267 unsigned int num_var_explicit_RHS, num_var_nonexplicit_RHS;
268 std::vector<variable_info> varInfoListExplicitRHS, varInfoListNonexplicitRHS;
269
270 // Variables needed to calculate the LHS
271 unsigned int num_var_LHS;
272 std::vector<variable_info> varInfoListLHS;
273 std::vector<variable_info> varChangeInfoListLHS;
274
275 // Variables for loading in initial conditions
276 std::vector<bool> load_ICs;
277 std::vector<bool> load_parallel_file;
278 std::vector<std::string> load_file_name;
279 std::vector<std::string> load_field_name;
280
281 // Variables for saving/loading checkpoints
282 bool resume_from_checkpoint;
283 std::vector<unsigned int> checkpointTimeStepList;
284
285 // Postprocessing parameters
286 unsigned int num_integrated_fields;
287 bool postProcessingRequired;
288 std::vector<unsigned int> integrated_field_indices;
289
290 // Variable and residual info
291 std::vector<variable_info> pp_varInfoList;
292 std::vector<variable_info> pp_baseVarInfoList;
293
294 // List of boundary conditions
295 std::vector<varBCs<dim>> BC_list;
296
297 // List of user-defined constants
298 std::map<std::string, InputVariant<dim>> model_constants;
299
300 // Nucleation parameters
301 bool nucleation_occurs;
302 std::vector<unsigned int> nucleating_variable_indices;
303 std::vector<unsigned int> nucleation_need_value;
304 bool evolution_before_nucleation;
305 // Declare later
306 // bool multiple_nuclei_per_order_parameter;
307 double min_distance_between_nuclei; // Only enforced for nuclei placed during
308 // the same time step
309 double nucleation_order_parameter_cutoff;
310 unsigned int steps_between_nucleation_attempts;
311 double nucleation_start_time;
312 double nucleation_end_time;
313
314 // Grain remapping parameters
315 bool grain_remapping_activated;
316 std::vector<unsigned int> variables_for_remapping; // Note: this should be a sorted list
317 unsigned int skip_grain_reassignment_steps;
318 double order_parameter_threshold;
319 double buffer_between_grains;
320
321 bool load_grain_structure;
322 std::string load_vtk_file_type; // adding this string to know what type of vtk file you
323 // want to read, it will be passed to
324 // initialconditions.cc
325 double min_radius_for_loading_grains;
326 std::string grain_structure_filename;
327 std::string grain_structure_variable_name;
328 unsigned int num_grain_smoothing_cycles;
329
330private:
335 void
336 assign_spatial_discretization_parameters(dealii::ParameterHandler &parameter_handler);
337
342 void
343 assign_temporal_discretization_parameters(dealii::ParameterHandler &parameter_handler);
348 void
349 assign_linear_solve_parameters(dealii::ParameterHandler &parameter_handler);
350
355 void
356 assign_nonlinear_solve_parameters(dealii::ParameterHandler &parameter_handler);
357
362 void
363 assign_output_parameters(dealii::ParameterHandler &parameter_handler);
364
369 void
370 assign_load_initial_condition_parameters(dealii::ParameterHandler &parameter_handler);
371
376 void
377 assign_nucleation_parameters(dealii::ParameterHandler &parameter_handler);
378
383 void
384 assign_grain_parameters(dealii::ParameterHandler &parameter_handler);
385
390 void
391 assign_boundary_condition_parameters(dealii::ParameterHandler &parameter_handler);
392
393 // Method to create the list of time steps where the results should be output
394 // (called from loadInputParameters)
395 std::vector<unsigned int>
396 setTimeStepList(const std::string &outputSpacingType,
397 unsigned int numberOfOutputs,
398 const std::vector<unsigned int> &userGivenTimeStepList);
399
400 void
401 load_model_constants(inputFileReader &input_file_reader,
402 dealii::ParameterHandler &parameter_handler);
403
407 unsigned int
408 compute_tensor_parentheses(const unsigned int n_elements,
409 const std::vector<std::string> &tensor_elements);
410
414 void
415 remove_parentheses(std::vector<std::string> &tensor_elements);
416
420 dealii::Tensor<1, dim>
421 compute_rank_1_tensor_constant(const unsigned int n_elements,
422 std::vector<std::string> tensor_elements);
423
427 dealii::Tensor<2, dim>
428 compute_rank_2_tensor_constant(const unsigned int n_elements,
429 std::vector<std::string> tensor_elements);
430
434 InputVariant<dim>
435 construct_user_constant(std::vector<std::string> &model_constants_strings);
436
440 InputVariant<dim>
441 primitive_model_constant(std::vector<std::string> &model_constants_strings);
442
443 [[nodiscard]] dealii::Tensor<2, 2 * dim - 1 + dim / 3>
444 get_Cij_tensor(std::vector<double> elastic_constants,
445 const std::string &elastic_const_symmetry) const;
446
447 dealii::Tensor<2, 2 * dim - 1 + dim / 3>
448 getCIJMatrix(const elasticityModel model,
449 const std::vector<double> &constants,
450 dealii::ConditionalOStream &pcout) const;
451
452 // Private nucleation variables
453 std::vector<nucleationParameters<dim>> nucleation_parameters_list;
454 std::map<unsigned int, unsigned int> nucleation_parameters_list_index;
455};
456
457#endif /* INCLUDE_USERINPUTPARAMETERS_H_ */
Definition SolverParameters.h:55
Definition SolverParameters.h:84
Parameters file reader. Declares parameter names in a dealii parameter_handler and parses the file fo...
Definition inputFileReader.h:18
Definition userInputParameters.h:47
dealii::Tensor< 1, dim > get_model_constant_rank_1_tensor(const std::string &constant_name) const
Retrieve the rank 1 tensor from the model_constants that are defined from the parameters....
Definition userInputParameters.h:131
bool get_model_constant_bool(const std::string &constant_name) const
Retrieve the bool from the model_constants that are defined from the parameters.prm parser....
Definition userInputParameters.h:113
void load_BC_list(const std::vector< std::string > &list_of_BCs)
Creates a list of BCs to store in BC_list object.
Definition userInputParameters.cc:988
dealii::Tensor< 2, dim > get_model_constant_rank_2_tensor(const std::string &constant_name) const
Retrieve the rank 2 tensor from the model_constants that are defined from the parameters....
Definition userInputParameters.h:149
int get_model_constant_int(const std::string &constant_name) const
Retrieve the int from the model_constants that are defined from the parameters.prm parser....
Definition userInputParameters.h:95
double get_model_constant_double(const std::string &constant_name) const
Retrieve the double from the model_constants that are defined from the parameters....
Definition userInputParameters.h:77
dealii::Tensor< 2, 2 *dim - 1+dim/3 > get_model_constant_elasticity_tensor(const std::string &constant_name) const
Retrieve the elasticity tensor from the model_constants that are defined from the parameters....
Definition userInputParameters.h:167
void assign_boundary_conditions(std::vector< std::string > &boundary_condition_list, varBCs< dim > &boundary_condition)
Assign the boundary condition to the varBC<dim> object given some boundary condition string vector.
Definition userInputParameters.cc:919
Definition varBCs.h:26