diff --git a/libnufi_lib.a b/libnufi_lib.a index 7b25e7c..00e4ef9 100644 Binary files a/libnufi_lib.a and b/libnufi_lib.a differ diff --git a/nufi/stopwatch.h b/nufi/stopwatch.h new file mode 100644 index 0000000..1d2b5ca --- /dev/null +++ b/nufi/stopwatch.h @@ -0,0 +1,37 @@ +#ifndef STOPWATCH_H +#define STOPWATCH_H + +#include + +template +class stopwatch +{ +public: + void reset(); + real elapsed(); + +private: + using clock = std::chrono::high_resolution_clock; + clock::time_point t0 { clock::now() }; +}; + + +template inline +void stopwatch::reset() +{ + t0 = clock::now(); +} + +template inline +real stopwatch::elapsed() +{ + using seconds = std::chrono::duration>; + + auto tnow = clock::now(); + auto duration = std::chrono::duration_cast( tnow - t0 ); + + return duration.count(); +} + +#endif // STOPWATCH_H + diff --git a/src/nufi_solver.cc b/src/nufi_solver.cc index 4d076e3..d97c628 100644 --- a/src/nufi_solver.cc +++ b/src/nufi_solver.cc @@ -17,6 +17,7 @@ #include "nufi/save_results.h" #include "nufi/poisson_problem.h" #include "nufi/fields.h" +#include "nufi/stopwatch.h" using namespace dealii; @@ -87,8 +88,12 @@ void NuFISolver::run() Gradient grad(x_min, x_max, Nx); + double total_time = 0; + for (unsigned int it = 0; it < Nt; ++it) { + stopwatch timer; + std::cout << "Timestep " << it << " / " << Nt << std::endl << std::endl; // compute rho @@ -127,9 +132,12 @@ void NuFISolver::run() E_x[ix] = -eval<1>(Parameters::X_DOMAIN_LEFT+ix*dx, current_coeffs); } + double timer_elapsed = timer.elapsed(); + total_time += timer_elapsed; + if (it % Parameters::PLOT_FREQUENCY == 0) { - std::cout << "Saving results... \n\n"; + std::cout << "Saving results... "; save_ftilda(*this, it, coeffs.get(), 128, 128, "results/ftilda_" + std::to_string(it) + ".dat"); save_rho(*this, it, coeffs.get(), 128, "results/rho_" + std::to_string(it) + ".dat"); // save_Efield(it, coeffs.get(), 128, "results/field_" + std::to_string(it) + ".dat"); @@ -138,12 +146,11 @@ void NuFISolver::run() double int_val = 0.5 * integral_space_vector_squared(current_coeffs); int_E_squared.push_back(int_val); save_space_vector(int_E_squared, "electricint", it); - - + std::cout << "Time since start = "<< total_time<<"\n\n"; } } - std::cout << "NuFI simulation finished.\n"; + std::cout << "NuFI simulation finished in "<< total_time <<" seconds.\n"; } NuFISolver::NuFISolver()