LCOV - code coverage report
Current view: top level - src/physics - QuasiStaticSolidMechanicsPhysicsBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: #33390 (250e9c) with base 846a5c Lines: 107 114 93.9 %
Date: 2026-07-31 18:20:40 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          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             : #include "QuasiStaticSolidMechanicsPhysicsBase.h"
      11             : #include "CommonSolidMechanicsAction.h"
      12             : #include "ActionWarehouse.h"
      13             : #include "AddAuxVariableAction.h"
      14             : #include "ComputeFiniteStrain.h"
      15             : #include "MooseApp.h"
      16             : #include "InputParameterWarehouse.h"
      17             : 
      18             : // map tensor name shortcuts to tensor material property names
      19             : std::map<std::string, std::string>
      20             :     QuasiStaticSolidMechanicsPhysicsBase::_rank_two_cartesian_component_table = {
      21             :         {"strain", "total_strain"},
      22             :         {"mechanical_strain", "mechanical_strain"},
      23             :         {"stress", "stress"},
      24             :         {"cauchy_stress", "cauchy_stress"},
      25             :         {"deformation_gradient", "deformation_gradient"},
      26             :         {"pk1_stress", "pk1_stress"},
      27             :         {"pk2_stress", "pk2_stress"},
      28             :         {"small_stress", "small_stress"},
      29             :         {"elastic_strain", "elastic_strain"},
      30             :         {"plastic_strain", "plastic_strain"},
      31             :         {"creep_strain", "creep_strain"},
      32             :         {"creep_stress", "creep_stress"}};
      33             : const std::vector<char> QuasiStaticSolidMechanicsPhysicsBase::_component_table = {'x', 'y', 'z'};
      34             : 
      35             : // map aux variable name prefixes to RankTwoInvariant option and list of permitted tensor name
      36             : // shortcuts
      37             : const std::map<std::string, std::pair<std::string, std::vector<std::string>>>
      38             :     QuasiStaticSolidMechanicsPhysicsBase::_rank_two_invariant_table = {
      39             :         {"vonmises", {"VonMisesStress", {"stress", "cauchy_stress", "pk1_stress", "pk2_stress"}}},
      40             :         {"effective", {"EffectiveStrain", {"plastic_strain", "creep_strain"}}},
      41             :         {"hydrostatic",
      42             :          {"Hydrostatic", {"stress", "cauchy_stress", "pk1_stress", "pk2_stress", "small_stress"}}},
      43             :         {"l2norm",
      44             :          {"L2norm",
      45             :           {"mechanical_strain",
      46             :            "stress",
      47             :            "cauchy_stress",
      48             :            "pk1_stress",
      49             :            "strain",
      50             :            "elastic_strain",
      51             :            "plastic_strain",
      52             :            "creep_strain"}}},
      53             :         {"volumetric", {"VolumetricStrain", {"mechanical_strain", "strain"}}},
      54             :         {"firstinv",
      55             :          {"FirstInvariant",
      56             :           {"stress", "cauchy_stress", "pk1_stress", "pk2_stress", "small_stress", "strain"}}},
      57             :         {"secondinv",
      58             :          {"SecondInvariant",
      59             :           {"stress", "cauchy_stress", "pk1_stress", "pk2_stress", "small_stress", "strain"}}},
      60             :         {"thirdinv",
      61             :          {"ThirdInvariant",
      62             :           {"stress", "cauchy_stress", "pk1_stress", "pk2_stress", "small_stress", "strain"}}},
      63             :         {"triaxiality",
      64             :          {"TriaxialityStress",
      65             :           {
      66             :               "stress",
      67             :               "cauchy_stress",
      68             :               "pk1_stress",
      69             :               "pk2_stress",
      70             :               "small_stress",
      71             :           }}},
      72             :         {"maxshear",
      73             :          {"MaxShear",
      74             :           {
      75             :               "stress",
      76             :               "cauchy_stress",
      77             :               "pk1_stress",
      78             :               "pk2_stress",
      79             :               "small_stress",
      80             :           }}},
      81             :         {"intensity",
      82             :          {"StressIntensity",
      83             :           {
      84             :               "stress",
      85             :               "cauchy_stress",
      86             :               "pk1_stress",
      87             :               "pk2_stress",
      88             :               "small_stress",
      89             :           }}},
      90             :         {"max_principal",
      91             :          {"MaxPrincipal",
      92             :           {"mechanical_strain",
      93             :            "stress",
      94             :            "cauchy_stress",
      95             :            "pk1_stress",
      96             :            "pk2_stress",
      97             :            "small_stress",
      98             :            "strain"}}},
      99             :         {"mid_principal",
     100             :          {"MidPrincipal",
     101             :           {"mechanical_strain",
     102             :            "stress",
     103             :            "cauchy_stress",
     104             :            "pk1_stress",
     105             :            "pk2_stress",
     106             :            "small_stress",
     107             :            "strain"}}},
     108             :         {"min_principal",
     109             :          {"MinPrincipal",
     110             :           {"mechanical_strain",
     111             :            "stress",
     112             :            "cauchy_stress",
     113             :            "pk1_stress",
     114             :            "pk2_stress",
     115             :            "small_stress",
     116             :            "strain"}}}};
     117             : 
     118             : const std::map<std::string, std::pair<std::string, std::vector<std::string>>>
     119             :     QuasiStaticSolidMechanicsPhysicsBase::_rank_two_directional_component_table = {
     120             :         {"directional", {"Direction", {"stress", "strain"}}}};
     121             : 
     122             : const std::map<std::string, std::pair<std::string, std::vector<std::string>>>
     123             :     QuasiStaticSolidMechanicsPhysicsBase::_rank_two_cylindrical_component_table = {
     124             :         {"axial",
     125             :          {"AxialStress", {"stress", "strain", "plastic_strain", "creep_strain", "elastic_strain"}}},
     126             :         {"hoop",
     127             :          {"HoopStress", {"stress", "strain", "plastic_strain", "creep_strain", "elastic_strain"}}},
     128             :         {"radial", {"RadialStress", {"stress", "strain"}}}};
     129             : 
     130             : const std::map<std::string, std::pair<std::string, std::vector<std::string>>>
     131             :     QuasiStaticSolidMechanicsPhysicsBase::_rank_two_spherical_component_table = {
     132             :         {"spherical_hoop",
     133             :          {"HoopStress", {"stress", "strain", "plastic_strain", "creep_strain", "elastic_strain"}}},
     134             :         {"spherical_radial", {"RadialStress", {"stress", "strain"}}}};
     135             : 
     136             : InputParameters
     137        7736 : QuasiStaticSolidMechanicsPhysicsBase::validParams()
     138             : {
     139        7736 :   InputParameters params = Action::validParams();
     140             : 
     141       15472 :   params.addRequiredParam<std::vector<VariableName>>(
     142             :       "displacements", "The nonlinear displacement variables for the problem");
     143       15472 :   params.addParam<std::vector<VariableName>>("temperature", "The temperature");
     144             : 
     145       15472 :   MooseEnum strainType("SMALL FINITE", "SMALL");
     146       15472 :   params.addParam<MooseEnum>("strain", strainType, "Strain formulation");
     147       15472 :   params.addParam<bool>("incremental",
     148             :                         "Use incremental or total strain (if not explicitly specified this "
     149             :                         "defaults to incremental for finite strain and total for small strain)");
     150             : 
     151       15472 :   params.addParam<std::string>("base_name", "Material property base name");
     152       15472 :   params.addParam<bool>(
     153       15472 :       "volumetric_locking_correction", false, "Flag to correct volumetric locking");
     154       15472 :   params.addParam<bool>(
     155       15472 :       "use_finite_deform_jacobian", false, "Jacobian for corrotational finite strain");
     156       15472 :   params.addParam<bool>("add_variables", false, "Add the displacement variables");
     157       15472 :   params.addParam<std::vector<MaterialPropertyName>>(
     158             :       "eigenstrain_names", {}, "List of eigenstrains to be applied in this strain calculation");
     159       15472 :   params.addParam<bool>("use_automatic_differentiation",
     160       15472 :                         false,
     161             :                         "Flag to use automatic differentiation (AD) objects when possible");
     162             :   // Global Strain
     163       15472 :   params.addParam<MaterialPropertyName>(
     164             :       "global_strain",
     165             :       "Name of the global strain material to be applied in this strain calculation. "
     166             :       "The global strain tensor is constant over the whole domain and allows visualization "
     167             :       "of the deformed shape with the periodic BC");
     168             : 
     169             :   // Advanced
     170       15472 :   params.addParam<std::vector<AuxVariableName>>("save_in", {}, "The displacement residuals");
     171       15472 :   params.addParam<std::vector<AuxVariableName>>(
     172             :       "diag_save_in", {}, "The displacement diagonal preconditioner terms");
     173       15472 :   params.addParam<MooseEnum>("decomposition_method",
     174       15472 :                              ComputeFiniteStrain::decompositionType(),
     175             :                              "Methods to calculate the finite strain and rotation increments");
     176       15472 :   params.addParamNamesToGroup("save_in diag_save_in", "Advanced");
     177             : 
     178             :   // Planar Formulation
     179             :   MooseEnum planarFormulationType("NONE WEAK_PLANE_STRESS PLANE_STRAIN GENERALIZED_PLANE_STRAIN",
     180       15472 :                                   "NONE");
     181       15472 :   params.addParam<MooseEnum>(
     182             :       "planar_formulation", planarFormulationType, "Out-of-plane stress/strain formulation");
     183       15472 :   params.addParam<VariableName>("scalar_out_of_plane_strain",
     184             :                                 "Scalar variable for the out-of-plane strain (in y "
     185             :                                 "direction for 1D Axisymmetric or in z direction for 2D "
     186             :                                 "Cartesian problems)");
     187       15472 :   params.addParam<VariableName>("out_of_plane_strain",
     188             :                                 "Variable for the out-of-plane strain for plane stress models");
     189       15472 :   MooseEnum outOfPlaneDirection("x y z", "z");
     190       15472 :   params.addParam<MooseEnum>(
     191             :       "out_of_plane_direction", outOfPlaneDirection, "The direction of the out-of-plane strain.");
     192       15472 :   params.addDeprecatedParam<FunctionName>(
     193             :       "out_of_plane_pressure",
     194             :       "Function used to prescribe pressure (applied toward the body) in the out-of-plane direction "
     195             :       "(y for 1D Axisymmetric or z for 2D Cartesian problems)",
     196             :       "This has been replaced by 'out_of_plane_pressure_function'");
     197       15472 :   params.addParam<FunctionName>(
     198             :       "out_of_plane_pressure_function",
     199             :       "Function used to prescribe pressure (applied toward the body) in the out-of-plane direction "
     200             :       "(y for 1D Axisymmetric or z for 2D Cartesian problems)");
     201       15472 :   params.addParam<Real>(
     202             :       "pressure_factor",
     203             :       "Scale factor applied to prescribed out-of-plane pressure (both material and function)");
     204       15472 :   params.addParam<MaterialPropertyName>("out_of_plane_pressure_material",
     205             :                                         "0",
     206             :                                         "Material used to prescribe pressure (applied toward the "
     207             :                                         "body) in the out-of-plane direction");
     208       15472 :   params.addParamNamesToGroup("planar_formulation scalar_out_of_plane_strain out_of_plane_pressure "
     209             :                               "out_of_plane_pressure_material out_of_plane_pressure_function "
     210             :                               "pressure_factor out_of_plane_direction out_of_plane_strain",
     211             :                               "Out-of-plane stress/strain");
     212             : 
     213             :   // Output
     214       15472 :   params.addParam<MultiMooseEnum>("generate_output",
     215       15472 :                                   QuasiStaticSolidMechanicsPhysicsBase::outputPropertiesType(),
     216             :                                   "Add scalar quantity output for stress and/or strain");
     217             : 
     218       15472 :   params.addParam<MultiMooseEnum>(
     219             :       "material_output_order",
     220       15472 :       QuasiStaticSolidMechanicsPhysicsBase::materialOutputOrders(),
     221             :       "Specifies the order of the FE shape function to use for this variable.");
     222             : 
     223       15472 :   params.addParam<MultiMooseEnum>(
     224             :       "material_output_family",
     225       15472 :       QuasiStaticSolidMechanicsPhysicsBase::materialOutputFamilies(),
     226             :       "Specifies the family of FE shape functions to use for this variable.");
     227       15472 :   params.addParamNamesToGroup("generate_output material_output_order material_output_family",
     228             :                               "Output");
     229       15472 :   params.addParam<bool>("verbose", false, "Display extra information.");
     230             : 
     231       15472 :   params.addParam<bool>("new_system",
     232       15472 :                         false,
     233             :                         "If true use the new "
     234             :                         "LagrangianStressDiverence kernels.");
     235             : 
     236       15472 :   params.addParam<bool>(
     237             :       "compatibility_mode",
     238       15472 :       false,
     239             :       "If true, configure the Lagrangian kernel system to reproduce the OLD "
     240             :       "(StressDivergenceTensors + ComputeFiniteStrain) results bit-for-bit when wrapping an "
     241             :       "old-style ComputeStressBase material like ComputeMultiPlasticityStress. Implies "
     242             :       "`new_system = true` and `formulation = TOTAL`; auto-adds ComputeLagrangianWrappedStress "
     243             :       "around the user-supplied stress material; sets `kinematic_approximation` from "
     244             :       "`decomposition_method`; sets `F_bar_mode = incremental` when "
     245             :       "`volumetric_locking_correction = true`; redirects `stress` / `mechanical_strain` output "
     246             :       "requests to the equivalent NEW-system properties (`cauchy_stress` / "
     247             :       "`rotated_mechanical_strain`).");
     248             : 
     249       15472 :   MooseEnum formulationType("TOTAL UPDATED", "TOTAL");
     250       15472 :   params.addParam<MooseEnum>("formulation",
     251             :                              formulationType,
     252             :                              "Select between the total Lagrangian (TOTAL) "
     253             :                              "and updated Lagrangian (UPDATED) formulations "
     254             :                              "for the new kernel system.");
     255             : 
     256       15472 :   MooseEnum kinematicApproximation("linear quadratic rashid_approximate rashid_eigen", "linear");
     257       15472 :   params.addParam<MooseEnum>(
     258             :       "kinematic_approximation",
     259             :       kinematicApproximation,
     260             :       "Approximation used by the Lagrangian strain calculator to convert the incremental "
     261             :       "deformation gradient into the strain and vorticity increments (large deformation only).");
     262             : 
     263       23208 :   params.addRangeCheckedParam<Real>(
     264             :       "generalized_midpoint_alpha",
     265       15472 :       1.0,
     266             :       "generalized_midpoint_alpha >= 0.5 & generalized_midpoint_alpha <= 1.0",
     267             :       "Generalized midpoint weight for the deformation gradient in the Lagrangian strain "
     268             :       "calculator.  1.0 = backward Euler (default), 0.5 = midpoint rule.");
     269             : 
     270       15472 :   MooseEnum volumetricLockingCorrectionMode("total incremental", "total");
     271       15472 :   params.addParam<MooseEnum>(
     272             :       "volumetric_locking_correction_mode",
     273             :       volumetricLockingCorrectionMode,
     274             :       "Volumetric part averaged by the F-bar volumetric locking correction in the Lagrangian "
     275             :       "strain calculator: the total (default) or incremental deformation gradient.");
     276             : 
     277       15472 :   params.addParamNamesToGroup("add_variables displacements temperature", "Variables");
     278       15472 :   params.addParamNamesToGroup("strain incremental use_finite_deform_jacobian eigenstrain_names "
     279             :                               "volumetric_locking_correction kinematic_approximation "
     280             :                               "generalized_midpoint_alpha volumetric_locking_correction_mode",
     281             :                               "Strain");
     282       15472 :   params.addParamNamesToGroup("new_system compatibility_mode formulation",
     283             :                               "Lagrangian formulation");
     284             : 
     285        7736 :   return params;
     286        7736 : }
     287             : 
     288        4511 : QuasiStaticSolidMechanicsPhysicsBase::QuasiStaticSolidMechanicsPhysicsBase(
     289        4511 :     const InputParameters & parameters)
     290        9022 :   : Action(parameters), _use_ad(getParam<bool>("use_automatic_differentiation"))
     291             : {
     292        4511 :   const auto & params = _app.getInputParameterWarehouse().getInputParameters();
     293        4511 :   InputParameters & pars(*(params.find(uniqueActionName())->second.get()));
     294             : 
     295             :   // check if a container block with common parameters is found
     296        4511 :   auto action = _awh.getActions<CommonSolidMechanicsAction>();
     297        4511 :   if (action.size() == 1)
     298        3286 :     pars.applyParameters(action[0]->parameters());
     299             : 
     300             :   // append additional_generate_output
     301        9022 :   if (isParamValid("additional_generate_output"))
     302             :   {
     303          30 :     MultiMooseEnum generate_output = getParam<MultiMooseEnum>("generate_output");
     304             :     MultiMooseEnum additional_generate_output =
     305          30 :         getParam<MultiMooseEnum>("additional_generate_output");
     306             : 
     307          30 :     MultiMooseEnum material_output_order = getParam<MultiMooseEnum>("material_output_order");
     308             :     MultiMooseEnum additional_material_output_order =
     309          30 :         getParam<MultiMooseEnum>("additional_material_output_order");
     310             : 
     311          30 :     MultiMooseEnum material_output_family = getParam<MultiMooseEnum>("material_output_family");
     312             :     MultiMooseEnum additional_material_output_family =
     313          45 :         getParam<MultiMooseEnum>("additional_material_output_family");
     314             : 
     315          30 :     for (auto & output : additional_generate_output)
     316          30 :       generate_output.setAdditionalValue(output);
     317          15 :     for (auto & order : additional_material_output_order)
     318           0 :       material_output_order.setAdditionalValue(order);
     319          15 :     for (auto & family : additional_material_output_family)
     320           0 :       material_output_family.setAdditionalValue(family);
     321             : 
     322          15 :     pars.set<MultiMooseEnum>("generate_output") = generate_output;
     323          15 :     pars.set<MultiMooseEnum>("material_output_order") = material_output_order;
     324          15 :     pars.set<MultiMooseEnum>("material_output_family") = material_output_family;
     325          15 :   }
     326        4511 : }
     327             : 
     328             : MultiMooseEnum
     329       12247 : QuasiStaticSolidMechanicsPhysicsBase::materialOutputOrders()
     330             : {
     331       12247 :   auto orders = AddAuxVariableAction::getAuxVariableOrders().getRawNames();
     332             : 
     333       24494 :   return MultiMooseEnum(orders);
     334             : }
     335             : 
     336             : MultiMooseEnum
     337       12247 : QuasiStaticSolidMechanicsPhysicsBase::materialOutputFamilies()
     338             : {
     339       24494 :   return MultiMooseEnum("MONOMIAL LAGRANGE");
     340             : }
     341             : 
     342             : MultiMooseEnum
     343       12247 : QuasiStaticSolidMechanicsPhysicsBase::outputPropertiesType()
     344             : {
     345       12247 :   std::string options = "";
     346      159211 :   for (auto & r2tc : _rank_two_cartesian_component_table)
     347      587856 :     for (unsigned int a = 0; a < 3; ++a)
     348     1763568 :       for (unsigned int b = 0; b < 3; ++b)
     349     3955781 :         options += (options == "" ? "" : " ") + r2tc.first + '_' + _component_table[a] +
     350     1322676 :                    _component_table[b];
     351             : 
     352      183705 :   for (auto & r2i : _rank_two_invariant_table)
     353     1089983 :     for (auto & t : r2i.second.second)
     354     2755575 :       options += " " + r2i.first + "_" + t;
     355             : 
     356       24494 :   for (auto & r2sdc : _rank_two_directional_component_table)
     357       36741 :     for (auto & r : r2sdc.second.second)
     358       73482 :       options += " " + r2sdc.first + "_" + r;
     359             : 
     360       48988 :   for (auto & r2cc : _rank_two_cylindrical_component_table)
     361      183705 :     for (auto & r : r2cc.second.second)
     362      440892 :       options += " " + r2cc.first + "_" + r;
     363             : 
     364       36741 :   for (auto & r2sc : _rank_two_spherical_component_table)
     365      110223 :     for (auto & r : r2sc.second.second)
     366      257187 :       options += " " + r2sc.first + "_" + r;
     367             : 
     368       24494 :   return MultiMooseEnum(options, "", true);
     369             : }
     370             : 
     371             : void
     372           0 : QuasiStaticSolidMechanicsPhysicsBase::addCartesianComponentOutput(const std::string & enum_name,
     373             :                                                                   const std::string & prop_name)
     374             : {
     375           0 :   if (prop_name.empty())
     376             :     // the enum name is the actual tensor material property name
     377           0 :     _rank_two_cartesian_component_table.emplace(enum_name, enum_name);
     378             :   else
     379             :     // supply a different name for the enum options (this is done for
     380             :     // 'strain' -> 'mechanical_strain' in the TMA)
     381           0 :     _rank_two_cartesian_component_table.emplace(enum_name, prop_name);
     382           0 : }

Generated by: LCOV version 1.14