Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
composite_conv_check.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3 * Author: Markus Breit
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_DISC__OPERATOR__COMPOSITE_CONVERGENCE_CHECK__
34#define __H__LIB_DISC__OPERATOR__COMPOSITE_CONVERGENCE_CHECK__
35
36#include <ostream>
37#include <sstream>
38#include <string>
39#include <limits>
40#include <algorithm>
41#include <iomanip>
42#include <vector>
43#include <list>
44#include <math.h>
45
46#include "common/common.h"
47#include "common/stopwatch.h"
52
53namespace ug{
54
56// Composite convergence check
58
65template <class TVector, class TDomain>
67{
68 public:
73 int maxSteps, number minDefect, number relReduction);
75
77 virtual ~CompositeConvCheck() {};
78
80 void set_level(int level);
81
83 void set_maximum_steps(int maxSteps) {m_maxSteps = maxSteps;}
84
86 void set_rest_check(number minDefect, number relReduction){
87 m_bCheckRest = true;
88 m_restMinDefect = minDefect; m_restRelReduction = relReduction;
90 }
91
94
97 void set_component_check(const std::string& vFctName,
98 const std::vector<number>& vMinDefect,
99 const std::vector<number>& vRelReduction);
100
101 void set_component_check(const std::vector<std::string>& vFctName,
102 const std::vector<number>& vMinDefect,
103 const std::vector<number>& vRelReduction);
104
105 void set_component_check(const std::vector<std::string>& vFctName,
106 const number minDefect,
107 const number relReduction);
108
109 void set_component_check(const std::string& fctName,
110 const number minDefect,
111 const number relReduction);
113
115 void set_all_component_check(const number minDefect,
116 const number relReduction);
117
120 void set_group_check(const std::vector<std::string>& vFctName,
121 const number minDefect,
122 const number relReduction);
123
124 void set_group_check(const std::string& fctNames,
125 const number minDefect,
126 const number relReduction);
128
130 void start_defect(number initialDefect);
131 void start(const TVector& d);
132 void update_defect(number newDefect);
133 void update(const TVector& d);
134 bool iteration_ended();
135 bool post();
136
138 int step() const {return m_currentStep;}
139 number defect() const {return defect_all();};
141 number rate() const {return defect_all()/last_defect_all();}
142 number avg_rate() const {return std::pow(defect_all()/initial_defect_all(), 1.0/m_currentStep);}
143
145 int get_offset() const {return m_offset;};
146 void set_offset(int offset){m_offset = offset;};
147 void set_symbol(char symbol){m_symbol = symbol;};
148 void set_name(std::string name) {m_name = name;};
149 void set_info(std::string info) {m_info = info;};
150
152 void set_verbose(bool level) {m_verbose = level;};
153
155 void set_supress_unsuccessful(bool bsupress) {m_supress_unsuccessful = bsupress;}
156
158 void set_time_measurement(bool yesOrNo) {m_bTimeMeas = yesOrNo;};
159
161 void set_adaptive(bool adapt) {m_bAdaptive = adapt;}
162
165
167 void print_line(std::string line);
168
169 virtual std::string config_string() const
170 {
171 std::stringstream ss;
172 ss << "CompositeConvCheck( max steps = " << m_maxSteps << ")";
173 ss << " Components:\n";
174 for(size_t i=0; i<m_CmpInfo.size(); i++)
175 ss << " | " << m_CmpInfo[i].config_string() << "\n";
176 return ss.str();
177 }
178
179 protected:
180 void print_offset();
181 bool is_valid_number(number value);
182 const std::string& fctName(size_t i) {return m_CmpInfo[i].name;};
183
185 template <typename TBaseElem>
187
190
192 number norm(const TVector& vec, const std::vector<DoFIndex>& index);
193
194 protected:
197
199 std::string name;
200
204
205 std::vector<DoFIndex> vMultiIndex;
206 };
207
209 std::vector<NativCmpInfo> m_vNativCmpInfo;
211
214 number defect = 0.0;
215 for(size_t fct = 0; fct < m_vNativCmpInfo.size(); ++fct)
216 defect += pow(m_vNativCmpInfo[fct].currDefect, 2);
217 return sqrt(defect);
218 }
219
222 number defect = 0.0;
223 for(size_t fct = 0; fct < m_vNativCmpInfo.size(); ++fct)
224 defect += pow(m_vNativCmpInfo[fct].lastDefect, 2);
225 return sqrt(defect);
226 }
227
230 number defect = 0.0;
231 for(size_t fct = 0; fct < m_vNativCmpInfo.size(); ++fct)
232 defect += pow(m_vNativCmpInfo[fct].initDefect, 2);
233 return sqrt(defect);
234 }
235
236 protected:
237 struct CmpInfo
238 {
239 CmpInfo() : isRest(false) {}
240
241 std::vector<int> vFct;
242 std::string name;
243
247
250
251 bool isRest;
252
253 std::string config_string() const
254 {
255 std::stringstream ss;
256 if(isRest) ss << "[Remaining Components]";
257 else ss << "Component " << name;
258 ss << ": minDefect = " << minDefect << ", relReduction = " << relReduction;
259 return ss.str();
260 }
261
262 };
263
265 std::vector<CmpInfo> m_CmpInfo;
266
271 void update_rest_check();
272
275
278
279 protected:
282
285
288
291
293 std::string m_name;
294
296 std::string m_info;
297
298 protected:
301
304
305 // TODO: maybe solve this using an adaption/distribution event listener
308};
309
310} // end namespace ug
311
313
314#endif /* __H__LIB_DISC__OPERATOR__COMPOSITE_CONVERGENCE_CHECK__ */
location name
Definition checkpoint_util.lua:128
Definition smart_pointer.h:296
Definition smart_pointer.h:108
base class for approximation spaces without type of algebra or dof distribution
Definition approximation_space.h:279
Definition composite_conv_check.h:67
number defect() const
returns the current defect
Definition composite_conv_check.h:139
void set_group_check(const std::vector< std::string > &vFctName, const number minDefect, const number relReduction)
Definition composite_conv_check_impl.h:300
void set_level(int level)
set level of grid, where defect vectors come from
Definition composite_conv_check_impl.h:74
void set_info(std::string info)
sets info string
Definition composite_conv_check.h:149
void set_rest_check(number minDefect, number relReduction)
sets default values for non-explicitly specified cmps
Definition composite_conv_check.h:86
void start(const TVector &d)
computes the start defect and set it
Definition composite_conv_check_impl.h:428
number last_defect_all() const
returns last defect for all components
Definition composite_conv_check.h:221
std::vector< NativCmpInfo > m_vNativCmpInfo
info on natural components
Definition composite_conv_check.h:209
void set_supress_unsuccessful(bool bsupress)
set whether always to report success when max iter is reached (useful for LIMEX)
Definition composite_conv_check.h:155
int m_maxSteps
maximum number of steps to be performed
Definition composite_conv_check.h:277
char m_symbol
symbol for output appearance
Definition composite_conv_check.h:290
int get_offset() const
output
Definition composite_conv_check.h:145
void print_offset()
Definition composite_conv_check_impl.h:701
number rate() const
Definition composite_conv_check.h:141
virtual ~CompositeConvCheck()
destructor
Definition composite_conv_check.h:77
bool m_verbose
verbose level
Definition composite_conv_check.h:281
void set_symbol(char symbol)
sets the symbol used for output
Definition composite_conv_check.h:147
void disable_rest_check()
disables rest check
Definition composite_conv_check.h:93
virtual std::string config_string() const
returns information about configuration parameters
Definition composite_conv_check.h:169
void set_time_measurement(bool yesOrNo)
enables time measurement
Definition composite_conv_check.h:158
std::string m_info
info for iteration (e.g. preconditioner type)
Definition composite_conv_check.h:296
number m_restRelReduction
Definition composite_conv_check.h:270
bool is_valid_number(number value)
Definition composite_conv_check_impl.h:719
void set_component_check(const std::string &vFctName, const std::vector< number > &vMinDefect, const std::vector< number > &vRelReduction)
Definition composite_conv_check_impl.h:225
Stopwatch m_stopwatch
a stopwatch
Definition composite_conv_check.h:303
void set_name(std::string name)
sets the name of the iteration
Definition composite_conv_check.h:148
void set_adaptive(bool adapt)
whether or not the underlying approximatioon space is adaptive
Definition composite_conv_check.h:161
bool m_bCheckRest
default Values
Definition composite_conv_check.h:268
void print_line(std::string line)
prints a line using prefixes
Definition composite_conv_check_impl.h:711
void extract_dof_indices(ConstSmartPtr< DoFDistribution > dd)
extracts multi-indices for a fct-comp on a element type
Definition composite_conv_check_impl.h:86
number avg_rate() const
Definition composite_conv_check.h:142
void update_rest_check()
Definition composite_conv_check_impl.h:362
size_t m_numAllDoFs
Definition composite_conv_check.h:210
number norm(const TVector &vec, const std::vector< DoFIndex > &index)
calculates the 2-norm of the entries of the vector vec specified by index
Definition composite_conv_check_impl.h:153
SmartPtr< ApproximationSpace< TDomain > > m_spApprox
ApproxSpace.
Definition composite_conv_check.h:196
void set_verbose(bool level)
sets if verbose
Definition composite_conv_check.h:152
bool m_bTimeMeas
enables time measurement
Definition composite_conv_check.h:300
bool m_bAdaptive
adaptivity flag
Definition composite_conv_check.h:307
void update(const TVector &d)
computes the defect and sets it a the next defect value
Definition composite_conv_check_impl.h:536
number defect_all() const
returns defect for all components
Definition composite_conv_check.h:213
const std::string & fctName(size_t i)
Definition composite_conv_check.h:182
void set_offset(int offset)
sets the number of spaces printed before output information
Definition composite_conv_check.h:146
bool m_supress_unsuccessful
whether to always report success once max iter is reached
Definition composite_conv_check.h:284
int m_currentStep
current step
Definition composite_conv_check.h:274
std::string m_name
name of iteration
Definition composite_conv_check.h:293
void set_maximum_steps(int maxSteps)
sets maximum number of iteration steps
Definition composite_conv_check.h:83
void update_defect(number newDefect)
sets the update for the current defect
Definition composite_conv_check_impl.h:526
bool iteration_ended()
Definition composite_conv_check_impl.h:597
number initial_defect_all() const
returns initial defect for all components
Definition composite_conv_check.h:229
number reduction() const
Definition composite_conv_check.h:140
virtual SmartPtr< IConvergenceCheck< TVector > > clone()
clones this instance
Definition composite_conv_check_impl.h:199
void start_defect(number initialDefect)
defect control
Definition composite_conv_check_impl.h:404
int m_offset
number of spaces inserted before output
Definition composite_conv_check.h:287
void set_all_component_check(const number minDefect, const number relReduction)
sets check for all components in approximation space
Definition composite_conv_check_impl.h:245
int step() const
information about current status
Definition composite_conv_check.h:138
bool post()
Definition composite_conv_check_impl.h:622
std::vector< CmpInfo > m_CmpInfo
infos for each component
Definition composite_conv_check.h:265
number m_restMinDefect
Definition composite_conv_check.h:269
Definition convergence_check.h:72
Stopwatch class for quickly taking times.
Definition stopwatch.h:124
double number
Definition types.h:124
the ug namespace
stopwatch class for quickly taking times
Definition composite_conv_check.h:238
number relReduction
Relative reduction required for component.
Definition composite_conv_check.h:249
CmpInfo()
Definition composite_conv_check.h:239
std::vector< int > vFct
Index of components.
Definition composite_conv_check.h:241
number currDefect
Current Defect of component.
Definition composite_conv_check.h:245
std::string name
Name of components.
Definition composite_conv_check.h:242
std::string config_string() const
Definition composite_conv_check.h:253
number initDefect
Initial Defect of component.
Definition composite_conv_check.h:244
number minDefect
Minimal required Defect of component.
Definition composite_conv_check.h:248
number lastDefect
Last Defect if component.
Definition composite_conv_check.h:246
bool isRest
Shows, that this is group of remaining cmps.
Definition composite_conv_check.h:251
Definition composite_conv_check.h:198
std::vector< DoFIndex > vMultiIndex
associated indices
Definition composite_conv_check.h:205
number currDefect
Current Defect of component.
Definition composite_conv_check.h:202
number initDefect
Initial Defect of component.
Definition composite_conv_check.h:201
std::string name
Name of components.
Definition composite_conv_check.h:199
number lastDefect
Last Defect if component.
Definition composite_conv_check.h:203