www.mooseframework.org
VerifyElementUniqueID.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // MOOSE includes
16 #include "VerifyElementUniqueID.h"
17 #include "SubProblem.h"
18 #include "MooseMesh.h"
19 
20 template <>
23 {
25  return params;
26 }
27 
29  : ElementUserObject(parameters)
30 {
31 }
32 
33 // This object can't test every possible scenario. For instance, it can't detect recycled ids
34 // It's only designed to make sure that all ids are unique in any given
35 void
37 {
38  _all_ids.clear();
39  _all_ids.reserve(_subproblem.mesh().getMesh().n_local_nodes());
40 }
41 
42 void
44 {
45 #ifdef LIBMESH_ENABLE_UNIQUE_ID
46  _all_ids.push_back(_current_elem->unique_id());
47 #else
48  _all_ids.push_back(0);
49 #endif
50 }
51 
52 void
54 {
55  const VerifyElementUniqueID & uo = static_cast<const VerifyElementUniqueID &>(y);
56 
57  _all_ids.insert(_all_ids.end(), uo._all_ids.begin(), uo._all_ids.end());
58 }
59 
60 void
62 {
63  // On Parallel Mesh we have to look at all the ids over all the processors
65  _communicator.allgather(_all_ids);
66 
67  std::sort(_all_ids.begin(), _all_ids.end());
68  std::vector<dof_id_type>::iterator it_end = std::unique(_all_ids.begin(), _all_ids.end());
69  if (it_end != _all_ids.end())
70  mooseError("Duplicate unique_ids found!");
71 }
virtual MooseMesh & mesh()=0
InputParameters validParams< ElementUserObject >()
virtual void execute() override
Execute method.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
VerifyElementUniqueID(const InputParameters &parameters)
SubProblem & _subproblem
Reference to the Subproblem for this user object.
Definition: UserObject.h:146
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2355
virtual void finalize() override
Finalize.
InputParameters validParams< VerifyElementUniqueID >()
virtual void threadJoin(const UserObject &y) override
Must override.
std::vector< dof_id_type > _all_ids
const Elem *& _current_elem
The current element pointer (available during execute())
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
Base class for user-specific data.
Definition: UserObject.h:42
bool isDistributedMesh() const
Returns the final Mesh distribution type.
Definition: MooseMesh.h:737