https://mooseframework.inl.gov
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 
24 {
25  return emptyInputParameters();
26 }
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 unsigned int
36 ElementIDInterface::getElementIDIndex(const std::string & id_parameter_name,
37  unsigned int comp) const
38 {
39  auto & p = _obj_parameters.get<std::vector<ExtraElementIDName>>(id_parameter_name);
40  if (comp >= p.size())
41  mooseError(id_parameter_name, " does not have enough integer names");
42 
43  return getElementIDIndexByName(p[comp]);
44 }
45 
46 unsigned int
47 ElementIDInterface::getElementIDIndexByName(const std::string & id_name) const
48 {
49  if (!_id_mesh.get())
50  mooseError("Mesh is not available for getting element integers");
51 
52  auto & mesh_base = _id_mesh->getMesh();
53 
54  if (id_name == "subdomain_id")
55  {
56  if (mesh_base.has_elem_integer(id_name))
57  mooseError("MOOSE does not allow 'subdomain_id' element integer in a mesh. 'subdomain_id' is "
58  "reserved for element subdomain ID");
59  return mesh_base.n_elem_integers();
60  }
61 
62  if (!mesh_base.has_elem_integer(id_name))
63  mooseError(
64  "Mesh does not have an element integer names as ", id_name, " but required by ", _ei_name);
65 
66  auto id = mesh_base.get_elem_integer_index(id_name);
67 
68  return id;
69 }
70 
71 const dof_id_type &
72 ElementIDInterface::getElementID(const std::string & id_parameter_name, unsigned int comp) const
73 {
74  auto id = getElementIDIndex(id_parameter_name, comp);
75 
76  auto & _subproblem = *_obj_parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
77 
78  auto tid = _obj_parameters.get<THREAD_ID>("_tid");
79 
80  auto & assembly = _subproblem.assembly(tid, 0);
81 
82  return assembly.extraElemID(id);
83 }
84 
85 const dof_id_type &
86 ElementIDInterface::getElementIDNeighbor(const std::string & id_parameter_name,
87  unsigned int comp) const
88 {
89  auto id = getElementIDIndex(id_parameter_name, comp);
90 
91  auto & _subproblem = *_obj_parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
92 
93  auto tid = _obj_parameters.get<THREAD_ID>("_tid");
94 
95  auto & assembly = _subproblem.assembly(tid, 0);
96 
97  return assembly.extraElemIDNeighbor(id);
98 }
99 
100 const dof_id_type &
101 ElementIDInterface::getElementIDByName(const std::string & id_name) const
102 {
103  auto id = getElementIDIndexByName(id_name);
104 
105  auto & _subproblem = *_obj_parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
106 
107  auto tid = _obj_parameters.get<THREAD_ID>("_tid");
108 
109  auto & assembly = _subproblem.assembly(tid, 0);
110 
111  return assembly.extraElemID(id);
112 }
113 
114 const dof_id_type &
115 ElementIDInterface::getElementIDNeighborByName(const std::string & id_name) const
116 {
117  auto id = getElementIDIndexByName(id_name);
118 
119  auto & _subproblem = *_obj_parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
120 
121  auto tid = _obj_parameters.get<THREAD_ID>("_tid");
122 
123  auto & assembly = _subproblem.assembly(tid, 0);
124 
125  return assembly.extraElemIDNeighbor(id);
126 }
std::string name(const ElemQuality q)
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.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
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.
std::shared_ptr< MooseMesh > & _id_mesh
References to the mesh and displaced mesh (currently in the ActionWarehouse)
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...
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual const dof_id_type & getElementIDNeighborByName(const std::string &id_name) const
Gets a neighbor element integer with the element integer name.
InputParameters emptyInputParameters()
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
const std::string & _ei_name
Name of the object using 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...
virtual const dof_id_type & getElementIDByName(const std::string &id_name) const
Gets an element integer with the element integer name.
static InputParameters validParams()
const InputParameters & _obj_parameters
Reference to the object&#39;s input parameters.
virtual unsigned int getElementIDIndexByName(const std::string &id_name) const
Return the accessing integer for an extra element integer with its name.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
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.
ElementIDInterface(const MooseObject *moose_object)
unsigned int THREAD_ID
Definition: MooseTypes.h:209
uint8_t dof_id_type