www.mooseframework.org
RinglebMesh.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 "RinglebMesh.h"
11 
12 #include "libmesh/face_quad4.h"
13 #include "libmesh/face_tri3.h"
14 #include "libmesh/mesh_modification.h"
15 
16 registerMooseObject("MooseApp", RinglebMesh);
17 
20 {
22  params.addRequiredParam<Real>("gamma", "Gamma parameter");
23  params.addRequiredParam<Real>("kmax", "Value of k on the inner wall.");
24  params.addRequiredParam<Real>("kmin", "Value of k on the outer wall.");
25  params.addRequiredParam<int>("num_q_pts",
26  "How many points to discretize the range q = (0.5, k) into.");
27  params.addRequiredParam<int>("n_extra_q_pts",
28  "How many 'extra' points should be inserted in the final element"
29  " *in addition to* the equispaced q points.");
30  params.addRequiredParam<int>("num_k_pts", "How many points in the range k=(kmin, kmax).");
31  params.addParam<boundary_id_type>("inflow_bid", 1, "The boundary id to use for the inflow");
32  params.addParam<boundary_id_type>(
33  "inner_wall_bid", 2, "The boundary id to use for the inner wall");
34  params.addParam<boundary_id_type>("outflow_bid", 3, "The boundary id to use for the outflow");
35  params.addParam<boundary_id_type>(
36  "outer_wall_bid", 4, "The boundary id to use for the outer wall");
37  params.addParam<bool>(
38  "triangles", false, "If true, all the quadrilateral elements will be split into triangles");
39  params.addClassDescription("Creates a mesh for the Ringleb problem.");
40 
41  return params;
42 }
43 
45  : MooseMesh(parameters),
46  _gamma(getParam<Real>("gamma")),
47  _kmax(getParam<Real>("kmax")),
48  _kmin(getParam<Real>("kmin")),
49  _num_q_pts(getParam<int>("num_q_pts")),
50  _n_extra_q_pts(getParam<int>("n_extra_q_pts")),
51  _num_k_pts(getParam<int>("num_k_pts")),
52  _inflow_bid(getParam<boundary_id_type>("inflow_bid")),
53  _outflow_bid(getParam<boundary_id_type>("outflow_bid")),
54  _inner_wall_bid(getParam<boundary_id_type>("inner_wall_bid")),
55  _outer_wall_bid(getParam<boundary_id_type>("outer_wall_bid")),
56  _triangles(getParam<bool>("triangles"))
57 {
58 
59  // catch likely user errors
60  if (_kmax <= _kmin)
61  mooseError("RinglebMesh: kmax must be greater than kmin");
62 }
63 
64 std::unique_ptr<MooseMesh>
66 {
67  return std::make_unique<RinglebMesh>(*this);
68 }
69 
70 std::vector<Real>
71 RinglebMesh::arhopj(const Real & gamma, const std::vector<Real> & q, const int & index)
72 {
73  std::vector<Real> values(4);
74  Real a = std::sqrt(1 - ((gamma - 1) / 2.) * std::pow(q[index], 2));
75  Real rho = std::pow(a, 2. / (gamma - 1));
76  Real p = (1. / gamma) * std::pow(a, 2 * gamma / (gamma - 1));
77  Real J = 1. / a + 1. / (3. * std::pow(a, 3)) + 1. / (5. * std::pow(a, 5)) -
78  0.5 * std::log((1 + a) / (1 - a));
79  values = {a, rho, p, J};
80  return values;
81 }
82 
83 std::vector<Real>
84 RinglebMesh::computexy(const std::vector<Real> values,
85  const int & i,
86  const int & index,
87  const std::vector<Real> & ks,
88  const std::vector<Real> & q)
89 {
90  std::vector<Real> xy(2);
91 
92  // Compute x(q,k)
93  xy[0] = 0.5 / values[1] * (2. / ks[i] / ks[i] - 1. / q[index] / q[index]) - 0.5 * values[3];
94 
95  // Compute the term that goes under the sqrt sign
96  // If 1 - (q/k)^2 is slightly negative, we make it zero.
97  Real sqrt_term = 1. - q[index] * q[index] / ks[i] / ks[i];
98  sqrt_term = std::max(sqrt_term, 0.);
99 
100  // Compute y(q,k)
101  xy[1] = 1. / (ks[i] * values[1] * q[index]) * std::sqrt(sqrt_term);
102 
103  return xy;
104 }
105 
106 void
108 {
109  MeshBase & mesh = getMesh();
110  BoundaryInfo & boundary_info = mesh.get_boundary_info();
111 
113  std::vector<std::vector<Node *>> stream_nodes(_num_k_pts);
114 
116  int current_node_id = 0;
117 
119  std::vector<Real> ks(_num_k_pts);
120  Real diff = (_kmax - _kmin) / (_num_k_pts - 1);
121  for (int i = 0; i < _num_k_pts; i++)
122  ks[i] = _kmin + i * diff;
123 
124  for (int i = 0; i < _num_k_pts; i++)
125  {
126  stream_nodes[i].resize(2 * (_num_q_pts + _n_extra_q_pts));
127 
129  std::vector<Real> q(_num_q_pts);
130  Real diffq = (ks[i] - 0.5) / (_num_q_pts - 1);
131  for (int j = 0; j < _num_q_pts; j++)
132  q[j] = 0.5 + j * diffq;
133 
135  for (int j = _num_q_pts; j < _num_q_pts + _n_extra_q_pts; j++)
136  {
137  std::vector<Real>::iterator it = q.end();
138  q.insert(--it, 0.3 * q[j - 2] + 0.7 * q[j - 1]);
139  }
140 
141  std::vector<Real> vals(4);
142  std::vector<Real> xy(2);
144  for (int j = 0; j < _num_q_pts + _n_extra_q_pts; j++)
145  {
146  // Compute the different parameters
147  vals = arhopj(_gamma, q, j);
148 
149  // Compute x and y
150  xy = computexy(vals, i, j, ks, q);
151 
152  // Create a node with (x,y) coordinates as it's on the upper part of the mesh
153  if (j != _num_q_pts + _n_extra_q_pts - 1)
154  stream_nodes[i][j] = mesh.add_point(Point(xy[0], xy[1]), current_node_id++);
155  }
156 
158  for (int j = _num_q_pts + _n_extra_q_pts; j < 2 * (_num_q_pts + _n_extra_q_pts); j++)
159  {
160  int index = 2 * (_num_q_pts + _n_extra_q_pts) - 1 - j;
161  // Compute the different parameters
162  vals = arhopj(_gamma, q, index);
163 
164  // Compute x and y
165  xy = computexy(vals, i, index, ks, q);
166 
167  // Create a node with (x,-y) coordinates as it's on the lower part of the mesh
168  stream_nodes[i][j] = mesh.add_point(Point(xy[0], -xy[1]), current_node_id++);
169  }
170  }
171 
173  for (int i = 0; i < _num_k_pts - 1; i++)
174  {
175  for (int j = 0; j < 2 * (_num_q_pts + _n_extra_q_pts) - 1; j++)
176  {
178  if (j != _num_q_pts + _n_extra_q_pts - 1 and j != _num_q_pts + _n_extra_q_pts - 2)
179  {
180  Elem * elem = mesh.add_elem(new Quad4);
181  elem->set_node(0) = stream_nodes[i][j];
182  elem->set_node(1) = stream_nodes[i][j + 1];
183  elem->set_node(2) = stream_nodes[i + 1][j + 1];
184  elem->set_node(3) = stream_nodes[i + 1][j];
185 
186  if (i == 0)
187  boundary_info.add_side(elem->id(), /*side=*/0, _outer_wall_bid);
188  if (j == 0)
189  boundary_info.add_side(elem->id(), /*side=*/3, _inflow_bid);
190  if (j == 2 * (_num_q_pts + _n_extra_q_pts) - 2)
191  boundary_info.add_side(elem->id(), /*side=*/1, _outflow_bid);
192  if (i == _num_k_pts - 2)
193  boundary_info.add_side(elem->id(), /*side=*/2, _inner_wall_bid);
194  }
195  else if (j == _num_q_pts + _n_extra_q_pts - 2)
196  {
197  Elem * elem = mesh.add_elem(new Quad4);
198  elem->set_node(0) = stream_nodes[i][j];
199  elem->set_node(1) = stream_nodes[i][j + 2];
200  elem->set_node(2) = stream_nodes[i + 1][j + 2];
201  elem->set_node(3) = stream_nodes[i + 1][j];
202 
203  if (i == 0)
204  boundary_info.add_side(elem->id(), /*side=*/0, _outer_wall_bid);
205  if (i == _num_k_pts - 2)
206  boundary_info.add_side(elem->id(), /*side=*/2, _inner_wall_bid);
207  }
208  }
209  }
210 
212  mesh.prepare_for_use();
213 
215  if (_triangles)
216  MeshTools::Modification::all_tri(mesh);
217 
219  boundary_info.sideset_name(_inflow_bid) = "inflow";
220  boundary_info.sideset_name(_outflow_bid) = "outflow";
221  boundary_info.sideset_name(_inner_wall_bid) = "inner_wall";
222  boundary_info.sideset_name(_outer_wall_bid) = "outer_wall";
223 }
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
Definition: MooseMesh.C:78
const int & _num_q_pts
How many points to discretize the range q = (0.5, k) into.
Definition: RinglebMesh.h:57
const boundary_id_type _outer_wall_bid
Definition: RinglebMesh.h:66
const Real & _kmax
k is a streamline parameter, i.e.
Definition: RinglebMesh.h:51
Mesh generated from parameters.
Definition: RinglebMesh.h:17
const bool & _triangles
This parameter, if true, allows to split the quadrilateral elements into triangular elements...
Definition: RinglebMesh.h:69
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
std::vector< Real > arhopj(const Real &gamma, const std::vector< Real > &q, const int &index)
Definition: RinglebMesh.C:71
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
auto max(const L &left, const R &right)
const boundary_id_type _outflow_bid
Definition: RinglebMesh.h:66
int8_t boundary_id_type
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3198
std::vector< Real > computexy(const std::vector< Real > values, const int &i, const int &index, const std::vector< Real > &ks, const std::vector< Real > &q)
Definition: RinglebMesh.C:84
const Real & _kmin
kmin corresponds to the outer wall
Definition: RinglebMesh.h:54
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
registerMooseObject("MooseApp", RinglebMesh)
auto log(const T &)
const int & _n_extra_q_pts
how many "extra" points should be inserted in the nearest element from the horizontal in additi /// o...
Definition: RinglebMesh.h:60
static InputParameters validParams()
Definition: RinglebMesh.C:19
const boundary_id_type _inner_wall_bid
Definition: RinglebMesh.h:66
virtual void buildMesh() override
Must be overridden by child classes.
Definition: RinglebMesh.C:107
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Real & _gamma
Gamma.
Definition: RinglebMesh.h:45
RinglebMesh(const InputParameters &parameters)
Definition: RinglebMesh.C:44
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
const int & _num_k_pts
how many points in the range k=(kmin, kmax).
Definition: RinglebMesh.h:63
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
virtual Elem * elem(const dof_id_type i)
Various accessors (pointers/references) for Elem "i".
Definition: MooseMesh.C:2849
virtual std::unique_ptr< MooseMesh > safeClone() const override
A safer version of the clone() method that hands back an allocated object wrapped in a smart pointer...
Definition: RinglebMesh.C:65
const boundary_id_type _inflow_bid
The boundary ids to use for the ringleb mesh.
Definition: RinglebMesh.h:66
MooseUnits pow(const MooseUnits &, int)
Definition: Units.C:537
void ErrorVector unsigned int