mirror of
https://github.com/OPM/opm-simulators.git
synced 2026-10-25 23:20:12 -05:00
added: opm/models/simulatorutils.[ch]pp
move humanReadableTime from simulator.hh into it
This commit is contained in:
1 parent
daea73d696
commit
478ddb5e52
5 files changed
+183
-96
No files matched your search
@@ -65,6 +65,7 @@ list (APPEND MAIN_SOURCE_FILES
|
||||
opm/models/parallel/tasklets.cpp
|
||||
opm/models/parallel/threadmanager.cpp
|
||||
opm/models/utils/parametersystem.cpp
|
||||
opm/models/utils/simulatorutils.cpp
|
||||
opm/models/utils/terminal.cpp
|
||||
opm/models/utils/timer.cpp
|
||||
opm/simulators/flow/ActionHandler.cpp
|
||||
@@ -722,6 +723,7 @@ list (APPEND PUBLIC_HEADER_FILES
|
||||
opm/models/utils/quadraturegeometries.hh
|
||||
opm/models/utils/signum.hh
|
||||
opm/models/utils/simulator.hh
|
||||
opm/models/utils/simulatorutils.hpp
|
||||
opm/models/utils/start.hh
|
||||
opm/models/utils/terminal.hpp
|
||||
opm/models/utils/timer.hpp
|
||||
|
||||
@@ -28,14 +28,16 @@
|
||||
#ifndef EWOMS_FV_BASE_PROBLEM_HH
|
||||
#define EWOMS_FV_BASE_PROBLEM_HH
|
||||
|
||||
#include <dune/common/fvector.hh>
|
||||
|
||||
#include <opm/models/discretization/common/fvbaseparameters.hh>
|
||||
#include <opm/models/discretization/common/fvbaseproperties.hh>
|
||||
#include <opm/models/discretization/common/restrictprolong.hh>
|
||||
|
||||
#include <opm/models/io/vtkmultiwriter.hh>
|
||||
#include <opm/models/io/restart.hh>
|
||||
#include <opm/models/discretization/common/restrictprolong.hh>
|
||||
|
||||
#include <dune/common/fvector.hh>
|
||||
#include <opm/models/utils/simulatorutils.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
@@ -485,24 +487,33 @@ public:
|
||||
<< "Simulation of problem '" << asImp_().name() << "' finished.\n"
|
||||
<< "\n"
|
||||
<< "------------------------ Timing ------------------------\n"
|
||||
<< "Setup time: " << setupTime << " seconds" << Simulator::humanReadableTime(setupTime)
|
||||
<< "Setup time: " << setupTime << " seconds"
|
||||
<< humanReadableTime(setupTime)
|
||||
<< ", " << setupTime/(executionTime + setupTime)*100 << "%\n"
|
||||
<< "Simulation time: " << executionTime << " seconds" << Simulator::humanReadableTime(executionTime)
|
||||
<< "Simulation time: " << executionTime << " seconds"
|
||||
<< humanReadableTime(executionTime)
|
||||
<< ", " << executionTime/(executionTime + setupTime)*100 << "%\n"
|
||||
<< " Linearization time: " << linearizeTime << " seconds" << Simulator::humanReadableTime(linearizeTime)
|
||||
<< " Linearization time: " << linearizeTime << " seconds"
|
||||
<< humanReadableTime(linearizeTime)
|
||||
<< ", " << linearizeTime/executionTime*100 << "%\n"
|
||||
<< " Linear solve time: " << solveTime << " seconds" << Simulator::humanReadableTime(solveTime)
|
||||
<< " Linear solve time: " << solveTime << " seconds"
|
||||
<< humanReadableTime(solveTime)
|
||||
<< ", " << solveTime/executionTime*100 << "%\n"
|
||||
<< " Newton update time: " << updateTime << " seconds" << Simulator::humanReadableTime(updateTime)
|
||||
<< " Newton update time: " << updateTime << " seconds"
|
||||
<< humanReadableTime(updateTime)
|
||||
<< ", " << updateTime/executionTime*100 << "%\n"
|
||||
<< " Pre/postprocess time: " << prePostProcessTime << " seconds" << Simulator::humanReadableTime(prePostProcessTime)
|
||||
<< " Pre/postprocess time: " << prePostProcessTime << " seconds"
|
||||
<< humanReadableTime(prePostProcessTime)
|
||||
<< ", " << prePostProcessTime/executionTime*100 << "%\n"
|
||||
<< " Output write time: " << writeTime << " seconds" << Simulator::humanReadableTime(writeTime)
|
||||
<< " Output write time: " << writeTime << " seconds"
|
||||
<< humanReadableTime(writeTime)
|
||||
<< ", " << writeTime/executionTime*100 << "%\n"
|
||||
<< "First process' simulation CPU time: " << localCpuTime << " seconds" << Simulator::humanReadableTime(localCpuTime) << "\n"
|
||||
<< "First process' simulation CPU time: " << localCpuTime << " seconds"
|
||||
<< humanReadableTime(localCpuTime) << "\n"
|
||||
<< "Number of processes: " << numProcesses << "\n"
|
||||
<< "Threads per processes: " << threadsPerProcess << "\n"
|
||||
<< "Total CPU time: " << globalCpuTime << " seconds" << Simulator::humanReadableTime(globalCpuTime) << "\n"
|
||||
<< "Total CPU time: " << globalCpuTime << " seconds"
|
||||
<< humanReadableTime(globalCpuTime) << "\n"
|
||||
<< "\n"
|
||||
<< "----------------------------------------------------------------\n"
|
||||
<< std::endl;
|
||||
|
||||
@@ -28,21 +28,23 @@
|
||||
#ifndef EWOMS_SIMULATOR_HH
|
||||
#define EWOMS_SIMULATOR_HH
|
||||
|
||||
#include <opm/models/io/restart.hh>
|
||||
#include <opm/models/utils/parametersystem.hpp>
|
||||
#include <dune/common/parallel/mpihelper.hh>
|
||||
|
||||
#include <opm/models/utils/basicproperties.hh>
|
||||
#include <opm/models/utils/propertysystem.hh>
|
||||
#include <opm/models/utils/timer.hpp>
|
||||
#include <opm/models/utils/timerguard.hh>
|
||||
#include <opm/models/parallel/mpiutil.hpp>
|
||||
#include <opm/models/discretization/common/fvbaseproperties.hh>
|
||||
|
||||
#include <dune/common/parallel/mpihelper.hh>
|
||||
#include <opm/models/io/restart.hh>
|
||||
|
||||
#include <opm/models/parallel/mpiutil.hpp>
|
||||
|
||||
#include <opm/models/utils/basicproperties.hh>
|
||||
#include <opm/models/utils/parametersystem.hpp>
|
||||
#include <opm/models/utils/propertysystem.hh>
|
||||
#include <opm/models/utils/simulatorutils.hpp>
|
||||
#include <opm/models/utils/timer.hpp>
|
||||
#include <opm/models/utils/timerguard.hh>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
@@ -802,82 +804,6 @@ public:
|
||||
EWOMS_CATCH_PARALLEL_EXCEPTIONS_FATAL(problem_->finalize());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Given a time step size in seconds, return it in a format which is more
|
||||
* easily parsable by humans.
|
||||
*
|
||||
* e.g. 874000.0 will become "10.12 days"
|
||||
*/
|
||||
static std::string humanReadableTime(Scalar timeInSeconds, bool isAmendment=true)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << std::setprecision(4);
|
||||
if (isAmendment)
|
||||
oss << " (";
|
||||
if (timeInSeconds >= 365.25*24*60*60) {
|
||||
int years = static_cast<int>(timeInSeconds/(365.25*24*60*60));
|
||||
int days = static_cast<int>((timeInSeconds - years*(365.25*24*60*60))/(24*60*60));
|
||||
|
||||
double accuracy = 1e-2;
|
||||
double hours =
|
||||
std::round(1.0/accuracy*
|
||||
(timeInSeconds
|
||||
- years*(365.25*24*60*60)
|
||||
- days*(24*60*60))/(60*60))
|
||||
*accuracy;
|
||||
|
||||
oss << years << " years, " << days << " days, " << hours << " hours";
|
||||
}
|
||||
else if (timeInSeconds >= 24.0*60*60) {
|
||||
int days = static_cast<int>(timeInSeconds/(24*60*60));
|
||||
int hours = static_cast<int>((timeInSeconds - days*(24*60*60))/(60*60));
|
||||
|
||||
double accuracy = 1e-2;
|
||||
double minutes =
|
||||
std::round(1.0/accuracy*
|
||||
(timeInSeconds
|
||||
- days*(24*60*60)
|
||||
- hours*(60*60))/60)
|
||||
*accuracy;
|
||||
|
||||
oss << days << " days, " << hours << " hours, " << minutes << " minutes";
|
||||
}
|
||||
else if (timeInSeconds >= 60.0*60) {
|
||||
int hours = static_cast<int>(timeInSeconds/(60*60));
|
||||
int minutes = static_cast<int>((timeInSeconds - hours*(60*60))/60);
|
||||
|
||||
double accuracy = 1e-2;
|
||||
double seconds =
|
||||
std::round(1.0/accuracy*
|
||||
(timeInSeconds
|
||||
- hours*(60*60)
|
||||
- minutes*60))
|
||||
*accuracy;
|
||||
|
||||
oss << hours << " hours, " << minutes << " minutes, " << seconds << " seconds";
|
||||
}
|
||||
else if (timeInSeconds >= 60.0) {
|
||||
int minutes = static_cast<int>(timeInSeconds/60);
|
||||
|
||||
double accuracy = 1e-3;
|
||||
double seconds =
|
||||
std::round(1.0/accuracy*
|
||||
(timeInSeconds
|
||||
- minutes*60))
|
||||
*accuracy;
|
||||
|
||||
oss << minutes << " minutes, " << seconds << " seconds";
|
||||
}
|
||||
else if (!isAmendment)
|
||||
oss << timeInSeconds << " seconds";
|
||||
else
|
||||
return "";
|
||||
if (isAmendment)
|
||||
oss << ")";
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \name Saving/restoring the simulation state
|
||||
* \{
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
// vi: set et ts=4 sw=4 sts=4:
|
||||
/*
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Consult the COPYING file in the top-level source directory of this
|
||||
module for the precise wording of the license and the list of
|
||||
copyright holders.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <opm/models/utils/simulatorutils.hpp>
|
||||
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
std::string humanReadableTime(double timeInSeconds, bool isAmendment)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << std::setprecision(4);
|
||||
if (isAmendment) {
|
||||
oss << " (";
|
||||
}
|
||||
if (timeInSeconds >= 365.25 * 24 * 60 * 60) {
|
||||
int years = static_cast<int>(timeInSeconds / (365.25 * 24 * 60 * 60));
|
||||
int days = static_cast<int>((timeInSeconds - years*(365.25 * 24 * 60 * 60)) / (24 * 60 * 60));
|
||||
|
||||
constexpr double accuracy = 1e-2;
|
||||
double hours =
|
||||
std::round(1.0 / accuracy *
|
||||
(timeInSeconds
|
||||
- years * (365.25 * 24 * 60 * 60)
|
||||
- days * (24 * 60 * 60)) / (60 * 60))
|
||||
*accuracy;
|
||||
|
||||
oss << years << " years, " << days << " days, " << hours << " hours";
|
||||
}
|
||||
else if (timeInSeconds >= 24.0 * 60 * 60) {
|
||||
int days = static_cast<int>(timeInSeconds / (24 * 60 * 60));
|
||||
int hours = static_cast<int>((timeInSeconds - days * (24 * 60 * 60)) / (60 * 60));
|
||||
|
||||
constexpr double accuracy = 1e-2;
|
||||
double minutes =
|
||||
std::round(1.0 / accuracy *
|
||||
(timeInSeconds
|
||||
- days * (24 * 60 * 60)
|
||||
- hours * (60 * 60)) / 60)
|
||||
*accuracy;
|
||||
|
||||
oss << days << " days, " << hours << " hours, " << minutes << " minutes";
|
||||
}
|
||||
else if (timeInSeconds >= 60.0 * 60) {
|
||||
int hours = static_cast<int>(timeInSeconds / (60 * 60));
|
||||
int minutes = static_cast<int>((timeInSeconds - hours * (60 * 60)) / 60);
|
||||
|
||||
constexpr double accuracy = 1e-2;
|
||||
double seconds =
|
||||
std::round(1.0 / accuracy *
|
||||
(timeInSeconds
|
||||
- hours * (60 * 60)
|
||||
- minutes * 60))
|
||||
* accuracy;
|
||||
|
||||
oss << hours << " hours, " << minutes << " minutes, " << seconds << " seconds";
|
||||
}
|
||||
else if (timeInSeconds >= 60.0) {
|
||||
int minutes = static_cast<int>(timeInSeconds / 60);
|
||||
|
||||
constexpr double accuracy = 1e-3;
|
||||
double seconds =
|
||||
std::round(1.0 / accuracy *
|
||||
(timeInSeconds
|
||||
- minutes * 60))
|
||||
* accuracy;
|
||||
|
||||
oss << minutes << " minutes, " << seconds << " seconds";
|
||||
}
|
||||
else if (!isAmendment) {
|
||||
oss << timeInSeconds << " seconds";
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
if (isAmendment) {
|
||||
oss << ")";
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
} // end namespace Opm
|
||||
@@ -0,0 +1,41 @@
|
||||
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
// vi: set et ts=4 sw=4 sts=4:
|
||||
/*
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Consult the COPYING file in the top-level source directory of this
|
||||
module for the precise wording of the license and the list of
|
||||
copyright holders.
|
||||
*/
|
||||
|
||||
#ifndef OPM_SIMULATOR_UTILS_HPP
|
||||
#define OPM_SIMULATOR_UTILS_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
/*!
|
||||
* \brief Given a time step size in seconds, return it in a format which is more
|
||||
* easily parsable by humans.
|
||||
*
|
||||
* e.g. 874000.0 will become "10.12 days"
|
||||
*/
|
||||
std::string humanReadableTime(double timeInSeconds, bool isAmendment = true);
|
||||
|
||||
} // namespace Opm
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user