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 : #include "groups_util.h"
34 : #include "common/util/string_util.h"
35 :
36 : #include <algorithm>
37 : #include <limits>
38 :
39 : using namespace std;
40 :
41 : namespace ug{
42 :
43 : void
44 0 : CreateFunctionIndexMapping(FunctionIndexMapping& map,
45 : const FunctionGroup& grpFromSmall,
46 : const FunctionGroup& grpToLarge)
47 : {
48 : // clear map
49 : map.clear();
50 :
51 : // check that groups are based on same function pattern
52 0 : if(grpToLarge.function_pattern() != grpFromSmall.function_pattern())
53 0 : UG_THROW("CreateFunctionIndexMapping: groups are not based on same "
54 : "function pattern, thus no mapping can be created.");
55 :
56 : // check that "from group" is contained in "to group"
57 0 : if(!grpToLarge.contains(grpFromSmall))
58 0 : UG_THROW("CreateFunctionIndexMapping: smaller FunctionGroup "
59 : << grpFromSmall << " is not contained in larger Group " <<
60 : grpToLarge<<". Cannot create Mapping.");
61 :
62 : // loop all functions on grpFrom
63 0 : for(size_t from = 0; from < grpFromSmall.size(); ++from)
64 : {
65 : // get unique id of function
66 : const size_t uniqueID = grpFromSmall[from];
67 :
68 : // find unique id of function in grpTo
69 0 : const size_t locIndex = grpToLarge.local_index(uniqueID);
70 :
71 : // set mapping
72 0 : map.push_back(locIndex);
73 : }
74 0 : }
75 :
76 0 : void CreateFunctionIndexMapping(FunctionIndexMapping& map,
77 : const FunctionGroup& grpFrom,
78 : ConstSmartPtr<FunctionPattern> fctPattern)
79 : {
80 0 : FunctionGroup commonFctGroup(fctPattern);
81 0 : commonFctGroup.add_all();
82 0 : CreateFunctionIndexMapping(map, grpFrom, commonFctGroup);
83 0 : }
84 :
85 :
86 : /**
87 : * This function create the union of function groups. Container is clear at beginning.
88 : *
89 : * \param[out] fctGrp Union of Functions
90 : * \param[in] vFctGrp Vector of function group (may contain NULL)
91 : * \param[in] sortFct flag if group should be sorted after adding
92 : */
93 0 : void CreateUnionOfFunctionGroups(FunctionGroup& fctGrp,
94 : const vector<const FunctionGroup*>& vFctGrp,
95 : bool sortFct)
96 : {
97 : // clear group
98 : fctGrp.clear();
99 :
100 : // if empty, nothing to do
101 0 : if(vFctGrp.empty()) return;
102 :
103 : // set underlying subsetHandler
104 : size_t grp = 0;
105 0 : for(; grp < vFctGrp.size(); ++grp)
106 : {
107 0 : if(vFctGrp[grp] == NULL) continue;
108 :
109 : ConstSmartPtr<FunctionPattern> pFctPat = vFctGrp[grp]->function_pattern();
110 0 : if(pFctPat.invalid())
111 0 : UG_THROW("CreateUnionOfFunctionGroups: Function group "
112 : <<grp<<" has NULL as underlying FunctionPattern.");
113 :
114 0 : fctGrp.set_function_pattern(pFctPat);
115 : break;
116 : }
117 :
118 : // if no function group given
119 0 : if(grp == vFctGrp.size()) return;
120 :
121 : // add all Subset groups of the element discs
122 0 : for(size_t i = 0; i < vFctGrp.size(); ++i)
123 : {
124 : // add subset group of elem disc
125 0 : if(vFctGrp[i] != NULL)
126 : {
127 : try{
128 0 : fctGrp.add(*vFctGrp[i]);
129 0 : }UG_CATCH_THROW("Cannot add functions of the Function Group "<< i << ".");
130 : }
131 : }
132 :
133 : // sort iff required
134 0 : if(sortFct) fctGrp.sort();
135 : }
136 :
137 :
138 : } // end namespace ug
|