LCOV - code coverage report
Current view: top level - src/physics - DynamicSolidMechanicsPhysics.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 87 92 94.6 %
Date: 2025-07-25 05:00:39 Functions: 5 5 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 "DynamicSolidMechanicsPhysics.h"
      11             : #include "Factory.h"
      12             : #include "FEProblem.h"
      13             : #include "Parser.h"
      14             : 
      15             : registerMooseAction("SolidMechanicsApp", DynamicSolidMechanicsPhysics, "meta_action");
      16             : 
      17             : registerMooseAction("SolidMechanicsApp", DynamicSolidMechanicsPhysics, "setup_mesh_complete");
      18             : 
      19             : registerMooseAction("SolidMechanicsApp",
      20             :                     DynamicSolidMechanicsPhysics,
      21             :                     "validate_coordinate_systems");
      22             : 
      23             : registerMooseAction("SolidMechanicsApp", DynamicSolidMechanicsPhysics, "add_variable");
      24             : 
      25             : registerMooseAction("SolidMechanicsApp", DynamicSolidMechanicsPhysics, "add_aux_variable");
      26             : 
      27             : registerMooseAction("SolidMechanicsApp", DynamicSolidMechanicsPhysics, "add_kernel");
      28             : 
      29             : registerMooseAction("SolidMechanicsApp", DynamicSolidMechanicsPhysics, "add_aux_kernel");
      30             : 
      31             : registerMooseAction("SolidMechanicsApp", DynamicSolidMechanicsPhysics, "add_material");
      32             : 
      33             : registerMooseAction("SolidMechanicsApp",
      34             :                     DynamicSolidMechanicsPhysics,
      35             :                     "add_master_action_material");
      36             : 
      37             : InputParameters
      38         300 : DynamicSolidMechanicsPhysics::validParams()
      39             : {
      40         300 :   InputParameters params = QuasiStaticSolidMechanicsPhysics::validParams();
      41         300 :   params.addClassDescription("Set up dynamic stress divergence kernels");
      42         600 :   params.addParam<bool>("static_initialization",
      43         600 :                         false,
      44             :                         "Set to true get the system to "
      45             :                         "equilibrium under gravity by running a "
      46             :                         "quasi-static analysis (by solving Ku = F) "
      47             :                         "in the first time step.");
      48             : 
      49         600 :   params.addParam<std::vector<AuxVariableName>>(
      50             :       "velocities",
      51        1500 :       std::vector<AuxVariableName>({"vel_x", "vel_y", "vel_z"}),
      52             :       "Names of the velocity variables");
      53         600 :   params.addParam<std::vector<AuxVariableName>>(
      54             :       "accelerations",
      55        1500 :       std::vector<AuxVariableName>({"accel_x", "accel_y", "accel_z"}),
      56             :       "Names of the acceleration variables");
      57         600 :   params.addParamNamesToGroup("velocities accelerations", "Variables");
      58             : 
      59         600 :   params.addParam<Real>("hht_alpha",
      60         600 :                         0,
      61             :                         "alpha parameter for mass dependent numerical damping induced "
      62             :                         "by HHT time integration scheme");
      63         600 :   params.addParam<Real>("newmark_beta", 0.25, "beta parameter for Newmark Time integration");
      64         600 :   params.addParam<Real>("newmark_gamma", 0.5, "gamma parameter for Newmark Time integration");
      65         600 :   params.addParam<MaterialPropertyName>("mass_damping_coefficient",
      66         600 :                                         0.0,
      67             :                                         "Name of material property or a constant real "
      68             :                                         "number defining mass Rayleigh parameter (eta).");
      69         600 :   params.addParam<MaterialPropertyName>("stiffness_damping_coefficient",
      70         600 :                                         0.0,
      71             :                                         "Name of material property or a constant real "
      72             :                                         "number defining stiffness Rayleigh parameter (zeta).");
      73         600 :   params.addParam<MaterialPropertyName>(
      74             :       "density", "density", "Name of Material Property that provides the density");
      75         600 :   params.addParamNamesToGroup("hht_alpha newmark_beta newmark_gamma",
      76             :                               "Time integration parameters");
      77             : 
      78         300 :   return params;
      79           0 : }
      80             : 
      81         300 : DynamicSolidMechanicsPhysics::DynamicSolidMechanicsPhysics(const InputParameters & params)
      82             :   : QuasiStaticSolidMechanicsPhysics(params),
      83         300 :     _velocities(getParam<std::vector<AuxVariableName>>("velocities")),
      84         900 :     _accelerations(getParam<std::vector<AuxVariableName>>("accelerations"))
      85             : {
      86         300 : }
      87             : 
      88             : void
      89         702 : DynamicSolidMechanicsPhysics::act()
      90             : {
      91         702 :   const std::array<std::string, 3> dir{{"x", "y", "z"}};
      92             : 
      93         702 :   if (_velocities.size() < _ndisp)
      94           0 :     paramError("velocities", "Supply one velocity variable per displacement direction");
      95         702 :   if (_accelerations.size() < _ndisp)
      96           0 :     paramError("accelerations", "Supply one acceleration variable per displacement direction");
      97             : 
      98             :   // Add aux variables for velocities and accelerations
      99         858 :   if (_current_task == "add_aux_variable" && getParam<bool>("add_variables"))
     100             :   {
     101          72 :     auto params = _factory.getValidParams("MooseVariable");
     102             :     // determine necessary order
     103          72 :     const bool second = _problem->mesh().hasSecondOrderElements();
     104             : 
     105         216 :     params.set<MooseEnum>("order") = second ? "SECOND" : "FIRST";
     106         144 :     params.set<MooseEnum>("family") = "LAGRANGE";
     107             : 
     108         252 :     for (unsigned int i = 0; i < _ndisp; ++i)
     109             :     {
     110         180 :       _problem->addAuxVariable("MooseVariable", _velocities[i], params);
     111         360 :       _problem->addAuxVariable("MooseVariable", _accelerations[i], params);
     112             :     }
     113          72 :   }
     114             : 
     115             :   // Add aux kernel for velocities and accelerations
     116         702 :   if (_current_task == "add_aux_kernel")
     117             :   {
     118             :     //
     119             :     // Note: AuxKernels that are limited to TIMESTEP_END to not get their dependencies
     120             :     // resolved automatically. Thus we _must_ construct the acceleration kernels _first_.
     121             :     // NewmarkAccelAux only uses the old velocity.
     122             :     //
     123             : 
     124             :     // acceleration aux kernels
     125         270 :     for (unsigned int i = 0; i < _ndisp; ++i)
     126             :     {
     127             :       auto kernel_type = "NewmarkAccelAux";
     128         192 :       auto params = _factory.getValidParams(kernel_type);
     129         384 :       params.set<AuxVariableName>("variable") = _accelerations[i];
     130         576 :       params.set<std::vector<VariableName>>("displacement") = {_displacements[i]};
     131         576 :       params.set<std::vector<VariableName>>("velocity") = {_velocities[i]};
     132         192 :       params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_END;
     133         384 :       params.set<Real>("beta") = getParam<Real>("newmark_beta");
     134         192 :       params.applyParameters(parameters());
     135         384 :       _problem->addAuxKernel(kernel_type, "TM_" + name() + '_' + _accelerations[i], params);
     136         192 :     }
     137             : 
     138             :     // velocity aux kernels
     139         270 :     for (unsigned int i = 0; i < _ndisp; ++i)
     140             :     {
     141             :       auto kernel_type = "NewmarkVelAux";
     142         192 :       auto params = _factory.getValidParams(kernel_type);
     143         384 :       params.set<AuxVariableName>("variable") = _velocities[i];
     144         576 :       params.set<std::vector<VariableName>>("acceleration") = {_accelerations[i]};
     145         192 :       params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_END;
     146         384 :       params.set<Real>("gamma") = getParam<Real>("newmark_gamma");
     147         192 :       params.applyParameters(parameters());
     148         384 :       _problem->addAuxKernel(kernel_type, "TM_" + name() + '_' + _velocities[i], params);
     149         192 :     }
     150             :   }
     151             : 
     152             :   // add inertia kernel
     153         702 :   if (_current_task == "add_kernel")
     154             :   {
     155         270 :     for (unsigned int i = 0; i < _ndisp; ++i)
     156             :     {
     157         192 :       auto kernel_type = _use_ad ? "ADInertialForce" : "InertialForce";
     158         192 :       auto params = _factory.getValidParams(kernel_type);
     159             : 
     160         384 :       params.set<NonlinearVariableName>("variable") = _displacements[i];
     161         576 :       params.set<std::vector<VariableName>>("velocity") = {_velocities[i]};
     162         576 :       params.set<std::vector<VariableName>>("acceleration") = {_accelerations[i]};
     163         192 :       params.set<bool>("use_displaced_mesh") = false;
     164         384 :       params.set<Real>("beta") = getParam<Real>("newmark_beta");
     165         384 :       params.set<Real>("gamma") = getParam<Real>("newmark_gamma");
     166         384 :       params.set<Real>("alpha") = getParam<Real>("hht_alpha");
     167         384 :       params.set<MaterialPropertyName>("eta") =
     168         384 :           getParam<MaterialPropertyName>("mass_damping_coefficient");
     169             : 
     170         192 :       params.applyParameters(parameters());
     171             : 
     172         576 :       _problem->addKernel(kernel_type, "TM_" + name() + "_inertia_" + dir[i], params);
     173         192 :     }
     174             :   }
     175             : 
     176             :   // call parent class method
     177         702 :   QuasiStaticSolidMechanicsPhysics::act();
     178        1470 : }
     179             : 
     180             : std::string
     181         732 : DynamicSolidMechanicsPhysics::getKernelType()
     182             : {
     183             :   // choose kernel type based on coordinate system
     184         732 :   if (_coord_system == Moose::COORD_XYZ)
     185         732 :     return "DynamicStressDivergenceTensors";
     186             :   else
     187           0 :     mooseError("Unsupported coordinate system");
     188             : }
     189             : 
     190             : InputParameters
     191         744 : DynamicSolidMechanicsPhysics::getKernelParameters(std::string type)
     192             : {
     193         744 :   InputParameters params = QuasiStaticSolidMechanicsPhysics::getKernelParameters(type);
     194             : 
     195        1488 :   if (params.isParamDefined("alpha"))
     196        1464 :     params.set<Real>("alpha") = getParam<Real>("hht_alpha");
     197        1488 :   if (params.isParamDefined("zeta"))
     198        1464 :     params.set<MaterialPropertyName>("zeta") =
     199        1464 :         getParam<MaterialPropertyName>("stiffness_damping_coefficient");
     200             : 
     201         744 :   return params;
     202           0 : }

Generated by: LCOV version 1.14