Skip to content

Commit

Permalink
Removing duplicated functions of Cartesian and hexagonal reporting ID…
Browse files Browse the repository at this point in the history
… generators
  • Loading branch information
yjung-anl committed Dec 1, 2021
1 parent 24442d4 commit 886f807
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 322 deletions.
Expand Up @@ -25,12 +25,6 @@ class CartesianIDPatternedMeshGenerator : public PatternedMeshGenerator
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;
/// name of integer ID.
const std::string _element_id_name;
/// integer ID assignment type
Expand Down
Expand Up @@ -26,17 +26,6 @@ class HexIDPatternedMeshGenerator : public PatternedHexMeshGenerator
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
Expand Down
99 changes: 99 additions & 0 deletions modules/reactor/include/utils/ReportingIDGeneratorUtils.h
@@ -0,0 +1,99 @@
//* 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 "MooseTypes.h"
#include "libmesh/elem.h"
#include "libmesh/replicated_mesh.h"
#include "libmesh/dof_object.h"

namespace ReportingIDGeneratorUtils
{
/**
* assign IDs for each component in pattern in sequential order
* @param meshes input meshes of the cartesian or hexagonal patterned mesh generator
* @param pattern 2D vector of the mesh pattern
* @param use_exclude_id flag to indicate if exclude_id is defined
* @param exclude_ids flag to indicate if exclude_id is used for each input mesh
* @return list of reporting IDs for individual mesh elements
**/
std::vector<dof_id_type>
getCellwiseIntegerIDs(const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
const std::vector<std::vector<unsigned int>> & pattern,
const bool use_exclude_id,
const std::vector<bool> & exclude_ids);

/**
* assign IDs for each input component type
* @param meshes input meshes of the cartesian or hexagonal patterned mesh generator
* @param pattern 2D vector of the mesh pattern
* @return list of reporting IDs for individual mesh elements
**/
std::vector<dof_id_type>
getPatternIntegerIDs(const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
const std::vector<std::vector<unsigned int>> & pattern);

/**
* assign IDs based on user-defined mapping defined in id_pattern
* @param meshes input meshes of the cartesian or hexagonal patterned mesh generator
* @param pattern 2D vector of the mesh pattern
* @param id_pattern user-defined integer ID for each input pattern cell
* @return list of reporting IDs for individual mesh elements
**/
std::vector<dof_id_type>
getManualIntegerIDs(const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
const std::vector<std::vector<unsigned int>> & pattern,
const std::vector<std::vector<dof_id_type>> & id_pattern);

/**
* get list of block IDs in input mesh cells
* @param meshes input meshes of the cartesian or hexagonal patterned mesh generator
* @param pattern 2D vector of the mesh pattern
* @return list of block IDs in input meshes
**/
std::set<SubdomainID> getCellBlockIDs(const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
const std::vector<std::vector<unsigned int>> & pattern);

/**
* get list of block IDs for the assembly duck regions
* @param mesh output mesh from the cartesian or hexagonal patterned mesh generator
* @param has_assembly_duct flag to indicate if assembly duct exists
* @param blks list of block defined in the input meshes of the cartesian or hexagonal patterned
*mesh generator
* @return list of block ids in the assembly duct region
**/
std::map<SubdomainID, unsigned int> getDuckBlockIDs(const std::unique_ptr<MeshBase> & mesh,
const bool has_assembly_duct,
const std::set<SubdomainID> & blks);

/**
* assign the reporting IDs to the output mesh from the cartesian or hexagonal patterned mesh
*generator
* @param mesh output mesh from the cartesian or hexagonal patterned mesh generator
* @param extra_id_index index of extra integer id for assigning the reproting IDs
* @param assign_type type of integer ID assignment
* @param use_exclude_id flag to indicate if exclude_id is defined
* @param exclude_ids flag to indicate if exclude_id is used for each input mesh
* @param has_assembly_duct flag to indicate if assembly duct exists
* @param input_meshes input meshes of the cartesian or hexagonal patterned mesh generator
* @param pattern 2D vector of the mesh pattern
* @param id_pattern user-defined integer ID for each input pattern cell
* @return output mesh file having reporting IDs
**/
void assignReportingIDs(std::unique_ptr<MeshBase> & mesh,
const unsigned int extra_id_index,
const std::string assign_type,
const bool use_exclude_id,
const std::vector<bool> & exclude_ids,
const bool has_assembly_duct,
const std::vector<std::unique_ptr<ReplicatedMesh>> & input_meshes,
const std::vector<std::vector<unsigned int>> & pattern,
const std::vector<std::vector<dof_id_type>> & id_pattern);
}
104 changes: 23 additions & 81 deletions modules/reactor/src/meshgenerators/CartesianIDPatternedMeshGenerator.C
Expand Up @@ -8,26 +8,28 @@
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "CartesianIDPatternedMeshGenerator.h"
#include "libmesh/elem.h"

#include "ReportingIDGeneratorUtils.h"

registerMooseObject("ReactorApp", CartesianIDPatternedMeshGenerator);

InputParameters
CartesianIDPatternedMeshGenerator::validParams()
{
InputParameters params = PatternedMeshGenerator::validParams();
MooseEnum option("cell pattern manual", "cell");
params.addRequiredParam<std::string>("id_name", "Name of Integer ID set");
params.addRequiredParam<std::string>("id_name", "Name of integer ID set");
params.addParam<std::vector<MeshGeneratorName>>(
"exclude_id", "Name of inputs to be excluded in ID generation.");
params.addParam<MooseEnum>("assign_type", option, "Type of integer id assignment");
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 CartesianIDPatternedMeshGenerator source code is to generate "
"patterned Cartesian meshes with Reporting ID");
"patterned Cartesian meshes with reporting ID");
return params;
}

CartesianIDPatternedMeshGenerator::CartesianIDPatternedMeshGenerator(
const InputParameters & parameters)
: PatternedMeshGenerator(parameters),
Expand Down Expand Up @@ -67,88 +69,28 @@ std::unique_ptr<MeshBase>
CartesianIDPatternedMeshGenerator::generate()
{
auto mesh = PatternedMeshGenerator::generate();
// assumes that the entire mesh has elements of each individual mesh sequentially ordered.
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();

unsigned int extra_id_index = 0;
unsigned int extra_id_index;
if (!mesh->has_elem_integer(_element_id_name))
extra_id_index = mesh->add_elem_integer(_element_id_name);
else
extra_id_index = mesh->get_elem_integer_index(_element_id_name);
unsigned int i = 0;
for (auto & elem : mesh->element_ptr_range())
elem->set_extra_integer(extra_id_index, integer_ids[i++]);
return mesh;
}

std::vector<dof_id_type>
CartesianIDPatternedMeshGenerator::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)
{
const 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);
}
}
extra_id_index = mesh->get_elem_integer_index(_element_id_name);
mooseWarning("extra integer id name already exists", _element_id_name);
}
return integer_ids;
}

std::vector<dof_id_type>
CartesianIDPatternedMeshGenerator::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;
}
// patternedMeshGenerator for Carterisan lattice does not support duct structures
const bool has_assembly_duct = false;
// asssign reporting IDs to individual elements
ReportingIDGeneratorUtils::assignReportingIDs(mesh,
extra_id_index,
_assign_type,
_use_exclude_id,
_exclude_ids,
has_assembly_duct,
_meshes,
_pattern,
_id_pattern);

std::vector<dof_id_type>
CartesianIDPatternedMeshGenerator::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)
{
dof_id_type 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;
return dynamic_pointer_cast<MeshBase>(mesh);
}

0 comments on commit 886f807

Please sign in to comment.