www.mooseframework.org
GhostingUserObject.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 #include "GhostingUserObject.h"
11 #include "NonlinearSystemBase.h"
12 #include "MooseMesh.h"
13 
15 
16 namespace
17 {
18 constexpr unsigned int GEOMETRIC_MAP_IDX = 0;
19 constexpr unsigned int ALGEBRAIC_MAP_IDX = 1;
20 }
21 
22 template <>
25 {
27 
28  params.addParam<std::vector<processor_id_type>>("pids", "The PID(s) to see the ghosting for");
29 
30  // No need to set or override this flag, this object is triggered by meshChanged events
31  params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL};
32 
33  params.addClassDescription("Creates ghosting maps that can be queried by external objects.");
34  return params;
35 }
36 
38  : GeneralUserObject(parameters),
39  _mesh(_subproblem.mesh()),
40  _nl(_fe_problem.getNonlinearSystemBase())
41 {
42  _maps.resize(2); // Geometric and Algebraic maps
43 
44  if (parameters.isParamValid("pids"))
45  _pids = getParam<std::vector<processor_id_type>>("pids");
46  else
47  {
48  // If a PIDs vector is not passed, generate patterns for all processors
49  _pids.resize(_app.n_processors());
50  std::iota(_pids.begin(), _pids.end(), 0);
51  }
52 }
53 
54 void
56 {
57  meshChanged();
58 }
59 
60 void
62 {
63  // Clear the maps before rebuilding
64  for (auto & map_ref : _maps)
65  for (auto pid_map_pair : map_ref)
66  pid_map_pair.second.clear();
67 
68  for (auto pid : _pids)
69  {
70  auto begin_elem = _mesh.getMesh().active_pid_elements_begin(pid);
71  const auto end_elem = _mesh.getMesh().active_pid_elements_end(pid);
72 
73  // Loop over all the geometric ghosting functors and build up a map of elements that are ghosted
74  // for each PID
75  libMesh::GhostingFunctor::map_type geometric_elems;
76  for (auto & gf : as_range(_mesh.getMesh().ghosting_functors_begin(),
77  _mesh.getMesh().ghosting_functors_end()))
78  (*gf)(begin_elem, end_elem, pid, geometric_elems);
79  _maps[GEOMETRIC_MAP_IDX].emplace(pid, geometric_elems);
80 
81  // Loop over all the algebraic ghosting functors and build up a map of elements that are ghosted
82  // for each PID
83  libMesh::GhostingFunctor::map_type algebraic_elems;
84  for (auto & gf : as_range(_nl.dofMap().algebraic_ghosting_functors_begin(),
85  _nl.dofMap().algebraic_ghosting_functors_end()))
86  (*gf)(begin_elem, end_elem, pid, algebraic_elems);
87  for (auto & gf :
88  as_range(_nl.dofMap().coupling_functors_begin(), _nl.dofMap().coupling_functors_end()))
89  (*gf)(begin_elem, end_elem, pid, algebraic_elems);
90  _maps[ALGEBRAIC_MAP_IDX].emplace(pid, algebraic_elems);
91  }
92 }
93 
94 Real
97  processor_id_type pid) const
98 {
99  unsigned int map_idx = (rm_type == Moose::RelationshipManagerType::GEOMETRIC ? GEOMETRIC_MAP_IDX
100  : ALGEBRAIC_MAP_IDX);
101 
102  auto map_it = _maps[map_idx].find(pid);
103  if (map_it == _maps[map_idx].end())
104  mooseError("No entry in the ghosting map for processor ID: ", pid);
105 
106  auto map_ref = map_it->second;
107  if (map_ref.find(elem) != map_ref.end())
108  return 1.;
109  else
110  return 0.;
111 }
std::vector< std::unordered_map< processor_id_type, libMesh::GhostingFunctor::map_type > > _maps
Ghost Functor maps Dimension one: Map type (Geometric, Algebraic) Dimension two: Proc ID -> Map Dimen...
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:24
std::vector< processor_id_type > _pids
The PID to show the ghosting for.
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:716
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
Real getElementalValue(const Elem *elem, Moose::RelationshipManagerType rm_type, processor_id_type pid) const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
This object loops over all of the underlying ghosting functors added by libMesh or MOOSE through Rela...
InputParameters validParams< GeneralUserObject >()
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:191
virtual DofMap & dofMap()
Gets writeable reference to the dof map.
Definition: SystemBase.C:932
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:65
GhostingUserObject(const InputParameters &parameters)
InputParameters validParams< GhostingUserObject >()
virtual void meshChanged() override
Called on this object when the mesh changes.
NonlinearSystemBase & _nl
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:177
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
registerMooseObject("MooseApp", GhostingUserObject)
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
const ExecFlagType EXEC_INITIAL