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