https://mooseframework.inl.gov
Loading...
Searching...
No Matches
INSFEFluidMomentumBC.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
14 MDFluidMomentumBC,
15 "02/01/2024 00:00",
17
20{
22 params.addClassDescription("Specifies flow of momentum through a boundary");
23 params.addParam<bool>("conservative_form", false, "Whether the conservative form is used");
24 params.addParam<bool>(
25 "p_int_by_parts", false, "Whether integration by parts is applied to the pressure term");
26 params.addRequiredParam<unsigned>("component", "0,1,or 2 for x-, y-, or z- direction");
27 params.addParam<FunctionName>("p_fn", "Pressure function with time at the boundary");
28 params.addParam<FunctionName>("v_fn", "Velocity function with time at the boundary");
29
30 // coupled with branch pressure and density
31 // The 'branch_center' is a little bit tricky, because SAM 1D and multi-D could be in
32 // different mesh system.
33 // * The volume branch center is always defined in physical 3D XYZ coordinate system,
34 // * but multi-D flow could be simulated in 2D XY coordinate system,
35 // * the volume brance center needs be mapped to the 2D/3D flow mesh system
36 // The pressure at the multi-D boundary and the branch pressure is related by:
37 // p_boundary = p_branch + rho_branch * (point_boundary - branch_center) * gravity
38 params.addCoupledVar("p_branch", "Coupled scalar branch pressure");
39 params.addCoupledVar("rho_branch", "Coupled scalar branch density for gravity head calculation");
40 params.addParam<VectorValue<Real>>("gravity", "Gravity vector in 2D/3D flow mesh system");
41 params.addParam<Point>("branch_center", "Position of branch center in 2D/3D flow mesh system");
42 return params;
43}
44
46 : INSFEFluidIntegratedBCBase(parameters),
47 _conservative_form(getParam<bool>("conservative_form")),
48 _p_int_by_parts(getParam<bool>("p_int_by_parts")),
49 _component(getParam<unsigned>("component")),
50 _mu(getMaterialProperty<Real>("dynamic_viscosity")),
51 _mu_t(getMaterialProperty<Real>("turbulence_viscosity")),
52 _has_pbc(parameters.isParamValid("p_fn")),
53 _has_vbc(parameters.isParamValid("v_fn")),
54 _p_fn(_has_pbc ? &getFunction("p_fn") : nullptr),
55 _v_fn(_has_vbc ? &getFunction("v_fn") : nullptr),
56 _has_pbranch(parameters.isParamValid("p_branch")),
57 _p_branch(_has_pbranch ? coupledScalarValue("p_branch") : _zero),
58 _p_branch_var_number(_has_pbranch ? coupledScalar("p_branch") : libMesh::invalid_uint),
59 _rho_branch(_has_pbranch ? coupledScalarValue("rho_branch") : _zero)
60{
61 if ((_has_pbc || _has_pbranch) && _has_vbc)
62 mooseError("Pressure and velocity cannot be BOTH specified in INSFEFluidMomentumBC.");
63 //
66 "Pressure function and branch pressure cannot be BOTH specified in INSFEFluidMomentumBC.");
67 //
68 if (_has_pbranch)
69 {
70 if (!(isParamValid("gravity") && isParamValid("branch_center")))
71 {
73 name(),
74 ": this boundary is coupled to a volume branch, ",
75 "please provide 'gravity' vector and 'branch_center' for gravity head calculation.");
76 }
77 _vec_g = getParam<VectorValue<Real>>("gravity");
78 _branch_center = getParam<Point>("branch_center");
79 }
80}
81
82Real
84{
85 Real porosity = _has_porosity ? _porosity[_qp] : 1;
86 RealVectorValue vec_vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
87
88 // pressure bc value
89 Real p_bc = 0.0;
90 if (_has_pbc)
91 p_bc = _p_fn->value(_t, _q_point[_qp]);
92 else if (_has_pbranch)
93 {
94 Real dH = (_q_point[_qp] - _branch_center) * _vec_g;
95 p_bc = _p_branch[0] + _rho_branch[0] * dH;
96 }
97 else
98 p_bc = _pressure[_qp];
99
100 // velocity bc value
101 Real v_bc = _has_vbc ? -_v_fn->value(_t, _q_point[_qp]) : vec_vel * _normals[_qp];
102
103 Real viscous_part = (porosity > 0.99)
104 ? -(_mu[_qp] + _mu_t[_qp]) * _grad_u[_qp] * _normals[_qp] * _test[_i][_qp]
105 : 0;
106 Real p_part = _p_int_by_parts ? porosity * p_bc * _normals[_qp](_component) * _test[_i][_qp] : 0;
107 Real conv_part = _conservative_form ? _rho[_qp] * _u[_qp] * v_bc / porosity * _test[_i][_qp] : 0;
108
109 return p_part + conv_part + viscous_part;
110}
111
112Real
114{
115 Real porosity = _has_porosity ? _porosity[_qp] : 1;
116 RealVectorValue vec_vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
117 Real v_bc = _has_vbc ? -_v_fn->value(_t, _q_point[_qp]) : vec_vel * _normals[_qp];
118
119 Real conv_part = 0;
121 {
122 if (_has_vbc)
123 conv_part = _rho[_qp] * _phi[_j][_qp] * v_bc / porosity * _test[_i][_qp];
124 else
125 conv_part = _rho[_qp] * _phi[_j][_qp] * v_bc / porosity * _test[_i][_qp] +
126 _rho[_qp] * _u[_qp] * _phi[_j][_qp] * _normals[_qp](_component) / porosity *
127 _test[_i][_qp];
128 }
129 Real viscous_part = (porosity > 0.99)
130 ? -(_mu[_qp] + _mu_t[_qp]) * _grad_phi[_j][_qp](_component) *
132 : 0;
133
134 return conv_part + viscous_part;
135}
136
137Real
139{
140 unsigned m = this->mapVarNumber(jvar);
141 RealVectorValue vec_vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
142 Real porosity = _has_porosity ? _porosity[_qp] : 1;
143
144 // this is the jacobian w.r.t branch pressure
145 if (jvar == _p_branch_var_number)
146 return _p_int_by_parts ? porosity * _normals[_qp](_component) * _test[_i][_qp] : 0;
147
148 Real jac = 0;
149 switch (m)
150 {
151 case 0:
152 if (!(_has_pbc || _has_pbranch))
153 jac = _p_int_by_parts
154 ? porosity * _phi[_j][_qp] * _normals[_qp](_component) * _test[_i][_qp]
155 : 0;
156 break;
157
158 case 1:
159 case 2:
160 case 3:
161 if (m != (_component + 1))
162 jac = _conservative_form ? _rho[_qp] / porosity * _phi[_j][_qp] * _test[_i][_qp] * _u[_qp] *
163 _normals[_qp](m - 1)
164 : 0;
165 break;
166
167 case 4:
168 default:
169 jac = 0;
170 }
171
172 return jac;
173}
registerMooseObject("NavierStokesApp", INSFEFluidMomentumBC)
registerMooseObjectRenamed("NavierStokesApp", MDFluidMomentumBC, "02/01/2024 00:00", INSFEFluidMomentumBC)
virtual Real value(Real t, const Point &p) const
This class couples together all the variables for the 3D fluid equations to allow them to be used in ...
static InputParameters validParams()
const MaterialProperty< Real > & _rho
Specifies flow of momentum out of a boundary.
virtual Real computeQpJacobian() override
RealVectorValue _vec_g
Gravity vector.
unsigned int _p_branch_var_number
The var number of the branch pressure.
const bool _conservative_form
Whether conservative form to be used for the convection term.
const MaterialProperty< Real > & _mu
Fluid dynamic viscosity.
INSFEFluidMomentumBC(const InputParameters &parameters)
Point _branch_center
The location of the center (a reference point) of the connected branch.
const Function * _p_fn
The function that specifies the boundary pressure.
bool _has_pbranch
Whether a (SAM) branch component is connected.
virtual Real computeQpResidual() override
const VariableValue & _rho_branch
The fluid density of the connected branch component.
static InputParameters validParams()
const MaterialProperty< Real > & _mu_t
Turbulent viscosity.
const bool _has_vbc
Whether boundary velocity is specified.
const Function * _v_fn
The function that specifies the boundary velocity.
const bool _has_pbc
Whether boundary pressure is specified.
const unsigned _component
The component (x=0, y=1, z=2) of the momentum equation this kernel is applied.
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
const VariableValue & _p_branch
The pressure of the connected branch component.
const bool _p_int_by_parts
Whether integration by parts to be used for the pressure gradient term.
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)
unsigned int _qp
unsigned int _i
unsigned int _j
const MooseArray< Point > & _q_point
const VariablePhiGradient & _grad_phi
const VariableGradient & _grad_u
const VariableValue & _u
const VariablePhiValue & _phi
const MooseArray< Point > & _normals
const VariableTestValue & _test
const std::string & name() const
void mooseError(Args &&... args) const
bool isParamValid(const std::string &name) const
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...