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 "MatchedValueBC.h" 11 : 12 : registerMooseObject("MooseApp", MatchedValueBC); 13 : registerMooseObject("MooseApp", ADMatchedValueBC); 14 : 15 : template <bool is_ad> 16 : InputParameters 17 28974 : MatchedValueBCTempl<is_ad>::validParams() 18 : { 19 28974 : InputParameters params = GenericNodalBC<is_ad>::validParams(); 20 28974 : params.addRequiredCoupledVar("v", "The variable whose value we are to match."); 21 28974 : params.addParam<Real>("u_coeff", 1.0, " A coefficient for primary variable u"); 22 28974 : params.addParam<Real>("v_coeff", 1.0, " A coefficient for coupled variable v"); 23 28974 : params.addClassDescription("Implements a NodalBC which equates two different Variables' values " 24 : "on a specified boundary."); 25 28974 : return params; 26 0 : } 27 : 28 : template <bool is_ad> 29 222 : MatchedValueBCTempl<is_ad>::MatchedValueBCTempl(const InputParameters & parameters) 30 : : GenericNodalBC<is_ad>(parameters), 31 222 : _v(this->template coupledGenericValue<is_ad>("v")), 32 222 : _v_num(coupled("v")), 33 222 : _u_coeff(this->template getParam<Real>("u_coeff")), 34 444 : _v_coeff(this->template getParam<Real>("v_coeff")) 35 : { 36 222 : } 37 : 38 : template <> 39 : GenericReal<true> 40 10155 : MatchedValueBCTempl<true>::computeQpResidual() 41 : { 42 20310 : return _u_coeff * _u - _v_coeff * _v[_qp]; 43 : } 44 : 45 : template <> 46 : GenericReal<false> 47 3666 : MatchedValueBCTempl<false>::computeQpResidual() 48 : { 49 3666 : return _u_coeff * _u[_qp] - _v_coeff * _v[_qp]; 50 : } 51 : 52 : template <bool is_ad> 53 : Real 54 1358 : MatchedValueBCTempl<is_ad>::computeQpOffDiagJacobian(unsigned int jvar) 55 : { 56 : // For the AD version, we do not need this implementation since AD will 57 : // automatically compute derivatives. In other words, this function will 58 : // never be called for the AD version. But we can not eliminate this function 59 : // for the AD because C++ does not support an optional function declaration based 60 : // on a template parameter. 61 1358 : if (jvar == _v_num) 62 1358 : return -_v_coeff; 63 : else 64 0 : return 0.; 65 : } 66 : 67 : template class MatchedValueBCTempl<false>; 68 : template class MatchedValueBCTempl<true>;