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< MeshBasegenerate () override
 
std::unique_ptr< CSG::CSGBasegenerateInternalCSG ()
 
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< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
bool isKokkosObject () const
 
MooseAppgetMooseApp () 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 InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (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::CSGBasegenerateCSG ()
 
TcopyMeshProperty (const std::string &target_data_name, const std::string &source_data_name, const std::string &source_mesh)
 
TcopyMeshProperty (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 TgetMeshProperty (const std::string &data_name, const std::string &prefix)
 
const TgetMeshProperty (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
 
TdeclareMeshProperty (const std::string &data_name, Args &&... args)
 
TdeclareMeshProperty (const std::string &data_name, const T &data_value)
 
TdeclareMeshProperty (const std::string &data_name, Args &&... args)
 
TdeclareMeshProperty (const std::string &data_name, const T &data_value)
 
TsetMeshProperty (const std::string &data_name, Args &&... args)
 
TsetMeshProperty (const std::string &data_name, const T &data_value)
 
TsetMeshProperty (const std::string &data_name, Args &&... args)
 
TsetMeshProperty (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
 
RestartableDataValuesetMeshPropertyHelper (const std::string &data_name)
 
const RestartableDataValuegetMeshPropertyInternal (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 45 of file CoarseMeshExtraElementIDGenerator.C.

46 : MeshGenerator(params),
47 _input(getMesh("input")),
48 _coarse_mesh(getMesh("coarse_mesh")),
49 _coarse_id_name(getParam<std::string>("extra_element_id_name")),
50 _using_coarse_element_id(isParamValid("coarse_mesh_extra_element_id")),
51 _embedding_necessary(getParam<bool>("enforce_mesh_embedding"))
52{
53}
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 56 of file CoarseMeshExtraElementIDGenerator.C.

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

23{
25 params.addRequiredParam<MeshGeneratorName>(
26 "input", "Name of an existing mesh generator to which we assign coarse element IDs");
27 params.addRequiredParam<MeshGeneratorName>(
28 "coarse_mesh", "Name of an existing mesh generator as the coarse mesh");
29 params.addRequiredParam<std::string>(
30 "extra_element_id_name", "Name for the extra element ID that is added to the input mesh");
31 params.addParam<std::string>(
32 "coarse_mesh_extra_element_id",
33 "Name for the extra element ID that is copied from the coarse mesh (default to element ID)");
34 params.addParam<std::vector<SubdomainName>>(
35 "subdomains", std::vector<SubdomainName>(), "Subdomains to apply extra element IDs to.");
36 params.addParam<bool>("enforce_mesh_embedding",
37 false,
38 "True to error out when the input mesh is not embedded in the coarse mesh");
39
40 params.addClassDescription("Assign coarse element IDs for elements on a "
41 "mesh based on a coarse mesh.");
42 return params;
43}
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: