diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 36552e709..e0990f57c 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -252,9 +252,57 @@ namespace Opm #endif } + /// checks cartesian adjacency of global indices g1 and g2 + bool cartesianAdjacent(const Grid& grid, int g1, int g2) { + // we need cartDims from UgGridHelpers + using namespace UgGridHelpers; + + int diff = std::abs(g1 - g2); + + const int * dimens = cartDims(grid); + if (diff == 1) + return true; + if (diff == dimens[0]) + return true; + if (diff == dimens[0] * dimens[1]) + return true; + + return false; + } + /// Write the NNC structure of the given grid to NNC. + /// + /// Write cell adjacencies beyond Cartesian neighborhoods to NNC. + /// + /// The trans vector is indexed by face number as it is in grid. + void exportNncStructure(NNC& nnc, const Grid& grid, const std::vector& trans) { + // we use numFaces, numCells, cell2Faces, globalCell from UgGridHelpers + using namespace UgGridHelpers; + size_t num_faces = numFaces(grid); + if (trans.size() > 0 && trans.size() != num_faces) { + throw std::logic_error( + "non-empty trans vector with wrong dimension."); + } + + auto fc = faceCells(grid); + for (size_t i = 0; i < num_faces; ++i) { + auto c1 = fc(i, 0); + auto c2 = fc(i, 1); + + if (c1 == -1 || c2 == -1) + continue; // face on grid boundary + // translate from active cell idx (ac1,ac2) to global cell idx + c1 = globalCell(grid) ? globalCell(grid)[c1] : c1; + c2 = globalCell(grid) ? globalCell(grid)[c2] : c2; + if (!cartesianAdjacent(grid, c1, c2)) { + // suppose c1,c2 is specified in ECLIPSE input + // we here overwrite its trans by grid's + nnc.addNNC(c1, c2, trans[i]); + } + } + } // Print startup message if on output rank. void printStartupMessage() @@ -676,7 +724,8 @@ namespace Opm const auto initConfig = eclipse_state_->getInitConfig(); simtimer.init(timeMap, (size_t)initConfig->getRestartStep()); - + Opm::NNC nnc = eclipse_state_->getNNC(); // copy, otherwise we write to ecl_state + exportNncStructure(nnc, grid_init_->grid(), trans_); if (!schedule->initOnly()) { if (output_cout_) { @@ -704,10 +753,11 @@ namespace Opm fullReport.reportParam(tot_os); } } else { - output_writer_->writeInit( simtimer ); + output_writer_->writeInit( simtimer, geoprops_->nnc() ); if (output_cout_) { std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush; } + } return EXIT_SUCCESS; } diff --git a/opm/autodiff/SimulatorBase_impl.hpp b/opm/autodiff/SimulatorBase_impl.hpp index 0fc696db1..e401f1ddf 100644 --- a/opm/autodiff/SimulatorBase_impl.hpp +++ b/opm/autodiff/SimulatorBase_impl.hpp @@ -110,7 +110,7 @@ namespace Opm } // init output writer - output_writer_.writeInit( timer ); + output_writer_.writeInit( timer, geo_.nnc() ); std::string restorefilename = param_.getDefault("restorefile", std::string("") ); if( ! restorefilename.empty() ) diff --git a/opm/autodiff/SimulatorFullyImplicitBlackoilMultiSegment_impl.hpp b/opm/autodiff/SimulatorFullyImplicitBlackoilMultiSegment_impl.hpp index 77ec6c5ea..b775bcc93 100644 --- a/opm/autodiff/SimulatorFullyImplicitBlackoilMultiSegment_impl.hpp +++ b/opm/autodiff/SimulatorFullyImplicitBlackoilMultiSegment_impl.hpp @@ -74,7 +74,7 @@ namespace Opm } // init output writer - output_writer_.writeInit( timer ); + output_writer_.writeInit( timer, geo_.nnc()); std::string restorefilename = param_.getDefault("restorefile", std::string("") ); if( ! restorefilename.empty() ) diff --git a/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.cpp b/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.cpp index b6749454f..b54105923 100644 --- a/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.cpp +++ b/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.cpp @@ -246,10 +246,10 @@ namespace Opm void BlackoilOutputWriter:: - writeInit(const SimulatorTimerInterface& timer) + writeInit(const SimulatorTimerInterface& timer, const NNC& nnc) { if( eclWriter_ ) { - eclWriter_->writeInit(timer); + eclWriter_->writeInit(timer, nnc); } } diff --git a/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp b/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp index fa54b4325..2458b68b0 100644 --- a/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp +++ b/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp @@ -153,7 +153,7 @@ namespace Opm {} /** \copydoc Opm::OutputWriter::writeInit */ - void writeInit(const SimulatorTimerInterface& /* timer */) + void writeInit(const SimulatorTimerInterface& /* timer */, const NNC& nnc) {} /** \copydoc Opm::OutputWriter::writeTimeStep */ @@ -183,7 +183,7 @@ namespace Opm {} /** \copydoc Opm::OutputWriter::writeInit */ - void writeInit(const SimulatorTimerInterface& /* timer */) + void writeInit(const SimulatorTimerInterface& /* timer */, const NNC& nnc) {} /** \copydoc Opm::OutputWriter::writeTimeStep */ @@ -214,7 +214,7 @@ namespace Opm const double* permeability ); /** \copydoc Opm::OutputWriter::writeInit */ - void writeInit(const SimulatorTimerInterface &timer); + void writeInit(const SimulatorTimerInterface &timer, const NNC& nnc); /** \copydoc Opm::OutputWriter::writeTimeStep */ void writeTimeStep(const SimulatorTimerInterface& timer,