https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
ElementJacobianDamper Class Reference

This class implements a damper that limits the change in the Jacobian of elements. More...

#include <ElementJacobianDamper.h>

Inheritance diagram for ElementJacobianDamper:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 ElementJacobianDamper (const InputParameters &parameters)
 
virtual void initialSetup () override
 
virtual Real computeDamping (const NumericVector< Number > &, const NumericVector< Number > &update) override
 Computes this Damper's damping. More...
 
bool probeDamping (const NumericVector< Number > &update, Real damping, Real &max_difference, std::string &error_message)
 Probe a damped update on the displaced mesh and report the maximum relative change in JxW. More...
 
void checkMinDamping (const Real cur_damping) const
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
bool isKokkosObject () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool haveParameter (const std::string &name) const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
virtual void timestepSetup ()
 
virtual void jacobianSetup ()
 
virtual void residualSetup ()
 
virtual void subdomainSetup ()
 
virtual void customSetup (const ExecFlagType &)
 
const ExecFlagEnumgetExecuteOnEnum () const
 
virtual void meshChanged ()
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static InputParameters validParams ()
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 

Protected Member Functions

void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 
TdeclareRestartableData (const std::string &data_name, Args &&... args)
 
ManagedValue< TdeclareManagedRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
const TgetRestartableData (const std::string &data_name) const
 
TdeclareRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
TdeclareRecoverableData (const std::string &data_name, Args &&... args)
 
TdeclareRestartableDataWithObjectName (const std::string &data_name, const std::string &object_name, Args &&... args)
 
TdeclareRestartableDataWithObjectNameWithContext (const std::string &data_name, const std::string &object_name, void *context, Args &&... args)
 
std::string restartableName (const std::string &data_name) const
 

Protected Attributes

THREAD_ID _tid
 Thread ID. More...
 
Assembly_assembly
 
const QBase *const & _qrule
 Quadrature rule. More...
 
const MooseArray< Real > & _JxW
 Transformed Jacobian weights. More...
 
FEProblemBase_fe_problem
 The FE problem. More...
 
MooseSharedPointer< DisplacedProblem_displaced_problem
 The displaced problem. More...
 
MooseMesh_mesh
 The displaced mesh. More...
 
std::vector< MooseVariable * > _disp_var
 The displacement variables. More...
 
unsigned int _ndisp
 The number of displacement variables. More...
 
std::vector< VariableValue_disp_incr
 The current Newton increment in the displacement variables. More...
 
const Real _max_jacobian_diff
 Maximum allowed relative increment in Jacobian. More...
 
const bool _use_backtracking
 Whether to backtrack the trial update when probing would otherwise create a degenerate map. More...
 
const Real _backtrack_factor
 Multiplicative cutback applied during backtracking. More...
 
const unsigned int _max_backtrack_steps
 Maximum number of backtracking attempts. More...
 
SubProblem_subproblem
 
SystemBase_sys
 
const Real_min_damping
 
const bool & _enabled
 
MooseApp_app
 
Factory_factory
 
ActionFactory_action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters_pars
 
const ExecFlagEnum_execute_enum
 
const ExecFlagType_current_execute_flag
 
MooseApp_restartable_app
 
const std::string _restartable_system_name
 
const THREAD_ID _restartable_tid
 
const bool _restartable_read_only
 
FEProblemBase_mci_feproblem
 
const Parallel::Communicator & _communicator
 

Detailed Description

This class implements a damper that limits the change in the Jacobian of elements.

Definition at line 24 of file ElementJacobianDamper.h.

Constructor & Destructor Documentation

◆ ElementJacobianDamper()

ElementJacobianDamper::ElementJacobianDamper ( const InputParameters parameters)

Definition at line 66 of file ElementJacobianDamper.C.

68  _tid(parameters.get<THREAD_ID>("_tid")),
71  _JxW(_assembly.JxW()),
74  _max_jacobian_diff(getParam<Real>("max_increment")),
75  _use_backtracking(getParam<bool>("use_backtracking")),
76  _backtrack_factor(getParam<Real>("backtrack_factor")),
77  _max_backtrack_steps(getParam<unsigned int>("max_backtrack_steps"))
78 {
79  if (_displaced_problem == NULL)
80  mooseError("ElementJacobianDamper: Must use displaced problem");
81 
82  _mesh = &_displaced_problem->mesh();
83 
84  const std::vector<VariableName> & nl_vnames(getParam<std::vector<VariableName>>("displacements"));
85  _ndisp = nl_vnames.size();
86 
87  for (unsigned int i = 0; i < _ndisp; ++i)
88  {
89  _disp_var.push_back(&_sys.getFieldVariable<Real>(_tid, nl_vnames[i]));
90  _disp_incr.push_back(_disp_var.back()->increment());
91  }
92 }
const QBase *const & _qrule
Quadrature rule.
const T & getParam(const std::string &name) const
unsigned int _ndisp
The number of displacement variables.
const bool _use_backtracking
Whether to backtrack the trial update when probing would otherwise create a degenerate map...
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const InputParameters & parameters() const
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
MooseSharedPointer< DisplacedProblem > _displaced_problem
The displaced problem.
const unsigned int _max_backtrack_steps
Maximum number of backtracking attempts.
std::vector< VariableValue > _disp_incr
The current Newton increment in the displacement variables.
MooseMesh * _mesh
The displaced mesh.
const Real _max_jacobian_diff
Maximum allowed relative increment in Jacobian.
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
FEProblemBase & _fe_problem
The FE problem.
std::vector< MooseVariable * > _disp_var
The displacement variables.
unsigned int number() const
THREAD_ID _tid
Thread ID.
const MooseArray< Real > & JxW() const
virtual std::shared_ptr< const DisplacedProblem > getDisplacedProblem() const
MooseVariableFE< T > & getFieldVariable(THREAD_ID tid, const std::string &var_name)
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num)=0
void mooseError(Args &&... args) const
const Real _backtrack_factor
Multiplicative cutback applied during backtracking.
const libMesh::QBase *const & qRule() const
SubProblem & _subproblem
SystemBase & _sys
GeneralDamper(const InputParameters &parameters)
unsigned int THREAD_ID

Member Function Documentation

◆ computeDamping()

Real ElementJacobianDamper::computeDamping ( const NumericVector< Number > &  ,
const NumericVector< Number > &  update 
)
overridevirtual

Computes this Damper's damping.

Implements GeneralDamper.

Definition at line 100 of file ElementJacobianDamper.C.

102 {
103  auto probe_trial =
104  [&](const Real trial_damping, Real & max_difference, std::string & error_message)
105  {
106  const bool trial_nondegenerate_local =
107  probeDamping(update, trial_damping, max_difference, error_message);
108 
109  _communicator.max(max_difference);
110 
111  const unsigned int invalid_local = trial_nondegenerate_local ? 0 : 1;
112  unsigned int invalid = invalid_local;
113  _communicator.max(invalid);
114 
115  if (invalid)
116  {
117  processor_id_type first_invalid_processor =
118  invalid_local ? _communicator.rank() : std::numeric_limits<processor_id_type>::max();
119  _communicator.min(first_invalid_processor);
120  _communicator.broadcast(error_message, first_invalid_processor);
121  }
122 
123  return !invalid;
124  };
125 
126  if (!_use_backtracking)
127  {
128  Real max_difference = 0.0;
129  std::string error_message;
130 
131  PARALLEL_TRY
132  {
133  if (!probe_trial(/*trial_damping=*/1.0, max_difference, error_message))
134  _fe_problem.setException(error_message);
135  }
136  PARALLEL_CATCH;
137 
138  if (max_difference > _max_jacobian_diff)
139  return _max_jacobian_diff / max_difference;
140 
141  return 1.0;
142  }
143 
144  const Real minimum_trial_damping = std::max(_min_damping, std::numeric_limits<Real>::epsilon());
145  Real damping = 1.0;
146  std::string error_message;
147 
148  // Try 1 step, then at most max_backtrack_steps extra steps
149  for (unsigned int step = 0; step <= _max_backtrack_steps; ++step)
150  {
151  Real max_difference = 0.0;
152  bool trial_nondegenerate = false;
153 
154  PARALLEL_TRY { trial_nondegenerate = probe_trial(damping, max_difference, error_message); }
155  PARALLEL_CATCH;
156 
157  if (trial_nondegenerate && max_difference <= _max_jacobian_diff)
158  return damping;
159 
160  if (damping <= minimum_trial_damping || step == _max_backtrack_steps)
161  {
162  if (!trial_nondegenerate)
163  _fe_problem.setException(error_message.empty()
164  ? "ElementJacobianDamper could not find a nondegenerate "
165  "trial update."
166  : error_message);
167  else
168  _fe_problem.setException("ElementJacobianDamper could not reduce the relative Jacobian "
169  "increment below max_increment without driving the damping "
170  "factor below a usable threshold.");
171 
172  // The exception flag will abort the nonlinear step after the damper returns, so return the
173  // last trial damping only to satisfy the interface.
174  return damping;
175  }
176 
177  if (!trial_nondegenerate)
178  damping *= _backtrack_factor;
179  else
180  damping =
181  std::min(damping * _backtrack_factor, damping * _max_jacobian_diff / max_difference);
182  }
183 
184  return damping;
185 }
const bool _use_backtracking
Whether to backtrack the trial update when probing would otherwise create a degenerate map...
virtual void setException(const std::string &message)
processor_id_type rank() const
const unsigned int _max_backtrack_steps
Maximum number of backtracking attempts.
const Parallel::Communicator & _communicator
const Real _max_jacobian_diff
Maximum allowed relative increment in Jacobian.
uint8_t processor_id_type
FEProblemBase & _fe_problem
The FE problem.
void min(const T &r, T &o, Request &req) const
const Real & _min_damping
bool probeDamping(const NumericVector< Number > &update, Real damping, Real &max_difference, std::string &error_message)
Probe a damped update on the displaced mesh and report the maximum relative change in JxW...
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void max(const T &r, T &o, Request &req) const
const Real _backtrack_factor
Multiplicative cutback applied during backtracking.

◆ initialSetup()

void ElementJacobianDamper::initialSetup ( )
overridevirtual

Reimplemented from GeneralDamper.

Definition at line 95 of file ElementJacobianDamper.C.

96 {
97 }

◆ probeDamping()

bool ElementJacobianDamper::probeDamping ( const NumericVector< Number > &  update,
Real  damping,
Real max_difference,
std::string &  error_message 
)

Probe a damped update on the displaced mesh and report the maximum relative change in JxW.

Returns false if the trial update produces a degenerate map.

Definition at line 188 of file ElementJacobianDamper.C.

Referenced by computeDamping().

192 {
193  MooseArray<Real> JxW_displaced;
194 
195  // Vector for storing the original node coordinates
196  std::vector<Point> point_copies;
197 
198  max_difference = 0.0;
199  error_message.clear();
200 
201  try
202  {
203  // Loop over elements in the mesh
204  for (auto & current_elem : _mesh->getMesh().active_local_element_ptr_range())
205  {
206  point_copies.clear();
207  point_copies.reserve(current_elem->n_nodes());
208 
209  // Displace nodes with the trial Newton increment
210  for (unsigned int i = 0; i < current_elem->n_nodes(); ++i)
211  {
212  Node & displaced_node = current_elem->node_ref(i);
213 
214  point_copies.push_back(displaced_node);
215 
216  for (unsigned int j = 0; j < _ndisp; ++j)
217  {
218  const dof_id_type disp_dof_num =
219  displaced_node.dof_number(_sys.number(), _disp_var[j]->number(), 0);
220  displaced_node(j) += damping * update(disp_dof_num);
221  }
222  }
223 
224  try
225  {
226  // Reinit element to compute Jacobian of the trial displaced element
227  _assembly.reinit(current_elem);
228  JxW_displaced = _JxW;
229  }
230  catch (const std::exception & e)
231  {
232  restoreNodes(*current_elem, point_copies);
233 
234  // Degenerate-map failures mean this trial damping is too aggressive
235  if (strstr(e.what(), "Jacobian") || strstr(e.what(), "singular") ||
236  strstr(e.what(), "det != 0"))
237  {
238  error_message = e.what();
239  return false;
240  }
241 
242  throw;
243  }
244 
245  restoreNodes(*current_elem, point_copies);
246 
247  // Reinit element to compute Jacobian before displacement
248  try
249  {
250  _assembly.reinit(current_elem);
251  }
252  catch (const std::exception & e)
253  {
254  if (strstr(e.what(), "Jacobian") || strstr(e.what(), "singular") ||
255  strstr(e.what(), "det != 0"))
256  {
257  error_message = e.what();
258  return false;
259  }
260 
261  throw;
262  }
263 
264  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
265  {
266  const Real denominator = std::max(std::abs(_JxW[qp]), libMesh::TOLERANCE);
267  const Real diff = std::abs(JxW_displaced[qp] - _JxW[qp]) / denominator;
268  if (diff > max_difference)
269  max_difference = diff;
270  }
271 
272  JxW_displaced.release();
273  }
274  }
275  catch (const MooseException & e)
276  {
277  error_message = e.what();
279  return false;
280  }
281 
282  return true;
283 }
virtual const char * what() const
const QBase *const & _qrule
Quadrature rule.
unsigned int _ndisp
The number of displacement variables.
static constexpr Real TOLERANCE
virtual void setException(const std::string &message)
MooseMesh * _mesh
The displaced mesh.
void reinit(const Elem *elem)
const MooseArray< Real > & _JxW
Transformed Jacobian weights.
FEProblemBase & _fe_problem
The FE problem.
MeshBase & getMesh()
std::vector< MooseVariable * > _disp_var
The displacement variables.
unsigned int number() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
SystemBase & _sys
uint8_t dof_id_type

◆ validParams()

InputParameters ElementJacobianDamper::validParams ( )
static

Definition at line 38 of file ElementJacobianDamper.C.

39 {
41  params.addClassDescription("Damper that limits the change in element Jacobians");
42  params.addParam<std::vector<VariableName>>(
43  "displacements", {}, "The nonlinear displacement variables");
44  params.addParam<Real>(
45  "max_increment",
46  0.1,
47  "The maximum permissible relative increment in the Jacobian per Newton iteration");
48  params.addParam<bool>(
49  "use_backtracking",
50  false,
51  "If true, iteratively cut back the probed Newton update when a full trial update would "
52  "create a degenerate displaced element map. The accepted trial must also satisfy "
53  "max_increment.");
54  params.addRangeCheckedParam<Real>(
55  "backtrack_factor",
56  0.5,
57  "backtrack_factor > 0 & backtrack_factor < 1",
58  "Multiplicative cutback applied to the trial damping during ElementJacobianDamper "
59  "backtracking.");
60  params.addParam<unsigned int>(
61  "max_backtrack_steps", 12, "Maximum number of ElementJacobianDamper backtracking attempts.");
62  params.set<bool>("use_displaced_mesh") = true;
63  return params;
64 }
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addClassDescription(const std::string &doc_string)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)

Member Data Documentation

◆ _assembly

Assembly& ElementJacobianDamper::_assembly
protected

Definition at line 51 of file ElementJacobianDamper.h.

Referenced by probeDamping().

◆ _backtrack_factor

const Real ElementJacobianDamper::_backtrack_factor
protected

Multiplicative cutback applied during backtracking.

Definition at line 84 of file ElementJacobianDamper.h.

Referenced by computeDamping().

◆ _disp_incr

std::vector<VariableValue> ElementJacobianDamper::_disp_incr
protected

The current Newton increment in the displacement variables.

Definition at line 75 of file ElementJacobianDamper.h.

Referenced by ElementJacobianDamper().

◆ _disp_var

std::vector<MooseVariable *> ElementJacobianDamper::_disp_var
protected

The displacement variables.

Definition at line 69 of file ElementJacobianDamper.h.

Referenced by ElementJacobianDamper(), and probeDamping().

◆ _displaced_problem

MooseSharedPointer<DisplacedProblem> ElementJacobianDamper::_displaced_problem
protected

The displaced problem.

Definition at line 63 of file ElementJacobianDamper.h.

Referenced by ElementJacobianDamper().

◆ _fe_problem

FEProblemBase& ElementJacobianDamper::_fe_problem
protected

The FE problem.

Definition at line 60 of file ElementJacobianDamper.h.

Referenced by computeDamping(), and probeDamping().

◆ _JxW

const MooseArray<Real>& ElementJacobianDamper::_JxW
protected

Transformed Jacobian weights.

Definition at line 57 of file ElementJacobianDamper.h.

Referenced by probeDamping().

◆ _max_backtrack_steps

const unsigned int ElementJacobianDamper::_max_backtrack_steps
protected

Maximum number of backtracking attempts.

Definition at line 87 of file ElementJacobianDamper.h.

Referenced by computeDamping().

◆ _max_jacobian_diff

const Real ElementJacobianDamper::_max_jacobian_diff
protected

Maximum allowed relative increment in Jacobian.

Definition at line 78 of file ElementJacobianDamper.h.

Referenced by computeDamping().

◆ _mesh

MooseMesh* ElementJacobianDamper::_mesh
protected

The displaced mesh.

Definition at line 66 of file ElementJacobianDamper.h.

Referenced by ElementJacobianDamper(), and probeDamping().

◆ _ndisp

unsigned int ElementJacobianDamper::_ndisp
protected

The number of displacement variables.

Definition at line 72 of file ElementJacobianDamper.h.

Referenced by ElementJacobianDamper(), and probeDamping().

◆ _qrule

const QBase* const& ElementJacobianDamper::_qrule
protected

Quadrature rule.

Definition at line 54 of file ElementJacobianDamper.h.

Referenced by probeDamping().

◆ _tid

THREAD_ID ElementJacobianDamper::_tid
protected

Thread ID.

Definition at line 50 of file ElementJacobianDamper.h.

Referenced by ElementJacobianDamper().

◆ _use_backtracking

const bool ElementJacobianDamper::_use_backtracking
protected

Whether to backtrack the trial update when probing would otherwise create a degenerate map.

Definition at line 81 of file ElementJacobianDamper.h.

Referenced by computeDamping().


The documentation for this class was generated from the following files: