https://mooseframework.inl.gov
Loading...
Searching...
No Matches
GhostPrimaryFace.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
10#include "GhostPrimaryFace.h"
11#include "MooseApp.h"
12#include "libmesh/boundary_info.h"
13#include "libmesh/elem.h"
14
15#include <sstream>
16
18
19using namespace libMesh;
20
23{
25 params.addRequiredParam<BoundaryName>("primary_boundary",
26 "The name of the primary boundary sideset.");
27 params.addRequiredParam<BoundaryName>("secondary_boundary",
28 "The name of the secondary boundary sideset.");
29 params.addRequiredParam<bool>("enabled", "Whether this relationship manager should ghost.");
31 "Ghosts full-dimensional elements with sides on the primary boundary to processors that own "
32 "full-dimensional elements with sides on the secondary boundary.");
33 return params;
34}
35
37 : RelationshipManager(params),
38 _primary_boundary_name(getParam<BoundaryName>("primary_boundary")),
39 _secondary_boundary_name(getParam<BoundaryName>("secondary_boundary")),
40 _enabled(getParam<bool>("enabled"))
41{
42}
43
45 : RelationshipManager(other),
46 _primary_boundary_name(other._primary_boundary_name),
47 _secondary_boundary_name(other._secondary_boundary_name),
48 _enabled(other._enabled)
49{
50}
51
52void
56
57std::string
59{
60 std::ostringstream oss;
61 oss << "GhostPrimaryFace" << (_enabled ? "" : " (disabled)");
62 return oss.str();
63}
64
65bool
67 const MeshBase::const_element_iterator & range_end,
68 const BoundaryID secondary_boundary_id,
69 const bool generating_mesh) const
70{
71 const auto mesh_dim = _mesh->mesh_dimension();
72 const BoundaryInfo & binfo = _mesh->get_boundary_info();
73
74 for (const Elem * const elem : as_range(range_begin, range_end))
75 {
76 if (elem->dim() != mesh_dim)
77 continue;
78
79 if (generating_mesh)
80 {
81 // Boundary ids may not exist yet while generating the mesh, so treat any
82 // full-dimensional boundary element as being on the requested boundary.
83 if (elem->on_boundary())
84 return true;
85 }
86 else
87 for (const auto side : elem->side_index_range())
88 if (binfo.has_boundary_id(elem, side, secondary_boundary_id))
89 return true;
90 }
91
92 return false;
93}
94
95void
97 const MeshBase::const_element_iterator & range_end,
98 const processor_id_type p,
99 map_type & coupled_elements)
100{
101 if (!_enabled)
102 return;
103
104 const bool generating_mesh = !_moose_mesh->getMeshPtr();
105 const auto primary_boundary_id = generating_mesh
108 const auto secondary_boundary_id = generating_mesh
111
112 if (!hasSecondaryBoundaryFace(range_begin, range_end, secondary_boundary_id, generating_mesh))
113 return;
114
115 const auto mesh_dim = _mesh->mesh_dimension();
116 const BoundaryInfo & binfo = _mesh->get_boundary_info();
117
118 for (const Elem * const elem : _mesh->active_element_ptr_range())
119 {
120 if (elem->processor_id() == p || elem->dim() != mesh_dim)
121 continue;
122
123 if (generating_mesh)
124 {
125 // Boundary ids may not exist yet while generating the mesh, so ghost any
126 // full-dimensional boundary element.
127 if (elem->on_boundary())
128 coupled_elements.emplace(elem, _null_mat);
129 }
130 else
131 for (const auto side : elem->side_index_range())
132 if (binfo.has_boundary_id(elem, side, primary_boundary_id))
133 {
134 coupled_elements.emplace(elem, _null_mat);
135 break;
136 }
137 }
138}
139
140bool
142{
143 const auto * const primary_face = dynamic_cast<const GhostPrimaryFace *>(&other);
144 if (!primary_face || !baseGreaterEqual(*primary_face))
145 return false;
146
147 // An enabled instance subsumes an otherwise compatible disabled instance, which adds no
148 // ghosting entries.
149 if (_enabled && !primary_face->_enabled)
150 return true;
151
152 // A disabled instance only subsumes another disabled instance.
153 if (!_enabled)
154 return !primary_face->_enabled;
155
156 // Once both are enabled, the two instances must ghost the same boundary pair on the same
157 // mesh to cover the same elements.
158 return primary_face->_enabled && _use_displaced_mesh == primary_face->_use_displaced_mesh &&
159 _primary_boundary_name == primary_face->_primary_boundary_name &&
160 _secondary_boundary_name == primary_face->_secondary_boundary_name;
161}
162
163std::unique_ptr<GhostingFunctor>
165{
166 return _app.getFactory().copyConstruct(*this);
167}
boundary_id_type BoundaryID
registerMooseObject("MooseApp", GhostPrimaryFace)
Ghosts full-dimensional elements with sides on the primary boundary to processors that own full-dimen...
const BoundaryName _secondary_boundary_name
Secondary boundary whose local presence triggers primary boundary ghosting.
const libMesh::CouplingMatrix *const _null_mat
null matrix for generating full variable coupling
const BoundaryName _primary_boundary_name
Primary boundary whose full-dimensional elements may be ghosted.
bool hasSecondaryBoundaryFace(const libMesh::MeshBase::const_element_iterator &range_begin, const libMesh::MeshBase::const_element_iterator &range_end, BoundaryID secondary_boundary_id, bool generating_mesh) const
Return whether the local element range contains a secondary boundary face.
std::string getInfo() const override
Method for returning relationship manager information (suitable for console output).
virtual bool operator>=(const RelationshipManager &other) const override
Whether this relationship manager provides more or the same amount and type of ghosting as the rhs.
static InputParameters validParams()
const bool _enabled
Whether this relationship manager should add ghosting entries.
GhostPrimaryFace(const InputParameters &params)
virtual void internalInitWithMesh(const libMesh::MeshBase &) override
virtual void operator()(const libMesh::MeshBase::const_element_iterator &range_begin, const libMesh::MeshBase::const_element_iterator &range_end, libMesh::processor_id_type p, map_type &coupled_elements) override
virtual std::unique_ptr< libMesh::GhostingFunctor > clone() const override
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
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.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition MooseApp.h:407
const MeshBase * getMeshPtr() const
Definition MooseMesh.C:3553
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition MooseMesh.C:1691
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
const bool _use_displaced_mesh
Which system this should go to (undisplaced or displaced)
virtual bool baseGreaterEqual(const RelationshipManager &rhs) const
Whether the base class provides more or the same amount and type of ghosting as the rhs.
static InputParameters validParams()
MooseMesh * _moose_mesh
Pointer to the MooseMesh object.
bool has_boundary_id(const Node *const node, const boundary_id_type id) const
std::map< const Elem *, const CouplingMatrix *, CompareDofObjectsByPIDAndThenID > map_type
const MeshBase * _mesh
const BoundaryInfo & get_boundary_info() const
unsigned int mesh_dimension() const
const BoundaryID INVALID_BOUNDARY_ID
Definition MooseTypes.C:22
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
uint8_t processor_id_type