LCOV - code coverage report
Current view: top level - src/timeintegrators - NewmarkBeta.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 54 60 90.0 %
Date: 2025-07-17 01:28:37 Functions: 9 9 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 "NewmarkBeta.h"
      11             : #include "NonlinearSystem.h"
      12             : #include "FEProblemBase.h"
      13             : 
      14             : registerMooseObject("MooseApp", NewmarkBeta);
      15             : 
      16             : InputParameters
      17       14517 : NewmarkBeta::validParams()
      18             : {
      19       14517 :   InputParameters params = TimeIntegrator::validParams();
      20       14517 :   params.addClassDescription(
      21             :       "Computes the first and second time derivative of variable using Newmark-Beta method.");
      22       14517 :   params.addRangeCheckedParam<Real>("beta", 0.25, "beta > 0.0", "beta value");
      23       14517 :   params.addRangeCheckedParam<Real>("gamma", 0.5, "gamma >= 0.5", "gamma value");
      24       43551 :   params.addParam<int>("inactive_tsteps",
      25       29034 :                        0,
      26             :                        "The time derivatives will set to be zero for this number of time steps.");
      27       14517 :   return params;
      28           0 : }
      29             : 
      30         168 : NewmarkBeta::NewmarkBeta(const InputParameters & parameters)
      31             :   : TimeIntegrator(parameters),
      32         168 :     _beta(getParam<Real>("beta")),
      33         168 :     _gamma(getParam<Real>("gamma")),
      34         168 :     _inactive_tsteps(getParam<int>("inactive_tsteps")),
      35         336 :     _du_dotdot_du(_sys.duDotDotDu())
      36             : {
      37         168 :   _fe_problem.setUDotOldRequested(true);
      38         168 :   _fe_problem.setUDotDotRequested(true);
      39         168 :   _fe_problem.setUDotDotOldRequested(true);
      40             : 
      41         168 :   if (_gamma > 2.0 * _beta)
      42           0 :     mooseError("NewmarkBeta: For Newmark method to be unconditionally stable, gamma should lie "
      43             :                "between 0.5 and 2.0*beta.");
      44             : 
      45         168 :   if (_gamma != 0.5)
      46          24 :     mooseWarning("NewmarkBeta: For gamma > 0.5, Newmark method is only first order accurate. "
      47             :                  "Please use either HHT time integration method or set gamma = 0.5 for second "
      48             :                  "order solution accuracy with time.");
      49         168 : }
      50             : 
      51         336 : NewmarkBeta::~NewmarkBeta() {}
      52             : 
      53             : void
      54        3058 : NewmarkBeta::computeTimeDerivatives()
      55             : {
      56        3058 :   if (!_sys.solutionUDot())
      57           0 :     mooseError("NewmarkBeta: Time derivative of solution (`u_dot`) is not stored. Please set "
      58             :                "uDotRequested() to true in FEProblemBase befor requesting `u_dot`.");
      59             : 
      60        3058 :   if (!_sys.solutionUDotDot())
      61           0 :     mooseError("NewmarkBeta: Second time derivative of solution (`u_dotdot`) is not stored. Please "
      62             :                "set uDotDotRequested() to true in FEProblemBase befor requesting `u_dotdot`.");
      63             : 
      64        3058 :   if (!_sys.solutionUDotOld())
      65           0 :     mooseError("NewmarkBeta: Old time derivative of solution (`u_dot_old`) is not stored. Please "
      66             :                "set uDotOldRequested() to true in FEProblemBase befor requesting `u_dot_old`.");
      67             : 
      68        3058 :   if (!_sys.solutionUDotDotOld())
      69           0 :     mooseError("NewmarkBeta: Old second time derivative of solution (`u_dotdot_old`) is not "
      70             :                "stored. Please set uDotDotOldRequested() to true in FEProblemBase befor requesting "
      71             :                "`u_dotdot_old`.");
      72             : 
      73        3058 :   NumericVector<Number> & u_dot = *_sys.solutionUDot();
      74        3058 :   NumericVector<Number> & u_dotdot = *_sys.solutionUDotDot();
      75        3058 :   NumericVector<Number> & u_dot_old = *_sys.solutionUDotOld();
      76        3058 :   NumericVector<Number> & u_dotdot_old = *_sys.solutionUDotDotOld();
      77             : 
      78        3058 :   if (_fe_problem.timeStep() <= _inactive_tsteps)
      79             :   {
      80          11 :     u_dot.zero();
      81          11 :     u_dotdot.zero();
      82             :   }
      83             :   else
      84             :   {
      85        3047 :     u_dotdot = *_solution;
      86        3047 :     computeTimeDerivativeHelper(u_dot, _solution_old, u_dot_old, u_dotdot, u_dotdot_old);
      87             :   }
      88             : 
      89             :   // make sure _u_dotdot and _u_dot are in good state
      90        3058 :   u_dotdot.close();
      91        3058 :   u_dot.close();
      92             : 
      93             :   // used for Jacobian calculations
      94        3058 :   _du_dotdot_du = 1.0 / _beta / _dt / _dt;
      95        3058 :   computeDuDotDu();
      96        3058 : }
      97             : 
      98             : void
      99      581540 : NewmarkBeta::computeADTimeDerivatives(ADReal & ad_u_dot,
     100             :                                       const dof_id_type & dof,
     101             :                                       ADReal & ad_u_dotdot) const
     102             : {
     103      581540 :   const auto & u_old = _solution_old(dof);
     104      581540 :   const auto & u_dot_old = (*_sys.solutionUDotOld())(dof);
     105      581540 :   const auto & u_dotdot_old = (*_sys.solutionUDotDotOld())(dof);
     106             : 
     107             :   // Seeds ad_u_dotdot with _ad_dof_values and associated derivatives provided via ad_u_dot from
     108             :   // MooseVariableData
     109      581540 :   ad_u_dotdot = ad_u_dot;
     110             : 
     111      581540 :   computeTimeDerivativeHelper(ad_u_dot, u_old, u_dot_old, ad_u_dotdot, u_dotdot_old);
     112      581540 : }
     113             : 
     114             : void
     115        2640 : NewmarkBeta::postResidual(NumericVector<Number> & residual)
     116             : {
     117        2640 :   residual += *_Re_time;
     118        2640 :   residual += *_Re_non_time;
     119        2640 :   residual.close();
     120        2640 : }
     121             : 
     122             : Real
     123        3058 : NewmarkBeta::duDotDuCoeff() const
     124             : {
     125        3058 :   return _gamma / _beta;
     126             : }

Generated by: LCOV version 1.14