www.mooseframework.org
MaterialTimeStepPostprocessor.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
23 
24 InputParameters
26 {
27  InputParameters params = ElementPostprocessor::validParams();
28 
29  params.addClassDescription("This postprocessor estimates a timestep that reduces the increment "
30  "change in a material property below a given threshold.");
31 
32  params.addParam<bool>("use_material_timestep_limit",
33  true,
34  "if true, the time step is limited by the minimum value of the "
35  "matl_timestep_limit property");
36 
37  params.addParam<MaterialPropertyName>("elements_changed_property",
38  "Name of the material property used to limit the time step "
39  "if its value changes by more than "
40  "'elements_changed_threshold' in at least "
41  "'elements_changed' elements");
42 
43  params.addRangeCheckedParam<int>("elements_changed",
44  "elements_changed > 0",
45  "Maximum number of elements within which the property named in "
46  "'elements_changed_property' is allowed to change by more than "
47  "'elements_changed_threshold' before the time step is limited.");
48 
49  params.addRangeCheckedParam<Real>("elements_changed_threshold",
50  "elements_changed_threshold' > 0",
51  "Maximum permitted change in the value of "
52  "'elements_changed_property' in 'elements_changed' elements "
53  "before the time step is limited.");
54 
55  return params;
56 }
57 
59  : ElementPostprocessor(parameters),
60  _use_material_timestep_limit(getParam<bool>("use_material_timestep_limit")),
61  _matl_time_step(_use_material_timestep_limit
62  ? &getMaterialPropertyByName<Real>("matl_timestep_limit")
63  : nullptr),
64  _matl_value(std::numeric_limits<Real>::max()),
65  _use_elements_changed(parameters.isParamSetByUser("elements_changed_property")),
66  _changed_property(_use_elements_changed
67  ? &getMaterialPropertyByName<Real>(
68  getParam<MaterialPropertyName>("elements_changed_property"))
69  : nullptr),
70  _changed_property_old(_use_elements_changed
71  ? &getMaterialPropertyOldByName<Real>(
72  getParam<MaterialPropertyName>("elements_changed_property"))
73  : nullptr),
74  _elements_changed(isParamValid("elements_changed") ? getParam<int>("elements_changed") : 0),
75  _count(0),
76  _elements_changed_threshold(parameters.isParamSetByUser("elements_changed_threshold'")
77  ? getParam<Real>("elements_changed_threshold'")
78  : TOLERANCE * TOLERANCE),
79  _qp(0)
80 {
81  if (_use_elements_changed && !parameters.isParamSetByUser("elements_changed"))
82  paramError("elements_changed", "needs to be set when elements_changed_property is defined");
83 
85  mooseError("either use_material_timestep_limit needs to be true or elements_changed_property "
86  "defined");
87 }
88 
89 void
91 {
92  _matl_value = std::numeric_limits<Real>::max(); // start w/ the min
93  _count = 0;
94 }
95 
96 void
98 {
100  {
101  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
102  _matl_value = std::min(_matl_value, (*_matl_time_step)[_qp]);
103  }
104 
106  {
107  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
108  {
109  if (!MooseUtils::absoluteFuzzyEqual((*_changed_property)[_qp],
112  {
113  ++_count;
114  return;
115  }
116  }
117  }
118 }
119 
120 Real
122 {
123  gatherMin(_matl_value);
124  gatherSum(_count);
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 {
135  const MaterialTimeStepPostprocessor & pps = static_cast<const MaterialTimeStepPostprocessor &>(y);
137  _matl_value = std::min(_matl_value, pps._matl_value);
139  _count += pps._count;
140 }
MaterialTimeStepPostprocessor::_elements_changed
const int _elements_changed
Target number of changed elements used to determine if we need to change the time step.
Definition: MaterialTimeStepPostprocessor.h:53
MaterialTimeStepPostprocessor::validParams
static InputParameters validParams()
Definition: MaterialTimeStepPostprocessor.C:25
MaterialTimeStepPostprocessor::initialize
virtual void initialize()
Definition: MaterialTimeStepPostprocessor.C:90
MaterialTimeStepPostprocessor.h
MaterialTimeStepPostprocessor::_matl_time_step
const MaterialProperty< Real > * _matl_time_step
Pointer to the material property containing the time step limit.
Definition: MaterialTimeStepPostprocessor.h:39
defineLegacyParams
defineLegacyParams(MaterialTimeStepPostprocessor)
MaterialTimeStepPostprocessor::_qp
unsigned int _qp
Current quadrature point.
Definition: MaterialTimeStepPostprocessor.h:62
MaterialTimeStepPostprocessor::_changed_property
const MaterialProperty< Real > * _changed_property
Material property used to determine if elements have changed.
Definition: MaterialTimeStepPostprocessor.h:48
MaterialTimeStepPostprocessor::threadJoin
virtual void threadJoin(const UserObject &y)
Definition: MaterialTimeStepPostprocessor.C:133
MaterialTimeStepPostprocessor::_matl_value
Real _matl_value
Current time step limit from the material properties.
Definition: MaterialTimeStepPostprocessor.h:42
MaterialTimeStepPostprocessor::execute
virtual void execute()
Definition: MaterialTimeStepPostprocessor.C:97
MaterialTimeStepPostprocessor::_changed_property_old
const MaterialProperty< Real > * _changed_property_old
Definition: MaterialTimeStepPostprocessor.h:49
validParams
InputParameters validParams()
MaterialTimeStepPostprocessor::_use_elements_changed
const bool _use_elements_changed
Flag to limit the time step based on the number of elements changed.
Definition: MaterialTimeStepPostprocessor.h:45
MaterialTimeStepPostprocessor::_use_material_timestep_limit
const bool _use_material_timestep_limit
Flag to find the time step limit from material properties.
Definition: MaterialTimeStepPostprocessor.h:36
MaterialTimeStepPostprocessor::_elements_changed_threshold
const Real _elements_changed_threshold
Tolerance to determine if elements have changed.
Definition: MaterialTimeStepPostprocessor.h:59
registerMooseObject
registerMooseObject("TensorMechanicsApp", MaterialTimeStepPostprocessor)
MaterialTimeStepPostprocessor::_count
int _count
Current number of elements changed.
Definition: MaterialTimeStepPostprocessor.h:56
MaterialTimeStepPostprocessor::getValue
virtual Real getValue()
Definition: MaterialTimeStepPostprocessor.C:121
MaterialTimeStepPostprocessor
This postporocessor calculates an estimated timestep size that limits an auxiliary variable to below ...
Definition: MaterialTimeStepPostprocessor.h:23
MaterialTimeStepPostprocessor::MaterialTimeStepPostprocessor
MaterialTimeStepPostprocessor(const InputParameters &parameters)
Definition: MaterialTimeStepPostprocessor.C:58