root/src/io_parameter_impl.cpp

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

DEFINITIONS

This source file includes following definitions.
  1. project_dir
  2. dune_fem_parameter_append
  3. get_gridKey
  4. get_macroGrid
  5. doubleVector_to_string
  6. file_check

   1 /*! \file io_parameter_impl.cpp
   2     \brief Implementation of `io_parameter_impl.h`
   3 
   4      Revision history
   5      --------------------------------------------------
   6 
   7           Revised by Christian Power April 2016
   8           Originally written by Christian Power
   9                (power22c@gmail.com) March 2016
  10 
  11      Idea
  12      --------------------------------------------------
  13 
  14      Implementation of some helper functions.
  15 
  16      \author Christian Power
  17      \date 16. April 2016
  18      \copyright Copyright (c) 2016 Christian Power. All rights reserved.
  19 */
  20 
  21 #include <fstream>
  22 #include <dassert.h>
  23 #include <config.h>
  24 #include <dune/fem/io/parameter.hh>
  25 #include <dune/fem/io/file/dataoutput.hh>
  26 #include "io_parameter_impl.h"
  27 #include "grid.h"
  28 #include "esfem_error.h"
  29 
  30 using namespace std;
  31 
  32 const std::string& Esfem::Impl::project_dir(){
  33   // static const std::string project_dir {"/Users/christianpower/cpp/DISS_surfaces/"}; 
  34   static const std::string project_dir {"/home/power/cpp/DISS_surfaces/"}; 
  35   // os depending
  36   return project_dir;
  37 }
  38 void Esfem::Impl::dune_fem_parameter_append(int argc, char** argv, const std::string& file){
  39   using Dune::Fem::Parameter;
  40   Parameter::append(argc, argv);
  41   for( int i = 1; i < argc; ++i )
  42     Parameter::append(argv[i]);
  43 #ifndef NDEBUG
  44   std::clog << "Using parameter file: " << file << std::endl;
  45 #endif 
  46   Parameter::append(file);
  47 }
  48 std::string Esfem::Impl::get_gridKey(){
  49   const auto grid_key = Dune::Fem::IOInterface::
  50     defaultGridKey(Esfem::Grid::Grid_and_time::Grid::dimension);
  51 #ifndef NDEBUG
  52   std::clog << "grid_key: " << grid_key << std::endl;
  53 #endif
  54   return grid_key;
  55 }
  56 std::string Esfem::Impl::get_macroGrid(){
  57   const auto grid_key = get_gridKey();
  58   const auto macro_grid = Dune::Fem::Parameter::getValue<std::string>(grid_key);
  59   if(Dune::Fem::MPIManager::rank() == 0)
  60     std::clog << "Loading macro grid: " << macro_grid << std::endl;
  61   return macro_grid;
  62 }
  63 std::string Esfem::Impl::doubleVector_to_string(const std::vector<double>& vd){
  64   constexpr size_t max_vec_size = 100;
  65   Assert::dynamic<Assert::level(1), Esfem::Parameter_error>
  66     (vd.size() <= max_vec_size,
  67      Assert::compose(__FILE__, __LINE__, 
  68                      "Vector is to big for doubleVector_to_string()"));
  69   std::ostringstream oss;
  70   oss << '{';
  71   for(std::size_t it = 0; it < vd.size() - 1; ++it)
  72     oss << vd[it] << ", ";
  73   oss <<  vd.back() << '}';
  74   return oss.str();
  75 }
  76 void Esfem::Impl::file_check(const std::vector<std::string>& file_list){  
  77   for(const auto& file_name : file_list){
  78     ofstream fs {file_name, ios_base::app};
  79     Assert::dynamic<Assert::level(1), Esfem::Parameter_error>
  80       (!fs.fail(),
  81        Assert::compose(__FILE__, __LINE__, file_name + ".fail() == true"));
  82   }
  83 }

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