root/src/io_parameter.cpp

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

DEFINITIONS

This source file includes following definitions.
  1. grid
  2. error_log
  3. paraview
  4. start_time
  5. global_timeStep
  6. max_timeSteps
  7. prePattern_timeSteps
  8. pattern_timeSteps
  9. last_step
  10. eps
  11. bdf_alphas
  12. bdf_gammas
  13. tg_a
  14. tg_b
  15. tg_Dc
  16. tg_gamma
  17. velocity_regularization
  18. surface_growthFactor
  19. mcf_regularization
  20. u_hom_value
  21. w_hom_value
  22. u_pertubation
  23. w_pertubation
  24. u_init_dof
  25. w_init_dof

   1 /*! \file io_parameter.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) 27. Januar 2016
  10 
  11      Implementation details for io_parameter.h
  12      Created by Christian Power on 27.01.2016
  13      Copyright (c) 2016 Christian Power. All rights reserved.
  14  */
  15 
  16 #include <config.h>
  17 #include <sstream>
  18 #include <dune/fem/io/parameter.hh>
  19 #include <dune/fem/io/file/dataoutput.hh>
  20 #include <bdf.h>
  21 #include <dassert.h>
  22 #include "esfem_error.h"
  23 #include "io_parameter.h"
  24 #include "io_parameter_impl.h"
  25 
  26 using namespace std;
  27 // using Dune::Fem::Parameter;
  28 using Esfem::Io::Parameter;
  29 // ----------------------------------------------------------------------
  30 // Implementation of Esfem::Io::Parameter
  31 
  32 struct Parameter::Data{
  33   const double t_0;
  34   const double t_end;
  35   const double t_end_pattern;
  36   const double dT;
  37   const std::string grid_dgf;
  38   const std::string error_log;
  39   const std::string paraview;
  40   const double eps;
  41   const std::vector<double> bdf_alphas;
  42   const std::vector<double> bdf_gammas;
  43   // bdf coefficients ordered w.r.t. the polynomial order: from X^0 to X^n
  44   const double tg_a;
  45   const double tg_b;
  46   const double tg_Dc;
  47   const double tg_gamma;
  48   const double velocity_regularization;
  49   const double surface_growthFactor;
  50   const double mcf_regularization;
  51   const double u_hom_value;
  52   const double w_hom_value;
  53   const double u_pertubation;
  54   const double w_pertubation;
  55   const std::string u_init_dof;
  56   const std::string w_init_dof;
  57   Data();
  58 };
  59 
  60 Esfem::Io::Parameter::Data::Data()
  61   : t_0 {Dune::Fem::Parameter::getValue<double>("heat.starttime", 0.0)},
  62   t_end {Dune::Fem::Parameter::getValue<double>("heat.endtime", 0.6)},
  63   t_end_pattern {Dune::Fem::Parameter::getValue<double>("heat.pattern.endtime", t_end)},
  64   dT {Dune::Fem::Parameter::getValue<double>("heat.timestep",0.1)},
  65   grid_dgf {Esfem::Impl::get_macroGrid()},
  66   error_log {Dune::Fem::Parameter::getValue<std::string>
  67       ("fem.io.errorFile", Esfem::Impl::project_dir() + "output/l2h1error")},
  68   paraview {Dune::Fem::Parameter::getValue<std::string> 
  69       ("fem.io.outputName", Esfem::Impl::project_dir() + 
  70        "output/ALE_LiteratureExample-")},
  71   eps {Dune::Fem::Parameter::getValue<double>("heat.solvereps", 1e-8)},
  72   bdf_alphas {NUMERIK::bdf_alpha_coeff
  73       (Dune::Fem::Parameter::getValue<int>("heat.bdf", 1))},
  74   bdf_gammas {NUMERIK::bdf_gamma_coeff
  75       (Dune::Fem::Parameter::getValue<int>("heat.bdf", 1))},
  76   tg_a {Dune::Fem::Parameter::getValue<double>("tumor_growth.heat.a", .1)},
  77   tg_b {Dune::Fem::Parameter::getValue<double>("tumor_growth.heat.b", .9)},
  78   tg_Dc {Dune::Fem::Parameter::getValue<double>("tumor_growth.heat.Dc", 10.)},
  79   tg_gamma {Dune::Fem::Parameter::getValue<double>("tumor_growth.heat.gamma", 30.)},
  80   velocity_regularization
  81   {Dune::Fem::Parameter::getValue<double>("tumor_growth.surface.alpha", 1e-3)},
  82   surface_growthFactor
  83   {Dune::Fem::Parameter::getValue<double>("tumor_growth.surface.delta", .4)},
  84   mcf_regularization
  85   {Dune::Fem::Parameter::getValue<double>("tumor_growth.surface.epsilon", .01)},
  86   u_hom_value {Dune::Fem::Parameter::getValue<double>
  87       ("tumor_growth.heat.u_hom", tg_a + tg_b)},
  88   w_hom_value {Dune::Fem::Parameter::getValue<double>
  89       ("tumor_growth.heat.w_hom", tg_b  / ( u_hom_value * u_hom_value ) )},
  90   u_pertubation {Dune::Fem::Parameter::getValue<double>("tumor_growth.heat.u_pertubation", .01)},
  91   w_pertubation {Dune::Fem::Parameter::getValue<double>("tumor_growth.heat.w_pertubation", .01)},
  92   u_init_dof {Dune::Fem::Parameter::getValue<std::string>
  93       ("tumor_growth.io.u_init_dof", Esfem::Impl::project_dir() + "output/u_dof.log")},
  94   w_init_dof {Dune::Fem::Parameter::getValue<std::string>
  95       ("tumor_growth.io.w_init_dof", Esfem::Impl::project_dir() + "output/w_dof.log")}
  96 {
  97   Assert::dynamic<Assert::level(1), Esfem::Parameter_error>
  98     (eps > 0, Assert::compose(__FILE__, __LINE__, "Non positive tolerance."));
  99   Assert::dynamic<Assert::level(1), Esfem::Parameter_error>
 100     ( dT > eps, Assert::compose(__FILE__, __LINE__, "Time step too small."));
 101   Assert::dynamic<Assert::level(1), Esfem::Parameter_error>
 102     ((t_0 <= t_end_pattern) && (t_end_pattern <= t_end),
 103      Assert::compose
 104      (__FILE__, __LINE__, "Something is wrong with heat.starttime, "
 105       "heat.endtime or heat.pattern.starttime."));
 106   Esfem::Impl::file_check({grid_dgf, error_log, u_init_dof, w_init_dof});
 107 }
 108 
 109 Esfem::Io::Parameter::Parameter(int argc, char** argv,
 110                                 const std::string& parameter_file_name){
 111   Esfem::Impl::dune_fem_parameter_append(argc, argv, parameter_file_name);
 112   d_ptr =  make_unique<Data>();
 113 
 114   // const auto bdf_no = Dune::Fem::Parameter::getValue<int>("heat.bdf", 1);
 115   // check_bdfNo(bdf_no);
 116 
 117   // const auto t0 = Parameter::getValue<double>("heat.starttime", 0.0);
 118   // const auto t_end = Parameter::getValue<double>("heat.endtime", 0.6);
 119   // const auto t0_pat = Parameter::getValue<double>("heat.pattern.starttime", t_end);
 120   // check t0, t0_pattern, t_end
 121 
 122   // const auto a = Parameter::getValue<double>("tumor_growth.heat.a", .1);
 123   // const auto b = Parameter::getValue<double>("tumor_growth.heat.b", .9);
 124   // const auto u_hom = Parameter::getValue<double>("tumor_growth.heat.u_hom",
 125   //                                             a + b);
 126   // const auto w_hom = Parameter::getValue<double>("tumor_growth.heat.w_hom",
 127   //                                             b  / ( u_hom * u_hom ) );
 128   
 129   // d_ptr =  make_unique<Data>();
 130     // (Data{
 131     //   t0,
 132     //  Parameter::getValue<double>("heat.timestep",0.1),
 133     //  t0_pat,
 134     //  t_end,
 135     //  Esfem::Impl::get_macroGrid(),
 136     //  Parameter::getValue<std::string>
 137     //  ("fem.io.errorFile", Esfem::Impl::project_dir() + "output/l2h1error"),
 138     //  Parameter::getValue<std::string> 
 139     //  ("fem.io.outputName", Esfem::Impl::project_dir() + 
 140     //   "output/ALE_LiteratureExample-"),
 141     //  Dune::Fem::Parameter::getValue<double>("heat.solvereps", 1e-8),
 142     //  NUMERIK::bdf_alpha_coeff(bdf_no),
 143     //  NUMERIK::bdf_gamma_coeff(bdf_no),
 144     //  a,
 145     //  b,
 146     //  Parameter::getValue<double>("tumor_growth.heat.Dc", 10.),
 147     //  Parameter::getValue<double>("tumor_growth.heat.gamma", 30.),
 148     //  u_hom,
 149     //  w_hom,
 150     //  Parameter::getValue<double>("tumor_growth.heat.u_pertubation", .01),
 151     //  Parameter::getValue<double>("tumor_growth.heat.w_pertubation", .01),
 152     //  Parameter::getValue<std::string>("tumor_growth.io.u_init_dof",
 153     //                                   Esfem::Impl::project_dir() + "output/u_dof.log"),
 154     //  Parameter::getValue<std::string>("tumor_growth.io.w_init_dof",
 155     //                                   Esfem::Impl::project_dir() + "output/w_dof.log")
 156     //  }
 157     //   );
 158 }
 159 Esfem::Io::Parameter::~Parameter() = default;
 160 const std::string& Esfem::Io::Parameter::grid() const noexcept{
 161   return d_ptr -> grid_dgf;
 162 }
 163 const std::string& Esfem::Io::Parameter::error_log() const noexcept{
 164   return d_ptr -> error_log;
 165 }
 166 const std::string& Esfem::Io::Parameter::paraview() const noexcept{
 167   return d_ptr -> paraview;
 168 }
 169 double Esfem::Io::Parameter::start_time() const noexcept{
 170   return d_ptr -> t_0;
 171 }
 172 double Esfem::Io::Parameter::global_timeStep() const noexcept{
 173   return d_ptr -> dT;
 174 }
 175 long Esfem::Io::Parameter::max_timeSteps() const{
 176   const auto t_n = d_ptr->t_end;
 177   const auto t_0 = d_ptr->t_0;
 178   return (t_n - t_0)/d_ptr->dT + .1;
 179 }
 180 long Esfem::Io::Parameter::prePattern_timeSteps() const{
 181   const auto t_n = d_ptr->t_end_pattern;
 182   const auto t_0 = d_ptr->t_0;
 183   return (t_n - t_0)/d_ptr->dT + .1;
 184 }
 185 long Esfem::Io::Parameter::pattern_timeSteps() const{
 186   const auto t_n = d_ptr->t_end;
 187   const auto t_0 = d_ptr->t_end_pattern;
 188   return (t_n - t_0)/d_ptr->dT; // may narrow
 189 }
 190 double Esfem::Io::Parameter::last_step() const{
 191   const double rv = d_ptr->t_end - global_timeStep() * max_timeSteps();
 192   return rv > 0 ? rv : 0;
 193 }
 194 double Esfem::Io::Parameter::eps() const noexcept{
 195   return d_ptr -> eps;
 196 }
 197 const std::vector<double>& Esfem::Io::Parameter::bdf_alphas() const noexcept{
 198   return d_ptr -> bdf_alphas;
 199 }
 200 const std::vector<double>& Esfem::Io::Parameter::bdf_gammas() const noexcept{
 201   return d_ptr -> bdf_gammas;
 202 }
 203 double Esfem::Io::Parameter::tg_a() const noexcept{
 204   return d_ptr -> tg_a;
 205 }
 206 double Esfem::Io::Parameter::tg_b() const noexcept{
 207   return d_ptr -> tg_b;
 208 }
 209 double Esfem::Io::Parameter::tg_Dc() const noexcept{
 210   return d_ptr -> tg_Dc;
 211 }
 212 double Esfem::Io::Parameter::tg_gamma() const noexcept{
 213   return d_ptr -> tg_gamma;
 214 }
 215 double Parameter::velocity_regularization() const noexcept{
 216   return d_ptr -> velocity_regularization;
 217 }
 218 double Parameter::surface_growthFactor() const noexcept{
 219   return d_ptr -> surface_growthFactor;
 220 }
 221 double Parameter::mcf_regularization() const noexcept{
 222   return d_ptr -> mcf_regularization;
 223 }
 224 double Esfem::Io::Parameter::u_hom_value() const noexcept{
 225   return d_ptr -> u_hom_value;
 226 }
 227 double Esfem::Io::Parameter::w_hom_value() const noexcept{
 228   return d_ptr -> w_hom_value;
 229 }
 230 double Esfem::Io::Parameter::u_pertubation() const noexcept{
 231   return d_ptr -> u_pertubation;
 232 }
 233 double Esfem::Io::Parameter::w_pertubation() const noexcept{
 234   return d_ptr -> w_pertubation;
 235 }
 236 const std::string& Esfem::Io::Parameter::u_init_dof() const noexcept{
 237   return d_ptr -> u_init_dof;
 238 }
 239 const std::string& Esfem::Io::Parameter::w_init_dof() const noexcept{
 240   return d_ptr -> w_init_dof;
 241 }
 242 
 243 std::ostream& Esfem::Io::operator<<(std::ostream& os, const Parameter& d){
 244   using Dune::Fem::Parameter;
 245   const auto& p = d.d_ptr;
 246   os << "t_0: " << p->t_0 << '\n'
 247      << "dT: " << p->dT << '\n'
 248      << "t_end_pattern: " << p-> t_end_pattern << '\n'
 249      << "t_end: " << p->t_end << '\n'
 250      << "grid_dgf: " << p->grid_dgf << '\n'
 251      << "error_log: " << p->error_log << '\n'
 252      << "paraview: " << p->paraview << '\n'
 253      << "eps: " << p->eps << '\n'
 254      << "bdf_alphas: " << Esfem::Impl::doubleVector_to_string(p->bdf_alphas) << '\n'
 255      << "bdf_gammas: " << Esfem::Impl::doubleVector_to_string(p->bdf_gammas) << '\n'
 256      << "tg_a: " << p->tg_a << '\n'
 257      << "tg_b: " << p->tg_b << '\n'
 258      << "tg_Dc: " << p->tg_Dc << '\n'
 259      << "tg_gamma: " << p->tg_gamma << '\n'
 260      << "velocity_regularization: " << p->velocity_regularization << '\n'
 261      << "surface_growthFactor: " << p->surface_growthFactor << '\n'
 262      << "mcf_regularization: " << p->mcf_regularization << '\n'
 263      << "u_hom_value: " << p -> u_hom_value << '\n'
 264      << "w_hom_value: " << p -> w_hom_value << '\n'
 265      << "u_pertubation: " << p -> u_pertubation << '\n'
 266      << "w_pertubation: " << p -> w_pertubation << '\n'
 267      << "u_init_dof: " << p -> u_init_dof << '\n'
 268      << "w_init_dof: " << p -> w_init_dof << '\n'
 269      << "logistic_growth.r_start: "
 270      << Parameter::getValue<double>("logistic_growth.r_start", 1.) << '\n'
 271      << "logistic_growth.r_end: "
 272      << Parameter::getValue<double>("logistic_growth.r_end", 2.) << '\n'
 273      << "logistic_growth.steepness: "
 274      << Parameter::getValue<double>("logistic_growth.steepness", .5)
 275     ;
 276   return os;
 277 }

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