ug4
compol_subset.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__compol_subset__
34 #define __H__UG__compol_subset__
36 
37 namespace ug
38 {
39 
40 
41 template <class TLayout>
43 {
44  public:
45  typedef TLayout Layout;
46  typedef typename Layout::Type GeomObj;
47  typedef typename Layout::Element Element;
48  typedef typename Layout::Interface Interface;
49  typedef typename Interface::const_iterator InterfaceIter;
50 
52 
54  ComPol_Subset(ISubsetHandler& sel, bool overwrite = false)
55  : m_sh(sel), m_overwriteEnabled(overwrite)
56  {}
57 
58  virtual int
60  {
61  return interface.size() * sizeof(int);
62  }
63 
65  virtual bool
66  collect(ug::BinaryBuffer& buff, const Interface& interface)
67  {
68  // write the entry indices of marked elements.
69  for(InterfaceIter iter = interface.begin();
70  iter != interface.end(); ++iter)
71  {
72  Element elem = interface.get_element(iter);
73  int si = m_sh.get_subset_index(elem);
74  buff.write((char*)&si, sizeof(int));
75  }
76 
77  return true;
78  }
79 
81  virtual bool
82  extract(ug::BinaryBuffer& buff, const Interface& interface)
83  {
84  int nsi = -1;
85  bool retVal = true;
86  for(InterfaceIter iter = interface.begin();
87  iter != interface.end(); ++iter)
88  {
89  Element elem = interface.get_element(iter);
90  buff.read((char*)&nsi, sizeof(int));
92  m_sh.assign_subset(elem, nsi);
93  }
94  else{
95  if(m_sh.get_subset_index(elem) == -1){
96  m_sh.assign_subset(elem, nsi);
97  }
98  else if(m_sh.get_subset_index(elem) != nsi){
99  // if the subset indices do not match, we have a problem here.
100  retVal = false;
101  }
102  }
103  }
104  return retVal;
105  }
106 
107  protected:
110 };
111 
112 }// end of namespace
113 
114 #endif
specializations are responsible to pack and unpack interface data during communication.
Definition: pcl_communication_structs.h:790
A Buffer for binary data.
Definition: binary_buffer.h:56
void read(char *buf, size_t size)
reads data of the given size (in bytes)
Definition: binary_buffer_impl.h:58
void write(const char *buf, size_t size)
writes data of the given size (in bytes)
Definition: binary_buffer_impl.h:71
Definition: compol_subset.h:43
Layout::Interface Interface
Definition: compol_subset.h:48
virtual int get_required_buffer_size(const Interface &interface)
returns the size of the buffer in bytes, that will be required for interface-communication.
Definition: compol_subset.h:59
Layout::Element Element
Definition: compol_subset.h:47
TLayout Layout
Definition: compol_subset.h:45
ComPol_Subset(ISubsetHandler &sel, bool overwrite=false)
Construct the communication policy with a ug::SubsetHandler.
Definition: compol_subset.h:54
bool m_overwriteEnabled
Definition: compol_subset.h:109
ISubsetHandler & m_sh
Definition: compol_subset.h:108
Interface::const_iterator InterfaceIter
Definition: compol_subset.h:49
virtual bool extract(ug::BinaryBuffer &buff, const Interface &interface)
reads marks from the given stream
Definition: compol_subset.h:82
Layout::Type GeomObj
Definition: compol_subset.h:46
virtual bool collect(ug::BinaryBuffer &buff, const Interface &interface)
writes 1 for selected and 0 for unassigned interface entries
Definition: compol_subset.h:66
Definition: subset_handler_interface.h:223
void assign_subset(TIterator iterBegin, TIterator iterEnd, int subsetIndex)
Definition: subset_handler_interface_impl.hpp:170
int get_subset_index(GridObject *elem) const
Definition: subset_handler_interface.cpp:560
the ug namespace