$extrastylesheet
libMesh::PointLocatorList Class Reference

#include <point_locator_list.h>

Inheritance diagram for libMesh::PointLocatorList:

List of all members.

Public Member Functions

 PointLocatorList (const MeshBase &mesh, const PointLocatorBase *master=NULL)
 ~PointLocatorList ()
virtual void clear ()
virtual void init ()
virtual const Elemoperator() (const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=NULL) const
virtual void enable_out_of_mesh_mode ()
virtual void disable_out_of_mesh_mode ()
virtual void set_close_to_point_tol (Real close_to_point_tol)
virtual void unset_close_to_point_tol ()
bool initialized () const

Static Public Member Functions

static UniquePtr
< PointLocatorBase
build (PointLocatorType t, const MeshBase &mesh, const PointLocatorBase *master=NULL)
static std::string get_info ()
static void print_info (std::ostream &out=libMesh::out)
static unsigned int n_objects ()
static void enable_print_counter_info ()
static void disable_print_counter_info ()

Public Attributes

bool _verbose

Protected Types

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

Protected Member Functions

void increment_constructor_count (const std::string &name)
void increment_destructor_count (const std::string &name)

Protected Attributes

std::vector< std::pair< Point,
const Elem * > > * 
_list
const PointLocatorBase_master
const MeshBase_mesh
bool _initialized
bool _use_close_to_point_tol
Real _close_to_point_tol

Static Protected Attributes

static Counts _counts
static Threads::atomic
< unsigned int > 
_n_objects
static Threads::spin_mutex _mutex
static bool _enable_print_counter = true

Detailed Description

This is a point locator. It locates points in space using a list of element centroids: given a mesh this locator returns the element that is closest to the given point in global coordinates. Note that this may yield severe difficulties in case of extremely distorted elements, e.g. infinite elements.

This list version is not efficient, but especially reliable for the case of finding the closest dim-1 element (nearest-surface-element, e.g. used for projecting boundary conditions from a surface mesh onto a volumetric mesh). It should be noted that this class only works when the element list in the associated mesh object is not modified (like refinement etc). Otherwise, the point locator has to be cleared and re-initialized. Use PointLocatorBase::build() to create objects of this type at run time.

Author:
Daniel Dreyer, 2003

Definition at line 65 of file point_locator_list.h.


Member Typedef Documentation

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts [protected, inherited]

Data structure to log the information. The log is identified by the class name.

Definition at line 113 of file reference_counter.h.


Constructor & Destructor Documentation

libMesh::PointLocatorList::PointLocatorList ( const MeshBase mesh,
const PointLocatorBase master = NULL 
)

Constructor. Needs the mesh which holds the elements that should be identified as being close. Optionally takes a master interpolator. This master helps in saving memory by simply only setting up one list for all point locators. Only the master locator holds a list, the others simply use the master's list.

Definition at line 38 of file point_locator_list.C.

References init().

                                                                    :
  PointLocatorBase (mesh,master),
  _list            (NULL)
{
  // This code will only work if your mesh is the Voroni mesh of it's
  // own elements' centroids.  If your mesh is that regular you might
  // as well hand-code an O(1) algorithm for locating points within
  // it. - RHS
  libmesh_experimental();

  this->init();
}

Destructor.

Definition at line 54 of file point_locator_list.C.

References clear().

{
  this->clear ();
}

Member Function Documentation

UniquePtr< PointLocatorBase > libMesh::PointLocatorBase::build ( PointLocatorType  t,
const MeshBase mesh,
const PointLocatorBase master = NULL 
) [static, inherited]

Builds an PointLocator for the mesh mesh. Optionally takes a master PointLocator to save memory. An UniquePtr<PointLocatorBase> is returned to prevent memory leak. This way the user need not remember to delete the object.

Definition at line 64 of file point_locator_base.C.

References libMesh::Trees::ELEMENTS, libMesh::LIST, libMesh::Trees::LOCAL_ELEMENTS, libMesh::TREE, libMesh::TREE_ELEMENTS, and libMesh::TREE_LOCAL_ELEMENTS.

Referenced by libMesh::MeshBase::point_locator(), and libMesh::MeshBase::sub_point_locator().

{
  switch (t)
    {
    case TREE:
      return UniquePtr<PointLocatorBase>(new PointLocatorTree(mesh, /*Trees::NODES,*/ master));

    case TREE_ELEMENTS:
      return UniquePtr<PointLocatorBase>(new PointLocatorTree(mesh, Trees::ELEMENTS, master));

    case TREE_LOCAL_ELEMENTS:
      return UniquePtr<PointLocatorBase>(new PointLocatorTree(mesh, Trees::LOCAL_ELEMENTS, master));

    case LIST:
      return UniquePtr<PointLocatorBase>(new PointLocatorList(mesh, master));

    default:
      libmesh_error_msg("ERROR: Bad PointLocatorType = " << t);
    }

  libmesh_error_msg("We'll never get here!");
  return UniquePtr<PointLocatorBase>();
}

Clears the locator. Overloaded from base class. This method frees dynamic memory using "delete".

Implements libMesh::PointLocatorBase.

Definition at line 61 of file point_locator_list.C.

References _list, and libMesh::PointLocatorBase::_master.

Referenced by ~PointLocatorList().

{
  // only delete the list when we are the master
  if (this->_list != NULL)
    {
      if (this->_master == NULL)
        {
          // we own the list
          this->_list->clear();
          delete this->_list;
        }
      else
        // someone else owns and therefore deletes the list
        this->_list = NULL;
    }
}

Disables out-of-mesh mode (default). If asked to find a point that is contained in no mesh at all, the point locator will now crash.

Implements libMesh::PointLocatorBase.

Definition at line 207 of file point_locator_list.C.

{
  // This functionality is not yet implemented for PointLocatorList.
  libmesh_not_implemented();
}

Enables out-of-mesh mode. In this mode, if asked to find a point that is contained in no mesh at all, the point locator will return a NULL pointer instead of crashing. Per default, this mode is off.

Implements libMesh::PointLocatorBase.

Definition at line 199 of file point_locator_list.C.

{
  // This functionality is not yet implemented for PointLocatorList.
  libmesh_not_implemented();
}

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

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

{
  _enable_print_counter = true;
  return;
}
std::string libMesh::ReferenceCounter::get_info ( ) [static, inherited]

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

References libMesh::ReferenceCounter::_counts, and libMesh::Quality::name().

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

{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)

  std::ostringstream oss;

  oss << '\n'
      << " ---------------------------------------------------------------------------- \n"
      << "| Reference count information                                                |\n"
      << " ---------------------------------------------------------------------------- \n";

  for (Counts::iterator it = _counts.begin();
       it != _counts.end(); ++it)
    {
      const std::string name(it->first);
      const unsigned int creations    = it->second.first;
      const unsigned int destructions = it->second.second;

      oss << "| " << name << " reference count information:\n"
          << "|  Creations:    " << creations    << '\n'
          << "|  Destructions: " << destructions << '\n';
    }

  oss << " ---------------------------------------------------------------------------- \n";

  return oss.str();

#else

  return "";

#endif
}
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name) [inline, protected, inherited]

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

Definition at line 163 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

{
  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
  std::pair<unsigned int, unsigned int>& p = _counts[name];

  p.first++;
}
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name) [inline, protected, inherited]

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

Definition at line 176 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

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

{
  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
  std::pair<unsigned int, unsigned int>& p = _counts[name];

  p.second++;
}
void libMesh::PointLocatorList::init ( ) [virtual]

Initializes the locator, so that the operator() methods can be used. Overloaded from base class. This method allocates dynamic memory using "new".

Implements libMesh::PointLocatorBase.

Definition at line 80 of file point_locator_list.C.

References libMesh::PointLocatorBase::_initialized, _list, libMesh::PointLocatorBase::_master, libMesh::PointLocatorBase::_mesh, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), end, libMesh::err, libMesh::PointLocatorBase::initialized(), libMesh::libmesh_assert(), libMesh::MeshBase::n_active_elem(), and libMesh::START_LOG().

Referenced by PointLocatorList().

{
  libmesh_assert (!this->_list);

  if (this->_initialized)
    libMesh::err << "ERROR: Already initialized!  Will ignore this call..." << std::endl;

  else
    {
      if (this->_master == NULL)
        {
          START_LOG("init(no master)", "PointLocatorList");

          // We are the master, so we have to build the list.
          // First create it, then get a handy reference, and
          // then try to speed up by reserving space...
          this->_list = new std::vector<std::pair<Point, const Elem *> >;
          std::vector<std::pair<Point, const Elem *> >& my_list = *(this->_list);

          my_list.clear();
          my_list.reserve(this->_mesh.n_active_elem());

          // fill our list with the centroids and element
          // pointers of the mesh.  For this use the handy
          // element iterators.
          MeshBase::const_element_iterator       el  = _mesh.active_elements_begin();
          const MeshBase::const_element_iterator end = _mesh.active_elements_end();

          for (; el!=end; ++el)
            my_list.push_back(std::make_pair((*el)->centroid(), *el));

          STOP_LOG("init(no master)", "PointLocatorList");
        }

      else
        {
          // We are _not_ the master.  Let our _list point to
          // the master's list.  But for this we first transform
          // the master in a state for which we are friends
          // (this should also beware of a bad master pointer?).
          // And make sure the master @e has a list!
          const PointLocatorList* my_master =
            cast_ptr<const PointLocatorList*>(this->_master);

          if (my_master->initialized())
            this->_list = my_master->_list;
          else
            libmesh_error_msg("ERROR: Initialize master first, then servants!");
        }
    }

  // ready for take-off
  this->_initialized = true;
}
bool libMesh::PointLocatorBase::initialized ( ) const [inherited]
Returns:
true when this object is properly initialized and ready for use, false otherwise.

Definition at line 57 of file point_locator_base.C.

References libMesh::PointLocatorBase::_initialized.

Referenced by libMesh::PointLocatorTree::init(), and init().

{
  return this->_initialized;
}
static unsigned int libMesh::ReferenceCounter::n_objects ( ) [inline, static, inherited]

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

Definition at line 79 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

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

  { return _n_objects; }
const Elem * libMesh::PointLocatorList::operator() ( const Point p,
const std::set< subdomain_id_type > *  allowed_subdomains = NULL 
) const [virtual]

Locates the element in which the point with global coordinates p is located, optionally restricted to a set of allowed subdomains. Overloaded from base class.

Implements libMesh::PointLocatorBase.

Definition at line 137 of file point_locator_list.C.

References libMesh::PointLocatorBase::_initialized, _list, libMesh::Elem::active(), libMesh::libmesh_assert(), std::max(), libMesh::Real, libMesh::TypeVector< T >::size_sq(), libMesh::START_LOG(), and libMesh::Elem::subdomain_id().

{
  libmesh_assert (this->_initialized);

  START_LOG("operator()", "PointLocatorList");

  // Ask the list.  This is quite expensive, since
  // we loop through the whole list to try to find
  // the @e nearest element.
  // However, there is not much else to do: when
  // we would use bounding boxes like in a tree,
  // it may happen that a surface element is just
  // in plane with a bounding box face, and quite
  // close to it.  But when a point comes, this
  // point may belong to the bounding box (where the
  // coplanar element does @e not belong to).  Then
  // we would search through the elements in this
  // bounding box, while the other bounding box'es
  // element is closer, but we simply don't consider
  // it!
  //
  // We _can_, however, use size_sq() instead of size()
  // here to avoid repeated calls to std::sqrt(), which is
  // pretty expensive.
  {
    std::vector<std::pair<Point, const Elem *> >& my_list = *(this->_list);

    Real              last_distance_sq = std::numeric_limits<Real>::max();
    const Elem *      last_elem        = NULL;
    const std::size_t max_index        = my_list.size();

    for (std::size_t n=0; n<max_index; n++)
      {
        // Only consider elements in the allowed_subdomains list, if it exists
        if (!allowed_subdomains ||
            allowed_subdomains->count(my_list[n].second->subdomain_id()))
          {
            const Real current_distance_sq = Point(my_list[n].first -p).size_sq();

            if (current_distance_sq < last_distance_sq)
              {
                last_distance_sq = current_distance_sq;
                last_elem        = my_list[n].second;
              }
          }
      }

    // If we found an element, it should be active
    libmesh_assert (!last_elem || last_elem->active());

    // If we found an element and have a restriction list, they better match
    libmesh_assert (!last_elem || !allowed_subdomains || allowed_subdomains->count(last_elem->subdomain_id()));

    STOP_LOG("operator()", "PointLocatorList");

    // return the element
    return last_elem;
  }
}
void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out) [static, inherited]

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

Definition at line 88 of file reference_counter.C.

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

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

void libMesh::PointLocatorList::set_close_to_point_tol ( Real  close_to_point_tol) [virtual]

Set a tolerance to use when determining if a point is contained within the mesh.

Reimplemented from libMesh::PointLocatorBase.

Definition at line 214 of file point_locator_list.C.

{
  // This functionality is not yet implemented for PointLocatorList.
  libmesh_not_implemented();
}

Specify that we do not want to use a user-specified tolerance to determine if a point is contained within the mesh.

Reimplemented from libMesh::PointLocatorBase.

Definition at line 221 of file point_locator_list.C.

{
  // This functionality is not yet implemented for PointLocatorList.
  libmesh_not_implemented();
}

Member Data Documentation

bool libMesh::ReferenceCounter::_enable_print_counter = true [static, protected, inherited]

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

Definition at line 137 of file reference_counter.h.

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

bool libMesh::PointLocatorBase::_initialized [protected, inherited]

true when properly initialized, false otherwise.

Definition at line 153 of file point_locator_base.h.

Referenced by libMesh::PointLocatorTree::init(), init(), libMesh::PointLocatorBase::initialized(), operator()(), and libMesh::PointLocatorTree::operator()().

std::vector<std::pair<Point, const Elem *> >* libMesh::PointLocatorList::_list [protected]

Pointer to the list of element centroids. Only the master has such a list. For servants, this pointer points to the list of the master. Note that it's not a std::list as the name might suggest, but a std::vector.

Definition at line 140 of file point_locator_list.h.

Referenced by clear(), init(), and operator()().

Const pointer to our master, initialized to NULL if none given. When using multiple PointLocators, one can be assigned master and be in charge of something that all can have access to.

Definition at line 143 of file point_locator_base.h.

Referenced by libMesh::PointLocatorTree::clear(), clear(), libMesh::PointLocatorTree::init(), and init().

const MeshBase& libMesh::PointLocatorBase::_mesh [protected, inherited]

constant reference to the mesh in which the point is looked for.

Definition at line 148 of file point_locator_base.h.

Referenced by libMesh::PointLocatorTree::enable_out_of_mesh_mode(), libMesh::PointLocatorTree::init(), init(), and libMesh::PointLocatorTree::perform_linear_search().

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 131 of file reference_counter.h.

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects [static, protected, inherited]

The number of objects. Print the reference count information when the number returns to 0.

Definition at line 126 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().

true if we will use a user-specified tolerance for locating the element.

Definition at line 159 of file point_locator_base.h.

Referenced by libMesh::PointLocatorTree::operator()(), libMesh::PointLocatorBase::set_close_to_point_tol(), and libMesh::PointLocatorBase::unset_close_to_point_tol().

Boolean flag to indicate whether to print out extra info.

Definition at line 135 of file point_locator_base.h.

Referenced by libMesh::PointLocatorTree::operator()().


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