ug4
compol_selection.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_selection__
34 #define __H__UG__compol_selection__
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 
55  ComPol_Selection(ISelector& sel, bool select = true, bool deselect = true)
56  : m_sel(sel), m_bSelectAllowed(select), m_bDeselectAllowed(deselect)
57  {}
58 
59  virtual int
61  {return interface.size() * sizeof(byte);}
62 
64  virtual bool
65  collect(ug::BinaryBuffer& buff, const Interface& interface)
66  {
67  // write the entry indices of marked elements.
68  for(InterfaceIter iter = interface.begin();
69  iter != interface.end(); ++iter)
70  {
71  Element elem = interface.get_element(iter);
72  byte refMark = m_sel.get_selection_status(elem);
73  buff.write((char*)&refMark, sizeof(byte));
74  }
75 
76  return true;
77  }
78 
80  virtual bool
81  extract(ug::BinaryBuffer& buff, const Interface& interface)
82  {
83  byte val;
84  for(InterfaceIter iter = interface.begin();
85  iter != interface.end(); ++iter)
86  {
87  Element elem = interface.get_element(iter);
88  buff.read((char*)&val, sizeof(byte));
89  if(val && select_allowed())
90  m_sel.select(elem, val);
91  else if(!val && deselect_allowed())
92  m_sel.deselect(elem);
93  }
94  return true;
95  }
96 
97  protected:
98  inline bool select_allowed() {return m_bSelectAllowed;}
99  inline bool deselect_allowed() {return m_bDeselectAllowed;}
100 
104 };
105 
106 
107 
109 
112 template <class TLayout>
114 {
115  public:
116  typedef TLayout Layout;
117  typedef typename Layout::Type GeomObj;
118  typedef typename Layout::Element Element;
119  typedef typename Layout::Interface Interface;
120  typedef typename Interface::const_iterator InterfaceIter;
121 
123  : m_sel(sel), m_stateBits(stateBits)
124  {}
125 
126  virtual int
128  {return interface.size() * sizeof(byte);}
129 
131  virtual bool
132  collect(ug::BinaryBuffer& buff, const Interface& interface)
133  {
134  // write the entry indices of marked elements.
135  for(InterfaceIter iter = interface.begin();
136  iter != interface.end(); ++iter)
137  {
138  Element elem = interface.get_element(iter);
139  byte refMark = m_sel.get_selection_status(elem);
140  buff.write((char*)&refMark, sizeof(byte));
141  }
142 
143  return true;
144  }
145 
147  virtual bool
148  extract(ug::BinaryBuffer& buff, const Interface& interface)
149  {
150  byte val;
151  for(InterfaceIter iter = interface.begin();
152  iter != interface.end(); ++iter)
153  {
154  Element elem = interface.get_element(iter);
155  buff.read((char*)&val, sizeof(byte));
157  | (val & m_stateBits));
158  }
159  return true;
160  }
161 
164 };
165 
166 }// end of namespace
167 
168 #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_selection.h:114
virtual bool extract(ug::BinaryBuffer &buff, const Interface &interface)
reads marks from the given stream
Definition: compol_selection.h:148
Layout::Element Element
Definition: compol_selection.h:118
Layout::Type GeomObj
Definition: compol_selection.h:117
ISelector & m_sel
Definition: compol_selection.h:162
Layout::Interface Interface
Definition: compol_selection.h:119
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_selection.h:127
virtual bool collect(ug::BinaryBuffer &buff, const Interface &interface)
writes writes the selection states of the interface entries
Definition: compol_selection.h:132
byte m_stateBits
Definition: compol_selection.h:163
ComPol_EnableSelectionStateBits(ISelector &sel, byte stateBits)
Definition: compol_selection.h:122
Interface::const_iterator InterfaceIter
Definition: compol_selection.h:120
TLayout Layout
Definition: compol_selection.h:116
Definition: compol_selection.h:43
TLayout Layout
Definition: compol_selection.h:45
bool deselect_allowed()
Definition: compol_selection.h:99
Layout::Element Element
Definition: compol_selection.h:47
virtual bool extract(ug::BinaryBuffer &buff, const Interface &interface)
reads marks from the given stream
Definition: compol_selection.h:81
bool select_allowed()
Definition: compol_selection.h:98
bool m_bDeselectAllowed
Definition: compol_selection.h:103
Layout::Type GeomObj
Definition: compol_selection.h:46
bool m_bSelectAllowed
Definition: compol_selection.h:102
virtual bool collect(ug::BinaryBuffer &buff, const Interface &interface)
writes 1 for selected and 0 for unselected interface entries
Definition: compol_selection.h:65
ISelector & m_sel
Definition: compol_selection.h:101
ComPol_Selection(ISelector &sel, bool select=true, bool deselect=true)
Construct the communication policy with a ug::Selector.
Definition: compol_selection.h:55
Layout::Interface Interface
Definition: compol_selection.h:48
Interface::const_iterator InterfaceIter
Definition: compol_selection.h:49
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_selection.h:60
base-implementation of a selector
Definition: selector_interface.h:126
void select(GridObject *elem, byte status)
selects an element
Definition: selector_interface_impl.hpp:56
byte get_selection_status(GridObject *elem) const
returns the selection state of the specified elelent
Definition: selector_interface_impl.hpp:125
void deselect(GridObject *elem)
Definition: selector_interface_impl.hpp:96
unsigned char byte
Definition: types.h:113
the ug namespace