mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-12-25 00:40:02 -06:00
add utility function for verifying simulator output directory
use this in fvbaseproblem.hh. allows to encapsulate some includes
This commit is contained in:
parent
5d2a25ac14
commit
e56fc10b4c
@ -44,9 +44,6 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
namespace Opm::Properties {
|
namespace Opm::Properties {
|
||||||
|
|
||||||
template <class TypeTag, class MyTypeTag>
|
template <class TypeTag, class MyTypeTag>
|
||||||
@ -208,23 +205,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
std::string outputDir() const
|
std::string outputDir() const
|
||||||
{
|
{
|
||||||
std::string outputDir = Parameters::Get<Parameters::OutputDir>();
|
return simulatorOutputDir();
|
||||||
|
|
||||||
if (outputDir.empty())
|
|
||||||
outputDir = ".";
|
|
||||||
|
|
||||||
// TODO: replace this by std::filesystem once we require c++-2017
|
|
||||||
struct stat st;
|
|
||||||
if (::stat(outputDir.c_str(), &st) != 0)
|
|
||||||
throw std::runtime_error("Could not access output directory '"+outputDir+"':"
|
|
||||||
+strerror(errno));
|
|
||||||
if (!S_ISDIR(st.st_mode))
|
|
||||||
throw std::runtime_error("Path to output directory '"+outputDir+"' exists but is not a directory");
|
|
||||||
|
|
||||||
if (access(outputDir.c_str(), W_OK) != 0)
|
|
||||||
throw std::runtime_error("Output directory '"+outputDir+"' exists but is not writeable");
|
|
||||||
|
|
||||||
return outputDir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -24,10 +24,16 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <opm/models/utils/simulatorutils.hpp>
|
#include <opm/models/utils/simulatorutils.hpp>
|
||||||
|
|
||||||
|
#include <opm/models/discretization/common/fvbaseparameters.hh>
|
||||||
|
|
||||||
|
#include <opm/models/utils/parametersystem.hpp>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if HAVE_QUAD
|
#if HAVE_QUAD
|
||||||
@ -110,6 +116,32 @@ std::string humanReadableTime(double timeInSeconds, bool isAmendment)
|
|||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string simulatorOutputDir()
|
||||||
|
{
|
||||||
|
std::string outputDir = Parameters::Get<Parameters::OutputDir>();
|
||||||
|
|
||||||
|
if (outputDir.empty()) {
|
||||||
|
outputDir = ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: replace this by std::filesystem once we require c++-2017
|
||||||
|
struct stat st;
|
||||||
|
if (::stat(outputDir.c_str(), &st) != 0)
|
||||||
|
throw std::runtime_error("Could not access output directory '" + outputDir + "':" +
|
||||||
|
strerror(errno));
|
||||||
|
if (!S_ISDIR(st.st_mode)) {
|
||||||
|
throw std::runtime_error("Path to output directory '" +outputDir +
|
||||||
|
"' exists but is not a directory");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (access(outputDir.c_str(), W_OK) != 0) {
|
||||||
|
throw std::runtime_error("Output directory '" + outputDir +
|
||||||
|
"' exists but is not writeable");
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputDir;
|
||||||
|
}
|
||||||
|
|
||||||
template<class Scalar>
|
template<class Scalar>
|
||||||
std::vector<Scalar> readTimeStepFile(const std::string& file)
|
std::vector<Scalar> readTimeStepFile(const std::string& file)
|
||||||
{
|
{
|
||||||
|
@ -37,6 +37,11 @@ namespace Opm {
|
|||||||
*/
|
*/
|
||||||
std::string humanReadableTime(double timeInSeconds, bool isAmendment = true);
|
std::string humanReadableTime(double timeInSeconds, bool isAmendment = true);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Determine and check the configured directory for simulation output.
|
||||||
|
*/
|
||||||
|
std::string simulatorOutputDir();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Read explicitly defined time steps from file.
|
* \brief Read explicitly defined time steps from file.
|
||||||
* \param file File to read
|
* \param file File to read
|
||||||
|
Loading…
Reference in New Issue
Block a user