ResInsight/ApplicationLibCode/CommandFileInterface/RicfCreateMultipleFractures.cpp

189 lines
7.6 KiB
C++
Raw Normal View History

2018-08-22 04:23:02 -05:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
2018-08-22 04:23:02 -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-22 04:23:02 -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.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
2018-08-22 04:23:02 -05:00
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicfCreateMultipleFractures.h"
#include "RicfApplicationTools.h"
2018-08-22 04:23:02 -05:00
#include "RicfCommandFileExecutor.h"
#include "FractureCommands/RicCreateMultipleFracturesFeature.h"
#include "FractureCommands/RicCreateMultipleFracturesOptionItemUi.h"
#include "FractureCommands/RicCreateMultipleFracturesUi.h"
#include "RimDialogData.h"
#include "RimEclipseCase.h"
#include "RimEclipseCaseCollection.h"
#include "RimFractureTemplate.h"
#include "RimOilField.h"
#include "RimProject.h"
2018-08-22 04:23:02 -05:00
#include "RimWellPath.h"
#include "RiaLogging.h"
#include "RiaWellNameComparer.h"
#include "cafCmdFeatureManager.h"
#include "cafPdmFieldScriptingCapability.h"
2018-08-22 04:23:02 -05:00
CAF_PDM_SOURCE_INIT( RicfCreateMultipleFractures, "createMultipleFractures" );
2018-08-22 04:23:02 -05:00
2018-08-22 04:43:35 -05:00
namespace caf
2018-08-22 04:23:02 -05:00
{
template <>
void AppEnum<MultipleFractures::Action>::setUp()
{
2020-04-24 01:22:32 -05:00
addItem( MultipleFractures::Action::APPEND_FRACTURES, "APPEND_FRACTURES", "Append Fractures" );
addItem( MultipleFractures::Action::REPLACE_FRACTURES, "REPLACE_FRACTURES", "Replace Fractures" );
2018-08-22 04:23:02 -05:00
2020-04-24 01:22:32 -05:00
setDefault( MultipleFractures::Action::NONE );
2018-08-22 04:23:02 -05:00
}
} // namespace caf
2018-08-22 04:23:02 -05:00
//--------------------------------------------------------------------------------------------------
///
2018-08-22 04:23:02 -05:00
//--------------------------------------------------------------------------------------------------
RicfCreateMultipleFractures::RicfCreateMultipleFractures()
{
CAF_PDM_InitScriptableField( &m_caseId, "caseId", -1, "Case ID" );
CAF_PDM_InitScriptableField( &m_wellPathNames, "wellPathNames", std::vector<QString>(), "Well Path Names" );
CAF_PDM_InitScriptableField( &m_minDistFromWellTd, "minDistFromWellTd", 100.0, "Min Distance From Well TD" );
CAF_PDM_InitScriptableField( &m_maxFracturesPerWell, "maxFracturesPerWell", 100, "Max Fractures per Well" );
CAF_PDM_InitScriptableField( &m_templateId, "templateId", -1, "Template ID" );
CAF_PDM_InitScriptableField( &m_topLayer, "topLayer", -1, "Top Layer" );
CAF_PDM_InitScriptableField( &m_baseLayer, "baseLayer", -1, "Base Layer" );
CAF_PDM_InitScriptableField( &m_spacing, "spacing", 300.0, "Spacing" );
CAF_PDM_InitScriptableField( &m_action,
"action",
caf::AppEnum<MultipleFractures::Action>( MultipleFractures::Action::APPEND_FRACTURES ),
"Action" );
2018-08-22 04:23:02 -05:00
}
//--------------------------------------------------------------------------------------------------
///
2018-08-22 04:23:02 -05:00
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicfCreateMultipleFractures::execute()
2018-08-22 04:23:02 -05:00
{
using TOOLS = RicfApplicationTools;
RimProject* project = RimProject::current();
2018-08-22 04:23:02 -05:00
RiuCreateMultipleFractionsUi* settings = project->dialogData()->multipleFractionsData();
// Get case and fracture template
auto gridCase = TOOLS::caseFromId( m_caseId );
auto fractureTemplate = fractureTemplateFromId( m_templateId );
std::vector<RimWellPath*> wellPaths;
// Find well paths
{
QStringList wellsNotFound;
wellPaths = TOOLS::wellPathsFromNames( TOOLS::toQStringList( m_wellPathNames ), &wellsNotFound );
if ( !wellsNotFound.empty() )
{
QString error = QString( "createMultipleFractures: These well paths were not found: %1" ).arg( wellsNotFound.join( ", " ) );
RiaLogging::error( error );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
}
}
if ( !gridCase )
{
QString error = QString( "createMultipleFractures: Could not find case with ID %1" ).arg( m_caseId );
RiaLogging::error( error );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
}
if ( !fractureTemplate )
{
QString error = QString( "createMultipleFractures: Could not find fracture template with ID %1" ).arg( m_templateId );
RiaLogging::error( error );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
}
2018-08-22 04:23:02 -05:00
if ( wellPaths.empty() )
2018-08-22 04:23:02 -05:00
{
QString error( "createMultipleFractures: No wellpaths found" );
RiaLogging::error( error );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
}
2018-08-22 04:23:02 -05:00
if ( !validateArguments() )
{
QString error( "createMultipleFractures: Mandatory argument(s) missing" );
RiaLogging::error( error );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
}
RicCreateMultipleFracturesOptionItemUi* options = new RicCreateMultipleFracturesOptionItemUi();
caf::CmdFeatureManager* commandManager = caf::CmdFeatureManager::instance();
auto feature =
dynamic_cast<RicCreateMultipleFracturesFeature*>( commandManager->getCommandFeature( "RicCreateMultipleFracturesFeature" ) );
2018-08-22 04:23:02 -05:00
// Default layers
int topLayer = m_topLayer;
int baseLayer = m_baseLayer;
if ( feature && ( topLayer < 0 || baseLayer < 0 ) )
{
auto ijkRange = feature->ijkRangeForGrid( gridCase );
if ( topLayer < 0 ) topLayer = static_cast<int>( ijkRange.first.z() );
if ( baseLayer < 0 ) baseLayer = static_cast<int>( ijkRange.second.z() );
}
options->setValues( topLayer, baseLayer, fractureTemplate, m_spacing );
settings->clearWellPaths();
for ( auto wellPath : wellPaths )
{
settings->addWellPath( wellPath );
}
2018-08-22 04:23:02 -05:00
settings->setValues( gridCase, m_minDistFromWellTd, m_maxFracturesPerWell );
settings->clearOptions();
settings->insertOptionItem( nullptr, options );
2018-08-22 04:23:02 -05:00
if ( feature )
{
2020-04-24 01:22:32 -05:00
if ( m_action == MultipleFractures::Action::APPEND_FRACTURES ) feature->appendFractures();
if ( m_action == MultipleFractures::Action::REPLACE_FRACTURES ) feature->replaceFractures();
2018-08-22 04:23:02 -05:00
}
return caf::PdmScriptResponse();
2018-08-22 04:23:02 -05:00
}
//--------------------------------------------------------------------------------------------------
///
2018-08-22 04:23:02 -05:00
//--------------------------------------------------------------------------------------------------
bool RicfCreateMultipleFractures::validateArguments() const
{
bool valid = m_caseId >= 0 && m_templateId >= 0;
2018-08-22 04:23:02 -05:00
if ( valid ) return true;
2018-08-22 04:23:02 -05:00
return false;
}
//--------------------------------------------------------------------------------------------------
///
2018-08-22 04:23:02 -05:00
//--------------------------------------------------------------------------------------------------
RimFractureTemplate* RicfCreateMultipleFractures::fractureTemplateFromId( int templateId ) const
2018-08-22 04:23:02 -05:00
{
for ( RimFractureTemplate* t : RimProject::current()->allFractureTemplates() )
2018-08-22 04:23:02 -05:00
{
if ( t->id() == templateId ) return t;
2018-08-22 04:23:02 -05:00
}
RiaLogging::error( QString( "createMultipleFractures: Could not find fracture template with ID %1" ).arg( templateId ) );
2018-08-22 04:23:02 -05:00
return nullptr;
}