www.mooseframework.org
VerifyElementUniqueID.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 // MOOSE includes
11 #include "VerifyElementUniqueID.h"
12 #include "SubProblem.h"
13 #include "MooseMesh.h"
14 
16 
17 template <>
20 {
22  return params;
23 }
24 
26  : ElementUserObject(parameters)
27 {
28 }
29 
30 // This object can't test every possible scenario. For instance, it can't detect recycled ids
31 // It's only designed to make sure that all ids are unique in any given
32 void
34 {
35  _all_ids.clear();
36  _all_ids.reserve(_subproblem.mesh().getMesh().n_local_nodes());
37 }
38 
39 void
41 {
42 #ifdef LIBMESH_ENABLE_UNIQUE_ID
43  _all_ids.push_back(_current_elem->unique_id());
44 #else
45  _all_ids.push_back(0);
46 #endif
47 }
48 
49 void
51 {
52  const VerifyElementUniqueID & uo = static_cast<const VerifyElementUniqueID &>(y);
53 
54  _all_ids.insert(_all_ids.end(), uo._all_ids.begin(), uo._all_ids.end());
55 }
56 
57 void
59 {
60  // On Parallel Mesh we have to look at all the ids over all the processors
62  _communicator.allgather(_all_ids);
63 
64  std::sort(_all_ids.begin(), _all_ids.end());
65  std::vector<dof_id_type>::iterator it_end = std::unique(_all_ids.begin(), _all_ids.end());
66  if (it_end != _all_ids.end())
67  mooseError("Duplicate unique_ids found!");
68 }
virtual MooseMesh & mesh()=0
InputParameters validParams< ElementUserObject >()
bool isDistributedMesh() const
Returns the final Mesh distribution type.
Definition: MooseMesh.h:784
virtual void execute() override
Execute method.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
VerifyElementUniqueID(const InputParameters &parameters)
SubProblem & _subproblem
Reference to the Subproblem for this user object.
Definition: UserObject.h:138
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
virtual void finalize() override
Finalize.
InputParameters validParams< VerifyElementUniqueID >()
virtual void threadJoin(const UserObject &y) override
Must override.
std::vector< dof_id_type > _all_ids
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
const Elem *const & _current_elem
The current element pointer (available during execute())
registerMooseObject("MooseApp", VerifyElementUniqueID)
Base class for user-specific data.
Definition: UserObject.h:37