LCOV - code coverage report
Current view: top level - src/auxkernels - DiffusionFluxAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 26 31 83.9 %
Date: 2026-05-29 20:35:17 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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 "DiffusionFluxAux.h"
      11             : #include "Assembly.h"
      12             : 
      13             : registerMooseObject("MooseApp", DiffusionFluxAux);
      14             : 
      15             : InputParameters
      16        3436 : DiffusionFluxAux::validParams()
      17             : {
      18        3436 :   InputParameters params = AuxKernel::validParams();
      19       13744 :   MooseEnum component("x y z normal");
      20        6872 :   params.addClassDescription("Compute components of flux vector for diffusion problems "
      21             :                              "$(\\vec{J} = -D \\nabla C)$.");
      22       13744 :   params.addRequiredParam<MooseEnum>("component", component, "The desired component of flux.");
      23       13744 :   params.addRequiredCoupledVar("diffusion_variable", "The name of the variable");
      24       10308 :   params.addRequiredParam<MaterialPropertyName>(
      25             :       "diffusivity",
      26             :       "The name of the diffusivity material property that will be used in the flux computation.");
      27        6872 :   return params;
      28        3436 : }
      29             : 
      30         195 : DiffusionFluxAux::DiffusionFluxAux(const InputParameters & parameters)
      31             :   : AuxKernel(parameters),
      32         195 :     _use_normal(getParam<MooseEnum>("component") == "normal"),
      33         390 :     _component(getParam<MooseEnum>("component")),
      34         390 :     _grad_u(coupledGradient("diffusion_variable")),
      35         390 :     _diffusion_coef(hasMaterialProperty<Real>("diffusivity")
      36         481 :                         ? &getMaterialProperty<Real>("diffusivity")
      37             :                         : nullptr),
      38         247 :     _ad_diffusion_coef(!_diffusion_coef ? &getADMaterialProperty<Real>("diffusivity") : nullptr),
      39         195 :     _normals(_assembly.normals()),
      40         390 :     _fv_var(dynamic_cast<const MooseVariableFVReal *>(&_var))
      41             : {
      42         221 :   if (_use_normal && !isParamValid("boundary"))
      43           0 :     paramError("boundary", "A boundary must be provided if using the normal component!");
      44         195 : }
      45             : 
      46             : Real
      47     1390336 : DiffusionFluxAux::computeValue()
      48             : {
      49             :   Real gradient;
      50             :   // FE relies on coupleable
      51     1390336 :   if (!_fv_var)
      52     1390336 :     gradient = _use_normal ? _grad_u[_qp] * _normals[_qp] : _grad_u[_qp](_component);
      53             :   else
      54             :   {
      55             :     // Use the boundary gradient when kernel is boundary restricted
      56             :     const auto _vec_grad =
      57           0 :         _bnd ? raw_value(_fv_var->adGradSln(*_mesh.faceInfo(_current_elem, _current_side),
      58           0 :                                             determineState()))
      59           0 :              : raw_value(_fv_var->adGradSln(_current_elem, determineState()));
      60           0 :     gradient = _use_normal ? _vec_grad * _normals[_qp] : _vec_grad(_component);
      61             :   }
      62     1390336 :   const Real diffusion_coef = _diffusion_coef ? (*_diffusion_coef)[_qp]
      63      521856 :                                               : MetaPhysicL::raw_value((*_ad_diffusion_coef)[_qp]);
      64     1390336 :   return -diffusion_coef * gradient;
      65             : }

Generated by: LCOV version 1.14