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 
19 
22 {
24  params.addRequiredParam<Real>("gamma", "Gamma parameter");
25  params.addRequiredParam<Real>("kmax", "Value of k on the inner wall.");
26  params.addRequiredParam<Real>("kmin", "Value of k on the outer wall.");
27  params.addRequiredParam<int>("num_q_pts",
28  "How many points to discretize the range q = (0.5, k) into.");
29  params.addRequiredParam<int>("n_extra_q_pts",
30  "How many 'extra' points should be inserted in the final element"
31  " *in addition to* the equispaced q points.");
32  params.addRequiredParam<int>("num_k_pts", "How many points in the range k=(kmin, kmax).");
33  params.addParam<boundary_id_type>("inflow_bid", 1, "The boundary id to use for the inflow");
34  params.addParam<boundary_id_type>(
35  "inner_wall_bid", 2, "The boundary id to use for the inner wall");
36  params.addParam<boundary_id_type>("outflow_bid", 3, "The boundary id to use for the outflow");
37  params.addParam<boundary_id_type>(
38  "outer_wall_bid", 4, "The boundary id to use for the outer wall");
39  params.addParam<bool>(
40  "triangles", false, "If true, all the quadrilateral elements will be split into triangles");
41  params.addClassDescription("Creates a mesh for the Ringleb problem.");
42 
43  return params;
44 }
45 
47  : MooseMesh(parameters),
48  _gamma(getParam<Real>("gamma")),
49  _kmax(getParam<Real>("kmax")),
50  _kmin(getParam<Real>("kmin")),
51  _num_q_pts(getParam<int>("num_q_pts")),
52  _n_extra_q_pts(getParam<int>("n_extra_q_pts")),
53  _num_k_pts(getParam<int>("num_k_pts")),
54  _inflow_bid(getParam<boundary_id_type>("inflow_bid")),
55  _outflow_bid(getParam<boundary_id_type>("outflow_bid")),
56  _inner_wall_bid(getParam<boundary_id_type>("inner_wall_bid")),
57  _outer_wall_bid(getParam<boundary_id_type>("outer_wall_bid")),
58  _triangles(getParam<bool>("triangles"))
59 {
60 
61  // catch likely user errors
62  if (_kmax <= _kmin)
63  mooseError("RinglebMesh: kmax must be greater than kmin");
64 }
65 
66 std::unique_ptr<MooseMesh>
68 {
69  return libmesh_make_unique<RinglebMesh>(*this);
70 }
71 
72 std::vector<Real>
73 RinglebMesh::arhopj(const Real & gamma, const std::vector<Real> & q, const int & index)
74 {
75  std::vector<Real> values(4);
76  Real a = std::sqrt(1 - ((gamma - 1) / 2.) * std::pow(q[index], 2));
77  Real rho = std::pow(a, 2. / (gamma - 1));
78  Real p = (1. / gamma) * std::pow(a, 2 * gamma / (gamma - 1));
79  Real J = 1. / a + 1. / (3. * std::pow(a, 3)) + 1. / (5. * std::pow(a, 5)) -
80  0.5 * std::log((1 + a) / (1 - a));
81  values = {a, rho, p, J};
82  return values;
83 }
84 
85 std::vector<Real>
86 RinglebMesh::computexy(const std::vector<Real> values,
87  const int & i,
88  const int & index,
89  const std::vector<Real> & ks,
90  const std::vector<Real> & q)
91 {
92  std::vector<Real> xy(2);
93 
94  // Compute x(q,k)
95  xy[0] = 0.5 / values[1] * (2. / ks[i] / ks[i] - 1. / q[index] / q[index]) - 0.5 * values[3];
96 
97  // Compute the term that goes under the sqrt sign
98  // If 1 - (q/k)^2 is slightly negative, we make it zero.
99  Real sqrt_term = 1. - q[index] * q[index] / ks[i] / ks[i];
100  sqrt_term = std::max(sqrt_term, 0.);
101 
102  // Compute y(q,k)
103  xy[1] = 1. / (ks[i] * values[1] * q[index]) * std::sqrt(sqrt_term);
104 
105  return xy;
106 }
107 
108 void
110 {
111  MeshBase & mesh = getMesh();
112 
114  std::vector<std::vector<Node *>> stream_nodes(_num_k_pts);
115 
117  int current_node_id = 0;
118 
120  std::vector<Real> ks(_num_k_pts);
121  Real diff = (_kmax - _kmin) / (_num_k_pts - 1);
122  for (int i = 0; i < _num_k_pts; i++)
123  ks[i] = _kmin + i * diff;
124 
125  for (int i = 0; i < _num_k_pts; i++)
126  {
127  stream_nodes[i].resize(2 * (_num_q_pts + _n_extra_q_pts));
128 
130  std::vector<Real> q(_num_q_pts);
131  Real diffq = (ks[i] - 0.5) / (_num_q_pts - 1);
132  for (int j = 0; j < _num_q_pts; j++)
133  q[j] = 0.5 + j * diffq;
134 
136  for (int j = _num_q_pts; j < _num_q_pts + _n_extra_q_pts; j++)
137  {
138  std::vector<Real>::iterator it = q.end();
139  q.insert(--it, 0.3 * q[j - 2] + 0.7 * q[j - 1]);
140  }
141 
142  std::vector<Real> vals(4);
143  std::vector<Real> xy(2);
145  for (int j = 0; j < _num_q_pts + _n_extra_q_pts; j++)
146  {
147  // Compute the different parameters
148  vals = arhopj(_gamma, q, j);
149 
150  // Compute x and y
151  xy = computexy(vals, i, j, ks, q);
152 
153  // Create a node with (x,y) coordinates as it's on the upper part of the mesh
154  if (j != _num_q_pts + _n_extra_q_pts - 1)
155  stream_nodes[i][j] = mesh.add_point(Point(xy[0], xy[1]), current_node_id++);
156  }
157 
159  for (int j = _num_q_pts + _n_extra_q_pts; j < 2 * (_num_q_pts + _n_extra_q_pts); j++)
160  {
161  int index = 2 * (_num_q_pts + _n_extra_q_pts) - 1 - j;
162  // Compute the different parameters
163  vals = arhopj(_gamma, q, index);
164 
165  // Compute x and y
166  xy = computexy(vals, i, index, ks, q);
167 
168  // Create a node with (x,-y) coordinates as it's on the lower part of the mesh
169  stream_nodes[i][j] = mesh.add_point(Point(xy[0], -xy[1]), current_node_id++);
170  }
171  }
172 
174  for (int i = 0; i < _num_k_pts - 1; i++)
175  {
176  for (int j = 0; j < 2 * (_num_q_pts + _n_extra_q_pts) - 1; j++)
177  {
179  if (j != _num_q_pts + _n_extra_q_pts - 1 and j != _num_q_pts + _n_extra_q_pts - 2)
180  {
181  Elem * elem = mesh.add_elem(new Quad4);
182  elem->set_node(0) = stream_nodes[i][j];
183  elem->set_node(1) = stream_nodes[i][j + 1];
184  elem->set_node(2) = stream_nodes[i + 1][j + 1];
185  elem->set_node(3) = stream_nodes[i + 1][j];
186 
187  if (i == 0)
188  mesh.boundary_info->add_side(elem->id(), /*side=*/0, _outer_wall_bid);
189  if (j == 0)
190  mesh.boundary_info->add_side(elem->id(), /*side=*/3, _inflow_bid);
191  if (j == 2 * (_num_q_pts + _n_extra_q_pts) - 2)
192  mesh.boundary_info->add_side(elem->id(), /*side=*/1, _outflow_bid);
193  if (i == _num_k_pts - 2)
194  mesh.boundary_info->add_side(elem->id(), /*side=*/2, _inner_wall_bid);
195  }
196  else if (j == _num_q_pts + _n_extra_q_pts - 2)
197  {
198  Elem * elem = mesh.add_elem(new Quad4);
199  elem->set_node(0) = stream_nodes[i][j];
200  elem->set_node(1) = stream_nodes[i][j + 2];
201  elem->set_node(2) = stream_nodes[i + 1][j + 2];
202  elem->set_node(3) = stream_nodes[i + 1][j];
203 
204  if (i == 0)
205  mesh.boundary_info->add_side(elem->id(), /*side=*/0, _outer_wall_bid);
206  if (i == _num_k_pts - 2)
207  mesh.boundary_info->add_side(elem->id(), /*side=*/2, _inner_wall_bid);
208  }
209  }
210  }
211 
213  mesh.prepare_for_use();
214 
216  if (_triangles)
217  MeshTools::Modification::all_tri(mesh);
218 
220  mesh.boundary_info->sideset_name(_inflow_bid) = "inflow";
221  mesh.boundary_info->sideset_name(_outflow_bid) = "outflow";
222  mesh.boundary_info->sideset_name(_inner_wall_bid) = "inner_wall";
223  mesh.boundary_info->sideset_name(_outer_wall_bid) = "outer_wall";
224 }
RinglebMesh::safeClone
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:67
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
defineLegacyParams
defineLegacyParams(RinglebMesh)
InputParameters::addParam
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.
Definition: InputParameters.h:1198
RinglebMesh::arhopj
std::vector< Real > arhopj(const Real &gamma, const std::vector< Real > &q, const int &index)
Definition: RinglebMesh.C:73
RinglebMesh::_outflow_bid
const boundary_id_type _outflow_bid
Definition: RinglebMesh.h:71
registerMooseObject
registerMooseObject("MooseApp", RinglebMesh)
RinglebMesh
Mesh generated from parameters.
Definition: RinglebMesh.h:22
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
RinglebMesh::_kmin
const Real & _kmin
kmin corresponds to the outer wall
Definition: RinglebMesh.h:59
RinglebMesh::computexy
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:86
MooseMesh::getMesh
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2599
MooseMesh::elem
virtual Elem * elem(const dof_id_type i)
Various accessors (pointers/references) for Elem "i".
Definition: MooseMesh.C:2275
InputParameters::addClassDescription
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.
Definition: InputParameters.C:70
RinglebMesh::validParams
static InputParameters validParams()
Definition: RinglebMesh.C:21
RinglebMesh::buildMesh
virtual void buildMesh() override
Must be overridden by child classes.
Definition: RinglebMesh.C:109
MathUtils::pow
T pow(T x, int e)
Definition: MathUtils.h:44
RinglebMesh::_inner_wall_bid
const boundary_id_type _inner_wall_bid
Definition: RinglebMesh.h:71
RinglebMesh::_inflow_bid
const boundary_id_type _inflow_bid
The boundary ids to use for the ringleb mesh.
Definition: RinglebMesh.h:71
RinglebMesh::_num_k_pts
const int & _num_k_pts
how many points in the range k=(kmin, kmax).
Definition: RinglebMesh.h:68
RinglebMesh::_n_extra_q_pts
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:65
MooseMesh
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
RinglebMesh::_num_q_pts
const int & _num_q_pts
How many points to discretize the range q = (0.5, k) into.
Definition: RinglebMesh.h:62
RinglebMesh::_outer_wall_bid
const boundary_id_type _outer_wall_bid
Definition: RinglebMesh.h:71
RinglebMesh::_gamma
const Real & _gamma
Gamma.
Definition: RinglebMesh.h:50
RinglebMesh.h
InputParameters::addRequiredParam
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...
Definition: InputParameters.h:1176
MooseMesh::validParams
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
Definition: MooseMesh.C:65
RinglebMesh::RinglebMesh
RinglebMesh(const InputParameters &parameters)
Definition: RinglebMesh.C:46
RinglebMesh::_triangles
const bool & _triangles
This parameter, if true, allows to split the quadrilateral elements into triangular elements.
Definition: RinglebMesh.h:74
RinglebMesh::_kmax
const Real & _kmax
k is a streamline parameter, i.e.
Definition: RinglebMesh.h:56