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
21{
23 params.addRequiredParam<BoundaryName>("primary_boundary",
24 "The name of the primary boundary sideset.");
25 params.addRequiredParam<BoundaryName>("secondary_boundary",
26 "The name of the secondary boundary sideset.");
27 params.addRequiredParam<bool>("enabled", "Whether this relationship manager should ghost.");
29 "Ghosts full-dimensional elements with sides on the primary boundary to processors that own "
30 "full-dimensional elements with sides on the secondary boundary.");
31 return params;
32}
33
35 : RelationshipManager(params),
36 _primary_boundary_name(getParam<BoundaryName>("primary_boundary")),
37 _secondary_boundary_name(getParam<BoundaryName>("secondary_boundary")),
38 _enabled(getParam<bool>("enabled"))
39{
40}
41
43 : RelationshipManager(other),
44 _primary_boundary_name(other._primary_boundary_name),
45 _secondary_boundary_name(other._secondary_boundary_name),
46 _enabled(other._enabled)
47{
48}
49
50void
54
55std::string
57{
58 std::ostringstream oss;
59 oss << "GhostPrimaryFace" << (_enabled ? "" : " (disabled)");
60 return oss.str();
61}
62
63bool
64GhostPrimaryFace::hasSecondaryBoundaryFace(const MeshBase::const_element_iterator & range_begin,
65 const MeshBase::const_element_iterator & range_end,
66 const BoundaryID secondary_boundary_id,
67 const bool generating_mesh) const
68{
69 const auto mesh_dim = _mesh->mesh_dimension();
70 const BoundaryInfo & binfo = _mesh->get_boundary_info();
71
72 for (const Elem * const elem : as_range(range_begin, range_end))
73 {
74 if (elem->dim() != mesh_dim)
75 continue;
76
77 if (generating_mesh)
78 {
79 // Boundary ids may not exist yet while generating the mesh, so treat any
80 // full-dimensional boundary element as being on the requested boundary.
81 if (elem->on_boundary())
82 return true;
83 }
84 else
85 for (const auto side : elem->side_index_range())
86 if (binfo.has_boundary_id(elem, side, secondary_boundary_id))
87 return true;
88 }
89
90 return false;
91}
92
93void
94GhostPrimaryFace::operator()(const MeshBase::const_element_iterator & range_begin,
95 const MeshBase::const_element_iterator & range_end,
96 const processor_id_type p,
97 map_type & coupled_elements)
98{
99 if (!_enabled)
100 return;
101
102 const bool generating_mesh = !_moose_mesh->getMeshPtr();
103 const auto primary_boundary_id = generating_mesh
106 const auto secondary_boundary_id = generating_mesh
109
110 if (!hasSecondaryBoundaryFace(range_begin, range_end, secondary_boundary_id, generating_mesh))
111 return;
112
113 const auto mesh_dim = _mesh->mesh_dimension();
114 const BoundaryInfo & binfo = _mesh->get_boundary_info();
115
116 for (const Elem * const elem : _mesh->active_element_ptr_range())
117 {
118 if (elem->processor_id() == p || elem->dim() != mesh_dim)
119 continue;
120
121 if (generating_mesh)
122 {
123 // Boundary ids may not exist yet while generating the mesh, so ghost any
124 // full-dimensional boundary element.
125 if (elem->on_boundary())
126 coupled_elements.emplace(elem, _null_mat);
127 }
128 else
129 for (const auto side : elem->side_index_range())
130 if (binfo.has_boundary_id(elem, side, primary_boundary_id))
131 {
132 coupled_elements.emplace(elem, _null_mat);
133 break;
134 }
135 }
136}
137
138bool
140{
141 const auto * const primary_face = dynamic_cast<const GhostPrimaryFace *>(&other);
142 if (!primary_face || !baseGreaterEqual(*primary_face))
143 return false;
144
145 // An enabled instance subsumes an otherwise compatible disabled instance, which adds no
146 // ghosting entries.
147 if (_enabled && !primary_face->_enabled)
148 return true;
149
150 // A disabled instance only subsumes another disabled instance.
151 if (!_enabled)
152 return !primary_face->_enabled;
153
154 // Once both are enabled, the two instances must ghost the same boundary pair on the same
155 // mesh to cover the same elements.
156 return primary_face->_enabled && _use_displaced_mesh == primary_face->_use_displaced_mesh &&
157 _primary_boundary_name == primary_face->_primary_boundary_name &&
158 _secondary_boundary_name == primary_face->_secondary_boundary_name;
159}
160
161std::unique_ptr<libMesh::GhostingFunctor>
163{
164 return _app.getFactory().copyConstruct(*this);
165}
boundary_id_type BoundaryID
registerMooseObject("MooseApp", GhostPrimaryFace)
std::unique_ptr< T > copyConstruct(const T &object)
Copy constructs the object object.
Definition Factory.h:358
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.
virtual std::unique_ptr< libMesh::GhostingFunctor > clone() const override
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
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:3506
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition MooseMesh.C:1639
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.
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