https://mooseframework.inl.gov
Loading...
Searching...
No Matches
RinglebMesh.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 "RinglebMesh.h"
11
12#include "MooseApp.h"
13
14#include "libmesh/face_quad4.h"
15#include "libmesh/face_tri3.h"
16#include "libmesh/mesh_modification.h"
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
66std::unique_ptr<MooseMesh>
68{
69 return _app.getFactory().copyConstruct(*this);
70}
71
72std::vector<Real>
73RinglebMesh::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
85std::vector<Real>
86RinglebMesh::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
108void
110{
111 MeshBase & mesh = getMesh();
112 BoundaryInfo & boundary_info = mesh.get_boundary_info();
113
115 std::vector<std::vector<Node *>> stream_nodes(_num_k_pts);
116
118 int current_node_id = 0;
119
121 std::vector<Real> ks(_num_k_pts);
122 Real diff = (_kmax - _kmin) / (_num_k_pts - 1);
123 for (int i = 0; i < _num_k_pts; i++)
124 ks[i] = _kmin + i * diff;
125
126 for (int i = 0; i < _num_k_pts; i++)
127 {
128 stream_nodes[i].resize(2 * (_num_q_pts + _n_extra_q_pts));
129
131 std::vector<Real> q(_num_q_pts);
132 Real diffq = (ks[i] - 0.5) / (_num_q_pts - 1);
133 for (int j = 0; j < _num_q_pts; j++)
134 q[j] = 0.5 + j * diffq;
135
137 for (int j = _num_q_pts; j < _num_q_pts + _n_extra_q_pts; j++)
138 {
139 std::vector<Real>::iterator it = q.end();
140 q.insert(--it, 0.3 * q[j - 2] + 0.7 * q[j - 1]);
141 }
142
143 std::vector<Real> vals(4);
144 std::vector<Real> xy(2);
146 for (int j = 0; j < _num_q_pts + _n_extra_q_pts; j++)
147 {
148 // Compute the different parameters
149 vals = arhopj(_gamma, q, j);
150
151 // Compute x and y
152 xy = computexy(vals, i, j, ks, q);
153
154 // Create a node with (x,y) coordinates as it's on the upper part of the mesh
155 if (j != _num_q_pts + _n_extra_q_pts - 1)
156 stream_nodes[i][j] = mesh.add_point(Point(xy[0], xy[1]), current_node_id++);
157 }
158
160 for (int j = _num_q_pts + _n_extra_q_pts; j < 2 * (_num_q_pts + _n_extra_q_pts); j++)
161 {
162 int index = 2 * (_num_q_pts + _n_extra_q_pts) - 1 - j;
163 // Compute the different parameters
164 vals = arhopj(_gamma, q, index);
165
166 // Compute x and y
167 xy = computexy(vals, i, index, ks, q);
168
169 // Create a node with (x,-y) coordinates as it's on the lower part of the mesh
170 stream_nodes[i][j] = mesh.add_point(Point(xy[0], -xy[1]), current_node_id++);
171 }
172 }
173
175 for (int i = 0; i < _num_k_pts - 1; i++)
176 {
177 for (int j = 0; j < 2 * (_num_q_pts + _n_extra_q_pts) - 1; j++)
178 {
180 if (j != _num_q_pts + _n_extra_q_pts - 1 and j != _num_q_pts + _n_extra_q_pts - 2)
181 {
182 Elem * elem = mesh.add_elem(new Quad4);
183 elem->set_node(0, stream_nodes[i][j]);
184 elem->set_node(1, stream_nodes[i][j + 1]);
185 elem->set_node(2, stream_nodes[i + 1][j + 1]);
186 elem->set_node(3, stream_nodes[i + 1][j]);
187
188 if (i == 0)
189 boundary_info.add_side(elem->id(), /*side=*/0, _outer_wall_bid);
190 if (j == 0)
191 boundary_info.add_side(elem->id(), /*side=*/3, _inflow_bid);
192 if (j == 2 * (_num_q_pts + _n_extra_q_pts) - 2)
193 boundary_info.add_side(elem->id(), /*side=*/1, _outflow_bid);
194 if (i == _num_k_pts - 2)
195 boundary_info.add_side(elem->id(), /*side=*/2, _inner_wall_bid);
196 }
197 else if (j == _num_q_pts + _n_extra_q_pts - 2)
198 {
199 Elem * elem = mesh.add_elem(new Quad4);
200 elem->set_node(0, stream_nodes[i][j]);
201 elem->set_node(1, stream_nodes[i][j + 2]);
202 elem->set_node(2, stream_nodes[i + 1][j + 2]);
203 elem->set_node(3, stream_nodes[i + 1][j]);
204
205 if (i == 0)
206 boundary_info.add_side(elem->id(), /*side=*/0, _outer_wall_bid);
207 if (i == _num_k_pts - 2)
208 boundary_info.add_side(elem->id(), /*side=*/2, _inner_wall_bid);
209 }
210 }
211 }
212
213 // We just created this mesh from scratch, and we're not in the mesh
214 // generator system that will handle flagged preparation
215 // requirements later, so we need a full prepare_for_use() here.
216 mesh.prepare_for_use();
217
219 if (_triangles)
220 MeshTools::Modification::all_tri(mesh);
221
223 boundary_info.sideset_name(_inflow_bid) = "inflow";
224 boundary_info.sideset_name(_outflow_bid) = "outflow";
225 boundary_info.sideset_name(_inner_wall_bid) = "inner_wall";
226 boundary_info.sideset_name(_outer_wall_bid) = "outer_wall";
227}
std::array< Real, 2 > values
Definition MortarUtils.C:52
registerMooseObject("MooseApp", RinglebMesh)
void ErrorVector unsigned int
std::unique_ptr< T > copyConstruct(const T &object)
Copy constructs the object object.
Definition Factory.h:358
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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...
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.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition MooseApp.h:407
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
virtual Elem * elem(const dof_id_type i)
Various accessors (pointers/references) for Elem "i".
Definition MooseMesh.C:3200
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3549
static InputParameters validParams()
Typical "Moose-style" constructor and copy constructor.
Definition MooseMesh.C:83
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
Mesh generated from parameters.
Definition RinglebMesh.h:18
const boundary_id_type _inner_wall_bid
Definition RinglebMesh.h:66
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
static InputParameters validParams()
Definition RinglebMesh.C:21
const int & _num_k_pts
how many points in the range k=(kmin, kmax).
Definition RinglebMesh.h:63
const Real & _kmax
k is a streamline parameter, i.e.
Definition RinglebMesh.h:51
const Real & _gamma
Gamma.
Definition RinglebMesh.h:45
RinglebMesh(const InputParameters &parameters)
Definition RinglebMesh.C:46
const bool & _triangles
This parameter, if true, allows to split the quadrilateral elements into triangular elements.
Definition RinglebMesh.h:69
const Real & _kmin
kmin corresponds to the outer wall
Definition RinglebMesh.h:54
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
virtual void buildMesh() override
Must be overridden by child classes.
std::vector< Real > arhopj(const Real &gamma, const std::vector< Real > &q, const int &index)
Definition RinglebMesh.C:73
const int & _num_q_pts
How many points to discretize the range q = (0.5, k) into.
Definition RinglebMesh.h:57
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
const boundary_id_type _outflow_bid
Definition RinglebMesh.h:66
const boundary_id_type _outer_wall_bid
Definition RinglebMesh.h:66
const boundary_id_type _inflow_bid
The boundary ids to use for the ringleb mesh.
Definition RinglebMesh.h:66
MeshBase & mesh
MooseUnits pow(const MooseUnits &, int)
Definition Units.C:537