root/test/io_dgf.cpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. name
  2. main
  3. print_errMsg

   1 /*! \file io_dgf.cpp
   2 
   3     \brief <Program Name>
   4 
   5      Revision history:
   6 
   7           Revised by Christian Power dd.mm.yyyy
   8           Originally written by Christian Power
   9                (power22c@gmail.com) March 2016
  10 
  11      Testing the components of io_dgf.h.
  12 
  13      Created by Christian Power on 08.03.2016
  14 
  15      Copyright (c) 2016 Christian Power. All rights reserved.
  16  */
  17 
  18 #include "esfem.h"
  19 
  20 void print_errMsg(const std::exception&);
  21 template<typename FEFun>
  22 std::string name(const FEFun& fef){
  23   constexpr auto base_dir = "/Users/christianpower/cpp/DISS_surfaces/test/";
  24   return base_dir + fef.name() + ".dgf";
  25 }
  26 
  27 using namespace std;
  28 
  29 int main(int argc, char** argv) try{
  30   class {
  31     int i {0};
  32   public:
  33     void operator()(const string& m = "Hello"){
  34       clog << m << ' ' << i++ << endl;
  35     }
  36   } hello;
  37   
  38   const string this_dir {"/Users/christianpower/cpp/DISS_surfaces/test/"};
  39   
  40   Dune::Fem::MPIManager::initialize(argc, argv);
  41   
  42   const auto parameter_file = this_dir + "test_parameter.txt";
  43   Esfem::Io::Parameter data {argc, argv, parameter_file};
  44   // Two additional parameter
  45   const auto dgf_inputFile = this_dir + "input_test00.dgf";
  46   const auto dgf_outputFile = "/Users/christianpower/cpp/DISS_surfaces/test/"
  47     "output_test00.dgf";
  48   
  49   const Esfem::Io::Dgf::Handler dgf_interpreter {dgf_inputFile};
  50   Esfem::Grid::Grid_and_time grid {data};
  51   Esfem::Grid::Scal_FEfun fef {"fef", grid};
  52   Esfem::Grid::Vec_FEfun vfef {"vfef", grid};
  53 
  54   dgf_interpreter.read(dgf_inputFile, vfef);
  55   vfef *= -1.;
  56   dgf_interpreter.write(name(vfef), vfef);
  57 
  58   fef += 1.;
  59   dgf_interpreter.write(name(fef), fef);
  60 
  61   try{
  62     hello(name(fef));
  63     dgf_interpreter.read(name(fef), vfef); }
  64   catch(const exception& e){
  65     clog << "Caught error 0 as expected." << endl;
  66     print_errMsg(e);
  67   }  
  68   try{
  69     hello(name(vfef));
  70     dgf_interpreter.read(name(vfef), fef); }
  71   catch(const exception& e){
  72     clog << "Caught error 1 as expected." << endl;
  73     print_errMsg(e);
  74   }
  75  }
  76  catch(const exception& e){
  77    print_errMsg(e);
  78    return 1;
  79  }
  80  catch(const Dune::Exception& e){
  81    cerr << "Dune error: " << e << endl;
  82    return 2;
  83  }
  84  catch(...){
  85    cerr << "Unkown error in main().\n";
  86    return 3;
  87  }
  88 
  89 // ----------------------------------------------------------------------
  90 // Internal Implementation
  91 
  92 void print_errMsg(const std::exception& e){
  93   std::cerr << e.what() << '\n';
  94   try{
  95     std::rethrow_if_nested(e);
  96   }
  97   catch(const std::exception& nested){
  98     print_errMsg(nested);
  99   }
 100 }
 101 
 102 /*! Log:
 103  */

/* [<][>][^][v][top][bottom][index][help] */