forked from idaholab/moose
/
DepletionIDGenerator.C
110 lines (101 loc) · 4.12 KB
/
DepletionIDGenerator.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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;
}