www.mooseframework.org
ElementSideNeighborLayers.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 
11 #include "MooseMesh.h"
12 #include "Conversion.h"
13 #include "MooseApp.h"
14 #include "Executioner.h"
15 #include "FEProblemBase.h"
16 #include "NonlinearSystem.h"
17 
18 #include "libmesh/default_coupling.h"
19 #include "libmesh/point_neighbor_coupling.h"
20 #include "libmesh/dof_map.h"
21 
23 
26 {
28 
29  params.addRangeCheckedParam<unsigned short>(
30  "layers",
31  1,
32  "element_side_neighbor_layers>=1 & element_side_neighbor_layers<=10",
33  "The number of additional geometric elements to make available when "
34  "using distributed mesh. No effect with replicated mesh.");
35  params.addParam<bool>("use_point_neighbors",
36  false,
37  "Whether to use point neighbors, which introduces additional ghosting to "
38  "that used for simple face neighbors.");
39 
40  return params;
41 }
42 
44  : FunctorRelationshipManager(parameters),
45  _layers(getParam<unsigned short>("layers")),
46  _use_point_neighbors(getParam<bool>("use_point_neighbors"))
47 {
48 }
49 
52  _layers(other._layers),
53  _use_point_neighbors(other._use_point_neighbors)
54 {
55 }
56 
57 std::unique_ptr<GhostingFunctor>
59 {
60  return std::make_unique<ElementSideNeighborLayers>(*this);
61 }
62 
63 std::string
65 {
66  std::ostringstream oss;
67  std::string layers = _layers == 1 ? "layer" : "layers";
68 
69  oss << "ElementSideNeighborLayers (" << _layers << " " << layers << ')';
70 
71  return oss.str();
72 }
73 
74 // the LHS ("this" object) in MooseApp::addRelationshipManager is the existing RelationshipManager
75 // object to which we are comparing the rhs to determine whether it should get added
76 bool
78 {
79  const auto * rm = dynamic_cast<const ElementSideNeighborLayers *>(&rhs);
80  if (!rm)
81  return false;
82  else
83  // We use a >= comparison instead of == for _layers because if we already have more ghosting
84  // than the new RM provides, then that's an indication that we should *not* add the new one
85  return (_layers >= rm->_layers) && (_use_point_neighbors == rm->_use_point_neighbors) &&
86  baseGreaterEqual(*rm);
87 }
88 
89 template <typename Functor>
90 void
92 {
93  functor.set_n_levels(_layers);
94 
95  if (_dof_map)
96  {
97  // Need to see if there are periodic BCs - if so we need to dig them out
98  auto periodic_boundaries_ptr = _dof_map->get_periodic_boundaries();
99 
100  mooseAssert(periodic_boundaries_ptr, "Periodic Boundaries Pointer is nullptr");
101 
102  functor.set_periodic_boundaries(periodic_boundaries_ptr);
103  functor.set_dof_coupling(_dof_map->_dof_coupling);
104  }
105 }
106 
107 void
109 {
111  {
112  auto functor = std::make_unique<PointNeighborCoupling>();
113  initFunctor(*functor);
114  _functor = std::move(functor);
115  }
116  else
117  {
118  auto functor = std::make_unique<DefaultCoupling>();
119  initFunctor(*functor);
120  _functor = std::move(functor);
121  }
122 }
123 
124 void
126 {
127  if (_dof_map)
128  {
130  static_cast<PointNeighborCoupling *>(_functor.get())
131  ->set_dof_coupling(_dof_map->_dof_coupling);
132  else
133  static_cast<DefaultCoupling *>(_functor.get())->set_dof_coupling(_dof_map->_dof_coupling);
134  }
135 }
virtual std::string getInfo() const override
Method for returning relationship manager information (suitable for console output).
ElementSideNeighborLayers(const InputParameters &parameters)
unsigned short _layers
Size of the halo or stencil of elements available in each local processors partition.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
registerMooseObject("MooseApp", ElementSideNeighborLayers)
void initFunctor(Functor &functor)
Helper for initing.
virtual void internalInitWithMesh(const MeshBase &) override
Called before this RM is attached.
std::unique_ptr< GhostingFunctor > _functor
ElementSideNeighborLayers is used to increase the halo or stencil depth of each processor&#39;s partition...
static InputParameters validParams()
FunctorEnvelope< T > Functor
const DofMap * _dof_map
Pointer to DofMap (may be null if this is geometric only).
virtual bool baseGreaterEqual(const RelationshipManager &rhs) const
Whether the base class provides more or the same amount and type of ghosting as the rhs...
virtual bool operator>=(const RelationshipManager &rhs) const override
Whether this relationship manager provides more or the same amount and type of ghosting as the rhs...
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
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...
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
virtual std::unique_ptr< GhostingFunctor > clone() const override
According to the base class docs, "We call mesh_reinit() whenever the relevant Mesh has changed...
static InputParameters validParams()
Intermediate base class for RelationshipManagers that are simply built using ghosting functors...