https://mooseframework.inl.gov
NSFVUtils.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 "NSFVUtils.h"
11 #include "FEProblemBase.h"
12 #include "Factory.h"
13 #include "MooseObject.h"
14 #include "InputParameters.h"
15 #include "MooseEnum.h"
16 #include "MooseError.h"
17 #include "MooseTypes.h"
18 #include "MooseUtils.h"
19 
20 namespace Moose
21 {
22 namespace FV
23 {
24 bool
26  Moose::FV::InterpMethod & advected_interp_method,
27  Moose::FV::InterpMethod & velocity_interp_method)
28 {
29  const bool need_more_ghosting =
30  setInterpolationMethod(obj, advected_interp_method, "advected_interp_method");
31 
32  const auto & velocity_interp_method_in = obj.getParam<MooseEnum>("velocity_interp_method");
33  if (velocity_interp_method_in == "average")
34  velocity_interp_method = InterpMethod::Average;
35  else if (velocity_interp_method_in == "rc")
36  velocity_interp_method = InterpMethod::RhieChow;
37  else
38  obj.mooseError("Unrecognized interpolation type ", std::string(velocity_interp_method_in));
39 
40  return need_more_ghosting;
41 }
42 
45 {
46  auto params = advectedInterpolationParameter();
47  MooseEnum velocity_interp_method("average rc", "rc");
48  params.addParam<MooseEnum>(
49  "velocity_interp_method",
50  velocity_interp_method,
51  "The interpolation to use for the velocity. Options are "
52  "'average' and 'rc' which stands for Rhie-Chow. The default is Rhie-Chow.");
53  return params;
54 }
55 }
56 }
57 
58 namespace NS
59 {
62 {
63  return MooseEnum("average upwind vanLeer min_mod venkatakrishnan", "upwind");
64 }
65 
66 std::string
67 fvAdvectedInterpolationMethodType(const MooseEnum & interpolation_method)
68 {
69  const std::string method_name = interpolation_method;
70  if (interpolation_method == "average")
71  return "FVGeometricAverage";
72  if (interpolation_method == "upwind")
73  return "FVAdvectedUpwind";
74  if (interpolation_method == "vanLeer")
75  return "FVAdvectedVanLeerWeightBased";
76  if (interpolation_method == "min_mod")
77  return "FVAdvectedMinmodWeightBased";
78  if (interpolation_method == "venkatakrishnan")
79  return "FVAdvectedVenkatakrishnanDeferredCorrection";
80 
81  mooseError("Unsupported linear FV advected interpolation method '", method_name, "'.");
82 }
83 
86 {
87  return MooseEnum("average harmonic");
88 }
89 
90 std::string
91 fvFaceInterpolationMethodType(const MooseEnum & interpolation_method)
92 {
93  const std::string method_name = interpolation_method;
94  if (interpolation_method == "average")
95  return "FVGeometricAverage";
96  if (interpolation_method == "harmonic")
97  return "FVHarmonicAverage";
98 
99  mooseError("Unsupported linear FV face interpolation method '", method_name, "'.");
100 }
101 
102 void
104  Factory & factory,
105  const MooseEnum & interpolation_method)
106 {
107  const std::string method_name = interpolation_method;
108  if (problem.hasFVInterpolationMethod(method_name))
109  return;
110 
111  const auto method_type = fvFaceInterpolationMethodType(interpolation_method);
112 
113  InputParameters params = factory.getValidParams(method_type);
114  problem.addFVInterpolationMethod(method_type, method_name, params);
115 }
116 
117 template <class T>
118 std::tuple<bool, T, T>
120  const FaceInfo & fi,
121  const Moose::StateArg & time)
122 {
123  if (!fi.neighborPtr() || (fi.elem().subdomain_id() == fi.neighbor().subdomain_id()))
124  // We've agreed to only support porosity jump treatment at subdomain boundaries
125  return {false, 0, 0};
126 
127  mooseAssert(porosity.hasBlocks(fi.elem().subdomain_id()) &&
128  porosity.hasBlocks(fi.neighbor().subdomain_id()),
129  "Porosity should have blocks on both elem and neighbor");
130 
131  const Moose::FaceArg face_elem{
132  &fi, Moose::FV::LimiterType::CentralDifference, true, false, fi.elemPtr(), nullptr};
133  const Moose::FaceArg face_neighbor{
134  &fi, Moose::FV::LimiterType::CentralDifference, true, false, fi.neighborPtr(), nullptr};
135  const auto eps_elem = porosity(face_elem, time), eps_neighbor = porosity(face_neighbor, time);
136  return {!MooseUtils::relativeFuzzyEqual(eps_elem, eps_neighbor), eps_elem, eps_neighbor};
137 }
138 
139 template std::tuple<bool, Real, Real> isPorosityJumpFace<Real>(
140  const Moose::FunctorBase<Real> & porosity, const FaceInfo & fi, const Moose::StateArg & time);
141 template std::tuple<bool, ADReal, ADReal> isPorosityJumpFace<ADReal>(
142  const Moose::FunctorBase<ADReal> & porosity, const FaceInfo & fi, const Moose::StateArg & time);
143 }
bool setInterpolationMethods(const MooseObject &obj, Moose::FV::InterpMethod &advected_interp_method, Moose::FV::InterpMethod &velocity_interp_method)
Sets the advection and velocity interpolation methods.
Definition: NSFVUtils.C:25
std::string fvFaceInterpolationMethodType(const MooseEnum &interpolation_method)
Gets the FVInterpolationMethod object type for a face interpolation method name.
Definition: NSFVUtils.C:91
const T & getParam(const std::string &name) const
void mooseError(Args &&... args)
MooseEnum fvFaceInterpolationMethods()
Enum of the interpolation methods supported by FVInterpolationMethod objects.
Definition: NSFVUtils.C:85
InputParameters interpolationParameters()
Definition: NSFVUtils.C:44
const Elem & elem() const
InputParameters getValidParams(const std::string &name) const
void addFVFaceInterpolationMethod(FEProblemBase &problem, Factory &factory, const MooseEnum &interpolation_method)
Add the FVInterpolationMethod object for a face interpolation method name, if absent.
Definition: NSFVUtils.C:103
std::string fvAdvectedInterpolationMethodType(const MooseEnum &interpolation_method)
Gets the FVInterpolationMethod object type for an advected interpolation method.
Definition: NSFVUtils.C:67
static const std::string porosity
Definition: NS.h:108
const Elem * neighborPtr() const
bool hasFVInterpolationMethod(const InterpolationMethodName &name) const
InputParameters advectedInterpolationParameter()
template std::tuple< bool, ADReal, ADReal > isPorosityJumpFace< ADReal >(const Moose::FunctorBase< ADReal > &porosity, const FaceInfo &fi, const Moose::StateArg &time)
const Elem & neighbor() const
const Elem * elemPtr() const
MooseEnum fvAdvectedInterpolationMethods()
Enum of the advected interpolation methods supported by FVInterpolationMethod objects.
Definition: NSFVUtils.C:61
std::tuple< bool, T, T > isPorosityJumpFace(const Moose::FunctorBase< T > &porosity, const FaceInfo &fi, const Moose::StateArg &time)
Checks to see whether the porosity value jumps from one side to the other of the provided face...
Definition: NSFVUtils.C:119
void mooseError(Args &&... args) const
virtual void addFVInterpolationMethod(const std::string &method_type, const std::string &name, InputParameters &parameters)
bool setInterpolationMethod(const MooseObject &obj, Moose::FV::InterpMethod &interp_method, const std::string &param_name)
template std::tuple< bool, Real, Real > isPorosityJumpFace< Real >(const Moose::FunctorBase< Real > &porosity, const FaceInfo &fi, const Moose::StateArg &time)