LCOV - code coverage report
Current view: top level - src/actions - MastodonModelAction.C (source / functions) Hit Total Coverage
Test: idaholab/mastodon: 55510a Lines: 115 116 99.1 %
Date: 2025-08-26 23:09:31 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*************************************************/
       2             : /*           DO NOT MODIFY THIS HEADER           */
       3             : /*                                               */
       4             : /*                     MASTODON                  */
       5             : /*                                               */
       6             : /*    (c) 2015 Battelle Energy Alliance, LLC     */
       7             : /*            ALL RIGHTS RESERVED                */
       8             : /*                                               */
       9             : /*   Prepared by Battelle Energy Alliance, LLC   */
      10             : /*     With the U. S. Department of Energy       */
      11             : /*                                               */
      12             : /*     See COPYRIGHT for full restrictions       */
      13             : /*************************************************/
      14             : 
      15             : #include "MastodonModelAction.h"
      16             : 
      17             : // MOOSE includes
      18             : #include "Conversion.h"
      19             : #include "Factory.h"
      20             : #include "FEProblem.h"
      21             : #include "MooseMesh.h"
      22             : #include "Action.h"
      23             : #include "MooseObjectAction.h"
      24             : 
      25             : registerMooseAction("MastodonApp", MastodonModelAction, "meta_action");
      26             : 
      27             : registerMooseAction("MastodonApp", MastodonModelAction, "add_variable");
      28             : 
      29             : registerMooseAction("MastodonApp", MastodonModelAction, "add_aux_variable");
      30             : 
      31             : registerMooseAction("MastodonApp", MastodonModelAction, "add_kernel");
      32             : 
      33             : registerMooseAction("MastodonApp", MastodonModelAction, "add_aux_kernel");
      34             : 
      35             : InputParameters
      36          16 : MastodonModelAction::validParams()
      37             : {
      38          16 :   InputParameters params = Action::validParams();
      39          16 :   params.addClassDescription("Creates the required displacement Variables, velocity and "
      40             :                              "acceleration AuxVariables and AuxKernels, inertia kernels and the "
      41             :                              "DynamicTensorMechanicsAction based on the dimension of the mesh and "
      42             :                              "if static or dynamic analysis is being performed.");
      43          32 :   params.addParam<std::vector<SubdomainName>>("block",
      44             :                                               "A list of ids of the blocks (subdomains) "
      45             :                                               "that these model parameters apply to.");
      46          32 :   params.addParam<bool>("dynamic_analysis", true, "false, if static analysis is to be performed.");
      47          32 :   params.addParam<Real>("beta", 0.25, "beta parameter for Newmark time integration.");
      48          32 :   params.addParam<Real>("gamma", 0.5, "gamma parameter for Newmark time integration.");
      49          32 :   params.addParam<std::vector<NonlinearVariableName>>(
      50             :       "displacements",
      51          80 :       std::vector<NonlinearVariableName>({"disp_x", "disp_y", "disp_z"}),
      52             :       "Names of the displacement variables.");
      53          32 :   params.addParam<std::vector<AuxVariableName>>(
      54             :       "velocities",
      55          80 :       std::vector<AuxVariableName>({"vel_x", "vel_y", "vel_z"}),
      56             :       "Names of the velocity variables.");
      57          32 :   params.addParam<std::vector<AuxVariableName>>(
      58             :       "accelerations",
      59          80 :       std::vector<AuxVariableName>({"accel_x", "accel_y", "accel_z"}),
      60             :       "Names of the acceleration variables.");
      61          32 :   MooseEnum dim("1=1 2=2 3=3", "3");
      62          32 :   params.addParam<MooseEnum>("dim", dim, "Dimension of the mesh.");
      63          32 :   params.addParam<MaterialPropertyName>(
      64          32 :       "eta", 0.0, "eta parameter or mass matrix multiplier for Rayleigh damping.");
      65          32 :   params.addParam<MaterialPropertyName>(
      66          32 :       "zeta", 0.0, "zeta parameter or stiffness matrix multiplier for Rayleigh damping.");
      67          32 :   params.addParam<bool>(
      68          32 :       "use_displaced_mesh", false, "true, if calculations are performed on displaced mesh.");
      69          16 :   return params;
      70          16 : }
      71             : 
      72          16 : MastodonModelAction::MastodonModelAction(const InputParameters & params)
      73             :   : Action(params),
      74          16 :     _disp_variables(getParam<std::vector<NonlinearVariableName>>("displacements")),
      75          32 :     _vel_auxvariables(getParam<std::vector<AuxVariableName>>("velocities")),
      76          32 :     _accel_auxvariables(getParam<std::vector<AuxVariableName>>("accelerations")),
      77          32 :     _dim(getParam<MooseEnum>("dim")),
      78          48 :     _use_displaced_mesh(getParam<bool>("use_displaced_mesh"))
      79             : {
      80          16 : }
      81             : 
      82             : void
      83          78 : MastodonModelAction::act()
      84             : {
      85             :   // Adding displacement Variables
      86          78 :   if (_current_task == "add_variable")
      87          16 :     addDisplacementVariables();
      88             : 
      89             :   // Adding DynamicTensorMechanicsAction
      90          77 :   if (_current_task == "meta_action")
      91          16 :     addDynamicTensorMechanicsAction();
      92             : 
      93             :   // Adding AuxVariables and AuxKernels required for dynamic analysis. These
      94             :   // include velocity and acceleration AuxVariables and AuxKernels.
      95         154 :   const bool dynamic_analysis = getParam<bool>("dynamic_analysis");
      96          77 :   if (dynamic_analysis)
      97             :   {
      98             :     // Adding velocity and acceleration AuxVariables
      99          62 :     if (_current_task == "add_aux_variable")
     100          13 :       addVelAccelAuxVariables();
     101             : 
     102             :     // Adding inertia kernels
     103          62 :     if (_current_task == "add_kernel")
     104          12 :       addInertiaKernels();
     105             : 
     106             :     // Adding velocity and acceleration Auxkernels
     107          62 :     if (_current_task == "add_aux_kernel")
     108          12 :       addVelAccelAuxKernels();
     109             :   }
     110          77 : }
     111             : 
     112             : void
     113          16 : MastodonModelAction::addDynamicTensorMechanicsAction()
     114             : {
     115             :   std::vector<VariableName> dim_disp_variables(_disp_variables.begin(),
     116          16 :                                                _disp_variables.begin() + _dim);
     117             :   // Retrieve action parameters and set the parameters
     118             :   InputParameters action_params =
     119          16 :       _action_factory.getValidParams("LegacyDynamicTensorMechanicsAction");
     120          16 :   action_params.set<std::vector<VariableName>>("displacements") = dim_disp_variables;
     121          16 :   action_params.applyParameters(parameters(), {"eta", "zeta"});
     122          32 :   action_params.set<MaterialPropertyName>("mass_damping_coefficient") =
     123          16 :       getParam<MaterialPropertyName>("eta");
     124          32 :   action_params.set<MaterialPropertyName>("stiffness_damping_coefficient") =
     125          16 :       getParam<MaterialPropertyName>("zeta");
     126             :   // Create the action and add it to the action warehouse
     127             :   std::shared_ptr<Action> dynamictensormechanics_action =
     128          32 :       std::static_pointer_cast<Action>(_action_factory.create(
     129             :           "LegacyDynamicTensorMechanicsAction", "DynamicTensorMechanics", action_params));
     130          48 :   _awh.addActionBlock(dynamictensormechanics_action);
     131          16 : }
     132             : 
     133             : void
     134          16 : MastodonModelAction::addDisplacementVariables()
     135             : {
     136          16 :   if (_dim != _problem->mesh().dimension())
     137           1 :     mooseError("Error in MastodonModelAction block, ",
     138             :                name(),
     139             :                ". dim is not equal to the mesh dimension, which is ",
     140           1 :                _problem->mesh().dimension(),
     141             :                ".");
     142             : 
     143          15 :   auto params = _factory.getValidParams("MooseVariable");
     144             :   // determine necessary order
     145          15 :   const bool second = _problem->mesh().hasSecondOrderElements();
     146             : 
     147          45 :   params.set<MooseEnum>("order") = second ? "SECOND" : "FIRST";
     148          30 :   params.set<MooseEnum>("family") = "LAGRANGE";
     149          30 :   if (isParamValid("scaling"))
     150           0 :     params.set<std::vector<Real>>("scaling") = {getParam<Real>("scaling")};
     151             : 
     152             :   // Loop through the displacement variables
     153          54 :   for (std::size_t j = 0; j < _problem->mesh().dimension(); j++)
     154             :   {
     155             :     // Create displacement variables
     156          78 :     _problem->addVariable("MooseVariable", _disp_variables[j], params);
     157             :   }
     158          15 : }
     159             : 
     160             : void
     161          13 : MastodonModelAction::addVelAccelAuxVariables()
     162             : {
     163          13 :   auto params = _factory.getValidParams("MooseVariable");
     164          13 :   const bool second = _problem->mesh().hasSecondOrderElements();
     165          39 :   params.set<MooseEnum>("order") = second ? "SECOND" : "FIRST";
     166          26 :   params.set<MooseEnum>("family") = "LAGRANGE";
     167          45 :   for (std::size_t j = 0; j < _problem->mesh().dimension(); j++)
     168             :   {
     169          32 :     _problem->addAuxVariable("MooseVariable", _vel_auxvariables[j], params);
     170          64 :     _problem->addAuxVariable("MooseVariable", _accel_auxvariables[j], params);
     171             :   }
     172          13 : }
     173             : 
     174             : void
     175          12 : MastodonModelAction::addInertiaKernels()
     176             : {
     177          12 :   const std::vector<std::string> comp = {"x", "y", "z"};
     178          42 :   for (std::size_t i = 0; i < _problem->mesh().dimension(); i++)
     179             :   {
     180          60 :     InputParameters params = _factory.getValidParams("InertialForce");
     181          60 :     params.set<NonlinearVariableName>("variable") = _disp_variables[i];
     182          90 :     params.set<std::vector<VariableName>>("velocity") = {_vel_auxvariables[i]};
     183          90 :     params.set<std::vector<VariableName>>("acceleration") = {_accel_auxvariables[i]};
     184          60 :     params.set<Real>("beta") = getParam<Real>("beta");
     185          60 :     params.set<Real>("gamma") = getParam<Real>("gamma");
     186          90 :     params.set<MaterialPropertyName>("eta") = getParam<MaterialPropertyName>("eta");
     187          30 :     params.set<bool>("use_displaced_mesh") = _use_displaced_mesh;
     188          60 :     _problem->addKernel("InertialForce", "inertia" + comp[i], params);
     189          30 :   }
     190          72 : }
     191             : 
     192             : void
     193          12 : MastodonModelAction::addVelAccelAuxKernels()
     194             : {
     195          12 :   const std::vector<std::string> vel_auxkernel = {"vel_x", "vel_y", "vel_z"};
     196          12 :   const std::vector<std::string> accel_auxkernel = {"accel_x", "accel_y", "accel_z"};
     197          24 :   const Real beta = getParam<Real>("beta");
     198          24 :   const Real gamma = getParam<Real>("gamma");
     199          42 :   for (std::size_t j = 0; j < _problem->mesh().dimension(); j++)
     200             :   {
     201             :     // Velocity AuxKernels: These Auxkernels are added as MooseObjectActions
     202             :     // due to conflicts with DynamicTensorMechanicsAction when added using
     203             :     // addAuxKernel method. TODO: See if this needs to be fixed later.
     204          30 :     InputParameters action_params = _action_factory.getValidParams("AddKernelAction");
     205             :     // Create the action
     206          30 :     action_params.set<std::string>("type") = "NewmarkVelAux";
     207          30 :     action_params.set<std::string>("task") = "add_aux_kernel";
     208             :     std::shared_ptr<MooseObjectAction> vel_action = std::static_pointer_cast<MooseObjectAction>(
     209          60 :         _action_factory.create("AddKernelAction", vel_auxkernel[j], action_params));
     210             : 
     211             :     // Assigning input parameters
     212             :     InputParameters & vel_kernel_params = vel_action->getObjectParams();
     213          60 :     vel_kernel_params.set<AuxVariableName>("variable") = _vel_auxvariables[j];
     214          90 :     vel_kernel_params.set<std::vector<VariableName>>("acceleration") = {_accel_auxvariables[j]};
     215          30 :     vel_kernel_params.set<Real>("gamma") = gamma;
     216          30 :     vel_kernel_params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_END;
     217             :     // Add the action to the warehouse
     218          60 :     _awh.addActionBlock(vel_action);
     219             : 
     220             :     // Acceleration AuxKernels: Added using the addAuxKernel method
     221          60 :     InputParameters accel_kernel_params = _factory.getValidParams("NewmarkAccelAux");
     222          60 :     accel_kernel_params.set<AuxVariableName>("variable") = _accel_auxvariables[j];
     223          90 :     accel_kernel_params.set<std::vector<VariableName>>("displacement") = {_disp_variables[j]};
     224          90 :     accel_kernel_params.set<std::vector<VariableName>>("velocity") = {_vel_auxvariables[j]};
     225          30 :     accel_kernel_params.set<Real>("beta") = beta;
     226          30 :     accel_kernel_params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_END;
     227          30 :     _problem->addAuxKernel("NewmarkAccelAux", accel_auxkernel[j], accel_kernel_params);
     228          60 :   }
     229         102 : }

Generated by: LCOV version 1.14