https://mooseframework.inl.gov
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 
10 #include "INSFEFluidMomentumBC.h"
11 
12 registerMooseObject("NavierStokesApp", INSFEFluidMomentumBC);
13 registerMooseObjectRenamed("NavierStokesApp",
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  //
64  if (_has_pbc && _has_pbranch)
65  mooseError(
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  {
72  mooseError(
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 
82 Real
84 {
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  {
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 
112 Real
114 {
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;
120  if (_conservative_form)
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] +
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 
137 Real
139 {
140  unsigned m = this->mapVarNumber(jvar);
141  RealVectorValue vec_vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
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
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 }
const VariableTestValue & _test
const bool _conservative_form
Whether conservative form to be used for the convection term.
unsigned int _j
const unsigned int invalid_uint
const MooseArray< Point > & _normals
const bool _has_pbc
Whether boundary pressure is specified.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
RealVectorValue _vec_g
Gravity vector.
const MaterialProperty< Real > & _mu_t
Turbulent viscosity.
const unsigned _component
The component (x=0, y=1, z=2) of the momentum equation this kernel is applied.
unsigned int _p_branch_var_number
The var number of the branch pressure.
virtual Real computeQpResidual() override
const VariableGradient & _grad_u
unsigned int _i
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
bool _has_pbranch
Whether a (SAM) branch component is connected.
static InputParameters validParams()
const VariablePhiValue & _phi
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
unsigned int _qp
const bool _has_vbc
Whether boundary velocity is specified.
const VariablePhiGradient & _grad_phi
bool isParamValid(const std::string &name) const
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
static InputParameters validParams()
This class couples together all the variables for the 3D fluid equations to allow them to be used in ...
const MooseArray< Point > & _q_point
static const std::string porosity
Definition: NS.h:104
registerMooseObjectRenamed("NavierStokesApp", MDFluidMomentumBC, "02/01/2024 00:00", INSFEFluidMomentumBC)
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.
Specifies flow of momentum out of a boundary.
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.
void addCoupledVar(const std::string &name, const std::string &doc_string)
const MaterialProperty< Real > & _mu
Fluid dynamic viscosity.
const VariableValue & _rho_branch
The fluid density of the connected branch component.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Function * _v_fn
The function that specifies the boundary velocity.
const MaterialProperty< Real > & _rho
INSFEFluidMomentumBC(const InputParameters &parameters)
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
virtual Real value(Real t, const Point &p) const
virtual Real computeQpJacobian() override
const VariableValue & _u
registerMooseObject("NavierStokesApp", INSFEFluidMomentumBC)