https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SCMCoreMeshGeneratorBase.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#include "MooseApp.h"
13#include "MooseMeshUtils.h"
14#include "SubChannelMesh.h"
15
16#include "libmesh/mesh_modification.h"
17#include "libmesh/unstructured_mesh.h"
18
21{
23 params.addRequiredParam<std::vector<MeshGeneratorName>>(
24 "inputs",
25 "The SCM 1D assembly, duct, or 3D visualization assembly meshes that can be placed in the "
26 "core");
27 params.addRequiredParam<std::vector<std::vector<int>>>(
28 "pattern", "Core pattern of indices into 'inputs'; -1 marks an empty position.");
30 "assembly_pitch",
31 "assembly_pitch>0",
32 "Center-to-center distance between neighboring assembly positions [m]");
33 return params;
34}
35
37 : MeshGenerator(parameters),
38 _input_names(getParam<std::vector<MeshGeneratorName>>("inputs")),
39 _meshes(getMeshes("inputs")),
40 _pattern(getParam<std::vector<std::vector<int>>>("pattern")),
41 _assembly_pitch(getParam<Real>("assembly_pitch"))
42{
43 // Each SCM assembly and duct mesh generator stores its channel, gap and pin maps in the single
44 // SubChannelMesh, so with several assemblies only the data of the last generated one remains,
45 // and it refers to nodes of a mesh that is merged here. The SCM solver cannot use a core built
46 // from those generators until that data is stored per assembly. A core of 3D visualization
47 // assembly meshes is a plain [Mesh] and can be used in a run.
48 if (dynamic_cast<const SubChannelMesh *>(_mesh) && !_app.isParamSetByUser("mesh_only"))
49 mooseError("An SCM core mesh built from subchannel assembly or duct inputs can only be "
50 "generated with --mesh-only; solving on it is not supported yet.");
51}
52
53void
54SCMCoreMeshGeneratorBase::addAssembly(const int entry, const Point & center)
55{
56 if (entry == -1)
57 return;
58 if (entry < -1 || entry >= static_cast<int>(_input_names.size()))
59 paramError("pattern", "Entry ", entry, " is neither -1 nor a valid index into 'inputs'.");
60 _assemblies.emplace_back(entry, center);
61}
62
63std::unique_ptr<MeshBase>
65{
66 std::vector<bool> used(_input_names.size(), false);
67 for (const auto & [input, _] : _assemblies)
68 used[input] = true;
69 for (const auto i : index_range(_input_names))
70 if (!used[i])
71 paramWarning("inputs", "Input '", _input_names[i], "' is not used in 'pattern'.");
72
74
75 // The edge and corner subchannels of a 1D assembly are bounded by a duct wall, which the overlap
76 // check below also uses, whether or not a duct mesh is generated. A 3D visualization core has no
77 // duct generator, so the warning applies to 1D cores only.
78 if (dynamic_cast<const SubChannelMesh *>(_mesh))
79 for (const auto i : index_range(_input_names))
80 if (used[i] && !hasMeshProperty<bool>("duct_mesh", _input_names[i]))
82 "inputs",
83 "Input '",
84 _input_names[i],
85 "' has no duct mesh. Its edge and corner subchannels are still bounded by a "
86 "duct wall, which the overlap check also uses, but the wall does not appear in "
87 "the mesh. Use a duct mesh generator to include it.");
88
89 // All pairs are checked, not only neighbors, because an assembly next to an empty position may
90 // extend past its lattice cell into a farther occupied one. Every overlapping pair is reported at
91 // once so the user does not have to fix and rerun one pair at a time.
92 std::string overlaps;
93 for (const auto a : index_range(_assemblies))
94 for (const auto b : make_range(a + 1, _assemblies.size()))
95 {
96 const auto & [input_a, center_a] = _assemblies[a];
97 const auto & [input_b, center_b] = _assemblies[b];
98 if (overlap(input_a, input_b, center_b - center_a))
99 overlaps += "\n Assembly " + std::to_string(a) + " ('" + _input_names[input_a] +
100 "') and assembly " + std::to_string(b) + " ('" + _input_names[input_b] + "')";
101 }
102 if (!overlaps.empty())
103 paramError("assembly_pitch",
104 "The following assemblies overlap. Increase 'assembly_pitch' or use smaller "
105 "assemblies.",
106 overlaps);
107
108 std::vector<std::unique_ptr<MeshBase>> inputs;
109 for (const auto i : index_range(_meshes))
110 {
111 inputs.push_back(std::move(*_meshes[i]));
112 if (!inputs.back()->is_replicated())
113 paramError("inputs",
114 "Input '",
115 _input_names[i],
116 "' is not a replicated mesh. SCM core meshes require a replicated mesh; run "
117 "without --distributed-mesh.");
118 }
119
120 auto mesh = dynamic_pointer_cast<UnstructuredMesh>(buildMeshBaseObject());
121 mesh->set_spatial_dimension(3);
122
123 // Every subdomain and boundary of every placed assembly gets a new id and its name gets the
124 // assembly index as a suffix, so each assembly can be addressed by block or boundary
125 subdomain_id_type next_subdomain_id = 0;
126 boundary_id_type next_boundary_id = 0;
127 for (const auto k : index_range(_assemblies))
128 {
129 const auto & [input, center] = _assemblies[k];
130 auto assembly = dynamic_pointer_cast<UnstructuredMesh>(inputs[input]->clone());
131 const std::string suffix = "_" + std::to_string(k);
132
133 std::set<subdomain_id_type> subdomain_ids;
134 for (const auto * const elem : assembly->element_ptr_range())
135 subdomain_ids.insert(elem->subdomain_id());
136 std::map<subdomain_id_type, subdomain_id_type> subdomain_map;
137 const auto & old_subdomain_names = assembly->get_subdomain_name_map();
138 std::map<subdomain_id_type, std::string> subdomain_names;
139 for (const auto old_id : subdomain_ids)
140 {
141 subdomain_map[old_id] = next_subdomain_id;
142 const auto it = old_subdomain_names.find(old_id);
143 subdomain_names[next_subdomain_id] =
144 (it == old_subdomain_names.end() ? std::to_string(old_id) : it->second) + suffix;
145 ++next_subdomain_id;
146 }
147 assembly->set_subdomain_name_map() = subdomain_names;
148
149 if (assembly->has_elem_integer("assembly_id"))
150 paramError("inputs",
151 "Input '",
152 _input_names[input],
153 "' already has an 'assembly_id' extra element integer, which this mesh "
154 "generator would overwrite.");
155 const auto assembly_id_index = assembly->add_elem_integer("assembly_id");
156 for (auto * const elem : assembly->element_ptr_range())
157 {
158 elem->subdomain_id() = libmesh_map_find(subdomain_map, elem->subdomain_id());
159 elem->set_extra_integer(assembly_id_index, k);
160 }
161
162 auto & boundary_info = assembly->get_boundary_info();
163 const auto side_list = boundary_info.build_side_list();
164 const auto node_list = boundary_info.build_node_list();
165 const auto sideset_names = boundary_info.get_sideset_name_map();
166 const auto nodeset_names = boundary_info.get_nodeset_name_map();
167 std::map<boundary_id_type, boundary_id_type> boundary_map;
168 const auto map_boundary = [&boundary_map, &next_boundary_id](const boundary_id_type old_id)
169 {
170 const auto [it, inserted] = boundary_map.try_emplace(old_id, next_boundary_id);
171 if (inserted)
172 ++next_boundary_id;
173 return it->second;
174 };
175 for (const auto old_id : boundary_info.get_boundary_ids())
176 map_boundary(old_id);
177 for (const auto & [old_id, _] : sideset_names)
178 map_boundary(old_id);
179 for (const auto & [old_id, _] : nodeset_names)
180 map_boundary(old_id);
181
182 // SCM 1D assembly, duct, and 3D visualization assembly meshes carry only side and node
183 // boundaries, so the edge and shellface boundaries that clear() also drops are not restored
184 boundary_info.clear();
185 for (const auto & [elem_id, side, old_id] : side_list)
186 boundary_info.add_side(elem_id, side, libmesh_map_find(boundary_map, old_id));
187 for (const auto & [node_id, old_id] : node_list)
188 boundary_info.add_node(node_id, libmesh_map_find(boundary_map, old_id));
189 for (const auto & [old_id, old_name] : sideset_names)
190 boundary_info.sideset_name(libmesh_map_find(boundary_map, old_id)) = old_name + suffix;
191 for (const auto & [old_id, old_name] : nodeset_names)
192 boundary_info.nodeset_name(libmesh_map_find(boundary_map, old_id)) = old_name + suffix;
193
194 MeshTools::Modification::translate(*assembly, center(0), center(1), 0.0);
196 *mesh,
197 *assembly,
198 /*avoid_merging_subdomains=*/false,
199 /*avoid_merging_boundaries=*/false,
201 /*skip_preparation=*/true);
202 }
203
204 mesh->unset_is_prepared();
205 return dynamic_pointer_cast<MeshBase>(mesh);
206}
Point center
void ErrorVector unsigned int
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
MooseMesh *const _mesh
static InputParameters validParams()
std::unique_ptr< MeshBase > buildMeshBaseObject(unsigned int dim=libMesh::invalid_uint)
void paramWarning(const std::string &param, Args... args) const
void paramError(const std::string &param, Args... args) const
bool isParamSetByUser(const std::string &name) const
void mooseError(Args &&... args) const
MooseApp & _app
virtual bool overlap(unsigned int input_a, unsigned int input_b, const Point &offset) const =0
Whether the ducts of two inputs overlap when their centers are offset apart.
static InputParameters validParams()
virtual void readAssemblySizes()=0
Read the duct size metadata of every input.
std::vector< std::pair< unsigned int, Point > > _assemblies
Placed assemblies in pattern order: (index into the inputs, x-y center of the assembly)
std::unique_ptr< MeshBase > generate() override
SCMCoreMeshGeneratorBase(const InputParameters &parameters)
void addAssembly(int entry, const Point &center)
Check that a pattern entry is -1 or a valid input index and, if it is an index, place that input at c...
const std::vector< MeshGeneratorName > & _input_names
Names of the input SCM 1D assembly, duct, or 3D visualization assembly mesh generators.
const std::vector< std::unique_ptr< MeshBase > * > _meshes
Input meshes.
Base class for subchannel meshes.
const Parallel::Communicator & _communicator
MeshBase & mesh
void copyIntoMesh(MeshGenerator &mg, UnstructuredMesh &destination, const UnstructuredMesh &source, const bool avoid_merging_subdomains, const bool avoid_merging_boundaries, const Parallel::Communicator &communicator, const bool skip_preparation=false)