https://mooseframework.inl.gov
NSFVFunctorHeatFluxBC.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 "NSFVFunctorHeatFluxBC.h"
11 #include "NS.h"
12 #include "NSEnums.h"
13 
15 
18 {
20 
21  params.addRequiredParam<Real>("value", "total heat flux");
23  "phase", getPhaseEnum(), "'fluid' or 'solid' phase to which this BC is applied.");
24 
25  params.addRequiredParam<MooseEnum>("splitting", getSplittingEnum(), "type of splitting");
26 
28  "locality",
30  "whether to use local (at the boundary) or global (domain-averaged) "
31  "parameter values");
32 
33  params.addParam<MooseFunctorName>(NS::porosity, "porosity");
34  params.addParam<PostprocessorName>("average_porosity",
35  "postprocessor that provides domain-averaged proosity");
36 
37  // Name of the material properties, useful if not following the NS namespace conventions
38  params.addParam<MooseFunctorName>(NS::k, NS::k, "Fluid phase thermal conductivity");
39  params.addParam<MooseFunctorName>(NS::k_s, NS::k_s, "Solid phase thermal conductivity");
40  params.addParam<MooseFunctorName>(
41  NS::kappa, NS::kappa, "Fluid phase effective thermal conductivity");
42  params.addParam<MooseFunctorName>(
43  NS::kappa_s, NS::kappa_s, "Solid phase effective thermal conductivity");
44 
45  params.addParam<PostprocessorName>(
46  "average_k_fluid", "postprocessor that provides domain-averaged fluid thermal conductivity");
47  params.addParam<PostprocessorName>(
48  "average_kappa", "postprocessor that provides domain-averaged fluid thermal dispersion");
49  params.addParam<PostprocessorName>(
50  "average_k_solid", "postprocessor that provides domain-averaged solid thermal conductivity");
51  params.addParam<PostprocessorName>(
52  "average_kappa_solid",
53  "postprocessor that provides domain-averaged solid effective thermal "
54  "conductivity");
55  params.addClassDescription("Constant heat flux boundary condition with phase splitting "
56  "for fluid and solid energy equations");
57  return params;
58 }
59 
61  : FVFluxBC(parameters),
62  _value(getParam<Real>("value")),
63  _phase(getParam<MooseEnum>("phase").getEnum<NS::phase::PhaseEnum>()),
64  _split_type(getParam<MooseEnum>("splitting").getEnum<NS::splitting::SplittingEnum>()),
65  _locality(getParam<MooseEnum>("locality").getEnum<NS::settings::LocalityEnum>()),
66  // quantities needed for global evaluations
67  _average_eps(_locality == NS::settings::global &&
68  _split_type != NS::splitting::thermal_conductivity
69  ? &getPostprocessorValue("average_porosity")
70  : nullptr),
71  _average_k_f(_locality == NS::settings::global && _split_type != NS::splitting::porosity
72  ? &getPostprocessorValue("average_k_fluid")
73  : nullptr),
74  _average_k_s(_locality == NS::settings::global &&
75  _split_type == NS::splitting::thermal_conductivity
76  ? &getPostprocessorValue("average_k_solid")
77  : nullptr),
78  _average_kappa_s(_locality == NS::settings::global &&
79  _split_type == NS::splitting::effective_thermal_conductivity
80  ? &getPostprocessorValue("average_kappa_solid")
81  : nullptr),
82  _average_kappa(_locality == NS::settings::global &&
83  _split_type == NS::splitting::effective_thermal_conductivity
84  ? &getPostprocessorValue("average_kappa")
85  : nullptr),
86  // quantities needed for local evaluations
87  _eps(_locality == NS::settings::local && _split_type != NS::splitting::thermal_conductivity
88  ? &getFunctor<ADReal>(NS::porosity)
89  : nullptr),
90  _k_f(_locality == NS::settings::local && _split_type != NS::splitting::porosity
91  ? &getFunctor<ADReal>(NS::k)
92  : nullptr),
93  _k_s(_locality == NS::settings::local && _split_type == NS::splitting::thermal_conductivity
94  ? &getFunctor<ADReal>(NS::k_s)
95  : nullptr),
96  _kappa(_locality == NS::settings::local &&
97  _split_type == NS::splitting::effective_thermal_conductivity
98  ? &getFunctor<ADRealVectorValue>(NS::kappa)
99  : nullptr),
100  _kappa_s(_locality == NS::settings::local &&
101  _split_type == NS::splitting::effective_thermal_conductivity
102  ? &getFunctor<ADReal>(NS::kappa_s)
103  : nullptr)
104 {
105 }
106 
107 ADReal
109 {
110  // we don't need default statements in the switch-case statements for
111  // the SplittingEnum because we by default set the fraction to zero such that
112  // all of the heat flux enters the solid phase (though this default is never
113  // reached since the InputParameters class requires the MooseEnum to be
114  // one of 'porosity', 'thermal_conductivity', or 'effective_thermal_conductivity'
115  ADReal fraction = 0.0;
117 
118  // Get the functor argument for the face
119  const auto face_arg = singleSidedFaceArg();
120  const auto state = determineState();
121 
123  {
124  switch (_split_type)
125  {
127  {
128  fraction = (*_eps)(face_arg, state);
129  break;
130  }
132  {
133  ADReal d = (*_k_f)(face_arg, state) + (*_k_s)(face_arg, state);
134  fraction = d > tol ? (*_k_f)(face_arg, state) / d : 0.5;
135  break;
136  }
138  {
139  // TODO: for the case of an anisotropic conductivity, we technically should
140  // grab the component of kappa perpendicular to the boundary.
141 
142  // Need this logic to avoid AD failures when taking norms of zero. The
143  // division by sqrt(3) ensures equivalence with a non-vector form of kappa with
144  // 3 components
145  ADReal kappa;
146  if ((MooseUtils::absoluteFuzzyEqual((*_kappa)(face_arg, state)(0), 0)) &&
147  (MooseUtils::absoluteFuzzyEqual((*_kappa)(face_arg, state)(1), 0)) &&
148  (MooseUtils::absoluteFuzzyEqual((*_kappa)(face_arg, state)(2), 0)))
149  kappa = 1e-42;
150  else
151  kappa = (*_kappa)(face_arg, state).norm() / std::sqrt(3.0);
152 
153  ADReal d = (*_eps)(face_arg, state) * kappa + (*_kappa_s)(face_arg, state);
154  fraction = d > tol ? (*_eps)(face_arg, state) * kappa / d : 0.5;
155  break;
156  }
157  }
158  }
159  else
160  {
161  switch (_split_type)
162  {
164  {
165  fraction = *_average_eps;
166  break;
167  }
169  {
171  fraction = d > tol ? *_average_k_f / d : 0.5;
172  break;
173  }
175  {
176  ADReal d = (*_average_eps) * (*_average_kappa) + (*_average_kappa_s);
177  fraction = d > tol ? (*_average_eps) * (*_average_kappa) / d : 0.5;
178  break;
179  }
180  }
181  }
182 
183  if (_phase == NS::phase::solid)
184  return (1.0 - fraction) * -_value;
185  else
186  return fraction * -_value;
187 }
static const std::string kappa_s
Definition: NS.h:117
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
This boundary condition sets a constant heat flux with a splitting between the fluid and solid phases...
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
static InputParameters validParams()
const double tol
const NS::settings::LocalityEnum _locality
Where the values used in computing the splitting are pulled from, i.e.
Moose::StateArg determineState() const
NSFVFunctorHeatFluxBC(const InputParameters &parameters)
virtual ADReal computeQpResidual() override
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
const NS::phase::PhaseEnum _phase
Which phase this boundary condition is applied to, i.e. &#39;fluid&#39; or &#39;solid&#39;.
DualNumber< Real, DNDerivativeType, true > ADReal
void addRequiredParam(const std::string &name, const std::string &doc_string)
static const std::string k_s
Definition: NS.h:120
static const std::string porosity
Definition: NS.h:104
const PostprocessorValue * _average_k_s
Domain-average solid thermal conductivity.
const PostprocessorValue * _average_k_f
Domain-average fluid thermal conductivity.
const Moose::Functor< ADRealVectorValue > * _kappa
Fluid effective thermal conductivity.
static InputParameters validParams()
MooseEnum getLocalityEnum()
Definition: NSEnums.C:19
auto norm(const T &a) -> decltype(std::abs(a))
const NS::splitting::SplittingEnum _split_type
What parameters are used to split the heat flux, i.e.
static const std::string kappa
Definition: NS.h:116
const PostprocessorValue * _average_eps
Domain-average porosity.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addClassDescription(const std::string &doc_string)
registerADMooseObject("NavierStokesApp", NSFVFunctorHeatFluxBC)
MooseEnum getPhaseEnum()
Definition: NSEnums.C:13
static const Real k_epsilon
Definition: NS.h:207
MooseEnum getSplittingEnum()
Definition: NSEnums.C:25
const Real & _value
Value of the heat flux.
static const std::string k
Definition: NS.h:130
const Moose::Functor< ADReal > * _k_s
Solid thermal conductivity.
const Moose::Functor< ADReal > * _kappa_s
Solid effective thermal conductivity.