parallel.cc 4.54 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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <dune/dorie/dorie.hh> // System and DUNE Headers
#include <dune/dorie/interface/simulation.cc>

namespace Dune{
namespace Dorie{
	/// Resolve the second (default) template parameter of YaspGrid
	template<int dim>
	using YaspGrid = Dune::YaspGrid<dim>;
}
}

template<typename Traits>
using Sim = Dune::Dorie::Simulation<Traits>;

template<int dim, int order>
using Simplex = Dune::Dorie::BaseTraits<Dune::UGGrid,
	Dune::GeometryType::BasicType::simplex,dim,order,true,false>;

template<int dim, int order>
using SimplexAdaptive = Dune::Dorie::BaseTraits<Dune::UGGrid,
	Dune::GeometryType::BasicType::simplex,dim,order,true,true>;

template<int dim, int order>
using Cube = Dune::Dorie::BaseTraits<Dune::Dorie::YaspGrid,
	Dune::GeometryType::BasicType::cube,dim,order,true,false>;
29
/*
30 31 32
template<int dim, int order>
using CubeAdaptive = Dune::Dorie::BaseTraits<Dune::UGGrid,
	Dune::GeometryType::BasicType::cube,dim,order,true,true>;
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
int main(int argc, char** argv)
{
  try{
		Dune::Timer timer;

		//Initialize Mpi
		Dune::MPIHelper& helper = Dune::MPIHelper::instance(argc, argv);

		if (argc!=2)
			DUNE_THROW(Dune::IOError,"No parameter file specified!");
		const std::string inifilename = argv[1];

		// Read ini file
		Dune::ParameterTree inifile;
		Dune::ParameterTreeParser ptreeparser;
		ptreeparser.readINITree(inifilename,inifile);

		// Read necessary variables
		const std::string gtype = inifile.get<std::string>("grid.gridType");
		const int dim = inifile.get<int>("grid.dimensions");
		const int FEorder = inifile.get<int>("grid.FEorder");
		const int verbose = inifile.get<int>("output.verbose");
		const std::string outputPath = inifile.get<std::string>("output.outputPath");
		const bool adaptivity = inifile.get<bool>("adaptivity.useAdaptivity");

		// Attempt to create output directory
		mkdir(outputPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
	  int result = access(outputPath.c_str(), W_OK);
	  if (result != 0)
	    DUNE_THROW(Dune::IOError,"Output folder " << outputPath << " not writable");

		if (helper.rank()==0){
			std::cout << "INPUT FILE: " << inifilename << std::endl;
			std::cout << "BC FILE: " << inifile.get<std::string>("boundary.file") << std::endl;
			std::cout << "OUTPUT PATH: " << inifile.get<std::string>("output.outputPath") << std::endl;
			if (verbose>0){
				if(Dune::MPIHelper::isFake) std::cout << "MPI: SEQUENTIAL RUN" << std::endl;
				else std::cout << "MPI: PARALLEL RUN ON " << helper.size() << " PROCESS(ES)" << std::endl;
			}
		}

		if (dim==2)
		{
			if (gtype == "gmsh"){
				auto grid = Dune::Dorie::build_grid_gmsh<Dune::UGGrid<2>>(inifile,helper);
				if(adaptivity){
					switch(FEorder){
						case 1:{
							Sim<SimplexAdaptive<2,1>> sim(helper,grid,inifile);
							sim.run();
							break;
						}
						default:
							DUNE_THROW(Dune::NotImplemented,"Finite Element Order (grid.FEorder) not supported!");
					}
				}
				else{ // no adaptivity
					switch(FEorder){
						case 1:{
							Sim<Simplex<2,1>> sim(helper,grid,inifile);
							sim.run();
							break;
						}
						default:
							DUNE_THROW(Dune::NotImplemented,"Finite Element Order (grid.FEorder) not supported!");
					}
				}
			}
			else if (gtype == "rectangular"){
				if(adaptivity){
					auto grid = Dune::Dorie::build_grid_cube<Dune::UGGrid<2>>(inifile,helper);
					switch(FEorder){
						case 1:{
							Sim<CubeAdaptive<2,1>> sim(helper,grid,inifile);
							sim.run();
							break;
						}
						default:
							DUNE_THROW(Dune::NotImplemented,"Finite Element Order (grid.FEorder) not supported!");
					}
				}
				else{ // no adaptivity
					auto grid = Dune::Dorie::build_grid_cube<Dune::YaspGrid<2>>(inifile,helper);
					switch(FEorder){
						case 1:{
							Sim<Cube<2,1>> sim(helper,grid,inifile);
							sim.run();
							break;
						}
						default:
							DUNE_THROW(Dune::NotImplemented,"Finite Element Order (grid.FEorder) not supported!");
					}
126
				}
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
			}
			else
				DUNE_THROW(Dune::NotImplemented,"Grid Type not supported!");
		}

		// grid_dim != 2,3
		else{
		  DUNE_THROW(Dune::NotImplemented,"Number of dimensions (grid.dimensions) not supported!");
		}

		if(helper.rank()==0){
		  std::cout << "PROGRAM TERMINATED SUCCESSFULLY" << std::endl;
		  std::cout << "::: Execution time "
					<< std::setw(12) << std::setprecision(4) << std::scientific
					<< timer.elapsed() << std::endl;
		}

		return 0;
  }
  catch (Dune::Exception &e){
		std::cerr << "Dune reported error: " << e << std::endl;
		return 1;
  }
  catch (...){
		std::cerr << "Unknown exception thrown!" << std::endl;
		throw;
		return 1;
  }
}