https://mooseframework.inl.gov
FVDiffusion.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 "FVDiffusion.h"
11 
12 registerMooseObject("MooseApp", FVDiffusion);
13 
16 {
19  params.addClassDescription("Computes residual for diffusion operator for finite volume method.");
20  params.addRequiredParam<MooseFunctorName>("coeff", "diffusion coefficient");
21  MooseEnum coeff_interp_method("average harmonic", "harmonic");
22  params.addParam<MooseEnum>(
23  "coeff_interp_method",
24  coeff_interp_method,
25  "Switch that can select face interpolation method for diffusion coefficients.");
26 
27  // We need at least 2 layers here with the least accurate interpolation
28  params.set<unsigned short>("ghost_layers") = 2;
29 
30  // We add the relationship manager here, this will select the right number of
31  // ghosting layers depending on the chosen interpolation method
33  "ElementSideNeighborLayers",
36  [](const InputParameters & obj_params, InputParameters & rm_params)
37  { FVRelationshipManagerInterface::setRMParamsDiffusion(obj_params, rm_params, 3); });
38 
39  return params;
40 }
41 
43  : FVFluxKernel(params),
45  _coeff(getFunctor<ADReal>("coeff")),
46  _coeff_interp_method(
47  Moose::FV::selectInterpolationMethod(getParam<MooseEnum>("coeff_interp_method")))
48 {
49 }
50 
51 ADReal
53 {
54  using namespace Moose::FV;
55  const auto state = determineState();
56 
57  auto dudn = gradUDotNormal(state, _correct_skewness);
58  ADReal coeff;
59 
60  // If we are on internal faces, we interpolate the diffusivity as usual
62  {
63  const ADReal coeff_elem = _coeff(elemArg(), state);
64  const ADReal coeff_neighbor = _coeff(neighborArg(), state);
65  // If the diffusion coefficients are zero, then we can early return 0 (and avoid warnings if we
66  // have a harmonic interpolation)
67  if (!coeff_elem.value() && !coeff_neighbor.value())
68  return 0;
69 
70  interpolate(_coeff_interp_method, coeff, coeff_elem, coeff_neighbor, *_face_info, true);
71  }
72  // Else we just use the boundary values (which depend on how the diffusion
73  // coefficient is constructed)
74  else
75  {
76  const auto face = singleSidedFaceArg();
77  coeff = _coeff(face, state);
78  }
79 
80  return -1 * coeff * dudn;
81 }
static InputParameters validParams()
Definition: FVDiffusion.C:15
virtual ADReal gradUDotNormal(const Moose::StateArg &time, const bool correct_skewness) const
Calculates and returns "grad_u dot normal" on the face to be used for diffusive terms.
Definition: FVFluxKernel.C:232
Moose::ElemArg elemArg(bool correct_skewness=false) const
Definition: FVFluxKernel.C:239
const FaceInfo * _face_info
This is holds meta-data for geometric information relevant to the current face including elem+neighbo...
Definition: FVFluxKernel.h:89
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Moose::FV::InterpMethod _coeff_interp_method
Decides if a geometric arithmetic or harmonic average is used for the face interpolation of the diffu...
Definition: FVDiffusion.h:38
void addRelationshipManager(const std::string &name, Moose::RelationshipManagerType rm_type, Moose::RelationshipManagerInputParameterCallback input_parameter_callback=nullptr)
Tells MOOSE about a RelationshipManager that this object needs.
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:46
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
registerMooseObject("MooseApp", FVDiffusion)
bool isInternalFace(const FaceInfo &) const
Returns true if the face is an internal face.
Definition: MooseFunctor.h:569
FVDiffusion implements a standard diffusion term:
Definition: FVDiffusion.h:25
static InputParameters validParams()
Definition: FVFluxKernel.C:22
const bool _correct_skewness
Just a convenience member for using skewness correction.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
const Moose::Functor< ADReal > & _coeff
Definition: FVDiffusion.h:34
Moose::ElemArg neighborArg(bool correct_skewness=false) const
Definition: FVFluxKernel.C:246
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
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
Determine the single sided face argument when evaluating a functor on a face.
Definition: FVFluxKernel.C:253
InterpMethod selectInterpolationMethod(const std::string &interp_method)
Definition: MathFVUtils.C:81
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
MooseVariableFV< Real > & _var
Definition: FVFluxKernel.h:73
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
FVDiffusion(const InputParameters &params)
Definition: FVDiffusion.C:42
static void setRMParamsDiffusion(const InputParameters &obj_params, InputParameters &rm_params, const unsigned short conditional_extended_layers)
Helper function to set the relationship manager parameters for diffusion-related kernels.
Interface function that holds the member variables and functions related to the interpolation schemes...
void interpolate(InterpMethod m, T &result, const T2 &value1, const T3 &value2, const FaceInfo &fi, const bool one_is_elem)
Provides interpolation of face values for non-advection-specific purposes (although it can/will still...
Definition: MathFVUtils.h:282
FVFluxKernel is used for calculating residual contributions from numerical fluxes from surface integr...
Definition: FVFluxKernel.h:30
virtual ADReal computeQpResidual() override
This is the primary function that must be implemented for flux kernel terms.
Definition: FVDiffusion.C:52