-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathRifReaderRftInterface.cpp
More file actions
160 lines (139 loc) · 6.56 KB
/
RifReaderRftInterface.cpp
File metadata and controls
160 lines (139 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// 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.
//
// 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.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RifReaderRftInterface.h"
#include "RigEclipseCaseData.h"
#include "RigMainGrid.h"
#include "Well/RigEclipseWellLogExtractor.h"
#include "Well/RigWellPath.h"
#include "Well/RigWellPathGeometryTools.h"
#include "cafVecIjk.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifReaderRftInterface::~RifReaderRftInterface() = default;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::set<RifEclipseRftAddress> RifReaderRftInterface::eclipseRftAddresses( const QString& wellName, const QDateTime& timeStep )
{
std::set<RifEclipseRftAddress> matchingAddresses;
std::set<RifEclipseRftAddress> allAddresses = eclipseRftAddresses();
for ( const RifEclipseRftAddress& address : allAddresses )
{
if ( address.wellName() == wellName && address.timeStep() == timeStep )
{
matchingAddresses.insert( address );
}
}
return matchingAddresses;
}
//--------------------------------------------------------------------------------------------------
// Compute average measured depth for cell based on grid intersections for cells. If the well path geometry do not contain measured depth
// for a grid cell, the measured depth is estimated based on existing geometry for the well path.
//--------------------------------------------------------------------------------------------------
std::vector<double>
RifReaderRftInterface::computeMeasuredDepth( const QString& wellName, const QDateTime& timeStep, RigEclipseWellLogExtractor* eclExtractor )
{
if ( !eclExtractor ) return {};
if ( !eclExtractor->caseData() ) return {};
if ( eclExtractor->cellIntersectionMDs().empty() ) return {};
auto mainGrid = eclExtractor->caseData()->mainGrid();
if ( !mainGrid ) return {};
std::vector<double> avgMeasuredDepthForCells;
std::vector<double> tvdValuesToEstimate;
auto cellIjk = cellIndices( wellName, timeStep );
for ( const caf::VecIjk0& ijk : cellIjk )
{
if ( ijk.i() >= mainGrid->cellCountI() || ijk.j() >= mainGrid->cellCountJ() || ijk.k() >= mainGrid->cellCountK() ) continue;
auto globalCellIndex = mainGrid->cellIndexFromIJK( ijk.i(), ijk.j(), ijk.k() );
auto avgMd = eclExtractor->averageMdForCell( globalCellIndex );
if ( avgMd.has_value() )
{
avgMeasuredDepthForCells.push_back( avgMd.value() );
}
else
{
// The RFT cell is not part of cells intersected by well path
// Use the TVD of cell center to estimate measured depth
avgMeasuredDepthForCells.push_back( std::numeric_limits<double>::infinity() );
const RigCell& cell = mainGrid->cell( globalCellIndex );
if ( cell.isInvalid() )
{
tvdValuesToEstimate.push_back( std::numeric_limits<double>::infinity() );
}
else
{
tvdValuesToEstimate.push_back( -cell.center().z() );
}
}
}
if ( !tvdValuesToEstimate.empty() )
{
auto wellPathMd = eclExtractor->wellPathGeometry()->measuredDepths();
auto wellPathTvd = eclExtractor->wellPathGeometry()->trueVerticalDepths();
// Estimate measured depth for cells that do not have measured depth
auto estimatedMeasuredDepth = RigWellPathGeometryTools::interpolateMdFromTvd( wellPathMd, wellPathTvd, tvdValuesToEstimate );
double previousMd = std::numeric_limits<double>::infinity();
// Replace infinity MD values with estimated MD values based on well path geometry
// previousMd contains the last known measured depth value as we move along the well path
size_t estimatedIndex = 0;
for ( auto& measuredDepth : avgMeasuredDepthForCells )
{
if ( measuredDepth == std::numeric_limits<double>::infinity() )
{
// No measured depth for cell is found, try to estimate MD based on MD for previous cell
if ( estimatedIndex < estimatedMeasuredDepth.size() )
{
double estimatedMd = estimatedMeasuredDepth[estimatedIndex++];
if ( previousMd != std::numeric_limits<double>::infinity() )
{
if ( previousMd < estimatedMd )
{
// The estimated MD is larger than previous MD, use the estimated MD
measuredDepth = estimatedMd;
}
else
{
// The estimated MD is smaller than previous MD, use the previous MD + 1.0
measuredDepth = previousMd + 1.0;
}
}
else
{
// We do not have a valid previous MD, use the estimated MD
measuredDepth = estimatedMd;
}
}
else
{
measuredDepth = previousMd + 1.0;
}
}
// Assign the current MD as previous MD to be used for next estimated MD
previousMd = measuredDepth;
}
}
return avgMeasuredDepthForCells;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<caf::VecIjk0> RifReaderRftInterface::cellIndices( const QString& wellName, const QDateTime& timeStep )
{
return {};
}