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 "FunctorKernel.h" 11 : 12 : registerMooseObject("MooseApp", FunctorKernel); 13 : 14 : InputParameters 15 14724 : FunctorKernel::validParams() 16 : { 17 14724 : InputParameters params = ADKernelValue::validParams(); 18 : 19 29448 : params.addClassDescription("Adds a term from a functor."); 20 : 21 58896 : params.addRequiredParam<MooseFunctorName>("functor", "Functor to add"); 22 58896 : params.addRequiredParam<bool>( 23 : "functor_on_rhs", 24 : "If true, the functor to add is on the right hand side of the equation. By convention, all " 25 : "terms are moved to the left hand side, so if true, a factor of -1 is applied."); 26 : 27 58896 : MooseEnum modes("add=0 target=1", "add"); 28 44172 : params.addParam<MooseEnum>("mode", 29 : modes, 30 : "The operation mode, 'add' just returns the value of the functor and " 31 : "therefore adds the functor value to the residual" 32 : "'target' sets the residual term in such a way that the residual of " 33 : "the variable u vanishes if its value matches the given functor. " 34 : "Please note: In mode 'target' this kernel only imposes the equality " 35 : "between the variable and the functor when it is the only kernel in " 36 : "that variable's equation on the specified subdomains."); 37 : 38 29448 : return params; 39 14724 : } 40 : 41 240 : FunctorKernel::FunctorKernel(const InputParameters & parameters) 42 : : ADKernelValue(parameters), 43 240 : _mode((Mode)(int)parameters.get<MooseEnum>("mode")), 44 480 : _functor(getFunctor<ADReal>("functor")), 45 720 : _sign(getParam<bool>("functor_on_rhs") ? -1.0 : 1.0) 46 : { 47 240 : } 48 : 49 : ADReal 50 264954 : FunctorKernel::precomputeQpResidual() 51 : { 52 264954 : const Moose::ElemQpArg space_arg = {_current_elem, _qp, _qrule, _q_point[_qp]}; 53 264954 : const auto functor_value = _functor(space_arg, Moose::currentState()); 54 : 55 264954 : switch (_mode) 56 : { 57 125754 : case Mode::ADD: 58 125754 : return _sign * functor_value; 59 : 60 139200 : case Mode::TARGET: 61 139200 : return _sign * (functor_value - _u[_qp]); 62 : 63 0 : default: 64 0 : mooseError("FunctorKernel: Invalid mode"); 65 : } 66 264954 : }