Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
PressureBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "Pressure.h"
11 
12 #include "Assembly.h"
13 #include "Function.h"
14 #include "MooseError.h"
15 #include "FEProblemBase.h"
16 
17 template <bool is_ad>
20 {
22  params.addDeprecatedParam<unsigned int>(
23  "component", "The component for the pressure", "This parameter is no longer necessary");
24  params.addParam<bool>("use_displaced_mesh", true, "Whether to use the displaced mesh.");
25  return params;
26 }
27 
28 template <bool is_ad>
31 {
32  auto params = emptyInputParameters();
33  params.addRequiredCoupledVar("displacements",
34  "The string of displacements suitable for the problem statement");
35  return params;
36 }
37 
38 template <bool is_ad>
40  : PressureBaseParent<is_ad>(parameters),
41  _ndisp(this->coupledComponents("displacements")),
42  _component(
43  [this, &parameters]()
44  {
45  for (unsigned int i = 0; i < _ndisp; ++i)
46  _disp_var.push_back(this->coupled("displacements", i));
47 
48  for (unsigned int i = 0; i < _ndisp; ++i)
49  {
50  if (_var.number() == _disp_var[i])
51  {
52  if (parameters.isParamSetByUser("component") &&
53  i != this->template getParam<unsigned int>("component"))
54  this->paramError(
55  "component",
56  "The component this BC is acting on is now inferred from the position "
57  "of the `variable` in the `displacements` variable list. The explicitly "
58  "specified component value is at odds with teh automatically inferred "
59  "value. The `component` parameter has been deprecated. Please double "
60  "check your input for potential mestakes.");
61  return i;
62  }
63  }
64 
65  this->paramError("variable", "The BC variable should be a displacement variable.");
66  }())
67 {
68 }
69 
70 template <bool is_ad>
71 void
73 {
74  auto boundary_ids = this->boundaryIDs();
75  std::set<SubdomainID> block_ids;
76  for (auto bndry_id : boundary_ids)
77  {
78  auto bids = _mesh.getBoundaryConnectedBlocks(bndry_id);
79  block_ids.insert(bids.begin(), bids.end());
80  }
81 
82  _coord_type = _fe_problem.getCoordSystem(*block_ids.begin());
83  for (auto blk_id : block_ids)
84  {
85  if (_coord_type != _fe_problem.getCoordSystem(blk_id))
86  mooseError("The Pressure BC requires subdomains to have the same coordinate system.");
87  }
88 }
89 
90 template <bool is_ad>
93 {
94  return computePressure() * (_normals[_qp](_component) * _test[_i][_qp]);
95 }
96 
98  : PressureBaseTempl<false>(parameters),
99  _q_dxi(nullptr),
100  _q_deta(nullptr),
101  _phi_dxi(nullptr),
102  _phi_deta(nullptr),
103  _use_displaced_mesh(this->template getParam<bool>("use_displaced_mesh")),
104  _fe(libMesh::n_threads())
105 {
106 }
107 
108 Real
109 PressureBase::computeFaceStiffness(const unsigned int local_j, const unsigned int coupled_component)
110 {
111  //
112  // Note that this approach will break down for shell elements, i.e.,
113  // topologically 2D elements in 3D space with pressure loads on
114  // the faces.
115  //
116  const Real phi_dxi = (*_phi_dxi)[local_j][_qp];
117  const Real phi_deta = _phi_deta ? (*_phi_deta)[local_j][_qp] : 0;
118 
119  const RealGradient & dqdxi = (*_q_dxi)[_qp];
120  const RealGradient out_of_plane(0, 0, 1);
121  const RealGradient & dqdeta = _q_deta ? (*_q_deta)[_qp] : out_of_plane;
122  // Here, b is dqdxi (cross) dqdeta
123  // Then, normal is b/length(b)
124  RealGradient b(dqdxi(1) * dqdeta(2) - dqdxi(2) * dqdeta(1),
125  dqdxi(2) * dqdeta(0) - dqdxi(0) * dqdeta(2),
126  dqdxi(0) * dqdeta(1) - dqdxi(1) * dqdeta(0));
127  const Real inv_length = 1 / (b * _normals[_qp]);
128 
129  const unsigned int i = _component;
130  const unsigned int j = coupled_component;
131 
132  // const int posneg[3][3] = {{0, -1, 1}, {1, 0, -1}, {-1, 1, 0}};
133  const int posneg = 1 - (j + (2 - (i + 1) % 3)) % 3;
134 
135  // const unsigned int index[3][3] = {{0, 2, 1}, {2, 1, 0}, {1, 0, 2}};
136  const unsigned int index = 2 - (j + (i + 2) % 3) % 3;
137 
138  const Real variation_b = posneg * (phi_deta * dqdxi(index) - phi_dxi * dqdeta(index));
139 
140  Real rz_term = 0;
141  if (_coord_type == Moose::COORD_RZ && j == _subproblem.getAxisymmetricRadialCoord())
142  {
143  rz_term = _normals[_qp](i) * _phi[_j][_qp] / _q_point[_qp](0);
144  }
145 
146  return computePressure() * _test[_i][_qp] * (inv_length * variation_b + rz_term);
147 }
148 
149 Real
150 PressureBase::computeStiffness(const unsigned int coupled_component)
151 {
152  if (_ndisp > 1)
153  {
154  const std::map<unsigned int, unsigned int>::iterator j_it = _node_map.find(_j);
155  if (_test[_i][_qp] == 0 || j_it == _node_map.end())
156  return 0;
157 
158  return computeFaceStiffness(j_it->second, coupled_component);
159  }
160 
162  {
163  return computePressure() * _normals[_qp](_component) * _test[_i][_qp] * _phi[_j][_qp] *
164  (2 / _q_point[_qp](0));
165  }
166 
168  {
169  return computePressure() * _normals[_qp](_component) * _test[_i][_qp] * _phi[_j][_qp] /
170  _q_point[_qp](0);
171  }
172 
173  return 0;
174 }
175 
176 Real
178 {
181 
182  return 0;
183 }
184 
185 Real
186 PressureBase::computeQpOffDiagJacobian(const unsigned int jvar_num)
187 {
189  for (unsigned int j = 0; j < _ndisp; ++j)
190  if (jvar_num == _disp_var[j])
191  return computeStiffness(j);
192 
193  return 0;
194 }
195 
196 void
198 {
199  if (_ndisp == 1)
200  return;
201 
202  if (_fe[_tid] == nullptr)
203  {
204  const unsigned int dim = _sys.mesh().dimension() - 1;
205  QBase * const & qrule = _assembly.writeableQRuleFace();
206  _fe[_tid] = FEBase::build(dim, _var.feType());
207  _fe[_tid]->attach_quadrature_rule(qrule);
208  }
209 
210  _q_dxi = &_fe[_tid]->get_dxyzdxi();
211  _phi_dxi = &_fe[_tid]->get_dphidxi();
213  {
214  _q_deta = &_fe[_tid]->get_dxyzdeta();
215  _phi_deta = &_fe[_tid]->get_dphideta();
216  }
217 
218  _fe[_tid]->reinit(_current_side_elem);
219 
221  {
222  if (_q_deta->empty())
223  _q_deta = nullptr;
224  if (_phi_deta->empty())
225  _phi_deta = nullptr;
226  }
227 
228  // Compute node map (given elem node, supply face node)
229  _node_map.clear();
230  const unsigned int num_node_elem = _current_elem->n_nodes();
231  const Node * const * elem_nodes = _current_elem->get_nodes();
232  const unsigned int num_node_face = _current_side_elem->n_nodes();
233  const Node * const * face_nodes = _current_side_elem->get_nodes();
234  unsigned int num_found = 0;
235  for (unsigned i = 0; i < num_node_elem; ++i)
236  {
237  for (unsigned j = 0; j < num_node_face; ++j)
238  if (**(elem_nodes + i) == **(face_nodes + j))
239  {
240  _node_map[i] = j;
241  ++num_found;
242  break;
243  }
244  if (num_found == num_node_face)
245  break;
246  }
247 }
248 
249 void
251 {
253 }
254 
255 template class PressureBaseTempl<false>;
256 template class PressureBaseTempl<true>;
Moose::GenericType< Real, is_ad > GenericReal
virtual GenericReal< is_ad > computeQpResidual() override final
Definition: PressureBase.C:92
unsigned int n_threads()
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
typename std::conditional< is_ad, ADIntegratedBC, IntegratedBC >::type PressureBaseParent
Pressure applies a pressure on a given boundary in the direction defined by component.
Definition: PressureBase.h:26
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const std::vector< std::vector< Real > > * _phi_dxi
Definition: PressureBase.h:86
void mooseError(Args &&... args)
unsigned int dim
const bool _use_displaced_mesh
Definition: PressureBase.h:88
virtual Real computeQpOffDiagJacobian(const unsigned int jvar_num) override final
Definition: PressureBase.C:186
Moose::CoordinateSystemType _coord_type
Coordinate system type.
Definition: PressureBase.h:54
Real computeStiffness(const unsigned int coupled_component)
Definition: PressureBase.C:150
std::vector< unsigned int > _disp_var
Variable numbers of coupled displacement variables.
Definition: PressureBase.h:45
virtual GenericReal< is_ad > computePressure() const=0
COORD_RSPHERICAL
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
const std::vector< RealGradient > * _q_dxi
Definition: PressureBase.h:84
InputParameters emptyInputParameters()
static InputParameters actionParams()
Definition: PressureBase.C:30
std::vector< std::unique_ptr< FEBase > > _fe
Definition: PressureBase.h:91
InputParameters validParams()
const unsigned int _component
displacement component to apply the bc to
Definition: PressureBase.h:51
virtual void precalculateQpJacobian() override final
Definition: PressureBase.C:197
bool isParamSetByUser(const std::string &name) const
static InputParameters validParams()
Definition: PressureBase.C:19
virtual void initialSetup() override
Definition: PressureBase.C:72
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const std::vector< RealGradient > * _q_deta
Definition: PressureBase.h:85
const unsigned int _ndisp
Number of displacement variables.
Definition: PressureBase.h:48
std::map< unsigned int, unsigned int > _node_map
Definition: PressureBase.h:93
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
virtual Real computeQpJacobian() override final
Definition: PressureBase.C:177
const std::vector< std::vector< Real > > * _phi_deta
Definition: PressureBase.h:87
PressureBaseTempl(const InputParameters &parameters)
Definition: PressureBase.C:39
Real computeFaceStiffness(const unsigned int local_j, const unsigned int coupled_component)
Definition: PressureBase.C:109
PressureBase(const InputParameters &parameters)
Definition: PressureBase.C:97
virtual void precalculateQpOffDiagJacobian(const MooseVariableFEBase &jvar) override final
Definition: PressureBase.C:250