LCOV - code coverage report
Current view: top level - src/postprocessors - SideDiffusiveFluxIntegral.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 32 35 91.4 %
Date: 2025-07-17 01:28:37 Functions: 18 24 75.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 "SideDiffusiveFluxIntegral.h"
      11             : #include "MathFVUtils.h"
      12             : 
      13             : #include "metaphysicl/raw_type.h"
      14             : 
      15             : registerMooseObject("MooseApp", SideDiffusiveFluxIntegral);
      16             : registerMooseObject("MooseApp", ADSideDiffusiveFluxIntegral);
      17             : registerMooseObject("MooseApp", SideVectorDiffusivityFluxIntegral);
      18             : registerMooseObject("MooseApp", ADSideVectorDiffusivityFluxIntegral);
      19             : registerMooseObjectRenamed("MooseApp",
      20             :                            SideFluxIntegral,
      21             :                            "06/30/2021 24:00",
      22             :                            SideDiffusiveFluxIntegral);
      23             : registerMooseObjectRenamed("MooseApp",
      24             :                            ADSideFluxIntegral,
      25             :                            "06/30/2021 24:00",
      26             :                            ADSideDiffusiveFluxIntegral);
      27             : 
      28             : template <bool is_ad, typename T>
      29             : InputParameters
      30      143162 : SideDiffusiveFluxIntegralTempl<is_ad, T>::validParams()
      31             : {
      32      143162 :   InputParameters params = SideIntegralVariablePostprocessor::validParams();
      33      143162 :   params.addParam<MaterialPropertyName>(
      34             :       "diffusivity",
      35             :       "The name of the diffusivity material property that will be used in the flux computation. "
      36             :       "This must be provided if the variable is of finite element type");
      37      143162 :   params.addParam<MooseFunctorName>(
      38             :       "functor_diffusivity",
      39             :       "The name of the diffusivity functor that will be used in the flux computation. This must be "
      40             :       "provided if the variable is of finite volume type");
      41      143162 :   params.addClassDescription(
      42             :       "Computes the integral of the diffusive flux over the specified boundary");
      43      143162 :   return params;
      44           0 : }
      45             : 
      46             : template <bool is_ad, typename T>
      47         266 : SideDiffusiveFluxIntegralTempl<is_ad, T>::SideDiffusiveFluxIntegralTempl(
      48             :     const InputParameters & parameters)
      49             :   : SideIntegralVariablePostprocessor(parameters),
      50         532 :     _diffusion_coef(isParamValid("diffusivity")
      51         266 :                         ? &getGenericMaterialProperty<T, is_ad>("diffusivity")
      52             :                         : nullptr),
      53         532 :     _functor_diffusion_coef(isParamValid("functor_diffusivity")
      54         266 :                                 ? &getFunctor<Moose::GenericType<T, is_ad>>("functor_diffusivity")
      55         266 :                                 : nullptr)
      56             : {
      57         266 :   if (_fv && !isParamValid("functor_diffusivity"))
      58           0 :     mooseError(
      59             :         "For a finite volume variable, the parameter 'functor_diffusivity' must be provided");
      60         266 :   if (!_fv && !isParamValid("diffusivity"))
      61           0 :     mooseError("For a finite element variable, the parameter 'diffusivity' must be provided");
      62         266 : }
      63             : 
      64             : template <bool is_ad, typename T>
      65             : Real
      66         480 : SideDiffusiveFluxIntegralTempl<is_ad, T>::computeFaceInfoIntegral(const FaceInfo * const fi)
      67             : {
      68             :   // Get the gradient of the variable on the face
      69             :   const auto grad_u =
      70         480 :       MetaPhysicL::raw_value(_field_variable->gradient(makeCDFace(*fi), determineState()));
      71             : 
      72         480 :   return -diffusivityGradientProduct(grad_u,
      73         480 :                                      MetaPhysicL::raw_value((*_functor_diffusion_coef)(
      74        1440 :                                          makeCDFace(*fi), determineState()))) *
      75        1440 :          _normals[_qp];
      76             : }
      77             : 
      78             : template <bool is_ad, typename T>
      79             : Real
      80      119406 : SideDiffusiveFluxIntegralTempl<is_ad, T>::computeQpIntegral()
      81             : {
      82      238172 :   return -diffusivityGradientProduct(_grad_u[_qp],
      83      239452 :                                      MetaPhysicL::raw_value((*_diffusion_coef)[_qp])) *
      84      358218 :          _normals[_qp];
      85             : }
      86             : 
      87             : template <bool is_ad, typename T>
      88             : RealVectorValue
      89      119086 : SideDiffusiveFluxIntegralTempl<is_ad, T>::diffusivityGradientProduct(const RealVectorValue & grad_u,
      90             :                                                                      const Real diffusivity)
      91             : {
      92      119086 :   return grad_u * diffusivity;
      93             : }
      94             : 
      95             : template <bool is_ad, typename T>
      96             : RealVectorValue
      97         800 : SideDiffusiveFluxIntegralTempl<is_ad, T>::diffusivityGradientProduct(
      98             :     const RealVectorValue & grad_u, const RealVectorValue & diffusivity)
      99             : {
     100         800 :   RealVectorValue d_grad_u = grad_u;
     101        3200 :   for (const auto i : make_range(Moose::dim))
     102        2400 :     d_grad_u(i) *= diffusivity(i);
     103             : 
     104         800 :   return d_grad_u;
     105             : }
     106             : 
     107             : template class SideDiffusiveFluxIntegralTempl<false, Real>;
     108             : template class SideDiffusiveFluxIntegralTempl<true, Real>;
     109             : template class SideDiffusiveFluxIntegralTempl<false, RealVectorValue>;
     110             : template class SideDiffusiveFluxIntegralTempl<true, RealVectorValue>;

Generated by: LCOV version 1.14