LCOV - code coverage report
Current view: top level - src/actions - GeneralizedPlaneStrainActionPD.C (source / functions) Hit Total Coverage
Test: idaholab/moose peridynamics: #31405 (292dce) with base fef103 Lines: 73 79 92.4 %
Date: 2025-09-04 07:55:08 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 "GeneralizedPlaneStrainActionPD.h"
      11             : #include "NonlinearSystemBase.h"
      12             : #include "Factory.h"
      13             : #include "FEProblemBase.h"
      14             : #include "MooseObjectAction.h"
      15             : 
      16             : registerMooseAction("PeridynamicsApp", GeneralizedPlaneStrainActionPD, "add_kernel");
      17             : registerMooseAction("PeridynamicsApp", GeneralizedPlaneStrainActionPD, "add_user_object");
      18             : registerMooseAction("PeridynamicsApp", GeneralizedPlaneStrainActionPD, "add_scalar_kernel");
      19             : 
      20             : InputParameters
      21          57 : GeneralizedPlaneStrainActionPD::validParams()
      22             : {
      23          57 :   InputParameters params = Action::validParams();
      24          57 :   params.addClassDescription("Class for setting up the Kernel, ScalarKernel, and UserObject for "
      25             :                              "peridynamic generalized plane strain model");
      26             : 
      27         114 :   params.addRequiredParam<std::vector<VariableName>>(
      28             :       "displacements", "Nonlinear variable name for the displacements");
      29         114 :   params.addRequiredParam<VariableName>("scalar_out_of_plane_strain",
      30             :                                         "Scalar variable for strain in the out-of-plane direction");
      31         114 :   params.addParam<VariableName>("temperature", "Nonlinear variable for the temperature");
      32         114 :   MooseEnum formulation_option("ORDINARY_STATE NONORDINARY_STATE", "NONORDINARY_STATE");
      33         114 :   params.addParam<MooseEnum>("formulation", formulation_option, "Peridynamic formulation options");
      34         114 :   MooseEnum strain_type("SMALL FINITE", "SMALL");
      35         114 :   params.addParam<MooseEnum>("strain", strain_type, "Strain formulation");
      36         114 :   params.addParam<VariableName>("out_of_plane_stress_variable",
      37             :                                 "Name of out-of-plane stress auxiliary variable");
      38         114 :   params.addParam<FunctionName>(
      39             :       "out_of_plane_pressure",
      40             :       "0",
      41             :       "Function used to prescribe pressure in the out-of-plane direction");
      42         114 :   params.addParam<Real>("factor", 1.0, "Scale factor applied to prescribed out-of-plane pressure");
      43         114 :   params.addParam<bool>("full_jacobian",
      44         114 :                         false,
      45             :                         "Parameter to set whether to use the nonlocal full Jacobian formulation "
      46             :                         "for the scalar components");
      47         114 :   params.addParam<std::vector<SubdomainName>>("block",
      48             :                                               "List of ids of the blocks (subdomains) that the "
      49             :                                               "GeneralizedPlaneStrainActionPD will be applied "
      50             :                                               "to");
      51         114 :   params.addParam<std::vector<MaterialPropertyName>>(
      52             :       "eigenstrain_names", {}, "List of eigenstrains to be applied in this strain calculation");
      53             : 
      54          57 :   return params;
      55          57 : }
      56             : 
      57          57 : GeneralizedPlaneStrainActionPD::GeneralizedPlaneStrainActionPD(const InputParameters & params)
      58             :   : Action(params),
      59         114 :     _displacements(getParam<std::vector<VariableName>>("displacements")),
      60          57 :     _ndisp(_displacements.size()),
      61         114 :     _formulation(getParam<MooseEnum>("formulation")),
      62         114 :     _scalar_out_of_plane_strain(getParam<VariableName>("scalar_out_of_plane_strain"))
      63             : {
      64             :   // Generalized plane strain only applies to two dimensional modeling and simulation
      65          57 :   if (_ndisp != 2)
      66           0 :     mooseError("GeneralizedPlaneStrainPD only works for two dimensional case!");
      67             : 
      68             :   // Consistency check
      69          99 :   if (_formulation == "NONORDINARY_STATE" && isParamValid("out_of_plane_stress_variable"))
      70           0 :     mooseWarning("Variable out_of_plane_stress_variable will not be used in NONORDINARY_STATE "
      71             :                  "formulation option!");
      72         165 :   if (_formulation == "ORDINARY_STATE" && !isParamValid("out_of_plane_stress_variable"))
      73           0 :     mooseError("Variable out_of_plane_stress_variable must be provided for ORDINARY_STATE "
      74             :                "formulation option!");
      75          57 : }
      76             : 
      77             : void
      78         171 : GeneralizedPlaneStrainActionPD::act()
      79             : {
      80         171 :   if (_current_task == "add_kernel")
      81             :   {
      82             :     std::string k_type;
      83          57 :     if (_formulation == "ORDINARY_STATE")
      84             :       k_type = "GeneralizedPlaneStrainOffDiagOSPD"; // Based on the ordinary state-based model
      85          21 :     else if (_formulation == "NONORDINARY_STATE")
      86             :       k_type = "GeneralizedPlaneStrainOffDiagNOSPD"; // Based on Form I of horizon-stabilized
      87             :                                                      // correspondence model
      88             :     else
      89           0 :       paramError("formulation", "Unsupported peridynamic formulation");
      90             : 
      91          57 :     InputParameters params = _factory.getValidParams(k_type);
      92             : 
      93          57 :     params.applyParameters(parameters(),
      94             :                            {"displacements", "temperature", "scalar_out_of_plane_strain"});
      95             : 
      96         114 :     params.set<std::vector<VariableName>>("displacements") = _displacements;
      97         114 :     params.set<std::vector<VariableName>>("scalar_out_of_plane_strain") = {
      98         228 :         _scalar_out_of_plane_strain};
      99             : 
     100             :     // Coupling between scalar out-of-plane strain and in-plane displacements
     101         171 :     for (unsigned int i = 0; i < _ndisp; ++i)
     102             :     {
     103         228 :       std::string k_name = name() + "_GeneralizedPlaneStrainPDOffDiag_disp_" + Moose::stringify(i);
     104         228 :       params.set<NonlinearVariableName>("variable") = _displacements[i];
     105             : 
     106         114 :       _problem->addKernel(k_type, k_name, params);
     107             :     }
     108             : 
     109             :     // Coupling between scalar out-of-plane strain and temperature (only when temperature is a
     110             :     // nonlinear variable)
     111         114 :     if (isParamValid("temperature"))
     112             :     {
     113          16 :       VariableName temp = getParam<VariableName>("temperature");
     114          16 :       if (_problem->getNonlinearSystemBase(/*nl_sys_num=*/0).hasVariable(temp))
     115             :       {
     116          48 :         params.set<std::vector<VariableName>>("temperature") = {temp};
     117             : 
     118          16 :         std::string k_name = name() + "_GeneralizedPlaneStrainPDOffDiag_temp";
     119          32 :         params.set<NonlinearVariableName>("variable") = temp;
     120             : 
     121          16 :         if (_formulation == "NONORDINARY_STATE")
     122          16 :           params.set<std::vector<MaterialPropertyName>>("eigenstrain_names") =
     123          24 :               getParam<std::vector<MaterialPropertyName>>("eigenstrain_names");
     124             : 
     125          16 :         _problem->addKernel(k_type, k_name, params);
     126             :       }
     127             :     }
     128          57 :   }
     129         114 :   else if (_current_task == "add_user_object")
     130             :   {
     131             :     std::string uo_type;
     132          57 :     if (_formulation == "ORDINARY_STATE")
     133             :       uo_type = "GeneralizedPlaneStrainUserObjectOSPD";
     134          21 :     else if (_formulation == "NONORDINARY_STATE")
     135             :       uo_type = "GeneralizedPlaneStrainUserObjectNOSPD";
     136             :     else
     137           0 :       paramError("formulation", "Unsupported peridynamic formulation!");
     138             : 
     139          57 :     InputParameters params = _factory.getValidParams(uo_type);
     140             : 
     141          57 :     std::string uo_name = name() + "_GeneralizedPlaneStrainPDUserObject";
     142             : 
     143          57 :     params.applyParameters(parameters(), {"out_of_plane_stress_variable"});
     144             : 
     145          57 :     if (_formulation == "ORDINARY_STATE")
     146          72 :       params.set<std::vector<VariableName>>("out_of_plane_stress_variable") = {
     147         144 :           getParam<VariableName>("out_of_plane_stress_variable")};
     148             : 
     149          57 :     _problem->addUserObject(uo_type, uo_name, params);
     150          57 :   }
     151          57 :   else if (_current_task == "add_scalar_kernel")
     152             :   {
     153          57 :     std::string sk_type("GeneralizedPlaneStrainPD");
     154          57 :     InputParameters params = _factory.getValidParams(sk_type);
     155             : 
     156          57 :     std::string sk_name = name() + "_GeneralizedPlaneStrainPD";
     157             : 
     158         114 :     params.set<NonlinearVariableName>("variable") = _scalar_out_of_plane_strain;
     159             : 
     160             :     // set the UserObjectName using added UserObject
     161         114 :     params.set<UserObjectName>("generalized_plane_strain_uo") =
     162          57 :         name() + "_GeneralizedPlaneStrainPDUserObject";
     163             : 
     164          57 :     _problem->addScalarKernel(sk_type, sk_name, params);
     165          57 :   }
     166             :   else
     167           0 :     mooseError("Task error in GeneralizedPlaneStrainActionPD!");
     168         243 : }

Generated by: LCOV version 1.14