forked from idaholab/moose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding reporting ID for hexagonal lattice, refs idaholab#19217
- Loading branch information
Showing
11 changed files
with
535 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
modules/reactor/include/meshgenerators/HexIDPatternedMeshGenerator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#pragma once | ||
|
||
#include "PatternedHexMeshGenerator.h" | ||
#include "MooseEnum.h" | ||
#include "MeshMetaDataInterface.h" | ||
|
||
/** | ||
* Generates patterned hexagonal meshes with a reporting ID | ||
*/ | ||
class HexIDPatternedMeshGenerator : public PatternedHexMeshGenerator | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
HexIDPatternedMeshGenerator(const InputParameters & parameters); | ||
|
||
std::unique_ptr<MeshBase> generate() override; | ||
|
||
protected: | ||
/// assign IDs for each component in lattice in sequential order | ||
std::vector<dof_id_type> getCellwiseIntegerIDs() const; | ||
/// assign IDs for each input component type | ||
std::vector<dof_id_type> getPatternIntegerIDs() const; | ||
/// Assign IDs based on user-defined mapping defined in id_pattern | ||
std::vector<dof_id_type> getManualIntegerIDs() const; | ||
/// get list of block IDs in input mesh cells | ||
std::set<SubdomainID> getCellBlockIDs() const; | ||
/// get list of block IDs for duck regions | ||
std::map<SubdomainID, unsigned int> getDuckBlockIDs(std::unique_ptr<MeshBase> & mesh, | ||
std::set<SubdomainID> & blks) const; | ||
/// name of integer ID | ||
const std::string _element_id_name; | ||
/// integer ID assignment type | ||
const std::string _assign_type; | ||
/// flag to indicate if exclude_id is defined | ||
const bool _use_exclude_id; | ||
/// flag to indicate if exclude_id is used for each input | ||
std::vector<bool> _exclude_ids; | ||
/// hold integer ID for each input pattern cell | ||
std::vector<std::vector<dof_id_type>> _id_pattern; | ||
}; |
217 changes: 217 additions & 0 deletions
217
modules/reactor/src/meshgenerators/HexIDPatternedMeshGenerator.C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
#include "PatternedHexMeshGenerator.h" | ||
#include "HexIDPatternedMeshGenerator.h" | ||
|
||
registerMooseObject("ReactorApp", HexIDPatternedMeshGenerator); | ||
|
||
defineLegacyParams(HexIDPatternedMeshGenerator); | ||
|
||
InputParameters | ||
HexIDPatternedMeshGenerator::validParams() | ||
{ | ||
InputParameters params = PatternedHexMeshGenerator::validParams(); | ||
params.addRequiredParam<std::string>("id_name", "Reporting_id_name"); | ||
params.addParam<std::vector<MeshGeneratorName>>( | ||
"exclude_id", "Name of inputs to be excluded in ID generation."); | ||
MooseEnum option("cell pattern manual", "cell"); | ||
params.addParam<MooseEnum>("assign_type", option, "Type of integer id assignment"); | ||
params.addParam<std::vector<std::vector<dof_id_type>>>( | ||
"id_pattern", | ||
"User-defined element IDs. A double-indexed array starting with the upper-left corner"); | ||
params.addClassDescription("This HexIDPatternedMeshGenerator source code is to generate " | ||
"patterned hexagonal meshes with Reporting ID"); | ||
return params; | ||
} | ||
|
||
HexIDPatternedMeshGenerator::HexIDPatternedMeshGenerator(const InputParameters & parameters) | ||
: PatternedHexMeshGenerator(parameters), | ||
_element_id_name(getParam<std::string>("id_name")), | ||
_assign_type(getParam<MooseEnum>("assign_type")), | ||
_use_exclude_id(isParamValid("exclude_id")) | ||
{ | ||
if (_use_exclude_id && _assign_type != "cell") | ||
paramError("exclude_id", "works only when \"assign_type\" is equal 'cell'"); | ||
if (!isParamValid("id_pattern") && _assign_type == "manual") | ||
paramError("id_pattern", "required when \"assign_type\" is equal to 'manual'"); | ||
|
||
if (_assign_type == "manual") | ||
_id_pattern = getParam<std::vector<std::vector<dof_id_type>>>("id_pattern"); | ||
_exclude_ids.resize(_input_names.size()); | ||
if (_use_exclude_id) | ||
{ | ||
std::vector<MeshGeneratorName> exclude_id_name = | ||
getParam<std::vector<MeshGeneratorName>>("exclude_id"); | ||
for (unsigned int i = 0; i < _input_names.size(); ++i) | ||
{ | ||
_exclude_ids[i] = false; | ||
for (auto input_name : exclude_id_name) | ||
if (_input_names[i] == input_name) | ||
{ | ||
_exclude_ids[i] = true; | ||
break; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
for (unsigned int i = 0; i < _input_names.size(); ++i) | ||
_exclude_ids[i] = false; | ||
} | ||
} | ||
|
||
std::unique_ptr<MeshBase> | ||
HexIDPatternedMeshGenerator::generate() | ||
{ | ||
auto mesh = PatternedHexMeshGenerator::generate(); | ||
std::vector<dof_id_type> integer_ids; | ||
if (_assign_type == "cell") | ||
integer_ids = getCellwiseIntegerIDs(); | ||
else if (_assign_type == "pattern") | ||
integer_ids = getPatternIntegerIDs(); | ||
else if (_assign_type == "manual") | ||
integer_ids = getManualIntegerIDs(); | ||
|
||
std::set<SubdomainID> blks = getCellBlockIDs(); | ||
unsigned int duct_boundary_id = *std::max_element(integer_ids.begin(), integer_ids.end()) + 1; | ||
|
||
std::map<SubdomainID, unsigned int> blks_duct = getDuckBlockIDs(mesh, blks); | ||
|
||
unsigned int extra_id_index = mesh->add_elem_integer(_element_id_name); | ||
|
||
unsigned int i = 0; | ||
unsigned int id = integer_ids[i]; | ||
unsigned old_id = id; | ||
for (auto elem : mesh->element_ptr_range()) | ||
{ | ||
auto blk = elem->subdomain_id(); | ||
auto it = blks.find(blk); | ||
if (it == blks.end()) | ||
{ | ||
if (_has_assembly_duct) | ||
{ | ||
auto it2 = blks_duct.find(blk); | ||
if (it2 == blks_duct.end()) | ||
elem->set_extra_integer(extra_id_index, old_id); | ||
else | ||
elem->set_extra_integer(extra_id_index, duct_boundary_id + it2->second); | ||
} | ||
else | ||
elem->set_extra_integer(extra_id_index, old_id); | ||
} | ||
else | ||
{ | ||
elem->set_extra_integer(extra_id_index, id); | ||
++i; | ||
old_id = id; | ||
id = integer_ids[i]; | ||
} | ||
} | ||
return dynamic_pointer_cast<MeshBase>(mesh); | ||
} | ||
|
||
std::vector<dof_id_type> | ||
HexIDPatternedMeshGenerator::getCellwiseIntegerIDs() const | ||
{ | ||
std::vector<dof_id_type> integer_ids; | ||
dof_id_type id = 0; | ||
for (MooseIndex(_pattern) i = 0; i < _pattern.size(); ++i) | ||
{ | ||
for (MooseIndex(_pattern[i]) j = 0; j < _pattern[i].size(); ++j) | ||
{ | ||
ReplicatedMesh & cell_mesh = *_meshes[_pattern[i][j]]; | ||
unsigned int n_cell_elem = cell_mesh.n_elem(); | ||
bool exclude_id = false; | ||
if (_use_exclude_id) | ||
if (_exclude_ids[_pattern[i][j]]) | ||
exclude_id = true; | ||
if (!exclude_id) | ||
{ | ||
for (unsigned int k = 0; k < n_cell_elem; ++k) | ||
integer_ids.push_back(id); | ||
++id; | ||
} | ||
else | ||
for (unsigned int k = 0; k < n_cell_elem; ++k) | ||
integer_ids.push_back(DofObject::invalid_id); | ||
} | ||
} | ||
return integer_ids; | ||
} | ||
|
||
std::vector<dof_id_type> | ||
HexIDPatternedMeshGenerator::getPatternIntegerIDs() const | ||
{ | ||
std::vector<dof_id_type> integer_ids; | ||
for (MooseIndex(_pattern) i = 0; i < _pattern.size(); ++i) | ||
{ | ||
for (MooseIndex(_pattern[i]) j = 0; j < _pattern[i].size(); ++j) | ||
{ | ||
const ReplicatedMesh & cell_mesh = *_meshes[_pattern[i][j]]; | ||
unsigned int n_cell_elem = cell_mesh.n_elem(); | ||
for (unsigned int k = 0; k < n_cell_elem; ++k) | ||
integer_ids.push_back(_pattern[i][j]); | ||
} | ||
} | ||
return integer_ids; | ||
} | ||
std::vector<dof_id_type> | ||
HexIDPatternedMeshGenerator::getManualIntegerIDs() const | ||
{ | ||
std::vector<dof_id_type> integer_ids; | ||
for (MooseIndex(_pattern) i = 0; i < _pattern.size(); ++i) | ||
{ | ||
for (MooseIndex(_pattern[i]) j = 0; j < _pattern[i].size(); ++j) | ||
{ | ||
unsigned int id = _id_pattern[i][j]; | ||
const ReplicatedMesh & cell_mesh = *_meshes[_pattern[i][j]]; | ||
unsigned int n_cell_elem = cell_mesh.n_elem(); | ||
for (unsigned int k = 0; k < n_cell_elem; ++k) | ||
integer_ids.push_back(id); | ||
} | ||
} | ||
return integer_ids; | ||
} | ||
|
||
std::set<SubdomainID> | ||
HexIDPatternedMeshGenerator::getCellBlockIDs() const | ||
{ | ||
std::set<SubdomainID> blks; | ||
for (MooseIndex(_pattern) i = 0; i < _pattern.size(); ++i) | ||
{ | ||
for (MooseIndex(_pattern[i]) j = 0; j < _pattern[i].size(); ++j) | ||
{ | ||
const ReplicatedMesh & cell_mesh = *_meshes[_pattern[i][j]]; | ||
for (auto elem : cell_mesh.element_ptr_range()) | ||
{ | ||
auto blk = elem->subdomain_id(); | ||
auto it = blks.find(blk); | ||
if (it == blks.end()) | ||
blks.insert(blk); | ||
} | ||
} | ||
} | ||
return blks; | ||
} | ||
|
||
std::map<SubdomainID, unsigned int> | ||
HexIDPatternedMeshGenerator::getDuckBlockIDs(std::unique_ptr<MeshBase> & mesh, | ||
std::set<SubdomainID> & blks) const | ||
{ | ||
unsigned int i = 0; | ||
std::map<SubdomainID, unsigned int> blks_duct; | ||
if (_has_assembly_duct) | ||
{ | ||
for (auto elem : mesh->element_ptr_range()) | ||
{ | ||
auto blk = elem->subdomain_id(); | ||
auto it1 = blks.find(blk); | ||
if (it1 == blks.end()) | ||
{ | ||
auto it2 = blks_duct.find(blk); | ||
if (it2 == blks_duct.end()) | ||
blks_duct[blk] = i++; | ||
} | ||
} | ||
blks_duct.erase(blks_duct.begin()); | ||
} | ||
return blks_duct; | ||
} |
65 changes: 65 additions & 0 deletions
65
modules/reactor/test/tests/meshgenerators/reporting_id/hexagonal_id/assembly_reporting_id.i
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
[Mesh] | ||
[pin1] | ||
type = PolygonConcentricCircleMeshGenerator | ||
preserve_volumes = true | ||
ring_radii = 0.4 | ||
ring_intervals = 1 | ||
background_intervals = 1 | ||
num_sides = 6 | ||
num_sectors_per_side = '2 2 2 2 2 2' | ||
polygon_size = 0.5 | ||
[] | ||
[pin2] | ||
type = PolygonConcentricCircleMeshGenerator | ||
preserve_volumes = true | ||
ring_radii = 0.4 | ||
ring_intervals = 1 | ||
background_intervals = 1 | ||
num_sides = 6 | ||
num_sectors_per_side = '2 2 2 2 2 2' | ||
polygon_size = 0.5 | ||
[] | ||
[assembly] | ||
type = HexIDPatternedMeshGenerator | ||
inputs = 'pin1 pin2' | ||
pattern_boundary = hexagon | ||
pattern = ' 1 0 1; | ||
0 0 0 0; | ||
1 0 1 0 1; | ||
0 0 0 0; | ||
1 0 1' | ||
hexagon_size = 2.6 | ||
duct_sizes = '2.4 2.5' | ||
duct_intervals = '1 1' | ||
assign_type = 'cell' | ||
id_name = 'pin_id' | ||
[] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
[] | ||
|
||
[AuxVariables] | ||
[pin_id] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
[] | ||
[] | ||
|
||
[AuxKernels] | ||
[set_pin_id] | ||
type = ElemExtraIDAux | ||
variable = pin_id | ||
extra_id_name = pin_id | ||
[] | ||
[] | ||
|
||
[Outputs] | ||
exodus = true | ||
execute_on = timestep_end | ||
[] |
Oops, something went wrong.