www.mooseframework.org
AdaptivityAction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "AdaptivityAction.h"
16 
17 #ifdef LIBMESH_ENABLE_AMR
18 
19 #include "FEProblem.h"
20 #include "NonlinearSystemBase.h"
21 #include "Adaptivity.h"
22 #include "Executioner.h"
23 #include "MooseEnum.h"
24 #include "MooseVariable.h"
25 
26 #include "libmesh/transient_system.h"
27 #include "libmesh/system_norm.h"
28 
29 template <>
32 {
34  MooseEnum estimators("KellyErrorEstimator LaplacianErrorEstimator PatchRecoveryErrorEstimator",
35  "KellyErrorEstimator");
36 
37  params.addParam<unsigned int>(
38  "steps", 0, "The number of adaptivity steps to perform at any one time for steady state");
39  params.addRangeCheckedParam<unsigned int>(
40  "interval", 1, "interval>0", "The number of time steps betweeen each adaptivity phase");
41  params.addParam<unsigned int>(
42  "initial_adaptivity",
43  0,
44  "The number of adaptivity steps to perform using the initial conditions");
45  params.addParam<Real>("refine_fraction",
46  0.0,
47  "The fraction of elements or error to refine. Should be between 0 and 1.");
48  params.addParam<Real>("coarsen_fraction",
49  0.0,
50  "The fraction of elements or error to coarsen. Should be between 0 and 1.");
51  params.addParam<unsigned int>(
52  "max_h_level",
53  0,
54  "Maximum number of times a single element can be refined. If 0 then infinite.");
55  params.addParam<MooseEnum>(
56  "error_estimator", estimators, "The class name of the error estimator you want to use.");
57  params.addDeprecatedParam<bool>(
58  "print_changed_info",
59  false,
60  "Determines whether information about the mesh is printed when adaptivity occurs",
61  "Use the Console output parameter 'print_mesh_changed_info'");
62  params.addParam<Real>("start_time",
63  -std::numeric_limits<Real>::max(),
64  "The time that adaptivity will be active after.");
65  params.addParam<Real>("stop_time",
66  std::numeric_limits<Real>::max(),
67  "The time after which adaptivity will no longer be active.");
68  params.addParam<std::vector<std::string>>(
69  "weight_names", "List of names of variables that will be associated with weight_values");
70  params.addParam<std::vector<Real>>(
71  "weight_values",
72  "List of values between 0 and 1 to weight the associated weight_names error by");
73  params.addParam<unsigned int>("cycles_per_step", 1, "The number of adaptivity cycles per step");
74 
75  params.addParam<bool>(
76  "show_initial_progress", true, "Show the progress of the initial adaptivity");
77  params.addParam<bool>(
78  "recompute_markers_during_cycles", false, "Recompute markers during adaptivity cycles");
79  return params;
80 }
81 
83 
84 void
86 {
87  NonlinearSystemBase & system = _problem->getNonlinearSystemBase();
88 
89  Adaptivity & adapt = _problem->adaptivity();
90 
91  adapt.init(getParam<unsigned int>("steps"), getParam<unsigned int>("initial_adaptivity"));
92 
93  adapt.setErrorEstimator(getParam<MooseEnum>("error_estimator"));
94 
95  adapt.setParam("cycles_per_step", getParam<unsigned int>("cycles_per_step"));
96  adapt.setParam("refine fraction", getParam<Real>("refine_fraction"));
97  adapt.setParam("coarsen fraction", getParam<Real>("coarsen_fraction"));
98  adapt.setParam("max h-level", getParam<unsigned int>("max_h_level"));
99  adapt.setParam("recompute_markers_during_cycles",
100  getParam<bool>("recompute_markers_during_cycles"));
101 
102  adapt.setPrintMeshChanged(getParam<bool>("print_changed_info"));
103 
104  const std::vector<std::string> & weight_names =
105  getParam<std::vector<std::string>>("weight_names");
106  const std::vector<Real> & weight_values = getParam<std::vector<Real>>("weight_values");
107 
108  int num_weight_names = weight_names.size();
109  int num_weight_values = weight_values.size();
110 
111  if (num_weight_names)
112  {
113  if (num_weight_names != num_weight_values)
114  mooseError("Number of weight_names must be equal to number of weight_values in "
115  "Execution/Adaptivity");
116 
117  // If weights have been specified then set the default weight to zero
118  std::vector<Real> weights(system.nVariables(), 0);
119 
120  for (int i = 0; i < num_weight_names; i++)
121  {
122  std::string name = weight_names[i];
123  double value = weight_values[i];
124 
125  weights[system.getVariable(0, name).number()] = value;
126  }
127 
128  std::vector<FEMNormType> norms(system.nVariables(), H1_SEMINORM);
129 
130  SystemNorm sys_norm(norms, weights);
131 
132  adapt.setErrorNorm(sys_norm);
133  }
134 
135  adapt.setTimeActive(getParam<Real>("start_time"), getParam<Real>("stop_time"));
136  adapt.setInterval(getParam<unsigned int>("interval"));
137 }
138 
139 #endif // LIBMESH_ENABLE_AMR
void setPrintMeshChanged(bool state=true)
Definition: Adaptivity.h:87
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
void setInterval(unsigned int interval)
Set the interval (number of timesteps) between refinement steps.
Definition: Adaptivity.h:223
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
void init(unsigned int steps, unsigned int initial_steps)
Initialize the initial adaptivity ;-)
Definition: Adaptivity.C:59
void setTimeActive(Real start_time, Real stop_time)
Sets the time when the adaptivity is active.
Definition: Adaptivity.C:251
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Base class for actions.
Definition: Action.h:39
Nonlinear system to be solved.
nl system()
virtual MooseVariable & getVariable(THREAD_ID tid, const std::string &var_name)
Gets a reference to a variable of with specified name.
Definition: SystemBase.C:103
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
void setErrorEstimator(const MooseEnum &error_estimator_name)
Set the error estimator.
Definition: Adaptivity.C:104
AdaptivityAction(InputParameters params)
InputParameters validParams< AdaptivityAction >()
unsigned int number() const
Get variable number coming from libMesh.
Takes care of everything related to mesh adaptivity.
Definition: Adaptivity.h:48
const std::string & name() const
The name of the action.
Definition: Action.h:51
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:131
void setErrorNorm(SystemNorm &sys_norm)
Set the error norm (FIXME: improve description)
Definition: Adaptivity.C:118
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
void setParam(const std::string &param_name, const T &param_value)
Set adaptivity parameter.
Definition: Adaptivity.h:307
virtual void act() override
virtual unsigned int nVariables()
Get the number of variables in this system.
Definition: SystemBase.C:580
InputParameters validParams< Action >()
Definition: Action.C:23