33 #ifndef __H__UG_global_attachments
34 #define __H__UG_global_attachments
46 template <
class TAttachment>
48 bool passOnBehaviour =
false)
54 "Attachment with name '" <<
name
55 <<
"' was already declared in GlobalAttachments with a different type. "
57 ", new type: " << typeName);
71 template <
class TAttachment>
75 remove_function_entry<Volume>(ae);
76 remove_function_entry<Face>(ae);
77 remove_function_entry<Edge>(ae);
78 remove_function_entry<Vertex>(ae);
86 const std::string& typeName,
87 bool passOnBehaviour =
false)
90 "Unregistered attachment type used in "
91 <<
"GlobalAttachments::declare_attachment: '"
92 << typeName <<
"' during declaration of attachment '"
97 template <
class TAttachment>
104 static const std::vector<std::string>&
132 if (procId < 0)
return;
139 procComm.
broadcast<std::vector<std::string> >(possible_attachment_names, procId);
141 UG_THROW(
"There are more than one proc loading the grid"<<
142 "please make sure all processes broadcast their GlobalAttachments");
144 std::vector<byte> locDeclared(possible_attachment_names.size(), 0);
145 std::vector<byte> globDeclared(possible_attachment_names.size(), 0);
147 for(
size_t i = 0; i < possible_attachment_names.size(); ++i){
148 byte& b = locDeclared[i];
151 if(GlobalAttachments::is_attached<Vertex>(grid, possible_attachment_names[i]))
153 if(GlobalAttachments::is_attached<Edge>(grid, possible_attachment_names[i]))
155 if(GlobalAttachments::is_attached<Face>(grid, possible_attachment_names[i]))
157 if(GlobalAttachments::is_attached<Volume>(grid, possible_attachment_names[i]))
164 for(
size_t i = 0; i < possible_attachment_names.size(); ++i){
165 byte& b = globDeclared[i];
170 GlobalAttachments::attach<Vertex>(grid, possible_attachment_names[i]);
172 GlobalAttachments::attach<Edge>(grid, possible_attachment_names[i]);
174 GlobalAttachments::attach<Face>(grid, possible_attachment_names[i]);
176 GlobalAttachments::attach<Volume>(grid, possible_attachment_names[i]);
183 template <
class TElem>
192 template <
class TElem>
200 template <
class TAttachment>
205 TAttachment* a =
dynamic_cast<TAttachment*
>(e.
attachment);
206 UG_COND_THROW(!a,
"Attachment with invalid type queried. Given type "
207 "is " << e.
type <<
", queried type is " <<
219 template <
class TElem>
223 const std::string&
name)
231 template <
class TElem>
235 const std::string&
name)
238 function_entry<TElem>(ae).writeFunc(out, grid, *ae.
attachment);
241 template <
class TElem>
245 const std::string&
name)
273 template <
class TElem,
class TAttachment>
276 readFunc = &read_attachment_from_stream<TElem, TAttachment>;
277 writeFunc = &write_attachment_to_stream<TElem, TAttachment>;
278 addSerializer = &add_attachment_serializer<TElem, TAttachment>;
279 attach = &cast_and_attach<TElem, TAttachment>;
288 template <
class TAttachment>
315 for(AttachmentMap::iterator i = m.begin(); i != m.end(); ++i) {
316 if(i->second.attachment)
317 delete i->second.attachment;
333 static bool initialized =
false;
341 template <
class TElem>
355 template <
class TElem>
362 template <
class TElem>
369 template <
class TElem>
372 functions<TElem>().erase(functions<TElem>().begin() + ae.
functionIndex);
375 template <
class TElem,
class TAttachment>
382 TAttachment& a =
dynamic_cast<TAttachment&
>(
attachment);
390 iter != grid.
end<TElem>(); ++iter)
398 template <
class TElem,
class TAttachment>
405 TAttachment& a =
dynamic_cast<TAttachment&
>(
attachment);
424 template <
class TElem,
class TAttachment>
432 TAttachment& a =
dynamic_cast<TAttachment&
>(
attachment);
437 template <
class TElem,
class TAttachment>
443 TAttachment& a =
dynamic_cast<TAttachment&
>(
attachment);
455 register_attachment_type<Attachment<bool> >();
456 register_attachment_type<Attachment<char> >();
457 register_attachment_type<Attachment<byte> >();
458 register_attachment_type<Attachment<int> >();
459 register_attachment_type<Attachment<uint> >();
460 register_attachment_type<Attachment<float> >();
461 register_attachment_type<Attachment<double> >();
463 register_attachment_type<Attachment<vector1> >();
464 register_attachment_type<Attachment<vector2> >();
465 register_attachment_type<Attachment<vector3> >();
466 register_attachment_type<Attachment<vector4> >();
location name
Definition: checkpoint_util.lua:128
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
Serialization callback for grid attachments.
Definition: serialization.h:290
Global attachments are automatically read/written from/to files and are considered during redistribut...
Definition: global_attachments.h:44
static void write_attachment_to_stream(std::ostream &out, Grid &grid, IAttachment &attachment)
Definition: global_attachments.h:400
static bool is_attached(Grid &g, const std::string &name)
Definition: global_attachments.h:194
static void SynchronizeDeclaredGlobalAttachments(Grid &grid, int procId)
Definition: global_attachments.h:130
static FunctionVec & functions()
Definition: global_attachments.h:343
~GlobalAttachments()
Definition: global_attachments.h:312
static AttachmentTypeMap & attachment_types()
Definition: global_attachments.h:332
static const std::vector< std::string > & declared_attachment_names()
Definition: global_attachments.h:105
std::map< std::string, IAttachmentType > AttachmentTypeMap
Definition: global_attachments.h:297
FunctionVec m_functionVecs[4]
Definition: global_attachments.h:473
static GlobalAttachments & inst()
Definition: global_attachments.h:304
static void undeclare_attachment(const std::string &name)
Definition: global_attachments.h:72
static void write_attachment_values(std::ostream &out, Grid &grid, const std::string &name)
Definition: global_attachments.h:233
static std::vector< std::string > & attachment_names()
Definition: global_attachments.h:322
static void attach(Grid &g, const std::string &name)
Definition: global_attachments.h:185
static void register_standard_attachment_types()
Definition: global_attachments.h:450
static AttachmentEntry & attachment_entry(const std::string &name)
Definition: global_attachments.h:348
static void add_attachment_serializer(GridDataSerializationHandler &handler, Grid &g, IAttachment &attachment)
Definition: global_attachments.h:427
std::vector< std::string > m_attachmentNames
Definition: global_attachments.h:470
static bool type_is_registered(const std::string &typeName)
Definition: global_attachments.h:124
static bool attachment_pass_on_behaviour(const std::string &name)
Definition: global_attachments.h:117
static void read_attachment_from_stream(std::istream &in, Grid &grid, IAttachment &attachment)
Definition: global_attachments.h:377
static void read_attachment_values(std::istream &in, Grid &grid, const std::string &name)
Definition: global_attachments.h:221
static void declare_attachment(const std::string &name, bool passOnBehaviour=false)
Definition: global_attachments.h:47
static void add_data_serializer(GridDataSerializationHandler &handler, Grid &grid, const std::string &name)
Definition: global_attachments.h:243
static void register_attachment_type()
Definition: global_attachments.h:98
static void remove_function_entry(const AttachmentEntry &ae)
Definition: global_attachments.h:371
GlobalAttachments()
Definition: global_attachments.h:310
static void declare_attachment(const std::string &name, const std::string &typeName, bool passOnBehaviour=false)
Definition: global_attachments.h:85
std::map< std::string, AttachmentEntry > AttachmentMap
Definition: global_attachments.h:296
static void cast_and_attach(Grid &grid, IAttachment &attachment)
Definition: global_attachments.h:439
std::vector< IFunctionEntry > FunctionVec
Definition: global_attachments.h:298
AttachmentMap m_attachmentMap
Definition: global_attachments.h:471
static IFunctionEntry & function_entry(const AttachmentEntry &ae)
Definition: global_attachments.h:364
static TAttachment attachment(const std::string &name)
Definition: global_attachments.h:202
static bool is_declared(const std::string &name)
Definition: global_attachments.h:111
static const char * type_name(const std::string &name)
Definition: global_attachments.h:213
AttachmentTypeMap m_attachmentTypeMap
Definition: global_attachments.h:472
static AttachmentMap & attachments()
Definition: global_attachments.h:327
static IFunctionEntry & function_entry(const std::string &name)
Definition: global_attachments.h:357
the generic attachment-accessor for access to grids attachment pipes.
Definition: grid.h:182
Serialization of data associated with grid elements.
Definition: serialization.h:186
void add(SPVertexDataSerializer cb)
Adds a callback class for serialization and deserialization.
Definition: serialization.cpp:69
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
void attach_to(IAttachment &attachment, bool passOnValues)
attach with custom pass-on-behaviour and unspecified default value.
Definition: grid_impl.hpp:296
bool has_attachment(IAttachment &attachment)
Definition: grid.h:796
geometry_traits< TGeomObj >::iterator begin()
Definition: grid_impl.hpp:164
geometry_traits< TGeomObj >::iterator end()
Definition: grid_impl.hpp:175
the interface for attachments.
Definition: attachment_pipe.h:239
#define PCL_RO_BOR
Definition: pcl_methods.h:68
#define UG_THROW(msg)
Definition: error.h:57
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
function util LuaCallbackHelper create(func)
Definition: global_attachments.h:256
const char * type
Definition: global_attachments.h:261
int functionIndex
Definition: global_attachments.h:262
AttachmentEntry()
Definition: global_attachments.h:257
IAttachment * attachment
Definition: global_attachments.h:260
AttachmentEntry(IAttachment *a, const char *t, int fi)
Definition: global_attachments.h:258
Definition: global_attachments.h:289
AttachmentType()
Definition: global_attachments.h:290
Definition: global_attachments.h:274
FunctionEntry()
Definition: global_attachments.h:275
Definition: global_attachments.h:283
void(* declareFunc)(const std::string &, bool)
Definition: global_attachments.h:285
IAttachmentType()
Definition: global_attachments.h:284
Definition: global_attachments.h:265
void(* writeFunc)(std::ostream &, Grid &, IAttachment &)
Definition: global_attachments.h:268
void(* readFunc)(std::istream &, Grid &, IAttachment &)
Definition: global_attachments.h:267
void(* addSerializer)(GridDataSerializationHandler &, Grid &, IAttachment &)
Definition: global_attachments.h:269
void(* attach)(Grid &, IAttachment &)
Definition: global_attachments.h:270
IFunctionEntry()
Definition: global_attachments.h:266
geometry_traits< TElem >::iterator iterator
Definition: grid.h:143
Definition: attachment_info_traits.h:46
static const char * type_name()
static void write_value(std::ostream &out, const_reference_type v)
Definition: attachment_io_traits.h:45
static void read_value(std::istream &in, reference_type v)
Definition: attachment_io_traits.h:46