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 depletion id, refs idaholab#19217
- Loading branch information
Showing
8 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
modules/reactor/include/meshgenerators/DepletionIDGenerator.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,31 @@ | ||
//* 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 "MeshGenerator.h" | ||
/** | ||
* Assigns depletion IDs to elements based on reporting and material IDs | ||
*/ | ||
class DepletionIDGenerator : public MeshGenerator | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
DepletionIDGenerator(const InputParameters & parameters); | ||
|
||
virtual std::unique_ptr<MeshBase> generate() override; | ||
|
||
protected: | ||
/// input mesh for adding element IDs | ||
std::unique_ptr<MeshBase> & _input; | ||
/// material id name | ||
std::string _material_id_name; | ||
/// flag of using single region material id option | ||
const bool _use_exclude_material_id; | ||
}; |
110 changes: 110 additions & 0 deletions
110
modules/reactor/src/meshgenerators/DepletionIDGenerator.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,110 @@ | ||
//* 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 | ||
|
||
#include "DepletionIDGenerator.h" | ||
|
||
registerMooseObject("ReactorApp", DepletionIDGenerator); | ||
|
||
#include "libmesh/elem.h" | ||
|
||
InputParameters | ||
DepletionIDGenerator::validParams() | ||
{ | ||
InputParameters params = MeshGenerator::validParams(); | ||
params.addRequiredParam<MeshGeneratorName>( | ||
"input", "Name of an existing mesh generator to which we assign element IDs"); | ||
params.addParam<std::vector<std::string>>("id_names", "Extra integer id names"); | ||
params.addParam<std::string>("material_id_name", "material_id", "Material id name"); | ||
params.addParam<std::vector<unsigned int>>( | ||
"exclude_material_id", | ||
"Define a list of material IDs to be excluded in the depletion ID generation"); | ||
params.addClassDescription("This DepletionIDGenerator source code is to assign depletion IDs for " | ||
"elements on a mesh based on material and other extra element IDs."); | ||
return params; | ||
} | ||
DepletionIDGenerator::DepletionIDGenerator(const InputParameters & params) | ||
: MeshGenerator(params), | ||
_input(getMesh("input")), | ||
_material_id_name(getParam<std::string>("material_id_name")), | ||
_use_exclude_material_id(isParamValid("exclude_material_id")) | ||
{ | ||
} | ||
|
||
std::unique_ptr<MeshBase> | ||
DepletionIDGenerator::generate() | ||
{ | ||
std::unique_ptr<MeshBase> mesh = std::move(_input); | ||
|
||
if (!mesh->has_elem_integer(_material_id_name)) | ||
mooseError("material_id is not defined in input mesh!"); | ||
unsigned int material_id = mesh->get_elem_integer_index(_material_id_name); | ||
|
||
unsigned int depletion_id; | ||
if (mesh->has_elem_integer("depletion_id")) | ||
depletion_id = mesh->get_elem_integer_index("depletion_id"); | ||
else | ||
depletion_id = mesh->add_elem_integer("depletion_id"); | ||
|
||
std::vector<std::string> id_names; | ||
if (isParamValid("id_names")) | ||
id_names = getParam<std::vector<std::string>>("id_names"); | ||
|
||
std::map<unsigned int, unsigned int> merge_base_id; | ||
std::vector<unsigned int> exclude_material_id; | ||
if (_use_exclude_material_id) | ||
{ | ||
exclude_material_id = getParam<std::vector<unsigned int>>("exclude_material_id"); | ||
} | ||
// initialize depletion id to material id | ||
for (auto & elem : mesh->active_local_element_ptr_range()) | ||
{ | ||
unsigned int id = elem->get_extra_integer(material_id); | ||
// if exclude_material_id is used, set depletion id to 0 for those elements | ||
if (_use_exclude_material_id) | ||
if (std::find(exclude_material_id.begin(), exclude_material_id.end(), id) != | ||
exclude_material_id.end()) | ||
id = 0; | ||
elem->set_extra_integer(depletion_id, id); | ||
} | ||
for (auto id_name : id_names) | ||
{ | ||
// find unique combinations of existing depletion id and reporting id | ||
unsigned int reporting_id = mesh->get_elem_integer_index(id_name); | ||
std::set<std::pair<unsigned int, unsigned int>> unique_ids; | ||
for (auto & elem : mesh->active_local_element_ptr_range()) | ||
{ | ||
unsigned int id1 = elem->get_extra_integer(reporting_id); | ||
unsigned int id2 = elem->get_extra_integer(depletion_id); | ||
auto it = unique_ids.find(std::pair<unsigned int, unsigned int>(id1, id2)); | ||
if (it == unique_ids.end()) | ||
unique_ids.insert(std::pair<unsigned int, unsigned int>(id1, id2)); | ||
} | ||
comm().set_union(unique_ids); | ||
// update depletion id based on updated uniqe combinations | ||
dof_id_type i = 1; | ||
std::map<std::pair<dof_id_type, dof_id_type>, dof_id_type> map_depletion_id; | ||
for (auto & ids : unique_ids) | ||
{ | ||
dof_id_type new_id; | ||
if (ids.second == 0) | ||
new_id = 0; | ||
else | ||
new_id = i++; | ||
map_depletion_id[ids] = new_id; | ||
} | ||
for (auto & elem : mesh->active_local_element_ptr_range()) | ||
{ | ||
dof_id_type id1 = elem->get_extra_integer(reporting_id); | ||
dof_id_type id2 = elem->get_extra_integer(depletion_id); | ||
std::pair<dof_id_type, dof_id_type> ids(id1, id2); | ||
elem->set_extra_integer(depletion_id, map_depletion_id[ids]); | ||
} | ||
} | ||
return mesh; | ||
} |
41 changes: 41 additions & 0 deletions
41
modules/reactor/test/tests/meshgenerators/reporting_id/depletion_id/depletion_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,41 @@ | ||
[Mesh] | ||
[fmg] | ||
type = FileMeshGenerator | ||
file = depletion_id_in.e | ||
exodus_extra_element_integers = 'material_id pin_id assembly_id' | ||
[] | ||
[depl_map] | ||
type = DepletionIDGenerator | ||
input = 'fmg' | ||
id_names = 'pin_id assembly_id' | ||
material_id_name = 'material_id' | ||
[] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
[] | ||
|
||
[AuxVariables] | ||
[depletion_id] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
[] | ||
[] | ||
|
||
[AuxKernels] | ||
[set_depletion_id] | ||
type = ElemExtraIDAux | ||
variable = depletion_id | ||
extra_id_name = depletion_id | ||
[] | ||
[] | ||
|
||
[Outputs] | ||
exodus = true | ||
execute_on = timestep_end | ||
[] |
42 changes: 42 additions & 0 deletions
42
...actor/test/tests/meshgenerators/reporting_id/depletion_id/depletion_id_exclude_material.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,42 @@ | ||
[Mesh] | ||
[fmg] | ||
type = FileMeshGenerator | ||
file = depletion_id_in.e | ||
exodus_extra_element_integers = 'material_id pin_id assembly_id' | ||
[] | ||
[depl_map] | ||
type = DepletionIDGenerator | ||
input = 'fmg' | ||
id_names = 'pin_id assembly_id' | ||
material_id_name = 'material_id' | ||
exclude_material_id = '3 4' | ||
[] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
[] | ||
|
||
[Problem] | ||
solve = false | ||
[] | ||
|
||
[AuxVariables] | ||
[depletion_id] | ||
family = MONOMIAL | ||
order = CONSTANT | ||
[] | ||
[] | ||
|
||
[AuxKernels] | ||
[set_depletion_id] | ||
type = ElemExtraIDAux | ||
variable = depletion_id | ||
extra_id_name = depletion_id | ||
[] | ||
[] | ||
|
||
[Outputs] | ||
exodus = true | ||
execute_on = timestep_end | ||
[] |
Binary file added
BIN
+269 KB
modules/reactor/test/tests/meshgenerators/reporting_id/depletion_id/depletion_id_in.e
Binary file not shown.
Binary file added
BIN
+199 KB
...t/tests/meshgenerators/reporting_id/depletion_id/gold/depletion_id_exclude_material_out.e
Binary file not shown.
Binary file added
BIN
+199 KB
modules/reactor/test/tests/meshgenerators/reporting_id/depletion_id/gold/depletion_id_out.e
Binary file not shown.
16 changes: 16 additions & 0 deletions
16
modules/reactor/test/tests/meshgenerators/reporting_id/depletion_id/tests
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,16 @@ | ||
[Tests] | ||
[2dcore] | ||
type = 'Exodiff' | ||
input = 'depletion_id_exclude_material.i' | ||
exodiff = 'depletion_id_exclude_material_out.e' | ||
requirement ='The system shall generate plane depletion IDs for 2d core' | ||
recover = false | ||
[] | ||
[2dcore_exclude_material_id] | ||
type = 'Exodiff' | ||
input = 'depletion_id_exclude_material.i' | ||
exodiff = 'depletion_id_exclude_material_out.e' | ||
requirement ='The system shall generate plane depletion IDs for 2d core with exclude_material_id option' | ||
recover = false | ||
[] | ||
[] |