mirror of
https://github.com/OPM/opm-upscaling.git
synced 2025-02-25 18:45:23 -06:00
Added all functionality, not tested yet.
This commit is contained in:
@@ -38,6 +38,12 @@ namespace Dune
|
||||
: parser_(file)
|
||||
{
|
||||
const int* dims = &parser_.getSPECGRID().dimensions[0];
|
||||
|
||||
int layersz = 8*dims[0]*dims[1];
|
||||
const std::vector<double>& ZCORN = parser_.getFloatingPointValue("ZCORN");
|
||||
botmax_ = *std::max_element(ZCORN.begin(), ZCORN.begin() + layersz/2);
|
||||
topmin_ = *std::min_element(ZCORN.begin() + dims[2]*layersz - layersz/2,
|
||||
ZCORN.begin() + dims[2]*layersz);
|
||||
std::cout << "Parsed grdecl file with dimensions (" << dims[0] << ", " << dims[1] << ", " << dims[2] << ")" << std::endl;
|
||||
}
|
||||
|
||||
@@ -52,6 +58,22 @@ namespace Dune
|
||||
|
||||
|
||||
|
||||
const int* newDimensions() const
|
||||
{
|
||||
return new_dims_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const std::pair<double, double> zLimits() const
|
||||
{
|
||||
return std::make_pair(botmax_, topmin_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void chop(int imin, int imax, int jmin, int jmax, double zmin, double zmax)
|
||||
{
|
||||
const int* dims = dimensions();
|
||||
@@ -86,11 +108,9 @@ namespace Dune
|
||||
std::cerr << "Error! ZCORN size (" << ZCORN.size() << ") not consistent with SPECGRID\n";
|
||||
throw std::runtime_error("Inconsistent ZCORN and SPECGRID.");
|
||||
}
|
||||
double botmax = *std::max_element(ZCORN.begin(), ZCORN.begin() + layersz/2);
|
||||
double topmin = *std::min_element(ZCORN.begin() + dims[2]*layersz - layersz/2,
|
||||
ZCORN.begin() + dims[2]*layersz);
|
||||
zmin = std::max(zmin, botmax);
|
||||
zmax = std::min(zmax, topmin);
|
||||
|
||||
zmin = std::max(zmin, botmax_);
|
||||
zmax = std::min(zmax, topmin_);
|
||||
if (zmin >= zmax) {
|
||||
std::cerr << "Error: zmin >= zmax (zmin = " << zmin << ", zmax = " << zmax << ")\n";
|
||||
throw std::runtime_error("zmin >= zmax");
|
||||
@@ -189,6 +209,8 @@ namespace Dune
|
||||
|
||||
private:
|
||||
EclipseGridParser parser_;
|
||||
double botmax_;
|
||||
double topmin_;
|
||||
std::vector<double> new_COORD_;
|
||||
std::vector<double> new_ZCORN_;
|
||||
int new_dims_[3];
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
|
||||
|
||||
#include "CornerpointChopper.hpp"
|
||||
#include <boost/random/mersenne_twister.hpp>
|
||||
#include <boost/random/uniform_int.hpp>
|
||||
#include <boost/random/uniform_real.hpp>
|
||||
#include <boost/random/variate_generator.hpp>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
@@ -34,10 +39,34 @@ int main(int argc, char** argv)
|
||||
int imax = param.getDefault("imax", dims[0]);
|
||||
int jmin = param.getDefault("jmin", 0);
|
||||
int jmax = param.getDefault("jmax", dims[1]);
|
||||
double zmin = param.getDefault("zmin", -1e100);
|
||||
double zmax = param.getDefault("zmax", 1e100);
|
||||
ch.chop(imin, imax, jmin, jmax, zmin, zmax);
|
||||
double zmin = param.getDefault("zmin", ch.zLimits().first);
|
||||
double zmax = param.getDefault("zmax", ch.zLimits().second);
|
||||
int subsamples = param.getDefault("subsamples", 1);
|
||||
int ilen = param.getDefault("ilen", imax - imin);
|
||||
int jlen = param.getDefault("jlen", jmax - jmin);
|
||||
double zlen = param.getDefault("zlen", zmax - zmin);
|
||||
std::string filebase = param.getDefault<std::string>("filebase", "subsample");
|
||||
std::string outnam = filebase + ".grdecl";
|
||||
ch.writeGrdecl(filebase);
|
||||
// Random number generator from boost.
|
||||
boost::mt19937 gen;
|
||||
// Note that end is included in interval for uniform_int.
|
||||
boost::uniform_int<> disti(imin, imax - ilen);
|
||||
boost::uniform_int<> distj(jmin, jmax - jlen);
|
||||
boost::uniform_real<> distz(zmin, zmax - zlen);
|
||||
boost::variate_generator<boost::mt19937&, boost::uniform_int<> > ri(gen, disti);
|
||||
boost::variate_generator<boost::mt19937&, boost::uniform_int<> > rj(gen, distj);
|
||||
boost::variate_generator<boost::mt19937&, boost::uniform_real<> > rz(gen, distz);
|
||||
for (int sample = 0; sample < subsamples; ++sample) {
|
||||
int istart = ri();
|
||||
int jstart = rj();
|
||||
double zstart = rz();
|
||||
ch.chop(istart, istart + ilen, jstart, jstart + jlen, zstart, zstart + zlen);
|
||||
std::string outname = filebase;
|
||||
if (subsamples > 1) {
|
||||
std::ostringstream oss;
|
||||
oss << 'R' << std::setw(4) << std::setfill('0') << sample;
|
||||
outname += oss.str();
|
||||
}
|
||||
outname += ".grdecl";
|
||||
ch.writeGrdecl(outname);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user