libMesh::SystemSubsetBySubdomain Class Reference

#include <system_subset_by_subdomain.h>

Inheritance diagram for libMesh::SystemSubsetBySubdomain:

List of all members.

Classes

class  SubdomainSelection
class  SubdomainSelectionByList

Public Member Functions

 SystemSubsetBySubdomain (const System &system, const SubdomainSelection &subdomain_selection, const std::set< unsigned int > *const var_nums=NULL)
 SystemSubsetBySubdomain (const System &system, const std::set< subdomain_id_type > &subdomain_ids, const std::set< unsigned int > *const var_nums=NULL)
virtual ~SystemSubsetBySubdomain ()
virtual const std::vector
< unsigned int > & 
dof_ids (void) const
void init (const SubdomainSelection &subdomain_selection)
void init (const std::set< subdomain_id_type > &subdomain_ids)
const Systemget_system (void) const

Static Public Member Functions

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 ()

Protected Types

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

Protected Member Functions

void set_var_nums (const std::set< unsigned int > *const var_nums)
void increment_constructor_count (const std::string &name)
void increment_destructor_count (const std::string &name)

Protected Attributes

std::set< unsigned int > _var_nums
std::vector< unsigned int > _dof_ids
const System_system

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 class represents a subset of the dofs of a System, selected by the subdomain_id and possible the variable numbers. The dofs in the subset will be sorted.

Author:
Tim Kroeger, 2010.

Definition at line 46 of file system_subset_by_subdomain.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::SystemSubsetBySubdomain::SystemSubsetBySubdomain ( const System system,
const SubdomainSelection subdomain_selection,
const std::set< unsigned int > *const   var_nums = NULL 
)

Constructor. The subset will consist of those dofs which are associated to at least one mesh element that has a subdomain id contained in the subdomain_selection. If var_nums is not a NULL pointer, dofs that are associated to a variable number that is not contained in var_nums will not contain to the subset, no matter what elements they belong to.

Definition at line 60 of file system_subset_by_subdomain.C.

References init(), and set_var_nums().

00062                                                                       :
00063     SystemSubset(system),
00064     _var_nums(),
00065     _dof_ids()
00066   {
00067     this->set_var_nums(var_nums);
00068     this->init(subdomain_selection);
00069   }

libMesh::SystemSubsetBySubdomain::SystemSubsetBySubdomain ( const System system,
const std::set< subdomain_id_type > &  subdomain_ids,
const std::set< unsigned int > *const   var_nums = NULL 
)

Constructor. The subset will consist of those dofs which are associated to at least one mesh element that has a subdomain id contained in the set subdomain_ids. If var_nums is not a NULL pointer, dofs that are associated to a variable number that is not contained in var_nums will not contain to the subset, no matter what elements they belong to.

Definition at line 72 of file system_subset_by_subdomain.C.

References init(), and set_var_nums().

00074                                                                       :
00075     SystemSubset(system),
00076     _var_nums(),
00077     _dof_ids()
00078   {
00079     this->set_var_nums(var_nums);
00080     this->init(subdomain_ids);
00081   }

libMesh::SystemSubsetBySubdomain::~SystemSubsetBySubdomain ( void   )  [virtual]

Destructor.

Definition at line 84 of file system_subset_by_subdomain.C.

00085   {
00086   }


Member Function Documentation

void libMesh::ReferenceCounter::disable_print_counter_info (  )  [static, inherited]

Definition at line 106 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

00107 {
00108   _enable_print_counter = false;
00109   return;
00110 }

const std::vector< unsigned int > & libMesh::SystemSubsetBySubdomain::dof_ids ( void   )  const [virtual]

Method that returns the actual set of dofs that the subset consists of. The result will contain local dofs on each processor only and will not contain duplictates.

Implements libMesh::SystemSubset.

Definition at line 90 of file system_subset_by_subdomain.C.

References _dof_ids.

00091   {
00092     return _dof_ids;
00093   }

void libMesh::ReferenceCounter::enable_print_counter_info (  )  [static, inherited]

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.

00101 {
00102   _enable_print_counter = true;
00103   return;
00104 }

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().

00048 {
00049 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
00050 
00051   std::ostringstream oss;
00052 
00053   oss << '\n'
00054       << " ---------------------------------------------------------------------------- \n"
00055       << "| Reference count information                                                |\n"
00056       << " ---------------------------------------------------------------------------- \n";
00057 
00058   for (Counts::iterator it = _counts.begin();
00059        it != _counts.end(); ++it)
00060     {
00061       const std::string name(it->first);
00062       const unsigned int creations    = it->second.first;
00063       const unsigned int destructions = it->second.second;
00064 
00065       oss << "| " << name << " reference count information:\n"
00066           << "|  Creations:    " << creations    << '\n'
00067           << "|  Destructions: " << destructions << '\n';
00068     }
00069 
00070   oss << " ---------------------------------------------------------------------------- \n";
00071 
00072   return oss.str();
00073 
00074 #else
00075 
00076   return "";
00077 
00078 #endif
00079 }

const System & libMesh::SystemSubset::get_system ( void   )  const [inherited]

Returns the System to which we belong.

Definition at line 43 of file system_subset.C.

References libMesh::SystemSubset::_system.

Referenced by libMesh::LinearImplicitSystem::restrict_solve_to().

00044   {
00045     return _system;
00046   }

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, and libMesh::Threads::spin_mtx.

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

00164 {
00165   Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
00166   std::pair<unsigned int, unsigned int>& p = _counts[name];
00167 
00168   p.first++;
00169 }

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, and libMesh::Threads::spin_mtx.

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

00177 {
00178   Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
00179   std::pair<unsigned int, unsigned int>& p = _counts[name];
00180 
00181   p.second++;
00182 }

void libMesh::SystemSubsetBySubdomain::init ( const std::set< subdomain_id_type > &  subdomain_ids  ) 

Initializes the class. Will be called by the constructors. Can also be called manually to update the subset. This is required if (a) the subdomain ids of some elements have changed in the meantime and you want these changes to take effect, or (b) you want to use a different list of subdomain ids now.

Definition at line 196 of file system_subset_by_subdomain.C.

References init().

00197   {
00198     SubdomainSelectionByList selection(subdomain_ids);
00199     this->init(selection);
00200   }

void libMesh::SystemSubsetBySubdomain::init ( const SubdomainSelection subdomain_selection  ) 

Initializes the class. Will be called by the constructors. Can also be called manually to update the subset. This is required if (a) the subdomain ids of some elements have changed in the meantime and you want these changes to take effect, or (b) you want to use a different SubdomainSelection object now.

Definition at line 115 of file system_subset_by_subdomain.C.

References _dof_ids, libMesh::SystemSubset::_system, _var_nums, libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::CommWorld, libMesh::DofMap::dof_indices(), libMesh::DofMap::end_dof(), libMesh::DofMap::first_dof(), libMesh::System::get_dof_map(), libMesh::System::get_mesh(), mesh, libMesh::n_processors(), libMesh::processor_id(), libMesh::Parallel::Communicator::receive(), libMesh::Parallel::Communicator::send(), libMesh::Elem::subdomain_id(), and swap().

Referenced by init(), and SystemSubsetBySubdomain().

00116   {
00117     _dof_ids.clear();
00118 
00119     std::vector<std::vector<dof_id_type> > dof_ids_per_processor(libMesh::n_processors());
00120 
00121     const DofMap & dof_map = _system.get_dof_map();
00122     std::vector<dof_id_type> dof_indices;
00123 
00124     const MeshBase& mesh = _system.get_mesh();
00125     MeshBase::const_element_iterator       el     = mesh.active_local_elements_begin();
00126     const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
00127     for ( ; el != end_el; ++el)
00128       {
00129         const Elem* elem = *el;
00130         if(subdomain_selection(elem->subdomain_id()))
00131           {
00132             std::set<unsigned int>::const_iterator it = _var_nums.begin();
00133             const std::set<unsigned int>::const_iterator itEnd = _var_nums.end();
00134             for (; it!=itEnd; ++it)
00135               {
00136                 dof_map.dof_indices (elem, dof_indices, *it);
00137                 for(size_t i=0; i<dof_indices.size(); i++)
00138                   {
00139                     const dof_id_type dof = dof_indices[i];
00140                     for(unsigned int proc=0; proc<libMesh::n_processors(); proc++)
00141                       {
00142                         if((dof>=dof_map.first_dof(proc)) && (dof<dof_map.end_dof(proc)))
00143                           {
00144                             dof_ids_per_processor[proc].push_back(dof);
00145                           }
00146                       }
00147                   }
00148               }
00149           }
00150       }
00151 
00152     /* Distribute information among processors.  */
00153     std::vector<Parallel::Request> request_per_processor(libMesh::n_processors());
00154     for(unsigned int proc=0; proc<libMesh::n_processors(); proc++)
00155       {
00156         if(proc!=libMesh::processor_id())
00157           {
00158             CommWorld.send(proc,dof_ids_per_processor[proc],request_per_processor[proc]);
00159           }
00160       }
00161     for(unsigned int proc=0; proc<libMesh::n_processors(); proc++)
00162       {
00163         std::vector<dof_id_type> received_dofs;
00164         if(proc==libMesh::processor_id())
00165           {
00166             received_dofs = dof_ids_per_processor[proc];
00167           }
00168         else
00169           {
00170             CommWorld.receive(proc,received_dofs);
00171           }
00172         for(unsigned int i=0; i<received_dofs.size(); i++)
00173           {
00174             _dof_ids.push_back(received_dofs[i]);
00175           }
00176       }
00177 
00178     /* Sort and unique the vector (using the same mechanism as in \p
00179        DofMap::prepare_send_list()).  */
00180     std::sort(_dof_ids.begin(), _dof_ids.end());
00181     std::vector<unsigned int>::iterator new_end = std::unique (_dof_ids.begin(), _dof_ids.end());
00182     std::vector<unsigned int> (_dof_ids.begin(), new_end).swap (_dof_ids);
00183 
00184     /* Wait for sends to be complete.  */
00185     for(unsigned int proc=0; proc<libMesh::n_processors(); proc++)
00186       {
00187         if(proc!=libMesh::processor_id())
00188           {
00189             request_per_processor[proc].wait();
00190           }
00191       }
00192   }

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.

00080   { return _n_objects; }

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().

00089 {
00090   if( _enable_print_counter ) out_stream << ReferenceCounter::get_info();
00091 }

void libMesh::SystemSubsetBySubdomain::set_var_nums ( const std::set< unsigned int > *const   var_nums  )  [protected]

Sets _var_nums to either a copy of var_nums or, if that is NULL, a set of all variable numbers that occur in the system.

Definition at line 97 of file system_subset_by_subdomain.C.

References libMesh::SystemSubset::_system, _var_nums, and libMesh::System::n_vars().

Referenced by SystemSubsetBySubdomain().

00098   {
00099     _var_nums.clear();
00100     if(var_nums!=NULL)
00101       {
00102         _var_nums = *var_nums;
00103       }
00104     else
00105       {
00106         for(unsigned int i=0; i<_system.n_vars(); i++)
00107           {
00108             _var_nums.insert(i);
00109           }
00110       }
00111   }


Member Data Documentation

std::vector<unsigned int> libMesh::SystemSubsetBySubdomain::_dof_ids [protected]

The actual set of the dof ids.

Definition at line 192 of file system_subset_by_subdomain.h.

Referenced by dof_ids(), and init().

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().

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().

const System& libMesh::SystemSubset::_system [protected, inherited]

A reference to the System we belong to.

Definition at line 78 of file system_subset.h.

Referenced by libMesh::SystemSubset::get_system(), init(), and set_var_nums().

std::set<unsigned int> libMesh::SystemSubsetBySubdomain::_var_nums [protected]

The set of all variable numbers that are contained in the subset. This will be set by the constructor to either a copy of its var_nums argument or, if that is NULL, a set of all variable numbers that occur in the system.

Definition at line 187 of file system_subset_by_subdomain.h.

Referenced by init(), and set_var_nums().


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

Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:40 UTC

Hosted By:
SourceForge.net Logo