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 104 : ExplicitDirichletBCBase::validParams() 20 : { 21 104 : InputParameters params = NodalBC::validParams(); 22 104 : return params; 23 : } 24 : 25 52 : ExplicitDirichletBCBase::ExplicitDirichletBCBase(const InputParameters & parameters) 26 : : NodalBC(parameters), 27 104 : _mass_diag(initLumpedMass()), 28 52 : _u_old(_var.nodalValueOld()), 29 52 : _u_dot_old(_var.nodalValueDotOld()), 30 52 : _explicit_integrator( 31 104 : dynamic_cast<const ExplicitMixedOrder *>(&_sys.getTimeIntegrator(_var.number()))) 32 : { 33 52 : if (!_explicit_integrator) 34 0 : mooseError("Time integrator for the variable is not of the right type."); 35 52 : } 36 : 37 : Real 38 4072 : ExplicitDirichletBCBase::computeQpResidual() 39 : { 40 : // Get dof for current var 41 4072 : const auto dofnum = _variable->nodalDofIndex(); 42 : Real resid = 0; 43 : // Compute residual to enforce BC based on time order 44 4072 : switch (_var_time_order) 45 : { 46 3520 : case ExplicitMixedOrder::FIRST: 47 3520 : resid = (computeQpValue() - _u_old) / _dt; 48 3520 : resid /= -_mass_diag(dofnum); 49 3520 : break; 50 : 51 552 : case ExplicitMixedOrder::SECOND: 52 552 : Real avg_dt = (_dt + _dt_old) / 2; 53 552 : resid = (computeQpValue() - _u_old) / (avg_dt * _dt) - (_u_dot_old) / avg_dt; 54 552 : resid /= -_mass_diag(dofnum); 55 552 : break; 56 : } 57 4072 : return resid; 58 : } 59 : 60 : void 61 372 : ExplicitDirichletBCBase::timestepSetup() 62 : { 63 : // Now is the point that the time integrator has the variable time orders setup 64 372 : _var_time_order = _explicit_integrator->findVariableTimeOrder(_var.number()); 65 372 : } 66 : 67 : const NumericVector<Number> & 68 52 : ExplicitDirichletBCBase::initLumpedMass() 69 : { 70 52 : const auto & nl = _fe_problem.getNonlinearSystemBase(_sys.number()); 71 104 : if (nl.hasVector("mass_matrix_diag_inverted")) 72 104 : 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 : }