LCOV - code coverage report
Current view: top level - src/timeintegrators - CentralDifference.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 51 54 94.4 %
Date: 2025-07-17 01:28:37 Functions: 7 7 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             : // MOOSE includes
      11             : #include "CentralDifference.h"
      12             : #include "NonlinearSystem.h"
      13             : #include "FEProblem.h"
      14             : 
      15             : // libMesh includes
      16             : #include "libmesh/nonlinear_solver.h"
      17             : 
      18             : using namespace libMesh;
      19             : 
      20             : registerMooseObject("MooseApp", CentralDifference);
      21             : 
      22             : InputParameters
      23       14469 : CentralDifference::validParams()
      24             : {
      25       14469 :   InputParameters params = ActuallyExplicitEuler::validParams();
      26             : 
      27       14469 :   params.addClassDescription("Implementation of explicit, Central Difference integration without "
      28             :                              "invoking any of the nonlinear solver");
      29             : 
      30       14469 :   return params;
      31           0 : }
      32             : 
      33         136 : CentralDifference::CentralDifference(const InputParameters & parameters)
      34             :   : ActuallyExplicitEuler(parameters),
      35         272 :     _du_dotdot_du(_sys.duDotDotDu()),
      36         136 :     _solution_older(_sys.solutionState(2))
      37             : {
      38         136 :   if (_solve_type == LUMPED)
      39          24 :     _is_lumped = true;
      40             : 
      41         136 :   _fe_problem.setUDotOldRequested(true);
      42         136 :   _fe_problem.setUDotDotRequested(true);
      43         136 :   _fe_problem.setUDotDotOldRequested(true);
      44         136 : }
      45             : 
      46             : void
      47        1442 : CentralDifference::computeADTimeDerivatives(ADReal & ad_u_dot,
      48             :                                             const dof_id_type & dof,
      49             :                                             ADReal & ad_u_dotdot) const
      50             : {
      51             :   // Seeds ad_u_dotdot with _ad_dof_values and associated derivatives provided via ad_u_dot from
      52             :   // MooseVariableData
      53        1442 :   ad_u_dotdot = ad_u_dot;
      54             : 
      55        1442 :   computeTimeDerivativeHelper(ad_u_dot, ad_u_dotdot, _solution_old(dof), _solution_older(dof));
      56        1442 : }
      57             : 
      58             : void
      59          60 : CentralDifference::initialSetup()
      60             : {
      61          60 :   ActuallyExplicitEuler::initialSetup();
      62             : 
      63             :   // _nl here so that we don't create this vector in the aux system time integrator
      64          60 :   _nl->disassociateVectorFromTag(*_nl->solutionUDot(), _u_dot_factor_tag);
      65          60 :   _nl->addVector(_u_dot_factor_tag, true, GHOSTED);
      66          60 :   _nl->disassociateVectorFromTag(*_nl->solutionUDotDot(), _u_dotdot_factor_tag);
      67          60 :   _nl->addVector(_u_dotdot_factor_tag, true, GHOSTED);
      68          60 : }
      69             : 
      70             : void
      71       22693 : CentralDifference::computeTimeDerivatives()
      72             : {
      73       22693 :   if (!_sys.solutionUDot())
      74           0 :     mooseError("CentralDifference: Time derivative of solution (`u_dot`) is not stored. Please "
      75             :                "set uDotRequested() to true in FEProblemBase before requesting `u_dot`.");
      76             : 
      77       22693 :   if (!_sys.solutionUDotDot())
      78           0 :     mooseError("CentralDifference: Time derivative of solution (`u_dotdot`) is not stored. Please "
      79             :                "set uDotDotRequested() to true in FEProblemBase before requesting `u_dot`.");
      80             : 
      81             :   // Declaring u_dot and u_dotdot
      82       22693 :   auto & u_dot = *_sys.solutionUDot();
      83       22693 :   auto & u_dotdot = *_sys.solutionUDotDot();
      84             : 
      85       22693 :   u_dot = *_solution;
      86       22693 :   u_dotdot = *_solution;
      87             : 
      88             :   // Computing derivatives
      89       22693 :   computeTimeDerivativeHelper(u_dot, u_dotdot, _solution_old, _solution_older);
      90             : 
      91             :   // make sure _u_dotdot and _u_dot are in good state
      92       22693 :   u_dotdot.close();
      93       22693 :   u_dot.close();
      94             : 
      95             :   // used for Jacobian calculations
      96       22693 :   computeDuDotDu();
      97       22693 :   _du_dotdot_du = 1.0 / (_dt * _dt);
      98             : 
      99             :   // Computing udotdot "factor"
     100             :   // u_dotdot_factor = u_dotdot - (u - u_old)/dt^2 = (u - 2* u_old + u_older - u + u_old) / dt^2
     101             :   // u_dotdot_factor = (u_older - u_old)/dt^2
     102       22693 :   if (_sys.hasVector(_u_dotdot_factor_tag)) // so that we don't do this in the aux system
     103             :   {
     104        4796 :     auto & u_dotdot_factor = _sys.getVector(_u_dotdot_factor_tag);
     105        4796 :     u_dotdot_factor = _sys.solutionOlder();
     106        4796 :     u_dotdot_factor -= _sys.solutionOld();
     107        4796 :     u_dotdot_factor *= 1.0 / (_dt * _dt);
     108        4796 :     u_dotdot_factor.close();
     109             :   }
     110             : 
     111             :   // Computing udot "factor"
     112             :   // u_dot_factor = u_dot - (u - u_old)/2/dt = (u - u_older)/ 2/ dt - (u - u_old)/2/dt
     113             :   // u_dot_factor = (u_old - u_older)/2/dt
     114       22693 :   if (_sys.hasVector(_u_dot_factor_tag)) // so that we don't do this in the aux system
     115             :   {
     116        4796 :     auto & u_dot_factor = _sys.getVector(_u_dot_factor_tag);
     117        4796 :     u_dot_factor = _sys.solutionOld();
     118        4796 :     u_dot_factor -= _sys.solutionOlder();
     119        4796 :     u_dot_factor *= 1.0 / (2.0 * _dt);
     120        4796 :     u_dot_factor.close();
     121             :   }
     122       22693 : }
     123             : 
     124             : Real
     125       22693 : CentralDifference::duDotDuCoeff() const
     126             : {
     127       22693 :   return Real(1) / Real(2);
     128             : }

Generated by: LCOV version 1.14