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 
18 template <>
21 {
23  params.addRequiredParam<Real>("gamma", "Gamma parameter");
24  params.addRequiredParam<Real>("kmax", "Value of k on the inner wall.");
25  params.addRequiredParam<Real>("kmin", "Value of k on the outer wall.");
26  params.addRequiredParam<int>("num_q_pts",
27  "How many points to discretize the range q = (0.5, k) into.");
28  params.addRequiredParam<int>("n_extra_q_pts",
29  "How many 'extra' points should be inserted in the final element"
30  " *in addition to* the equispaced q points.");
31  params.addRequiredParam<int>("num_k_pts", "How many points in the range k=(kmin, kmax).");
32  params.addParam<boundary_id_type>("inflow_bid", 1, "The boundary id to use for the inflow");
33  params.addParam<boundary_id_type>(
34  "inner_wall_bid", 2, "The boundary id to use for the inner wall");
35  params.addParam<boundary_id_type>("outflow_bid", 3, "The boundary id to use for the outflow");
36  params.addParam<boundary_id_type>(
37  "outer_wall_bid", 4, "The boundary id to use for the outer wall");
38  params.addParam<bool>(
39  "triangles", false, "If true, all the quadrilateral elements will be split into triangles");
40  params.addClassDescription("Creates a mesh for the Ringleb problem.");
41 
42  return params;
43 }
44 
46  : MooseMesh(parameters),
47  _gamma(getParam<Real>("gamma")),
48  _kmax(getParam<Real>("kmax")),
49  _kmin(getParam<Real>("kmin")),
50  _num_q_pts(getParam<int>("num_q_pts")),
51  _n_extra_q_pts(getParam<int>("n_extra_q_pts")),
52  _num_k_pts(getParam<int>("num_k_pts")),
53  _inflow_bid(getParam<boundary_id_type>("inflow_bid")),
54  _outflow_bid(getParam<boundary_id_type>("outflow_bid")),
55  _inner_wall_bid(getParam<boundary_id_type>("inner_wall_bid")),
56  _outer_wall_bid(getParam<boundary_id_type>("outer_wall_bid")),
57  _triangles(getParam<bool>("triangles"))
58 {
59 
60  // catch likely user errors
61  if (_kmax <= _kmin)
62  mooseError("RinglebMesh: kmax must be greater than kmin");
63 }
64 
65 std::unique_ptr<MooseMesh>
67 {
68  return libmesh_make_unique<RinglebMesh>(*this);
69 }
70 
71 std::vector<Real>
72 RinglebMesh::arhopj(const Real & gamma, const std::vector<Real> & q, const int & index)
73 {
74  std::vector<Real> values(4);
75  Real a = std::sqrt(1 - ((gamma - 1) / 2.) * std::pow(q[index], 2));
76  Real rho = std::pow(a, 2. / (gamma - 1));
77  Real p = (1. / gamma) * std::pow(a, 2 * gamma / (gamma - 1));
78  Real J = 1. / a + 1. / (3. * std::pow(a, 3)) + 1. / (5. * std::pow(a, 5)) -
79  0.5 * std::log((1 + a) / (1 - a));
80  values = {a, rho, p, J};
81  return values;
82 }
83 
84 std::vector<Real>
85 RinglebMesh::computexy(const std::vector<Real> values,
86  const int & i,
87  const int & index,
88  const std::vector<Real> & ks,
89  const std::vector<Real> & q)
90 {
91  std::vector<Real> xy(2);
92 
93  // Compute x(q,k)
94  xy[0] = 0.5 / values[1] * (2. / ks[i] / ks[i] - 1. / q[index] / q[index]) - 0.5 * values[3];
95 
96  // Compute the term that goes under the sqrt sign
97  // If 1 - (q/k)^2 is slightly negative, we make it zero.
98  Real sqrt_term = 1. - q[index] * q[index] / ks[i] / ks[i];
99  sqrt_term = std::max(sqrt_term, 0.);
100 
101  // Compute y(q,k)
102  xy[1] = 1. / (ks[i] * values[1] * q[index]) * std::sqrt(sqrt_term);
103 
104  return xy;
105 }
106 
107 void
109 {
110  MeshBase & mesh = getMesh();
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  mesh.boundary_info->add_side(elem->id(), /*side=*/0, _outer_wall_bid);
188  if (j == 0)
189  mesh.boundary_info->add_side(elem->id(), /*side=*/3, _inflow_bid);
190  if (j == 2 * (_num_q_pts + _n_extra_q_pts) - 2)
191  mesh.boundary_info->add_side(elem->id(), /*side=*/1, _outflow_bid);
192  if (i == _num_k_pts - 2)
193  mesh.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  mesh.boundary_info->add_side(elem->id(), /*side=*/0, _outer_wall_bid);
205  if (i == _num_k_pts - 2)
206  mesh.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  mesh.boundary_info->sideset_name(_inflow_bid) = "inflow";
220  mesh.boundary_info->sideset_name(_outflow_bid) = "outflow";
221  mesh.boundary_info->sideset_name(_inner_wall_bid) = "inner_wall";
222  mesh.boundary_info->sideset_name(_outer_wall_bid) = "outer_wall";
223 }
const int & _num_q_pts
How many points to discretize the range q = (0.5, k) into.
Definition: RinglebMesh.h:60
const boundary_id_type _outer_wall_bid
Definition: RinglebMesh.h:69
const Real & _kmax
k is a streamline parameter, i.e.
Definition: RinglebMesh.h:54
Mesh generated from parameters.
Definition: RinglebMesh.h:22
const bool & _triangles
This parameter, if true, allows to split the quadrilateral elements into triangular elements...
Definition: RinglebMesh.h:72
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
std::vector< Real > arhopj(const Real &gamma, const std::vector< Real > &q, const int &index)
Definition: RinglebMesh.C:72
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...
const boundary_id_type _outflow_bid
Definition: RinglebMesh.h:69
Real pow(Real x, int e)
Definition: MathUtils.C:211
InputParameters validParams< MooseMesh >()
Definition: MooseMesh.C:63
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
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:85
const Real & _kmin
kmin corresponds to the outer wall
Definition: RinglebMesh.h:57
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
InputParameters validParams< RinglebMesh >()
Definition: RinglebMesh.C:20
registerMooseObject("MooseApp", RinglebMesh)
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:63
const boundary_id_type _inner_wall_bid
Definition: RinglebMesh.h:69
virtual void buildMesh() override
Must be overridden by child classes.
Definition: RinglebMesh.C:108
const Real & _gamma
Gamma.
Definition: RinglebMesh.h:48
RinglebMesh(const InputParameters &parameters)
Definition: RinglebMesh.C:45
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:66
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:2253
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:66
const boundary_id_type _inflow_bid
The boundary ids to use for the ringleb mesh.
Definition: RinglebMesh.h:69