diff --git a/inc/Output.h b/inc/Output.h index 7f4033a..545882f 100644 --- a/inc/Output.h +++ b/inc/Output.h @@ -68,6 +68,10 @@ namespace Output { /// \brief Print final program screen /// void farewellScreen(); + + /// \brief Print elapsed time + /// + void printElapsedTime(); } #endif /* OUTPUT_H_ */ diff --git a/src/Input.cpp b/src/Input.cpp index 9906206..9abc526 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -137,10 +137,8 @@ Solver* Input::getSolver() { return new SolverExplicitUSL(); } - throw (key); } - throw(0); } diff --git a/src/MPM.cpp b/src/MPM.cpp index 0f65e2e..795eba2 100644 --- a/src/MPM.cpp +++ b/src/MPM.cpp @@ -332,6 +332,7 @@ void MPM::solve(){ else{ ModelSetup::setInitialSimulationTime(std::chrono::system_clock::now()); solver->Solve(); + Output::printElapsedTime(); } } diff --git a/src/Output.cpp b/src/Output.cpp index b941c4f..480e05b 100644 --- a/src/Output.cpp +++ b/src/Output.cpp @@ -563,58 +563,60 @@ namespace Output{ cout<<"|"+hSpaces+"|"<<"\n"; cout<<"|"<* bodies, double itime) { - clearScreen(); - - welcomeScreen(); + std::cout <<"Time: "<< std::setw(8) << std::scientific << std::setprecision(4) << itime << " s, "; + std::cout <<"Energy: "<< std::setw(8) << std::scientific << std::setprecision(4) << DynamicRelaxation::computeKineticEnergy(bodies) << " J, "; + std::cout << std::setw(1) << std::fixed << std::setprecision(0) <<"(" << int(100 * itime / ModelSetup::getTime()) << "%) \n"; + } - // get total kinetic energy - double ienergy = DynamicRelaxation::computeKineticEnergy(bodies); - - // hours to minutes and seconds - std::chrono::duration elapsed_seconds = std::chrono::system_clock::now() - ModelSetup::getInitialSimulationTime() ; - auto hours = std::chrono::duration_cast(elapsed_seconds); - auto minutes = std::chrono::duration_cast(elapsed_seconds) - hours; - double seconds = elapsed_seconds.count() - (hours.count() * 3600 + minutes.count() * 60); - - std::cout << "Time : " << std::setw(8) << std::fixed << std::setprecision(4) << itime << "s" << std::endl; - std::cout << "Energy : " << std::setw(8) << std::scientific << std::setprecision(2) << ienergy << "J" << std::endl; - std::cout << "Particles : " << Particle::getTotalParticles() << std::endl; - std::cout << "Threads : " << ModelSetup::getThreads() << std::endl; - std::cout << "Time Step : " << ModelSetup::getTimeStep() << "s" << std::endl; - std::cout << "Elapsed time : "<< hours.count() << "h : " << minutes.count() << "m, " << std::fixed << std::setprecision(2) << seconds << "s"<* bodies, double itime) + { + std::cout << " Time : " << std::setw(8) << std::scientific << std::setprecision(4) << ModelSetup::getTime() << "s" << std::endl; + std::cout << "Time step : " << std::setw(8) << std::scientific << std::setprecision(4) << ModelSetup::getTimeStep() << "s" << std::endl; + std::cout << "Particles : " << Particle::getTotalParticles() << std::endl; + std::cout << " Threads : " << ModelSetup::getThreads() << std::endl; + std::cout << " Results : " << ModelSetup::getResultNum() << std::endl; + } - showProgressBar(progress); - int width = 55; - string hLines(width,'-'); - cout<<"\n"<* bodies, double iTime) { + // Get total kinetic energy + double ienergy = DynamicRelaxation::computeKineticEnergy(bodies); + + // Open the simulation CSV file in append mode + std::ofstream csv_file("simulation_data.csv", std::ios::app); + if (!csv_file.is_open()) { + std::cerr << "Error opening the CSV file" << std::endl; + } + + // Write time and energy to the file + csv_file << iTime << "," << ienergy << "\n"; + + // Close the file + csv_file.close(); +} + void writeResultInStep(int loopCounter, int resultSteps,vector* bodies, double iTime) { + if (iTime == 0) { printModelInfo(bodies, iTime); initializeCSVFile("simulation_data.csv");} + if (loopCounter%resultSteps==0) { // write model results @@ -622,6 +624,18 @@ namespace Output{ // update terminal updateTerminal(bodies,iTime); + + writeCSVEnergyFile(bodies,iTime); } } + + void printElapsedTime() { + // hours to minutes and seconds + std::chrono::duration elapsed_seconds = std::chrono::system_clock::now() - ModelSetup::getInitialSimulationTime(); + auto hours = std::chrono::duration_cast(elapsed_seconds); + auto minutes = std::chrono::duration_cast(elapsed_seconds) - hours; + double seconds = elapsed_seconds.count() - (hours.count() * 3600 + minutes.count() * 60); + std::cout << "\nElapsed time: " << hours.count() << " h, " << minutes.count() << " m, " << std::fixed << std::setprecision(2) << seconds << " s" << std::endl; + farewellScreen(); + } }