ug4
parallel_subset_util_impl.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-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__LIB_GRID__PARALLELL_SUBSET_UTIL_IMPL__
34 #define __H__LIB_GRID__PARALLELL_SUBSET_UTIL_IMPL__
35 
36 #include "../distributed_grid.h"
37 #include "compol_subset.h"
40 
41 namespace ug
42 {
43 template <class TElem>
45  DistributedGridManager& distGridMgr,
47  bool clearContainer)
48 {
49 // get multigrid
50  MultiGrid* pMG = dynamic_cast<MultiGrid*>(distGridMgr.get_assigned_grid());
51  if(!pMG){
52  throw(UGError(" Can't create surface-view. A Multigrid is required.\n"));
53  }
54 
55 // some typedefs
56  typedef typename geometry_traits<TElem>::iterator ElemIter;
57 
58 // clear the target surfaceView
59  if(clearContainer)
60  surfaceViewOut.clear();
61 
62 // iterate through all levels of the mgsh
63  for(size_t level = 0; level < mgsh.num_levels(); ++level){
64 // iterate through all subsets on that level
65  for(int si = 0; si < mgsh.num_subsets(); ++si){
66  // iterate through all elements in the subset on that level
67  for(ElemIter iter = mgsh.begin<TElem>(si, level);
68  iter != mgsh.end<TElem>(si, level); ++iter)
69  {
70  TElem* elem = *iter;
71  // check whether the element has children
72  if(!distGridMgr.is_ghost(elem)){
73  if(!pMG->has_children(elem)){
74  // the element is a part of the surface-view. add it to the handler
75  surfaceViewOut.assign_subset(elem, si);
76  }
77  }
78  }
79  }
80  }
81 }
82 
83 
85 // CreateSurfaceView
86 template <class TSurfaceView>
87 void CreateSurfaceView(TSurfaceView& surfaceViewOut,
88  DistributedGridManager& distGridMgr,
90 {
91 // get multigrid
92  MultiGrid* pMG = dynamic_cast<MultiGrid*>(distGridMgr.get_assigned_grid());
93  if(!pMG){
94  throw(UGError(" Can't create surface-view. A Multigrid is required.\n"));
95  }
96 
97 // This method clears the surfaceViewOut and assigns all objects of
98 // which lie on the surface of the mg to the surface view.
99  CollectSurfaceViewElements<Vertex>(surfaceViewOut, distGridMgr, mgsh, true);
100  CollectSurfaceViewElements<Edge>(surfaceViewOut, distGridMgr, mgsh, false);
101  CollectSurfaceViewElements<Face>(surfaceViewOut, distGridMgr, mgsh, false);
102  CollectSurfaceViewElements<Volume>(surfaceViewOut, distGridMgr, mgsh, false);
103 
104 // assign associated elements of lower dimension to the surface view
105  bool assignSidesOnly = true;
106  if(mgsh.num<Volume>() > 0 && !pMG->option_is_enabled(VOLOPT_AUTOGENERATE_FACES))
107  assignSidesOnly = false;
108  else if(mgsh.num<Volume>() > 0 && !pMG->option_is_enabled(VOLOPT_AUTOGENERATE_EDGES))
109  assignSidesOnly = false;
110  else if(mgsh.num<Face>() > 0 && !pMG->option_is_enabled(FACEOPT_AUTOGENERATE_EDGES))
111  assignSidesOnly = false;
112 
113  if(assignSidesOnly){
114  AssignAssociatedSidesToSubsets<Volume>(surfaceViewOut, mgsh);
115  AssignAssociatedSidesToSubsets<Face>(surfaceViewOut, mgsh);
116  AssignAssociatedSidesToSubsets<Edge>(surfaceViewOut, mgsh);
117  }
118  else
119  {
120  UG_LOG("INFO in CreateSurfaceView: Performing AssignAssociatedLowerDimElemsToSubsets ");
121  UG_LOG("for all elements (Small Performance drawback).\n");
122 
123  AssignAssociatedLowerDimElemsToSubsets<Volume>(surfaceViewOut, mgsh);
124  AssignAssociatedLowerDimElemsToSubsets<Face>(surfaceViewOut, mgsh);
125  AssignAssociatedLowerDimElemsToSubsets<Edge>(surfaceViewOut, mgsh);
126  }
127 
128 // set num subsets for surface view
129 // this needed, when some elements subsets do not appear in this part of the
130 // surface grid. But still, num_subsets() has to return the correct number.
131  if(mgsh.num_subsets() > 0)
132  surfaceViewOut.subset_required(mgsh.num_subsets() - 1);
133 
134 // for a parallel subset handler we have to copy the subset-indices to
135 // avoid problems at interfaces.
136 // This happens e.g. in 2d, where a triangle is an element of the surface view only
137 // on one process. Associated vertices on other processes wouldn't know that
138 // they are surface view element, too. This has to be communicated.
139  ComPol_Subset<VertexLayout> cpSubsetVRT(surfaceViewOut);
140  ComPol_Subset<EdgeLayout> cpSubsetEDGE(surfaceViewOut);
141  ComPol_Subset<FaceLayout> cpSubsetFACE(surfaceViewOut);
142  ComPol_Subset<VolumeLayout> cpSubsetVOL(surfaceViewOut);
147 
148  comVRT.send_data(distGridMgr.grid_layout_map().template get_layout<Vertex>(INT_H_SLAVE), cpSubsetVRT);
149  comEDGE.send_data(distGridMgr.grid_layout_map().template get_layout<Edge>(INT_H_SLAVE), cpSubsetEDGE);
150  comFACE.send_data(distGridMgr.grid_layout_map().template get_layout<Face>(INT_H_SLAVE), cpSubsetFACE);
151  comVOL.send_data(distGridMgr.grid_layout_map().template get_layout<Volume>(INT_H_SLAVE), cpSubsetVOL);
152 
153  comVRT.receive_data(distGridMgr.grid_layout_map().template get_layout<Vertex>(INT_H_MASTER), cpSubsetVRT);
154  comEDGE.receive_data(distGridMgr.grid_layout_map().template get_layout<Edge>(INT_H_MASTER), cpSubsetEDGE);
155  comFACE.receive_data(distGridMgr.grid_layout_map().template get_layout<Face>(INT_H_MASTER), cpSubsetFACE);
156  comVOL.receive_data(distGridMgr.grid_layout_map().template get_layout<Volume>(INT_H_MASTER), cpSubsetVOL);
157 
158  comVRT.communicate();
159  comEDGE.communicate();
160  comFACE.communicate();
161  comVOL.communicate();
162 
163  comVRT.send_data(distGridMgr.grid_layout_map().template get_layout<Vertex>(INT_H_MASTER), cpSubsetVRT);
164  comEDGE.send_data(distGridMgr.grid_layout_map().template get_layout<Edge>(INT_H_MASTER), cpSubsetEDGE);
165  comFACE.send_data(distGridMgr.grid_layout_map().template get_layout<Face>(INT_H_MASTER), cpSubsetFACE);
166  comVOL.send_data(distGridMgr.grid_layout_map().template get_layout<Volume>(INT_H_MASTER), cpSubsetVOL);
167 
168  comVRT.receive_data(distGridMgr.grid_layout_map().template get_layout<Vertex>(INT_H_SLAVE), cpSubsetVRT);
169  comEDGE.receive_data(distGridMgr.grid_layout_map().template get_layout<Edge>(INT_H_SLAVE), cpSubsetEDGE);
170  comFACE.receive_data(distGridMgr.grid_layout_map().template get_layout<Face>(INT_H_SLAVE), cpSubsetFACE);
171  comVOL.receive_data(distGridMgr.grid_layout_map().template get_layout<Volume>(INT_H_SLAVE), cpSubsetVOL);
172 
173  comVRT.communicate();
174  comEDGE.communicate();
175  comFACE.communicate();
176  comVOL.communicate();
177 }
178 
179 
180 }// end of namespace
181 
182 #endif
Performs communication between interfaces on different processes.
Definition: pcl_interface_communicator.h:68
bool communicate(int tag=749345)
sends and receives the collected data.
Definition: pcl_interface_communicator_impl.hpp:409
void send_data(int targetProc, const Interface &interface, ICommunicationPolicy< TLayout > &commPol)
collects data that will be send during communicate.
Definition: pcl_interface_communicator_impl.hpp:80
void receive_data(int srcProc, const Interface &interface, ICommunicationPolicy< TLayout > &commPol)
registers a communication-policy to receive data on communicate.
Definition: pcl_interface_communicator_impl.hpp:188
Definition: compol_subset.h:43
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
MultiGrid * get_assigned_grid()
Definition: distributed_grid.h:97
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
bool option_is_enabled(uint option) const
see set_options for a description of valid parameters.
Definition: grid.cpp:721
Definition: subset_handler_interface.h:223
void assign_subset(TIterator iterBegin, TIterator iterEnd, int subsetIndex)
Definition: subset_handler_interface_impl.hpp:170
void clear()
Definition: subset_handler_interface.cpp:500
int num_subsets() const
returns the number of subset-infos (return value is int, since SubsetIndices are of type int)
Definition: subset_handler_interface.h:317
Definition: multi_grid.h:72
bool has_children(TElem *elem) const
Definition: multi_grid.h:217
Handles subsets on a per level basis.
Definition: subset_handler_multi_grid.h:60
uint num() const
returns the total number of elements
Definition: subset_handler_multi_grid_impl.hpp:202
geometry_traits< TElem >::iterator end(int subsetIndex, int level)
returns the end-iterator for the elements of type TElem in the given subset.
Definition: subset_handler_multi_grid_impl.hpp:64
uint num_levels() const
returns the number of levels
Definition: subset_handler_multi_grid.h:80
geometry_traits< TElem >::iterator begin(int subsetIndex, int level)
returns the begin-iterator for the elements of type TElem in the given subset.
Definition: subset_handler_multi_grid_impl.hpp:44
Instances of this class or of derived classes are thrown if errors arise.
Definition: error.h:104
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
Definition: grid_base_object_traits.h:68
@ VOLOPT_AUTOGENERATE_EDGES
Definition: grid_constants.h:82
@ VOLOPT_AUTOGENERATE_FACES
Definition: grid_constants.h:83
@ FACEOPT_AUTOGENERATE_EDGES
Definition: grid_constants.h:71
#define UG_LOG(msg)
Definition: log.h:367
the ug namespace
void CreateSurfaceView(TSurfaceView &surfaceViewOut, MultiGrid &mg, MGSubsetHandler &mgsh)
Definition: multi_grid_util_impl.hpp:74
@ INT_H_MASTER
horizontal master node
Definition: parallel_grid_layout.h:104
@ INT_H_SLAVE
horizontal slave node
Definition: parallel_grid_layout.h:105
void CollectSurfaceViewElements(ISubsetHandler &surfaceViewOut, MultiGrid &mg, MGSubsetHandler &mgsh, bool clearContainer=true)
Definition: multi_grid_util_impl.hpp:42