https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
CoarseMeshExtraElementIDGenerator Class Reference

#include <CoarseMeshExtraElementIDGenerator.h>

Inheritance diagram for CoarseMeshExtraElementIDGenerator:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 CoarseMeshExtraElementIDGenerator (const InputParameters &parameters)
 
virtual std::unique_ptr< MeshBase > generate () override
 
std::unique_ptr< CSG::CSGBase > generateInternalCSG ()
 
std::unique_ptr< MeshBase > generateInternal ()
 
const std::set< MeshGeneratorName > & getRequestedMeshGenerators () const
 
const std::set< MeshGeneratorName > & getRequestedMeshGeneratorsForSub () const
 
void addParentMeshGenerator (const MeshGenerator &mg, const AddParentChildKey)
 
void addChildMeshGenerator (const MeshGenerator &mg, const AddParentChildKey)
 
const std::set< const MeshGenerator *, Comparator > & getParentMeshGenerators () const
 
const std::set< const MeshGenerator *, Comparator > & getChildMeshGenerators () const
 
const std::set< const MeshGenerator *, Comparator > & getSubMeshGenerators () const
 
bool isParentMeshGenerator (const MeshGeneratorName &name, const bool direct=true) const
 
bool isChildMeshGenerator (const MeshGeneratorName &name, const bool direct=true) const
 
bool isNullMeshName (const MeshGeneratorName &name) const
 
bool hasSaveMesh () const
 
bool hasOutput () const
 
const std::string & getSavedMeshName () const
 
bool hasGenerateData () const
 
bool hasGenerateCSG () const
 
bool isDataOnly () const
 
virtual bool enabled () const
 
std::shared_ptr< MooseObject > getSharedPtr ()
 
std::shared_ptr< const MooseObject > getSharedPtr () const
 
bool isKokkosObject () const
 
MooseApp & getMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParameters & parameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const T & getParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const T * queryParam (const std::string &name) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static InputParameters validParams ()
 
static bool hasGenerateData (const InputParameters &params)
 
static bool hasGenerateCSG (const InputParameters &params)
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 
static void setHasGenerateData (InputParameters &params)
 
static void setHasGenerateCSG (InputParameters &params)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string data_only_param
 
static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 
static constexpr auto SYSTEM
 
static constexpr auto NAME
 

Protected Member Functions

virtual void generateData ()
 
virtual std::unique_ptr< CSG::CSGBase > generateCSG ()
 
T & copyMeshProperty (const std::string &target_data_name, const std::string &source_data_name, const std::string &source_mesh)
 
T & copyMeshProperty (const std::string &source_data_name, const std::string &source_mesh)
 
std::unique_ptr< MeshBase > & getMesh (const std::string &param_name, const bool allow_invalid=false)
 
std::vector< std::unique_ptr< MeshBase > * > getMeshes (const std::string &param_name)
 
std::unique_ptr< MeshBase > & getMeshByName (const MeshGeneratorName &mesh_generator_name)
 
std::vector< std::unique_ptr< MeshBase > * > getMeshesByName (const std::vector< MeshGeneratorName > &mesh_generator_names)
 
std::unique_ptr< CSG::CSGBase > & getCSGBase (const std::string &param_name)
 
std::unique_ptr< CSG::CSGBase > & getCSGBaseByName (const MeshGeneratorName &mesh_generator_name)
 
std::vector< std::unique_ptr< CSG::CSGBase > * > getCSGBases (const std::string &param_name)
 
std::vector< std::unique_ptr< CSG::CSGBase > * > getCSGBasesByName (const std::vector< MeshGeneratorName > &mesh_generator_names)
 
void declareMeshForSub (const std::string &param_name)
 
void declareMeshesForSub (const std::string &param_name)
 
void declareMeshForSubByName (const MeshGeneratorName &mesh_generator_name)
 
void declareMeshesForSubByName (const std::vector< MeshGeneratorName > &mesh_generator_names)
 
std::unique_ptr< MeshBase > buildMeshBaseObject (unsigned int dim=libMesh::invalid_uint)
 
std::unique_ptr< ReplicatedMesh > buildReplicatedMesh (unsigned int dim=libMesh::invalid_uint)
 
std::unique_ptr< DistributedMesh > buildDistributedMesh (unsigned int dim=libMesh::invalid_uint)
 
void addMeshSubgenerator (const std::string &type, const std::string &name, Ts... extra_input_parameters)
 
void addMeshSubgenerator (const std::string &type, const std::string &name, InputParameters params)
 
void declareNullMeshName (const MeshGeneratorName &name)
 
void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 
const T & getMeshProperty (const std::string &data_name, const std::string &prefix)
 
const T & getMeshProperty (const std::string &data_name)
 
bool hasMeshProperty (const std::string &data_name, const std::string &prefix) const
 
bool hasMeshProperty (const std::string &data_name, const std::string &prefix) const
 
bool hasMeshProperty (const std::string &data_name) const
 
bool hasMeshProperty (const std::string &data_name) const
 
std::string meshPropertyName (const std::string &data_name) const
 
T & declareMeshProperty (const std::string &data_name, Args &&... args)
 
T & declareMeshProperty (const std::string &data_name, const T &data_value)
 
T & declareMeshProperty (const std::string &data_name, Args &&... args)
 
T & declareMeshProperty (const std::string &data_name, const T &data_value)
 
T & setMeshProperty (const std::string &data_name, Args &&... args)
 
T & setMeshProperty (const std::string &data_name, const T &data_value)
 
T & setMeshProperty (const std::string &data_name, Args &&... args)
 
T & setMeshProperty (const std::string &data_name, const T &data_value)
 

Static Protected Member Functions

static std::string meshPropertyName (const std::string &data_name, const std::string &prefix)
 

Protected Attributes

std::unique_ptr< MeshBase > & _input
 input mesh for adding element IDs
 
std::unique_ptr< MeshBase > & _coarse_mesh
 name of the coarse mesh file
 
const std::string & _coarse_id_name
 coarse element ID name
 
const bool _using_coarse_element_id
 whether or not using the coarse element ID for the extra element ID assignment
 
const bool & _embedding_necessary
 whether the input mesh must be embedded in the coarse mesh
 
MooseMesh *const _mesh
 
const bool & _enabled
 
MooseApp & _app
 
Factory & _factory
 
ActionFactory & _action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters & _pars
 
const Parallel::Communicator & _communicator
 

Private Member Functions

virtual std::string meshPropertyPrefix (const std::string &) const override final
 
void checkGetMesh (const MeshGeneratorName &mesh_generator_name, const std::string &param_name) const
 
const MeshGeneratorName * getMeshGeneratorNameFromParam (const std::string &param_name, const bool allow_invalid) const
 
const std::vector< MeshGeneratorName > & getMeshGeneratorNamesFromParam (const std::string &param_name) const
 
RestartableDataValue & setMeshPropertyHelper (const std::string &data_name)
 
const RestartableDataValue & getMeshPropertyInternal (const std::string &data_name, const std::string &prefix) const
 
void mooseErrorInternal (Args &&... args) const
 

Static Private Member Functions

static const hit::Node * getHitNode (const InputParameters &params)
 
static std::string messagePrefix (const InputParameters &params, const bool hit_prefix)
 

Private Attributes

std::set< MeshGeneratorName > _requested_mesh_generators
 
std::set< MeshGeneratorName > _requested_mesh_generators_for_sub
 
std::vector< std::pair< std::string, std::unique_ptr< MeshBase > * > > _requested_meshes
 
std::vector< std::pair< std::string, std::unique_ptr< CSG::CSGBase > * > > _requested_csg_bases
 
std::unique_ptr< MeshBase > _null_mesh
 
std::unique_ptr< CSG::CSGBase > _null_csg_base
 
std::set< const MeshGenerator *, Comparator > _parent_mesh_generators
 
std::set< const MeshGenerator *, Comparator > _child_mesh_generators
 
std::set< const MeshGenerator *, Comparator > _sub_mesh_generators
 
std::set< std::string > _null_mesh_names
 
const std::string & _save_with_name
 
const bool _data_only
 
const ParallelParamObject & _parent
 
const MooseBase & _si_moose_base
 
const FEProblemBase * _si_problem
 
MooseApp & _meta_data_app
 
const MooseObject *const _meta_data_object
 

Detailed Description

Definition at line 14 of file CoarseMeshExtraElementIDGenerator.h.

Constructor & Destructor Documentation

◆ CoarseMeshExtraElementIDGenerator()

CoarseMeshExtraElementIDGenerator::CoarseMeshExtraElementIDGenerator ( const InputParameters &  parameters)

Definition at line 43 of file CoarseMeshExtraElementIDGenerator.C.

44 : MeshGenerator(params),
45 _input(getMesh("input")),
46 _coarse_mesh(getMesh("coarse_mesh")),
47 _coarse_id_name(getParam<std::string>("extra_element_id_name")),
48 _using_coarse_element_id(isParamValid("coarse_mesh_extra_element_id")),
49 _embedding_necessary(getParam<bool>("enforce_mesh_embedding"))
50{
51}
const std::string & _coarse_id_name
coarse element ID name
std::unique_ptr< MeshBase > & _input
input mesh for adding element IDs
const bool & _embedding_necessary
whether the input mesh must be embedded in the coarse mesh
std::unique_ptr< MeshBase > & _coarse_mesh
name of the coarse mesh file
const bool _using_coarse_element_id
whether or not using the coarse element ID for the extra element ID assignment
std::unique_ptr< MeshBase > & getMesh(const std::string &param_name, const bool allow_invalid=false)
bool isParamValid(const std::string &name) const

Member Function Documentation

◆ generate()

std::unique_ptr< MeshBase > CoarseMeshExtraElementIDGenerator::generate ( )
overridevirtual

Implements MeshGenerator.

Definition at line 54 of file CoarseMeshExtraElementIDGenerator.C.

55{
56 std::unique_ptr<MeshBase> mesh = std::move(_input);
57
58 unsigned int coarse_id;
59 const bool already_has_id = mesh->has_elem_integer(_coarse_id_name);
60 if (!already_has_id)
61 coarse_id = mesh->add_elem_integer(_coarse_id_name);
62 else
63 coarse_id = mesh->get_elem_integer_index(_coarse_id_name);
64
65 // Get the requested subdomain IDs
66 std::set<SubdomainID> included_subdomains;
67 std::set<SubdomainName> bad_subdomains;
68 for (const auto & snm : getParam<std::vector<SubdomainName>>("subdomains"))
69 {
70 auto sid = MooseMeshUtils::getSubdomainID(snm, *mesh);
71 if (!MooseMeshUtils::hasSubdomainID(*mesh, sid))
72 bad_subdomains.insert(snm);
73 else
74 included_subdomains.insert(sid);
75 }
76 if (!bad_subdomains.empty())
77 paramError("subdomains",
78 "The requested subdomains do not exist on the fine mesh: ",
79 Moose::stringify(bad_subdomains));
80
81 // If we are not going through the entire mesh and the ID already exists, we need to offset the
82 // assigned ID so that we don't copy ones that are already there
83 dof_id_type id_offset = 0;
84 if (already_has_id && !included_subdomains.empty())
85 {
86 for (auto & elem : mesh->active_element_ptr_range())
87 {
88 dof_id_type elem_id = elem->get_extra_integer(coarse_id);
89 if (elem_id != DofObject::invalid_id && elem_id > id_offset)
90 id_offset = elem_id;
91 }
92 id_offset++;
93 }
94
95 std::unique_ptr<MeshBase> coarse_mesh = std::move(_coarse_mesh);
96
97 bool using_subdomain_id = false;
98 unsigned int id_for_assignment = 0;
100 {
101 const auto & id_name = getParam<std::string>("coarse_mesh_extra_element_id");
102 if (id_name == "subdomain_id")
103 using_subdomain_id = true;
104 else
105 {
106 using_subdomain_id = false;
107 if (!coarse_mesh->has_elem_integer(id_name))
108 paramError("coarse_mesh_extra_element_id",
109 "The extra element ID does not exist on the coarse mesh");
110 else
111 id_for_assignment = coarse_mesh->get_elem_integer_index(id_name);
112 }
113 }
114
115 // a relative tolerance on checking if fine mesh is embedded in the coarse mesh
116 Real aeps = 0.01;
117
118 // The coarse mesh is serialized for distributed mesh to avoid boundary issues.
119 // As it is coarse this should be cheap. This will be a null operation for a replicated mesh.
120 MeshSerializer tm(*coarse_mesh);
121
122 // build a point_locator on coarse mesh
123 std::unique_ptr<PointLocatorBase> point_locator =
124 PointLocatorBase::build(TREE_ELEMENTS, *coarse_mesh);
125 point_locator->enable_out_of_mesh_mode();
126
127 // loop through fine mesh elements and get element's centroid
128 auto elem_range = included_subdomains.empty()
129 ? mesh->active_element_ptr_range()
130 : mesh->active_subdomain_set_elements_ptr_range(included_subdomains);
131 for (auto & elem : elem_range)
132 {
133 // Get the centroid of the fine elem
134 Point centroid = elem->true_centroid();
135
136 // Find coarse elem
137 const Elem * coarse_elem = (*point_locator)(centroid);
138 if (!coarse_elem)
139 mooseError("Could not find a coarse element containing a fine element with centroid ",
140 centroid);
141
142 // get id from the coarse element
143 dof_id_type elem_id;
145 {
146 if (using_subdomain_id)
147 elem_id = coarse_elem->subdomain_id();
148 else
149 elem_id = coarse_elem->get_extra_integer(id_for_assignment);
150 }
151 else
152 elem_id = coarse_elem->id();
153 elem_id += id_offset;
154
155 // Check if the fine elem is nested in the coarse element
156 for (unsigned int n = 0; n < elem->n_nodes(); n++)
157 {
158 // Get the node: we need to manually move it towards the centroid to
159 // ensure that nothing weird happes due to round-off
160 Point current_node = elem->point(n);
161 current_node.add_scaled(current_node, -aeps);
162 current_node.add_scaled(centroid, aeps);
163
164 // Get the element this node is in and check if it is the same
165 // as the coarse elem; however check if node_elem is valid as it
166 // might not be in case the sub element it outside the coarse domain
167 const Elem * node_elem = (*point_locator)(current_node);
168 if (!node_elem)
169 mooseError("Could not find a coarse element containing a node of fine element at ",
170 elem->point(n));
171
172 // get another id from the coarse element with this node
173 dof_id_type node_elem_id;
175 {
176 if (using_subdomain_id)
177 node_elem_id = node_elem->subdomain_id();
178 else
179 node_elem_id = node_elem->get_extra_integer(id_for_assignment);
180 }
181 else
182 node_elem_id = node_elem->id();
183
184 if (node_elem_id != elem_id)
187 "Input mesh is not nested in the coarse mesh in CoarseMeshExtraElementIDGenerator.");
188 }
189
190 elem->set_extra_integer(coarse_id, elem_id);
191 }
192
193 return mesh;
194}
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
const T & getParam(const std::string &name) const
MeshBase & mesh
bool hasSubdomainID(const MeshBase &input_mesh, const SubdomainID &id)
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
std::string stringify(const T &t)
uint8_t dof_id_type
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ validParams()

InputParameters CoarseMeshExtraElementIDGenerator::validParams ( )
static

Definition at line 20 of file CoarseMeshExtraElementIDGenerator.C.

21{
23 params.addRequiredParam<MeshGeneratorName>(
24 "input", "Name of an existing mesh generator to which we assign coarse element IDs");
25 params.addRequiredParam<MeshGeneratorName>(
26 "coarse_mesh", "Name of an existing mesh generator as the coarse mesh");
27 params.addRequiredParam<std::string>(
28 "extra_element_id_name", "Name for the extra element ID that is added to the input mesh");
29 params.addParam<std::string>(
30 "coarse_mesh_extra_element_id",
31 "Name for the extra element ID that is copied from the coarse mesh (default to element ID)");
32 params.addParam<std::vector<SubdomainName>>(
33 "subdomains", std::vector<SubdomainName>(), "Subdomains to apply extra element IDs to.");
34 params.addParam<bool>("enforce_mesh_embedding",
35 false,
36 "True to error out when the input mesh is not embedded in the coarse mesh");
37
38 params.addClassDescription("Assign coarse element IDs for elements on a "
39 "mesh based on a coarse mesh.");
40 return params;
41}
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()

Member Data Documentation

◆ _coarse_id_name

const std::string& CoarseMeshExtraElementIDGenerator::_coarse_id_name
protected

coarse element ID name

Definition at line 28 of file CoarseMeshExtraElementIDGenerator.h.

Referenced by generate().

◆ _coarse_mesh

std::unique_ptr<MeshBase>& CoarseMeshExtraElementIDGenerator::_coarse_mesh
protected

name of the coarse mesh file

Definition at line 26 of file CoarseMeshExtraElementIDGenerator.h.

Referenced by generate().

◆ _embedding_necessary

const bool& CoarseMeshExtraElementIDGenerator::_embedding_necessary
protected

whether the input mesh must be embedded in the coarse mesh

Definition at line 32 of file CoarseMeshExtraElementIDGenerator.h.

Referenced by generate().

◆ _input

std::unique_ptr<MeshBase>& CoarseMeshExtraElementIDGenerator::_input
protected

input mesh for adding element IDs

Definition at line 24 of file CoarseMeshExtraElementIDGenerator.h.

Referenced by generate().

◆ _using_coarse_element_id

const bool CoarseMeshExtraElementIDGenerator::_using_coarse_element_id
protected

whether or not using the coarse element ID for the extra element ID assignment

Definition at line 30 of file CoarseMeshExtraElementIDGenerator.h.

Referenced by generate().


The documentation for this class was generated from the following files: