libMesh
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Static Protected Attributes | Private Attributes | List of all members
AugmentSparsityOnInterface Class Referenceabstract

#include <augment_sparsity_on_interface.h>

Inheritance diagram for AugmentSparsityOnInterface:
[legend]

Public Types

typedef std::map< const Elem *, const CouplingMatrix *, CompareDofObjectsByPIDAndThenID > map_type
 What elements do we care about and what variables do we care about on each element?
 

Public Member Functions

 AugmentSparsityOnInterface (MeshBase &mesh, boundary_id_type crack_boundary_lower, boundary_id_type crack_boundary_upper)
 Constructor.
 
virtual std::unique_ptr< GhostingFunctorclone () const override
 A clone() is needed because GhostingFunctor can not be shared between different meshes.
 
const ElementSideMapget_lower_to_upper () const
 
virtual void operator() (const MeshBase::const_element_iterator &range_begin, const MeshBase::const_element_iterator &range_end, processor_id_type p, map_type &coupled_elements) override
 User-defined function to augment the sparsity pattern.
 
virtual void mesh_reinit () override
 Rebuild the cached _lower_to_upper map whenever our Mesh has changed.
 
virtual void redistribute () override
 Update the cached _lower_to_upper map whenever our Mesh has been redistributed.
 
virtual void set_mesh (const MeshBase *mesh)
 It should be called after cloning a ghosting functor.
 
virtual void set_periodic_boundaries (const PeriodicBoundaries *)
 
const MeshBaseget_mesh () const
 Return the mesh associated with ghosting functor.
 
virtual void operator() (const MeshBase::const_element_iterator &range_begin, const MeshBase::const_element_iterator &range_end, processor_id_type p, map_type &coupled_elements)=0
 For the specified range of active elements, what other elements currently living (whether local or ghosted) on this processor need to be coupled/ghosted to accommodate them? Don't bother to return any results which already have processor_id p.
 
virtual void dofmap_reinit ()
 For algebraic ghosting or coupling functors we also call dofmap_reinit() later, after dofs have been distributed on the new mesh but before the functors have been queried for send_list or sparsity pattern calculations.
 
virtual void delete_remote_elements ()
 GhostingFunctor subclasses with relatively long-lasting caches may want to delete the no-longer-relevant parts of those caches after a redistribution is complete.
 

Static Public Member Functions

static std::string get_info ()
 Gets a string containing the reference information.
 
static void print_info (std::ostream &out_stream=libMesh::out)
 Prints the reference information, by default to libMesh::out.
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects.
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info().
 
static void disable_print_counter_info ()
 

Public Attributes

return nullptr { libmesh_deprecated()
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information.
 

Protected Member Functions

void increment_constructor_count (const std::string &name) noexcept
 Increments the construction counter.
 
void increment_destructor_count (const std::string &name) noexcept
 Increments the destruction counter.
 

Static Protected Attributes

static Counts _counts
 Actually holds the data.
 
static Threads::atomic< unsigned int_n_objects
 The number of objects.
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting.
 
static bool _enable_print_counter = true
 Flag to control whether reference count information is printed when print_info is called.
 

Private Attributes

MeshBase_mesh
 The Mesh we're calculating on.
 
ElementSideMap _lower_to_upper
 A map from (lower element ID, side ID) to matching upper element ID.
 
ElementMap _upper_to_lower
 The inverse (ignoring sides) of the above map.
 
boundary_id_type _crack_boundary_lower
 Boundary IDs for the lower and upper faces of the "crack" in the mesh.
 
boundary_id_type _crack_boundary_upper
 
bool _initialized
 Make sure we've been initialized before use.
 

Detailed Description

Definition at line 19 of file augment_sparsity_on_interface.h.

Member Typedef Documentation

◆ Counts

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

Definition at line 119 of file reference_counter.h.

◆ map_type

typedef std::map<const Elem*, const CouplingMatrix*, CompareDofObjectsByPIDAndThenID> libMesh::GhostingFunctor::map_type
inherited

What elements do we care about and what variables do we care about on each element?

Definition at line 243 of file ghosting_functor.h.

Constructor & Destructor Documentation

◆ AugmentSparsityOnInterface()

AugmentSparsityOnInterface::AugmentSparsityOnInterface ( MeshBase mesh,
boundary_id_type  crack_boundary_lower,
boundary_id_type  crack_boundary_upper 
)

Constructor.

Definition at line 11 of file augment_sparsity_on_interface.C.

13 :
14 _mesh(mesh),
15 _crack_boundary_lower(crack_boundary_lower),
16 _crack_boundary_upper(crack_boundary_upper),
17 _initialized(false)
18{
19 this->mesh_reinit();
20}
boundary_id_type _crack_boundary_lower
Boundary IDs for the lower and upper faces of the "crack" in the mesh.
bool _initialized
Make sure we've been initialized before use.
MeshBase & _mesh
The Mesh we're calculating on.
virtual void mesh_reinit() override
Rebuild the cached _lower_to_upper map whenever our Mesh has changed.
MeshBase & mesh

References mesh_reinit().

Member Function Documentation

◆ clone()

virtual std::unique_ptr< GhostingFunctor > AugmentSparsityOnInterface::clone ( ) const
inlineoverridevirtual

A clone() is needed because GhostingFunctor can not be shared between different meshes.

The operations in GhostingFunctor are mesh dependent.

Implements libMesh::GhostingFunctor.

Definition at line 60 of file augment_sparsity_on_interface.h.

61 {
62 return std::make_unique<AugmentSparsityOnInterface>
64 }

References _crack_boundary_lower, _crack_boundary_upper, and _mesh.

◆ delete_remote_elements()

virtual void libMesh::GhostingFunctor::delete_remote_elements ( )
inlinevirtualinherited

GhostingFunctor subclasses with relatively long-lasting caches may want to delete the no-longer-relevant parts of those caches after a redistribution is complete.

Reimplemented in libMesh::DefaultCoupling, libMesh::GhostPointNeighbors, libMesh::NonManifoldGhostingFunctor, libMesh::OverlapCoupling, and libMesh::PointNeighborCoupling.

Definition at line 293 of file ghosting_functor.h.

293{};

◆ disable_print_counter_info()

void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 100 of file reference_counter.C.

101{
102 _enable_print_counter = false;
103 return;
104}
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called.

References libMesh::ReferenceCounter::_enable_print_counter.

◆ dofmap_reinit()

virtual void libMesh::GhostingFunctor::dofmap_reinit ( )
inlinevirtualinherited

For algebraic ghosting or coupling functors we also call dofmap_reinit() later, after dofs have been distributed on the new mesh but before the functors have been queried for send_list or sparsity pattern calculations.

Definition at line 274 of file ghosting_functor.h.

274{};

◆ enable_print_counter_info()

void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info().

Enabled by default.

Definition at line 94 of file reference_counter.C.

95{
97 return;
98}

References libMesh::ReferenceCounter::_enable_print_counter.

Referenced by libMesh::LibMeshInit::~LibMeshInit().

◆ get_info()

std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

48{
49#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50
51 std::ostringstream oss;
52
53 oss << '\n'
54 << " ---------------------------------------------------------------------------- \n"
55 << "| Reference count information |\n"
56 << " ---------------------------------------------------------------------------- \n";
57
58 for (const auto & [name, cd] : _counts)
59 oss << "| " << name << " reference count information:\n"
60 << "| Creations: " << cd.first << '\n'
61 << "| Destructions: " << cd.second << '\n';
62
63 oss << " ---------------------------------------------------------------------------- \n";
64
65 return oss.str();
66
67#else
68
69 return "";
70
71#endif
72}
static Counts _counts
Actually holds the data.
std::string name(const ElemQuality q)
This function returns a string containing some name for q.

References libMesh::ReferenceCounter::_counts.

Referenced by libMesh::ReferenceCounter::print_info().

◆ get_lower_to_upper()

const ElementSideMap & AugmentSparsityOnInterface::get_lower_to_upper ( ) const
Returns
a const reference to the lower-to-upper element ID map.

Definition at line 22 of file augment_sparsity_on_interface.C.

23{
25 return _lower_to_upper;
26}
ElementSideMap _lower_to_upper
A map from (lower element ID, side ID) to matching upper element ID.
libmesh_assert(ctx)

References _initialized, _lower_to_upper, and libMesh::libmesh_assert().

Referenced by main().

◆ get_mesh()

const MeshBase * libMesh::GhostingFunctor::get_mesh ( ) const
inlineinherited

Return the mesh associated with ghosting functor.

Definition at line 237 of file ghosting_functor.h.

237{ libmesh_assert(_mesh); return _mesh; }

References libMesh::GhostingFunctor::_mesh, and libMesh::libmesh_assert().

◆ increment_constructor_count()

void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

Definition at line 183 of file reference_counter.h.

184{
185 libmesh_try
186 {
187 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188 std::pair<unsigned int, unsigned int> & p = _counts[name];
189 p.first++;
190 }
191 libmesh_catch (...)
192 {
193 auto stream = libMesh::err.get();
194 stream->exceptions(stream->goodbit); // stream must not throw
195 libMesh::err << "Encountered unrecoverable error while calling "
196 << "ReferenceCounter::increment_constructor_count() "
197 << "for a(n) " << name << " object." << std::endl;
198 std::terminate();
199 }
200}
streamT * get()
Rather than implement every ostream/ios/ios_base function, we'll be lazy and make esoteric uses go th...
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition threads.C:30
OStreamProxy err

References libMesh::err, libMesh::BasicOStreamProxy< charT, traits >::get(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< T >::ReferenceCountedObject(), libMesh::ReferenceCountedObject< T >::ReferenceCountedObject(), and libMesh::ReferenceCountedObject< T >::ReferenceCountedObject().

◆ increment_destructor_count()

void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

Definition at line 207 of file reference_counter.h.

208{
209 libmesh_try
210 {
211 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
212 std::pair<unsigned int, unsigned int> & p = _counts[name];
213 p.second++;
214 }
215 libmesh_catch (...)
216 {
217 auto stream = libMesh::err.get();
218 stream->exceptions(stream->goodbit); // stream must not throw
219 libMesh::err << "Encountered unrecoverable error while calling "
220 << "ReferenceCounter::increment_destructor_count() "
221 << "for a(n) " << name << " object." << std::endl;
222 std::terminate();
223 }
224}

References libMesh::err, libMesh::BasicOStreamProxy< charT, traits >::get(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< T >::~ReferenceCountedObject().

◆ mesh_reinit()

void AugmentSparsityOnInterface::mesh_reinit ( )
overridevirtual

Rebuild the cached _lower_to_upper map whenever our Mesh has changed.

Reimplemented from libMesh::GhostingFunctor.

Definition at line 28 of file augment_sparsity_on_interface.C.

29{
30 this->_initialized = true;
31
32 // Loop over all elements (not just local elements) to make sure we find
33 // "neighbor" elements on opposite sides of the crack.
34
35 // Map from (elem, side) to vertex average
36 std::map<std::pair<const Elem *, unsigned char>, Point> lower;
37 std::map<std::pair<const Elem *, unsigned char>, Point> upper;
38
39 // To avoid extraneous allocation when getting element side vertex averages
40 std::unique_ptr<const Elem> side_elem;
41
42 for (const auto & elem : _mesh.active_element_ptr_range())
43 for (auto side : elem->side_index_range())
44 if (elem->neighbor_ptr(side) == nullptr)
45 {
47 {
48 elem->build_side_ptr(side_elem, side);
49
50 lower[std::make_pair(elem, side)] = side_elem->vertex_average();
51 }
52
54 {
55 elem->build_side_ptr(side_elem, side);
56
57 upper[std::make_pair(elem, side)] = side_elem->vertex_average();
58 }
59 }
60
61 // If we're doing a reinit on a distributed mesh then we may not see
62 // all the vertex averages, or even a matching number of vertex averages.
63 // std::size_t n_lower = lower.size();
64 // std::size_t n_upper = upper.size();
65 // libmesh_assert(n_lower == n_upper);
66
67 // Clear _lower_to_upper. This map will be used for matrix assembly later on.
68 _lower_to_upper.clear();
69
70 // Clear _upper_to_lower. This map will be used for element ghosting
71 // on distributed meshes, communication send_list construction in
72 // parallel, and sparsity calculations
73 _upper_to_lower.clear();
74
75 // We do an N^2 search to find elements with matching vertex averages. This could be optimized,
76 // e.g. by first sorting the vertex averages based on their (x,y,z) location.
77 {
78 for (const auto & [lower_key, lower_val] : lower)
79 {
80 // find closest vertex average in upper
81 Real min_distance = std::numeric_limits<Real>::max();
82
83 for (const auto & [upper_key, upper_val] : upper)
84 {
85 Real distance = (upper_val - lower_val).norm();
86 if (distance < min_distance)
87 {
88 min_distance = distance;
89 _lower_to_upper[lower_key] = upper_key.first;
90 }
91 }
92
93 // For pairs with local elements, we should have found a
94 // matching pair by now.
95 const Elem * elem = lower_key.first;
96 const Elem * neighbor = _lower_to_upper[lower_key];
97 if (min_distance < TOLERANCE)
98 {
99 // fill up the inverse map
100 _upper_to_lower[neighbor] = elem;
101 }
102 else
103 {
104 libmesh_assert_not_equal_to(elem->processor_id(), _mesh.processor_id());
105 // This must have a false positive; a remote element would
106 // have been closer.
107 _lower_to_upper.erase(lower_key);
108 }
109 }
110
111 // Let's make sure we didn't miss any upper elements either
112#ifndef NDEBUG
113 for (const auto & upper_pr : upper)
114 {
115 const Elem * neighbor = upper_pr.first.first;
116 if (neighbor->processor_id() != _mesh.processor_id())
117 continue;
118 ElementMap::const_iterator utl_it =
119 _upper_to_lower.find(neighbor);
120 libmesh_assert(utl_it != _upper_to_lower.end());
121 }
122#endif
123 }
124}
ElementMap _upper_to_lower
The inverse (ignoring sides) of the above map.
bool has_boundary_id(const Node *const node, const boundary_id_type id) const
processor_id_type processor_id() const
Definition dof_object.h:881
This is the base class from which all geometric element types are derived.
Definition elem.h:96
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition mesh_base.h:170
processor_id_type processor_id() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
auto norm(const T &a)
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real distance(const Point &p)

References _crack_boundary_lower, _crack_boundary_upper, _initialized, _lower_to_upper, _mesh, _upper_to_lower, distance(), libMesh::MeshBase::get_boundary_info(), libMesh::BoundaryInfo::has_boundary_id(), libMesh::libmesh_assert(), libMesh::DofObject::processor_id(), libMesh::ParallelObject::processor_id(), libMesh::Real, and libMesh::TOLERANCE.

Referenced by AugmentSparsityOnInterface(), and redistribute().

◆ n_objects()

static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 85 of file reference_counter.h.

86 { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.

References libMesh::ReferenceCounter::_n_objects.

Referenced by libMesh::LibMeshInit::~LibMeshInit().

◆ operator()() [1/2]

void AugmentSparsityOnInterface::operator() ( const MeshBase::const_element_iterator range_begin,
const MeshBase::const_element_iterator range_end,
processor_id_type  p,
map_type coupled_elements 
)
overridevirtual

User-defined function to augment the sparsity pattern.

Definition at line 126 of file augment_sparsity_on_interface.C.

131{
133
134 const CouplingMatrix * const null_mat = nullptr;
135
136 for (const auto & elem : as_range(range_begin, range_end))
137 {
138 if (elem->processor_id() != p)
139 coupled_elements.emplace(elem, null_mat);
140
141 for (auto side : elem->side_index_range())
142 if (elem->neighbor_ptr(side) == nullptr)
143 {
144 ElementSideMap::const_iterator ltu_it =
145 _lower_to_upper.find(std::make_pair(elem, side));
146 if (ltu_it != _lower_to_upper.end())
147 {
148 const Elem * neighbor = ltu_it->second;
149 if (neighbor->processor_id() != p)
150 coupled_elements.emplace(neighbor, null_mat);
151 }
152 }
153
154 ElementMap::const_iterator utl_it =
155 _upper_to_lower.find(elem);
156 if (utl_it != _upper_to_lower.end())
157 {
158 const Elem * neighbor = utl_it->second;
159 if (neighbor->processor_id() != p)
160 coupled_elements.emplace(neighbor, null_mat);
161 }
162
163 }
164}
This class defines a coupling matrix.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.

References libMesh::as_range(), libMesh::libmesh_assert(), and libMesh::DofObject::processor_id().

◆ operator()() [2/2]

virtual void libMesh::GhostingFunctor::operator() ( const MeshBase::const_element_iterator range_begin,
const MeshBase::const_element_iterator range_end,
processor_id_type  p,
map_type coupled_elements 
)
pure virtualinherited

For the specified range of active elements, what other elements currently living (whether local or ghosted) on this processor need to be coupled/ghosted to accommodate them? Don't bother to return any results which already have processor_id p.

This API is new, and we should replace "ignoring those on processor p" with "ignoring those which match a predicate functor" eventually.

Implemented in libMesh::DefaultCoupling, libMesh::GhostPointNeighbors, libMesh::NonManifoldGhostingFunctor, libMesh::OverlapCoupling, libMesh::PointNeighborCoupling, libMesh::SiblingCoupling, OverlappingCouplingFunctor, and AugmentSparsityOnNodes.

◆ print_info()

void libMesh::ReferenceCounter::print_info ( std::ostream &  out_stream = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

Definition at line 81 of file reference_counter.C.

82{
84 out_stream << ReferenceCounter::get_info();
85}
static std::string get_info()
Gets a string containing the reference information.

References libMesh::ReferenceCounter::_enable_print_counter, and libMesh::ReferenceCounter::get_info().

Referenced by libMesh::LibMeshInit::~LibMeshInit().

◆ redistribute()

virtual void AugmentSparsityOnInterface::redistribute ( )
inlineoverridevirtual

Update the cached _lower_to_upper map whenever our Mesh has been redistributed.

We'll be lazy and just recalculate from scratch.

Reimplemented from libMesh::GhostingFunctor.

Definition at line 89 of file augment_sparsity_on_interface.h.

90 { this->mesh_reinit(); }

References mesh_reinit().

◆ set_mesh()

virtual void libMesh::GhostingFunctor::set_mesh ( const MeshBase mesh)
inlinevirtualinherited

It should be called after cloning a ghosting functor.

Ghosting functor is mesh dependent

Definition at line 227 of file ghosting_functor.h.

227{ _mesh = mesh; }

References libMesh::GhostingFunctor::_mesh, and mesh.

Referenced by libMesh::DofMap::add_algebraic_ghosting_functor(), and libMesh::DofMap::add_coupling_functor().

◆ set_periodic_boundaries()

virtual void libMesh::GhostingFunctor::set_periodic_boundaries ( const PeriodicBoundaries )
inlinevirtualinherited

Reimplemented in libMesh::DefaultCoupling, and libMesh::PointNeighborCoupling.

Definition at line 231 of file ghosting_functor.h.

231{}

Member Data Documentation

◆ _counts

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

Actually holds the data.

Definition at line 124 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::get_info().

◆ _crack_boundary_lower

boundary_id_type AugmentSparsityOnInterface::_crack_boundary_lower
private

Boundary IDs for the lower and upper faces of the "crack" in the mesh.

Definition at line 43 of file augment_sparsity_on_interface.h.

Referenced by clone(), and mesh_reinit().

◆ _crack_boundary_upper

boundary_id_type AugmentSparsityOnInterface::_crack_boundary_upper
private

Definition at line 43 of file augment_sparsity_on_interface.h.

Referenced by clone(), and mesh_reinit().

◆ _enable_print_counter

bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 143 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info(), and libMesh::ReferenceCounter::print_info().

◆ _initialized

bool AugmentSparsityOnInterface::_initialized
private

Make sure we've been initialized before use.

Definition at line 48 of file augment_sparsity_on_interface.h.

Referenced by get_lower_to_upper(), and mesh_reinit().

◆ _lower_to_upper

ElementSideMap AugmentSparsityOnInterface::_lower_to_upper
private

A map from (lower element ID, side ID) to matching upper element ID.

Here "lower" and "upper" refer to the lower and upper (wrt +z direction) sides of the crack in our mesh.

Definition at line 33 of file augment_sparsity_on_interface.h.

Referenced by get_lower_to_upper(), and mesh_reinit().

◆ _mesh

MeshBase& AugmentSparsityOnInterface::_mesh
private

The Mesh we're calculating on.

Definition at line 26 of file augment_sparsity_on_interface.h.

Referenced by clone(), and mesh_reinit().

◆ _mutex

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 137 of file reference_counter.h.

◆ _n_objects

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

◆ _upper_to_lower

ElementMap AugmentSparsityOnInterface::_upper_to_lower
private

The inverse (ignoring sides) of the above map.

Definition at line 38 of file augment_sparsity_on_interface.h.

Referenced by mesh_reinit().

◆ nullptr

return libMesh::GhostingFunctor::nullptr { libmesh_deprecated()
inherited

Definition at line 220 of file ghosting_functor.h.


The documentation for this class was generated from the following files: