https://mooseframework.inl.gov
ElementSideNeighborLayers.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 
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 
22 using namespace libMesh;
23 
25 
28 {
30 
31  params.addRangeCheckedParam<unsigned short>(
32  "layers",
33  1,
34  "element_side_neighbor_layers>=1 & element_side_neighbor_layers<=10",
35  "The number of additional geometric elements to make available when "
36  "using distributed mesh. No effect with replicated mesh.");
37  params.addParam<bool>("use_point_neighbors",
38  false,
39  "Whether to use point neighbors, which introduces additional ghosting to "
40  "that used for simple face neighbors.");
41 
42  return params;
43 }
44 
46  : FunctorRelationshipManager(parameters),
47  _layers(getParam<unsigned short>("layers")),
48  _use_point_neighbors(getParam<bool>("use_point_neighbors"))
49 {
50 }
51 
54  _layers(other._layers),
55  _use_point_neighbors(other._use_point_neighbors)
56 {
57 }
58 
59 std::unique_ptr<GhostingFunctor>
61 {
62  return _app.getFactory().copyConstruct(*this);
63 }
64 
65 std::string
67 {
68  std::ostringstream oss;
69  std::string layers = _layers == 1 ? "layer" : "layers";
70 
71  oss << "ElementSideNeighborLayers (" << _layers << " " << layers << ')';
72 
73  return oss.str();
74 }
75 
76 // the LHS ("this" object) in MooseApp::addRelationshipManager is the existing RelationshipManager
77 // object to which we are comparing the rhs to determine whether it should get added
78 bool
80 {
81  const auto * rm = dynamic_cast<const ElementSideNeighborLayers *>(&rhs);
82  if (!rm)
83  return false;
84  else
85  // We use a >= comparison instead of == for _layers because if we already have more ghosting
86  // than the new RM provides, then that's an indication that we should *not* add the new one
87  return (_layers >= rm->_layers) && (_use_point_neighbors == rm->_use_point_neighbors) &&
88  baseGreaterEqual(*rm);
89 }
90 
91 template <typename Functor>
92 void
94 {
95  functor.set_n_levels(_layers);
96 
97  if (_dof_map)
98  {
99  // Need to see if there are periodic BCs - if so we need to dig them out
100  auto periodic_boundaries_ptr = _dof_map->get_periodic_boundaries();
101 
102  mooseAssert(periodic_boundaries_ptr, "Periodic Boundaries Pointer is nullptr");
103 
104  functor.set_periodic_boundaries(periodic_boundaries_ptr);
105  functor.set_dof_coupling(_dof_map->_dof_coupling);
106  }
107 }
108 
109 void
111 {
113  {
114  auto functor = std::make_unique<PointNeighborCoupling>();
115  initFunctor(*functor);
116  _functor = std::move(functor);
117  }
118  else
119  {
120  auto functor = std::make_unique<DefaultCoupling>();
121  initFunctor(*functor);
122  _functor = std::move(functor);
123  }
124 }
125 
126 void
128 {
129  if (_dof_map)
130  {
132  static_cast<PointNeighborCoupling *>(_functor.get())
133  ->set_dof_coupling(_dof_map->_dof_coupling);
134  else
135  static_cast<DefaultCoupling *>(_functor.get())->set_dof_coupling(_dof_map->_dof_coupling);
136  }
137 }
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...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
registerMooseObject("MooseApp", ElementSideNeighborLayers)
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition: MooseApp.h:394
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()
PeriodicBoundaries * get_periodic_boundaries()
FunctorEnvelope< T > Functor
CouplingMatrix * _dof_coupling
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:353
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 optional parameter and a documentation string to the InputParameters object...
const libMesh::DofMap * _dof_map
Pointer to DofMap (may be null if this is geometric only).
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...