https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MomentumFreeSlipBC.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 "MomentumFreeSlipBC.h"
11#include "MooseMesh.h"
12#include "MooseVariable.h"
13#include "SystemBase.h"
14#include "FEProblemBase.h"
15#include "libmesh/numeric_vector.h"
16
18
21{
23 params.addRequiredCoupledVar("rho_u", "x-component of velocity");
24 params.addRequiredCoupledVar("rho_v", "y-component of velocity");
25 params.addCoupledVar("rho_w", "z-component of velocity");
26 params.addClassDescription("Implements free slip boundary conditions for the Navier Stokes"
27 "momentum equation.");
28 return params;
29}
30
32 : NodalNormalBC(parameters),
33 _mesh_dimension(_mesh.dimension()),
34 _rho_u(coupledValue("rho_u")),
35 _rho_v(_mesh_dimension >= 2 ? coupledValue("rho_v") : _zero),
36 _rho_w(_mesh_dimension >= 3 ? coupledValue("rho_w") : _zero),
37 _rho_u_var(getVar("rho_u", 0)),
38 _rho_v_var(getVar("rho_v", 0)),
39 _rho_w_var(getVar("rho_w", 0))
40{
41 if (_mesh_dimension == 1)
42 mooseError(type(), " is not applicable for one-dimensional mesh.");
43 else if (_mesh_dimension == 3)
44 mooseError(type(), " has not been implemented for three-dimensional mesh.");
45 else if (_mesh_dimension != 2)
46 mooseError("Mesh dimension ", std::to_string(_mesh_dimension), " not supported.");
47
48 auto check_var = [this](const auto & var_name, const auto * const var_ptr)
49 {
50 if (var_ptr)
51 return;
52
53 if (isCoupledConstant(var_name))
54 paramError(var_name, "A coupled constant for this variable is not supported in this class");
55 else
56 mooseError(var_name, "This variable must be supplied.");
57
58 if (!var_ptr->isNodal())
59 paramError(var_name, "Only nodal variables supported");
60 };
61
62 check_var("rho_u", _rho_u_var);
63 check_var("rho_v", _rho_v_var);
64 if (_mesh_dimension == 3)
65 check_var("rho_w", _rho_w_var);
66}
67
69
70bool
72{
73 // this prevents zeroing out the row
75}
76
77void
79{
80 _normal = Point(_nx[_qp], _ny[_qp], _nz[_qp]);
81
82 auto set_residual = [this](auto & residual)
83 {
84 const auto rho_u_dof_idx = _rho_u_var->nodalDofIndex();
85 const auto rho_v_dof_idx = _rho_v_var->nodalDofIndex();
86
87 const auto rho_un = _normal(0) * _rho_u[0] + _normal(1) * _rho_v[0];
88 const auto Re_u = residual(rho_u_dof_idx);
89 const auto Re_v = residual(rho_v_dof_idx);
90
91 // We obtain these contributions in 3 steps:
92 // 1.) Tranform the momentum residuals into (tangential, normal)
93 // components by left-multiplying the residual by:
94 // R = [tx ty] = [-ny nx]
95 // [nx ny] [ nx ny]
96 // 2.) Impose the no-normal-flow BC, rho_un = 0, in the normal momentum component's
97 // residual.
98 // 3.) Transform back to (x,y) momentum components by left-multiplying the residual by
99 // R^{-1} = R^T.
100 const auto rho_u_val =
101 (Re_u * _normal(1) * _normal(1) - Re_v * _normal(0) * _normal(1)) + rho_un * _normal(0);
102 const auto rho_v_val =
103 (-Re_u * _normal(0) * _normal(1) + Re_v * _normal(0) * _normal(0)) + rho_un * _normal(1);
104
105 // NOTE: we have to handle all components at the same time, otherwise we'd work with the
106 // modified residual and we do not want that
107 residual.set(rho_u_dof_idx, rho_u_val);
108 residual.set(rho_v_dof_idx, rho_v_val);
109 };
110
111 setResidual(_sys, set_residual);
112}
registerMooseObject("NavierStokesApp", MomentumFreeSlipBC)
virtual bool isCoupledConstant(const std::string &var_name) const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)
Boundary condition that applies free slip condition at nodes.
const unsigned int _mesh_dimension
The dimension of the mesh.
const MooseVariable *const _rho_u_var
x-velocity variable
const VariableValue & _rho_v
Momentum in y-direction.
const MooseVariable *const _rho_v_var
y-velocity variable
MomentumFreeSlipBC(const InputParameters &parameters)
virtual bool shouldApply() const override
const VariableValue & _rho_u
Momentum in x-direction.
virtual void computeResidual() override
static InputParameters validParams()
const MooseVariable *const _rho_w_var
z-velocity variable
const std::string & type() const
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
const dof_id_type & nodalDofIndex() const override
const unsigned int _qp
const VariableValue & _nz
const VariableValue & _ny
static InputParameters validParams()
const VariableValue & _nx
SystemBase & _sys
FEProblemBase & _fe_problem
const bool & currentlyComputingJacobian() const
void setResidual(SystemBase &sys, const T &residual, MooseVariableFE< T > &var)