https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ElementIDInterface.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "ElementIDInterface.h"
11
12#include "InputParameters.h"
13#include "MooseObject.h"
14#include "MooseApp.h"
15#include "ActionWarehouse.h"
16#include "MooseMesh.h"
17#include "SubProblem.h"
18#include "Assembly.h"
19
20#include "libmesh/mesh_base.h"
21
27
29 : _obj_parameters(moose_object->parameters()),
30 _id_mesh(moose_object->getMooseApp().actionWarehouse().mesh()),
31 _ei_name(moose_object->name())
32{
33}
34
35#ifdef MOOSE_KOKKOS_ENABLED
38 : _obj_parameters(object._obj_parameters), _id_mesh(object._id_mesh), _ei_name(object._ei_name)
39{
40}
41#endif
42
43unsigned int
44ElementIDInterface::getElementIDIndex(const std::string & id_parameter_name,
45 unsigned int comp) const
46{
47 auto & p = _obj_parameters.get<std::vector<ExtraElementIDName>>(id_parameter_name);
48 if (comp >= p.size())
49 mooseError(id_parameter_name, " does not have enough integer names");
50
51 return getElementIDIndexByName(p[comp]);
52}
53
54unsigned int
55ElementIDInterface::getElementIDIndexByName(const std::string & id_name) const
56{
57 if (!_id_mesh.get())
58 mooseError("Mesh is not available for getting element integers");
59
60 auto & mesh_base = _id_mesh->getMesh();
61
62 if (id_name == "subdomain_id")
63 {
64 if (mesh_base.has_elem_integer(id_name))
65 mooseError("MOOSE does not allow 'subdomain_id' element integer in a mesh. 'subdomain_id' is "
66 "reserved for element subdomain ID");
67 return mesh_base.n_elem_integers();
68 }
69
70 if (!mesh_base.has_elem_integer(id_name))
72 "Mesh does not have an element integer names as ", id_name, " but required by ", _ei_name);
73
74 auto id = mesh_base.get_elem_integer_index(id_name);
75
76 return id;
77}
78
79const dof_id_type &
80ElementIDInterface::getElementID(const std::string & id_parameter_name, unsigned int comp) const
81{
82 auto id = getElementIDIndex(id_parameter_name, comp);
83
84 auto & _subproblem = *_obj_parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
85
86 auto tid = _obj_parameters.get<THREAD_ID>("_tid");
87
88 auto & assembly = _subproblem.assembly(tid, 0);
89
90 return assembly.extraElemID(id);
91}
92
93const dof_id_type &
94ElementIDInterface::getElementIDNeighbor(const std::string & id_parameter_name,
95 unsigned int comp) const
96{
97 auto id = getElementIDIndex(id_parameter_name, comp);
98
99 auto & _subproblem = *_obj_parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
100
101 auto tid = _obj_parameters.get<THREAD_ID>("_tid");
102
103 auto & assembly = _subproblem.assembly(tid, 0);
104
105 return assembly.extraElemIDNeighbor(id);
106}
107
108const dof_id_type &
109ElementIDInterface::getElementIDByName(const std::string & id_name) const
110{
111 auto id = getElementIDIndexByName(id_name);
112
113 auto & _subproblem = *_obj_parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
114
115 auto tid = _obj_parameters.get<THREAD_ID>("_tid");
116
117 auto & assembly = _subproblem.assembly(tid, 0);
118
119 return assembly.extraElemID(id);
120}
121
122const dof_id_type &
123ElementIDInterface::getElementIDNeighborByName(const std::string & id_name) const
124{
125 auto id = getElementIDIndexByName(id_name);
126
127 auto & _subproblem = *_obj_parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
128
129 auto tid = _obj_parameters.get<THREAD_ID>("_tid");
130
131 auto & assembly = _subproblem.assembly(tid, 0);
132
133 return assembly.extraElemIDNeighbor(id);
134}
InputParameters emptyInputParameters()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
unsigned int THREAD_ID
Definition MooseTypes.h:237
const std::string & _ei_name
Name of the object using this interface.
const InputParameters & _obj_parameters
Reference to the object's input parameters.
virtual const dof_id_type & getElementIDByName(const std::string &id_name) const
Gets an element integer with the element integer name.
virtual const dof_id_type & getElementIDNeighbor(const std::string &id_parameter_name, unsigned int comp=0) const
Gets a neighbor element integer with a parameter of the object derived from this interface.
virtual unsigned int getElementIDIndex(const std::string &id_parameter_name, unsigned int comp=0) const
Gets index of an element integer with a parameter of the object derived from this interface.
ElementIDInterface(const MooseObject *moose_object)
virtual unsigned int getElementIDIndexByName(const std::string &id_name) const
Return the accessing integer for an extra element integer with its name.
std::shared_ptr< MooseMesh > & _id_mesh
References to the mesh and displaced mesh (currently in the ActionWarehouse)
static InputParameters validParams()
virtual const dof_id_type & getElementID(const std::string &id_parameter_name, unsigned int comp=0) const
Gets an element integer with a parameter of the object derived from this interface.
virtual const dof_id_type & getElementIDNeighborByName(const std::string &id_name) const
Gets a neighbor element integer with the element integer name.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller.
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
MeshBase & mesh