LCOV - code coverage report
Current view: top level - src/actions - GeneralizedPlaneStrainAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 76 80 95.0 %
Date: 2025-07-25 05:00:39 Functions: 3 3 100.0 %
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 "GeneralizedPlaneStrainAction.h"
      11             : 
      12             : #include "Conversion.h"
      13             : #include "FEProblem.h"
      14             : #include "MooseMesh.h"
      15             : #include "NonlinearSystemBase.h"
      16             : 
      17             : registerMooseAction("SolidMechanicsApp", GeneralizedPlaneStrainAction, "add_scalar_kernel");
      18             : 
      19             : registerMooseAction("SolidMechanicsApp", GeneralizedPlaneStrainAction, "add_kernel");
      20             : 
      21             : registerMooseAction("SolidMechanicsApp", GeneralizedPlaneStrainAction, "add_user_object");
      22             : 
      23             : InputParameters
      24         194 : GeneralizedPlaneStrainAction::validParams()
      25             : {
      26         194 :   InputParameters params = Action::validParams();
      27         194 :   params.addClassDescription("Set up the GeneralizedPlaneStrain environment");
      28         388 :   params.addRequiredParam<std::vector<VariableName>>("displacements", "The displacement variables");
      29         388 :   params.addRequiredParam<VariableName>("scalar_out_of_plane_strain",
      30             :                                         "Scalar variable for the out-of-plane strain (in "
      31             :                                         "y direction for 1D Axisymmetric or in z "
      32             :                                         "direction for 2D Cartesian problems)");
      33         388 :   params.addParam<std::vector<VariableName>>("temperature", "The temperature variable");
      34         388 :   MooseEnum outOfPlaneDirection("x y z", "z");
      35         388 :   params.addParam<MooseEnum>(
      36             :       "out_of_plane_direction", outOfPlaneDirection, "The direction of the out-of-plane strain.");
      37         388 :   params.addParam<FunctionName>(
      38             :       "out_of_plane_pressure_function",
      39             :       "Function used to prescribe pressure (applied toward the body) in the out-of-plane direction "
      40             :       "(y for 1D Axisymmetric or z for 2D Cartesian problems)");
      41         388 :   params.addDeprecatedParam<FunctionName>(
      42             :       "out_of_plane_pressure",
      43             :       "Function used to prescribe pressure (applied toward the body) in the out-of-plane direction "
      44             :       "(y for 1D Axisymmetric or z for 2D Cartesian problems)",
      45             :       "This has been replaced by 'out_of_plane_pressure_function'");
      46         388 :   params.addParam<MaterialPropertyName>("out_of_plane_pressure_material",
      47             :                                         "0",
      48             :                                         "Material used to prescribe pressure (applied toward the "
      49             :                                         "body) in the out-of-plane direction");
      50         388 :   params.addDeprecatedParam<Real>(
      51             :       "factor",
      52             :       "Scale factor applied to prescribed out-of-plane pressure (both material and function)",
      53             :       "This has been replaced by 'pressure_factor'");
      54         388 :   params.addParam<Real>(
      55             :       "pressure_factor",
      56             :       "Scale factor applied to prescribed out-of-plane pressure (both material and function)");
      57         388 :   params.addParam<bool>("use_displaced_mesh", false, "Whether to use displaced mesh");
      58         388 :   params.addParam<std::string>("base_name", "Material property base name");
      59         388 :   params.addParam<std::vector<SubdomainName>>("block",
      60             :                                               "The list of ids of the blocks (subdomain) "
      61             :                                               "that the GeneralizedPlaneStrain kernels "
      62             :                                               "will be applied to");
      63         388 :   params.addParam<std::vector<TagName>>(
      64             :       "extra_vector_tags",
      65             :       "The tag names for extra vectors that residual data should be saved into");
      66         388 :   params.addParam<std::vector<TagName>>("absolute_value_vector_tags",
      67             :                                         "The tag names for extra vectors that the absolute value "
      68             :                                         "of the residual should be accumulated into");
      69             : 
      70         194 :   return params;
      71         194 : }
      72             : 
      73         194 : GeneralizedPlaneStrainAction::GeneralizedPlaneStrainAction(const InputParameters & params)
      74             :   : Action(params),
      75         388 :     _displacements(getParam<std::vector<VariableName>>("displacements")),
      76         194 :     _ndisp(_displacements.size()),
      77         582 :     _out_of_plane_direction(getParam<MooseEnum>("out_of_plane_direction"))
      78             : {
      79         194 : }
      80             : 
      81             : void
      82         582 : GeneralizedPlaneStrainAction::act()
      83             : {
      84             :   // user object name
      85         582 :   const std::string uo_name = _name + "_GeneralizedPlaneStrainUserObject";
      86             : 
      87             :   //
      88             :   // Add off diagonal Jacobian kernels
      89             :   //
      90         582 :   if (_current_task == "add_kernel")
      91             :   {
      92         194 :     std::string k_type = "GeneralizedPlaneStrainOffDiag";
      93         194 :     InputParameters params = _factory.getValidParams(k_type);
      94             : 
      95         388 :     params.applyParameters(parameters(), {"scalar_out_of_plane_strain"});
      96         388 :     params.set<std::vector<VariableName>>("scalar_out_of_plane_strain") = {
      97         776 :         getParam<VariableName>("scalar_out_of_plane_strain")};
      98             : 
      99             :     // add off-diagonal jacobian kernels for the displacements
     100         592 :     for (unsigned int i = 0; i < _ndisp; ++i)
     101             :     {
     102         398 :       if (_out_of_plane_direction == i)
     103          48 :         continue;
     104             : 
     105         700 :       std::string k_name = _name + "GeneralizedPlaneStrainOffDiag_disp" + Moose::stringify(i);
     106         700 :       params.set<NonlinearVariableName>("variable") = _displacements[i];
     107             : 
     108         350 :       _problem->addKernel(k_type, k_name, params);
     109             :     }
     110             : 
     111             :     // add temperature kernel only if temperature is a nonlinear variable (and not an auxvariable)
     112         388 :     if (isParamValid("temperature"))
     113             :     {
     114         144 :       auto temp = getParam<std::vector<VariableName>>("temperature");
     115          48 :       if (temp.size() > 1)
     116           0 :         mooseError("Only one variable may be specified in 'temperature'");
     117          48 :       if (_problem->getNonlinearSystemBase(/*nl_sys_num=*/0).hasVariable(temp[0]))
     118             :       {
     119          18 :         std::string k_name = _name + "_GeneralizedPlaneStrainOffDiag_temp";
     120          36 :         params.set<NonlinearVariableName>("variable") = temp[0];
     121             : 
     122          18 :         _problem->addKernel(k_type, k_name, params);
     123             :       }
     124          48 :     }
     125         194 :   }
     126             : 
     127             :   //
     128             :   // Add user object
     129             :   //
     130         388 :   else if (_current_task == "add_user_object")
     131             :   {
     132         194 :     std::string uo_type = "GeneralizedPlaneStrainUserObject";
     133         194 :     InputParameters params = _factory.getValidParams(uo_type);
     134             : 
     135             :     // Skipping selected parameters in applyParameters() and then manually setting them only if they
     136             :     // are set by the user is just to prevent both the current and deprecated variants of these
     137             :     // parameters from both getting passed to the UserObject. Once we get rid of the deprecated
     138             :     // versions, we can just set them all with applyParameters().
     139         970 :     params.applyParameters(
     140             :         parameters(),
     141             :         {"out_of_plane_pressure", "out_of_plane_pressure_function", "factor", "pressure_factor"});
     142         388 :     if (parameters().isParamSetByUser("out_of_plane_pressure"))
     143           0 :       params.set<FunctionName>("out_of_plane_pressure") =
     144           0 :           getParam<FunctionName>("out_of_plane_pressure");
     145         388 :     if (parameters().isParamSetByUser("out_of_plane_pressure_function"))
     146          24 :       params.set<FunctionName>("out_of_plane_pressure_function") =
     147          24 :           getParam<FunctionName>("out_of_plane_pressure_function");
     148         388 :     if (parameters().isParamSetByUser("factor"))
     149           0 :       params.set<Real>("factor") = getParam<Real>("factor");
     150         388 :     if (parameters().isParamSetByUser("pressure_factor"))
     151          24 :       params.set<Real>("pressure_factor") = getParam<Real>("pressure_factor");
     152             : 
     153         194 :     _problem->addUserObject(uo_type, uo_name, params);
     154         194 :   }
     155             : 
     156             :   //
     157             :   // Add scalar kernel
     158             :   //
     159         194 :   else if (_current_task == "add_scalar_kernel")
     160             :   {
     161         194 :     std::string sk_type = "GeneralizedPlaneStrain";
     162         194 :     InputParameters params = _factory.getValidParams(sk_type);
     163             : 
     164         388 :     params.set<NonlinearVariableName>("variable") =
     165         582 :         getParam<VariableName>("scalar_out_of_plane_strain");
     166             : 
     167             :     // set the UserObjectName from previously added UserObject
     168         388 :     params.set<UserObjectName>("generalized_plane_strain") = uo_name;
     169             : 
     170         388 :     if (isParamValid("extra_vector_tags"))
     171          12 :       params.set<std::vector<TagName>>("extra_vector_tags") =
     172          18 :           getParam<std::vector<TagName>>("extra_vector_tags");
     173         388 :     if (isParamValid("absolute_value_vector_tags"))
     174          24 :       params.set<std::vector<TagName>>("absolute_value_vector_tags") =
     175          36 :           getParam<std::vector<TagName>>("absolute_value_vector_tags");
     176             : 
     177         194 :     _problem->addScalarKernel(sk_type, _name + "_GeneralizedPlaneStrain", params);
     178         194 :   }
     179        1552 : }

Generated by: LCOV version 1.14