LCOV - code coverage report
Current view: top level - src/actions - SeismicForceAction.C (source / functions) Hit Total Coverage
Test: idaholab/mastodon: 55510a Lines: 51 53 96.2 %
Date: 2025-08-26 23:09:31 Functions: 3 3 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             : // MOOSE includes
      16             : #include "FEProblemBase.h"
      17             : #include "Factory.h"
      18             : #include "MooseMesh.h"
      19             : 
      20             : // Mastodon includes
      21             : #include "SeismicForceAction.h"
      22             : 
      23             : registerMooseAction("MastodonApp", SeismicForceAction, "add_bc");
      24             : 
      25             : InputParameters
      26           8 : SeismicForceAction::validParams()
      27             : {
      28           8 :   InputParameters params = Action::validParams();
      29           8 :   params.addClassDescription("This action sets up Seismic forces boundary conditions.");
      30             : 
      31          16 :   params.addRequiredParam<std::vector<VariableName>>("displacements",
      32             :                                                      "The displacement variables for the problem.");
      33          16 :   params.addRequiredParam<std::vector<BoundaryName>>(
      34             :       "boundary",
      35             :       "The list of boundary IDs from the mesh where this boundary "
      36             :       "condition will be applied.");
      37          16 :   params.addRequiredParam<std::vector<unsigned int>>(
      38             :       "input_components", "The directions in which the input ground motions are applied.");
      39          16 :   params.addParam<std::vector<VariableName>>(
      40             :       "velocities",
      41             :       "The vector of velocity variables names. The input "
      42             :       "velocities can be obtained from this variable. The size "
      43             :       "of this vector must be same size as input_component.");
      44          16 :   params.addParam<std::vector<FunctionName>>("velocity_functions",
      45             :                                              "The vector of function names that describes the "
      46             :                                              "input ground motions. Must be same size as "
      47             :                                              "input_component.");
      48          16 :   params.addParam<Real>(
      49          16 :       "alpha", 0.0, "The alpha parameter required for HHT time integration scheme.");
      50          16 :   params.addRequiredRangeCheckedParam<Real>(
      51             :       "density", "density>0.0", "Density of the underlying bedrock.");
      52          16 :   params.addRequiredRangeCheckedParam<Real>(
      53             :       "p_wave_speed", "p_wave_speed>0.0", "P-wave speed of the underlying bedrock.");
      54          16 :   params.addRequiredRangeCheckedParam<Real>(
      55             :       "shear_wave_speed", "shear_wave_speed>0.0", "shear wave speed of the underlying bedrock.");
      56           8 :   return params;
      57           0 : }
      58             : 
      59           8 : SeismicForceAction::SeismicForceAction(const InputParameters & params)
      60             :   : Action(params),
      61           8 :     _boundary(getParam<std::vector<BoundaryName>>("boundary")),
      62          16 :     _displacements(getParam<std::vector<VariableName>>("displacements")),
      63          16 :     _input_components(getParam<std::vector<unsigned int>>("input_components")),
      64          20 :     _velocity_ptrs(isParamValid("velocities") ? &getParam<std::vector<VariableName>>("velocities")
      65             :                                               : NULL),
      66           8 :     _velocity_function_ptrs(isParamValid("velocity_functions")
      67          18 :                                 ? &getParam<std::vector<FunctionName>>("velocity_functions")
      68           8 :                                 : NULL)
      69             : {
      70           8 :   if (!_velocity_ptrs && !_velocity_function_ptrs)
      71           1 :     mooseError("A list of functions ('velocity_functions') or variables "
      72             :                "('velocities') describing the input velocity must be supplied "
      73             :                "in the \"",
      74             :                name(),
      75             :                "\" block.");
      76             : 
      77           7 :   if (_velocity_ptrs && (_input_components.size() != _velocity_ptrs->size()))
      78           1 :     mooseError("The number of components listed in 'input_components' must "
      79             :                "equal the number of variables in 'velocities' in the \"",
      80             :                name(),
      81             :                "\" block.");
      82             : 
      83           6 :   if (_velocity_function_ptrs && (_input_components.size() != _velocity_function_ptrs->size()))
      84           1 :     mooseError("The number of components listed in 'input_components' must "
      85             :                "equal the number of functions in 'velocity_functions' in the "
      86             :                "\"",
      87             :                name(),
      88             :                "\" block.");
      89           5 : }
      90             : 
      91             : void
      92           5 : SeismicForceAction::act()
      93             : {
      94             :   // Cannot be done in constructor because _mesh is not defineds
      95           5 :   if (_displacements.size() != _mesh->dimension())
      96           1 :     mooseError("The number of supplied 'displacements' must equal the mesh "
      97             :                "dimension in the \"",
      98             :                name(),
      99             :                "\" block.");
     100             : 
     101             :   // Define parameters object for object to be created
     102           4 :   InputParameters params = _factory.getValidParams("SeismicForce");
     103           4 :   params.set<std::vector<BoundaryName>>("boundary") = _boundary;
     104           8 :   params.set<Real>("alpha") = getParam<Real>("alpha");
     105           8 :   params.set<Real>("density") = getParam<Real>("density");
     106           8 :   params.set<Real>("p_wave_speed") = getParam<Real>("p_wave_speed");
     107           8 :   params.set<Real>("shear_wave_speed") = getParam<Real>("shear_wave_speed");
     108             : 
     109             :   // Loop through each component and create SeismicForce object
     110           4 :   std::string prefix = "mastodon_seismic_force";
     111          10 :   for (unsigned int j = 0; j < _input_components.size(); ++j)
     112             :   {
     113           6 :     params.set<unsigned int>("vel_component") = _input_components[j];
     114           6 :     if (_velocity_function_ptrs)
     115          12 :       params.set<FunctionName>("velocity_function") = (*_velocity_function_ptrs)[j];
     116             :     else
     117           0 :       params.set<std::vector<VariableName>>("velocity") = {(*_velocity_ptrs)[j]};
     118             : 
     119          24 :     for (unsigned int i = 0; i < _displacements.size(); ++i)
     120             :     {
     121          18 :       std::stringstream obj_name;
     122          54 :       obj_name << prefix << "_" << name() << "_" << i << "_" << _input_components[j];
     123          18 :       params.set<unsigned int>("component") = i;
     124          36 :       params.set<NonlinearVariableName>("variable") = _displacements[i];
     125             : 
     126          36 :       _problem->addBoundaryCondition("SeismicForce", obj_name.str(), params);
     127          18 :     }
     128             :   }
     129           4 : }

Generated by: LCOV version 1.14