Skip to content

Commit

Permalink
Code improvement for RevolveGenerator based on review comments 2
Browse files Browse the repository at this point in the history
  • Loading branch information
miaoyinb committed Jun 13, 2024
1 parent ae12365 commit 66d7916
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AdvancedExtruderGenerator : public MeshGenerator
std::vector<std::unordered_map<boundary_id_type, boundary_id_type>> _boundary_swap_pairs;

/// Easier to work with version of _elem_integers_swaps
std::vector<std::unordered_map<unsigned int, unsigned int>> _elem_integers_swap_pairs;
std::vector<std::unordered_map<dof_id_type, dof_id_type>> _elem_integers_swap_pairs;

/// The direction of the extrusion
Point _direction;
Expand Down
10 changes: 7 additions & 3 deletions framework/include/utils/MooseMeshUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,16 @@ void swapNodesInElem(Elem & elem, const unsigned int nd1, const unsigned int nd2
* @param id_name name of the parameter to be swapped used for exception messages
* @param id_swaps vector of vectors of the ids to be swapped
* @param id_swap_pairs vector of maps of the swapped pairs
* @param row_index_shift shift to be applied to the row index in the exception messages (useful
* when this method is utilized to process a fraction of a long vector)
*/
template <typename T>
void
idSwapParametersProcessor(const std::string & class_name,
const std::string & id_name,
const std::vector<std::vector<T>> & id_swaps,
std::vector<std::unordered_map<T, T>> & id_swap_pairs)
std::vector<std::unordered_map<T, T>> & id_swap_pairs,
const unsigned int row_index_shift = 0)
{
id_swap_pairs.resize(id_swaps.size());
for (const auto i : index_range(id_swaps))
Expand All @@ -347,14 +350,15 @@ idSwapParametersProcessor(const std::string & class_name,

if (swaps.size() % 2)
throw MooseException("Row ",
i + 1,
row_index_shift + i + 1,
" of ",
id_name,
" in ",
class_name,
" does not contain an even number of entries! Num entries: ",
swaps.size());

swap_pairs.reserve(swaps.size() / 2);
for (unsigned int j = 0; j < swaps.size(); j += 2)
swap_pairs[swaps[j]] = swaps[j + 1];
}
Expand All @@ -373,5 +377,5 @@ void extraElemIntegerSwapParametersProcessor(
const unsigned int num_sections,
const unsigned int num_integers,
const std::vector<std::vector<std::vector<dof_id_type>>> & elem_integers_swaps,
std::vector<std::unordered_map<unsigned int, unsigned int>> & elem_integers_swap_pairs);
std::vector<std::unordered_map<dof_id_type, dof_id_type>> & elem_integers_swap_pairs);
}
33 changes: 18 additions & 15 deletions framework/src/utils/MooseMeshUtils.C
Original file line number Diff line number Diff line change
Expand Up @@ -499,26 +499,29 @@ extraElemIntegerSwapParametersProcessor(
const unsigned int num_sections,
const unsigned int num_integers,
const std::vector<std::vector<std::vector<dof_id_type>>> & elem_integers_swaps,
std::vector<std::unordered_map<unsigned int, unsigned int>> & elem_integers_swap_pairs)
std::vector<std::unordered_map<dof_id_type, dof_id_type>> & elem_integers_swap_pairs)
{
elem_integers_swap_pairs.resize(num_sections * num_integers);
elem_integers_swap_pairs.reserve(num_sections * num_integers);
for (const auto i : make_range(num_integers))
{
for (const auto j : make_range(num_sections))
const auto & elem_integer_swaps = elem_integers_swaps[i];
std::vector<std::unordered_map<dof_id_type, dof_id_type>> elem_integer_swap_pairs;
try
{
const auto & extra_swaps = elem_integers_swaps[i][j];
auto & extra_swap_pairs = elem_integers_swap_pairs[i * num_sections + j];

if (extra_swaps.size() % 2)
throw MooseException("Row ",
i * num_sections + j + 1,
" of elem_integers_swaps in ",
class_name,
" does not contain an even number of entries! Num entries: ",
extra_swaps.size());
for (unsigned int k = 0; k < extra_swaps.size(); k += 2)
extra_swap_pairs[extra_swaps[k]] = extra_swaps[k + 1];
MooseMeshUtils::idSwapParametersProcessor(class_name,
"elem_integers_swaps",
elem_integer_swaps,
elem_integer_swap_pairs,
i * num_sections);
}
catch (const MooseException & e)
{
throw MooseException(e.what());
}

elem_integers_swap_pairs.insert(elem_integers_swap_pairs.end(),
elem_integer_swap_pairs.begin(),
elem_integer_swap_pairs.end());
}
}
}
4 changes: 2 additions & 2 deletions modules/reactor/include/meshgenerators/RevolveGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class RevolveGenerator : public PolygonMeshGeneratorBase
std::vector<std::unordered_map<boundary_id_type, boundary_id_type>> _boundary_swap_pairs;

/// Easier to work with version of _elem_integers_swaps
std::vector<std::unordered_map<unsigned int, unsigned int>> _elem_integers_swap_pairs;
std::vector<std::unordered_map<dof_id_type, dof_id_type>> _elem_integers_swap_pairs;

/// Whether to revolve for a full circle or not
bool _full_circle_revolving;
Expand Down Expand Up @@ -116,7 +116,7 @@ class RevolveGenerator : public PolygonMeshGeneratorBase
* Categorize the nodes of an element into two groups: nodes on the axis and nodes off the axis.
* @param elem the element whose nodes are to be categorized
* @param nodes_on_axis a list of node IDs on the axis
* @return a pair of two lists of node IDs: the first list is for nodes on the axis, and the
* @return a pair of lists of node IDs: the first list is for nodes on the axis, and the
* second list is for nodes off the axis
*/
std::pair<std::vector<dof_id_type>, std::vector<dof_id_type>>
Expand Down
Loading

0 comments on commit 66d7916

Please sign in to comment.