https://mooseframework.inl.gov
MaterialTimeStepPostprocessor.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 #include "MooseVariable.h"
12 #include "SubProblem.h"
13 #include "MooseTypes.h"
14 
15 #include "libmesh/quadrature.h"
16 
17 #include <algorithm>
18 #include <limits>
19 
21 
24 {
26 
27  params.addClassDescription("This postprocessor estimates a timestep that reduces the increment "
28  "change in a material property below a given threshold.");
29 
30  params.addParam<bool>("use_material_timestep_limit",
31  true,
32  "if true, the time step is limited by the minimum value of the "
33  "material_timestep_limit property");
34 
35  params.addParam<MaterialPropertyName>("elements_changed_property",
36  "Name of the material property used to limit the time step "
37  "if its value changes by more than "
38  "'elements_changed_threshold' in at least "
39  "'elements_changed' elements");
40 
41  params.addRangeCheckedParam<int>("elements_changed",
42  "elements_changed > 0",
43  "Maximum number of elements within which the property named in "
44  "'elements_changed_property' is allowed to change by more than "
45  "'elements_changed_threshold' before the time step is limited.");
46 
47  params.addRangeCheckedParam<Real>("elements_changed_threshold",
48  "elements_changed_threshold' > 0",
49  "Maximum permitted change in the value of "
50  "'elements_changed_property' in 'elements_changed' elements "
51  "before the time step is limited.");
52  params.addRangeCheckedParam<Real>("maximum_value",
53  std::numeric_limits<Real>::max(),
54  "maximum_value>=0",
55  "Maximum value returned by this postprocessor.");
56 
57  return params;
58 }
59 
61  : ElementPostprocessor(parameters),
62  _use_material_timestep_limit(getParam<bool>("use_material_timestep_limit")),
63  _matl_time_step(_use_material_timestep_limit
64  ? &getMaterialPropertyByName<Real>("material_timestep_limit")
65  : nullptr),
66  _matl_value(getParam<Real>("maximum_value")),
67  _use_elements_changed(parameters.isParamSetByUser("elements_changed_property")),
68  _changed_property(_use_elements_changed
69  ? &getMaterialPropertyByName<Real>(
70  getParam<MaterialPropertyName>("elements_changed_property"))
71  : nullptr),
72  _changed_property_old(_use_elements_changed
73  ? &getMaterialPropertyOldByName<Real>(
74  getParam<MaterialPropertyName>("elements_changed_property"))
75  : nullptr),
76  _elements_changed(isParamValid("elements_changed") ? getParam<int>("elements_changed") : 0),
77  _count(0),
78  _elements_changed_threshold(parameters.isParamSetByUser("elements_changed_threshold'")
79  ? getParam<Real>("elements_changed_threshold'")
80  : TOLERANCE * TOLERANCE),
81  _max(getParam<Real>("maximum_value")),
82  _qp(0)
83 {
84  if (_use_elements_changed && !parameters.isParamSetByUser("elements_changed"))
85  paramError("elements_changed", "needs to be set when elements_changed_property is defined");
86 
88  mooseError("either use_material_timestep_limit needs to be true or elements_changed_property "
89  "defined");
90 }
91 
92 void
94 {
95  _matl_value = _max; // start w/ the maximum allowed value
96  _count = 0;
97 }
98 
99 void
101 {
103  {
104  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
105  _matl_value = std::min(_matl_value, (*_matl_time_step)[_qp]);
106  }
107 
109  {
110  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
111  {
115  {
116  ++_count;
117  return;
118  }
119  }
120  }
121 }
122 
123 Real
125 {
126  if (_count == 0 || !_use_elements_changed)
127  return _matl_value;
128 
129  return std::min(_dt * (Real)_elements_changed / (Real)_count, _matl_value);
130 }
131 
132 void
134 {
136  gatherSum(_count);
137 }
138 
139 void
141 {
142  const auto & pps = static_cast<const MaterialTimeStepPostprocessor &>(y);
144  _matl_value = std::min(_matl_value, pps._matl_value);
146  _count += pps._count;
147 }
unsigned int _qp
Current quadrature point.
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual void threadJoin(const UserObject &y) override
virtual Real getValue() const override
MaterialTimeStepPostprocessor(const InputParameters &parameters)
static InputParameters validParams()
registerMooseObject("SolidMechanicsApp", MaterialTimeStepPostprocessor)
const std::vector< double > y
void gatherMin(T &value)
Real _matl_value
Current time step limit from the material properties.
void gatherSum(T &value)
const bool _use_material_timestep_limit
Flag to find the time step limit from material properties.
int _count
Current number of elements changed.
void paramError(const std::string &param, Args... args) const
bool isParamSetByUser(const std::string &name) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
const Real _max
Maximum allowed value.
This postporocessor calculates an estimated timestep size that limits an auxiliary variable to below ...
const bool _use_elements_changed
Flag to limit the time step based on the number of elements changed.
const int _elements_changed
Target number of changed elements used to determine if we need to change the time step...
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
const InputParameters & parameters() const
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const MaterialProperty< Real > *const _changed_property
Material property used to determine if elements have changed.
const Real _elements_changed_threshold
Tolerance to determine if elements have changed.
const MaterialProperty< Real > *const _changed_property_old
void ErrorVector unsigned int
const MaterialProperty< Real > *const _matl_time_step
Pointer to the material property containing the time step limit.