1#ifndef DUNE_FEM_FEMEOCTABLE_HH
2#define DUNE_FEM_FEMEOCTABLE_HH
13#include <dune/fem/io/io.hh>
14#include <dune/fem/io/parameter.hh>
15#include <dune/fem/storage/singleton.hh>
58 static double calculate (
double &eold,
double &enew,
double &hold,
double &hnew )
61 ret = log(eold/enew)/log(hold/hnew);
72 std::vector< std::stringstream* > outputFile_;
73 std::vector< std::string > fileNames_;
74 std::vector< int > level_;
75 std::vector< std::vector< double > > prevError_;
76 std::vector< std::vector< double > > error_;
77 std::vector< std::vector< std::string > > description_;
78 std::vector< double > prevh_;
79 std::vector< bool > initial_;
80 std::vector< std::vector< int > > pos_;
98 std::ofstream filewriter;
100 for(
size_t k=0;k<outputFile_.size();++k)
102 std::stringstream filename;
103 filename << fileNames_[k] <<
".dat";
104 filewriter.open( filename.str().c_str() );
105 filewriter << outputFile_[k]->str();
107 delete outputFile_[k];
113 int init(
const std::string& path,
114 const std::string& name,
const std::string& descript)
116 if (MPIManager::rank() != 0)
return -1;
117 if( !createDirectory( path ) )
119 return init(path+
"/"+name,descript);
122 int init(
const std::string& filename,
const std::string& descript)
124 if (MPIManager::rank() != 0)
return -1;
127 outputFile_.push_back((std::stringstream *) 0);
129 fileNames_.push_back(
"");
131 prevError_.push_back( std::vector< double >() );
132 error_.push_back( std::vector< double >() );
133 description_.push_back( std::vector< std::string >() );
135 initial_.push_back(1);
136 pos_.push_back( std::vector< int >() );
138 const int tabId = outputFile_.size() -1;
140 fileNames_[tabId] = filename;
141 outputFile_[tabId] =
new std::stringstream;
145 *outputFile_[tabId] << descript <<
"\n";
151 void checkTabId (
const int tabId)
153 if (tabId > nrOfTabs_ || tabId <0)
155 std::cout<<
"No table with id:"<<tabId<<
" existing!"<<std::endl;
160 template <
class StrVectorType>
161 size_t addentry(
const int tabId,
const StrVectorType& descript,
size_t size)
165 if (!initial_[tabId])
167 pos_[tabId].push_back(error_[tabId].
size());
168 for (
size_t i=0;i<
size;++i) {
169 error_[tabId].push_back(0);
170 prevError_[tabId].push_back(0);
171 description_[tabId].push_back(descript[i]);
173 return pos_[tabId].size()-1;
176 size_t addentry(
const int tabId,
const std::string& descript) {
180 if (!initial_[tabId])
182 pos_[tabId].push_back(error_[tabId].
size());
183 error_[tabId].push_back(0);
184 prevError_[tabId].push_back(0);
185 description_[tabId].push_back(descript);
186 return pos_[tabId].size()-1;
189 template <
class VectorType>
190 void seterrors(
const int tabId,
size_t id,
const VectorType& err,
size_t size)
194 assert(
id<pos_[tabId].
size());
195 int pos = pos_[tabId][ id ];
196 assert(pos+
size <= error_[tabId].
size());
198 for (
size_t i=0; i<
size; ++i)
199 error_[tabId][pos+i] = err[i];
205 seterrors(tabId,
id,err,SIZE);
208 void seterrors(
const int tabId,
size_t id,
const double& err) {
211 int pos = pos_[tabId][id];
212 error_[tabId][pos] = err;
216 template<
class EocCalculator>
217 void writeerr(
const int tabId,
218 std::vector<double> &vals,
219 std::vector<std::string> &descriptions,
220 std::string &delimiter,
221 std::string &terminatingChar,
223 std::string &tableSpacer,
228 typedef EocCalculator EocCalculatorType;
232 assert(vals.size() == descriptions.size());
233 if (MPIManager::rank() != 0)
return;
235 if (initial_[tabId]) {
236 *outputFile_[tabId] << header;
237 for(
unsigned int k=0;k<descriptions.size();++k)
239 *outputFile_[tabId] << descriptions[k] << delimiter;
241 for (
unsigned int i=0;i<error_[tabId].size();i++)
243 *outputFile_[tabId] << description_[tabId][i] << delimiter <<
"EOC" << delimiter;
245 *outputFile_[tabId] << terminatingChar <<
"\n" << tableSpacer <<
"\n";
248 *outputFile_[tabId] << level_[tabId] << delimiter;
249 for(
unsigned int k =0; k<vals.size(); ++k)
250 *outputFile_[tabId] << vals[k] << delimiter;
252 for (
unsigned int i=0;i<error_[tabId].size();++i) {
253 *outputFile_[tabId] <<delimiter << error_[tabId][i] << delimiter;
254 if (initial_[tabId]) {
255 *outputFile_[tabId] <<
" --- ";
258 *outputFile_[tabId] << EocCalculatorType :: calculate(prevError_[tabId][i], error_[tabId][i], prevh_[tabId], vals[0] );
260 prevError_[tabId][i]=error_[tabId][i];
261 error_[tabId][i] = -1;
263 *outputFile_[tabId] << terminatingChar<<
"\n" << footer;
267 outputFile_[tabId]->seekp(0,std::ios::end);
268 int length = outputFile_[tabId]->tellp();
269 length -= footer.length();
270 outputFile_[tabId]->seekp(length, std::ios::beg);
273 prevh_[tabId] = vals[0];
275 initial_[tabId] =
false;
278 template<
class EocCalculator>
279 void printerr(
const int tabId,
280 std::vector<double> vals,
281 std::vector<std::string> descriptions,
284 typedef EocCalculator EocCalculatorType;
288 assert(descriptions.size() == vals.size());
292 out <<
"level: " << level_[tabId] << std::endl;
293 for(
unsigned int k =0 ;k< vals.size();++k)
294 out << descriptions[k]<<
": " << vals[k] << std::endl;
296 for (
unsigned int i=0;i<error_[tabId].size();++i)
299 out << description_[tabId][i] <<
": " << error_[tabId][i] << std::endl;
300 if (! initial_[tabId])
302 const double eoc = EocCalculatorType :: calculate( prevError_[tabId][i], error_[tabId][i], prevh_[tabId], vals[0]);
304 out <<
"EOC (" <<description_[tabId][i] <<
"): " << eoc << std::endl;
319 static int initialize(
const std::string& path,
const std::string& name,
const std::string& descript) {
320 return instance().init(path,name,descript);
324 static int initialize(
const std::string& name,
const std::string& descript) {
325 return instance().init(name,descript);
338 template <
class StrVectorType>
339 static size_t addEntry(
const int tabId,
const StrVectorType& descript,
size_t size) {
343 template <
class StrVectorType>
344 static size_t addEntry(
const StrVectorType& descript,
size_t size) {
356 template <
class StrVectorType>
357 static size_t addEntry(
const int tabId,
const StrVectorType& descript) {
358 return instance().addentry(tabId,descript,descript.size());
361 template <
class StrVectorType>
362 static size_t addEntry(
const StrVectorType& descript) {
363 return instance().addentry(0,descript,descript.size());
371 static size_t addEntry(
const int tabId,
const std::string& descript) {
372 return instance().addentry(tabId, descript);
375 static size_t addEntry(
const std::string& descript) {
376 return instance().addentry(0, descript);
385 static size_t addEntry(
const int tabId,
const char* descript) {
386 return addEntry(tabId,std::string(descript));
389 static size_t addEntry(
const char* descript) {
390 return addEntry(0,std::string(descript));
403 template <
class VectorType>
404 static void setErrors(
const int tabId,
size_t id,
const VectorType& err,
int size)
409 template <
class VectorType>
410 static void setErrors(
size_t id,
const VectorType& err,
int size)
424 template <
class VectorType>
425 static void setErrors(
const int tabId,
size_t id,
const VectorType& err) {
426 instance().seterrors(tabId,
id,err,err.size());
429 template <
class VectorType>
430 static void setErrors(
size_t id,
const VectorType& err) {
431 instance().seterrors(0,
id,err,err.size());
456 static void setErrors(
const int tabId,
size_t id,
const double& err) {
460 static void setErrors(
size_t id,
const double& err) {
480 std::vector<double> &vals,
481 std::vector<std::string> &descriptions,
482 std::string delimiter =
" ",
483 std::string terminatingChar =
"",
484 std::string header =
"",
485 std::string tableSpacer =
"",
486 std::string footer =
"" )
491 static void write(std::vector<double> &vals,
492 std::vector<std::string> &descriptions,
493 std::string delimiter =
" ",
494 std::string terminatingChar =
"",
495 std::string header =
"",
496 std::string tableSpacer =
"",
497 std::string footer =
""
518 template<
class EocCalculatorType>
520 std::vector<double> &vals,
521 std::vector<std::string> &descriptions,
522 std::string delimiter =
" ",
523 std::string terminatingChar =
"",
524 std::string header =
"",
525 std::string tableSpacer =
"",
526 std::string footer =
""
529 instance().template writeerr<EocCalculatorType>(tabId, vals, descriptions, delimiter, terminatingChar, header, tableSpacer, footer);
532 template<
class EocCalculatorType>
533 static void write(std::vector<double> &vals,
534 std::vector<std::string> &descriptions,
535 std::string delimiter =
" ",
536 std::string terminatingChar =
"",
537 std::string header =
"",
538 std::string tableSpacer =
"",
539 std::string footer =
""
542 instance().template writeerr<EocCalculatorType>(0, vals, descriptions, delimiter, terminatingChar, header, tableSpacer, footer );
559 std::vector<double> &vals,
560 std::vector<std::string> &descriptions,
562 std::string delimiter =
" ",
563 std::string terminatingChar =
"",
564 std::string header =
"",
565 std::string tableSpacer =
"",
566 std::string footer =
"")
575 static void write(std::vector<double> &vals,
576 std::vector<std::string> &descriptions,
578 std::string delimiter =
" ",
579 std::string terminatingChar =
"",
580 std::string header =
"",
581 std::string tableSpacer =
"",
582 std::string footer =
"")
605 template <
class EocCalculatorType>
607 std::vector<double> &vals,
608 std::vector<std::string> &descriptions,
610 std::string delimiter =
" ",
611 std::string terminatingChar =
"",
612 std::string header =
"",
613 std::string tableSpacer =
"",
614 std::string footer =
"")
617 instance().template printerr<EocCalculatorType>( tabId, vals, descriptions, out );
620 instance().template writeerr<EocCalculatorType>(tabId, vals, descriptions, delimiter, terminatingChar, header, tableSpacer, footer);
623 template <
class EocCalculatorType>
624 static void write(std::vector<double> &vals,
625 std::vector<std::string> &descriptions,
627 std::string delimiter =
" ",
628 std::string terminatingChar =
"",
629 std::string header =
"",
630 std::string tableSpacer =
"",
631 std::string footer =
"")
634 instance().template printerr<EocCalculatorType>(0, vals, descriptions, out );
637 instance().template writeerr<EocCalculatorType>(0, vals, descriptions,delimiter, terminatingChar, header, tableSpacer, footer);
Write a self contained tex table for eoc runs with timing information.
Definition: femeoctable.hh:56
The Fem Eoc Table writer.
Definition: femeoctable.hh:70
static void write(const int tabId, std::vector< double > &vals, std::vector< std::string > &descriptions, std::ostream &out, std::string delimiter=" ", std::string terminatingChar="", std::string header="", std::string tableSpacer="", std::string footer="")
commit a line to the eoc file
Definition: femeoctable.hh:558
static void setErrors(const int tabId, size_t id, const VectorType &err, int size)
add a vector of error values for the given id (returned by addEntry)
Definition: femeoctable.hh:404
static int initialize(const std::string &path, const std::string &name, const std::string &descript)
Definition: femeoctable.hh:319
static void setErrors(const int tabId, size_t id, const double &err)
add a single error value for the given id (returned by addEntry)
Definition: femeoctable.hh:456
static void write(const int tabId, std::vector< double > &vals, std::vector< std::string > &descriptions, std::ostream &out, std::string delimiter=" ", std::string terminatingChar="", std::string header="", std::string tableSpacer="", std::string footer="")
commit a line to the eoc file, using EocCalculatorType for non standart Eoc calculations.
Definition: femeoctable.hh:606
static void write(const int tabId, std::vector< double > &vals, std::vector< std::string > &descriptions, std::string delimiter=" ", std::string terminatingChar="", std::string header="", std::string tableSpacer="", std::string footer="")
commit a line to the eoc file, using EocCalculatorType to calculate the eoc.
Definition: femeoctable.hh:519
static size_t addEntry(const int tabId, const StrVectorType &descript)
add a vector of new eoc values
Definition: femeoctable.hh:357
static void write(const int tabId, std::vector< double > &vals, std::vector< std::string > &descriptions, std::string delimiter=" ", std::string terminatingChar="", std::string header="", std::string tableSpacer="", std::string footer="")
commit a line to the eoc file
Definition: femeoctable.hh:479
static int initialize(const std::string &name, const std::string &descript)
Definition: femeoctable.hh:324
static size_t addEntry(const int tabId, const char *descript)
add a single new eoc output
Definition: femeoctable.hh:385
static void setErrors(const int tabId, size_t id, const VectorType &err)
add a vector of error values for the given id (returned by addEntry)
Definition: femeoctable.hh:425
static void setErrors(const int tabId, size_t id, const FieldVector< double, SIZE > &err)
add a vector in a FieldVector of error values for the given id (returned by addEntry)
Definition: femeoctable.hh:442
static size_t addEntry(const int tabId, const std::string &descript)
add a single new eoc output
Definition: femeoctable.hh:371
static size_t addEntry(const int tabId, const StrVectorType &descript, size_t size)
add a vector of new eoc values
Definition: femeoctable.hh:339
static bool verbose()
obtain the cached value for fem.verbose with default verbosity level 2
Definition: parameter.hh:466
return singleton instance of given Object type.
Definition: singleton.hh:93
static DUNE_EXPORT Object & instance(Args &&... args)
return singleton instance of given Object type.
Definition: singleton.hh:123
vector space out of a tensor product of fields.
Definition: fvector.hh:91
Default exception class for I/O errors.
Definition: exceptions.hh:231
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75