https://mooseframework.inl.gov
Loading...
Searching...
No Matches
RinglebMeshGenerator.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
11#include "CastUniquePointer.h"
12
13#include "libmesh/replicated_mesh.h"
14#include "libmesh/mesh_modification.h"
15#include "libmesh/face_quad4.h"
16#include "libmesh/face_tri3.h"
17
19
22{
24
25 params.addRequiredParam<Real>("gamma", "Gamma parameter");
26 params.addRequiredParam<Real>("kmax", "Value of k on the inner wall.");
27 params.addRequiredParam<Real>("kmin", "Value of k on the outer wall.");
28 params.addRequiredParam<int>("num_q_pts",
29 "How many points to discretize the range q = (0.5, k) into.");
30 params.addRequiredParam<int>("n_extra_q_pts",
31 "How many 'extra' points should be inserted in the final element"
32 " *in addition to* the equispaced q points.");
33 params.addRequiredParam<int>("num_k_pts", "How many points in the range k=(kmin, kmax).");
34 params.addParam<boundary_id_type>("inflow_bid", 1, "The boundary id to use for the inflow");
35 params.addParam<boundary_id_type>(
36 "inner_wall_bid", 2, "The boundary id to use for the inner wall");
37 params.addParam<boundary_id_type>("outflow_bid", 3, "The boundary id to use for the outflow");
38 params.addParam<boundary_id_type>(
39 "outer_wall_bid", 4, "The boundary id to use for the outer wall");
40 params.addParam<bool>(
41 "triangles", false, "If true, all the quadrilateral elements will be split into triangles");
42 params.addClassDescription("Creates a mesh for the Ringleb problem.");
43
44 return params;
45}
46
48 : MeshGenerator(parameters),
49 _gamma(getParam<Real>("gamma")),
50 _kmax(getParam<Real>("kmax")),
51 _kmin(getParam<Real>("kmin")),
52 _num_q_pts(getParam<int>("num_q_pts")),
53 _n_extra_q_pts(getParam<int>("n_extra_q_pts")),
54 _num_k_pts(getParam<int>("num_k_pts")),
55 _inflow_bid(getParam<boundary_id_type>("inflow_bid")),
56 _outflow_bid(getParam<boundary_id_type>("outflow_bid")),
57 _inner_wall_bid(getParam<boundary_id_type>("inner_wall_bid")),
58 _outer_wall_bid(getParam<boundary_id_type>("outer_wall_bid")),
59 _triangles(getParam<bool>("triangles"))
60{
61 declareMeshProperty("use_distributed_mesh", false);
62
63 // catch likely user errors
64 if (_kmax <= _kmin)
65 mooseError("RinglebMesh: kmax must be greater than kmin");
66}
67
68std::vector<Real>
69RinglebMeshGenerator::arhopj(const Real & gamma, const std::vector<Real> & q, const int & index)
70{
71 std::vector<Real> values(4);
72 Real a = std::sqrt(1 - ((gamma - 1) / 2.) * std::pow(q[index], 2));
73 Real rho = std::pow(a, 2. / (gamma - 1));
74 Real p = (1. / gamma) * std::pow(a, 2 * gamma / (gamma - 1));
75 Real J = 1. / a + 1. / (3. * std::pow(a, 3)) + 1. / (5. * std::pow(a, 5)) -
76 0.5 * std::log((1 + a) / (1 - a));
77 values = {a, rho, p, J};
78 return values;
79}
80
81std::vector<Real>
83 const int & i,
84 const int & index,
85 const std::vector<Real> & ks,
86 const std::vector<Real> & q)
87{
88 std::vector<Real> xy(2);
89
90 // Compute x(q,k)
91 xy[0] = 0.5 / values[1] * (2. / ks[i] / ks[i] - 1. / q[index] / q[index]) - 0.5 * values[3];
92
93 // Compute the term that goes under the sqrt sign
94 // If 1 - (q/k)^2 is slightly negative, we make it zero.
95 Real sqrt_term = 1. - q[index] * q[index] / ks[i] / ks[i];
96 sqrt_term = std::max(sqrt_term, 0.);
97
98 // Compute y(q,k)
99 xy[1] = 1. / (ks[i] * values[1] * q[index]) * std::sqrt(sqrt_term);
100
101 return xy;
102}
103
104std::unique_ptr<MeshBase>
106{
107 std::unique_ptr<ReplicatedMesh> mesh = buildReplicatedMesh(2);
108 BoundaryInfo & boundary_info = mesh->get_boundary_info();
109
111 std::vector<std::vector<Node *>> stream_nodes(_num_k_pts);
112
114 int current_node_id = 0;
115
117 std::vector<Real> ks(_num_k_pts);
118 Real diff = (_kmax - _kmin) / (_num_k_pts - 1);
119 for (int i = 0; i < _num_k_pts; i++)
120 ks[i] = _kmin + i * diff;
121
122 for (int i = 0; i < _num_k_pts; i++)
123 {
124 stream_nodes[i].resize(2 * (_num_q_pts + _n_extra_q_pts));
125
127 std::vector<Real> q(_num_q_pts);
128 Real diffq = (ks[i] - 0.5) / (_num_q_pts - 1);
129 for (int j = 0; j < _num_q_pts; j++)
130 q[j] = 0.5 + j * diffq;
131
133 for (int j = _num_q_pts; j < _num_q_pts + _n_extra_q_pts; j++)
134 {
135 std::vector<Real>::iterator it = q.end();
136 q.insert(--it, 0.3 * q[j - 2] + 0.7 * q[j - 1]);
137 }
138
139 std::vector<Real> vals(4);
140 std::vector<Real> xy(2);
142 for (int j = 0; j < _num_q_pts + _n_extra_q_pts; j++)
143 {
144 // Compute the different parameters
145 vals = arhopj(_gamma, q, j);
146
147 // Compute x and y
148 xy = computexy(vals, i, j, ks, q);
149
150 // Create a node with (x,y) coordinates as it's on the upper part of the mesh
151 if (j != _num_q_pts + _n_extra_q_pts - 1)
152 stream_nodes[i][j] = mesh->add_point(Point(xy[0], xy[1]), current_node_id++);
153 }
154
156 for (int j = _num_q_pts + _n_extra_q_pts; j < 2 * (_num_q_pts + _n_extra_q_pts); j++)
157 {
158 int index = 2 * (_num_q_pts + _n_extra_q_pts) - 1 - j;
159 // Compute the different parameters
160 vals = arhopj(_gamma, q, index);
161
162 // Compute x and y
163 xy = computexy(vals, i, index, ks, q);
164
165 // Create a node with (x,-y) coordinates as it's on the lower part of the mesh
166 stream_nodes[i][j] = mesh->add_point(Point(xy[0], -xy[1]), current_node_id++);
167 }
168 }
169
171 for (int i = 0; i < _num_k_pts - 1; i++)
172 {
173 for (int j = 0; j < 2 * (_num_q_pts + _n_extra_q_pts) - 1; j++)
174 {
176 if (j != _num_q_pts + _n_extra_q_pts - 1 and j != _num_q_pts + _n_extra_q_pts - 2)
177 {
178 Elem * elem = mesh->add_elem(new Quad4);
179 elem->set_node(0, stream_nodes[i][j]);
180 elem->set_node(1, stream_nodes[i][j + 1]);
181 elem->set_node(2, stream_nodes[i + 1][j + 1]);
182 elem->set_node(3, stream_nodes[i + 1][j]);
183
184 if (i == 0)
185 boundary_info.add_side(elem->id(), /*side=*/0, _outer_wall_bid);
186 if (j == 0)
187 boundary_info.add_side(elem->id(), /*side=*/3, _inflow_bid);
188 if (j == 2 * (_num_q_pts + _n_extra_q_pts) - 2)
189 boundary_info.add_side(elem->id(), /*side=*/1, _outflow_bid);
190 if (i == _num_k_pts - 2)
191 boundary_info.add_side(elem->id(), /*side=*/2, _inner_wall_bid);
192 }
193 else if (j == _num_q_pts + _n_extra_q_pts - 2)
194 {
195 Elem * elem = mesh->add_elem(new Quad4);
196 elem->set_node(0, stream_nodes[i][j]);
197 elem->set_node(1, stream_nodes[i][j + 2]);
198 elem->set_node(2, stream_nodes[i + 1][j + 2]);
199 elem->set_node(3, stream_nodes[i + 1][j]);
200
201 if (i == 0)
202 boundary_info.add_side(elem->id(), /*side=*/0, _outer_wall_bid);
203 if (i == _num_k_pts - 2)
204 boundary_info.add_side(elem->id(), /*side=*/2, _inner_wall_bid);
205 }
206 }
207 }
208
210 mesh->prepare_for_use();
211
213 if (_triangles)
214 MeshTools::Modification::all_tri(*mesh);
215
217 boundary_info.sideset_name(_inflow_bid) = "inflow";
218 boundary_info.sideset_name(_outflow_bid) = "outflow";
219 boundary_info.sideset_name(_inner_wall_bid) = "inner_wall";
220 boundary_info.sideset_name(_outer_wall_bid) = "outer_wall";
221
222 return dynamic_pointer_cast<MeshBase>(mesh);
223}
std::array< Real, 2 > values
Definition MortarUtils.C:52
registerMooseObject("MooseApp", RinglebMeshGenerator)
void ErrorVector unsigned int
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.
MeshGenerators are objects that can modify or add to an existing mesh.
std::unique_ptr< ReplicatedMesh > buildReplicatedMesh(unsigned int dim=libMesh::invalid_uint)
Build a replicated mesh.
static InputParameters validParams()
T & declareMeshProperty(const std::string &data_name, Args &&... args)
Methods for writing out attributes to the mesh meta-data store, which can be retrieved from most othe...
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
Generates a mesh given all the parameters.
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)
RinglebMeshGenerator(const InputParameters &parameters)
const int & _n_extra_q_pts
how many "extra" points should be inserted in the nearest element from the horizontal in additi /// o...
const bool & _triangles
This parameter, if true, allows to split the quadrilateral elements into triangular elements.
const Real & _gamma
Gamma.
const boundary_id_type _outer_wall_bid
const Real & _kmax
k is a streamline parameter, i.e.
const boundary_id_type _inner_wall_bid
std::vector< Real > arhopj(const Real &gamma, const std::vector< Real > &q, const int &index)
const boundary_id_type _inflow_bid
The boundary ids to use for the ringleb mesh.
const Real & _kmin
kmin corresponds to the outer wall
const boundary_id_type _outflow_bid
const int & _num_k_pts
how many points in the range k=(kmin, kmax).
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
const int & _num_q_pts
How many points to discretize the range q = (0.5, k) into.
static InputParameters validParams()
MeshBase & mesh
MooseUnits pow(const MooseUnits &, int)
Definition Units.C:537