diff --git a/OpenMP/reader.cpp b/OpenMP/reader.cpp index 8c02e0d..75b19e8 100644 --- a/OpenMP/reader.cpp +++ b/OpenMP/reader.cpp @@ -1,68 +1,68 @@ // // Created by Arnaud Pannatier on 06.05.18. // #include "reader.h" #include #include - +#include Grid Reader::readGridFromFile (std::string filename,std::size_t nx, std::size_t ny) { Grid ret = Grid(nx,ny); //std::cout << filename << std::endl; std::ifstream file (filename, std::ios::in | std::ios::binary); if (file.is_open()) { char * memblock; file.ignore( std::numeric_limits::max() ); std::streamsize size = file.gcount(); file.clear(); //std::cout << size << " -- size " << std::endl; memblock = new char[size]; file.seekg (0, std::ios::beg); file.read (memblock, size); file.close(); //std::cout << "the entire file content is in memory" << std::endl; double* double_values = reinterpret_cast(memblock); for(std::size_t x(0); x(double_values); std::ofstream file(filename, std::ios::out | std::ios::binary); file.write (memblock, sizeof(memblock)*nx*ny); std::cout << "Grid Saved ! " << std::endl; delete double_values; } diff --git a/Sequential/CMakeLists.txt b/Sequential/CMakeLists.txt index ba29886..11761a1 100644 --- a/Sequential/CMakeLists.txt +++ b/Sequential/CMakeLists.txt @@ -1,9 +1,9 @@ -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 2.8) project(phpctsunamiproject) set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_FLAGS "-O3 -ftree-vectorize") +set(CMAKE_CXX_FLAGS "-std=c++11 -O3 -ftree-vectorize") add_executable(Test Test.cpp grid.cpp grid.h) -add_executable(phpctsunamiproject main.cpp grid.cpp grid.h double_buffer.cpp double_buffer.h simulation.cpp simulation.h reader.cpp reader.h) \ No newline at end of file +add_executable(phpctsunamiproject main.cpp grid.cpp grid.h double_buffer.cpp double_buffer.h simulation.cpp simulation.h reader.cpp reader.h) diff --git a/Sequential/simulation.cpp b/Sequential/simulation.cpp index ffbc1cd..fa1991a 100644 --- a/Sequential/simulation.cpp +++ b/Sequential/simulation.cpp @@ -1,194 +1,196 @@ // // Created by Arnaud Pannatier on 06.05.18. // Based on the code of : // - Nicolas Richart // - Vincent Keller // - Vittoria Rezzonico // See the files AUTHORS and COPYRIGHT for the concerning information // /* -------------------------------------------------------------------------- */ #include "simulation.h" #include "reader.h" /* -------------------------------------------------------------------------- */ #include #include +#include +#include Simulation::Simulation (std::size_t NX_, double G_, int SIZE_, double TEND_, double DX_, std::string dir_) :NX(NX_), NY(NX_),dir(dir_), G(G_),TEND(TEND_),DX(DX_),dt(0),T(0),nt(0),SIZE(SIZE_), H(DoubleBuffer(NX,NX)), HU(DoubleBuffer(NX,NX)), HV(DoubleBuffer(NX,NX)), Zdx(Grid(NX,NX)), Zdy(Grid(NX,NX)){}; void Simulation::readInitialConditionsFromFile () { std::stringstream filename, filenameH, filenameHU,filenameHV, filenameZdx, filenameZdy; filename << dir << "Data_nx" << NX << "_" << SIZE << "km_T" <<"0.2"; filenameH << filename.str() << "_h.bin"; filenameHU << filename.str() << "_hu.bin"; filenameHV << filename.str() << "_hv.bin"; filenameZdx << filename.str() << "_Zdx.bin"; filenameZdy << filename.str() << "_Zdy.bin"; // Load initial condition from data files H.current () = Reader::readGridFromFile(filenameH.str(), NX,NX); HU.current() = Reader::readGridFromFile(filenameHU.str(), NX,NX); HV.current() = Reader::readGridFromFile(filenameHV.str(), NX,NX); // Load topography slopes from data files Zdx = Reader::readGridFromFile(filenameZdx.str(), NX,NX); Zdy = Reader::readGridFromFile(filenameZdy.str(), NX,NX); //std::cout << "ZDX (486,486) " << Zdx(486,486) << std::endl; //std::cout << "ZDy (486,486) " << Zdy(486,486) << std::endl; // Allocate memory for computing H.old () = Grid(NX,NX); HU.old() = Grid(NX,NX); HV.old() = Grid(NX,NX); std::cout << "Data Loaded - Start of Simulation " << std::endl; } /* -------------------------------------------------------------------------- */ std::tuple Simulation::compute() { int s = 0; double totalTime = 0; auto begin = std::chrono::high_resolution_clock::now (); readInitialConditionsFromFile(); while(T < TEND){ s++; auto start = std::chrono::high_resolution_clock::now (); compute_mu_and_set_dt (); compute_step(); T = T + dt; nt = nt + 1; auto end = std::chrono::high_resolution_clock::now(); auto duration = end-start; auto ms = std::chrono::duration_cast(duration).count(); std::cout << "\r" << " dt : " << dt << " Computing T: " << T << ". " << (100*T/TEND) <<"%" << " --------- Time for a step : " << ms << " " << std::flush; } writeResultsToFile (); auto end = std::chrono::high_resolution_clock::now(); auto duration = end-begin; totalTime = std::chrono::duration_cast(duration).count(); return std::make_tuple(totalTime, s); } /* -------------------------------------------------------------------------- */ void Simulation::compute_mu_and_set_dt () { double Max = 0.0; double Current; Grid& cH = H.current(); Grid& cHU = HU.current(); Grid& cHV = HV.current(); for(std::size_t i(0); i Max){ Max = Current; } //if(i == 186 && j == 186){ // std::cout << Current << std::endl; //} } } dt = DX/(sqrt(2)*Max); //std::cout << "DT : " << dt << " --------------------------" << H.current()(486,486) << std::endl; if(T+dt > TEND){ dt = TEND-T; } } void Simulation::compute_step () { H.swap(); HU.swap(); HV.swap(); H.old().applyBoundaryConditions(); HU.old().applyBoundaryConditions(); HV.old().applyBoundaryConditions(); Grid& oH = H.old(); Grid& oHU = HU.old(); Grid& oHV = HV.old(); Grid& cH = H.current(); double C = 0.5*dt/DX; //std::cout << C << " " << G << std::endl; for(std::size_t i(1);i