1#ifndef DUNE_FEM_FEMEOC_HH 
    2#define DUNE_FEM_FEMEOC_HH 
   13#include <dune/fem/io/io.hh> 
   14#include <dune/fem/io/file/latextablewriter.hh> 
   15#include <dune/fem/io/parameter.hh> 
   16#include <dune/fem/storage/singleton.hh> 
   52      typedef std::pair< std::string, double > DoublePairType;
 
   53      typedef std::pair< std::string, int >    IntPairType;
 
   58      typedef std::tuple< int, double, double, double, int, std::vector< double >,
 
   59                          std::vector< double >, std::vector< int > >
 
   64      class ErrorColumnWriter;
 
   65      class EOCColumnWriter;
 
   68      std::string filename_;
 
   70      std::vector< double > error_;
 
   71      std::vector< const EOCColumnWriter * > eocColumns_;
 
   72      std::vector< std::string > description_;
 
   73      std::vector< int > pos_;
 
   94      void init ( 
const std::string& path, 
const std::string &name, 
const std::string &descript )
 
   96        if( MPIManager::rank() == 0 )
 
   98          if( createDirectory( path ) )
 
   99            init( path + 
"/" + name, descript );
 
  101            std::cerr << 
"Error: Unable to create path '" << path << 
"'" << std::endl;
 
  105      void init ( 
const std::string &filename, 
const std::string &descript )
 
  107        if( MPIManager::rank() != 0 )
 
  110        std::string name = filename;
 
  113        if( Parameter::getValue< bool >( 
"fem.io.eocFileTimeStamp", 
false ) )
 
  115          time_t seconds = time(0);
 
  116          struct tm *ptm = localtime( &seconds );
 
  118          strftime( timeString, 20, 
"_%d%m%Y_%H%M%S", ptm );
 
  119          name += std::string( timeString );
 
  124          filename_ = name + 
"_body.tex";
 
  125          std::ofstream main( (name + 
"_main.tex").c_str() );
 
  128            std::cerr << 
"Could not open file : " 
  129                      << (name+
"_main.tex").c_str()
 
  130                      << 
" ... ABORTING" << std::endl;
 
  134          main << 
"\\documentclass[12pt,english]{article}\n" 
  135               << 
"\\usepackage[T1]{fontenc}\n" 
  136               << 
"\\usepackage[latin1]{inputenc}\n" 
  137               << 
"\\usepackage{setspace}\n" 
  138               << 
"\\onehalfspacing\n" 
  139               << 
"\\makeatletter\n" 
  140               << 
"\\providecommand{\\boldsymbol}[1]{\\mbox{\\boldmath $#1$}}\n" 
  141               << 
"\\providecommand{\\tabularnewline}{\\\\}\n" 
  142               << 
"\\usepackage{babel}\n" 
  144               << 
"\\begin{document}\n" 
  145               << 
"\\begin{center}\\large\n" 
  146               << 
"\n\\end{center}\n\n" 
  151               << 
"\\end{document}\n" << std::endl;
 
  156          std::cerr << 
"Could not open file : " 
  157                    << 
" already opened!" 
  158                    << 
" ... ABORTING" << std::endl;
 
  163      template <
class StrVectorType>
 
  164      size_t addentry(
const StrVectorType& descript,
size_t size)
 
  168          std::cerr << 
"Trying to add a new entry to FemEoc although " 
  169                    << 
"entries have already been writen to disk!" 
  170                    << 
" ... ABORTING" << std::endl;
 
  173        pos_.push_back(error_.size());
 
  174        for (
size_t i=0;i<
size;++i) {
 
  176          description_.push_back(descript[i]);
 
  178        return pos_.size()-1;
 
  181      size_t addentry ( 
const std::string &descript )
 
  185          std::cerr << 
"Trying to add a new entry to FemEoc although " 
  186                    << 
"entries have already been writen to disk!" 
  187                    << 
" ... ABORTING" << std::endl;
 
  190        pos_.push_back(error_.size());
 
  192        description_.push_back(descript);
 
  193        return pos_.size()-1;
 
  196      template <
class VectorType>
 
  197      void seterrors(
size_t id,
const VectorType& err,
size_t size)
 
  199        assert(
id<pos_.size());
 
  200        int pos = pos_[ id ];
 
  201        assert(pos+
size <= error_.size());
 
  203        for (
size_t i=0; i<
size; ++i)
 
  204          error_[pos+i] = err[i];
 
  210        seterrors(
id,err,SIZE);
 
  213      void seterrors(
size_t id,
const double& err) {
 
  218      void writeerr ( 
double h, 
double size, 
double time, 
int counter );
 
  219      void writeerr(
double h,
double size,
double time,
int counter,
 
  220                    const std::vector< DoublePairType>& doubleValues,
 
  221                    const std::vector< IntPairType>& intValues);
 
  223      void writeerr(
double h,
double size,
double time,
int counter,
 
  224                    double avgTimeStep,
double minTimeStep,
double maxTimeStep ,
 
  225                    const int newton_iterations, 
const int ils_iterations,
 
  226                    const int max_newton_iterations, 
const int max_ils_iterations);
 
  229      void printerr(
const double h,
 
  234      void printerr(
const double h,
 
  238                    const std::vector< DoublePairType>& doubleValues,
 
  239                    const std::vector< IntPairType>& intValues,
 
  254      static void initialize(
const std::string& path, 
const std::string& name, 
const std::string& descript) {
 
  255        instance().init(path,name,descript);
 
  258      static void initialize(
const std::string& name, 
const std::string& descript) {
 
  268      template <
class StrVectorType>
 
  278      template <
class StrVectorType>
 
  279      static size_t addEntry(
const StrVectorType& descript) {
 
  280        return instance().addentry(descript,descript.size());
 
  286      static size_t addEntry(
const std::string& descript) {
 
  287        return instance().addentry(descript);
 
  294        return addEntry(std::string(descript));
 
  301      template <
class VectorType>
 
  311      template <
class VectorType>
 
  312      static void setErrors(
size_t id,
const VectorType& err) {
 
  313        instance().seterrors(
id,err,err.size());
 
  335      static void write(
double h,
double size,
double time,
int counter)
 
  379                        const double avgTimeStep,
 
  380                        const double minTimeStep,
 
  381                        const double maxTimeStep,
 
  382                        const int newton_iterations,
 
  383                        const int ils_iterations,
 
  384                        const int max_newton_iterations,
 
  385                        const int max_ils_iterations)
 
  387        std::vector< DoublePairType > doubleValues;
 
  388        doubleValues.push_back( DoublePairType( 
"avg dt", avgTimeStep ) );
 
  389        doubleValues.push_back( DoublePairType( 
"min dt", minTimeStep ) );
 
  390        doubleValues.push_back( DoublePairType( 
"max dt", maxTimeStep ) );
 
  392        std::vector< IntPairType > intValues;
 
  393        intValues.push_back( IntPairType( 
"Newton", newton_iterations ) );
 
  394        intValues.push_back( IntPairType( 
"ILS", ils_iterations ) );
 
  395        intValues.push_back( IntPairType( 
"max{Newton/linS}", max_newton_iterations ) );
 
  396        intValues.push_back( IntPairType( 
"max{ILS/linS}", max_ils_iterations ) );
 
  399        instance().writeerr(h,
size,time,counter, doubleValues, intValues );
 
  415                        const std::vector< DoublePairType >& doubleValues,
 
  416                        const std::vector< IntPairType >& intValues )
 
  419        instance().writeerr(h,
size,time,counter, doubleValues, intValues );
 
  440                        const double avgTimeStep,
 
  441                        const double minTimeStep,
 
  442                        const double maxTimeStep,
 
  443                        const int newton_iterations,
 
  444                        const int ils_iterations,
 
  445                        const int max_newton_iterations,
 
  446                        const int max_ils_iterations,
 
  449        std::vector< DoublePairType > doubleValues;
 
  450        doubleValues.push_back( DoublePairType( 
"avg dt", avgTimeStep ) );
 
  451        doubleValues.push_back( DoublePairType( 
"min dt", minTimeStep ) );
 
  452        doubleValues.push_back( DoublePairType( 
"max dt", maxTimeStep ) );
 
  454        std::vector< IntPairType > intValues;
 
  455        intValues.push_back( IntPairType( 
"Newton", newton_iterations ) );
 
  456        intValues.push_back( IntPairType( 
"ILS", ils_iterations ) );
 
  457        intValues.push_back( IntPairType( 
"max{Newton/linS}", max_newton_iterations ) );
 
  458        intValues.push_back( IntPairType( 
"max{ILS/linS}", max_ils_iterations ) );
 
  461        instance().printerr( h, 
size, time, counter, doubleValues, intValues, out );
 
  464        instance().writeerr(h,
size,time,counter, doubleValues, intValues );
 
  485                        const std::vector< DoublePairType >& doubleValues,
 
  486                        const std::vector< IntPairType >& intValues,
 
  490        instance().printerr( h, 
size, time, counter, doubleValues, intValues, out );
 
  493        instance().writeerr(h,
size,time,counter, doubleValues, intValues );
 
  499    class FemEoc::ErrorColumnWriter
 
  505      ErrorColumnWriter ( 
const std::string &header, 
const int index )
 
  510      std::string entry ( 
const FemEoc::DataTuple &data )
 const 
  512        return toString( error( data ) );
 
  515      std::string header ()
 const { 
return header_; }
 
  518      double error ( 
const FemEoc::DataTuple &data )
 const 
  520        return std::get< 5 >( data )[ index_ ];
 
  523      std::string 
toString ( 
const double &error )
 const 
  525        std::ostringstream s;
 
  526        s << 
"$" << error << 
"$";
 
  537    class FemEoc::EOCColumnWriter
 
  538    : 
public FemEoc::ErrorColumnWriter
 
  540      typedef FemEoc::ErrorColumnWriter BaseType;
 
  543      explicit EOCColumnWriter ( 
const int index )
 
  544      : BaseType( 
"EOC", index ),
 
  545        hOld_( 
std::numeric_limits< double >::infinity() )
 
  548      std::string entry ( 
const DataTuple &data )
 const 
  550        const double h = std::get< 1 >( data );
 
  551        const double e = BaseType::error( data );
 
  553        std::string entry = 
"---";
 
  554        if( hOld_ < std::numeric_limits< double >::infinity() )
 
  555          entry = BaseType::toString( eoc( h, e ) );
 
  561      double eoc ( 
const double h, 
const double e )
 const 
  563        return std::log( e / eOld_ ) / std::log( h / hOld_ );
 
  567      mutable double hOld_;
 
  568      mutable double eOld_;
 
  574      ::writeerr ( 
double h, 
double size, 
double time, 
int counter )
 
  576      std::vector< DoublePairType > doubleValues;
 
  577      std::vector< IntPairType > intValues;
 
  578      writeerr( h, 
size, time, counter, doubleValues, intValues);
 
  583      ::writeerr(
double h,
double size,
double time,
int counter,
 
  584                 const std::vector< DoublePairType >& doubleValues,
 
  585                 const std::vector< IntPairType >& intValues )
 
  587      if( MPIManager::rank() != 0 )
 
  593        columns.push_back( 
new Fem::NumberColumnWriter< DataTuple, Fem::TupleDataSource< 0 > >( 
"level" ) );
 
  594        columns.push_back( 
new Fem::NumberColumnWriter< DataTuple, Fem::TupleDataSource< 1 > >( 
"h" ) );
 
  595        columns.push_back( 
new Fem::NumberColumnWriter< DataTuple, Fem::TupleDataSource< 2 > >( 
"size" ) );
 
  596        columns.push_back( 
new Fem::NumberColumnWriter< DataTuple, Fem::TupleDataSource< 3 > >( 
"CPU-time" ) );
 
  597        columns.push_back( 
new Fem::NumberColumnWriter< DataTuple, Fem::TupleDataSource< 4 > >( 
"counter" ) );
 
  600        typedef Fem::ArrayDataSource< Fem::TupleDataSource< 6 > > DoubleValueSource;
 
  601        for( 
unsigned int i = 0; i < doubleValues.size(); ++i )
 
  603          columns.push_back( 
new Fem::NumberColumnWriter< DataTuple, DoubleValueSource >( doubleValues[ i ].first, DoubleValueSource( i ) ) );
 
  606        typedef Fem::ArrayDataSource< Fem::TupleDataSource< 7 > > IntValueSource;
 
  607        for( 
unsigned int i = 0; i < intValues.size(); ++i )
 
  609          columns.push_back( 
new Fem::NumberColumnWriter< DataTuple, IntValueSource >( intValues[ i ].first, IntValueSource( i ) ) );
 
  612        eocColumns_.resize( error_.size(), (
const EOCColumnWriter *)0 );
 
  613        for( 
unsigned int i = 0; i < error_.size(); ++i )
 
  616          columns.push_back( 
new ErrorColumnWriter( description_[ i ], i ) );
 
  617          eocColumns_[ i ] = 
new EOCColumnWriter( i );
 
  618          columns.push_back( eocColumns_[ i ] );
 
  621        tableWriter_ = 
new TableWriter( filename_, columns );
 
  624      std::vector< double > doubleVals( doubleValues.size() );
 
  625      for( 
unsigned int i=0; i<doubleValues.size(); ++i )
 
  626        doubleVals[ i ] =  doubleValues[ i ].second;
 
  628      std::vector< int > intVals( intValues.size() );
 
  629      for( 
unsigned int i=0; i<intValues.size(); ++i )
 
  630        intVals[ i ] =  intValues[ i ].second;
 
  632      DataTuple data( level_, h, 
size, time, counter, error_, doubleVals, intVals );
 
  639      ::printerr(
const double h,
 
  645      std::vector< DoublePairType > doubleValues;
 
  646      std::vector< IntPairType >    intValues;
 
  647      printerr( h, 
size, time, counter, doubleValues, intValues, out );
 
  651      ::printerr(
const double h,
 
  655                  const std::vector< DoublePairType >& doubleValues,
 
  656                  const std::vector< IntPairType >& intValues,
 
  661      out << 
"level:   " << level_  << std::endl;
 
  662      out << 
"h        " << h << std::endl;
 
  663      out << 
"size:    " << 
size << std::endl;
 
  664      out << 
"time:    " << time << 
" sec. " << std::endl;
 
  665      out << 
"counter: " << counter << std::endl;
 
  666      for( 
unsigned int i=0; i<doubleValues.size(); ++i )
 
  668        out << doubleValues[ i ].first << 
": " << doubleValues[ i ].second << std::endl;
 
  670      for( 
unsigned int i=0; i<intValues.size(); ++i )
 
  672        out << intValues[ i ].first << 
": " << intValues[ i ].second << std::endl;
 
  675      for (
unsigned int i=0;i<error_.size();++i)
 
  677        out << description_[i] << 
":       " << error_[i] << std::endl;
 
  680          const double eoc = eocColumns_[ i ]->eoc( h, error_[ i ] );
 
  681          out << 
"EOC (" <<description_[i] << 
"): " << eoc << std::endl;
 
Write a self contained tex table for eoc runs with timing information.
Definition: femeoc.hh:51
 
static void clear()
close file and allow FemEoc to used for a second run
Definition: femeoc.hh:250
 
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:411
 
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:375
 
static void write(double h, double size, double time, int counter)
commit a line to the eoc file
Definition: femeoc.hh:335
 
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:319
 
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:302
 
static void setErrors(size_t id, const double &err)
add a single error value for the given id (returned by addEntry)
Definition: femeoc.hh:325
 
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:312
 
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:348
 
static size_t addEntry(const char *descript)
add a single new eoc output
Definition: femeoc.hh:293
 
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:254
 
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:481
 
static size_t addEntry(const StrVectorType &descript)
add a vector of new eoc values
Definition: femeoc.hh:279
 
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:436
 
static void initialize(const std::string &name, const std::string &descript)
open file name and write description string into tex file
Definition: femeoc.hh:258
 
static size_t addEntry(const std::string &descript)
add a single new eoc output
Definition: femeoc.hh:286
 
static size_t addEntry(const StrVectorType &descript, size_t size)
add a vector of new eoc values
Definition: femeoc.hh:269
 
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:97
 
std::string toString(Precision p)
map precision to VTK type name
Definition: common.hh:280
 
Implements a vector constructed from a given type representing a field and a compile-time given size.
 
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
 
Class representing column writer in general.
Definition: latextablewriter.hh:39
 
writes latex tables based on user-defined row structure
Definition: latextablewriter.hh:242
 
void writeRow(const DataTuple &data)
Write row to the table.
Definition: latextablewriter.hh:312
 
std::vector< const ColumnWriterType * > ColumnWriterVectorType
Abstract column vector type.
Definition: latextablewriter.hh:246
 
AbstractColumnWriter< DataTuple > ColumnWriterType
Abstract column type.
Definition: latextablewriter.hh:244