ResInsight/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp

445 lines
21 KiB
C++
Raw Normal View History

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017- Statoil ASA
2018-08-09 04:30:18 -05:00
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
2018-08-09 04:30:18 -05:00
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
2018-08-09 04:30:18 -05:00
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicExportFractureCompletionsImpl.h"
#include "RiaLogging.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimFracture.h"
#include "RimFractureContainmentTools.h"
#include "RimFractureTemplate.h"
#include "RimSimWellFracture.h"
#include "RimSimWellFractureCollection.h"
#include "RimSimWellInView.h"
#include "RimStimPlanFractureTemplate.h"
#include "RimWellPath.h"
#include "RimWellPathCompletions.h"
#include "RimWellPathFracture.h"
#include "RimWellPathFractureCollection.h"
#include "RigEclipseCaseData.h"
2018-08-09 04:30:18 -05:00
#include "RigEclipseToStimPlanCellTransmissibilityCalculator.h"
#include "RigFractureCell.h"
#include "RigFractureGrid.h"
#include "RigFractureTransmissibilityEquations.h"
#include "RigMainGrid.h"
#include "RigSimWellData.h"
#include "RigSimulationWellCoordsAndMD.h"
2018-08-09 04:30:18 -05:00
#include "RigTransmissibilityCondenser.h"
#include "RigWellPath.h"
2018-08-09 04:30:18 -05:00
#include "RigWellPathStimplanIntersector.h"
#include <vector>
//--------------------------------------------------------------------------------------------------
2018-08-09 04:30:18 -05:00
///
//--------------------------------------------------------------------------------------------------
2018-08-09 04:30:18 -05:00
std::vector<RigCompletionData>
RicExportFractureCompletionsImpl::generateCompdatValuesForWellPath(RimWellPath* wellPath,
RimEclipseCase* caseToApply,
QTextStream* outputStreamForIntermediateResultsText)
{
std::vector<RimFracture*> fracturesAlongWellPath;
if (wellPath->fractureCollection()->isChecked())
{
for (const auto& frac : wellPath->fractureCollection()->fractures)
{
if (frac->isChecked())
{
fracturesAlongWellPath.push_back(frac);
}
}
}
return generateCompdatValues(caseToApply,
wellPath->completions()->wellNameForExport(),
wellPath->wellPathGeometry(),
fracturesAlongWellPath,
outputStreamForIntermediateResultsText);
}
//--------------------------------------------------------------------------------------------------
2018-08-09 04:30:18 -05:00
///
//--------------------------------------------------------------------------------------------------
std::vector<RigCompletionData> RicExportFractureCompletionsImpl::generateCompdatValuesForWellPathSingleFracture(
RimWellPath* wellPath,
RimEclipseCase* caseToApply,
RimFracture* fracture,
QTextStream* outputStreamForIntermediateResultsText)
{
std::vector<RimFracture*> fracturesAlongWellPath;
fracturesAlongWellPath.push_back(fracture);
return generateCompdatValues(caseToApply,
wellPath->completions()->wellNameForExport(),
wellPath->wellPathGeometry(),
fracturesAlongWellPath,
outputStreamForIntermediateResultsText);
}
//--------------------------------------------------------------------------------------------------
2018-08-09 04:30:18 -05:00
///
//--------------------------------------------------------------------------------------------------
2018-08-09 04:30:18 -05:00
std::vector<RigCompletionData>
RicExportFractureCompletionsImpl::generateCompdatValuesForSimWell(RimEclipseCase* eclipseCase,
const RimSimWellInView* well,
QTextStream* outputStreamForIntermediateResultsText)
{
std::vector<RigCompletionData> completionData;
auto branches = well->wellPipeBranches();
for (size_t branchIndex = 0; branchIndex < branches.size(); ++branchIndex)
{
std::vector<RimFracture*> fractures;
for (RimSimWellFracture* fracture : well->simwellFractureCollection->simwellFractures())
{
if (fracture->isChecked() && static_cast<size_t>(fracture->branchIndex()) == branchIndex)
{
fractures.push_back(fracture);
}
}
2018-08-09 04:30:18 -05:00
std::vector<RigCompletionData> branchCompletions = generateCompdatValues(
eclipseCase, well->name(), branches[branchIndex], fractures, outputStreamForIntermediateResultsText);
completionData.insert(completionData.end(), branchCompletions.begin(), branchCompletions.end());
}
return completionData;
}
//--------------------------------------------------------------------------------------------------
2018-08-09 04:30:18 -05:00
///
//--------------------------------------------------------------------------------------------------
2018-08-09 04:30:18 -05:00
std::vector<RigCompletionData>
RicExportFractureCompletionsImpl::generateCompdatValues(RimEclipseCase* caseToApply,
const QString& wellPathName,
const RigWellPath* wellPathGeometry,
const std::vector<RimFracture*>& fractures,
QTextStream* outputStreamForIntermediateResultsText)
{
2018-08-03 03:30:44 -05:00
std::vector<RigCompletionData> fractureCompletions;
2018-08-09 04:30:18 -05:00
if (!caseToApply || !caseToApply->eclipseCaseData())
2018-08-03 03:30:44 -05:00
{
return fractureCompletions;
}
2018-08-09 04:30:18 -05:00
double cDarcyInCorrectUnit = RiaEclipseUnitTools::darcysConstant(caseToApply->eclipseCaseData()->unitsType());
const RigMainGrid* mainGrid = caseToApply->eclipseCaseData()->mainGrid();
2018-08-09 04:30:18 -05:00
// To handle several fractures in the same eclipse cell we need to keep track of the transmissibility
// to the well from each fracture intersecting the cell and sum these transmissibilities at the end.
2018-08-09 04:30:18 -05:00
// std::map <eclipseCellIndex ,map< fracture, trans> >
std::map<size_t, std::map<RimFracture*, double>> eclCellIdxToTransPrFractureMap;
for (RimFracture* fracture : fractures)
{
RimFractureTemplate* fracTemplate = fracture->fractureTemplate();
if (!fracTemplate) continue;
const RigFractureGrid* fractureGrid = fracTemplate->fractureGrid();
if (!fractureGrid) continue;
bool useFiniteConductivityInFracture = (fracTemplate->conductivityType() == RimFractureTemplate::FINITE_CONDUCTIVITY);
2018-08-09 04:30:18 -05:00
// If finite cond chosen and conductivity not present in stimplan file, do not calculate trans for this fracture
if (useFiniteConductivityInFracture)
{
if (dynamic_cast<RimStimPlanFractureTemplate*>(fracTemplate))
{
RimStimPlanFractureTemplate* fracTemplateStimPlan = dynamic_cast<RimStimPlanFractureTemplate*>(fracTemplate);
if (!fracTemplateStimPlan->hasConductivity())
{
2018-08-09 04:30:18 -05:00
RiaLogging::error("Trying to export completion data for stimPlan fracture without conductivity data for " +
fracture->name());
RiaLogging::error("No transmissibilities will be calculated for " + fracture->name());
continue;
}
}
}
using CellIdxSpace = RigTransmissibilityCondenser::CellAddress;
RigTransmissibilityCondenser transCondenser;
//////
2018-08-09 04:30:18 -05:00
// Calculate Matrix To Fracture Trans
const std::vector<RigFractureCell>& fractureCells = fractureGrid->fractureCells();
2017-12-22 01:19:49 -06:00
for (const RigFractureCell& fractureCell : fractureCells)
{
if (!fractureCell.hasNonZeroConductivity()) continue;
RigEclipseToStimPlanCellTransmissibilityCalculator eclToFractureTransCalc(caseToApply,
fracture->transformMatrix(),
fracture->fractureTemplate()->skinFactor(),
cDarcyInCorrectUnit,
fractureCell);
2018-08-09 04:30:18 -05:00
const std::vector<size_t>& fractureCellContributingEclipseCells =
eclToFractureTransCalc.globalIndiciesToContributingEclipseCells();
const std::vector<double>& fractureCellContributingEclipseCellTransmissibilities =
eclToFractureTransCalc.contributingEclipseCellTransmissibilities();
size_t stimPlanCellIndex = fractureGrid->getGlobalIndexFromIJ(fractureCell.getI(), fractureCell.getJ());
2018-08-09 04:30:18 -05:00
auto truncatedFractureCellIndices =
RimFractureContainmentTools::fracturedCellsTruncatedByFaults(caseToApply, fracture);
2018-08-09 04:30:18 -05:00
for (size_t i = 0; i < fractureCellContributingEclipseCells.size(); i++)
{
2018-08-09 04:30:18 -05:00
if (fracture->isEclipseCellWithinContainment(caseToApply->eclipseCaseData()->mainGrid(),
truncatedFractureCellIndices,
fractureCellContributingEclipseCells[i]))
{
2018-08-09 04:30:18 -05:00
if (useFiniteConductivityInFracture)
{
2018-08-09 04:30:18 -05:00
transCondenser.addNeighborTransmissibility(
{true, CellIdxSpace::ECLIPSE, fractureCellContributingEclipseCells[i]},
{false, CellIdxSpace::STIMPLAN, stimPlanCellIndex},
fractureCellContributingEclipseCellTransmissibilities[i]);
}
else
{
2018-08-09 04:30:18 -05:00
transCondenser.addNeighborTransmissibility(
{true, CellIdxSpace::ECLIPSE, fractureCellContributingEclipseCells[i]},
{true, CellIdxSpace::WELL, 1},
fractureCellContributingEclipseCellTransmissibilities[i]);
}
}
}
}
//////
// Calculate Transmissibility in the fracture: From one StimPlan Cell to the other
if (useFiniteConductivityInFracture)
{
for (size_t i = 0; i < fractureGrid->iCellCount(); i++)
{
2018-08-09 04:30:18 -05:00
for (size_t j = 0; j < fractureGrid->jCellCount(); j++)
{
size_t fractureCellIndex = fractureGrid->getGlobalIndexFromIJ(i, j);
2018-08-09 04:30:18 -05:00
const RigFractureCell& fractureCell = fractureGrid->cellFromIndex(fractureCellIndex);
if (!fractureCell.hasNonZeroConductivity()) continue;
2018-08-09 04:30:18 -05:00
if (i < fractureGrid->iCellCount() - 1)
{
2018-08-09 04:30:18 -05:00
size_t fractureCellNeighbourXIndex = fractureGrid->getGlobalIndexFromIJ(i + 1, j);
const RigFractureCell& fractureCellNeighbourX = fractureGrid->cellFromIndex(fractureCellNeighbourXIndex);
2018-08-09 04:30:18 -05:00
double horizontalTransToXneigbour = RigFractureTransmissibilityEquations::centerToCenterFractureCellTrans(
fractureCell.getConductivityValue(),
fractureCell.cellSizeX(),
fractureCell.cellSizeZ(),
fractureCellNeighbourX.getConductivityValue(),
fractureCellNeighbourX.cellSizeX(),
fractureCellNeighbourX.cellSizeZ(),
cDarcyInCorrectUnit);
transCondenser.addNeighborTransmissibility(
{false, RigTransmissibilityCondenser::CellAddress::STIMPLAN, fractureCellIndex},
{false, RigTransmissibilityCondenser::CellAddress::STIMPLAN, fractureCellNeighbourXIndex},
horizontalTransToXneigbour);
}
2018-08-09 04:30:18 -05:00
if (j < fractureGrid->jCellCount() - 1)
{
2018-08-09 04:30:18 -05:00
size_t fractureCellNeighbourZIndex = fractureGrid->getGlobalIndexFromIJ(i, j + 1);
const RigFractureCell& fractureCellNeighbourZ = fractureGrid->cellFromIndex(fractureCellNeighbourZIndex);
2018-08-09 04:30:18 -05:00
double verticalTransToZneigbour = RigFractureTransmissibilityEquations::centerToCenterFractureCellTrans(
fractureCell.getConductivityValue(),
fractureCell.cellSizeZ(),
fractureCell.cellSizeX(),
fractureCellNeighbourZ.getConductivityValue(),
fractureCellNeighbourZ.cellSizeZ(),
fractureCellNeighbourZ.cellSizeX(),
cDarcyInCorrectUnit);
transCondenser.addNeighborTransmissibility(
{false, RigTransmissibilityCondenser::CellAddress::STIMPLAN, fractureCellIndex},
{false, RigTransmissibilityCondenser::CellAddress::STIMPLAN, fractureCellNeighbourZIndex},
verticalTransToZneigbour);
}
}
2018-08-09 04:30:18 -05:00
}
}
/////
// Calculate transmissibility into the well
2018-08-09 04:30:18 -05:00
if (useFiniteConductivityInFracture)
{
////
2018-08-09 04:30:18 -05:00
// If fracture has orientation Azimuth or Transverse, assume only radial inflow
2018-08-09 04:30:18 -05:00
if (fracture->fractureTemplate()->orientationType() == RimFractureTemplate::AZIMUTH ||
fracture->fractureTemplate()->orientationType() == RimFractureTemplate::TRANSVERSE_WELL_PATH)
{
const RigFractureGrid* fracGrid = fracture->fractureTemplate()->fractureGrid();
if (fracGrid)
{
2018-08-09 04:30:18 -05:00
std::pair<size_t, size_t> wellCellIJ = fracGrid->fractureCellAtWellCenter();
size_t wellCellIndex = fracGrid->getGlobalIndexFromIJ(wellCellIJ.first, wellCellIJ.second);
const RigFractureCell& wellCell = fractureGrid->cellFromIndex(wellCellIndex);
2018-08-09 04:30:18 -05:00
double radialTrans =
RigFractureTransmissibilityEquations::fractureCellToWellRadialTrans(wellCell.getConductivityValue(),
wellCell.cellSizeX(),
wellCell.cellSizeZ(),
fracture->wellRadius(),
fracTemplate->skinFactor(),
cDarcyInCorrectUnit);
transCondenser.addNeighborTransmissibility(
{true, RigTransmissibilityCondenser::CellAddress::WELL, 1},
{false, RigTransmissibilityCondenser::CellAddress::STIMPLAN, wellCellIndex},
radialTrans);
}
}
else if (fracture->fractureTemplate()->orientationType() == RimFractureTemplate::ALONG_WELL_PATH)
{
////
2018-08-09 04:30:18 -05:00
// If fracture has orientation along well, linear inflow along well and radial flow at endpoints
RigWellPathStimplanIntersector wellFractureIntersector(wellPathGeometry, fracture);
2018-08-09 04:30:18 -05:00
const std::map<size_t, RigWellPathStimplanIntersector::WellCellIntersection>& fractureWellCells =
wellFractureIntersector.intersections();
for (const auto& fracCellIdxIsectDataPair : fractureWellCells)
{
size_t fracWellCellIdx = fracCellIdxIsectDataPair.first;
RigWellPathStimplanIntersector::WellCellIntersection intersection = fracCellIdxIsectDataPair.second;
const RigFractureCell& fractureWellCell = fractureGrid->cellFromIndex(fracWellCellIdx);
double linearTrans = 0.0;
if (intersection.hlength > 0.0 || intersection.vlength > 0.0)
{
2018-08-09 04:30:18 -05:00
linearTrans = RigFractureTransmissibilityEquations::fractureCellToWellLinearTrans(
fractureWellCell.getConductivityValue(),
fractureWellCell.cellSizeX(),
fractureWellCell.cellSizeZ(),
intersection.vlength,
intersection.hlength,
fracture->perforationEfficiency(),
fracTemplate->skinFactor(),
cDarcyInCorrectUnit);
}
2018-08-09 04:30:18 -05:00
transCondenser.addNeighborTransmissibility(
{true, RigTransmissibilityCondenser::CellAddress::WELL, 1},
{false, RigTransmissibilityCondenser::CellAddress::STIMPLAN, fracWellCellIdx},
linearTrans);
}
}
}
/////
2018-08-09 04:30:18 -05:00
// Insert total transmissibility from eclipse-cell to well for this fracture into the map
std::vector<RigCompletionData> allCompletionsForOneFracture;
std::set<RigTransmissibilityCondenser::CellAddress> externalCells = transCondenser.externalCells();
for (RigTransmissibilityCondenser::CellAddress externalCell : externalCells)
{
if (externalCell.m_cellIndexSpace == RigTransmissibilityCondenser::CellAddress::ECLIPSE)
{
2018-08-09 04:30:18 -05:00
double trans = transCondenser.condensedTransmissibility(
externalCell, {true, RigTransmissibilityCondenser::CellAddress::WELL, 1});
eclCellIdxToTransPrFractureMap[externalCell.m_globalCellIdx][fracture] = trans;
2018-08-09 04:30:18 -05:00
RigCompletionData compDat(wellPathName,
RigCompletionDataGridCell(externalCell.m_globalCellIdx, caseToApply->mainGrid()),
fracture->fractureMD());
double diameter = 2.0 * fracture->wellRadius();
compDat.setFromFracture(trans, fracture->fractureTemplate()->skinFactor(), diameter);
compDat.addMetadata(fracture->name(), QString::number(trans));
allCompletionsForOneFracture.push_back(compDat);
}
}
/////
// Compute Non-Dracy Flow parameters
if (fracture->fractureTemplate()->isNonDarcyFlowEnabled())
{
double dFactorForFracture = fracture->fractureTemplate()->dFactor();
2018-08-09 04:30:18 -05:00
double khForFracture = fracture->fractureTemplate()->kh();
double sumOfTransmissibilitiesInFracture = 0.0;
for (const auto& c : allCompletionsForOneFracture)
{
sumOfTransmissibilitiesInFracture += c.transmissibility();
}
for (auto& c : allCompletionsForOneFracture)
{
// NOTE : What is supposed to happen when the transmissibility is close to zero?
double dFactorForOneConnection = dFactorForFracture * sumOfTransmissibilitiesInFracture / c.transmissibility();
c.setDFactor(dFactorForOneConnection);
double khForOneConnection = khForFracture * c.transmissibility() / sumOfTransmissibilitiesInFracture;
c.setKh(khForOneConnection);
}
}
2018-08-09 04:30:18 -05:00
std::copy(
allCompletionsForOneFracture.begin(), allCompletionsForOneFracture.end(), std::back_inserter(fractureCompletions));
2018-08-09 04:30:18 -05:00
if (outputStreamForIntermediateResultsText)
{
2018-08-09 04:30:18 -05:00
(*outputStreamForIntermediateResultsText)
<< "\n"
<< "\n"
<< "\n----------- All Transmissibilities " << fracture->name() << " -------------------- \n\n";
(*outputStreamForIntermediateResultsText)
<< QString::fromStdString(transCondenser.neighborTransDebugOutput(mainGrid, fractureGrid));
(*outputStreamForIntermediateResultsText)
<< "\n"
<< "\n"
<< "\n----------- Condensed Results " << fracture->name() << " -------------------- \n\n";
(*outputStreamForIntermediateResultsText)
<< QString::fromStdString(transCondenser.condensedTransDebugOutput(mainGrid, fractureGrid));
(*outputStreamForIntermediateResultsText) << "\n";
}
2018-08-09 04:30:18 -05:00
}
return fractureCompletions;
}