Line data Source code
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 "ConcentricCircleGeneratorBase.h"
11 :
12 : InputParameters
13 5982 : ConcentricCircleGeneratorBase::validParams()
14 : {
15 5982 : InputParameters params = PolygonMeshGeneratorBase::validParams();
16 11964 : params.addRangeCheckedParam<std::vector<Real>>(
17 : "ring_radii", "ring_radii>0", "Radii of major concentric circles (rings).");
18 11964 : params.addRangeCheckedParam<std::vector<unsigned int>>(
19 : "ring_intervals",
20 : "ring_intervals>0",
21 : "Number of radial mesh intervals within each major concentric circle excluding their "
22 : "boundary layers.");
23 11964 : params.addRangeCheckedParam<std::vector<Real>>(
24 : "ring_radial_biases",
25 : "ring_radial_biases>0",
26 : "Values used to create biasing in radial meshing for ring regions.");
27 11964 : params.addRangeCheckedParam<std::vector<Real>>(
28 : "ring_inner_boundary_layer_widths",
29 : "ring_inner_boundary_layer_widths>=0",
30 : "Widths of each ring regions that are assigned to be each ring's inner boundary layers.");
31 11964 : params.addParam<std::vector<unsigned int>>(
32 : "ring_inner_boundary_layer_intervals",
33 : "Number of radial intervals of the rings' inner boundary layers");
34 11964 : params.addRangeCheckedParam<std::vector<Real>>(
35 : "ring_inner_boundary_layer_biases",
36 : "ring_inner_boundary_layer_biases>0",
37 : "Growth factors used for mesh biasing of the rings' inner boundary layers.");
38 11964 : params.addRangeCheckedParam<std::vector<Real>>(
39 : "ring_outer_boundary_layer_widths",
40 : "ring_outer_boundary_layer_widths>=0",
41 : "Widths of each ring regions that are assigned to be each ring's outer boundary layers.");
42 11964 : params.addParam<std::vector<unsigned int>>(
43 : "ring_outer_boundary_layer_intervals",
44 : "Number of radial intervals of the rings' outer boundary layers");
45 11964 : params.addRangeCheckedParam<std::vector<Real>>(
46 : "ring_outer_boundary_layer_biases",
47 : "ring_outer_boundary_layer_biases>0",
48 : "Growth factors used for mesh biasing of the rings' outer boundary layers.");
49 11964 : params.addParam<std::vector<subdomain_id_type>>(
50 : "ring_block_ids", "Optional customized block ids for each ring geometry block.");
51 11964 : params.addParam<std::vector<SubdomainName>>(
52 : "ring_block_names", "Optional customized block names for each ring geometry block.");
53 11964 : params.addParam<bool>("preserve_volumes",
54 11964 : true,
55 : "Volume of concentric circles can be preserved using this function.");
56 11964 : params.addParam<subdomain_id_type>("block_id_shift", 0, "Integer used to shift block IDs.");
57 11964 : params.addParam<bool>("create_inward_interface_boundaries",
58 11964 : false,
59 : "Whether the inward interface boundaries are created.");
60 11964 : params.addParam<bool>("create_outward_interface_boundaries",
61 11964 : true,
62 : "Whether the outward interface boundaries are created.");
63 11964 : params.addParam<boundary_id_type>(
64 11964 : "interface_boundary_id_shift", 0, "Integer used to shift interface boundary IDs.");
65 11964 : params.addParam<bool>("generate_side_specific_boundaries",
66 11964 : false,
67 : "whether the side-specific external boundaries are generated or not");
68 11964 : params.addRangeCheckedParam<boundary_id_type>("external_boundary_id",
69 : "external_boundary_id>0",
70 : "Optional customized external boundary id.");
71 11964 : params.addParam<BoundaryName>(
72 : "external_boundary_name", "", "Optional customized external boundary name.");
73 :
74 11964 : MooseEnum tri_elem_type("TRI3 TRI6 TRI7", "TRI3");
75 11964 : params.addParam<MooseEnum>(
76 : "tri_element_type", tri_elem_type, "Type of the triangular elements to be generated.");
77 11964 : MooseEnum quad_elem_type("QUAD4 QUAD8 QUAD9", "QUAD4");
78 11964 : params.addParam<MooseEnum>(
79 : "quad_element_type", quad_elem_type, "Type of the quadrilateral elements to be generated.");
80 :
81 11964 : params.addParam<std::vector<std::string>>(
82 : "inward_interface_boundary_names",
83 : "Optional customized boundary names for the internal inward interfaces between block.");
84 11964 : params.addParam<std::vector<std::string>>(
85 : "outward_interface_boundary_names",
86 : "Optional customized boundary names for the internal outward interfaces between block.");
87 :
88 11964 : params.addParamNamesToGroup(
89 : "ring_block_ids ring_block_names external_boundary_id external_boundary_name "
90 : "inward_interface_boundary_names outward_interface_boundary_names "
91 : "block_id_shift create_inward_interface_boundaries create_outward_interface_boundaries "
92 : "interface_boundary_id_shift generate_side_specific_boundaries",
93 : "Customized Subdomain/Boundary");
94 11964 : params.addParamNamesToGroup("ring_intervals", "General Mesh Density");
95 11964 : params.addParamNamesToGroup(
96 : "ring_radial_biases ring_inner_boundary_layer_biases ring_inner_boundary_layer_widths "
97 : "ring_inner_boundary_layer_intervals ring_outer_boundary_layer_biases "
98 : "ring_outer_boundary_layer_widths ring_outer_boundary_layer_intervals ",
99 : "Mesh Boundary Layers and Biasing Options");
100 :
101 5982 : params.addClassDescription("This ConcentricCircleGeneratorBase object is a base class to be "
102 : "inherited for mesh generators that involve concentric circles.");
103 5982 : return params;
104 5982 : }
105 :
106 3047 : ConcentricCircleGeneratorBase::ConcentricCircleGeneratorBase(const InputParameters & parameters)
107 : : PolygonMeshGeneratorBase(parameters),
108 8486 : _ring_radii(isParamValid("ring_radii") ? getParam<std::vector<Real>>("ring_radii")
109 : : std::vector<Real>()),
110 10878 : _ring_intervals(isParamValid("ring_intervals")
111 3047 : ? getParam<std::vector<unsigned int>>("ring_intervals")
112 : : std::vector<unsigned int>()),
113 6120 : _ring_radial_biases(isParamValid("ring_radial_biases")
114 3047 : ? getParam<std::vector<Real>>("ring_radial_biases")
115 3047 : : std::vector<Real>(_ring_intervals.size(), 1.0)),
116 9265 : _ring_inner_boundary_layer_params(
117 3047 : {isParamValid("ring_inner_boundary_layer_widths")
118 3047 : ? getParam<std::vector<Real>>("ring_inner_boundary_layer_widths")
119 3023 : : std::vector<Real>(_ring_intervals.size(), 0.0),
120 : std::vector<Real>(),
121 6094 : isParamValid("ring_inner_boundary_layer_intervals")
122 3047 : ? getParam<std::vector<unsigned int>>("ring_inner_boundary_layer_intervals")
123 3027 : : std::vector<unsigned int>(_ring_intervals.size(), 0),
124 6094 : isParamValid("ring_inner_boundary_layer_biases")
125 3047 : ? getParam<std::vector<Real>>("ring_inner_boundary_layer_biases")
126 3047 : : std::vector<Real>(_ring_intervals.size(), 0.0)}),
127 9269 : _ring_outer_boundary_layer_params(
128 3047 : {isParamValid("ring_outer_boundary_layer_widths")
129 3047 : ? getParam<std::vector<Real>>("ring_outer_boundary_layer_widths")
130 3023 : : std::vector<Real>(_ring_intervals.size(), 0.0),
131 : std::vector<Real>(),
132 6094 : isParamValid("ring_outer_boundary_layer_intervals")
133 3047 : ? getParam<std::vector<unsigned int>>("ring_outer_boundary_layer_intervals")
134 3025 : : std::vector<unsigned int>(_ring_intervals.size(), 0),
135 6094 : isParamValid("ring_outer_boundary_layer_biases")
136 3047 : ? getParam<std::vector<Real>>("ring_outer_boundary_layer_biases")
137 3047 : : std::vector<Real>(_ring_intervals.size(), 0.0)}),
138 9818 : _ring_block_ids(isParamValid("ring_block_ids")
139 3047 : ? getParam<std::vector<subdomain_id_type>>("ring_block_ids")
140 : : std::vector<subdomain_id_type>()),
141 9764 : _ring_block_names(isParamValid("ring_block_names")
142 3047 : ? getParam<std::vector<SubdomainName>>("ring_block_names")
143 : : std::vector<SubdomainName>()),
144 6094 : _preserve_volumes(getParam<bool>("preserve_volumes")),
145 6094 : _block_id_shift(getParam<subdomain_id_type>("block_id_shift")),
146 6094 : _create_inward_interface_boundaries(getParam<bool>("create_inward_interface_boundaries")),
147 6094 : _create_outward_interface_boundaries(getParam<bool>("create_outward_interface_boundaries")),
148 6094 : _interface_boundary_id_shift(getParam<boundary_id_type>("interface_boundary_id_shift")),
149 6094 : _generate_side_specific_boundaries(getParam<bool>("generate_side_specific_boundaries")),
150 7415 : _external_boundary_id(isParamValid("external_boundary_id")
151 5689 : ? getParam<boundary_id_type>("external_boundary_id")
152 : : 0),
153 3047 : _external_boundary_name(getParam<BoundaryName>("external_boundary_name")),
154 3059 : _inward_interface_boundary_names(
155 3047 : isParamValid("inward_interface_boundary_names")
156 3047 : ? getParam<std::vector<std::string>>("inward_interface_boundary_names")
157 : : std::vector<std::string>()),
158 3135 : _outward_interface_boundary_names(
159 3047 : isParamValid("outward_interface_boundary_names")
160 3047 : ? getParam<std::vector<std::string>>("outward_interface_boundary_names")
161 : : std::vector<std::string>()),
162 6094 : _tri_elem_type(getParam<MooseEnum>("tri_element_type").template getEnum<TRI_ELEM_TYPE>()),
163 9141 : _quad_elem_type(getParam<MooseEnum>("quad_element_type").template getEnum<QUAD_ELEM_TYPE>())
164 : {
165 : // Customized interface boundary id/name related error messages
166 3047 : if (!_create_inward_interface_boundaries && _inward_interface_boundary_names.size() > 0)
167 4 : paramError("create_inward_interface_boundaries",
168 : "If set false, 'inward_interface_boundary_names' "
169 : "should not be provided as they are not used.");
170 3043 : if (!_create_outward_interface_boundaries && _outward_interface_boundary_names.size() > 0)
171 4 : paramError("create_outward_interface_boundaries",
172 : "If set false, 'outward_interface_boundary_names' "
173 : "should not be provided as they are not used.");
174 3039 : if (!_create_outward_interface_boundaries && !_create_inward_interface_boundaries &&
175 1067 : _interface_boundary_id_shift != 0)
176 4 : paramError("interface_boundary_id_shift",
177 : "this parameter should not be set if no interface boundaries are created.");
178 :
179 : // Rings related error messages
180 3035 : if (_ring_radii.size() != _ring_intervals.size())
181 4 : paramError("ring_radii", "This parameter and ring_intervals must have the same length.");
182 3031 : if (_ring_radii.size() != _ring_radial_biases.size())
183 4 : paramError("ring_radii", "This parameter and ring_radial_biases must have the same length.");
184 3920 : for (unsigned int i = 1; i < _ring_intervals.size(); i++)
185 897 : if (_ring_radii[i] <= _ring_radii[i - 1])
186 4 : paramError("ring_radii", "This parameter must be strictly ascending.");
187 3021 : if (_ring_radii.size() != _ring_inner_boundary_layer_params.widths.size() ||
188 3021 : _ring_radii.size() != _ring_inner_boundary_layer_params.intervals.size() ||
189 3021 : _ring_radii.size() != _ring_inner_boundary_layer_params.biases.size() ||
190 3021 : _ring_radii.size() != _ring_outer_boundary_layer_params.widths.size() ||
191 6044 : _ring_radii.size() != _ring_outer_boundary_layer_params.intervals.size() ||
192 : _ring_radii.size() != _ring_outer_boundary_layer_params.biases.size())
193 2 : paramError("ring_radii",
194 : "The inner and outer ring boundary layer parameters must have the same sizes as "
195 : "ring_radii.");
196 3021 : }
197 :
198 : void
199 2689 : ConcentricCircleGeneratorBase::assignInterfaceBoundaryNames(ReplicatedMesh & mesh) const
200 : {
201 2689 : if (!_inward_interface_boundary_names.empty())
202 : {
203 0 : for (unsigned int i = 0; i < _inward_interface_boundary_names.size(); i++)
204 : {
205 0 : mesh.get_boundary_info().sideset_name(i * 2 + 2 + _interface_boundary_id_shift) =
206 : _inward_interface_boundary_names[i];
207 0 : mesh.get_boundary_info().nodeset_name(i * 2 + 2 + _interface_boundary_id_shift) =
208 : _inward_interface_boundary_names[i];
209 : }
210 : }
211 2689 : if (!_outward_interface_boundary_names.empty())
212 : {
213 108 : for (unsigned int i = 0; i < _outward_interface_boundary_names.size(); i++)
214 : {
215 72 : mesh.get_boundary_info().sideset_name(i * 2 + 1 + _interface_boundary_id_shift) =
216 : _outward_interface_boundary_names[i];
217 72 : mesh.get_boundary_info().nodeset_name(i * 2 + 1 + _interface_boundary_id_shift) =
218 : _outward_interface_boundary_names[i];
219 : }
220 : }
221 2689 : }
222 :
223 : void
224 2691 : ConcentricCircleGeneratorBase::assignBlockIdsNames(ReplicatedMesh & mesh,
225 : std::vector<subdomain_id_type> & block_ids_old,
226 : std::vector<subdomain_id_type> & block_ids_new,
227 : std::vector<SubdomainName> & block_names,
228 : const std::string & generator_name) const
229 : {
230 2691 : if (block_ids_old.size() != block_ids_new.size() || block_ids_old.size() != block_names.size())
231 0 : mooseError("In ",
232 : generator_name,
233 : " ",
234 0 : _name,
235 : ": block_ids_old, block_ids_new and block_names must have the same size.");
236 :
237 6771 : for (auto it = block_names.begin(); it != block_names.end() - 1; it++)
238 : {
239 4082 : auto it_tmp = std::find(block_names.begin(), it + 1, *(it + 1));
240 4082 : if (it_tmp != it + 1 && block_ids_new[std::distance(block_names.begin(), it + 1)] !=
241 227 : block_ids_new[std::distance(block_names.begin(), it_tmp)])
242 2 : mooseError("In ",
243 : generator_name,
244 : " ",
245 2 : _name,
246 : ": blocks with different ids cannot have the same block name.");
247 : }
248 401248 : for (const auto & elem : mesh.element_ptr_range())
249 445262 : for (unsigned i = 0; i < block_ids_old.size(); ++i)
250 445262 : if (elem->subdomain_id() == block_ids_old[i])
251 : {
252 197935 : elem->subdomain_id() = block_ids_new[i];
253 197935 : break;
254 2689 : }
255 9458 : for (unsigned i = 0; i < block_ids_new.size(); ++i)
256 6769 : mesh.subdomain_name(block_ids_new[i]) = block_names[i];
257 2689 : }
258 :
259 : void
260 2096 : ConcentricCircleGeneratorBase::ringBlockIdsNamesPreparer(
261 : unsigned int & block_counter,
262 : unsigned int & ring_block_num,
263 : std::vector<subdomain_id_type> & block_ids_old,
264 : std::vector<subdomain_id_type> & block_ids_new,
265 : std::vector<SubdomainName> & block_names) const
266 : {
267 2096 : if (_ring_intervals.front() == 1)
268 1294 : ring_block_num = _ring_intervals.size();
269 : else
270 : {
271 802 : ring_block_num = _ring_intervals.size() + 1;
272 802 : block_ids_old.push_back(_block_id_shift + 1);
273 838 : block_ids_new.push_back(_ring_block_ids.empty() ? block_ids_old.back()
274 : : _ring_block_ids.front());
275 802 : block_names.push_back(_ring_block_names.empty()
276 1604 : ? (SubdomainName)std::to_string(block_ids_new.back())
277 : : _ring_block_names.front());
278 802 : block_counter++;
279 : }
280 4955 : for (unsigned int i = ring_block_num - _ring_intervals.size(); i < ring_block_num; i++)
281 : {
282 2859 : block_ids_old.push_back(_block_id_shift + 1 + i);
283 3621 : block_ids_new.push_back(_ring_block_ids.empty() ? block_ids_old.back() : _ring_block_ids[i]);
284 2859 : block_names.push_back(_ring_block_names.empty()
285 5718 : ? (SubdomainName)std::to_string(block_ids_new.back())
286 2025 : : _ring_block_names[i]);
287 2859 : block_counter++;
288 : }
289 2096 : }
|