https://mooseframework.inl.gov
Loading...
Searching...
No Matches
BernoulliFormLossPressureJump.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
10
11#include "FVUtils.h"
12#include "MooseEnum.h"
13
15
18{
19 auto params = PressureJumpModel::validParams();
20 params.addClassDescription(
21 "Provides Bernoulli and form-loss pressure jumps to PorousRhieChowMassFlux.");
22 params.addRequiredParam<MooseFunctorName>("porosity", "The porosity functor.");
23 params.addRequiredParam<MooseFunctorName>("density", "The density functor.");
24 params.addParam<std::vector<Real>>(
25 "form_loss", {}, "Form-loss coefficients for each pressure-jump boundaries.");
26 MultiMooseEnum reference_velocity_side("lower_porosity higher_porosity");
27 params.addParam<MultiMooseEnum>(
28 "reference_velocity_side",
29 reference_velocity_side,
30 "Reference-velocity sides for each the pressure-jump boundaries. The default is "
31 "lower_porosity.");
32 return params;
33}
34
36 : PressureJumpModel(params),
37 _porosity(getFunctor<Real>("porosity")),
38 _density(getFunctor<Real>("density"))
39{
40 const auto & boundary_names = getParam<std::vector<BoundaryName>>("boundary");
41 const auto & form_loss = getParam<std::vector<Real>>("form_loss");
42 const auto & reference_velocity_side = getParam<MultiMooseEnum>("reference_velocity_side");
43
44 if (!form_loss.empty() && form_loss.size() != boundary_names.size())
45 paramError("form_loss", "Must have the same length as boundary.");
46 if (params.isParamSetByUser("reference_velocity_side") &&
47 reference_velocity_side.size() != boundary_names.size())
48 paramError("reference_velocity_side", "Must have the same length as boundary.");
49 if (params.isParamSetByUser("reference_velocity_side") && form_loss.empty())
50 paramError("reference_velocity_side", "Requires form_loss to be provided.");
51
52 for (const auto value : form_loss)
53 if (value < 0.0)
54 paramError("form_loss", "All entries must be >= 0.");
55
56 for (const auto i : index_range(boundary_names))
57 {
58 const auto boundary_id = _moose_mesh.getBoundaryID(boundary_names[i]);
59 _form_loss_by_id[boundary_id] = form_loss.empty() ? 0.0 : form_loss[i];
60 _use_higher_porosity_by_id[boundary_id] = params.isParamSetByUser("reference_velocity_side")
61 ? reference_velocity_side[i] == "higher_porosity"
62 : false;
63 }
64}
65
66Real
68 const Real face_mass_flux) const
69{
70 mooseAssert(appliesTo(fi), "The pressure jump model must apply to the supplied face.");
71 mooseAssert(fi.neighborPtr(), "A pressure jump requires an internal face.");
72
73 const auto time = Moose::currentState();
74 const auto elem_rho = _density(makeElemArg(fi.elemPtr()), time);
75 const auto neighbor_rho = _density(makeElemArg(fi.neighborPtr()), time);
76 const auto elem_porosity = _porosity(makeElemArg(fi.elemPtr()), time);
77 const auto neighbor_porosity = _porosity(makeElemArg(fi.neighborPtr()), time);
78
79 if (elem_rho <= 0.0 || neighbor_rho <= 0.0)
80 mooseError("density must be positive on pressure-jump face ", fi.id(), ".");
81 // The porosity matches the Rhie-Chow object's, whose porous momentum flux already rejects
82 // nonpositive values on every face.
83 mooseAssert(elem_porosity > 0.0 && neighbor_porosity > 0.0,
84 "Porosity must be positive on pressure-jump face " + std::to_string(fi.id()) + ".");
85
86 Real face_rho = 0.0;
88 Moose::FV::InterpMethod::Average, face_rho, elem_rho, neighbor_rho, fi, true);
89
90 const bool elem_is_owner = elemIsOwner(fi);
91 const Real porosity_owner = elem_is_owner ? elem_porosity : neighbor_porosity;
92 const Real porosity_non_owner = elem_is_owner ? neighbor_porosity : elem_porosity;
93
94 // The reversible term is the difference in dynamic pressure between the two sides. Density is
95 // assumed to vary smoothly, so one face-interpolated density stands in for the owner and
96 // non-owner densities in this term and in the form loss.
97 const Real superficial_velocity = face_mass_flux / face_rho;
98 const Real velocity_owner = superficial_velocity / porosity_owner;
99 const Real velocity_non_owner = superficial_velocity / porosity_non_owner;
100 Real pressure_jump =
101 0.5 * face_rho * (velocity_owner * velocity_owner - velocity_non_owner * velocity_non_owner);
102
104 for (const auto candidate_id : fi.boundaryIDs())
105 if (boundaryIDs().count(candidate_id))
106 {
107 // The form loss and reference side are set per boundary, so they would be ambiguous on a
108 // face carrying more than one of this model's boundaries.
109 mooseAssert(boundary_id == Moose::INVALID_BOUNDARY_ID,
110 "Pressure-jump face " + std::to_string(fi.id()) +
111 " lies on more than one boundary of this model.");
112 boundary_id = candidate_id;
113 }
114
115 const Real form_loss = libmesh_map_find(_form_loss_by_id, boundary_id);
116 if (form_loss > 0.0 && face_mass_flux != 0.0)
117 {
118 const bool use_higher_porosity = libmesh_map_find(_use_higher_porosity_by_id, boundary_id);
119 const bool use_elem = use_higher_porosity ? elem_porosity >= neighbor_porosity
120 : elem_porosity <= neighbor_porosity;
121 const Real reference_velocity =
122 superficial_velocity / (use_elem ? elem_porosity : neighbor_porosity);
123 const Real owner_to_non_owner_mass_flux = elem_is_owner ? face_mass_flux : -face_mass_flux;
124 const Real flow_sign = owner_to_non_owner_mass_flux > 0.0 ? 1.0 : -1.0;
125 pressure_jump -=
126 flow_sign * 0.5 * form_loss * face_rho * reference_velocity * reference_velocity;
127 }
128
129 return pressure_jump;
130}
boundary_id_type BoundaryID
registerMooseObject("NavierStokesApp", BernoulliFormLossPressureJump)
Computes reversible Bernoulli and irreversible form-loss pressure jumps.
static InputParameters validParams()
Return the input parameters for this pressure-jump model.
BernoulliFormLossPressureJump(const InputParameters &params)
Construct the Bernoulli and form-loss pressure-jump model.
std::unordered_map< BoundaryID, bool > _use_higher_porosity_by_id
Whether each boundary uses the higher-porosity side for its form-loss reference velocity.
std::unordered_map< BoundaryID, Real > _form_loss_by_id
Form-loss coefficient associated with each pressure-jump boundary.
const Moose::Functor< Real > & _porosity
Porosity on each side of a pressure-jump face.
Real computePressureJump(const FaceInfo &fi, Real face_mass_flux) const override
Compute pressure on the non-owner side minus pressure on the owner side.
const Moose::Functor< Real > & _density
Density on each side of a pressure-jump face.
const std::set< BoundaryID > & boundaryIDs() const
const Elem * neighborPtr() const
dof_id_type id() const
const Elem * elemPtr() const
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
bool isParamSetByUser(const std::string &name) const
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Interface for pressure-jump models evaluated by PorousRhieChowMassFlux.
MooseMesh & _moose_mesh
Mesh used to resolve boundary names and determine pressure-jump orientation.
const std::unordered_set< BoundaryID > & boundaryIDs() const
Boundary IDs handled by this model.
static InputParameters validParams()
Return the input parameters shared by pressure-jump models.
bool elemIsOwner(const FaceInfo &fi) const
Return whether the FaceInfo element is the oriented owner of the pressure jump.
bool appliesTo(const FaceInfo &fi) const
Return whether this model applies to a face.
void interpolate(InterpMethod m, T &result, const T2 &value1, const T3 &value2, const FaceInfo &fi, const bool one_is_elem)
const BoundaryID INVALID_BOUNDARY_ID
StateArg currentState()