Line data Source code
1 : /*
2 : * Copyright (c) 2013-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 "dof_distribution_info.h"
34 : #include "lib_grid/tools/subset_group.h"
35 : #include "lib_disc/common/function_group.h"
36 : #include "lib_disc/reference_element/reference_element_util.h"
37 : #include "lib_disc/local_finite_element/local_finite_element_provider.h"
38 :
39 : #include "common/log.h"
40 : #include <iostream>
41 : using namespace std;
42 :
43 : namespace ug{
44 :
45 0 : DoFDistributionInfo::DoFDistributionInfo(ConstSmartPtr<ISubsetHandler> spSH)
46 0 : : FunctionPattern(spSH)
47 0 : {}
48 :
49 0 : void DoFDistributionInfo::init()
50 : {
51 : PROFILE_FUNC();
52 : FunctionPattern::lock();
53 0 : create_offsets();
54 0 : }
55 :
56 :
57 0 : void DoFDistributionInfo::create_offsets()
58 : {
59 : PROFILE_FUNC();
60 :
61 : /////////////////////////////////////////////
62 : // resize arrays and reset values to zero
63 : /////////////////////////////////////////////
64 :
65 : // resize for subsets
66 0 : for(int gbo = VERTEX; gbo < NUM_GEOMETRIC_BASE_OBJECTS; ++gbo){
67 0 : m_vMaxDoFsInDim[gbo] = 0;
68 : m_vvMaxDoFsInDimPerSubset[gbo].clear();
69 0 : m_vvMaxDoFsInDimPerSubset[gbo].resize(num_subsets(), 0);
70 : }
71 :
72 0 : for(int roid = ROID_VERTEX; roid < NUM_REFERENCE_OBJECTS; ++roid){
73 0 : m_vMaxDoFsOnROID[roid] = 0;
74 : m_vvNumDoFsOnROIDPerSubset[roid].clear();
75 0 : m_vvNumDoFsOnROIDPerSubset[roid].resize(num_subsets(), 0);
76 : }
77 :
78 : // resize function infos
79 : m_vFctInfo.clear();
80 0 : m_vFctInfo.resize(num_fct());
81 :
82 0 : for(size_t fct = 0; fct < num_fct(); ++fct){
83 :
84 0 : for(int gbo = VERTEX; gbo < NUM_GEOMETRIC_BASE_OBJECTS; ++gbo){
85 0 : m_vFctInfo[fct].vMaxDoFsInDim[gbo] = 0;
86 : m_vFctInfo[fct].vvMaxDoFsInDimPerSubset[gbo].clear();
87 0 : m_vFctInfo[fct].vvMaxDoFsInDimPerSubset[gbo].resize(num_subsets(), 0);
88 : }
89 :
90 0 : for(int roid = ROID_VERTEX; roid < NUM_REFERENCE_OBJECTS; ++roid){
91 0 : m_vFctInfo[fct].vMaxDoFsOnROID[roid] = 0;
92 : m_vFctInfo[fct].vvNumDoFsOnROIDPerSubset[roid].clear();
93 0 : m_vFctInfo[fct].vvNumDoFsOnROIDPerSubset[roid].resize(num_subsets(), 0);
94 :
95 0 : m_vFctInfo[fct].vvOffsets[roid].resize(num_subsets(), NOT_DEF_ON_SUBSET);
96 : }
97 : }
98 :
99 : /////////////////////////////////////////////
100 : // compute values
101 : /////////////////////////////////////////////
102 :
103 : // loop reference element by reference element
104 0 : for(int r = ROID_VERTEX; r < NUM_REFERENCE_OBJECTS; ++r)
105 : {
106 : // get reference element and dimension
107 : const ReferenceObjectID roid = (ReferenceObjectID) r;
108 0 : const int d = ReferenceElementDimension(roid);
109 :
110 : // loop subsets and functions
111 0 : for(int si = 0; si < num_subsets(); ++si)
112 : {
113 0 : for(size_t fct = 0; fct < num_fct(); ++fct)
114 : {
115 : // get dof info for space
116 : const CommonLocalDoFSet& lds =
117 0 : LocalFiniteElementProvider::get_dofs(lfeid(fct));
118 :
119 : // function info
120 : FctInfo& fi = m_vFctInfo[fct];
121 :
122 : // get numDoFs on (fct,roid,si)
123 0 : size_t numFctDoFOnROIDPerSubset = 0;
124 :
125 : // if number specified by the space, set it
126 0 : if(lds.num_dof(roid) != CommonLocalDoFSet::NOT_SPECIFIED)
127 0 : numFctDoFOnROIDPerSubset = (size_t)lds.num_dof(roid);
128 :
129 : // if function not defined on subset, number of DoFs is zero
130 : if(!is_def_in_subset(fct, si))
131 0 : numFctDoFOnROIDPerSubset = 0;
132 :
133 :
134 : ///// Infos on fct //////
135 :
136 :
137 : // set num DoFs (always >= 0)
138 0 : fi.vvNumDoFsOnROIDPerSubset[roid][si] = numFctDoFOnROIDPerSubset;
139 :
140 : // get fct maximum on roid on whole grid (always >= 0)
141 0 : fi.vMaxDoFsOnROID[roid] =
142 0 : std::max(fi.vMaxDoFsOnROID[roid], numFctDoFOnROIDPerSubset);
143 :
144 : // get fct maximum in dimension per subset (always >= 0)
145 0 : fi.vvMaxDoFsInDimPerSubset[d][si] =
146 0 : std::max(fi.vvMaxDoFsInDimPerSubset[d][si], numFctDoFOnROIDPerSubset);
147 :
148 : // get fct maximum in dimension on whole grid (always >= 0)
149 0 : fi.vMaxDoFsInDim[d] =
150 0 : std::max(fi.vMaxDoFsInDim[d], numFctDoFOnROIDPerSubset);
151 :
152 :
153 : ///// Summarize over functions //////
154 :
155 : // set offset for each function defined in the subset
156 0 : fi.vvOffsets[roid][si] = m_vvNumDoFsOnROIDPerSubset[roid][si];
157 :
158 : // count number of dofs on (roid, si)
159 0 : m_vvNumDoFsOnROIDPerSubset[roid][si] += numFctDoFOnROIDPerSubset;
160 :
161 : } // end fct
162 : } // end subset
163 :
164 :
165 : // loop subsets and sum up global maxima
166 0 : for(int si = 0; si < num_subsets(); ++si)
167 : {
168 0 : const size_t numDoFOnROIDPerSubset = m_vvNumDoFsOnROIDPerSubset[roid][si];
169 :
170 : // get maximum in dimension on whole grid (always >= 0)
171 0 : m_vMaxDoFsOnROID[roid] =
172 0 : std::max(m_vMaxDoFsOnROID[roid], numDoFOnROIDPerSubset);
173 :
174 : // get maximum in dimension per subset (always >= 0)
175 0 : m_vvMaxDoFsInDimPerSubset[d][si] =
176 0 : std::max(m_vvMaxDoFsInDimPerSubset[d][si], numDoFOnROIDPerSubset);
177 :
178 : // get maximum on roid on whole grid (always >= 0)
179 0 : m_vMaxDoFsInDim[d] =
180 0 : std::max(m_vMaxDoFsInDim[d], numDoFOnROIDPerSubset);
181 : } // end subset
182 :
183 : } // end roid
184 0 : }
185 :
186 0 : void DoFDistributionInfo::print_local_dof_statistic(int verboseLev) const
187 : {
188 : // Subset informations
189 0 : UG_LOG(num_subsets() << " Subset(s) used (Subset Name, dim): ");
190 0 : for(int si = 0; si < num_subsets(); ++si)
191 : {
192 0 : if(si > 0) UG_LOG(", ");
193 0 : UG_LOG("(" << subset_name(si) << ", " << dim_subset(si) << ")");
194 : }
195 : UG_LOG("\n");
196 :
197 : // Function informations
198 : UG_LOG(num_fct() << " Function(s) defined (Symbolic Name, dim): ");
199 0 : for(size_t fct = 0; fct < num_fct(); ++fct)
200 : {
201 0 : if(fct > 0) UG_LOG(", ");
202 0 : UG_LOG("(" << name(fct) << ", " << dim(fct) << ")");
203 : }
204 : UG_LOG("\n");
205 :
206 : // print subsets of functions
207 0 : if(verboseLev >= 2)
208 : {
209 : UG_LOG("Function definition on subsets: \n");
210 0 : for(size_t fct = 0; fct < num_fct(); ++fct)
211 : {
212 0 : UG_LOG(" "<<name(fct) << ": ");
213 0 : if(is_def_everywhere(fct)) UG_LOG("[everywhere] ");
214 : bool bFirst = true;
215 0 : for(int si = 0; si < num_subsets(); ++si)
216 : {
217 0 : if(bFirst) bFirst = false; else UG_LOG(", ");
218 0 : if(!is_def_in_subset(fct, si)) continue;
219 0 : UG_LOG(subset_name(si));
220 : }
221 : UG_LOG("\n");
222 : }
223 : UG_LOG("\n");
224 : }
225 :
226 : // write info for subset/fct -> localFEId info
227 : UG_LOG("\n\t\t\t Subsets\n");
228 : UG_LOG(" "<<setw(14)<<"Function"<<" |");
229 0 : for(int si = 0; si < num_subsets(); ++si)
230 0 : UG_LOG(setw(11)<<si<<setw(8)<<" "<<"|")
231 : UG_LOG("\n");
232 0 : for(size_t fct = 0; fct < num_fct(); ++fct)
233 : {
234 0 : UG_LOG(" "<<setw(14)<<name(fct)<<" |");
235 0 : for(int si = 0; si < num_subsets(); ++si)
236 : {
237 : if(!is_def_in_subset(fct,si))
238 : {UG_LOG(setw(8)<<"---"<<setw(8)<<" "<<"|");}
239 0 : else {UG_LOG(setw(16)<<lfeid(fct)<<" |");}
240 : }
241 : UG_LOG("\n");
242 : }
243 :
244 : // write info about DoFs on ROID
245 : UG_LOG("\n");
246 : UG_LOG(" | "<<" "<<" | Subsets \n");
247 : UG_LOG(" ReferenceElement |");
248 : UG_LOG(" "<<setw(4)<<"max"<<" |");
249 0 : for(int si = 0; si < num_subsets(); ++si)
250 0 : UG_LOG(" "<<setw(4)<<si<<" |");
251 : UG_LOG("\n")
252 : UG_LOG("-------------------");
253 0 : for(int si = 0; si <= num_subsets(); ++si)
254 : UG_LOG("-------------");
255 : UG_LOG("\n")
256 :
257 0 : for(int i=ROID_VERTEX; i < NUM_REFERENCE_OBJECTS; ++i)
258 : {
259 : ReferenceObjectID roid = (ReferenceObjectID) i;
260 :
261 0 : UG_LOG(" " << setw(16) << roid << " |");
262 0 : UG_LOG(" "<<setw(4) << m_vMaxDoFsOnROID[roid] << " |");
263 0 : for(int si = 0; si < num_subsets(); ++si)
264 0 : UG_LOG(" "<<setw(4) << m_vvNumDoFsOnROIDPerSubset[roid][si] << " |");
265 :
266 : UG_LOG("\n");
267 : }
268 0 : for(int d = 0; d < NUM_GEOMETRIC_BASE_OBJECTS; ++d)
269 : {
270 0 : UG_LOG(setw(14) << " all " <<setw(2)<< d << "d |");
271 0 : UG_LOG(" "<<setw(4) << m_vMaxDoFsInDim[d] << " |");
272 : UG_LOG("\n");
273 : }
274 : UG_LOG("\n");
275 0 : }
276 :
277 :
278 0 : FunctionGroup DoFDistributionInfoProvider::fct_grp_by_name(const char* names) const
279 : {
280 0 : return FunctionGroup(m_spDDI, TokenizeString(names));
281 : }
282 :
283 0 : SubsetGroup DoFDistributionInfoProvider::subset_grp_by_name(const char* names) const
284 : {
285 0 : return m_spDDI->subset_grp_by_name(names);
286 : }
287 :
288 0 : SubsetGroup DoFDistributionInfoProvider::all_subsets_grp_except_for(const char* names) const
289 : {
290 0 : return m_spDDI->all_subsets_grp_except_for(names);
291 : }
292 :
293 : } // end namespace ug
|