Commit c3dc225d authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

added Environment for MPI initialization

parent 73513f33
...@@ -95,7 +95,7 @@ void run_periodic() ...@@ -95,7 +95,7 @@ void run_periodic()
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
auto b = [](auto const& x){ return x[0] < 1.e-8 || x[1] < 1.e-8 || x[0] > 1.0-1.e-8 || x[1] > 1.0-1.e-8; }; auto b = [](auto const& x){ return x[0] < 1.e-8 || x[1] < 1.e-8 || x[0] > 1.0-1.e-8 || x[1] > 1.0-1.e-8; };
...@@ -119,6 +119,5 @@ int main(int argc, char** argv) ...@@ -119,6 +119,5 @@ int main(int argc, char** argv)
run_periodic(); run_periodic();
AMDiS::finalize();
return 0; return 0;
} }
...@@ -13,7 +13,7 @@ using Param = LagrangeBasis<Grid, 1, 1>; ...@@ -13,7 +13,7 @@ using Param = LagrangeBasis<Grid, 1, 1>;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
ProblemStat<Param> prob("ch"); ProblemStat<Param> prob("ch");
prob.initialize(INIT_ALL); prob.initialize(INIT_ALL);
...@@ -68,6 +68,5 @@ int main(int argc, char** argv) ...@@ -68,6 +68,5 @@ int main(int argc, char** argv)
AdaptInstationary adapt("adapt", prob, adaptInfo, probInstat, adaptInfo); AdaptInstationary adapt("adapt", prob, adaptInfo, probInstat, adaptInfo);
adapt.adapt(); adapt.adapt();
AMDiS::finalize();
return 0; return 0;
} }
...@@ -17,7 +17,7 @@ using ElliptProblem = ProblemStat<ElliptParam>; ...@@ -17,7 +17,7 @@ using ElliptProblem = ProblemStat<ElliptParam>;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
using namespace Dune::Indices; using namespace Dune::Indices;
...@@ -39,6 +39,5 @@ int main(int argc, char** argv) ...@@ -39,6 +39,5 @@ int main(int argc, char** argv)
prob.solve(adaptInfo); prob.solve(adaptInfo);
prob.writeFiles(adaptInfo, true); prob.writeFiles(adaptInfo, true);
AMDiS::finalize();
return 0; return 0;
} }
...@@ -18,7 +18,7 @@ using ElliptProblem = ProblemStat<Param>; ...@@ -18,7 +18,7 @@ using ElliptProblem = ProblemStat<Param>;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
int numLevels = GRIDDIM == 2 ? 8 : 5; int numLevels = GRIDDIM == 2 ? 8 : 5;
if (argc > 2) if (argc > 2)
...@@ -92,6 +92,5 @@ int main(int argc, char** argv) ...@@ -92,6 +92,5 @@ int main(int argc, char** argv)
msg("{:<5} | {:<12} | {:<12} | {:<12} | {:<12} | {:<12}", msg("{:<5} | {:<12} | {:<12} | {:<12} | {:<12} | {:<12}",
i+1, widths[i], errL2[i], errH1[i], eocL2[i], eocH1[i]); i+1, widths[i], errL2[i], errH1[i], eocL2[i], eocH1[i]);
AMDiS::finalize();
return 0; return 0;
} }
...@@ -21,7 +21,7 @@ using HeatProblemInstat = ProblemInstat<HeatParam>; ...@@ -21,7 +21,7 @@ using HeatProblemInstat = ProblemInstat<HeatParam>;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
HeatProblem prob("heat"); HeatProblem prob("heat");
prob.initialize(INIT_ALL); prob.initialize(INIT_ALL);
...@@ -55,6 +55,5 @@ int main(int argc, char** argv) ...@@ -55,6 +55,5 @@ int main(int argc, char** argv)
AdaptInstationary adapt("adapt", prob, adaptInfo, probInstat, adaptInfo); AdaptInstationary adapt("adapt", prob, adaptInfo, probInstat, adaptInfo);
adapt.adapt(); adapt.adapt();
AMDiS::finalize();
return 0; return 0;
} }
...@@ -12,7 +12,7 @@ using Basis = TaylorHoodBasis<Grid>; ...@@ -12,7 +12,7 @@ using Basis = TaylorHoodBasis<Grid>;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
ProblemStat<Basis> prob("stokes"); ProblemStat<Basis> prob("stokes");
prob.initialize(INIT_ALL); prob.initialize(INIT_ALL);
...@@ -89,6 +89,5 @@ int main(int argc, char** argv) ...@@ -89,6 +89,5 @@ int main(int argc, char** argv)
// output solution // output solution
prob.writeFiles(adaptInfo); prob.writeFiles(adaptInfo);
AMDiS::finalize();
return 0; return 0;
} }
...@@ -51,7 +51,7 @@ void run(Grid& grid) ...@@ -51,7 +51,7 @@ void run(Grid& grid)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
// 2d grids // 2d grids
...@@ -85,6 +85,5 @@ int main(int argc, char** argv) ...@@ -85,6 +85,5 @@ int main(int argc, char** argv)
Dune::YaspGrid<3> grid4({1.0,1.0,1.0},{2,2,2}); Dune::YaspGrid<3> grid4({1.0,1.0,1.0},{2,2,2});
run(grid4); run(grid4);
AMDiS::finalize();
return 0; return 0;
} }
...@@ -79,7 +79,7 @@ void run(Grid& grid) ...@@ -79,7 +79,7 @@ void run(Grid& grid)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
#if HAVE_DUNE_SPGRID #if HAVE_DUNE_SPGRID
Dune::SPCube<double,2> cube({0.0,0.0},{1.0,1.0}); Dune::SPCube<double,2> cube({0.0,0.0},{1.0,1.0});
...@@ -92,6 +92,5 @@ int main(int argc, char** argv) ...@@ -92,6 +92,5 @@ int main(int argc, char** argv)
Dune::YaspGrid<2> grid2({1.0,1.0}, {2,2}); Dune::YaspGrid<2> grid2({1.0,1.0}, {2,2});
run(grid2); run(grid2);
AMDiS::finalize();
return 0; return 0;
} }
...@@ -10,7 +10,7 @@ using StokesProblem = ProblemStat<StokesParam>; ...@@ -10,7 +10,7 @@ using StokesProblem = ProblemStat<StokesParam>;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
StokesProblem prob("stokes"); StokesProblem prob("stokes");
prob.initialize(INIT_ALL); prob.initialize(INIT_ALL);
...@@ -58,6 +58,5 @@ int main(int argc, char** argv) ...@@ -58,6 +58,5 @@ int main(int argc, char** argv)
// output solution // output solution
prob.writeFiles(adaptInfo); prob.writeFiles(adaptInfo);
AMDiS::finalize();
return 0; return 0;
} }
...@@ -10,7 +10,7 @@ using StokesProblem = ProblemStat<StokesParam>; ...@@ -10,7 +10,7 @@ using StokesProblem = ProblemStat<StokesParam>;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
StokesProblem prob("stokes"); StokesProblem prob("stokes");
prob.initialize(INIT_ALL); prob.initialize(INIT_ALL);
...@@ -58,6 +58,5 @@ int main(int argc, char** argv) ...@@ -58,6 +58,5 @@ int main(int argc, char** argv)
// output solution // output solution
prob.writeFiles(adaptInfo); prob.writeFiles(adaptInfo);
AMDiS::finalize();
return 0; return 0;
} }
...@@ -11,7 +11,7 @@ using StokesProblem = ProblemStat<StokesParam>; ...@@ -11,7 +11,7 @@ using StokesProblem = ProblemStat<StokesParam>;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
StokesProblem prob("stokes"); StokesProblem prob("stokes");
prob.initialize(INIT_ALL); prob.initialize(INIT_ALL);
...@@ -48,6 +48,5 @@ int main(int argc, char** argv) ...@@ -48,6 +48,5 @@ int main(int argc, char** argv)
// output solution // output solution
prob.writeFiles(adaptInfo); prob.writeFiles(adaptInfo);
AMDiS::finalize();
return 0; return 0;
} }
...@@ -15,7 +15,7 @@ using ElliptProblem = ProblemStat<ElliptParam>; ...@@ -15,7 +15,7 @@ using ElliptProblem = ProblemStat<ElliptParam>;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
AMDiS::init(argc, argv); Environment env(argc, argv);
ElliptProblem prob("ellipt"); ElliptProblem prob("ellipt");
prob.initialize(INIT_ALL); prob.initialize(INIT_ALL);
...@@ -53,6 +53,5 @@ int main(int argc, char** argv) ...@@ -53,6 +53,5 @@ int main(int argc, char** argv)
prob.solve(adaptInfo); prob.solve(adaptInfo);
prob.writeFiles(adaptInfo, true); prob.writeFiles(adaptInfo, true);
AMDiS::finalize();
return 0; return 0;
} }
#include "AMDiS.hpp"
// AMDiS includes
#include <amdis/Initfile.hpp>
#include <amdis/Output.hpp>
namespace AMDiS
{
Dune::MPIHelper& init(int& argc, char**& argv, std::string const& initFileName)
{
// Maybe initialize MPI
static Dune::MPIHelper& mpiHelper = Dune::MPIHelper::instance(argc, argv);
Parameters::clearData();
if (initFileName.empty() && argc > 1) {
Parameters::init(argv[1]);
} else if (!initFileName.empty()) {
Parameters::init(initFileName);
} else {
warning("No initfile specified. Using default values for all parameters.");
}
return mpiHelper;
}
void finalize()
{}
} // end namespace AMDiS
...@@ -4,16 +4,11 @@ ...@@ -4,16 +4,11 @@
# include "config.h" # include "config.h"
#endif #endif
// std c++ headers #include <amdis/AdaptInfo.hpp>
#include <string> #include <amdis/Environment.hpp>
#include <amdis/Initfile.hpp>
#include <dune/common/exceptions.hh> // We use exceptions #include <amdis/LinearAlgebra.hpp>
#include <dune/common/parallel/mpihelper.hh> #include <amdis/Output.hpp>
#include <amdis/ProblemStat.hpp>
namespace AMDiS
{ namespace AMDiS {} // end namespace AMDiS
Dune::MPIHelper& init(int& argc, char**& argv, std::string const& initFileName = "");
void finalize();
} // end namespace AMDiS
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "AdaptInfo.hpp" #include "AdaptInfo.hpp"
// std c++ headers // std c++ headers
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "AdaptInstationary.hpp" #include "AdaptInstationary.hpp"
// AMDiS includes // AMDiS includes
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "AdaptStationary.hpp" #include "AdaptStationary.hpp"
// AMDiS includes // AMDiS includes
......
...@@ -4,7 +4,7 @@ dune_library_add_sources(amdis SOURCES ...@@ -4,7 +4,7 @@ dune_library_add_sources(amdis SOURCES
AdaptInfo.cpp AdaptInfo.cpp
AdaptInstationary.cpp AdaptInstationary.cpp
AdaptStationary.cpp AdaptStationary.cpp
AMDiS.cpp Environment.cpp
Initfile.cpp Initfile.cpp
InitfileParser.cpp InitfileParser.cpp
ProblemInstatBase.cpp ProblemInstatBase.cpp
...@@ -31,6 +31,7 @@ install(FILES ...@@ -31,6 +31,7 @@ install(FILES
DataTransfer.inc.hpp DataTransfer.inc.hpp
DirichletBC.hpp DirichletBC.hpp
DirichletBC.inc.hpp DirichletBC.inc.hpp
Environment.hpp
FileWriter.hpp FileWriter.hpp
FileWriterInterface.hpp FileWriterInterface.hpp
Flag.hpp Flag.hpp
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <dune/common/fvector.hh> #include <dune/common/fvector.hh>
#include <dune/common/hash.hh> #include <dune/common/hash.hh>
#include <dune/grid/common/geometry.hh>
#include <dune/grid/common/mcmgmapper.hh> #include <dune/grid/common/mcmgmapper.hh>
#include <dune/grid/common/rangegenerators.hh> #include <dune/grid/common/rangegenerators.hh>
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "Environment.hpp"
// 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);
}
Environment::Environment(int& argc, char**& argv, std::string const& initFileName)
: Environment(initFileName)
{
auto& helper = Dune::MPIHelper::instance(argc, argv);
auto& mpi = Mpi::instance();
mpi.registerMpiHelper(helper);
Parameters::clearData();
if (initFileName.empty()) {
if (argc > 1)
Parameters::init(argv[1]);
else
warning("No initfile specified. Using default values for all parameters.");
}
}
} // end namespace AMDiS
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment