Pass block values to OPM-output

This commit is contained in:
Tor Harald Sandve
2018-01-19 15:45:42 +01:00
parent 2264b44f38
commit 85ed4bffbf
3 changed files with 120 additions and 54 deletions

View File

@@ -281,18 +281,25 @@ namespace Ewoms
const Opm::data::Solution& localCellData_; const Opm::data::Solution& localCellData_;
Opm::data::Solution& globalCellData_; Opm::data::Solution& globalCellData_;
const std::map<std::pair<std::string, int>, double>& localBlockData_;
std::map<std::pair<std::string, int>, double>& globalBlockValues_;
const IndexMapType& localIndexMap_; const IndexMapType& localIndexMap_;
const IndexMapStorageType& indexMaps_; const IndexMapStorageType& indexMaps_;
public: public:
PackUnPack( const Opm::data::Solution& localCellData, PackUnPack( const Opm::data::Solution& localCellData,
Opm::data::Solution& globalCellData, Opm::data::Solution& globalCellData,
const std::map<std::pair<std::string, int>, double>& localBlockData,
std::map<std::pair<std::string, int>, double>& globalBlockValues,
const IndexMapType& localIndexMap, const IndexMapType& localIndexMap,
const IndexMapStorageType& indexMaps, const IndexMapStorageType& indexMaps,
const size_t globalSize, const size_t globalSize,
const bool isIORank ) const bool isIORank )
: localCellData_( localCellData ), : localCellData_( localCellData ),
globalCellData_( globalCellData ), globalCellData_( globalCellData ),
localBlockData_( localBlockData ),
globalBlockValues_( globalBlockValues ),
localIndexMap_( localIndexMap ), localIndexMap_( localIndexMap ),
indexMaps_( indexMaps ) indexMaps_( indexMaps )
{ {
@@ -332,6 +339,14 @@ namespace Ewoms
write( buffer, localIndexMap_, data); write( buffer, localIndexMap_, data);
} }
// write all block data
unsigned int size = localBlockData_.size();
buffer.write( size );
for (const auto& map : localBlockData_) {
buffer.write(map.first.first);
buffer.write(map.first.second);
buffer.write(map.second);
}
} }
void doUnpack( const IndexMapType& indexMap, MessageBufferType& buffer ) void doUnpack( const IndexMapType& indexMap, MessageBufferType& buffer )
@@ -345,6 +360,19 @@ namespace Ewoms
//write all data from local cell data to buffer //write all data from local cell data to buffer
read( buffer, indexMap, data); read( buffer, indexMap, data);
} }
// write all block data
unsigned int size = 0;
buffer.read(size);
for (size_t i = 0; i < size; ++i) {
std::string name;
int idx;
double data;
buffer.read( name );
buffer.read( idx );
buffer.read( data );
globalBlockValues_[std::make_pair(name, idx)] = data;
}
} }
// unpack all data associated with link // unpack all data associated with link
@@ -393,9 +421,10 @@ namespace Ewoms
}; };
// gather solution to rank 0 for EclipseWriter // gather solution to rank 0 for EclipseWriter
void collect( const Opm::data::Solution& localCellData ) void collect( const Opm::data::Solution& localCellData, const std::map<std::pair<std::string, int>, double>& localBlockValues)
{ {
globalCellData_ = {}; globalCellData_ = {};
globalBlockValues_.clear();
// index maps only have to be build when reordering is needed // index maps only have to be build when reordering is needed
if( ! needsReordering && ! isParallel() ) if( ! needsReordering && ! isParallel() )
{ {
@@ -406,6 +435,8 @@ namespace Ewoms
PackUnPack PackUnPack
packUnpack( localCellData, packUnpack( localCellData,
globalCellData_, globalCellData_,
localBlockValues,
globalBlockValues_,
localIndexMap_, localIndexMap_,
indexMaps_, indexMaps_,
numCells(), numCells(),
@@ -426,6 +457,11 @@ namespace Ewoms
#endif #endif
} }
const std::map<std::pair<std::string, int>, double>& globalBlockValues() const
{
return globalBlockValues_;
}
const Opm::data::Solution& globalCellData() const const Opm::data::Solution& globalCellData() const
{ {
return globalCellData_; return globalCellData_;
@@ -472,6 +508,7 @@ namespace Ewoms
IndexMapStorageType indexMaps_; IndexMapStorageType indexMaps_;
std::vector<int> globalRanks_; std::vector<int> globalRanks_;
Opm::data::Solution globalCellData_; Opm::data::Solution globalCellData_;
std::map<std::pair<std::string, int>, double> globalBlockValues_;
}; };
} // end namespace Opm } // end namespace Opm

View File

@@ -117,47 +117,9 @@ public:
if (!std::is_same<Discretization, Ewoms::EcfvDiscretization<TypeTag> >::value) if (!std::is_same<Discretization, Ewoms::EcfvDiscretization<TypeTag> >::value)
return; return;
std::map<std::string, int> rstKeywords = restartConfig.getRestartKeywords(reportStepNum); // Summary output is for all steps
for (auto& keyValue : rstKeywords) {
keyValue.second = restartConfig.getKeyword(keyValue.first, reportStepNum);
}
const Opm::SummaryConfig summaryConfig = simulator_.gridManager().summaryConfig(); const Opm::SummaryConfig summaryConfig = simulator_.gridManager().summaryConfig();
blockValues_.clear();
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
if (!FluidSystem::phaseIsActive(phaseIdx))
continue;
if (!substep || (phaseIdx == waterPhaseIdx && summaryConfig.require3DField("SWAT") )
|| (phaseIdx == gasPhaseIdx && summaryConfig.require3DField("SGAS") ) )
saturation_[phaseIdx].resize(bufferSize,0.0);
}
if (!substep || summaryConfig.require3DField("PRESSURE"))
oilPressure_.resize(bufferSize,0.0);
if (!substep || summaryConfig.require3DField("TEMP"))
temperature_.resize(bufferSize,0.0);
// Output the same as legacy
// TODO: Only needed if DISGAS or VAPOIL
if (true) {
if (!substep || summaryConfig.require3DField("RS"))
rs_.resize(bufferSize,0.0);
}
if (true) {
if (!substep || summaryConfig.require3DField("RV"))
rv_.resize(bufferSize,0.0);
}
if (GET_PROP_VALUE(TypeTag, EnableSolvent)) {
if (!substep || summaryConfig.require3DField("SSOL"))
sSol_.resize(bufferSize,0.0);
}
if (GET_PROP_VALUE(TypeTag, EnablePolymer)) {
if (!substep || summaryConfig.require3DField("POLYMER"))
cPolymer_.resize(bufferSize,0.0);
}
// Fluid in place // Fluid in place
for (int i = 0; i<FIPDataType::numFipValues; i++) { for (int i = 0; i<FIPDataType::numFipValues; i++) {
@@ -172,7 +134,42 @@ public:
pPvHydrocarbon_.resize(bufferSize, 0.0); pPvHydrocarbon_.resize(bufferSize, 0.0);
} }
if (!substep) { outputRestart_ = false;
// Only provide restart on restart steps
if (!restartConfig.getWriteRestartFile(reportStepNum) || substep)
return;
outputRestart_ = true;
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
if (!FluidSystem::phaseIsActive(phaseIdx))
continue;
saturation_[phaseIdx].resize(bufferSize,0.0);
}
oilPressure_.resize(bufferSize,0.0);
if (true)
temperature_.resize(bufferSize,0.0);
// Output the same as legacy
// TODO: Only needed if DISGAS or VAPOIL
if (true) {
rs_.resize(bufferSize,0.0);
}
if (true) {
rv_.resize(bufferSize,0.0);
}
if (GET_PROP_VALUE(TypeTag, EnableSolvent)) {
sSol_.resize(bufferSize,0.0);
}
if (GET_PROP_VALUE(TypeTag, EnablePolymer)) {
cPolymer_.resize(bufferSize,0.0);
}
if (true) {
// Output the same as legacy // Output the same as legacy
// TODO: Only needed if Vappars or hysteresis. // TODO: Only needed if Vappars or hysteresis.
soMax_.resize(bufferSize,0.0); soMax_.resize(bufferSize,0.0);
@@ -182,9 +179,11 @@ public:
krnSwMdcGo_.resize(bufferSize,0.0); krnSwMdcGo_.resize(bufferSize,0.0);
} }
// Only provide RESTART_AUXILIARY if it is asked for by the user // Only output RESTART_AUXILIARY asked for by the user.
if (!restartConfig.getWriteRestartFile(reportStepNum) || substep) std::map<std::string, int> rstKeywords = restartConfig.getRestartKeywords(reportStepNum);
return; for (auto& keyValue : rstKeywords) {
keyValue.second = restartConfig.getKeyword(keyValue.first, reportStepNum);
}
// Output the same as legacy // Output the same as legacy
// TODO: Only needed if DISGAS or VAPOIL // TODO: Only needed if DISGAS or VAPOIL
@@ -299,6 +298,7 @@ public:
if (!std::is_same<Discretization, Ewoms::EcfvDiscretization<TypeTag> >::value) if (!std::is_same<Discretization, Ewoms::EcfvDiscretization<TypeTag> >::value)
return; return;
const Opm::SummaryConfig& summaryConfig = simulator_.gridManager().summaryConfig();
for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) { for (unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(/*timeIdx=*/0); ++dofIdx) {
const auto& intQuants = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0); const auto& intQuants = elemCtx.intensiveQuantities(dofIdx, /*timeIdx=*/0);
const auto& fs = intQuants.fluidState(); const auto& fs = intQuants.fluidState();
@@ -562,8 +562,24 @@ public:
fip_[FIPDataType::GasInPlace][globalDofIdx] += gipl; fip_[FIPDataType::GasInPlace][globalDofIdx] += gipl;
} }
// Adding block values
const auto globalIdx = elemCtx.simulator().gridManager().grid().globalCell()[globalDofIdx];
for( const auto& node : summaryConfig ) {
if (node.type() == ECL_SMSPEC_BLOCK_VAR) {
int global_index = node.num() - 1;
std::pair<std::string, int> key = std::make_pair(node.keyword(), node.num());
if (global_index == globalIdx) {
if (strcmp(node.keyword(),"BGSAT")) {
blockValues_[key] = Toolbox::value(fs.saturation(waterPhaseIdx));
} else if (strcmp(node.keyword(),"BWSAT")) {
blockValues_[key] = Toolbox::value(fs.saturation(gasPhaseIdx));
} else if (strcmp(node.keyword(),"BPR")) {
blockValues_[key] = Toolbox::value(fs.pressure(oilPhaseIdx));
}
}
}
}
} }
} }
@@ -989,6 +1005,14 @@ public:
return 0; return 0;
} }
const std::map<std::pair<std::string, int>, double>& getBlockValues() {
return blockValues_;
}
const bool outputRestart() const {
return outputRestart_;
}
private: private:
@@ -1055,6 +1079,7 @@ private:
Scalar pvHydrocarbonSum = 0.0; Scalar pvHydrocarbonSum = 0.0;
size_t numElem = pPv_.size(); size_t numElem = pPv_.size();
for (size_t elem = 0; elem < numElem; ++elem) { for (size_t elem = 0; elem < numElem; ++elem) {
//ignore ghost cells (all ghost cells has fipnum == 0)
if(static_cast<int>(fipnum_[elem]) == reg || (-1 == reg && fipnum_[elem] > 0) ) if(static_cast<int>(fipnum_[elem]) == reg || (-1 == reg && fipnum_[elem] > 0) )
{ {
pPvSum += pPv_[elem];; pPvSum += pPv_[elem];;
@@ -1111,8 +1136,6 @@ private:
} }
} }
void outputRegionFluidInPlace_(const ScalarBuffer& oip, const ScalarBuffer& cip, const Scalar& pav, const int reg) void outputRegionFluidInPlace_(const ScalarBuffer& oip, const ScalarBuffer& cip, const Scalar& pav, const int reg)
{ {
const Opm::UnitSystem& units = simulator_.gridManager().eclState().getUnits(); const Opm::UnitSystem& units = simulator_.gridManager().eclState().getUnits();
@@ -1175,6 +1198,8 @@ private:
const Simulator& simulator_; const Simulator& simulator_;
bool outputRestart_;
ScalarBuffer saturation_[numPhases]; ScalarBuffer saturation_[numPhases];
ScalarBuffer oilPressure_; ScalarBuffer oilPressure_;
ScalarBuffer temperature_; ScalarBuffer temperature_;
@@ -1208,7 +1233,7 @@ private:
ScalarBuffer pvHydrocarbon_; ScalarBuffer pvHydrocarbon_;
ScalarBuffer pPv_; ScalarBuffer pPv_;
ScalarBuffer pPvHydrocarbon_; ScalarBuffer pPvHydrocarbon_;
std::map<std::pair<std::string, int>, double> blockValues_;
}; };
} // namespace Ewoms } // namespace Ewoms

View File

@@ -154,11 +154,12 @@ public:
// collect all data to I/O rank and assign to sol // collect all data to I/O rank and assign to sol
Opm::data::Solution localCellData; Opm::data::Solution localCellData;
if (eclOutputModule_.outputRestart())
eclOutputModule_.assignToSolution(localCellData); eclOutputModule_.assignToSolution(localCellData);
if (collectToIORank_.isParallel())
collectToIORank_.collect(localCellData);
//if (!substep) if (collectToIORank_.isParallel())
collectToIORank_.collect(localCellData, eclOutputModule_.getBlockValues());
std::map<std::string, double> miscSummaryData; std::map<std::string, double> miscSummaryData;
std::map<std::string, std::vector<double>> regionData; std::map<std::string, std::vector<double>> regionData;
eclOutputModule_.outputFIPLog(miscSummaryData, regionData, substep); eclOutputModule_.outputFIPLog(miscSummaryData, regionData, substep);
@@ -169,7 +170,7 @@ public:
std::map<std::string, std::vector<double>> extraRestartData; std::map<std::string, std::vector<double>> extraRestartData;
// Add suggested next timestep to extra data. // Add suggested next timestep to extra data.
if (!substep) if (eclOutputModule_.outputRestart())
extraRestartData["OPMEXTRA"] = std::vector<double>(1, nextstep); extraRestartData["OPMEXTRA"] = std::vector<double>(1, nextstep);
// Add TCPU // Add TCPU
@@ -178,6 +179,8 @@ public:
} }
bool enableDoublePrecisionOutput = false; //EWOMS_GET_PARAM(TypeTag, bool, EclOutputDoublePrecision); bool enableDoublePrecisionOutput = false; //EWOMS_GET_PARAM(TypeTag, bool, EclOutputDoublePrecision);
const Opm::data::Solution& cellData = collectToIORank_.isParallel() ? collectToIORank_.globalCellData() : localCellData; const Opm::data::Solution& cellData = collectToIORank_.isParallel() ? collectToIORank_.globalCellData() : localCellData;
const std::map<std::pair<std::string, int>, double>& blockValues = collectToIORank_.isParallel() ? collectToIORank_.globalBlockValues() : eclOutputModule_.getBlockValues();
eclIO_->writeTimeStep(episodeIdx, eclIO_->writeTimeStep(episodeIdx,
substep, substep,
t, t,
@@ -185,6 +188,7 @@ public:
dw, dw,
miscSummaryData, miscSummaryData,
regionData, regionData,
blockValues,
extraRestartData, extraRestartData,
enableDoublePrecisionOutput); enableDoublePrecisionOutput);
} }