ug4
domain.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3  * Author: Andreas Vogel
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__LIB_DISC__DOMAIN__
34 #define __H__UG__LIB_DISC__DOMAIN__
35 
38 
39 #include <map>
40 
41 #ifdef UG_PARALLEL
43 #endif
44 
45 namespace ug{
46 
56 
59 {
60  public:
61  typedef unsigned long long int_t;
62 
63  inline int element_type() const {return m_elementType;}
64  inline size_t num_levels() const {return m_numElems.size();}
66  inline size_t num_elements_on_level(size_t lvl) const {return (size_t)m_numElems[lvl];}
68  inline size_t num_surface_elements() const {return (size_t)m_numSurfElems;}
70  inline size_t num_local_elements_on_level(size_t lvl) const {return (size_t)m_numLocalElems[lvl];}
72  inline size_t min_num_local_elements_on_level(size_t lvl) const {return (size_t)m_minNumLocalElems[lvl];}
74  inline size_t max_num_local_elements_on_level(size_t lvl) const {return (size_t)m_maxNumLocalElems[lvl];}
76  inline size_t num_local_ghosts_on_level(size_t lvl) const {return (size_t)m_numLocalGhosts[lvl];}
77 
78  inline size_t num_subsets() const
79  {return m_subsetDims.size();}
80  inline size_t subset_dim(int si) const
81  {return m_subsetDims[si];}
82 
83  inline size_t num_elements() const
84  {
85  int_t total = 0;
86  for(size_t i = 0; i < m_numElems.size(); ++i){
87  total += m_numElems[i];
88  }
89  return (size_t)total;
90  }
91 
92  inline void set_info(GridBaseObjectId elemType,
93  const std::vector<int_t>& numElems,
94  const std::vector<int_t>& numLocalElems,
95  const std::vector<int_t>& minNumLocalElems,
96  const std::vector<int_t>& maxNumLocalElems,
97  const std::vector<int_t>& numLocalGhosts,
98  const std::vector<int_t>& subsetDims,
99  int_t numSurfElems)
100  {m_elementType = elemType;
101  m_numElems = numElems;
102  m_numLocalElems = numLocalElems;
103  m_minNumLocalElems = minNumLocalElems;
104  m_maxNumLocalElems = maxNumLocalElems;
105  m_numLocalGhosts = numLocalGhosts;
106  m_subsetDims = subsetDims;
107  m_numSurfElems = numSurfElems;
108  }
109 
110  std::string to_string() const;
111 
112  private:
114  std::vector<int_t> m_numElems;
115  std::vector<int_t> m_numLocalElems;
116  std::vector<int_t> m_minNumLocalElems;
117  std::vector<int_t> m_maxNumLocalElems;
118  std::vector<int_t> m_numLocalGhosts;
119  std::vector<int_t> m_subsetDims;
121 };
122 
123 
125 
137 template <typename TGrid = MultiGrid, typename TSubsetHandler = MGSubsetHandler>
138 class IDomain
139 {
140  public:
142  typedef TGrid grid_type;
143 
145  typedef TSubsetHandler subset_handler_type;
146 
147  public:
149 
153  IDomain(bool isAdaptive = true);
154 
156  virtual ~IDomain();
157 
159  virtual int get_dim() const = 0;
160 
162  inline SmartPtr<TGrid> grid() {return m_spGrid;};
163 
165  inline const ConstSmartPtr<TGrid> grid() const {return m_spGrid;};
166 
169 
171  inline const ConstSmartPtr<TSubsetHandler> subset_handler() const {return m_spSH;};
172 
174  SPMessageHub message_hub() {return m_spGrid->message_hub();}
175 
177  bool is_adaptive() const {return m_isAdaptive;}
178 
180 
181  bool empty() const {return m_spGrid->num_vertices() == 0;}
182 
184  void update_subset_infos(int rootProc);
185 
187 
189  const DomainInfo& domain_info() const {return m_domainInfo;}
190 
192 
193  void update_domain_info();
194 
196 
198  bool is_parallel() {return m_spGrid->is_parallel();}
199 
201  inline DistributedGridManager* distributed_grid_manager() {return m_spGrid->distributed_grid_manager();}
202 
204 
207  bool create_additional_subset_handler(std::string name);
208 
210  std::vector<std::string> additional_subset_handler_names() const;
211 
214 
217 
220 
223 
225  virtual SPIGeometry3d geometry3d() const = 0;
226 
227  protected:
228  #ifdef UG_PARALLEL
232  int rootProc,
233  pcl::ProcessCommunicator& procCom,
234  SPIGeometry3d geometry,
235  SPRefinementProjector projector = SPNULL);
236 
237  void serialize_projector (
238  BinaryBuffer& bufOut,
239  SPRefinementProjector proj);
240 
242  #endif
243 
246  std::map<std::string, SmartPtr<TSubsetHandler> > m_additionalSH;
247 
249 
253 
255 
258 
262  inline void grid_adaption_callback(const GridMessage_Adaption& msg);
263 
265  inline void grid_creation_callback(const GridMessage_Creation& msg);
266 
270 
271 #ifdef UG_PARALLEL
272  protected:
275  template <class TElem>
276  void count_ghosts(std::vector<DomainInfo::int_t>& numGhostsOnLvlOut);
277 #endif
278 
280  template <class TElem>
282 };
283 
284 
285 template <int d, typename TGrid = MultiGrid, typename TSubsetHandler = MGSubsetHandler>
286 class Domain : public IDomain<TGrid, TSubsetHandler>
287 {
288  private:
291 
292  public:
294  static const int dim = d;
295 
298 
301 
305 
306  public:
308  typedef typename base_type::grid_type grid_type;
309 
312 
313  public:
315 
320  Domain(bool isAdaptive = true);
321  virtual ~Domain() {};
322 
324  virtual int get_dim() const {return dim;}
325 
328 
330  inline const position_attachment_type& position_attachment() const {return m_aPos;}
331 
334 
336  inline const position_accessor_type& position_accessor() const{return m_aaPos;}
337 
338  virtual SPIGeometry3d geometry3d() const {return m_geometry3d;}
339 
340  protected:
344 };
345 
349 
350 } // end namespace ug
351 
352 // end group lib_disc_domain
354 
355 // include implementation
356 #include "domain_impl.h"
357 
358 #endif /* __H__UG__LIB_DISC__DOMAIN__ */
location name
Definition: checkpoint_util.lua:128
Definition: smart_pointer.h:296
Definition: smart_pointer.h:108
Definition: pcl_process_communicator.h:70
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
Definition: domain.h:287
Describes the contents of a domain.
Definition: domain.h:59
A message sent along with "GridRefinement" messages.
Definition: lib_grid_messages.h:91
Definition: lib_grid_messages.h:195
Definition: lib_grid_messages.h:166
describes a physical domain
Definition: domain.h:139
Grid::VertexAttachmentAccessor< position_attachment_type > position_accessor_type
Type of Accessor to the Position Data Attachment.
Definition: domain.h:304
const position_attachment_type & position_attachment() const
const access to Position Attachment
Definition: domain.h:330
virtual ~IDomain()
Destructor.
Definition: domain_impl.h:89
Domain< 3, MultiGrid, MGSubsetHandler > Domain3d
Definition: domain.h:348
MathVector< dim > position_type
Type of position coordinates.
Definition: domain.h:297
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
SmartPtr< TSubsetHandler > subset_handler()
returns Subset Handler
Definition: domain.h:168
TSubsetHandler subset_handler_type
Subset Handler type.
Definition: domain.h:145
size_t min_num_local_elements_on_level(size_t lvl) const
returns the minimum number of elements a process has on a given leven (excluding ghosts)
Definition: domain.h:72
std::vector< int_t > m_minNumLocalElems
Definition: domain.h:116
std::vector< int_t > m_subsetDims
Definition: domain.h:119
base_type::grid_type grid_type
Grid type.
Definition: domain.h:308
size_t num_elements_on_level(size_t lvl) const
returns the global number of elements on the given level (excluding ghosts...)
Definition: domain.h:66
virtual int get_dim() const =0
World Dimension.
DistributedGridManager * distributed_grid_manager()
returns Distributed Grid Manager
Definition: domain.h:201
Domain(bool isAdaptive=true)
Default constructor.
Definition: domain_impl.h:659
std::vector< int_t > m_numElems
Definition: domain.h:114
GridBaseObjectId m_elementType
Definition: domain.h:113
virtual int get_dim() const
World Dimension.
Definition: domain.h:324
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< TGrid > grid()
returns Grid
Definition: domain.h:162
Attachment< position_type > position_attachment_type
Type of Position Attachment.
Definition: domain.h:300
const ConstSmartPtr< TSubsetHandler > subset_handler() const
const access to Subset Handler
Definition: domain.h:171
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
std::vector< int_t > m_maxNumLocalElems
Definition: domain.h:117
virtual SPIGeometry3d geometry3d() const =0
returns the geometry of the domain
bool is_parallel()
returns whether the domain can be used for parallel computations
Definition: domain.h:198
MessageHub::SPCallbackId m_spGridDistributionCallbackID
Definition: domain.h:252
std::string to_string() const
Definition: domain.cpp:42
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
IDomain< TGrid, TSubsetHandler > base_type
base type
Definition: domain.h:290
size_t max_num_local_elements_on_level(size_t lvl) const
returns the maximum number of elements a process has on a given leven (excluding ghosts)
Definition: domain.h:74
void serialize_projector(BinaryBuffer &bufOut, SPRefinementProjector proj)
Definition: domain_impl.h:403
bool m_isAdaptive
Definition: domain.h:256
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
size_t num_local_elements_on_level(size_t lvl) const
returns the local number of elements on the given level (excluding ghosts...)
Definition: domain.h:70
const DomainInfo & domain_info() const
returns information on the current domain
Definition: domain.h:189
SPRefinementProjector deserialize_projector(BinaryBuffer &buf)
Definition: domain_impl.h:429
position_attachment_type & position_attachment()
returns Position Attachment
Definition: domain.h:327
Domain< 1, MultiGrid, MGSubsetHandler > Domain1d
Definition: domain.h:346
Domain< 2, MultiGrid, MGSubsetHandler > Domain2d
Definition: domain.h:347
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
size_t num_local_ghosts_on_level(size_t lvl) const
returns the local number of ghosts on the given level
Definition: domain.h:76
MessageHub::SPCallbackId m_spGridCreationCallbackID
Definition: domain.h:251
virtual SPIGeometry3d geometry3d() const
returns the geometry of the domain
Definition: domain.h:338
std::vector< int_t > m_numLocalGhosts
Definition: domain.h:118
int element_type() const
Definition: domain.h:63
position_accessor_type & position_accessor()
get Position Accessor
Definition: domain.h:333
const position_accessor_type & position_accessor() const
const access to Position Accessor
Definition: domain.h:336
std::map< std::string, SmartPtr< TSubsetHandler > > m_additionalSH
additional subset handlers
Definition: domain.h:246
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
DomainInfo m_domainInfo
Definition: domain.h:254
SmartPtr< TSubsetHandler > m_spSH
Subset Handler.
Definition: domain.h:245
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
const ConstSmartPtr< TGrid > grid() const
const access to Grid
Definition: domain.h:165
size_t num_surface_elements() const
returns the global number of surface elements (elements without children)
Definition: domain.h:68
virtual ~Domain()
Definition: domain.h:321
int_t m_numSurfElems
Definition: domain.h:120
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
size_t num_elements() const
Definition: domain.h:83
SPIGeometry3d m_geometry3d
Definition: domain.h:343
void set_info(GridBaseObjectId elemType, const std::vector< int_t > &numElems, const std::vector< int_t > &numLocalElems, const std::vector< int_t > &minNumLocalElems, const std::vector< int_t > &maxNumLocalElems, const std::vector< int_t > &numLocalGhosts, const std::vector< int_t > &subsetDims, int_t numSurfElems)
Definition: domain.h:92
base_type::subset_handler_type subset_handler_type
Subset Handler type.
Definition: domain.h:311
void update_domain_info()
updates the internal domain-info object.
Definition: domain_impl.h:212
TGrid grid_type
Grid type.
Definition: domain.h:142
position_attachment_type m_aPos
Position Attachment.
Definition: domain.h:341
bool m_adaptionIsActive
Definition: domain.h:257
size_t num_subsets() const
Definition: domain.h:78
position_accessor_type m_aaPos
Accessor.
Definition: domain.h:342
bool is_adaptive() const
returns whether the domain may be used for adaptive refinement
Definition: domain.h:177
size_t subset_dim(int si) const
Definition: domain.h:80
std::vector< int_t > m_numLocalElems
local number of elements excluding ghosts.
Definition: domain.h:115
bool empty() const
returns whether the associated grid is empty
Definition: domain.h:181
size_t num_levels() const
Definition: domain.h:64
const NullSmartPtr SPNULL
The equivalent to NULL for smart pointers.
Definition: smart_pointer.h:90
the ug namespace
GridBaseObjectId
enumeration of the GridBaseObjects that make up a grid.
Definition: grid_base_objects.h:59