https://mooseframework.inl.gov
InterfaceDiffusiveFluxIntegral.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 
11 #include "MathFVUtils.h"
12 #include "FaceInfo.h"
13 
14 #include "libmesh/remote_elem.h"
15 #include "metaphysicl/raw_type.h"
16 
19 
20 template <bool is_ad>
23 {
25 
26  params.addRequiredCoupledVar("variable",
27  "The name of the variable on the primary side of the interface");
28  params.addCoupledVar("neighbor_variable",
29  "The name of the variable on the secondary side of the interface.");
30  params.addRequiredParam<MaterialPropertyName>(
31  "diffusivity", "The name of the diffusivity property on the primary side of the interface");
32  params.addParam<MaterialPropertyName>("neighbor_diffusivity",
33  "The name of the diffusivity property on the secondary "
34  "side of the interface. By default, the "
35  "primary side material property name is used for the "
36  "secondary side. Only needed for finite volume");
37  MooseEnum interp_method("average harmonic", "harmonic");
38  params.addParam<MooseEnum>(
39  "coeff_interp_method",
40  interp_method,
41  "Switch that can select face interpolation method for diffusion coefficients.");
42  params.addClassDescription("Computes the diffusive flux on the interface.");
43 
44  return params;
45 }
46 
47 template <bool is_ad>
49  const InputParameters & parameters)
50  : InterfaceIntegralPostprocessor(parameters),
51  _grad_u(coupledGradient("variable")),
52  _u(coupledValue("variable")),
53  _u_neighbor(parameters.isParamSetByUser("neighbor_variable")
54  ? coupledNeighborValue("neighbor_variable")
55  : coupledNeighborValue("variable")),
56  _diffusion_coef(
57  getGenericMaterialProperty<Real, is_ad>(getParam<MaterialPropertyName>("diffusivity"))),
58  _diffusion_coef_neighbor(parameters.isParamSetByUser("neighbor_diffusivity")
59  ? getGenericNeighborMaterialProperty<Real, is_ad>(
60  getParam<MaterialPropertyName>("neighbor_diffusivity"))
61  : getGenericNeighborMaterialProperty<Real, is_ad>(
62  getParam<MaterialPropertyName>("diffusivity")))
63 {
64 
65  // Primary and secondary variable should both be of a similar variable type
66  if (parameters.isParamSetByUser("neighbor_variable"))
67  if ((_has_fv_vars && !getFieldVar("neighbor_variable", 0)->isFV()) ||
68  (!_has_fv_vars && getFieldVar("neighbor_variable", 0)->isFV()))
69  mooseError("For the InterfaceDiffusiveFluxIntegral, variable and "
70  "neighbor_variable should be of a similar variable type.");
71 
72  if (!_has_fv_vars && parameters.isParamSetByUser("coeff_interp_method"))
73  paramError(
74  "coeff_interp_method",
75  "This parameter should not be defined for the postprocessing of finite element variables!");
76 
77  const auto & interp_method = getParam<MooseEnum>("coeff_interp_method");
78  if (interp_method == "average")
80  else if (interp_method == "harmonic")
82 }
83 
84 template <bool is_ad>
85 Real
87 {
88  if (_has_fv_vars)
89  {
90  mooseAssert(_fi, "This should never be null. If it is then something went wrong in execute()");
91 
92  const auto normal = _fi->normal();
93 
94  // Form a finite difference gradient across the interface
95  Point one_over_gradient_support = _fi->elemCentroid() - _fi->neighborCentroid();
96  one_over_gradient_support /= (one_over_gradient_support * one_over_gradient_support);
97  const auto gradient = (_u[_qp] - _u_neighbor[_qp]) * one_over_gradient_support;
98 
99  Real diffusivity;
100  interpolate(_coeff_interp_method,
101  diffusivity,
102  MetaPhysicL::raw_value(_diffusion_coef[_qp]),
103  MetaPhysicL::raw_value(_diffusion_coef_neighbor[_qp]),
104  *_fi,
105  true);
106 
107  return -diffusivity * MetaPhysicL::raw_value(gradient * normal);
108  }
109  else
110  return -MetaPhysicL::raw_value(_diffusion_coef[_qp]) * _grad_u[_qp] * _normals[_qp];
111 }
112 
gc*elem+(1-gc)*neighbor
Moose::FV::InterpMethod _coeff_interp_method
Decides if a geometric arithmetic or harmonic average is used for the face interpolation of the diffu...
bool _has_fv_vars
Whether finite volume variables are involved in the user object.
1/(gc/elem+(1-gc)/neighbor)
virtual bool isFV() const
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:73
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
This postprocessor computes an integral of the diffusive flux over an interface.
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...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
This postprocessor add generel capabilities to the InterfacePostprocessor to compute an integral over...
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerMooseObject("MooseApp", InterfaceDiffusiveFluxIntegral)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
const InputParameters & parameters() const
Get the parameters of the object.
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...
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
InterfaceDiffusiveFluxIntegralTempl(const InputParameters &parameters)
const MooseVariableFieldBase * getFieldVar(const std::string &var_name, unsigned int comp) const
Definition: Coupleable.C:282