LCOV - code coverage report
Current view: top level - src/postprocessors - CriticalTimeStep.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 34 38 89.5 %
Date: 2025-07-25 05:00:39 Functions: 7 8 87.5 %
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 "CriticalTimeStep.h"
      11             : 
      12             : registerMooseObject("SolidMechanicsApp", CriticalTimeStep);
      13             : 
      14             : InputParameters
      15          52 : CriticalTimeStep::validParams()
      16             : {
      17          52 :   InputParameters params = ElementPostprocessor::validParams();
      18          52 :   params.addClassDescription(
      19             :       "Computes and reports the critical time step for the explicit solver.");
      20         104 :   params.addParam<MaterialPropertyName>(
      21             :       "density",
      22             :       "Name of Material Property  or a constant real number defining the density of the material.");
      23         104 :   params.addParam<MaterialPropertyName>(
      24             :       "density_scaling", "Name of material property to add mass scaling in explicit simulations.");
      25         104 :   params.addParam<Real>("factor", 1.0, "Factor to mulitply to the critical time step.");
      26          52 :   return params;
      27           0 : }
      28             : 
      29          26 : CriticalTimeStep::CriticalTimeStep(const InputParameters & parameters)
      30             :   : ElementPostprocessor(parameters),
      31             :     GuaranteeConsumer(this),
      32          26 :     _material_density(getMaterialPropertyByName<Real>("density")),
      33          52 :     _density_scaling(parameters.isParamSetByUser("density_scaling")
      34          38 :                          ? &getMaterialPropertyByName<Real>("density_scaling")
      35             :                          : nullptr),
      36          26 :     _effective_stiffness(getMaterialPropertyByName<Real>("effective_stiffness")),
      37          52 :     _factor(getParam<Real>("factor")),
      38          52 :     _critical_time(parameters.isParamValid("critical_time"))
      39             : {
      40          26 : }
      41             : 
      42             : void
      43          26 : CriticalTimeStep::initialSetup()
      44             : {
      45          52 :   if (!hasGuaranteedMaterialProperty("effective_stiffness", Guarantee::ISOTROPIC))
      46           2 :     paramError("CriticalTimeStep can only be used with elasticity tensor materials "
      47             :                "that guarantee isotropic tensors.");
      48          24 : }
      49             : 
      50             : void
      51          36 : CriticalTimeStep::initialize()
      52             : {
      53          36 :   _critical_time = std::numeric_limits<Real>::max();
      54          36 : }
      55             : 
      56             : void
      57        6264 : CriticalTimeStep::execute()
      58             : {
      59        6264 :   const Real dens = _material_density[0];
      60        6264 :   const Real dens_scaling = _density_scaling ? (*_density_scaling)[0] : 0.0;
      61             : 
      62             :   // In the above line, density is inferred only at the first quadrature point
      63             :   // of each element. Since critical time step is computed across all elements and
      64             :   // a minimum is then taken, this is okay.
      65       18792 :   _critical_time = std::min(_factor * _current_elem->hmin() * std::sqrt(dens + dens_scaling) /
      66        6264 :                                 (_effective_stiffness[0]),
      67        6264 :                             _critical_time);
      68        6264 : }
      69             : 
      70             : void
      71          36 : CriticalTimeStep::finalize()
      72             : {
      73          36 :   gatherMin(_critical_time);
      74          36 : }
      75             : 
      76             : Real
      77          36 : CriticalTimeStep::getValue() const
      78             : {
      79          36 :   return _critical_time;
      80             : }
      81             : 
      82             : void
      83           0 : CriticalTimeStep::threadJoin(const UserObject & y)
      84             : {
      85             :   const auto & pps = static_cast<const CriticalTimeStep &>(y);
      86           0 :   _critical_time = std::min(pps._critical_time, _critical_time);
      87           0 : }

Generated by: LCOV version 1.14