AMDiS.cpp 2.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "AMDiS.hpp"

// std c++ headers
#include <string>

#include <boost/program_options.hpp>

#include <dune/common/parallel/mpihelper.hh> // An initializer of MPI

// AMDiS includes
#include "Initfile.hpp"
#include "Log.hpp"

namespace AMDiS
{
//   using namespace std;

  void init(int argc, char** argv, std::string initFileName)
  {
    // Maybe initialize MPI
    Dune::MPIHelper& helper = Dune::MPIHelper::instance(argc, argv);
    
    Parameters::clearData();

    // read commandline arguments
    namespace po = boost::program_options;

    // Declare the supported options.
    po::options_description desc("Usage: " + std::string(argv[0]) + " init-file [options]\nAllowed options");
    desc.add_options()
    ("help", "produce help message")
    ("init-file", po::value<std::string>(), "set init file")
    ("parameters", po::value<std::string>(), "set parameter in init file\nsyntax: \"key1: value1; key2: value2...\"");

    po::options_description hidden("Hidden options");
    hidden.add_options()
    ("unknown", po::value<std::vector<std::string>>(), "unknown options");

    po::options_description cmdline_options;
    cmdline_options.add(desc).add(hidden);

    // first argument is init-filename
    po::positional_options_description p;
    p.add("init-file", 1);
    p.add("unknown", -1);

    // parse comandline
    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).allow_unregistered().run(), vm);
    po::notify(vm);

    // print help message
    if (vm.count("help"))
    {
      std::cout << desc << "\n";
      exit(1);
    }

    // set parameters before reading the initfile
    // if (vm.count("parameters"))
    //   Parameters::readArgv(vm["parameters"].as<std::string>());

    if (initFileName == "")
    {
      if (vm.count("init-file"))
        Parameters::init(vm["init-file"].as<std::string>());
      else
      {
        AMDIS_ERROR_EXIT("No init file specified!\n");
      }
    }
    else
    {
      Parameters::init(initFileName);
    }

    // reset parameters from command line
    bool ignoreCommandline = false;
    Parameters::get("ignore commandline options", ignoreCommandline);
    // if (vm.count("parameters") && !ignoreCommandline)
    //   Parameters::readArgv(vm["parameters"].as<std::string>(),0);
    // TODO: add command-line arguments again.
  }


  void init(std::string initFileName)
  {
    Parameters::init(initFileName);
  }


  void finalize()
  {}

} // end namespace AMDiS