https://mooseframework.inl.gov
PINSFVEnergyDiffusion.C
Go to the documentation of this file.
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 "PINSFVEnergyDiffusion.h"
11 #include "INSFVEnergyVariable.h"
12 #include "NS.h"
13 
14 registerMooseObject("NavierStokesApp", PINSFVEnergyDiffusion);
15 
18 {
19  auto params = FVFluxKernel::validParams();
21  params.addClassDescription("Diffusion term in the porous media incompressible Navier-Stokes "
22  "fluid energy equations : $-div(eps * k * grad(T))$");
23  params.addRequiredParam<MooseFunctorName>(NS::porosity, "Porosity");
24  params.addRequiredParam<MooseFunctorName>(NS::k, "Thermal conductivity");
25  params.addParam<bool>(
26  "effective_diffusivity",
27  false,
28  "Whether the conductivity should be multiplied by porosity, or whether the provided "
29  "conductivity is an effective conductivity taking porosity effects into account");
30  params.renameParam("effective_diffusivity", "effective_conductivity", "");
31  MooseEnum coeff_interp_method("average harmonic", "harmonic");
32  params.addParam<MooseEnum>(
33  "kappa_interp_method",
34  coeff_interp_method,
35  "Switch that can select face interpolation method for the thermal conductivity.");
36 
37  // We add the relationship manager here, this will select the right number of
38  // ghosting layers depending on the chosen interpolation method
39  params.addRelationshipManager(
40  "ElementSideNeighborLayers",
43  [](const InputParameters & obj_params, InputParameters & rm_params)
44  { FVRelationshipManagerInterface::setRMParamsDiffusion(obj_params, rm_params, 3); });
45 
46  params.set<unsigned short>("ghost_layers") = 2;
47  return params;
48 }
49 
51  : FVFluxKernel(params),
54  _k(getFunctor<ADReal>(NS::k)),
55  _eps(getFunctor<ADReal>(NS::porosity)),
56  _porosity_factored_in(getParam<bool>("effective_conductivity")),
57  _k_interp_method(
58  Moose::FV::selectInterpolationMethod(getParam<MooseEnum>("kappa_interp_method")))
59 {
60  if (!dynamic_cast<INSFVEnergyVariable *>(&_var))
61  mooseError("PINSFVEnergyDiffusion may only be used with a fluid temperature variable, "
62  "of variable type INSFVEnergyVariable.");
63 }
64 
65 ADReal
67 {
68  // Interpolate thermal conductivity times porosity on the face
69  ADReal k_eps_face;
70  const auto state = determineState();
71 
72  if (onBoundary(*_face_info))
73  {
74  const auto ssf = singleSidedFaceArg();
75  k_eps_face = _porosity_factored_in ? _k(ssf, state) : _k(ssf, state) * _eps(ssf, state);
76  }
77  else
78  {
79  const auto face_elem = elemArg();
80  const auto face_neighbor = neighborArg();
81 
82  auto value1 = _porosity_factored_in ? _k(face_elem, state)
83  : _k(face_elem, state) * _eps(face_elem, state);
84  auto value2 = _porosity_factored_in ? _k(face_neighbor, state)
85  : _k(face_neighbor, state) * _eps(face_neighbor, state);
86 
87  // Adapt to users either passing 0 thermal conductivity, 0 porosity, or k correlations going
88  // negative. The solution is invalid only for the latter case.
89  auto k_interp_method = _k_interp_method;
90  if (value1 <= 0 || value2 <= 0)
91  {
92  flagInvalidSolution(
93  "Negative or null thermal conductivity value. If this is on purpose use arithmetic mean "
94  "interpolation instead of the default harmonic interpolation.");
96  k_interp_method = Moose::FV::InterpMethod::Average;
97  if (value1 < 0)
98  value1 = 0;
99  if (value2 < 0)
100  value2 = 0;
101  }
102 
103  Moose::FV::interpolate(k_interp_method, k_eps_face, value1, value2, *_face_info, true);
104  }
105 
106  // Compute the temperature gradient dotted with the surface normal
107  auto dTdn = gradUDotNormal(state, _correct_skewness);
108 
109  return -k_eps_face * dTdn;
110 }
virtual ADReal gradUDotNormal(const Moose::StateArg &time, const bool correct_skewness) const
Moose::ElemArg elemArg(bool correct_skewness=false) const
const Moose::FV::InterpMethod _k_interp_method
which interpolation method for the diffusivity on faces
const FaceInfo * _face_info
Moose::StateArg determineState() const
const bool _porosity_factored_in
whether the diffusivity should be multiplied by porosity
DualNumber< Real, DNDerivativeType, true > ADReal
static InputParameters validParams()
static const std::string porosity
Definition: NS.h:104
bool onBoundary(const FaceInfo &fi) const
static InputParameters validParams()
static InputParameters validParams()
const Moose::Functor< ADReal > & _eps
the porosity
A flux kernel for diffusing energy in porous media across cell faces, using a scalar isotropic diffus...
Moose::ElemArg neighborArg(bool correct_skewness=false) const
void mooseError(Args &&... args) const
Moose::FaceArg singleSidedFaceArg(const FaceInfo *fi=nullptr, Moose::FV::LimiterType limiter_type=Moose::FV::LimiterType::CentralDifference, bool correct_skewness=false, const Moose::StateArg *state_limiter=nullptr) const
InterpMethod selectInterpolationMethod(const std::string &interp_method)
registerMooseObject("NavierStokesApp", PINSFVEnergyDiffusion)
MooseVariableFV< Real > & _var
ADReal computeQpResidual() override
static void setRMParamsDiffusion(const InputParameters &obj_params, InputParameters &rm_params, const unsigned short conditional_extended_layers)
const Moose::Functor< ADReal > & _k
the thermal conductivity
void interpolate(InterpMethod m, T &result, const T2 &value1, const T3 &value2, const FaceInfo &fi, const bool one_is_elem)
static const std::string k
Definition: NS.h:130
PINSFVEnergyDiffusion(const InputParameters &params)