@@ -47,6 +47,13 @@
|
||||
|
||||
namespace Opm {
|
||||
|
||||
// Silence compiler warnings about use of variables
|
||||
// that are instantiated in a different compilation unit.
|
||||
template<>
|
||||
const float CO2<float>::brineSalinity;
|
||||
template<>
|
||||
const double CO2<double>::brineSalinity;
|
||||
|
||||
/*!
|
||||
* \brief A two-phase fluid system with water and CO2.
|
||||
*
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <list>
|
||||
#include <ostream>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
@@ -456,8 +456,9 @@ void EclOutput::writeFormattedHeader(const std::string& arrName, int size, eclAr
|
||||
|
||||
std::string EclOutput::make_real_string_ecl(float value) const
|
||||
{
|
||||
char buffer [15];
|
||||
std::sprintf (buffer, "%10.7E", value);
|
||||
constexpr std::size_t buf_size = 15;
|
||||
char buffer [buf_size];
|
||||
std::snprintf (buffer, sizeof buffer, "%10.7E", value);
|
||||
|
||||
if (value == 0.0) {
|
||||
return "0.00000000E+00";
|
||||
@@ -482,7 +483,7 @@ std::string EclOutput::make_real_string_ecl(float value) const
|
||||
tmpstr = "0." + tmpstr.substr(0, 1) + tmpstr.substr(2, 7) +"E";
|
||||
}
|
||||
|
||||
std::sprintf (buffer, "%+03i", exp+1);
|
||||
std::snprintf (buffer, sizeof buffer, "%+03i", exp+1);
|
||||
tmpstr = tmpstr+buffer;
|
||||
|
||||
return tmpstr;
|
||||
@@ -491,8 +492,9 @@ std::string EclOutput::make_real_string_ecl(float value) const
|
||||
|
||||
std::string EclOutput::make_real_string_ix(float value) const
|
||||
{
|
||||
char buffer [15];
|
||||
std::sprintf (buffer, "%10.7E", value);
|
||||
constexpr std::size_t buf_size = 15;
|
||||
char buffer [buf_size];
|
||||
std::snprintf (buffer, sizeof buffer, "%10.7E", value);
|
||||
|
||||
if (value == 0.0) {
|
||||
return " 0.0000000E+00";
|
||||
@@ -559,7 +561,7 @@ std::string EclOutput::make_doub_string_ecl(double value) const
|
||||
std::string EclOutput::make_doub_string_ix(double value) const
|
||||
{
|
||||
char buffer [21];
|
||||
std::sprintf (buffer, "%19.13E", value);
|
||||
std::snprintf (buffer, sizeof buffer, "%19.13E", value);
|
||||
|
||||
if (value == 0.0) {
|
||||
return " 0.0000000000000E+00";
|
||||
|
||||
@@ -126,45 +126,47 @@ static void printHelp() {
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void writeGrdeclData(std::ofstream& ofileH, const std::string& name, const std::vector<T>& array)
|
||||
struct GrdeclDataFormatParams
|
||||
{
|
||||
int ncol;
|
||||
int w;
|
||||
int pre;
|
||||
bool is_string = false;
|
||||
bool is_int = false;
|
||||
bool is_string;
|
||||
bool is_int;
|
||||
};
|
||||
|
||||
if constexpr (std::is_same<T, float>::value){
|
||||
ncol = 4;
|
||||
w = 11;
|
||||
pre = 7;
|
||||
} else if constexpr (std::is_same<T, double>::value){
|
||||
ncol = 3;
|
||||
w = 21;
|
||||
pre = 14;
|
||||
} else if constexpr (std::is_same<T, int>::value){
|
||||
ncol = 8;
|
||||
w = 6;
|
||||
is_int = true;
|
||||
} else if constexpr (std::is_same<T, std::string>::value){
|
||||
ncol = 5;
|
||||
is_string = true;
|
||||
template <typename T>
|
||||
GrdeclDataFormatParams getFormat()
|
||||
{
|
||||
if constexpr (std::is_same<T, float>::value) {
|
||||
return {4, 11, 7, false, false};
|
||||
} else if constexpr (std::is_same<T, double>::value) {
|
||||
return {3, 21, 14, false, false};
|
||||
} else if constexpr (std::is_same<T, int>::value) {
|
||||
return {8, 6, -1, false, true};
|
||||
} else if constexpr (std::is_same<T, std::string>::value) {
|
||||
return {5, -1, -1, true, false};
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void writeGrdeclData(std::ofstream& ofileH, const std::string& name, const std::vector<T>& array)
|
||||
{
|
||||
const auto p = getFormat<T>();
|
||||
|
||||
int64_t data_size = static_cast<int64_t>(array.size());
|
||||
|
||||
ofileH << "\n" << name << std::endl;
|
||||
|
||||
for (int64_t n = 0; n < data_size; n++){
|
||||
if (is_string)
|
||||
if (p.is_string)
|
||||
ofileH << " " << array[n];
|
||||
else if (is_int)
|
||||
ofileH << " " << std::setw(w) << array[n];
|
||||
else if (p.is_int)
|
||||
ofileH << " " << std::setw(p.w) << array[n];
|
||||
else
|
||||
ofileH << " " << std::setw(w) << std::setprecision(pre) << std::scientific << array[n];
|
||||
ofileH << " " << std::setw(p.w) << std::setprecision(p.pre) << std::scientific << array[n];
|
||||
|
||||
if ((n+1) % ncol == 0)
|
||||
if ((n+1) % p.ncol == 0)
|
||||
ofileH << "\n";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user