2021-03-15 10:23:57 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021 - 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.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-04-09 06:08:35 -05:00
|
|
|
#include "RimEnsembleFractureStatistics.h"
|
2021-03-15 10:23:57 -05:00
|
|
|
|
2021-03-26 04:01:36 -05:00
|
|
|
#include "RiaDefines.h"
|
2021-04-14 14:16:49 -05:00
|
|
|
#include "RiaInterpolationTools.h"
|
2021-03-17 13:04:04 -05:00
|
|
|
#include "RiaLogging.h"
|
|
|
|
#include "RiaPreferences.h"
|
2021-04-14 14:16:49 -05:00
|
|
|
#include "RiaWeightedGeometricMeanCalculator.h"
|
|
|
|
#include "RiaWeightedHarmonicMeanCalculator.h"
|
2021-03-17 13:04:04 -05:00
|
|
|
|
|
|
|
#include "RigFractureGrid.h"
|
|
|
|
#include "RigSlice2D.h"
|
|
|
|
#include "RigStatisticsMath.h"
|
|
|
|
#include "RigStimPlanFractureDefinition.h"
|
|
|
|
|
|
|
|
#include "RifCsvDataTableFormatter.h"
|
2021-04-09 06:08:35 -05:00
|
|
|
#include "RifEnsembleFractureStatisticsExporter.h"
|
2021-03-17 13:04:04 -05:00
|
|
|
#include "RifStimPlanXmlReader.h"
|
|
|
|
|
2021-03-26 08:56:29 -05:00
|
|
|
#include "FractureCommands/RicNewStimPlanFractureTemplateFeature.h"
|
|
|
|
|
2021-03-24 06:03:19 -05:00
|
|
|
#include "cafAppEnum.h"
|
2021-03-15 10:23:57 -05:00
|
|
|
#include "cafPdmUiTextEditor.h"
|
2021-03-26 08:56:29 -05:00
|
|
|
#include "cafPdmUiToolButtonEditor.h"
|
2021-04-09 11:56:57 -05:00
|
|
|
#include "cafPdmUiTreeSelectionEditor.h"
|
2021-03-15 10:23:57 -05:00
|
|
|
|
2021-03-17 13:04:04 -05:00
|
|
|
#include <cmath>
|
|
|
|
|
2021-03-26 04:01:36 -05:00
|
|
|
#include <QDir>
|
2021-03-17 13:04:04 -05:00
|
|
|
#include <QFile>
|
|
|
|
|
2021-03-24 06:03:19 -05:00
|
|
|
namespace caf
|
|
|
|
{
|
|
|
|
template <>
|
2021-04-09 06:08:35 -05:00
|
|
|
void caf::AppEnum<RimEnsembleFractureStatistics::StatisticsType>::setUp()
|
2021-03-24 06:03:19 -05:00
|
|
|
{
|
2021-04-09 06:08:35 -05:00
|
|
|
addItem( RimEnsembleFractureStatistics::StatisticsType::MEAN, "MEAN", "Mean" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::StatisticsType::MIN, "MIN", "Minimum" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::StatisticsType::MAX, "MAX", "Maximum" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::StatisticsType::P10, "P10", "P10" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::StatisticsType::P50, "P50", "P50" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::StatisticsType::P90, "P90", "P90" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::StatisticsType::OCCURRENCE, "OCCURRENCE", "Occurrence" );
|
|
|
|
setDefault( RimEnsembleFractureStatistics::StatisticsType::MEAN );
|
2021-03-24 06:03:19 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 08:59:28 -05:00
|
|
|
template <>
|
|
|
|
void caf::AppEnum<RimEnsembleFractureStatistics::MeshType>::setUp()
|
|
|
|
{
|
|
|
|
addItem( RimEnsembleFractureStatistics::MeshType::ADAPTIVE, "ADAPTIVE", "Adaptive" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::MeshType::UNIFORM, "UNIFORM", "Uniform" );
|
2021-04-14 14:16:49 -05:00
|
|
|
addItem( RimEnsembleFractureStatistics::MeshType::NAIVE, "NAIVE", "Naive" );
|
2021-04-14 08:59:28 -05:00
|
|
|
setDefault( RimEnsembleFractureStatistics::MeshType::ADAPTIVE );
|
|
|
|
}
|
|
|
|
|
2021-04-14 14:16:49 -05:00
|
|
|
template <>
|
|
|
|
void caf::AppEnum<RimEnsembleFractureStatistics::MeanType>::setUp()
|
|
|
|
{
|
|
|
|
addItem( RimEnsembleFractureStatistics::MeanType::HARMONIC, "HARMONIC", "Harmonic" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::MeanType::ARITHMETIC, "ARITHMETIC", "Artihmetic" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::MeanType::GEOMETRIC, "GEOMETRIC", "Geometric" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::MeanType::MINIMUM, "MINIMUM", "Minimum" );
|
|
|
|
setDefault( RimEnsembleFractureStatistics::MeanType::HARMONIC );
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void caf::AppEnum<RimEnsembleFractureStatistics::AdaptiveSamplingSizeType>::setUp()
|
|
|
|
{
|
|
|
|
addItem( RimEnsembleFractureStatistics::AdaptiveSamplingSizeType::AVERAGE, "AVERAGE", "Average" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::AdaptiveSamplingSizeType::MINIMUM, "MINIMUM", "Minimum" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::AdaptiveSamplingSizeType::MAXIMUM, "MAXIMUM", "Maximum" );
|
|
|
|
addItem( RimEnsembleFractureStatistics::AdaptiveSamplingSizeType::USER_DEFINED, "USER_DEFINED", "User-Defined" );
|
|
|
|
setDefault( RimEnsembleFractureStatistics::AdaptiveSamplingSizeType::AVERAGE );
|
|
|
|
}
|
|
|
|
|
2021-03-24 06:03:19 -05:00
|
|
|
} // namespace caf
|
|
|
|
|
2021-04-09 06:08:35 -05:00
|
|
|
CAF_PDM_SOURCE_INIT( RimEnsembleFractureStatistics, "EnsembleFractureStatistics" );
|
2021-03-15 10:23:57 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
RimEnsembleFractureStatistics::RimEnsembleFractureStatistics()
|
2021-03-15 10:23:57 -05:00
|
|
|
{
|
2021-04-09 06:08:35 -05:00
|
|
|
CAF_PDM_InitObject( "Ensemble Fracture Statistics", ":/FractureTemplate16x16.png", "", "" );
|
2021-03-15 10:23:57 -05:00
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_filePaths, "FilePaths", "", "", "", "" );
|
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_filePathsTable, "FilePathsTable", "File Paths Table", "", "", "" );
|
|
|
|
m_filePathsTable.uiCapability()->setUiEditorTypeName( caf::PdmUiTextEditor::uiEditorTypeName() );
|
|
|
|
m_filePathsTable.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
|
|
|
m_filePathsTable.uiCapability()->setUiReadOnly( true );
|
|
|
|
m_filePathsTable.xmlCapability()->disableIO();
|
2021-03-26 08:56:29 -05:00
|
|
|
|
2021-04-14 08:59:28 -05:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_meshType, "MeshType", "Mesh Type", "", "", "" );
|
2021-04-14 14:16:49 -05:00
|
|
|
|
|
|
|
// Uniform sampling
|
2021-04-09 11:56:57 -05:00
|
|
|
CAF_PDM_InitField( &m_numSamplesX, "NumberOfSamplesX", 100, "X", "", "", "" );
|
|
|
|
CAF_PDM_InitField( &m_numSamplesY, "NumberOfSamplesY", 200, "Y", "", "", "" );
|
|
|
|
|
2021-04-14 14:16:49 -05:00
|
|
|
// Adaptive sampling
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_adaptiveMeanType, "AdaptiveMeanType", "Mean Type", "", "", "" );
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_adaptiveSamplingSizeType, "AdaptiveSamplingSizeType", "Sampling Type", "", "", "" );
|
|
|
|
CAF_PDM_InitField( &m_adaptiveNumSamplesY, "AdaptiveNumSamplesY", 30, "Number of Samples Y", "", "", "" );
|
|
|
|
|
2021-04-09 11:56:57 -05:00
|
|
|
std::vector<caf::AppEnum<RimEnsembleFractureStatistics::StatisticsType>> defaultStatisticsTypes = {
|
|
|
|
caf::AppEnum<RimEnsembleFractureStatistics::StatisticsType>( RimEnsembleFractureStatistics::StatisticsType::MEAN ) };
|
|
|
|
|
|
|
|
CAF_PDM_InitField( &m_selectedStatisticsType, "SelectedStatisticsType", defaultStatisticsTypes, "Statistics Type", "", "", "" );
|
|
|
|
m_selectedStatisticsType.uiCapability()->setUiEditorTypeName( caf::PdmUiTreeSelectionEditor::uiEditorTypeName() );
|
|
|
|
m_selectedStatisticsType.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::TOP );
|
|
|
|
|
2021-04-14 08:59:28 -05:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_computeStatistics, "ComputeStatistics", "Compute Templates", "", "", "" );
|
2021-03-26 08:56:29 -05:00
|
|
|
m_computeStatistics.uiCapability()->setUiEditorTypeName( caf::PdmUiToolButtonEditor::uiEditorTypeName() );
|
|
|
|
m_computeStatistics.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
|
|
|
|
|
|
|
setDeletable( true );
|
2021-03-15 10:23:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
RimEnsembleFractureStatistics::~RimEnsembleFractureStatistics()
|
2021-03-15 10:23:57 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
void RimEnsembleFractureStatistics::addFilePath( const QString& filePath )
|
2021-03-15 10:23:57 -05:00
|
|
|
{
|
|
|
|
m_filePaths.v().push_back( filePath );
|
|
|
|
m_filePathsTable = generateFilePathsTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
QString RimEnsembleFractureStatistics::generateFilePathsTable()
|
2021-03-15 10:23:57 -05:00
|
|
|
{
|
|
|
|
QString body;
|
|
|
|
for ( auto prop : m_filePaths.v() )
|
|
|
|
{
|
|
|
|
body.append( prop.path() + "<br>" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
2021-04-09 11:56:57 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QList<caf::PdmOptionItemInfo>
|
|
|
|
RimEnsembleFractureStatistics::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
|
|
|
bool* useOptionsOnly )
|
|
|
|
{
|
|
|
|
QList<caf::PdmOptionItemInfo> options;
|
|
|
|
if ( fieldNeedingOptions == &m_selectedStatisticsType )
|
|
|
|
{
|
|
|
|
for ( size_t i = 0; i < caf::AppEnum<RimEnsembleFractureStatistics::StatisticsType>::size(); ++i )
|
|
|
|
{
|
|
|
|
caf::AppEnum<RimEnsembleFractureStatistics::StatisticsType> t =
|
|
|
|
caf::AppEnum<RimEnsembleFractureStatistics::StatisticsType>::fromIndex( i );
|
|
|
|
t.uiText();
|
|
|
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( t.uiText(), t.value() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:23:57 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
void RimEnsembleFractureStatistics::defineEditorAttribute( const caf::PdmFieldHandle* field,
|
|
|
|
QString uiConfigName,
|
|
|
|
caf::PdmUiEditorAttribute* attribute )
|
2021-03-15 10:23:57 -05:00
|
|
|
{
|
|
|
|
if ( field == &m_filePathsTable )
|
|
|
|
{
|
|
|
|
auto myAttr = dynamic_cast<caf::PdmUiTextEditorAttribute*>( attribute );
|
|
|
|
if ( myAttr )
|
|
|
|
{
|
|
|
|
myAttr->wrapMode = caf::PdmUiTextEditorAttribute::NoWrap;
|
|
|
|
myAttr->textMode = caf::PdmUiTextEditorAttribute::HTML;
|
|
|
|
}
|
|
|
|
}
|
2021-04-09 11:56:57 -05:00
|
|
|
else if ( field == &m_selectedStatisticsType )
|
|
|
|
{
|
|
|
|
caf::PdmUiTreeSelectionEditorAttribute* attrib = dynamic_cast<caf::PdmUiTreeSelectionEditorAttribute*>( attribute );
|
|
|
|
if ( attrib )
|
|
|
|
{
|
|
|
|
attrib->showTextFilter = false;
|
|
|
|
attrib->showToggleAllCheckbox = false;
|
|
|
|
attrib->singleSelectionMode = false;
|
|
|
|
}
|
|
|
|
}
|
2021-03-15 10:23:57 -05:00
|
|
|
}
|
|
|
|
|
2021-03-26 08:56:29 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
void RimEnsembleFractureStatistics::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
|
|
|
const QVariant& oldValue,
|
|
|
|
const QVariant& newValue )
|
2021-03-26 08:56:29 -05:00
|
|
|
{
|
|
|
|
if ( changedField == &m_computeStatistics )
|
|
|
|
{
|
|
|
|
m_computeStatistics = false;
|
|
|
|
std::vector<QString> filePaths = computeStatistics();
|
|
|
|
RicNewStimPlanFractureTemplateFeature::createNewTemplatesFromFiles( filePaths );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-14 08:59:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimEnsembleFractureStatistics::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
|
|
{
|
|
|
|
uiOrdering.add( nameField() );
|
|
|
|
uiOrdering.add( &m_filePathsTable );
|
|
|
|
uiOrdering.add( &m_meshType );
|
|
|
|
uiOrdering.add( &m_numSamplesX );
|
|
|
|
uiOrdering.add( &m_numSamplesY );
|
|
|
|
bool isUniformMesh = m_meshType() == MeshType::UNIFORM;
|
|
|
|
m_numSamplesX.uiCapability()->setUiHidden( !isUniformMesh );
|
|
|
|
m_numSamplesY.uiCapability()->setUiHidden( !isUniformMesh );
|
|
|
|
|
2021-04-14 14:16:49 -05:00
|
|
|
uiOrdering.add( &m_adaptiveMeanType );
|
|
|
|
uiOrdering.add( &m_adaptiveSamplingSizeType );
|
|
|
|
uiOrdering.add( &m_adaptiveNumSamplesY );
|
|
|
|
|
|
|
|
bool isAdaptiveMesh = m_meshType() == MeshType::ADAPTIVE;
|
|
|
|
m_adaptiveMeanType.uiCapability()->setUiHidden( !isAdaptiveMesh );
|
|
|
|
m_adaptiveSamplingSizeType.uiCapability()->setUiHidden( !isAdaptiveMesh );
|
|
|
|
|
|
|
|
bool adaptiveSamplesUserDefined = m_adaptiveSamplingSizeType() == AdaptiveSamplingSizeType::USER_DEFINED;
|
|
|
|
m_adaptiveNumSamplesY.uiCapability()->setUiHidden( !isAdaptiveMesh || !adaptiveSamplesUserDefined );
|
|
|
|
|
2021-04-14 08:59:28 -05:00
|
|
|
uiOrdering.add( &m_selectedStatisticsType );
|
|
|
|
uiOrdering.add( &m_computeStatistics );
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:23:57 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
void RimEnsembleFractureStatistics::loadAndUpdateData()
|
2021-03-15 10:23:57 -05:00
|
|
|
{
|
|
|
|
m_filePathsTable = generateFilePathsTable();
|
2021-03-17 13:04:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
std::vector<QString> RimEnsembleFractureStatistics::computeStatistics()
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
|
|
|
auto unitSystem = RiaDefines::EclipseUnitSystem::UNITS_METRIC;
|
|
|
|
|
|
|
|
std::vector<cvf::ref<RigStimPlanFractureDefinition>> stimPlanFractureDefinitions =
|
|
|
|
readFractureDefinitions( m_filePaths.v(), unitSystem );
|
|
|
|
|
2021-03-26 04:01:36 -05:00
|
|
|
std::set<std::pair<QString, QString>> availableResults = findAllResultNames( stimPlanFractureDefinitions );
|
2021-03-17 13:04:04 -05:00
|
|
|
|
2021-04-09 06:08:35 -05:00
|
|
|
std::map<std::pair<RimEnsembleFractureStatistics::StatisticsType, QString>, std::shared_ptr<RigSlice2D>> statisticsGridsAll;
|
2021-03-17 13:04:04 -05:00
|
|
|
|
2021-04-09 11:56:57 -05:00
|
|
|
auto selectedStatistics = m_selectedStatisticsType.value();
|
|
|
|
|
2021-03-24 09:06:42 -05:00
|
|
|
// TODO: take from an incoming xml?
|
2021-04-07 08:00:52 -05:00
|
|
|
double timeStep = 1.0;
|
|
|
|
|
|
|
|
double referenceDepth = 0.0;
|
|
|
|
for ( auto definition : stimPlanFractureDefinitions )
|
|
|
|
{
|
|
|
|
referenceDepth += computeDepthOfWellPathAtFracture( definition );
|
|
|
|
}
|
|
|
|
referenceDepth /= stimPlanFractureDefinitions.size();
|
2021-03-24 09:06:42 -05:00
|
|
|
|
2021-04-14 09:16:06 -05:00
|
|
|
std::vector<double> gridXs;
|
|
|
|
std::vector<double> gridYs;
|
2021-04-14 14:16:49 -05:00
|
|
|
auto [minX, maxX, minY, maxY] = findSamplingIntervals( stimPlanFractureDefinitions, gridXs, gridYs );
|
|
|
|
RiaLogging::info(
|
|
|
|
QString( "Ensemble Fracture Size: X = [%1, %2] Y = [%3, %4]" ).arg( minX ).arg( maxX ).arg( minY ).arg( maxY ) );
|
2021-03-24 09:06:42 -05:00
|
|
|
|
2021-03-24 13:42:00 -05:00
|
|
|
for ( auto result : availableResults )
|
2021-03-24 09:06:42 -05:00
|
|
|
{
|
2021-03-26 04:01:36 -05:00
|
|
|
RiaLogging::info( QString( "Creating statistics for result: %1" ).arg( result.first ) );
|
2021-03-24 13:42:00 -05:00
|
|
|
|
|
|
|
std::vector<cvf::cref<RigFractureGrid>> fractureGrids =
|
2021-03-26 04:01:36 -05:00
|
|
|
createFractureGrids( stimPlanFractureDefinitions, unitSystem, result.first );
|
2021-03-24 13:42:00 -05:00
|
|
|
|
2021-04-14 09:16:06 -05:00
|
|
|
std::vector<std::vector<double>> samples( gridXs.size() * gridYs.size() );
|
|
|
|
sampleAllGrids( fractureGrids, gridXs, gridYs, samples );
|
2021-03-17 13:04:04 -05:00
|
|
|
|
2021-04-09 06:08:35 -05:00
|
|
|
std::map<RimEnsembleFractureStatistics::StatisticsType, std::shared_ptr<RigSlice2D>> statisticsGrids;
|
2021-04-14 09:16:06 -05:00
|
|
|
generateStatisticsGrids( samples, gridXs.size(), gridYs.size(), statisticsGrids, selectedStatistics );
|
2021-03-24 13:42:00 -05:00
|
|
|
|
|
|
|
for ( auto [statType, slice] : statisticsGrids )
|
|
|
|
{
|
2021-03-26 04:01:36 -05:00
|
|
|
auto key = std::make_pair( statType, result.first );
|
2021-03-24 13:42:00 -05:00
|
|
|
statisticsGridsAll[key] = slice;
|
|
|
|
}
|
|
|
|
}
|
2021-03-17 13:04:04 -05:00
|
|
|
|
2021-03-26 08:56:29 -05:00
|
|
|
std::vector<QString> xmlFilePaths;
|
|
|
|
|
|
|
|
// Save images in snapshot catalog relative to project directory
|
|
|
|
RiaApplication* app = RiaApplication::instance();
|
|
|
|
QString outputDirectoryPath = app->createAbsolutePathFromProjectRelativePath( "fracturestats" );
|
|
|
|
QDir outputDirectory( outputDirectoryPath );
|
|
|
|
if ( !outputDirectory.exists() )
|
|
|
|
{
|
|
|
|
outputDirectory.mkpath( outputDirectoryPath );
|
|
|
|
}
|
|
|
|
|
2021-04-09 11:56:57 -05:00
|
|
|
for ( auto t : selectedStatistics )
|
2021-03-24 06:03:19 -05:00
|
|
|
{
|
|
|
|
QString text = t.text();
|
2021-03-24 13:42:00 -05:00
|
|
|
|
|
|
|
// Get the all the properties for this statistics type
|
|
|
|
std::vector<std::shared_ptr<RigSlice2D>> statisticsSlices;
|
2021-03-26 04:01:36 -05:00
|
|
|
std::vector<std::pair<QString, QString>> properties;
|
2021-03-24 13:42:00 -05:00
|
|
|
for ( auto result : availableResults )
|
|
|
|
{
|
|
|
|
properties.push_back( result );
|
2021-03-26 04:01:36 -05:00
|
|
|
std::shared_ptr<RigSlice2D> slice = statisticsGridsAll[std::make_pair( t.value(), result.first )];
|
2021-03-24 13:42:00 -05:00
|
|
|
statisticsSlices.push_back( slice );
|
|
|
|
|
2021-03-26 08:56:29 -05:00
|
|
|
QString csvFilePath = outputDirectoryPath + "/" + text + "-" + result.first + ".csv";
|
|
|
|
writeStatisticsToCsv( csvFilePath, *slice );
|
2021-03-24 13:42:00 -05:00
|
|
|
}
|
2021-03-24 09:06:42 -05:00
|
|
|
|
2021-03-26 08:56:29 -05:00
|
|
|
QString xmlFilePath = outputDirectoryPath + "/" + name() + "-" + text + ".xml";
|
|
|
|
|
2021-04-14 09:16:06 -05:00
|
|
|
// TODO: add offset for grid ys
|
|
|
|
std::vector<double> gridYsWithOffset;
|
|
|
|
for ( double depth : gridYs )
|
|
|
|
gridYsWithOffset.push_back( referenceDepth - depth );
|
|
|
|
|
2021-03-26 08:56:29 -05:00
|
|
|
RiaLogging::info( QString( "Writing fracture group statistics to: %1" ).arg( xmlFilePath ) );
|
2021-04-09 06:08:35 -05:00
|
|
|
RifEnsembleFractureStatisticsExporter::writeAsStimPlanXml( statisticsSlices,
|
|
|
|
properties,
|
|
|
|
xmlFilePath,
|
|
|
|
gridXs,
|
2021-04-14 09:16:06 -05:00
|
|
|
gridYsWithOffset,
|
2021-04-09 06:08:35 -05:00
|
|
|
timeStep,
|
|
|
|
unitSystem );
|
2021-03-26 08:56:29 -05:00
|
|
|
|
|
|
|
xmlFilePaths.push_back( xmlFilePath );
|
2021-03-24 06:03:19 -05:00
|
|
|
}
|
2021-03-26 08:56:29 -05:00
|
|
|
|
|
|
|
return xmlFilePaths;
|
2021-03-17 13:04:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<cvf::ref<RigStimPlanFractureDefinition>>
|
2021-04-09 06:08:35 -05:00
|
|
|
RimEnsembleFractureStatistics::readFractureDefinitions( const std::vector<caf::FilePath>& filePaths,
|
|
|
|
RiaDefines::EclipseUnitSystem unitSystem ) const
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
|
|
|
double conductivityScaleFactor = 1.0;
|
|
|
|
|
|
|
|
std::vector<cvf::ref<RigStimPlanFractureDefinition>> results;
|
|
|
|
for ( auto filePath : m_filePaths.v() )
|
|
|
|
{
|
|
|
|
RiaLogging::info( QString( "Loading file: %1" ).arg( filePath.path() ) );
|
|
|
|
QString errorMessage;
|
|
|
|
cvf::ref<RigStimPlanFractureDefinition> stimPlanFractureDefinitionData =
|
|
|
|
RifStimPlanXmlReader::readStimPlanXMLFile( filePath.path(),
|
|
|
|
conductivityScaleFactor,
|
|
|
|
RifStimPlanXmlReader::MirrorMode::MIRROR_AUTO,
|
|
|
|
unitSystem,
|
|
|
|
&errorMessage );
|
|
|
|
if ( !errorMessage.isEmpty() )
|
|
|
|
{
|
|
|
|
RiaLogging::error( QString( "Error when reading file: '%1'" ).arg( errorMessage ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( stimPlanFractureDefinitionData.notNull() )
|
|
|
|
{
|
|
|
|
results.push_back( stimPlanFractureDefinitionData );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
std::set<std::pair<QString, QString>> RimEnsembleFractureStatistics::findAllResultNames(
|
2021-03-17 13:04:04 -05:00
|
|
|
const std::vector<cvf::ref<RigStimPlanFractureDefinition>>& stimPlanFractureDefinitions )
|
|
|
|
{
|
2021-03-26 04:01:36 -05:00
|
|
|
std::set<std::pair<QString, QString>> resultNames;
|
2021-03-17 13:04:04 -05:00
|
|
|
for ( auto stimPlanFractureDefinitionData : stimPlanFractureDefinitions )
|
|
|
|
{
|
2021-03-26 04:01:36 -05:00
|
|
|
for ( auto propertyNameWithUnit : stimPlanFractureDefinitionData->getStimPlanPropertyNamesUnits() )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
2021-03-26 04:01:36 -05:00
|
|
|
resultNames.insert( propertyNameWithUnit );
|
2021-03-17 13:04:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
std::vector<cvf::cref<RigFractureGrid>> RimEnsembleFractureStatistics::createFractureGrids(
|
2021-03-17 13:04:04 -05:00
|
|
|
const std::vector<cvf::ref<RigStimPlanFractureDefinition>>& stimPlanFractureDefinitions,
|
2021-03-24 13:42:00 -05:00
|
|
|
RiaDefines::EclipseUnitSystem unitSystem,
|
|
|
|
const QString& resultNameOnFile )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
|
|
|
// Defaults to avoid scaling
|
|
|
|
double halfLengthScaleFactor = 1.0;
|
|
|
|
double heightScaleFactor = 1.0;
|
|
|
|
|
|
|
|
std::vector<cvf::cref<RigFractureGrid>> fractureGrids;
|
|
|
|
for ( auto stimPlanFractureDefinitionData : stimPlanFractureDefinitions )
|
|
|
|
{
|
|
|
|
double wellPathDepthAtFracture = computeDepthOfWellPathAtFracture( stimPlanFractureDefinitionData );
|
|
|
|
|
|
|
|
// Always use last time steps
|
|
|
|
std::vector<double> timeSteps = stimPlanFractureDefinitionData->timeSteps();
|
|
|
|
int activeTimeStepIndex = timeSteps.size() - 1;
|
|
|
|
|
|
|
|
cvf::cref<RigFractureGrid> fractureGrid =
|
2021-03-24 13:42:00 -05:00
|
|
|
stimPlanFractureDefinitionData->createFractureGrid( resultNameOnFile,
|
2021-03-17 13:04:04 -05:00
|
|
|
activeTimeStepIndex,
|
|
|
|
halfLengthScaleFactor,
|
|
|
|
heightScaleFactor,
|
|
|
|
wellPathDepthAtFracture,
|
|
|
|
unitSystem );
|
|
|
|
|
|
|
|
if ( fractureGrid.notNull() )
|
|
|
|
{
|
|
|
|
fractureGrids.push_back( fractureGrid );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fractureGrids;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-14 14:16:49 -05:00
|
|
|
std::tuple<double, double, double, double> RimEnsembleFractureStatistics::findSamplingIntervals(
|
|
|
|
const std::vector<cvf::ref<RigStimPlanFractureDefinition>>& stimPlanFractureDefinitions,
|
|
|
|
std::vector<double>& gridXs,
|
|
|
|
std::vector<double>& gridYs ) const
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
|
|
|
// Find min and max extent of all the grids
|
2021-04-14 14:16:49 -05:00
|
|
|
auto [minX, maxX, minY, maxY] = findMaxGridExtents( stimPlanFractureDefinitions );
|
|
|
|
|
|
|
|
if ( m_meshType() == MeshType::UNIFORM )
|
|
|
|
{
|
|
|
|
generateUniformMesh( minX, maxX, minY, maxY, gridXs, gridYs );
|
|
|
|
}
|
|
|
|
else if ( m_meshType() == MeshType::NAIVE )
|
|
|
|
{
|
|
|
|
generateNaiveMesh( minX, maxX, minY, maxY, stimPlanFractureDefinitions, gridXs, gridYs );
|
|
|
|
}
|
|
|
|
else if ( m_meshType() == MeshType::ADAPTIVE )
|
|
|
|
{
|
|
|
|
generateAdaptiveMesh( minX, maxX, minY, maxY, stimPlanFractureDefinitions, gridXs, gridYs );
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_tuple( minX, maxX, minY, maxY );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::tuple<double, double, double, double> RimEnsembleFractureStatistics::findMaxGridExtents(
|
|
|
|
const std::vector<cvf::ref<RigStimPlanFractureDefinition>>& stimPlanFractureDefinitions )
|
|
|
|
{
|
2021-03-17 13:04:04 -05:00
|
|
|
double minX = std::numeric_limits<double>::max();
|
|
|
|
double maxX = -std::numeric_limits<double>::max();
|
|
|
|
double minY = std::numeric_limits<double>::max();
|
|
|
|
double maxY = -std::numeric_limits<double>::max();
|
|
|
|
|
2021-04-14 14:16:49 -05:00
|
|
|
for ( auto def : stimPlanFractureDefinitions )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
2021-04-14 14:16:49 -05:00
|
|
|
minX = std::min( minX, def->xs().front() );
|
|
|
|
maxX = std::max( maxX, def->xs().back() );
|
|
|
|
|
|
|
|
double offset = computeDepthOfWellPathAtFracture( def );
|
|
|
|
|
|
|
|
minY = std::min( minY, offset + def->ys().back() );
|
|
|
|
maxY = std::max( maxY, offset + def->ys().front() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_tuple( minX, maxX, minY, maxY );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimEnsembleFractureStatistics::generateUniformMesh( double minX,
|
|
|
|
double maxX,
|
|
|
|
double minY,
|
|
|
|
double maxY,
|
|
|
|
std::vector<double>& gridXs,
|
|
|
|
std::vector<double>& gridYs ) const
|
|
|
|
{
|
|
|
|
int numSamplesX = m_numSamplesX();
|
|
|
|
double sampleDistanceX = linearSampling( minX, maxX, numSamplesX, gridXs );
|
|
|
|
|
|
|
|
int numSamplesY = m_numSamplesY();
|
|
|
|
double sampleDistanceY = linearSampling( minY, maxY, numSamplesY, gridYs );
|
|
|
|
|
|
|
|
RiaLogging::info( QString( "Uniform Mesh. Output size: %1x%2. Sampling Distance X = %3 Sampling Distance Y = %4" )
|
|
|
|
.arg( numSamplesX )
|
|
|
|
.arg( numSamplesY )
|
|
|
|
.arg( sampleDistanceX )
|
|
|
|
.arg( sampleDistanceY ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimEnsembleFractureStatistics::generateNaiveMesh(
|
|
|
|
double minX,
|
|
|
|
double maxX,
|
|
|
|
double minY,
|
|
|
|
double maxY,
|
|
|
|
const std::vector<cvf::ref<RigStimPlanFractureDefinition>>& stimPlanFractureDefinitions,
|
|
|
|
std::vector<double>& gridXs,
|
|
|
|
std::vector<double>& gridYs ) const
|
|
|
|
{
|
|
|
|
// Find max number of cells in x direction
|
|
|
|
int maxNx = 0;
|
|
|
|
for ( auto def : stimPlanFractureDefinitions )
|
|
|
|
{
|
|
|
|
maxNx = std::max( maxNx, static_cast<int>( def->xs().size() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do linear sampling in x drection
|
|
|
|
linearSampling( minX, maxX, maxNx, gridXs );
|
|
|
|
|
|
|
|
std::vector<double> depths;
|
|
|
|
for ( auto def : stimPlanFractureDefinitions )
|
|
|
|
{
|
|
|
|
double offset = computeDepthOfWellPathAtFracture( def );
|
|
|
|
for ( double y : def->ys() )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
2021-04-14 14:16:49 -05:00
|
|
|
depths.push_back( offset + y );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort( depths.begin(), depths.end() );
|
|
|
|
gridYs = depths;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimEnsembleFractureStatistics::generateAdaptiveMesh(
|
|
|
|
double minX,
|
|
|
|
double maxX,
|
|
|
|
double minY,
|
|
|
|
double maxY,
|
|
|
|
const std::vector<cvf::ref<RigStimPlanFractureDefinition>>& stimPlanFractureDefinitions,
|
|
|
|
std::vector<double>& gridXs,
|
|
|
|
std::vector<double>& gridYs ) const
|
|
|
|
{
|
|
|
|
// Find max number of cells in x direction
|
|
|
|
int maxNx = 0;
|
|
|
|
for ( auto def : stimPlanFractureDefinitions )
|
|
|
|
{
|
|
|
|
maxNx = std::max( maxNx, static_cast<int>( def->xs().size() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do linear sampling in x drection
|
|
|
|
linearSampling( minX, maxX, maxNx, gridXs );
|
|
|
|
|
|
|
|
std::vector<Layer> layers;
|
|
|
|
generateAllLayers( stimPlanFractureDefinitions, layers );
|
|
|
|
|
|
|
|
const int targetNumLayers = getTargetNumberOfLayers( stimPlanFractureDefinitions );
|
|
|
|
|
|
|
|
// Group the layers into linearly spaced bins
|
|
|
|
double totalDepth = maxY - minY;
|
|
|
|
double binSize = totalDepth / targetNumLayers;
|
|
|
|
|
|
|
|
RiaLogging::info(
|
|
|
|
QString( "Adaptive mesh. Number of layers: %1. Layer thickness: %2" ).arg( targetNumLayers ).arg( binSize ) );
|
|
|
|
|
|
|
|
int nTotalMatches = 0;
|
|
|
|
|
|
|
|
std::vector<double> baseDepth;
|
|
|
|
baseDepth.push_back( minY );
|
|
|
|
|
|
|
|
std::vector<double> means;
|
|
|
|
double sumMeans = 0.0;
|
|
|
|
|
|
|
|
// Calculate
|
|
|
|
for ( int layerNo = 0; layerNo < targetNumLayers; layerNo++ )
|
|
|
|
{
|
|
|
|
double binTopDepth = minY + layerNo * binSize;
|
|
|
|
double binBottomDepth = minY + ( layerNo + 1 ) * binSize;
|
|
|
|
|
|
|
|
baseDepth.push_back( binBottomDepth );
|
|
|
|
|
|
|
|
RiaWeightedHarmonicMeanCalculator harmonicMeanCalculator;
|
|
|
|
RiaWeightedGeometricMeanCalculator geometricMeanCalculator;
|
|
|
|
|
|
|
|
double sum = 0.0;
|
|
|
|
double nMatches = 0;
|
|
|
|
double minThickness = std::numeric_limits<double>::max();
|
|
|
|
for ( Layer layer : layers )
|
|
|
|
{
|
|
|
|
// TODO: top and bottom is mixed up here (again!)
|
|
|
|
if ( layer.centerDepth() > binTopDepth && layer.centerDepth() <= binBottomDepth )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
2021-04-14 14:16:49 -05:00
|
|
|
harmonicMeanCalculator.addValueAndWeight( layer.thickness(), 1.0 );
|
|
|
|
geometricMeanCalculator.addValueAndWeight( layer.thickness(), 1.0 );
|
|
|
|
|
|
|
|
minThickness = std::min( minThickness, layer.thickness() );
|
|
|
|
|
|
|
|
sum += layer.thickness();
|
|
|
|
nMatches++;
|
|
|
|
nTotalMatches++;
|
2021-03-17 13:04:04 -05:00
|
|
|
}
|
|
|
|
}
|
2021-04-14 14:16:49 -05:00
|
|
|
|
|
|
|
double arithmeticMean = 0.0;
|
|
|
|
if ( nMatches > 0 ) arithmeticMean = sum / nMatches;
|
|
|
|
|
|
|
|
double harmonicMean = harmonicMeanCalculator.weightedMean();
|
|
|
|
double geometricMean = geometricMeanCalculator.weightedMean();
|
|
|
|
|
|
|
|
RiaLogging::info( QString( "Binning layer #%1: [%2 - %3] n=%4 means: A=%5 H=%6 G=%7" )
|
|
|
|
.arg( layerNo )
|
|
|
|
.arg( binTopDepth )
|
|
|
|
.arg( binBottomDepth )
|
|
|
|
.arg( nMatches )
|
|
|
|
.arg( arithmeticMean )
|
|
|
|
.arg( harmonicMean )
|
|
|
|
.arg( geometricMean ) );
|
|
|
|
|
|
|
|
double mean = std::numeric_limits<double>::infinity();
|
|
|
|
if ( m_adaptiveMeanType() == MeanType::HARMONIC )
|
|
|
|
{
|
|
|
|
mean = harmonicMean;
|
|
|
|
}
|
|
|
|
else if ( m_adaptiveMeanType() == MeanType::ARITHMETIC )
|
|
|
|
{
|
|
|
|
mean = arithmeticMean;
|
|
|
|
}
|
|
|
|
else if ( m_adaptiveMeanType() == MeanType::GEOMETRIC )
|
|
|
|
{
|
|
|
|
mean = geometricMean;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CAF_ASSERT( m_adaptiveMeanType() == MeanType::MINIMUM );
|
|
|
|
mean = minThickness;
|
|
|
|
}
|
|
|
|
|
|
|
|
means.push_back( mean );
|
|
|
|
sumMeans += mean;
|
2021-03-17 13:04:04 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 14:16:49 -05:00
|
|
|
RiaLogging::info( QString( "Total matches: %1 (expected: %2)" ).arg( nTotalMatches ).arg( layers.size() ) );
|
|
|
|
|
|
|
|
double totalThickness = totalDepth;
|
|
|
|
|
|
|
|
std::vector<double> scaledMeans;
|
|
|
|
double sumScaledMean = 0.0;
|
|
|
|
|
|
|
|
for ( double mean : means )
|
|
|
|
{
|
2021-04-21 09:32:07 -05:00
|
|
|
double scaledMean = 0.0;
|
|
|
|
if ( mean != 0.0 ) scaledMean = binSize / mean;
|
2021-04-14 14:16:49 -05:00
|
|
|
scaledMeans.push_back( scaledMean );
|
|
|
|
sumScaledMean += scaledMean;
|
|
|
|
}
|
|
|
|
|
|
|
|
RiaLogging::info( QString( "Total thickness: %1 Sum scaled mean: %2" ).arg( totalThickness ).arg( sumScaledMean ) );
|
|
|
|
std::vector<double> AM;
|
|
|
|
AM.push_back( 0.0 );
|
|
|
|
|
|
|
|
double sumAI = 0.0;
|
|
|
|
for ( int layerNo = 0; layerNo < targetNumLayers; layerNo++ )
|
|
|
|
{
|
|
|
|
double AI = scaledMeans[layerNo] * targetNumLayers / sumScaledMean;
|
|
|
|
sumAI += AI;
|
|
|
|
AM.push_back( sumAI );
|
|
|
|
}
|
|
|
|
|
|
|
|
auto findSmallerIndex = []( double value, const std::vector<double>& vec ) {
|
|
|
|
for ( size_t i = 0; i < vec.size(); i++ )
|
|
|
|
{
|
|
|
|
if ( vec[i] > value ) return i - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vec.size();
|
|
|
|
};
|
|
|
|
|
|
|
|
double prevDepth = baseDepth[0];
|
|
|
|
for ( int layerNo = 0; layerNo < targetNumLayers; layerNo++ )
|
|
|
|
{
|
|
|
|
double ap = layerNo;
|
|
|
|
|
|
|
|
int az = findSmallerIndex( ap, AM );
|
|
|
|
CAF_ASSERT( az >= 0 );
|
|
|
|
CAF_ASSERT( az < static_cast<int>( AM.size() ) );
|
|
|
|
int azNext = az + 1;
|
|
|
|
double ba = AM[az];
|
|
|
|
double bb = AM[azNext];
|
|
|
|
double be = bb - ba;
|
|
|
|
double bc = baseDepth[az];
|
|
|
|
double bd = baseDepth[azNext];
|
|
|
|
double bf = bd - bc;
|
|
|
|
double offset = ( ap - ba ) * bf / be;
|
|
|
|
double as = bc + offset;
|
|
|
|
double av = as - prevDepth;
|
|
|
|
double ay = as - av / 2.0;
|
|
|
|
RiaLogging::info( QString( "Res[%1] = %2 az=%3 ba=%4 bb=%5 bc=%6 av=%7 as=%8 offset=%9 azNext=%10" )
|
|
|
|
.arg( layerNo )
|
|
|
|
.arg( ay )
|
|
|
|
.arg( az )
|
|
|
|
.arg( ba )
|
|
|
|
.arg( bb )
|
|
|
|
.arg( bc )
|
|
|
|
.arg( av )
|
|
|
|
.arg( as )
|
|
|
|
.arg( offset )
|
|
|
|
.arg( azNext ) );
|
|
|
|
|
|
|
|
gridYs.push_back( as );
|
|
|
|
prevDepth = as;
|
|
|
|
}
|
|
|
|
gridYs.push_back( maxY );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimEnsembleFractureStatistics::generateAllLayers(
|
|
|
|
const std::vector<cvf::ref<RigStimPlanFractureDefinition>>& stimPlanFractureDefinitions,
|
|
|
|
std::vector<Layer>& layers )
|
|
|
|
{
|
|
|
|
for ( auto def : stimPlanFractureDefinitions )
|
|
|
|
{
|
|
|
|
double offset = computeDepthOfWellPathAtFracture( def );
|
|
|
|
bool isFirst = true;
|
|
|
|
double topDepth = 0.0;
|
|
|
|
for ( double y : def->ys() )
|
|
|
|
{
|
|
|
|
double depth = offset + y;
|
|
|
|
if ( !isFirst )
|
|
|
|
{
|
|
|
|
double bottomDepth = depth;
|
|
|
|
Layer layer( topDepth, bottomDepth );
|
|
|
|
layers.push_back( layer );
|
|
|
|
}
|
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
topDepth = depth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort( layers.begin(), layers.end(), []( const Layer& a, const Layer& b ) {
|
|
|
|
return a.centerDepth() > b.centerDepth();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
int RimEnsembleFractureStatistics::getTargetNumberOfLayers(
|
|
|
|
const std::vector<cvf::ref<RigStimPlanFractureDefinition>>& stimPlanFractureDefinitions ) const
|
|
|
|
{
|
|
|
|
if ( m_adaptiveSamplingSizeType() == AdaptiveSamplingSizeType::USER_DEFINED ) return m_adaptiveNumSamplesY();
|
|
|
|
|
|
|
|
int maxNy = 0;
|
|
|
|
int minNy = std::numeric_limits<int>::max();
|
|
|
|
int sum = 0;
|
|
|
|
for ( auto def : stimPlanFractureDefinitions )
|
|
|
|
{
|
|
|
|
int ny = static_cast<int>( def->ys().size() );
|
|
|
|
maxNy = std::max( maxNy, ny );
|
|
|
|
minNy = std::min( minNy, ny );
|
|
|
|
sum += ny;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_adaptiveSamplingSizeType() == AdaptiveSamplingSizeType::MAXIMUM )
|
|
|
|
return maxNy;
|
|
|
|
else if ( m_adaptiveSamplingSizeType() == AdaptiveSamplingSizeType::MINIMUM )
|
|
|
|
return minNy;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CAF_ASSERT( m_adaptiveSamplingSizeType() == AdaptiveSamplingSizeType::AVERAGE );
|
|
|
|
return static_cast<int>( std::ceil( static_cast<double>( sum ) / stimPlanFractureDefinitions.size() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
double RimEnsembleFractureStatistics::linearSampling( double minValue,
|
|
|
|
double maxValue,
|
|
|
|
int numSamples,
|
|
|
|
std::vector<double>& samples )
|
|
|
|
{
|
|
|
|
double sampleDistance = ( maxValue - minValue ) / numSamples;
|
|
|
|
|
|
|
|
for ( int s = 0; s < numSamples; s++ )
|
|
|
|
{
|
|
|
|
double pos = minValue + s * sampleDistance + sampleDistance * 0.5;
|
|
|
|
samples.push_back( pos );
|
|
|
|
}
|
|
|
|
|
|
|
|
return sampleDistance;
|
2021-03-17 13:04:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
bool RimEnsembleFractureStatistics::isCoordinateInsideFractureCell( double x, double y, const RigFractureCell& cell )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
|
|
|
const cvf::Vec3d& minPoint = cell.getPolygon()[0];
|
|
|
|
const cvf::Vec3d& maxPoint = cell.getPolygon()[2];
|
|
|
|
// TODO: Investigate strange ordering for y coords.
|
|
|
|
return ( x > minPoint.x() && x <= maxPoint.x() && y <= minPoint.y() && y > maxPoint.y() );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
double RimEnsembleFractureStatistics::computeDepthOfWellPathAtFracture(
|
2021-03-17 13:04:04 -05:00
|
|
|
cvf::ref<RigStimPlanFractureDefinition> stimPlanFractureDefinitionData )
|
|
|
|
{
|
|
|
|
double firstTvd = stimPlanFractureDefinitionData->topPerfTvd();
|
|
|
|
double lastTvd = stimPlanFractureDefinitionData->bottomPerfTvd();
|
|
|
|
|
|
|
|
if ( firstTvd != HUGE_VAL && lastTvd != HUGE_VAL )
|
|
|
|
{
|
|
|
|
return ( firstTvd + lastTvd ) / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
firstTvd = stimPlanFractureDefinitionData->minDepth();
|
|
|
|
lastTvd = stimPlanFractureDefinitionData->maxDepth();
|
|
|
|
return ( firstTvd + lastTvd ) / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
void RimEnsembleFractureStatistics::sampleAllGrids( const std::vector<cvf::cref<RigFractureGrid>>& fractureGrids,
|
2021-04-14 09:16:06 -05:00
|
|
|
const std::vector<double>& samplesX,
|
|
|
|
const std::vector<double>& samplesY,
|
|
|
|
std::vector<std::vector<double>>& samples )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
2021-04-14 09:16:06 -05:00
|
|
|
for ( size_t y = 0; y < samplesY.size(); y++ )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
2021-04-14 09:16:06 -05:00
|
|
|
for ( size_t x = 0; x < samplesX.size(); x++ )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
2021-04-14 09:16:06 -05:00
|
|
|
double posX = samplesX[x];
|
|
|
|
double posY = samplesY[y];
|
2021-03-17 13:04:04 -05:00
|
|
|
|
|
|
|
for ( auto fractureGrid : fractureGrids )
|
|
|
|
{
|
|
|
|
for ( auto fractureCell : fractureGrid->fractureCells() )
|
|
|
|
{
|
|
|
|
if ( isCoordinateInsideFractureCell( posX, posY, fractureCell ) )
|
|
|
|
{
|
2021-04-21 09:32:07 -05:00
|
|
|
size_t idx = y * samplesX.size() + x;
|
|
|
|
double value = fractureCell.getConductivityValue();
|
|
|
|
if ( std::isinf( value ) ) value = 0.0;
|
|
|
|
samples[idx].push_back( value );
|
2021-03-17 13:04:04 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
bool RimEnsembleFractureStatistics::writeStatisticsToCsv( const QString& filePath, const RigSlice2D& samples )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
|
|
|
QFile data( filePath );
|
|
|
|
if ( !data.open( QFile::WriteOnly | QFile::Truncate ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream stream( &data );
|
|
|
|
QString fieldSeparator = RiaPreferences::current()->csvTextExportFieldSeparator;
|
|
|
|
RifCsvDataTableFormatter formatter( stream, fieldSeparator );
|
|
|
|
|
|
|
|
std::vector<RifTextDataTableColumn> header;
|
|
|
|
for ( size_t y = 0; y < samples.ny(); y++ )
|
|
|
|
header.push_back( RifTextDataTableColumn( "", RifTextDataTableDoubleFormat::RIF_FLOAT ) );
|
|
|
|
formatter.header( header );
|
|
|
|
|
|
|
|
for ( size_t y = 0; y < samples.ny(); y++ )
|
|
|
|
{
|
|
|
|
for ( size_t x = 0; x < samples.nx(); x++ )
|
|
|
|
{
|
|
|
|
formatter.add( samples.getValue( x, y ) );
|
|
|
|
}
|
|
|
|
formatter.rowCompleted();
|
|
|
|
}
|
|
|
|
formatter.tableCompleted();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-09 06:08:35 -05:00
|
|
|
void RimEnsembleFractureStatistics::generateStatisticsGrids(
|
|
|
|
const std::vector<std::vector<double>>& samples,
|
2021-04-14 09:16:06 -05:00
|
|
|
size_t numSamplesX,
|
|
|
|
size_t numSamplesY,
|
2021-04-09 11:56:57 -05:00
|
|
|
std::map<RimEnsembleFractureStatistics::StatisticsType, std::shared_ptr<RigSlice2D>>& statisticsGrids,
|
|
|
|
const std::vector<caf::AppEnum<RimEnsembleFractureStatistics::StatisticsType>>& statisticsTypes )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
2021-04-09 11:56:57 -05:00
|
|
|
for ( auto t : statisticsTypes )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
|
|
|
std::shared_ptr<RigSlice2D> grid = std::make_shared<RigSlice2D>( numSamplesX, numSamplesY );
|
2021-04-09 11:56:57 -05:00
|
|
|
statisticsGrids[t.value()] = grid;
|
2021-03-17 13:04:04 -05:00
|
|
|
}
|
|
|
|
|
2021-04-09 11:56:57 -05:00
|
|
|
auto isCalculationEnabled = []( StatisticsType t, auto statisticsTypes ) {
|
|
|
|
return std::find( statisticsTypes.begin(), statisticsTypes.end(), t ) != statisticsTypes.end();
|
|
|
|
};
|
|
|
|
|
|
|
|
bool calculateMin = isCalculationEnabled( StatisticsType::MIN, statisticsTypes );
|
|
|
|
bool calculateMax = isCalculationEnabled( StatisticsType::MAX, statisticsTypes );
|
|
|
|
bool calculateMean = isCalculationEnabled( StatisticsType::MEAN, statisticsTypes );
|
|
|
|
bool calculateP10 = isCalculationEnabled( StatisticsType::P10, statisticsTypes );
|
|
|
|
bool calculateP50 = isCalculationEnabled( StatisticsType::P50, statisticsTypes );
|
|
|
|
bool calculateP90 = isCalculationEnabled( StatisticsType::P90, statisticsTypes );
|
|
|
|
bool calculateOccurrence = isCalculationEnabled( StatisticsType::OCCURRENCE, statisticsTypes );
|
|
|
|
|
2021-04-21 09:32:07 -05:00
|
|
|
auto setValueNoInf = []( std::shared_ptr<RigSlice2D>& grid, size_t x, size_t y, double value ) {
|
|
|
|
// Guard against inf (happens in the regions not covered by any mesh)
|
|
|
|
if ( std::isinf( value ) ) value = 0.0;
|
|
|
|
grid->setValue( x, y, value );
|
|
|
|
};
|
|
|
|
|
2021-04-14 09:16:06 -05:00
|
|
|
for ( size_t y = 0; y < numSamplesY; y++ )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
2021-04-14 09:16:06 -05:00
|
|
|
for ( size_t x = 0; x < numSamplesX; x++ )
|
2021-03-17 13:04:04 -05:00
|
|
|
{
|
|
|
|
size_t idx = y * numSamplesX + x;
|
2021-04-09 11:56:57 -05:00
|
|
|
|
|
|
|
if ( calculateMin || calculateMax || calculateMean )
|
|
|
|
{
|
|
|
|
double min;
|
|
|
|
double max;
|
|
|
|
double sum;
|
|
|
|
double range;
|
|
|
|
double mean;
|
|
|
|
double dev;
|
|
|
|
RigStatisticsMath::calculateBasicStatistics( samples[idx], &min, &max, &sum, &range, &mean, &dev );
|
|
|
|
|
|
|
|
if ( calculateMean )
|
2021-04-21 09:32:07 -05:00
|
|
|
setValueNoInf( statisticsGrids[RimEnsembleFractureStatistics::StatisticsType::MEAN], x, y, mean );
|
2021-04-09 11:56:57 -05:00
|
|
|
|
|
|
|
if ( calculateMin )
|
2021-04-21 09:32:07 -05:00
|
|
|
setValueNoInf( statisticsGrids[RimEnsembleFractureStatistics::StatisticsType::MIN], x, y, min );
|
2021-04-09 11:56:57 -05:00
|
|
|
|
|
|
|
if ( calculateMax )
|
2021-04-21 09:32:07 -05:00
|
|
|
setValueNoInf( statisticsGrids[RimEnsembleFractureStatistics::StatisticsType::MAX], x, y, max );
|
2021-04-09 11:56:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( calculateP10 || calculateP50 || calculateP90 )
|
|
|
|
{
|
|
|
|
double p10;
|
|
|
|
double p50;
|
|
|
|
double p90;
|
|
|
|
double mean;
|
|
|
|
RigStatisticsMath::calculateStatisticsCurves( samples[idx], &p10, &p50, &p90, &mean );
|
|
|
|
|
|
|
|
if ( calculateP10 )
|
2021-04-21 09:32:07 -05:00
|
|
|
setValueNoInf( statisticsGrids[RimEnsembleFractureStatistics::StatisticsType::P10], x, y, p10 );
|
2021-04-09 11:56:57 -05:00
|
|
|
|
|
|
|
if ( calculateP50 )
|
2021-04-21 09:32:07 -05:00
|
|
|
setValueNoInf( statisticsGrids[RimEnsembleFractureStatistics::StatisticsType::P50], x, y, p50 );
|
2021-04-09 11:56:57 -05:00
|
|
|
|
|
|
|
if ( calculateP90 )
|
2021-04-21 09:32:07 -05:00
|
|
|
setValueNoInf( statisticsGrids[RimEnsembleFractureStatistics::StatisticsType::P90], x, y, p90 );
|
2021-04-09 11:56:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( calculateOccurrence )
|
|
|
|
{
|
|
|
|
statisticsGrids[RimEnsembleFractureStatistics::StatisticsType::OCCURRENCE]->setValue( x,
|
|
|
|
y,
|
|
|
|
samples[idx].size() );
|
|
|
|
}
|
2021-03-17 13:04:04 -05:00
|
|
|
}
|
|
|
|
}
|
2021-03-15 10:23:57 -05:00
|
|
|
}
|