www.mooseframework.org
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
DiracKernelInfo Class Reference

The DiracKernelInfo object is a place where all the Dirac points added by different DiracKernels are collected. More...

#include <DiracKernelInfo.h>

Public Types

typedef std::map< const Elem *, std::pair< std::vector< Point >, std::vector< unsigned int > > > MultiPointMap
 

Public Member Functions

 DiracKernelInfo ()
 
virtual ~DiracKernelInfo ()
 
void addPoint (const Elem *elem, const Point &p)
 Adds a point source. More...
 
void clearPoints ()
 Remove all of the current points and elements. More...
 
bool hasPoint (const Elem *elem, const Point &p)
 Return true if we have Point 'p' in Element 'elem'. More...
 
std::set< const Elem * > & getElements ()
 Returns a writeable reference to the _elements container. More...
 
MultiPointMapgetPoints ()
 Returns a writeable reference to the _points container. More...
 
void updatePointLocator (const MooseMesh &mesh)
 Called during FEProblemBase::meshChanged() to update the PointLocator object used by the DiracKernels. More...
 
const Elem * findPoint (const Point &p, const MooseMesh &mesh, const std::set< SubdomainID > &blocks)
 Used by client DiracKernel classes to determine the Elem in which the Point p resides. More...
 

Protected Member Functions

bool pointsFuzzyEqual (const Point &, const Point &)
 Check if two points are equal with respect to a tolerance. More...
 

Protected Attributes

std::set< const Elem * > _elements
 The list of elements that need distributions. More...
 
MultiPointMap _points
 The list of physical xyz Points that need to be evaluated in each element. More...
 
std::unique_ptr< PointLocatorBase > _point_locator
 The DiracKernelInfo object manages a PointLocator object which is used by all DiracKernels to find Points. More...
 
const Real _point_equal_distance_sq
 threshold distance squared below which two points are considered identical More...
 

Detailed Description

The DiracKernelInfo object is a place where all the Dirac points added by different DiracKernels are collected.

It is used, for example, by the FEProblemBase class to determine if finite element data needs to be recomputed on a given element.

Definition at line 35 of file DiracKernelInfo.h.

Member Typedef Documentation

◆ MultiPointMap

typedef std::map<const Elem *, std::pair<std::vector<Point>, std::vector<unsigned int> > > DiracKernelInfo::MultiPointMap

Definition at line 65 of file DiracKernelInfo.h.

Constructor & Destructor Documentation

◆ DiracKernelInfo()

DiracKernelInfo::DiracKernelInfo ( )

Definition at line 19 of file DiracKernelInfo.C.

21 {
22 }
static constexpr Real TOLERANCE
std::unique_ptr< PointLocatorBase > _point_locator
The DiracKernelInfo object manages a PointLocator object which is used by all DiracKernels to find Po...
const Real _point_equal_distance_sq
threshold distance squared below which two points are considered identical

◆ ~DiracKernelInfo()

DiracKernelInfo::~DiracKernelInfo ( )
virtual

Definition at line 24 of file DiracKernelInfo.C.

24 {}

Member Function Documentation

◆ addPoint()

void DiracKernelInfo::addPoint ( const Elem *  elem,
const Point &  p 
)

Adds a point source.

Parameters
elemPointer to the geometric element in which the point is located
pThe (x,y,z) location of the Dirac point

Definition at line 27 of file DiracKernelInfo.C.

Referenced by DiracKernelBase::addPoint().

28 {
29  _elements.insert(elem);
30 
31  std::pair<std::vector<Point>, std::vector<unsigned int>> & multi_point_list = _points[elem];
32 
33  const unsigned int npoint = multi_point_list.first.size();
34  mooseAssert(npoint == multi_point_list.second.size(),
35  "Different sizes for location and multiplicity data");
36 
37  for (unsigned int i = 0; i < npoint; ++i)
38  if (pointsFuzzyEqual(multi_point_list.first[i], p))
39  {
40  // a point at the same (within a tolerance) location as p exists, increase its multiplicity
41  multi_point_list.second[i]++;
42  return;
43  }
44 
45  // no prior point found at this location, add it with a multiplicity of one
46  multi_point_list.first.push_back(p);
47  multi_point_list.second.push_back(1);
48 }
std::set< const Elem * > _elements
The list of elements that need distributions.
MultiPointMap _points
The list of physical xyz Points that need to be evaluated in each element.
bool pointsFuzzyEqual(const Point &, const Point &)
Check if two points are equal with respect to a tolerance.

◆ clearPoints()

void DiracKernelInfo::clearPoints ( )

Remove all of the current points and elements.

Definition at line 51 of file DiracKernelInfo.C.

Referenced by DisplacedProblem::clearDiracInfo(), FEProblemBase::clearDiracInfo(), and DiracKernelBase::clearPoints().

52 {
53  _elements.clear();
54  _points.clear();
55 }
std::set< const Elem * > _elements
The list of elements that need distributions.
MultiPointMap _points
The list of physical xyz Points that need to be evaluated in each element.

◆ findPoint()

const Elem * DiracKernelInfo::findPoint ( const Point &  p,
const MooseMesh mesh,
const std::set< SubdomainID > &  blocks 
)

Used by client DiracKernel classes to determine the Elem in which the Point p resides.

Uses the PointLocator owned by this object.

Definition at line 111 of file DiracKernelInfo.C.

Referenced by DiracKernelBase::addPoint(), and DiracKernelBase::addPointWithValidId().

114 {
115  // If the PointLocator has never been created, do so now. NOTE - WE
116  // CAN'T DO THIS if findPoint() is only called on some processors,
117  // PointLocatorBase::build() is a 'parallel_only' method!
118  if (_point_locator.get() == NULL)
119  {
120  _point_locator = PointLocatorBase::build(TREE_LOCAL_ELEMENTS, mesh);
121  _point_locator->enable_out_of_mesh_mode();
122  }
123 
124  // Check that the PointLocator is ready to start locating points.
125  // So far I do not have any tests that trip this...
126  if (_point_locator->initialized() == false)
127  mooseError("Error, PointLocator is not initialized!");
128 
129  // Note: The PointLocator object returns NULL when the Point is not
130  // found within the Mesh. This is not considered to be an error as
131  // far as the DiracKernels are concerned: sometimes the Mesh moves
132  // out from the Dirac point entirely and in that case the Point just
133  // gets "deactivated".
134  const Elem * elem = (*_point_locator)(p, &blocks);
135 
136  // The processors may not agree on which Elem the point is in. This
137  // can happen if a Dirac point lies on the processor boundary, and
138  // two or more neighboring processors think the point is in the Elem
139  // on *their* side.
140  dof_id_type elem_id = elem ? elem->id() : DofObject::invalid_id;
141 
142  // We are going to let the element with the smallest ID "win", all other
143  // procs will return NULL.
144  dof_id_type min_elem_id = elem_id;
145  mesh.comm().min(min_elem_id);
146 
147  return min_elem_id == elem_id ? elem : NULL;
148 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
MeshBase & mesh
std::unique_ptr< PointLocatorBase > _point_locator
The DiracKernelInfo object manages a PointLocator object which is used by all DiracKernels to find Po...
uint8_t dof_id_type

◆ getElements()

std::set<const Elem *>& DiracKernelInfo::getElements ( )
inline

Returns a writeable reference to the _elements container.

Definition at line 62 of file DiracKernelInfo.h.

Referenced by DisplacedProblem::getDiracElements(), FEProblemBase::getDiracElements(), and DiracKernelBase::hasPointsOnElem().

62 { return _elements; }
std::set< const Elem * > _elements
The list of elements that need distributions.

◆ getPoints()

MultiPointMap& DiracKernelInfo::getPoints ( )
inline

Returns a writeable reference to the _points container.

Definition at line 70 of file DiracKernelInfo.h.

Referenced by DisplacedProblem::reinitDirac(), and FEProblemBase::reinitDirac().

70 { return _points; }
MultiPointMap _points
The list of physical xyz Points that need to be evaluated in each element.

◆ hasPoint()

bool DiracKernelInfo::hasPoint ( const Elem *  elem,
const Point &  p 
)

Return true if we have Point 'p' in Element 'elem'.

Definition at line 58 of file DiracKernelInfo.C.

Referenced by DiracKernelBase::isActiveAtPoint().

59 {
60  std::vector<Point> & point_list = _points[elem].first;
61 
62  for (const auto & pt : point_list)
63  if (pointsFuzzyEqual(pt, p))
64  return true;
65 
66  // If we haven't found it, we don't have it.
67  return false;
68 }
MultiPointMap _points
The list of physical xyz Points that need to be evaluated in each element.
bool pointsFuzzyEqual(const Point &, const Point &)
Check if two points are equal with respect to a tolerance.

◆ pointsFuzzyEqual()

bool DiracKernelInfo::pointsFuzzyEqual ( const Point &  a,
const Point &  b 
)
protected

Check if two points are equal with respect to a tolerance.

Definition at line 151 of file DiracKernelInfo.C.

Referenced by addPoint(), and hasPoint().

152 {
153  const Real dist_sq = (a - b).norm_sq();
154  return dist_sq < _point_equal_distance_sq;
155 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
auto norm_sq(const T &a) -> decltype(std::norm(a))
const Real _point_equal_distance_sq
threshold distance squared below which two points are considered identical

◆ updatePointLocator()

void DiracKernelInfo::updatePointLocator ( const MooseMesh mesh)

Called during FEProblemBase::meshChanged() to update the PointLocator object used by the DiracKernels.

Definition at line 71 of file DiracKernelInfo.C.

Referenced by FEProblemBase::meshChangedHelper(), and DisplacedProblem::updateMesh().

72 {
73  // Note: we could update the PointLocator *every* time we call this
74  // function, but that may introduce an unacceptable overhead in
75  // problems which don't need a PointLocator at all. This issue will
76  // most likely become a moot point when we eventually add a shared
77  // "CachingPointLocator" to MOOSE.
78  // _point_locator = PointLocatorBase::build(TREE_LOCAL_ELEMENTS, mesh);
79 
80  // Construct the PointLocator object if *any* processors have Dirac
81  // points. Note: building a PointLocator object is a parallel_only()
82  // function, so this is an all-or-nothing thing.
83  unsigned pl_needs_rebuild = _elements.size();
84  mesh.comm().max(pl_needs_rebuild);
85 
86  if (pl_needs_rebuild)
87  {
88  // PointLocatorBase::build() is a parallel_only function! So we
89  // can't skip building it just becuase our local _elements is
90  // empty, it might be non-empty on some other processor!
91  _point_locator = PointLocatorBase::build(TREE_LOCAL_ELEMENTS, mesh);
92 
93  // We may be querying for points which are not in the semilocal
94  // part of a distributed mesh.
95  _point_locator->enable_out_of_mesh_mode();
96  }
97  else
98  {
99  // There are no elements with Dirac points, but we have been
100  // requested to update the PointLocator so we have to assume the
101  // old one is invalid. Therefore we reset it to NULL... however
102  // adding this line causes the code to hang because it triggers
103  // the PointLocator to be rebuilt in a non-parallel-only segment
104  // of the code later... so it's commented out for now even though
105  // it's probably the right behavior.
106  // _point_locator.reset(NULL);
107  }
108 }
std::set< const Elem * > _elements
The list of elements that need distributions.
MeshBase & mesh
std::unique_ptr< PointLocatorBase > _point_locator
The DiracKernelInfo object manages a PointLocator object which is used by all DiracKernels to find Po...

Member Data Documentation

◆ _elements

std::set<const Elem *> DiracKernelInfo::_elements
protected

The list of elements that need distributions.

Definition at line 92 of file DiracKernelInfo.h.

Referenced by addPoint(), clearPoints(), getElements(), and updatePointLocator().

◆ _point_equal_distance_sq

const Real DiracKernelInfo::_point_equal_distance_sq
protected

threshold distance squared below which two points are considered identical

Definition at line 104 of file DiracKernelInfo.h.

Referenced by pointsFuzzyEqual().

◆ _point_locator

std::unique_ptr<PointLocatorBase> DiracKernelInfo::_point_locator
protected

The DiracKernelInfo object manages a PointLocator object which is used by all DiracKernels to find Points.

It needs to be centrally managed and it also needs to be rebuilt in FEProblemBase::meshChanged() to work with Mesh adaptivity.

Definition at line 101 of file DiracKernelInfo.h.

Referenced by findPoint(), and updatePointLocator().

◆ _points

MultiPointMap DiracKernelInfo::_points
protected

The list of physical xyz Points that need to be evaluated in each element.

Definition at line 95 of file DiracKernelInfo.h.

Referenced by addPoint(), clearPoints(), getPoints(), and hasPoint().


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