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 "FunctorElementalGradientAux.h" 11 : #include "metaphysicl/raw_type.h" 12 : 13 : registerMooseObject("MooseApp", FunctorElementalGradientAux); 14 : registerMooseObject("MooseApp", ADFunctorElementalGradientAux); 15 : 16 : template <bool is_ad> 17 : InputParameters 18 28675 : FunctorElementalGradientAuxTempl<is_ad>::validParams() 19 : { 20 28675 : InputParameters params = VectorAuxKernel::validParams(); 21 28675 : params.addClassDescription( 22 : "Evaluates the gradient of a functor (variable, function or functor material property) on " 23 : "the current element or quadrature point."); 24 28675 : params.addRequiredParam<MooseFunctorName>("functor", "The functor to evaluate"); 25 28675 : params.addParam<MooseFunctorName>("factor", 1, "A factor to apply on the functor"); 26 86025 : params.addParam<MaterialPropertyName>( 27 57350 : "factor_matprop", 1, "A (regular) material property factor to apply on the functor"); 28 : 29 : // We need some ghosting for the Finite Volume Fields (we use neighbor information to compute 30 : // gradient) 31 28675 : params.addParam<unsigned short>("ghost_layers", 1, "The number of layers of elements to ghost."); 32 28675 : params.addRelationshipManager( 33 : "ElementSideNeighborLayers", 34 : Moose::RelationshipManagerType::GEOMETRIC | Moose::RelationshipManagerType::ALGEBRAIC, 35 420 : [](const InputParameters & obj_params, InputParameters & rm_params) 36 : { 37 210 : rm_params.set<unsigned short>("layers") = obj_params.get<unsigned short>("ghost_layers"); 38 210 : rm_params.set<bool>("use_displaced_mesh") = obj_params.get<bool>("use_displaced_mesh"); 39 : }); 40 28675 : return params; 41 0 : } 42 : 43 : template <bool is_ad> 44 75 : FunctorElementalGradientAuxTempl<is_ad>::FunctorElementalGradientAuxTempl( 45 : const InputParameters & parameters) 46 : : VectorAuxKernel(parameters), 47 75 : _functor(getFunctor<GenericReal<is_ad>>("functor")), 48 75 : _factor(getFunctor<GenericReal<is_ad>>("factor")), 49 75 : _factor_matprop(getGenericMaterialProperty<Real, is_ad>("factor_matprop")), 50 150 : _use_qp_arg(dynamic_cast<MooseVariableFE<RealVectorValue> *>(&_var)) 51 : { 52 75 : if (!_use_qp_arg && !dynamic_cast<MooseVariableFV<Real> *>(&_var)) 53 0 : paramError( 54 : "variable", 55 : "The variable must be a non-vector, non-array finite-volume/finite-element variable."); 56 : 57 75 : if (isNodal()) 58 0 : paramError("variable", "This AuxKernel only supports Elemental fields"); 59 75 : } 60 : 61 : template <bool is_ad> 62 : RealVectorValue 63 27270 : FunctorElementalGradientAuxTempl<is_ad>::computeValue() 64 : { 65 : using MetaPhysicL::raw_value; 66 27270 : const auto state = determineState(); 67 27270 : if (_use_qp_arg) 68 : { 69 27270 : const Moose::ElemQpArg qp_arg = {_current_elem, _qp, _qrule, _q_point[_qp]}; 70 46470 : return raw_value(_factor(qp_arg, state)) * raw_value(_factor_matprop[_qp]) * 71 73740 : raw_value(_functor.gradient(qp_arg, state)); 72 : } 73 : else 74 : { 75 0 : const auto elem_arg = makeElemArg(_current_elem); 76 : mooseAssert(_qp == 0, "Only one Qp per element expected when using an elemental argument"); 77 0 : return raw_value(_factor(elem_arg, state)) * raw_value(_factor_matprop[_qp]) * 78 0 : raw_value(_functor.gradient(elem_arg, state)); 79 : } 80 : }