33 #ifndef __H__UG__LIB_DISC__DOMAIN_IMPL__
34 #define __H__UG__LIB_DISC__DOMAIN_IMPL__
45 #include <boost/archive/text_oarchive.hpp>
46 #include <boost/archive/text_iarchive.hpp>
60 template <
typename TGr
id,
typename TSubsetHandler>
64 m_spSH(
new TSubsetHandler(*m_spGrid)),
65 m_isAdaptive(isAdaptive),
66 m_adaptionIsActive(false)
88 template <
typename TGr
id,
typename TSubsetHandler>
94 template <
typename TGr
id,
typename TSubsetHandler>
100 TSubsetHandler& sh = *m_spSH;
101 for(
int i = 0; i < sh.num_subsets(); ++i){
103 if(sh.contains_volumes(i))
105 else if(sh.contains_faces(i))
107 else if(sh.contains_edges(i))
109 else if(sh.contains_vertices(i))
112 sh.subset_info(i).set_property(
"dim",
dim);
116 if (rootProc == -2)
return;
125 for(
int i = 0; i < sh.num_subsets(); ++i){
127 Serialize(buf, sh.subset_info(i).get_property(
"dim").to_int());
137 sh.subset_required(numSubsets - 1);
139 for(
int i = 0; i < numSubsets; ++i){
143 sh.subset_info(i).set_property(
"dim",
dim);
151 set_refinement_projector(
152 broadcast_refinement_projector(
153 rootProc, procCom, geometry3d(), m_refinementProjector));
160 template <
typename TGr
id,
typename TSubsetHandler>
166 m_adaptionIsActive =
true;
168 else if(m_adaptionIsActive){
172 update_domain_info();
173 m_adaptionIsActive =
false;
179 UG_THROW(
"Before any grid-adaption may be performed, the domain "
180 "has to be informed that grid-adaption shall begin. "
181 "You may use IRefiner::grid_adaption_begins() or schedule "
182 "an appropriate message to the associated grids message-hub.");
186 template <
typename TGr
id,
typename TSubsetHandler>
194 update_domain_info();
198 template <
typename TGr
id,
typename TSubsetHandler>
210 template <
typename TGr
id,
typename TSubsetHandler>
216 TGrid& mg = *m_spGrid;
217 TSubsetHandler& sh = *m_spSH;
220 if(mg.template num<Volume>() > 0)
222 else if(mg.template num<Face>() > 0)
224 else if(mg.template num<Edge>() > 0)
234 int numLevLocal = m_spGrid->num_levels();
238 if(numLevGlobal > 0){
239 m_spGrid->level_required(numLevGlobal-1);
240 m_spSH->level_required(numLevGlobal-1);
246 elemType = locElemType;
252 std::vector<int_t> subsetDims;
253 subsetDims.reserve(sh.num_subsets());
254 for(
int i = 0; i < sh.num_subsets(); ++i)
255 subsetDims.push_back(sh.subset_info(i).get_property(
"dim").to_int());
257 std::vector<int_t> numLocalGhosts;
261 count_ghosts<Volume>(numLocalGhosts);
264 count_ghosts<Face>(numLocalGhosts);
267 count_ghosts<Edge>(numLocalGhosts);
270 count_ghosts<Vertex>(numLocalGhosts);
273 UG_THROW(
"Unknown base object type");
277 numLocalGhosts.resize(mg.num_levels(), 0);
280 int_t numLocalSurfElems = 0;
281 std::vector<int_t> numLocalElems;
282 numLocalElems.reserve(mg.num_levels());
286 for(
size_t i = 0; i < mg.num_levels(); ++i)
287 numLocalElems.push_back(mg.template num<Volume>(i) - numLocalGhosts[i]);
288 numLocalSurfElems = count_local_unique_surface_elements<Volume>();
291 for(
size_t i = 0; i < mg.num_levels(); ++i)
292 numLocalElems.push_back(mg.template num<Face>(i) - numLocalGhosts[i]);
293 numLocalSurfElems = count_local_unique_surface_elements<Face>();
296 for(
size_t i = 0; i < mg.num_levels(); ++i)
297 numLocalElems.push_back(mg.template num<Edge>(i) - numLocalGhosts[i]);
298 numLocalSurfElems = count_local_unique_surface_elements<Edge>();
301 for(
size_t i = 0; i < mg.num_levels(); ++i)
302 numLocalElems.push_back(mg.template num<Vertex>(i) - numLocalGhosts[i]);
303 numLocalSurfElems = count_local_unique_surface_elements<Vertex>();
306 UG_THROW(
"Unknown base object type");
312 std::vector<int_t> numGlobalElems, minNumLocalElems, maxNumLocalElems;
313 int_t numGlobalSurfElems = 0;
316 numGlobalElems.resize(numLocalElems.size());
317 minNumLocalElems.resize(numLocalElems.size());
318 maxNumLocalElems.resize(numLocalElems.size());
324 numGlobalElems = numLocalElems;
325 minNumLocalElems = numLocalElems;
326 maxNumLocalElems = numLocalElems;
327 numGlobalSurfElems = numLocalSurfElems;
330 m_domainInfo.set_info(elemType, numGlobalElems, numLocalElems, minNumLocalElems,
331 maxNumLocalElems, numLocalGhosts, subsetDims, numGlobalSurfElems);
334 template <
typename TGr
id,
typename TSubsetHandler>
338 if(m_additionalSH[
name].valid())
345 template <
typename TGr
id,
typename TSubsetHandler>
349 typedef typename std::map<std::string, SmartPtr<TSubsetHandler> >::const_iterator iterator_t;
350 std::vector<std::string> names;
351 for(iterator_t iter = m_additionalSH.begin(); iter != m_additionalSH.end(); ++iter){
352 if(iter->second.valid())
353 names.push_back(iter->first);
358 template <
typename TGr
id,
typename TSubsetHandler>
364 UG_THROW(
"Requested additional subset handler with name '" <<
name
365 <<
"' doesn't exist in the given domain!");
370 template <
typename TGr
id,
typename TSubsetHandler>
376 UG_THROW(
"Requested additional subset handler with name '" <<
name
377 <<
"' doesn't exist in the given domain!");
382 template <
typename TGr
id,
typename TSubsetHandler>
386 m_refinementProjector = proj;
391 template <
typename TGr
id,
typename TSubsetHandler>
395 return m_refinementProjector;
401 template <
typename TGr
id,
typename TSubsetHandler>
407 static Archivar<boost::archive::text_oarchive,
421 std::stringstream ss;
422 boost::archive::text_oarchive ar(ss, boost::archive::no_header);
423 archivar.archive(ar, *proj);
427 template <
typename TGr
id,
typename TSubsetHandler>
431 static Archivar<boost::archive::text_iarchive,
448 std::stringstream ss(data, std::ios_base::in);
449 boost::archive::text_iarchive ar(ss, boost::archive::no_header);
450 archivar.archive(ar, *proj);
455 template <
typename TGr
id,
typename TSubsetHandler>
464 const int magicNumber = 3243578;
471 int projectorType = -1;
472 if(projector.
valid()){
482 if (psh == subset_handler().
get())
486 typedef typename std::map<std::string, SmartPtr<TSubsetHandler> >::const_iterator map_it_t;
487 map_it_t it = m_additionalSH.begin();
488 map_it_t it_end = m_additionalSH.end();
489 for (; it != it_end; ++it)
491 if (it->second.get() == psh)
497 UG_COND_THROW(it == it_end,
"Subset handler for projection handler not found "
498 "in list of available subset handlers.");
507 for(
size_t iproj = 0; iproj < numProjectors; ++iproj){
509 serialize_projector(buf, proj);
512 else if(projector.
valid()){
513 serialize_projector(buf, projector);
524 if(projectorType == 1){
528 if (sh_name == std::string(
""))
532 typedef typename std::map<std::string, SmartPtr<TSubsetHandler> >::const_iterator map_it_t;
533 map_it_t it = m_additionalSH.begin();
534 map_it_t it_end = m_additionalSH.end();
535 for (; it != it_end; ++it)
537 if (it->first == sh_name)
543 UG_COND_THROW(it == it_end,
"Subset handler name for projection handler not found "
544 "in list of available names.");
551 size_t numProjectors;
553 for(
size_t iproj = 0; iproj < numProjectors; ++iproj){
557 projector = projHandler;
559 else if(projectorType == 0){
560 projector = deserialize_projector(buf);
562 else if(projectorType == -1){
566 UG_THROW(
"Invalid projector type in 'BroadcastRefinementProjector': "
572 UG_COND_THROW(tmp != magicNumber,
"Magic number mismatch in "
573 "'BroadcastRefinementProjector'. Received "
574 << tmp <<
", but expected " << magicNumber);
584 template <
typename TGr
id,
typename TSubsetHandler>
585 template <
class TElem>
587 count_ghosts(std::vector<DomainInfo::int_t>& numGhostsOnLvlOut)
589 TGrid& mg = *m_spGrid;
593 numGhostsOnLvlOut.
clear();
594 numGhostsOnLvlOut.resize(mg.num_levels(), 0);
600 for(
size_t lvl = 0; lvl < layout.num_levels(); ++lvl){
601 if(lvl >= mg.num_levels())
604 typename Layout::LevelLayout& lvlLayout = layout.layout_on_level(lvl);
605 for(
typename Layout::LevelLayout::iterator iiter = lvlLayout.begin();
606 iiter != lvlLayout.end(); ++iiter)
608 Interface& intfc = lvlLayout.interface(iiter);
609 for(
typename Interface::iterator eiter = intfc.begin();
610 eiter != intfc.end(); ++eiter)
612 if(dgm.
is_ghost(intfc.get_element(eiter)))
613 ++numGhostsOnLvlOut[lvl];
622 template <
typename TGr
id,
typename TSubsetHandler>
623 template <
class TElem>
627 TGrid& mg = *m_spGrid;
634 typedef typename TGrid::template traits<TElem>::iterator iter_t;
635 for(iter_t ielem = mg.template begin<TElem>(); ielem != mg.template end<TElem>(); ++ielem)
639 if(!mg.has_children(e)){
657 template <
int d,
typename TGr
id,
typename TSubsetHandler>
659 Domain(
bool isAdaptive) :
IDomain<TGrid, TSubsetHandler>(isAdaptive)
680 this->
grid()->set_options(gridOpts);
683 m_aPos = GetDefaultPositionAttachment<position_attachment_type>();
686 if(!this->
grid()->
template has_attachment<Vertex>(
m_aPos))
687 this->
grid()->template attach_to<Vertex>(
m_aPos);
location name
Definition: checkpoint_util.lua:128
Definition: smart_pointer.h:296
Definition: smart_pointer.h:108
T * get()
returns encapsulated pointer
Definition: smart_pointer.h:197
bool valid() const
returns true if the pointer is valid, false if not.
Definition: smart_pointer.h:206
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition: smart_pointer.h:212
the standard multi-level-layout implementation
Definition: pcl_communication_structs.h:615
You may add elements to this interface and iterate over them.
Definition: pcl_communication_structs.h:207
Definition: pcl_process_communicator.h:70
void allreduce(const void *sendBuf, void *recBuf, int count, DataType type, ReduceOperation op) const
performs MPI_Allreduce on the processes of the communicator.
Definition: pcl_process_communicator.cpp:318
void broadcast(void *v, size_t size, DataType type, int root=0) const
Definition: pcl_process_communicator.cpp:685
Definition: archivar.h:59
A Buffer for binary data.
Definition: binary_buffer.h:56
manages the layouts and interfaces which are associated with a distributed grid.
Definition: distributed_grid.h:88
bool is_ghost(TElem *elem) const
returns true if the element is a ghost
Definition: distributed_grid_impl.hpp:67
GridLayoutMap & grid_layout_map()
Definition: distributed_grid.h:103
bool contains_status(TGeomObj *o, byte status) const
returns true if the status of the given object contains the given status.
Definition: distributed_grid.h:135
A factory class which creates instances given a class-name.
Definition: factory.h:75
SmartPtr< TBase > create(const std::string &className)
Definition: factory.h:83
const std::string & class_name(const size_t i) const
Definition: factory.h:125
bool access(Grid &grid, TAttachment &a)
Definition: grid.h:189
lets you access layouts by type and key
Definition: parallel_grid_layout.h:152
bool has_layout(const Key &key) const
checks whether the layout associated with the given key exists for the given type.
Definition: parallel_grid_layout_impl.hpp:44
Types< TType >::Layout & get_layout(const Key &key)
creates the required layout if it doesn't exist already.
Definition: parallel_grid_layout_impl.hpp:52
void clear()
Definition: parallel_grid_layout_impl.hpp:118
A message sent along with "GridRefinement" messages.
Definition: lib_grid_messages.h:91
bool adaption_ends() const
tells whether grid adaption has just been started or has been finished.
Definition: lib_grid_messages.cpp:44
bool adaption_begins() const
tells whether grid adaption has just been started or has been finished.
Definition: lib_grid_messages.cpp:38
Definition: lib_grid_messages.h:195
int proc_id() const
Definition: lib_grid_messages.h:201
GridMessageCreationType msg() const
Definition: lib_grid_messages.h:200
Definition: lib_grid_messages.h:166
describes a physical domain
Definition: domain.h:139
Definition: subset_handler_interface.h:223
Associates different projectors with individual subsets.
Definition: projection_handler.h:53
void set_default_projector(SPRefinementProjector projector)
Definition: projection_handler.cpp:113
void set_projector(int subsetIndex, SPRefinementProjector projector)
associate a projector with a given subsetIndex. Note that '-1' is a valid index, too.
Definition: projection_handler.cpp:119
SPRefinementProjector projector(size_t i)
Definition: projection_handler.h:127
size_t num_projectors() const
Definition: projection_handler.h:124
const ISubsetHandler * subset_handler() const
return the subset handler that the projection handler is based on
Definition: projection_handler.h:104
SPRefinementProjector default_projector()
Definition: projection_handler.h:133
Adjusts vertex coordinates during refinement.
Definition: refinement_projector.h:55
virtual void set_geometry(SPIGeometry3d geometry)
Definition: refinement_projector.h:76
virtual ~IDomain()
Destructor.
Definition: domain_impl.h:89
void set_refinement_projector(SPRefinementProjector proj)
sets the ug::RefinementProjector which can be used by refiners during refinement
Definition: domain_impl.h:384
void grid_distribution_callback(const GridMessage_Distribution &msg)
Definition: domain_impl.h:201
Domain(bool isAdaptive=true)
Default constructor.
Definition: domain_impl.h:659
SPRefinementProjector refinement_projector() const
returns the domain's ug::RefinementProjector. The pointer may be invalid.
Definition: domain_impl.h:393
void grid_creation_callback(const GridMessage_Creation &msg)
Called when a domain has been loaded and during domain distribution.
Definition: domain_impl.h:189
SmartPtr< MultiGrid > grid()
returns Grid
Definition: domain.h:162
void update_subset_infos(int rootProc)
updates and broadcasts subset names and dimensions from the given rootProc to all other processes.
Definition: domain_impl.h:96
MessageHub::SPCallbackId m_spGridDistributionCallbackID
Definition: domain.h:252
SmartPtr< TGrid > m_spGrid
Grid.
Definition: domain.h:244
IDomain(bool isAdaptive=true)
Default constructor.
Definition: domain_impl.h:61
SmartPtr< TSubsetHandler > additional_subset_handler(std::string name)
returns an additional subset handler Subset Handler
Definition: domain_impl.h:360
void serialize_projector(BinaryBuffer &bufOut, SPRefinementProjector proj)
Definition: domain_impl.h:403
void grid_adaption_callback(const GridMessage_Adaption &msg)
Definition: domain_impl.h:163
std::vector< std::string > additional_subset_handler_names() const
returns a list with the names of additional subset handlers
Definition: domain_impl.h:347
SPRefinementProjector deserialize_projector(BinaryBuffer &buf)
Definition: domain_impl.h:429
MessageHub::SPCallbackId m_spGridAdaptionCallbackID
Definition: domain.h:250
unsigned long long int_t
Definition: domain.h:61
size_t count_local_unique_surface_elements()
counts local surface elements which are not ghosts or h-slaves
Definition: domain_impl.h:625
MessageHub::SPCallbackId m_spGridCreationCallbackID
Definition: domain.h:251
void count_ghosts(std::vector< DomainInfo::int_t > &numGhostsOnLvlOut)
Definition: domain_impl.h:587
SPMessageHub message_hub()
returns the message hub of the grid
Definition: domain.h:174
static const int dim
World dimension.
Definition: domain.h:294
bool create_additional_subset_handler(std::string name)
creates an additional subset-handler with the given name
Definition: domain_impl.h:336
SPRefinementProjector m_refinementProjector
Definition: domain.h:248
SPRefinementProjector broadcast_refinement_projector(int rootProc, pcl::ProcessCommunicator &procCom, SPIGeometry3d geometry, SPRefinementProjector projector=SPNULL)
helper method to broadcast ug::RefinementProjectors to different processes
Definition: domain_impl.h:457
SPIGeometry3d m_geometry3d
Definition: domain.h:343
void update_domain_info()
updates the internal domain-info object.
Definition: domain_impl.h:212
position_attachment_type m_aPos
Position Attachment.
Definition: domain.h:341
position_accessor_type m_aaPos
Accessor.
Definition: domain.h:342
@ ES_H_SLAVE
Definition: distributed_grid.h:59
@ VRTOPT_STORE_ASSOCIATED_EDGES
Definition: grid_constants.h:48
@ VRTOPT_STORE_ASSOCIATED_FACES
Definition: grid_constants.h:49
@ VRTOPT_STORE_ASSOCIATED_VOLUMES
Definition: grid_constants.h:50
@ GRIDOPT_NONE
Definition: grid_constants.h:91
@ GRIDOPT_AUTOGENERATE_SIDES
sides are automatically created
Definition: grid_constants.h:102
#define PCL_RO_SUM
Definition: pcl_methods.h:63
int ProcRank()
returns the rank of the process
Definition: pcl_base.cpp:83
#define PCL_RO_MAX
Definition: pcl_methods.h:61
#define PCL_RO_MIN
Definition: pcl_methods.h:62
#define PCL_DT_INT
Definition: pcl_datatype.h:51
const NullSmartPtr SPNULL
The equivalent to NULL for smart pointers.
Definition: smart_pointer.h:90
#define UG_THROW(msg)
Definition: error.h:57
unsigned int uint
Definition: types.h:114
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
SM_edge_weight_map< typename T::value_type, ug::BidirectionalMatrix< T > > get(edge_weight_t, ug::BidirectionalMatrix< T > const &g)
Definition: bidirectional_boost.h:157
SmartPtr< RefinementProjector > SPRefinementProjector
Definition: refinement_projector.h:185
boost::mpl::tmp::ProjectorTypes ProjectorTypes
Definition: projectors.h:84
@ GMCT_CREATION_STOPS
Definition: lib_grid_messages.h:191
void Deserialize(TIStream &buf, ParallelVector< T > &v)
Deerialize for ParallelVector<T>
Definition: restart_bridge.cpp:112
SPIGeometry3d MakeGeometry3d(Grid &grid, TAPos aPos)
Utility method to construct an IGeometry3d for a given grid and position attachment.
Definition: geometry.h:163
GridBaseObjectId
enumeration of the GridBaseObjects that make up a grid.
Definition: grid_base_objects.h:59
@ VOLUME
Definition: grid_base_objects.h:63
@ VERTEX
Definition: grid_base_objects.h:60
@ EDGE
Definition: grid_base_objects.h:61
@ FACE
Definition: grid_base_objects.h:62
@ INT_V_MASTER
vertical master node
Definition: parallel_grid_layout.h:106
void Serialize(TOStream &buf, const ParallelVector< T > &v)
Serialize for ParallelVector<T>
Definition: restart_bridge.cpp:103
#define PROFILE_FUNC()
Definition: profiler.h:257
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836
function ProblemDisc new(problemDesc, dom)