1 #ifndef DUNE_FEM_FEMEOC_HH 2 #define DUNE_FEM_FEMEOC_HH 11 #include <dune/common/fvector.hh> 50 typedef std::pair< std::string, double > DoublePairType;
51 typedef std::pair< std::string, int > IntPairType;
56 typedef std::tuple< int, double, double, double, int, std::vector< double >,
57 std::vector< double >, std::vector< int > >
65 TableWriter *tableWriter_;
66 std::string filename_;
68 std::vector< double > error_;
69 std::vector< const EOCColumnWriter * > eocColumns_;
70 std::vector< std::string > description_;
71 std::vector< int > pos_;
90 void init (
const std::string&
path,
const std::string &name,
const std::string &descript )
95 init( path +
"/" + name, descript );
97 std::cerr <<
"Error: Unable to create path '" << path <<
"'" << std::endl;
101 void init (
const std::string &filename,
const std::string &descript )
106 std::string name = filename;
109 if( Parameter::getValue< bool >(
"fem.io.eocFileTimeStamp",
false ) )
111 time_t seconds = time(0);
112 struct tm *ptm = localtime( &seconds );
114 strftime( timeString, 20,
"_%d%m%Y_%H%M%S", ptm );
115 name += std::string( timeString );
120 filename_ = name +
"_body.tex";
121 std::ofstream
main( (name +
"_main.tex").c_str() );
124 std::cerr <<
"Could not open file : " 125 << (name+
"_main.tex").c_str()
126 <<
" ... ABORTING" << std::endl;
130 main <<
"\\documentclass[12pt,english]{article}\n" 131 <<
"\\usepackage[T1]{fontenc}\n" 132 <<
"\\usepackage[latin1]{inputenc}\n" 133 <<
"\\usepackage{setspace}\n" 134 <<
"\\onehalfspacing\n" 135 <<
"\\makeatletter\n" 136 <<
"\\providecommand{\\boldsymbol}[1]{\\mbox{\\boldmath $#1$}}\n" 137 <<
"\\providecommand{\\tabularnewline}{\\\\}\n" 138 <<
"\\usepackage{babel}\n" 140 <<
"\\begin{document}\n" 141 <<
"\\begin{center}\\large\n" 142 <<
"\n\\end{center}\n\n" 147 <<
"\\end{document}\n" << std::endl;
152 std::cerr <<
"Could not open file : " 153 <<
" already opened!" 154 <<
" ... ABORTING" << std::endl;
159 template <
class StrVectorType>
160 size_t addentry(
const StrVectorType& descript,
size_t size)
164 std::cerr <<
"Trying to add a new entry to FemEoc although " 165 <<
"entries have already been writen to disk!" 166 <<
" ... ABORTING" << std::endl;
169 pos_.push_back(error_.size());
170 for (
size_t i=0;i<size;++i) {
172 description_.push_back(descript[i]);
174 return pos_.size()-1;
177 size_t addentry (
const std::string &descript )
181 std::cerr <<
"Trying to add a new entry to FemEoc although " 182 <<
"entries have already been writen to disk!" 183 <<
" ... ABORTING" << std::endl;
186 pos_.push_back(error_.size());
188 description_.push_back(descript);
189 return pos_.size()-1;
192 template <
class VectorType>
193 void seterrors(
size_t id,
const VectorType& err,
size_t size)
195 assert(
id<pos_.size());
196 int pos = pos_[ id ];
197 assert(pos+size <= error_.size());
199 for (
size_t i=0; i<size; ++i)
200 error_[pos+i] = err[i];
204 void seterrors(
size_t id,
const FieldVector<double,SIZE>& err)
206 seterrors(
id,err,SIZE);
209 void seterrors(
size_t id,
const double& err) {
214 void writeerr (
double h,
double size,
double time,
int counter );
215 void writeerr(
double h,
double size,
double time,
int counter,
216 const std::vector< DoublePairType>& doubleValues,
217 const std::vector< IntPairType>& intValues);
219 void writeerr(
double h,
double size,
double time,
int counter,
220 double avgTimeStep,
double minTimeStep,
double maxTimeStep ,
221 const int newton_iterations,
const int ils_iterations,
222 const int max_newton_iterations,
const int max_ils_iterations);
225 void printerr(
const double h,
230 void printerr(
const double h,
234 const std::vector< DoublePairType>& doubleValues,
235 const std::vector< IntPairType>& intValues,
248 static void initialize(
const std::string& path,
const std::string& name,
const std::string& descript) {
249 instance().init(path,name,descript);
252 static void initialize(
const std::string& name,
const std::string& descript) {
262 template <
class StrVectorType>
263 static size_t addEntry(
const StrVectorType& descript,
size_t size) {
264 return instance().addentry(descript,size);
272 template <
class StrVectorType>
273 static size_t addEntry(
const StrVectorType& descript) {
274 return instance().addentry(descript,descript.size());
280 static size_t addEntry(
const std::string& descript) {
281 return instance().addentry(descript);
288 return addEntry(std::string(descript));
295 template <
class VectorType>
296 static void setErrors(
size_t id,
const VectorType& err,
int size)
305 template <
class VectorType>
306 static void setErrors(
size_t id,
const VectorType& err) {
307 instance().seterrors(
id,err,err.size());
313 static void setErrors(
size_t id,
const FieldVector<double,SIZE>& err) {
329 static void write(
double h,
double size,
double time,
int counter)
331 instance().writeerr(h,size,time,counter);
349 instance().printerr( h, size, time, counter, out );
352 instance().writeerr(h,size,time,counter);
373 const double avgTimeStep,
374 const double minTimeStep,
375 const double maxTimeStep,
376 const int newton_iterations,
377 const int ils_iterations,
378 const int max_newton_iterations,
379 const int max_ils_iterations)
381 std::vector< DoublePairType > doubleValues;
382 doubleValues.push_back( DoublePairType(
"avg dt", avgTimeStep ) );
383 doubleValues.push_back( DoublePairType(
"min dt", minTimeStep ) );
384 doubleValues.push_back( DoublePairType(
"max dt", maxTimeStep ) );
386 std::vector< IntPairType > intValues;
387 intValues.push_back( IntPairType(
"Newton", newton_iterations ) );
388 intValues.push_back( IntPairType(
"ILS", ils_iterations ) );
389 intValues.push_back( IntPairType(
"max{Newton/linS}", max_newton_iterations ) );
390 intValues.push_back( IntPairType(
"max{ILS/linS}", max_ils_iterations ) );
393 instance().writeerr(h,size,time,counter, doubleValues, intValues );
409 const std::vector< DoublePairType >& doubleValues,
410 const std::vector< IntPairType >& intValues )
413 instance().writeerr(h,size,time,counter, doubleValues, intValues );
434 const double avgTimeStep,
435 const double minTimeStep,
436 const double maxTimeStep,
437 const int newton_iterations,
438 const int ils_iterations,
439 const int max_newton_iterations,
440 const int max_ils_iterations,
443 std::vector< DoublePairType > doubleValues;
444 doubleValues.push_back( DoublePairType(
"avg dt", avgTimeStep ) );
445 doubleValues.push_back( DoublePairType(
"min dt", minTimeStep ) );
446 doubleValues.push_back( DoublePairType(
"max dt", maxTimeStep ) );
448 std::vector< IntPairType > intValues;
449 intValues.push_back( IntPairType(
"Newton", newton_iterations ) );
450 intValues.push_back( IntPairType(
"ILS", ils_iterations ) );
451 intValues.push_back( IntPairType(
"max{Newton/linS}", max_newton_iterations ) );
452 intValues.push_back( IntPairType(
"max{ILS/linS}", max_ils_iterations ) );
455 instance().printerr( h, size, time, counter, doubleValues, intValues, out );
458 instance().writeerr(h,size,time,counter, doubleValues, intValues );
479 const std::vector< DoublePairType >& doubleValues,
480 const std::vector< IntPairType >& intValues,
484 instance().printerr( h, size, time, counter, doubleValues, intValues, out );
487 instance().writeerr(h,size,time,counter, doubleValues, intValues );
504 std::string
entry (
const FemEoc::DataTuple &data )
const 506 return toString( error( data ) );
509 std::string
header ()
const {
return header_; }
512 double error (
const FemEoc::DataTuple &data )
const 514 return std::get< 5 >( data )[ index_ ];
519 std::ostringstream s;
520 s <<
"$" << error <<
"$";
538 : BaseType(
"EOC", index ),
539 hOld_(
std::numeric_limits< double >::infinity() )
542 std::string
entry (
const DataTuple &data )
const 544 const double h = std::get< 1 >( data );
545 const double e = BaseType::error( data );
547 std::string entry =
"---";
548 if( hOld_ < std::numeric_limits< double >::infinity() )
549 entry = BaseType::toString( eoc( h, e ) );
555 double eoc (
const double h,
const double e )
const 561 mutable double hOld_;
562 mutable double eOld_;
568 ::writeerr (
double h,
double size,
double time,
int counter )
570 std::vector< DoublePairType > doubleValues;
571 std::vector< IntPairType > intValues;
572 writeerr( h, size, time, counter, doubleValues, intValues);
577 ::writeerr(
double h,
double size,
double time,
int counter,
578 const std::vector< DoublePairType >& doubleValues,
579 const std::vector< IntPairType >& intValues )
595 for(
unsigned int i = 0; i < doubleValues.size(); ++i )
601 for(
unsigned int i = 0; i < intValues.size(); ++i )
607 for(
unsigned int i = 0; i < error_.size(); ++i )
612 columns.push_back( eocColumns_[ i ] );
615 tableWriter_ =
new TableWriter( filename_, columns );
618 std::vector< double > doubleVals( doubleValues.size() );
619 for(
unsigned int i=0; i<doubleValues.size(); ++i )
620 doubleVals[ i ] = doubleValues[ i ].second;
622 std::vector< int > intVals( intValues.size() );
623 for(
unsigned int i=0; i<intValues.size(); ++i )
624 intVals[ i ] = intValues[ i ].second;
626 DataTuple data( level_, h, size, time, counter, error_, doubleVals, intVals );
627 tableWriter_->writeRow( data );
633 ::printerr(
const double h,
639 std::vector< DoublePairType > doubleValues;
640 std::vector< IntPairType > intValues;
641 printerr( h, size, time, counter, doubleValues, intValues, out );
645 ::printerr(
const double h,
649 const std::vector< DoublePairType >& doubleValues,
650 const std::vector< IntPairType >& intValues,
655 out <<
"level: " << level_ << std::endl;
656 out <<
"h " << h << std::endl;
657 out <<
"size: " << size << std::endl;
658 out <<
"time: " << time <<
" sec. " << std::endl;
659 out <<
"counter: " << counter << std::endl;
660 for(
unsigned int i=0; i<doubleValues.size(); ++i )
662 out << doubleValues[ i ].first <<
": " << doubleValues[ i ].second << std::endl;
664 for(
unsigned int i=0; i<intValues.size(); ++i )
666 out << intValues[ i ].first <<
": " << intValues[ i ].second << std::endl;
669 for (
unsigned int i=0;i<error_.size();++i)
671 out << description_[i] <<
": " << error_[i] << std::endl;
674 const double eoc = eocColumns_[ i ]->eoc( h, error_[ i ] );
675 out <<
"EOC (" <<description_[i] <<
"): " << eoc << std::endl;
685 #endif // #ifndef DUNE_FEM_FEMEOC_HH EOCColumnWriter(const int index)
Definition: femeoc.hh:537
int main(int argc, char **argv)
Definition: dataconvert.cc:29
static void write(const double h, const double size, const double time, const int counter, const std::vector< DoublePairType > &doubleValues, const std::vector< IntPairType > &intValues)
commit a line to the eoc file
Definition: femeoc.hh:405
ErrorColumnWriter(const std::string &header, const int index)
Definition: femeoc.hh:499
static int rank()
Definition: mpimanager.hh:116
static void clear()
close file and allow FemEoc to used for a second run
Definition: femeoc.hh:244
gets the N th element of a provided tuple assuming its a number
Definition: latextablewriter.hh:166
std::string entry(const FemEoc::DataTuple &data) const
Definition: femeoc.hh:504
Write a self contained tex table for eoc runs with timing information.
Definition: femeoc.hh:48
bool createDirectory(const std::string &inName)
create a directory
Definition: io.cc:19
Definition: latextablewriter.hh:61
static void write(const double h, const double size, const double time, const int counter, const double avgTimeStep, const double minTimeStep, const double maxTimeStep, const int newton_iterations, const int ils_iterations, const int max_newton_iterations, const int max_ils_iterations, std::ostream &out)
commit a line to the eoc file
Definition: femeoc.hh:430
static double log(const Double &v)
Definition: double.hh:865
Class representing column writer in general.
Definition: latextablewriter.hh:39
static void write(const double h, const double size, const double time, const int counter, const std::vector< DoublePairType > &doubleValues, const std::vector< IntPairType > &intValues, std::ostream &out)
commit a line to the eoc file
Definition: femeoc.hh:475
static void setErrors(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: femeoc.hh:313
writes latex tables based on user-defined row structure
Definition: latextablewriter.hh:244
std::string toString(const double &error) const
Definition: femeoc.hh:517
Definition: coordinate.hh:4
std::vector< const ColumnWriterType * > ColumnWriterVectorType
Abstract column vector type.
Definition: latextablewriter.hh:249
static size_t addEntry(const StrVectorType &descript, size_t size)
add a vector of new eoc values
Definition: femeoc.hh:263
double eoc(const double h, const double e) const
Definition: femeoc.hh:555
static size_t addEntry(const char *descript)
add a single new eoc output
Definition: femeoc.hh:287
Definition: latextablewriter.hh:80
std::string header() const
Definition: femeoc.hh:509
static void write(double h, double size, double time, int counter)
commit a line to the eoc file
Definition: femeoc.hh:329
static void initialize(const std::string &path, const std::string &name, const std::string &descript)
open file path/name and write a description string into tex file
Definition: femeoc.hh:248
std::string path
Definition: readioparams.cc:155
static size_t addEntry(const std::string &descript)
add a single new eoc output
Definition: femeoc.hh:280
static void setErrors(size_t id, const VectorType &err)
add a vector of error values for the given id (returned by addEntry)
Definition: femeoc.hh:306
static bool verbose()
obtain the cached value for fem.verbose
Definition: io/parameter.hh:444
Definition: femeoc.hh:531
static void write(const double h, const double size, const double time, const int counter, const double avgTimeStep, const double minTimeStep, const double maxTimeStep, const int newton_iterations, const int ils_iterations, const int max_newton_iterations, const int max_ils_iterations)
commit a line to the eoc file
Definition: femeoc.hh:369
static void setErrors(size_t id, const VectorType &err, int size)
add a vector of error values for the given id (returned by addEntry)
Definition: femeoc.hh:296
std::string entry(const DataTuple &data) const
Definition: femeoc.hh:542
static FemEoc & instance()
Definition: femeoc.hh:239
double error(const FemEoc::DataTuple &data) const
Definition: femeoc.hh:512
static void initialize(const std::string &name, const std::string &descript)
open file name and write description string into tex file
Definition: femeoc.hh:252
static void write(const double h, const double size, const double time, const int counter, std::ostream &out)
commit a line to the eoc file
Definition: femeoc.hh:342
static void setErrors(size_t id, const double &err)
add a single error value for the given id (returned by addEntry)
Definition: femeoc.hh:319
Definition: femeoc.hh:493
static size_t addEntry(const StrVectorType &descript)
add a vector of new eoc values
Definition: femeoc.hh:273