Line data Source code
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__SPATIAL_DISC__SUBSET_ASSEMBLE_UTIL__
34 : #define __H__UG__LIB_DISC__SPATIAL_DISC__SUBSET_ASSEMBLE_UTIL__
35 :
36 : // extern includes
37 : #include <iostream>
38 : #include <vector>
39 :
40 : // other ug4 modules
41 : #include "common/common.h"
42 : #include "lib_grid/tools/subset_group.h"
43 : #include "lib_disc/common/function_group.h"
44 : #include "lib_disc/common/groups_util.h"
45 : #include "lib_disc/spatial_disc/elem_disc/elem_disc_interface.h"
46 :
47 : namespace ug {
48 :
49 : /**
50 : * This function create the union of subsets on which the Element Discretizations
51 : * work.
52 : *
53 : * \param[out] ssGrp Union of Subsets
54 : * \param[in] vElemDisc Vector of element discs, defined for subsets
55 : * \param[in] clearGroup flag if group should be cleared
56 : */
57 :
58 : template <typename TElemIn>
59 0 : void CreateSubsetGroups(std::vector<SubsetGroup>& vSSGrp,
60 : SubsetGroup& unionSSGrp,
61 : std::vector<TElemIn*> vElemDisc,
62 : ConstSmartPtr<ISubsetHandler> pSH)
63 : {
64 : PROFILE_FUNC_GROUP("discretization");
65 : // resize subset group vector
66 0 : vSSGrp.resize(vElemDisc.size());
67 :
68 : // if empty, nothing to do
69 0 : if(vSSGrp.empty()) {unionSSGrp.clear(); return;}
70 :
71 : // create subset group for each elem disc
72 0 : for(size_t i = 0; i < vSSGrp.size(); ++i)
73 : {
74 0 : vSSGrp[i].set_subset_handler(pSH);
75 0 : vSSGrp[i].add(vElemDisc[i]->symb_subsets());
76 : }
77 :
78 : // set underlying subsetHandler
79 0 : unionSSGrp.set_subset_handler(pSH);
80 :
81 : // add all Subset groups of the element discs
82 0 : for(size_t i = 0; i < vSSGrp.size(); ++i)
83 : {
84 : // add subset group of elem disc
85 : try{
86 0 : unionSSGrp.add(vSSGrp[i]);
87 0 : }UG_CATCH_THROW("Cannot add subsets of the Elem Disc "<<i<<" to union of Subsets.");
88 : }
89 : }
90 :
91 :
92 :
93 :
94 : /**
95 : * This function selects from a given set of element discretizations those
96 : * who work on a given subset.
97 : *
98 : * At the same time, pointers are converted
99 : * e.g. from TElemIn=IElemDisc<TDomain> to typename TElemOut=IElemError<TDomain>
100 : *
101 : * \param[out] vSubsetElemDisc Elem Disc items working on subset (pointers type of type TElemOut)
102 : * \param[in] vElemDisc Elem Disc items to select from (pointers type of type TElemIn)
103 : * \param[in] si Subset index
104 : * \param[in] clearVec flag if vector should be cleared
105 : */
106 : template <typename TElemOut, typename TElemIn>
107 0 : void GetElemDiscItemOnSubset(std::vector<TElemOut*>& vSubsetElemDiscOut,
108 : const std::vector<TElemIn*>& vElemDiscIn,
109 : const std::vector<SubsetGroup>& vSSGrp,
110 : int si, bool clearVec=true)
111 : {
112 : // clear Vector
113 0 : if(clearVec) vSubsetElemDiscOut.clear();
114 :
115 : // loop elem discs
116 0 : for(size_t i = 0; i < vElemDiscIn.size(); ++i)
117 : {
118 : // if subset is used, add elem disc to Subset Elem Discs
119 0 : if(vSSGrp[i].contains(si))
120 0 : vSubsetElemDiscOut.push_back(static_cast<TElemOut*>(vElemDiscIn[i]));
121 : }
122 0 : }
123 :
124 : /**
125 : * Legacy version of 'GetElemDiscItemOnSubset' for TElemOut=TElemIn=IElemDisc<TDomain>
126 : */
127 : template <typename TDomain>
128 : void GetElemDiscOnSubset(std::vector<IElemDisc<TDomain>*>& vSubsetElemDisc,
129 : const std::vector<IElemDisc<TDomain>*>& vElemDisc,
130 : const std::vector<SubsetGroup>& vSSGrp,
131 : int si, bool clearVec = true);
132 :
133 :
134 : } // end namespace ug
135 :
136 : #endif /* __H__UG__LIB_DISC__SPATIAL_DISC__SUBSET_ASSEMBLE_UTIL__ */
|