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 "DiffusionFluxFVAux.h" 11 : #include "Assembly.h" 12 : 13 : registerMooseObject("SubChannelApp", DiffusionFluxFVAux); 14 : 15 : InputParameters 16 0 : DiffusionFluxFVAux::validParams() 17 : { 18 0 : InputParameters params = AuxKernel::validParams(); 19 0 : MooseEnum component("x y z normal"); 20 0 : params.addClassDescription("Compute components of flux vector for diffusion problems " 21 : "$(\\vec{J} = -D \\nabla C)$."); 22 0 : params.addRequiredParam<MooseEnum>("component", component, "The desired component of flux."); 23 0 : params.addRequiredCoupledVar("diffusion_variable", "The name of the variable"); 24 0 : params.addRequiredParam<MaterialPropertyName>( 25 : "diffusivity", 26 : "The name of the diffusivity material property that will be used in the flux computation."); 27 0 : return params; 28 0 : } 29 : 30 0 : DiffusionFluxFVAux::DiffusionFluxFVAux(const InputParameters & parameters) 31 : : AuxKernel(parameters), 32 0 : _use_normal(getParam<MooseEnum>("component") == "normal"), 33 0 : _component(getParam<MooseEnum>("component")), 34 0 : _diffusion_var(dynamic_cast<const MooseVariableFVReal *>(getFieldVar("diffusion_variable", 0))), 35 0 : _diffusion_coef(hasMaterialProperty<Real>("diffusivity") 36 0 : ? &getMaterialProperty<Real>("diffusivity") 37 : : nullptr), 38 0 : _ad_diffusion_coef(!_diffusion_coef ? &getADMaterialProperty<Real>("diffusivity") : nullptr), 39 0 : _normals(_assembly.normals()) 40 : { 41 0 : if (_use_normal && !isParamValid("boundary")) 42 0 : paramError("boundary", "A boundary must be provided if using the normal component!"); 43 0 : } 44 : 45 : Real 46 0 : DiffusionFluxFVAux::computeValue() 47 : { 48 0 : const auto _vec_grad = raw_value(_diffusion_var->adGradSln(_current_elem, determineState())); 49 0 : const Real gradient = _use_normal ? _vec_grad * _normals[_qp] : _vec_grad(_component); 50 0 : const Real diffusion_coef = _diffusion_coef ? (*_diffusion_coef)[_qp] 51 0 : : MetaPhysicL::raw_value((*_ad_diffusion_coef)[_qp]); 52 0 : return -diffusion_coef * gradient; 53 : }