LCOV - code coverage report
Current view: top level - src/bcs - ExplicitDirichletBCBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: #32971 (54bef8) with base c6cf66 Lines: 31 33 93.9 %
Date: 2026-05-29 20:40:07 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 "ExplicitMixedOrder.h"
      11             : #include "ExplicitDirichletBCBase.h"
      12             : #include "MooseError.h"
      13             : #include "NonlinearSystemBase.h"
      14             : #include "libmesh/numeric_vector.h"
      15             : #include <iostream>
      16             : #include <ostream>
      17             : 
      18             : InputParameters
      19         112 : ExplicitDirichletBCBase::validParams()
      20             : {
      21         112 :   InputParameters params = NodalBC::validParams();
      22         112 :   return params;
      23             : }
      24             : 
      25          56 : ExplicitDirichletBCBase::ExplicitDirichletBCBase(const InputParameters & parameters)
      26             :   : NodalBC(parameters),
      27         112 :     _mass_diag(initLumpedMass()),
      28          56 :     _u_old(_var.nodalValueOld()),
      29          56 :     _u_dot_old(_var.nodalValueDotOld()),
      30          56 :     _explicit_integrator(
      31         112 :         dynamic_cast<const ExplicitMixedOrder *>(&_sys.getTimeIntegrator(_var.number())))
      32             : {
      33          56 :   if (!_explicit_integrator)
      34           0 :     mooseError("Time integrator for the variable is not of the right type.");
      35          56 : }
      36             : 
      37             : Real
      38        6572 : ExplicitDirichletBCBase::computeQpResidual()
      39             : {
      40             :   // Get dof for current var
      41        6572 :   const auto dofnum = _variable->nodalDofIndex();
      42             :   Real resid = 0;
      43             :   // Compute residual to enforce BC based on time order
      44        6572 :   switch (_var_time_order)
      45             :   {
      46        1760 :     case ExplicitMixedOrder::FIRST:
      47        1760 :       resid = (computeQpValue() - _u_old) / _dt;
      48        1760 :       resid /= -_mass_diag(dofnum);
      49        1760 :       break;
      50             : 
      51        4812 :     case ExplicitMixedOrder::SECOND:
      52        4812 :       Real avg_dt = (_dt + _dt_old) / 2;
      53        4812 :       resid = (computeQpValue() - _u_old) / (avg_dt * _dt) - (_u_dot_old) / avg_dt;
      54        4812 :       resid /= -_mass_diag(dofnum);
      55        4812 :       break;
      56             :   }
      57        6572 :   return resid;
      58             : }
      59             : 
      60             : void
      61         591 : ExplicitDirichletBCBase::timestepSetup()
      62             : {
      63             :   // Now is the point that the time integrator has the variable time orders setup
      64         591 :   _var_time_order = _explicit_integrator->findVariableTimeOrder(_var.number());
      65         591 : }
      66             : 
      67             : const NumericVector<Number> &
      68          56 : ExplicitDirichletBCBase::initLumpedMass()
      69             : {
      70          56 :   const auto & nl = _fe_problem.getNonlinearSystemBase(_sys.number());
      71         112 :   if (nl.hasVector("mass_matrix_diag_inverted"))
      72         112 :     return nl.getVector("mass_matrix_diag_inverted");
      73             : 
      74           0 :   mooseError("Lumped mass matrix is missing. Make sure ExplicitMixedOrder is being used as the "
      75             :              "time integrator.");
      76             : }

Generated by: LCOV version 1.14