Line data Source code
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 : 10 : #pragma once 11 : 12 : #include "DualRealOps.h" 13 : #include "InputParameters.h" 14 : #include "MooseTypes.h" 15 : 16 : class ConsoleStream; 17 : 18 : /** 19 : * Base class that provides capability for Newton generalized (anisotropic) return mapping 20 : * iterations on a single variable 21 : */ 22 : template <bool is_ad> 23 : class GeneralizedReturnMappingSolutionTempl 24 : { 25 : public: 26 : static InputParameters validParams(); 27 : 28 : GeneralizedReturnMappingSolutionTempl(const InputParameters & parameters); 29 141 : virtual ~GeneralizedReturnMappingSolutionTempl() {} 30 : 31 : protected: 32 : /** 33 : * Perform the return mapping iterations 34 : * @param effective_trial_stress Effective trial stress 35 : * @param scalar Inelastic strain increment magnitude being solved for 36 : * @param console Console output 37 : */ 38 : void returnMappingSolve(const GenericDenseVector<is_ad> & effective_trial_stress, 39 : const GenericDenseVector<is_ad> & stress_new, 40 : GenericReal<is_ad> & scalar, 41 : const ConsoleStream & console); 42 : /** 43 : * Compute the minimum permissible value of the scalar. For some models, the magnitude 44 : * of this may be known. 45 : * @param effective_trial_stress Effective trial stress 46 : */ 47 : virtual GenericReal<is_ad> 48 : minimumPermissibleValue(const GenericDenseVector<is_ad> & effective_trial_stress) const; 49 : 50 : /** 51 : * Compute the maximum permissible value of the scalar. For some models, the magnitude 52 : * of this may be known. 53 : * @param effective_trial_stress Effective trial stress 54 : */ 55 : virtual GenericReal<is_ad> 56 : maximumPermissibleValue(const GenericDenseVector<is_ad> & effective_trial_stress) const; 57 : 58 : /** 59 : * Compute an initial guess for the value of the scalar. For some cases, an 60 : * intellegent starting point can provide enhanced robustness in the Newton 61 : * iterations. This is also an opportunity for classes that derive from this 62 : * to perform initialization tasks. 63 : * @param effective_trial_stress Effective trial stress 64 : */ 65 : virtual GenericReal<is_ad> 66 57624 : initialGuess(const GenericDenseVector<is_ad> & /*effective_trial_stress*/) 67 : { 68 57624 : return 0.0; 69 : } 70 : 71 : /** 72 : * Compute the residual for a predicted value of the scalar. This residual should be 73 : * in strain increment units for all models for consistency. 74 : * @param effective_trial_stress Effective trial stress 75 : * @param scalar Inelastic strain increment magnitude being solved for 76 : */ 77 : virtual GenericReal<is_ad> 78 : computeResidual(const GenericDenseVector<is_ad> & effective_trial_stress, 79 : const GenericDenseVector<is_ad> & stress_new, 80 : const GenericReal<is_ad> & delta_gamma) = 0; 81 : 82 : /** 83 : * Compute a reference quantity to be used for checking relative convergence. This should 84 : * be in strain increment units for all models for consistency. 85 : * @param effective_trial_stress Effective trial stress 86 : * @param scalar Inelastic strain increment magnitude being solved for 87 : */ 88 : virtual Real 89 : computeReferenceResidual(const GenericDenseVector<is_ad> & effective_trial_stress, 90 : const GenericDenseVector<is_ad> & stress_new, 91 : const GenericReal<is_ad> & residual, 92 : const GenericReal<is_ad> & scalar_effective_inelastic_strain) = 0; 93 : 94 : virtual GenericReal<is_ad> 95 : computeDerivative(const GenericDenseVector<is_ad> & effective_trial_stress, 96 : const GenericDenseVector<is_ad> & stress_new, 97 : const GenericReal<is_ad> & scalar) = 0; 98 : /** 99 : * Finalize internal state variables for a model for a given iteration. 100 : * @param scalar Inelastic strain increment magnitude being solved for 101 : */ 102 1965580 : virtual void iterationFinalize(const GenericReal<is_ad> & /*scalar*/) {} 103 : 104 : /** 105 : * Output summary information for the convergence history of the model 106 : * @param iter_output Output stream 107 : * @param total_it Total iteration count 108 : */ 109 : virtual void outputIterationSummary(std::stringstream * iter_output, const unsigned int total_it); 110 : 111 : /// Whether to check to see whether iterative solution is within admissible range, and set within that range if outside 112 : bool _check_range; 113 : 114 : /// Whether to use line searches to improve convergence 115 : bool _line_search; 116 : 117 : /// Whether to save upper and lower bounds of root for scalar, and set solution to the midpoint between 118 : /// those bounds if outside them 119 : bool _bracket_solution; 120 : 121 : /** 122 : * Output information for a single iteration step to build the convergence history of the model 123 : * @param iter_output Output stream 124 : * @param it Current iteration count 125 : * @param effective_trial_stress Effective trial stress 126 : * @param scalar Inelastic strain increment magnitude being solved for 127 : * @param residual Current value of the residual 128 : * @param reference Current value of the reference quantity 129 : */ 130 : virtual void outputIterationStep(std::stringstream * iter_output, 131 : const GenericDenseVector<is_ad> & effective_trial_stress, 132 : const GenericReal<is_ad> & scalar, 133 : const GenericReal<is_ad> reference_residual); 134 : 135 : /** 136 : * Check to see whether the residual is within the convergence limits. 137 : * @param residual Current value of the residual 138 : * @param reference Current value of the reference quantity 139 : * @return Whether the model converged 140 : */ 141 : bool converged(const GenericReal<is_ad> & residual, const Real & reference); 142 : 143 : private: 144 : enum class InternalSolveOutput 145 : { 146 : NEVER, 147 : ON_ERROR, 148 : ALWAYS 149 : } _internal_solve_output_on; 150 : 151 : enum class SolveState 152 : { 153 : SUCCESS, 154 : NAN_INF, 155 : EXCEEDED_ITERATIONS 156 : }; 157 : 158 : /// Maximum number of return mapping iterations. This exists only to avoid an infinite loop, and is 159 : /// is intended to be a large number that is not settable by the user. 160 : const unsigned int _max_its; 161 : 162 : /// Whether to output iteration information all the time (regardless of whether iterations converge) 163 : const bool _internal_solve_full_iteration_history; 164 : 165 : /// Relative convergence tolerance 166 : Real _relative_tolerance; 167 : 168 : /// Absolute convergence tolerance 169 : Real _absolute_tolerance; 170 : 171 : /// Multiplier applied to relative and absolute tolerances for acceptable convergence 172 : Real _acceptable_multiplier; 173 : 174 : /// Number of residuals to be stored in history 175 : const std::size_t _num_resids; 176 : 177 : /// History of residuals used to check whether progress is still being made on decreasing the residual 178 : std::vector<Real> _residual_history; 179 : 180 : /// iteration number 181 : unsigned int _iteration; 182 : 183 : ///@{ Residual values, kept as members to retain solver state for summary outputting 184 : GenericReal<is_ad> _initial_residual; 185 : GenericReal<is_ad> _residual; 186 : ///@} 187 : 188 : /// MOOSE input name of the object performing the solve 189 : const std::string _svrms_name; 190 : 191 : /** 192 : * Method called from within this class to perform the actual return mappping iterations. 193 : * @param effective_trial_stress Effective trial stress 194 : * @param scalar Inelastic strain increment magnitude being solved for 195 : * @param iter_output Output stream -- if null, no output is produced 196 : * @return Whether the solution was successful 197 : */ 198 : SolveState internalSolve(const GenericDenseVector<is_ad> & effective_trial_stress, 199 : const GenericDenseVector<is_ad> & stress_new, 200 : GenericReal<is_ad> & scalar, 201 : std::stringstream * iter_output = nullptr); 202 : 203 : /** 204 : * Check to see whether the residual is within acceptable convergence limits. 205 : * This will only return true if it has been determined that progress is no 206 : * longer being made and that the residual is within the acceptable limits. 207 : * @param residual Current iteration count 208 : * @param residual Current value of the residual 209 : * @param reference Current value of the reference quantity 210 : * @return Whether the model converged 211 : */ 212 : bool convergedAcceptable(const unsigned int it, const Real & reference); 213 : 214 : /** 215 : * Check to see whether solution is within admissible range, and set it within that range 216 : * if it is not. 217 : * @param scalar Current value of the inelastic strain increment 218 : * @param scalar_increment Incremental change in scalar from the previous iteration 219 : * @param scalar_old Previous value of scalar 220 : * @param min_permissible_scalar Minimum permissible value of scalar 221 : * @param max_permissible_scalar Maximum permissible value of scalar 222 : * @param iter_output Output stream 223 : */ 224 : void checkPermissibleRange(GenericReal<is_ad> & scalar, 225 : GenericReal<is_ad> & scalar_increment, 226 : const GenericReal<is_ad> & scalar_old, 227 : const GenericReal<is_ad> min_permissible_scalar, 228 : const GenericReal<is_ad> max_permissible_scalar, 229 : std::stringstream * iter_output); 230 : 231 : /** 232 : * Update the upper and lower bounds of the root for the effective inelastic strain. 233 : * @param scalar Current value of the inelastic strain increment 234 : * @param residual Current value of the residual 235 : * @param init_resid_sign Sign of the initial value of the residual 236 : * @param scalar_upper_bound Upper bound value of scalar 237 : * @param scalar_lower_bound Lower bound value of scalar 238 : * @param iter_output Output stream 239 : */ 240 : void updateBounds(const GenericReal<is_ad> & scalar, 241 : const GenericReal<is_ad> & residual, 242 : const Real init_resid_sign, 243 : GenericReal<is_ad> & scalar_upper_bound, 244 : GenericReal<is_ad> & scalar_lower_bound, 245 : std::stringstream * iter_output); 246 : }; 247 : 248 : typedef GeneralizedReturnMappingSolutionTempl<false> GeneralizedReturnMappingSolution; 249 : typedef GeneralizedReturnMappingSolutionTempl<true> ADGeneralizedReturnMappingSolution;