www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
ADSingleVariableReturnMappingSolution< compute_stage > Class Template Referenceabstract

Base class that provides capability for Newton return mapping iterations on a single variable. More...

#include <ADSingleVariableReturnMappingSolution.h>

Inheritance diagram for ADSingleVariableReturnMappingSolution< compute_stage >:
[legend]

Public Member Functions

 ADSingleVariableReturnMappingSolution (const InputParameters &parameters)
 
virtual ~ADSingleVariableReturnMappingSolution ()
 

Protected Member Functions

void returnMappingSolve (const ADReal &effective_trial_stress, ADReal &scalar, const ConsoleStream &console)
 Perform the return mapping iterations. More...
 
virtual Real minimumPermissibleValue (const ADReal &effective_trial_stress) const
 Compute the minimum permissible value of the scalar. More...
 
virtual Real maximumPermissibleValue (const ADReal &effective_trial_stress) const
 Compute the maximum permissible value of the scalar. More...
 
virtual ADReal initialGuess (const ADReal &)
 Compute an initial guess for the value of the scalar. More...
 
virtual ADReal computeResidual (const ADReal &effective_trial_stress, const ADReal &scalar)=0
 Compute the residual for a predicted value of the scalar. More...
 
virtual ADReal computeDerivative (const ADReal &effective_trial_stress, const ADReal &scalar)=0
 Compute the derivative of the residual as a function of the scalar variable. More...
 
virtual Real computeReferenceResidual (const ADReal &effective_trial_stress, const ADReal &scalar)=0
 Compute a reference quantity to be used for checking relative convergence. More...
 
virtual void iterationFinalize (ADReal)
 Finalize internal state variables for a model for a given iteration. More...
 
virtual void outputIterationSummary (std::stringstream *iter_output, const unsigned int total_it)
 Output summary information for the convergence history of the model. More...
 

Protected Attributes

bool _check_range
 Whether to check to see whether iterative solution is within admissible range, and set within that range if outside. More...
 
bool _line_search
 Whether to use line searches to improve convergence. More...
 
bool _bracket_solution
 Whether to save upper and lower bounds of root for scalar, and set solution to the midpoint between those bounds if outside them. More...
 

Private Types

enum  InternalSolveOutput { InternalSolveOutput::NEVER, InternalSolveOutput::ON_ERROR, InternalSolveOutput::ALWAYS }
 
enum  SolveState { SolveState::SUCCESS, SolveState::NAN_INF, SolveState::EXCEEDED_ITERATIONS }
 

Private Member Functions

SolveState internalSolve (const ADReal effective_trial_stress, ADReal &scalar, std::stringstream *iter_output=nullptr)
 Method called from within this class to perform the actual return mappping iterations. More...
 
bool converged (const ADReal &residual, const Real reference)
 Check to see whether the residual is within the convergence limits. More...
 
bool convergedAcceptable (const unsigned int it, const Real reference)
 Check to see whether the residual is within acceptable convergence limits. More...
 
void checkPermissibleRange (ADReal &scalar, ADReal &scalar_increment, const ADReal &scalar_old, const Real min_permissible_scalar, const Real max_permissible_scalar, std::stringstream *iter_output)
 Check to see whether solution is within admissible range, and set it within that range if it is not. More...
 
void updateBounds (const ADReal &scalar, const ADReal &residual, const Real init_resid_sign, Real &scalar_upper_bound, Real &scalar_lower_bound, std::stringstream *iter_output)
 Update the upper and lower bounds of the root for the effective inelastic strain. More...
 
virtual void outputIterationStep (std::stringstream *iter_output, const ADReal &effective_trial_stress, const ADReal &scalar, const Real reference_residual)
 Output information for a single iteration step to build the convergence history of the model. More...
 

Private Attributes

enum ADSingleVariableReturnMappingSolution::InternalSolveOutput _internal_solve_output_on
 
const unsigned int _max_its
 Maximum number of return mapping iterations. More...
 
const bool _internal_solve_full_iteration_history
 Whether to output iteration information all the time (regardless of whether iterations converge) More...
 
Real _relative_tolerance
 Relative convergence tolerance. More...
 
Real _absolute_tolerance
 Absolute convergence tolerance. More...
 
Real _acceptable_multiplier
 Multiplier applied to relative and absolute tolerances for acceptable convergence. More...
 
const std::size_t _num_resids
 Number of residuals to be stored in history. More...
 
std::vector< Real > _residual_history
 History of residuals used to check whether progress is still being made on decreasing the residual. More...
 
unsigned int _iteration
 iteration number More...
 
const std::string _svrms_name
 MOOSE input name of the object performing the solve. More...
 
ADReal _initial_residual
 Residual values, kept as members to retain solver state for summary outputting. More...
 
ADReal _residual
 

Detailed Description

template<ComputeStage compute_stage>
class ADSingleVariableReturnMappingSolution< compute_stage >

Base class that provides capability for Newton return mapping iterations on a single variable.

Definition at line 32 of file ADSingleVariableReturnMappingSolution.h.

Member Enumeration Documentation

◆ InternalSolveOutput

template<ComputeStage compute_stage>
enum ADSingleVariableReturnMappingSolution::InternalSolveOutput
strongprivate
Enumerator
NEVER 
ON_ERROR 
ALWAYS 

Definition at line 132 of file ADSingleVariableReturnMappingSolution.h.

133  {
134  NEVER,
135  ON_ERROR,
136  ALWAYS
enum ADSingleVariableReturnMappingSolution::InternalSolveOutput _internal_solve_output_on

◆ SolveState

template<ComputeStage compute_stage>
enum ADSingleVariableReturnMappingSolution::SolveState
strongprivate
Enumerator
SUCCESS 
NAN_INF 
EXCEEDED_ITERATIONS 

Definition at line 139 of file ADSingleVariableReturnMappingSolution.h.

140  {
141  SUCCESS,
142  NAN_INF,
143  EXCEEDED_ITERATIONS
144  };

Constructor & Destructor Documentation

◆ ADSingleVariableReturnMappingSolution()

template<ComputeStage compute_stage>
ADSingleVariableReturnMappingSolution< compute_stage >::ADSingleVariableReturnMappingSolution ( const InputParameters &  parameters)

Definition at line 53 of file ADSingleVariableReturnMappingSolution.C.

55  : _check_range(false),
56  _line_search(true),
57  _bracket_solution(true),
59  parameters.get<MooseEnum>("internal_solve_output_on").getEnum<InternalSolveOutput>()),
60  _max_its(1000), // Far larger than ever expected to be needed
62  parameters.get<bool>("internal_solve_full_iteration_history")),
63  _relative_tolerance(parameters.get<Real>("relative_tolerance")),
64  _absolute_tolerance(parameters.get<Real>("absolute_tolerance")),
65  _acceptable_multiplier(parameters.get<Real>("acceptable_multiplier")),
66  _num_resids(30),
67  _residual_history(_num_resids, std::numeric_limits<Real>::max()),
68  _iteration(0),
69  _initial_residual(0.0),
70  _residual(0.0),
71  _svrms_name(parameters.get<std::string>("_object_name"))
72 {
73 }
ADReal _initial_residual
Residual values, kept as members to retain solver state for summary outputting.
bool _line_search
Whether to use line searches to improve convergence.
Real _absolute_tolerance
Absolute convergence tolerance.
const unsigned int _max_its
Maximum number of return mapping iterations.
const std::string _svrms_name
MOOSE input name of the object performing the solve.
bool _bracket_solution
Whether to save upper and lower bounds of root for scalar, and set solution to the midpoint between t...
std::vector< Real > _residual_history
History of residuals used to check whether progress is still being made on decreasing the residual...
Real _acceptable_multiplier
Multiplier applied to relative and absolute tolerances for acceptable convergence.
bool _check_range
Whether to check to see whether iterative solution is within admissible range, and set within that ra...
enum ADSingleVariableReturnMappingSolution::InternalSolveOutput _internal_solve_output_on
Real _relative_tolerance
Relative convergence tolerance.
const std::size_t _num_resids
Number of residuals to be stored in history.
const bool _internal_solve_full_iteration_history
Whether to output iteration information all the time (regardless of whether iterations converge) ...

◆ ~ADSingleVariableReturnMappingSolution()

template<ComputeStage compute_stage>
virtual ADSingleVariableReturnMappingSolution< compute_stage >::~ADSingleVariableReturnMappingSolution ( )
inlinevirtual

Definition at line 46 of file ADSingleVariableReturnMappingSolution.h.

46 {}

Member Function Documentation

◆ checkPermissibleRange()

template<ComputeStage compute_stage>
void ADSingleVariableReturnMappingSolution< compute_stage >::checkPermissibleRange ( ADReal &  scalar,
ADReal &  scalar_increment,
const ADReal &  scalar_old,
const Real  min_permissible_scalar,
const Real  max_permissible_scalar,
std::stringstream *  iter_output 
)
private

Check to see whether solution is within admissible range, and set it within that range if it is not.

Parameters
scalarCurrent value of the inelastic strain increment
scalar_incrementIncremental change in scalar from the previous iteration
scalar_oldPrevious value of scalar
min_permissible_scalarMinimum permissible value of scalar
max_permissible_scalarMaximum permissible value of scalar
iter_outputOutput stream

Definition at line 329 of file ADSingleVariableReturnMappingSolution.C.

336 {
337  if (scalar > max_permissible_scalar)
338  {
339  scalar_increment = (max_permissible_scalar - scalar_old) / 2.0;
340  scalar = scalar_old + scalar_increment;
341  if (iter_output)
342  *iter_output << "Scalar greater than maximum (" << max_permissible_scalar
343  << ") adjusted scalar=" << scalar << " scalar_increment=" << scalar_increment
344  << std::endl;
345  }
346  else if (scalar < min_permissible_scalar)
347  {
348  scalar_increment = (min_permissible_scalar - scalar_old) / 2.0;
349  scalar = scalar_old + scalar_increment;
350  if (iter_output)
351  *iter_output << "Scalar less than minimum (" << min_permissible_scalar
352  << ") adjusted scalar=" << scalar << " scalar_increment=" << scalar_increment
353  << std::endl;
354  }
355 }

◆ computeDerivative()

template<ComputeStage compute_stage>
virtual ADReal ADSingleVariableReturnMappingSolution< compute_stage >::computeDerivative ( const ADReal &  effective_trial_stress,
const ADReal &  scalar 
)
protectedpure virtual

Compute the derivative of the residual as a function of the scalar variable.

The residual should be in strain increment units for all models for consistency.

Parameters
effective_trial_stressEffective trial stress
scalarInelastic strain increment magnitude being solved for

Implemented in ADPowerLawCreepStressUpdate< compute_stage >.

◆ computeReferenceResidual()

template<ComputeStage compute_stage>
virtual Real ADSingleVariableReturnMappingSolution< compute_stage >::computeReferenceResidual ( const ADReal &  effective_trial_stress,
const ADReal &  scalar 
)
protectedpure virtual

Compute a reference quantity to be used for checking relative convergence.

This should be in strain increment units for all models for consistency.

Parameters
effective_trial_stressEffective trial stress
scalarInelastic strain increment magnitude being solved for

Implemented in ADRadialReturnStressUpdate< compute_stage >.

◆ computeResidual()

template<ComputeStage compute_stage>
virtual ADReal ADSingleVariableReturnMappingSolution< compute_stage >::computeResidual ( const ADReal &  effective_trial_stress,
const ADReal &  scalar 
)
protectedpure virtual

Compute the residual for a predicted value of the scalar.

This residual should be in strain increment units for all models for consistency.

Parameters
effective_trial_stressEffective trial stress
scalarInelastic strain increment magnitude being solved for

Implemented in ADPowerLawCreepStressUpdate< compute_stage >.

◆ converged()

template<ComputeStage compute_stage>
bool ADSingleVariableReturnMappingSolution< compute_stage >::converged ( const ADReal &  residual,
const Real  reference 
)
private

Check to see whether the residual is within the convergence limits.

Parameters
residualCurrent value of the residual
referenceCurrent value of the reference quantity
Returns
Whether the model converged

Definition at line 296 of file ADSingleVariableReturnMappingSolution.C.

298 {
299  const Real residual = MetaPhysicL::raw_value(ad_residual);
300  return (std::abs(residual) <= _absolute_tolerance ||
301  std::abs(residual / reference) <= _relative_tolerance);
302 }
Real _absolute_tolerance
Absolute convergence tolerance.
Real _relative_tolerance
Relative convergence tolerance.

◆ convergedAcceptable()

template<ComputeStage compute_stage>
bool ADSingleVariableReturnMappingSolution< compute_stage >::convergedAcceptable ( const unsigned int  it,
const Real  reference 
)
private

Check to see whether the residual is within acceptable convergence limits.

This will only return true if it has been determined that progress is no longer being made and that the residual is within the acceptable limits.

Parameters
residualCurrent iteration count
residualCurrent value of the residual
referenceCurrent value of the reference quantity
Returns
Whether the model converged

Definition at line 306 of file ADSingleVariableReturnMappingSolution.C.

308 {
309  // Require that we have at least done _num_resids evaluations before we allow for
310  // acceptable convergence
311  if (it < _num_resids)
312  return false;
313 
314  // Check to see whether the residual has dropped by convergence_history_factor over
315  // the last _num_resids iterations. If it has (which means it's still making progress),
316  // don't consider it to be converged within the acceptable limits.
317  const Real convergence_history_factor = 10.0;
318  if (std::abs(_residual * convergence_history_factor) <
319  std::abs(_residual_history[(it + 1) % _num_resids]))
320  return false;
321 
322  // Now that it's determined that progress is not being made, treat it as converged if
323  // we're within the acceptable convergence limits
324  return converged(_residual / _acceptable_multiplier, reference);
325 }
bool converged(const ADReal &residual, const Real reference)
Check to see whether the residual is within the convergence limits.
std::vector< Real > _residual_history
History of residuals used to check whether progress is still being made on decreasing the residual...
Real _acceptable_multiplier
Multiplier applied to relative and absolute tolerances for acceptable convergence.
const std::size_t _num_resids
Number of residuals to be stored in history.

◆ initialGuess()

template<ComputeStage compute_stage>
virtual ADReal ADSingleVariableReturnMappingSolution< compute_stage >::initialGuess ( const ADReal &  )
inlineprotectedvirtual

Compute an initial guess for the value of the scalar.

For some cases, an intellegent starting point can provide enhanced robustness in the Newton iterations. This is also an opportunity for classes that derive from this to perform initialization tasks.

Parameters
effective_trial_stressEffective trial stress

Definition at line 80 of file ADSingleVariableReturnMappingSolution.h.

80 { return 0.0; }

◆ internalSolve()

template<ComputeStage compute_stage>
ADSingleVariableReturnMappingSolution< compute_stage >::SolveState ADSingleVariableReturnMappingSolution< compute_stage >::internalSolve ( const ADReal  effective_trial_stress,
ADReal &  scalar,
std::stringstream *  iter_output = nullptr 
)
private

Method called from within this class to perform the actual return mappping iterations.

Parameters
effective_trial_stressEffective trial stress
scalarInelastic strain increment magnitude being solved for
iter_outputOutput stream – if null, no output is produced
Returns
Whether the solution was successful

Definition at line 151 of file ADSingleVariableReturnMappingSolution.C.

153 {
154  scalar = initialGuess(effective_trial_stress);
155  ADReal scalar_old = scalar;
156  ADReal scalar_increment = 0.0;
157  const Real min_permissible_scalar = minimumPermissibleValue(effective_trial_stress);
158  const Real max_permissible_scalar = maximumPermissibleValue(effective_trial_stress);
159  Real scalar_upper_bound = max_permissible_scalar;
160  Real scalar_lower_bound = min_permissible_scalar;
161  _iteration = 0;
162 
163  _initial_residual = _residual = computeResidual(effective_trial_stress, scalar);
164 
165  ADReal residual_old = _residual;
166 
167  Real init_resid_norm = MetaPhysicL::raw_value(std::abs(_residual));
168  if (init_resid_norm == 0.0)
169  init_resid_norm = 1.0;
170  Real init_resid_sign = (_residual < 0.0 ? -1.0 : 1.0);
171 
172  Real reference_residual = computeReferenceResidual(effective_trial_stress, scalar);
173 
174  if (converged(_residual, reference_residual))
175  {
176  iterationFinalize(scalar);
177  outputIterationStep(iter_output, effective_trial_stress, scalar, reference_residual);
178  return SolveState::SUCCESS;
179  }
180 
181  _residual_history.assign(_num_resids, std::numeric_limits<Real>::max());
182  _residual_history[0] = MetaPhysicL::raw_value(_residual);
183 
184  while (_iteration < _max_its && !converged(_residual, reference_residual) &&
185  !convergedAcceptable(_iteration, reference_residual))
186  {
187  scalar_increment = -_residual / computeDerivative(effective_trial_stress, scalar);
188  scalar = scalar_old + scalar_increment;
189 
190  if (_check_range)
191  checkPermissibleRange(scalar,
192  scalar_increment,
193  scalar_old,
194  min_permissible_scalar,
195  max_permissible_scalar,
196  iter_output);
197 
198  _residual = computeResidual(effective_trial_stress, scalar);
199  reference_residual = computeReferenceResidual(effective_trial_stress, scalar);
200  iterationFinalize(scalar);
201 
202  if (_bracket_solution)
203  updateBounds(
204  scalar, _residual, init_resid_sign, scalar_upper_bound, scalar_lower_bound, iter_output);
205 
206  if (converged(_residual, reference_residual))
207  {
208  outputIterationStep(iter_output, effective_trial_stress, scalar, reference_residual);
209  break;
210  }
211  else
212  {
213  bool modified_increment = false;
214 
215  // Line Search
216  if (_line_search)
217  {
218  if (residual_old - _residual != 0.0)
219  {
220  ADReal alpha = residual_old / (residual_old - _residual);
221  if (alpha > 1.0) // upper bound for alpha
222  alpha = 1.0;
223  else if (alpha < 1e-2) // lower bound for alpha
224  alpha = 1e-2;
225  if (alpha != 1.0)
226  {
227  modified_increment = true;
228  scalar_increment *= alpha;
229  if (iter_output)
230  *iter_output << " Line search alpha = " << alpha
231  << " increment = " << scalar_increment << std::endl;
232  }
233  }
234  }
235 
236  if (_bracket_solution)
237  {
238  // Check to see whether trial scalar_increment is outside the bounds, and set it to a point
239  // within the bounds if it is
240  if (scalar_old + scalar_increment >= scalar_upper_bound ||
241  scalar_old + scalar_increment <= scalar_lower_bound)
242  {
243  if (scalar_upper_bound != max_permissible_scalar &&
244  scalar_lower_bound != min_permissible_scalar)
245  {
246  ADReal frac = 0.5;
247  scalar_increment =
248  (1.0 - frac) * scalar_lower_bound + frac * scalar_upper_bound - scalar_old;
249  modified_increment = true;
250  if (iter_output)
251  *iter_output << " Trial scalar_increment exceeded bounds. Setting between "
252  "lower/upper bounds. frac: "
253  << frac << std::endl;
254  }
255  }
256  }
257 
258  // Update the trial scalar and recompute residual if the line search or bounds checking
259  // modified the increment
260  if (modified_increment)
261  {
262  scalar = scalar_old + scalar_increment;
263  _residual = computeResidual(effective_trial_stress, scalar);
264  reference_residual = computeReferenceResidual(effective_trial_stress, scalar);
265  iterationFinalize(scalar);
266 
267  if (_bracket_solution)
268  updateBounds(scalar,
269  _residual,
270  init_resid_sign,
271  scalar_upper_bound,
272  scalar_lower_bound,
273  iter_output);
274  }
275  }
276 
277  outputIterationStep(iter_output, effective_trial_stress, scalar, reference_residual);
278 
279  ++_iteration;
280  residual_old = _residual;
281  scalar_old = scalar;
282  _residual_history[_iteration % _num_resids] = MetaPhysicL::raw_value(_residual);
283  }
284 
285  if (std::isnan(_residual) || std::isinf(MetaPhysicL::raw_value(_residual)))
286  return SolveState::NAN_INF;
287 
288  if (_iteration == _max_its)
290 
291  return SolveState::SUCCESS;
292 }
virtual ADReal initialGuess(const ADReal &)
Compute an initial guess for the value of the scalar.
virtual ADReal computeDerivative(const ADReal &effective_trial_stress, const ADReal &scalar)=0
Compute the derivative of the residual as a function of the scalar variable.
ADReal _initial_residual
Residual values, kept as members to retain solver state for summary outputting.
virtual ADReal computeResidual(const ADReal &effective_trial_stress, const ADReal &scalar)=0
Compute the residual for a predicted value of the scalar.
virtual void outputIterationStep(std::stringstream *iter_output, const ADReal &effective_trial_stress, const ADReal &scalar, const Real reference_residual)
Output information for a single iteration step to build the convergence history of the model...
bool _line_search
Whether to use line searches to improve convergence.
bool converged(const ADReal &residual, const Real reference)
Check to see whether the residual is within the convergence limits.
const unsigned int _max_its
Maximum number of return mapping iterations.
virtual Real maximumPermissibleValue(const ADReal &effective_trial_stress) const
Compute the maximum permissible value of the scalar.
virtual void iterationFinalize(ADReal)
Finalize internal state variables for a model for a given iteration.
virtual Real computeReferenceResidual(const ADReal &effective_trial_stress, const ADReal &scalar)=0
Compute a reference quantity to be used for checking relative convergence.
bool _bracket_solution
Whether to save upper and lower bounds of root for scalar, and set solution to the midpoint between t...
std::vector< Real > _residual_history
History of residuals used to check whether progress is still being made on decreasing the residual...
bool _check_range
Whether to check to see whether iterative solution is within admissible range, and set within that ra...
virtual Real minimumPermissibleValue(const ADReal &effective_trial_stress) const
Compute the minimum permissible value of the scalar.
const std::size_t _num_resids
Number of residuals to be stored in history.
bool convergedAcceptable(const unsigned int it, const Real reference)
Check to see whether the residual is within acceptable convergence limits.
void checkPermissibleRange(ADReal &scalar, ADReal &scalar_increment, const ADReal &scalar_old, const Real min_permissible_scalar, const Real max_permissible_scalar, std::stringstream *iter_output)
Check to see whether solution is within admissible range, and set it within that range if it is not...
void updateBounds(const ADReal &scalar, const ADReal &residual, const Real init_resid_sign, Real &scalar_upper_bound, Real &scalar_lower_bound, std::stringstream *iter_output)
Update the upper and lower bounds of the root for the effective inelastic strain. ...

◆ iterationFinalize()

template<ComputeStage compute_stage>
virtual void ADSingleVariableReturnMappingSolution< compute_stage >::iterationFinalize ( ADReal  )
inlineprotectedvirtual

Finalize internal state variables for a model for a given iteration.

Parameters
scalarInelastic strain increment magnitude being solved for

Definition at line 112 of file ADSingleVariableReturnMappingSolution.h.

112 {}

◆ maximumPermissibleValue()

template<ComputeStage compute_stage>
Real ADSingleVariableReturnMappingSolution< compute_stage >::maximumPermissibleValue ( const ADReal &  effective_trial_stress) const
protectedvirtual

Compute the maximum permissible value of the scalar.

For some models, the magnitude of this may be known.

Parameters
effective_trial_stressEffective trial stress

Reimplemented in ADRadialReturnStressUpdate< compute_stage >.

Definition at line 85 of file ADSingleVariableReturnMappingSolution.C.

87 {
88  return std::numeric_limits<Real>::max();
89 }

◆ minimumPermissibleValue()

template<ComputeStage compute_stage>
Real ADSingleVariableReturnMappingSolution< compute_stage >::minimumPermissibleValue ( const ADReal &  effective_trial_stress) const
protectedvirtual

Compute the minimum permissible value of the scalar.

For some models, the magnitude of this may be known.

Parameters
effective_trial_stressEffective trial stress

Reimplemented in ADRadialReturnStressUpdate< compute_stage >.

Definition at line 77 of file ADSingleVariableReturnMappingSolution.C.

79 {
80  return std::numeric_limits<Real>::lowest();
81 }

◆ outputIterationStep()

template<ComputeStage compute_stage>
void ADSingleVariableReturnMappingSolution< compute_stage >::outputIterationStep ( std::stringstream *  iter_output,
const ADReal &  effective_trial_stress,
const ADReal &  scalar,
const Real  reference_residual 
)
privatevirtual

Output information for a single iteration step to build the convergence history of the model.

Parameters
iter_outputOutput stream
itCurrent iteration count
effective_trial_stressEffective trial stress
scalarInelastic strain increment magnitude being solved for
residualCurrent value of the residual
referenceCurrent value of the reference quantity

Definition at line 387 of file ADSingleVariableReturnMappingSolution.C.

392 {
393  if (iter_output)
394  {
395  const unsigned int it = _iteration;
396  const Real residual = MetaPhysicL::raw_value(_residual);
397 
398  *iter_output << " iteration=" << it
399  << " trial_stress=" << MetaPhysicL::raw_value(effective_trial_stress)
400  << " scalar=" << MetaPhysicL::raw_value(scalar) << " residual=" << residual
401  << " ref_res=" << reference_residual
402  << " rel_res=" << std::abs(MetaPhysicL::raw_value(residual)) / reference_residual
403  << " rel_tol=" << _relative_tolerance << " abs_res=" << std::abs(residual)
404  << " abs_tol=" << _absolute_tolerance << '\n';
405  }
406 }
Real _absolute_tolerance
Absolute convergence tolerance.
Real _relative_tolerance
Relative convergence tolerance.

◆ outputIterationSummary()

template<ComputeStage compute_stage>
void ADSingleVariableReturnMappingSolution< compute_stage >::outputIterationSummary ( std::stringstream *  iter_output,
const unsigned int  total_it 
)
protectedvirtual

Output summary information for the convergence history of the model.

Parameters
iter_outputOutput stream
total_itTotal iteration count

Reimplemented in ADRadialReturnStressUpdate< compute_stage >.

Definition at line 410 of file ADSingleVariableReturnMappingSolution.C.

Referenced by ADRadialReturnStressUpdate< compute_stage >::outputIterationSummary().

412 {
413  if (iter_output)
414  *iter_output << "In " << total_it << " iterations the residual went from " << _initial_residual
415  << " to " << _residual << " in '" << _svrms_name << "'.\n";
416 }
ADReal _initial_residual
Residual values, kept as members to retain solver state for summary outputting.
const std::string _svrms_name
MOOSE input name of the object performing the solve.

◆ returnMappingSolve()

template<ComputeStage compute_stage>
void ADSingleVariableReturnMappingSolution< compute_stage >::returnMappingSolve ( const ADReal &  effective_trial_stress,
ADReal &  scalar,
const ConsoleStream &  console 
)
protected

Perform the return mapping iterations.

Parameters
effective_trial_stressEffective trial stress
scalarInelastic strain increment magnitude being solved for
consoleConsole output

Definition at line 93 of file ADSingleVariableReturnMappingSolution.C.

95 {
96  // construct the stringstream here only if the debug level is set to ALL
97  std::stringstream * iter_output =
98  (_internal_solve_output_on == InternalSolveOutput::ALWAYS) ? new std::stringstream : nullptr;
99 
100  // do the internal solve and capture iteration info during the first round
101  // iff full history output is requested regardless of whether the solve failed or succeeded
102  auto solve_state = internalSolve(effective_trial_stress,
103  scalar,
104  _internal_solve_full_iteration_history ? iter_output : nullptr);
105  if (solve_state != SolveState::SUCCESS &&
107  {
108  // output suppressed by user, throw immediately
110  throw MooseException("");
111 
112  // user expects some kind of output, if necessary setup output stream now
113  if (!iter_output)
114  iter_output = new std::stringstream;
115 
116  // add the appropriate error message to the output
117  switch (solve_state)
118  {
119  case SolveState::NAN_INF:
120  *iter_output << "Encountered inf or nan in material return mapping iterations.\n";
121  break;
122 
124  *iter_output << "Exceeded maximum iterations in material return mapping iterations.\n";
125  break;
126 
127  default:
128  mooseError("Unhandled solver state");
129  }
130 
131  // if full history output is only requested for failed solves we have to repeat
132  // the solve a second time
134  internalSolve(effective_trial_stress, scalar, iter_output);
135 
136  // Append summary and throw exception
137  outputIterationSummary(iter_output, _iteration);
138  throw MooseException(iter_output->str());
139  }
140 
142  {
143  // the solve did not fail but the user requested debug output anyways
144  outputIterationSummary(iter_output, _iteration);
145  console << iter_output->str();
146  }
147 }
virtual void outputIterationSummary(std::stringstream *iter_output, const unsigned int total_it)
Output summary information for the convergence history of the model.
enum ADSingleVariableReturnMappingSolution::InternalSolveOutput _internal_solve_output_on
const bool _internal_solve_full_iteration_history
Whether to output iteration information all the time (regardless of whether iterations converge) ...
SolveState internalSolve(const ADReal effective_trial_stress, ADReal &scalar, std::stringstream *iter_output=nullptr)
Method called from within this class to perform the actual return mappping iterations.

◆ updateBounds()

template<ComputeStage compute_stage>
void ADSingleVariableReturnMappingSolution< compute_stage >::updateBounds ( const ADReal &  scalar,
const ADReal &  residual,
const Real  init_resid_sign,
Real &  scalar_upper_bound,
Real &  scalar_lower_bound,
std::stringstream *  iter_output 
)
private

Update the upper and lower bounds of the root for the effective inelastic strain.

Parameters
scalarCurrent value of the inelastic strain increment
residualCurrent value of the residual
init_resid_signSign of the initial value of the residual
scalar_upper_boundUpper bound value of scalar
scalar_lower_boundLower bound value of scalar
iter_outputOutput stream

Definition at line 359 of file ADSingleVariableReturnMappingSolution.C.

365 {
366  // Update upper/lower bounds as applicable
367  if (residual * init_resid_sign < 0.0 && scalar < scalar_upper_bound)
368  {
369  scalar_upper_bound = MetaPhysicL::raw_value(scalar);
370  if (scalar_upper_bound < scalar_lower_bound)
371  {
372  scalar_upper_bound = scalar_lower_bound;
373  scalar_lower_bound = 0.0;
374  if (iter_output)
375  *iter_output << " Corrected for scalar_upper_bound < scalar_lower_bound" << std::endl;
376  }
377  }
378  // Don't permit setting scalar_lower_bound > scalar_upper_bound (but do permit the reverse).
379  // This ensures that if we encounter multiple roots, we pick the lowest one.
380  else if (residual * init_resid_sign > 0.0 && scalar > scalar_lower_bound &&
381  scalar < scalar_upper_bound)
382  scalar_lower_bound = MetaPhysicL::raw_value(scalar);
383 }

Member Data Documentation

◆ _absolute_tolerance

template<ComputeStage compute_stage>
Real ADSingleVariableReturnMappingSolution< compute_stage >::_absolute_tolerance
private

Absolute convergence tolerance.

Definition at line 157 of file ADSingleVariableReturnMappingSolution.h.

◆ _acceptable_multiplier

template<ComputeStage compute_stage>
Real ADSingleVariableReturnMappingSolution< compute_stage >::_acceptable_multiplier
private

Multiplier applied to relative and absolute tolerances for acceptable convergence.

Definition at line 160 of file ADSingleVariableReturnMappingSolution.h.

◆ _bracket_solution

template<ComputeStage compute_stage>
bool ADSingleVariableReturnMappingSolution< compute_stage >::_bracket_solution
protected

Whether to save upper and lower bounds of root for scalar, and set solution to the midpoint between those bounds if outside them.

Definition at line 129 of file ADSingleVariableReturnMappingSolution.h.

◆ _check_range

template<ComputeStage compute_stage>
bool ADSingleVariableReturnMappingSolution< compute_stage >::_check_range
protected

Whether to check to see whether iterative solution is within admissible range, and set within that range if outside.

Definition at line 122 of file ADSingleVariableReturnMappingSolution.h.

◆ _initial_residual

template<ComputeStage compute_stage>
ADReal ADSingleVariableReturnMappingSolution< compute_stage >::_initial_residual
private

Residual values, kept as members to retain solver state for summary outputting.

Definition at line 172 of file ADSingleVariableReturnMappingSolution.h.

◆ _internal_solve_full_iteration_history

template<ComputeStage compute_stage>
const bool ADSingleVariableReturnMappingSolution< compute_stage >::_internal_solve_full_iteration_history
private

Whether to output iteration information all the time (regardless of whether iterations converge)

Definition at line 151 of file ADSingleVariableReturnMappingSolution.h.

◆ _internal_solve_output_on

template<ComputeStage compute_stage>
enum ADSingleVariableReturnMappingSolution::InternalSolveOutput ADSingleVariableReturnMappingSolution< compute_stage >::_internal_solve_output_on
private

◆ _iteration

template<ComputeStage compute_stage>
unsigned int ADSingleVariableReturnMappingSolution< compute_stage >::_iteration
private

iteration number

Definition at line 169 of file ADSingleVariableReturnMappingSolution.h.

◆ _line_search

template<ComputeStage compute_stage>
bool ADSingleVariableReturnMappingSolution< compute_stage >::_line_search
protected

Whether to use line searches to improve convergence.

Definition at line 125 of file ADSingleVariableReturnMappingSolution.h.

◆ _max_its

template<ComputeStage compute_stage>
const unsigned int ADSingleVariableReturnMappingSolution< compute_stage >::_max_its
private

Maximum number of return mapping iterations.

This exists only to avoid an infinite loop, and is is intended to be a large number that is not settable by the user.

Definition at line 148 of file ADSingleVariableReturnMappingSolution.h.

◆ _num_resids

template<ComputeStage compute_stage>
const std::size_t ADSingleVariableReturnMappingSolution< compute_stage >::_num_resids
private

Number of residuals to be stored in history.

Definition at line 163 of file ADSingleVariableReturnMappingSolution.h.

◆ _relative_tolerance

template<ComputeStage compute_stage>
Real ADSingleVariableReturnMappingSolution< compute_stage >::_relative_tolerance
private

Relative convergence tolerance.

Definition at line 154 of file ADSingleVariableReturnMappingSolution.h.

◆ _residual

template<ComputeStage compute_stage>
ADReal ADSingleVariableReturnMappingSolution< compute_stage >::_residual
private

Definition at line 173 of file ADSingleVariableReturnMappingSolution.h.

◆ _residual_history

template<ComputeStage compute_stage>
std::vector<Real> ADSingleVariableReturnMappingSolution< compute_stage >::_residual_history
private

History of residuals used to check whether progress is still being made on decreasing the residual.

Definition at line 166 of file ADSingleVariableReturnMappingSolution.h.

◆ _svrms_name

template<ComputeStage compute_stage>
const std::string ADSingleVariableReturnMappingSolution< compute_stage >::_svrms_name
private

MOOSE input name of the object performing the solve.

Definition at line 177 of file ADSingleVariableReturnMappingSolution.h.


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