Environment.cpp 1.04 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
#include <config.h>
2
3
4

#include "Environment.hpp"

Praetorius, Simon's avatar
Praetorius, Simon committed
5
#if AMDIS_HAS_PETSC
Praetorius, Simon's avatar
Praetorius, Simon committed
6
7
8
#include <petscsys.h>
#endif

9
10
11
12
13
14
15
16
17
18
19
20
21
// AMDiS includes
#include <amdis/Initfile.hpp>
#include <amdis/Output.hpp>

namespace AMDiS
{
  Environment::Environment(std::string const& initFileName)
  {
    Parameters::clearData();
    if (!initFileName.empty())
      Parameters::init(initFileName);
  }

Praetorius, Simon's avatar
Praetorius, Simon committed
22

23
24
25
  Environment::Environment(int& argc, char**& argv, std::string const& initFileName)
    : Environment(initFileName)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
26
#if AMDIS_HAS_PETSC
Praetorius, Simon's avatar
Praetorius, Simon committed
27
28
29
    PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
    petscInitialized_ = true;
#endif
30
31

    auto& mpi = Mpi::instance();
Praetorius, Simon's avatar
Praetorius, Simon committed
32
    mpi.registerMpiHelper(Dune::MPIHelper::instance(argc, argv));
33
34
35
36
37
38
39
40
41
42

    Parameters::clearData();
    if (initFileName.empty()) {
      if (argc > 1)
        Parameters::init(argv[1]);
      else
        warning("No initfile specified. Using default values for all parameters.");
    }
  }

Praetorius, Simon's avatar
Praetorius, Simon committed
43
44
45

  Environment::~Environment()
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
46
#if AMDIS_HAS_PETSC
Praetorius, Simon's avatar
Praetorius, Simon committed
47
48
49
50
51
    if (petscInitialized_)
      PetscFinalize();
#endif
  }

52
} // end namespace AMDiS