diff --git a/ApplicationLibCode/CommandFileInterface/RicfExportLgrForCompletions.cpp b/ApplicationLibCode/CommandFileInterface/RicfExportLgrForCompletions.cpp index 29f655e162..ada401f11f 100644 --- a/ApplicationLibCode/CommandFileInterface/RicfExportLgrForCompletions.cpp +++ b/ApplicationLibCode/CommandFileInterface/RicfExportLgrForCompletions.cpp @@ -18,22 +18,15 @@ #include "RicfExportLgrForCompletions.h" +#include "RiaApplication.h" + #include "RicfApplicationTools.h" #include "RicfCommandFileExecutor.h" +#include "RicfCommandForwarding.h" -#include "ExportCommands/RicExportLgrFeature.h" - -#include "RimDialogData.h" #include "RimEclipseCase.h" -#include "RimEclipseCaseCollection.h" -#include "RimFractureTemplate.h" -#include "RimOilField.h" -#include "RimProject.h" #include "RimWellPath.h" - -#include "RiaApplication.h" -#include "RiaLogging.h" -#include "RiaWellNameComparer.h" +#include "RimcEclipseCase.h" #include "cafPdmFieldScriptingCapability.h" @@ -60,63 +53,49 @@ RicfExportLgrForCompletions::RicfExportLgrForCompletions() //-------------------------------------------------------------------------------------------------- caf::PdmScriptResponse RicfExportLgrForCompletions::execute() { - using TOOLS = RicfApplicationTools; + const QString commandName = classKeyword(); - std::vector wellPaths; - - // Find well paths + QStringList wellsNotFound; + std::vector wellPaths = + RicfApplicationTools::wellPathsFromNames( RicfApplicationTools::toQStringList( m_wellPathNames ), &wellsNotFound ); + if ( !wellsNotFound.empty() ) { - QStringList wellsNotFound; - wellPaths = TOOLS::wellPathsFromNames( TOOLS::toQStringList( m_wellPathNames ), &wellsNotFound ); - if ( !wellsNotFound.empty() ) - { - QString error( QString( "exportLgrForCompletions: These well paths were not found: " ) + wellsNotFound.join( ", " ) ); - RiaLogging::error( error.toStdString() ); - return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error ); - } - } - - if ( wellPaths.empty() ) - { - QString error( "exportLgrForCompletions: Could not find any well paths" ); - RiaLogging::error( error.toStdString() ); - return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error ); + return RicfForwarding::errorResponse( "These well paths were not found: " + wellsNotFound.join( ", " ), commandName ); + } + if ( wellPaths.empty() ) return RicfForwarding::errorResponse( "Could not find any well paths", commandName ); + + auto rimCase = RicfForwarding::findCase( m_caseId() ); + if ( !rimCase ) return RicfForwarding::errorResponse( rimCase.error(), commandName ); + + auto* eclipseCase = dynamic_cast( rimCase.value() ); + if ( !eclipseCase ) + { + return RicfForwarding::errorResponse( QString( "Case with ID %1 is not an Eclipse case" ).arg( m_caseId() ), commandName ); } + // Resolve the export folder from the command file executor state. The Rimc method requires an explicit folder. QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath( RicfCommandFileExecutor::ExportType::LGRS ); if ( exportFolder.isNull() ) { exportFolder = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath( "LGR" ); } - RimEclipseCase* eclipseCase = TOOLS::caseFromId( m_caseId() ); - if ( !eclipseCase ) - { - QString error( QString( "exportLgrForCompletions: Could not find case with ID %1" ).arg( m_caseId() ) ); - RiaLogging::error( error.toStdString() ); - return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error ); - } + RimEclipseCase_exportLgrForCompletions method( eclipseCase ); + method.setWellPaths( wellPaths ); + method.setTimeStep( m_timeStep() ); + method.setExportFolder( exportFolder ); + method.setRefinement( m_refinementI(), m_refinementJ(), m_refinementK() ); + method.setSplitType( m_splitType() ); - cvf::Vec3st lgrCellCounts( m_refinementI, m_refinementJ, m_refinementK ); - QStringList wellsIntersectingOtherLgrs; - - RicExportLgrFeature::exportLgrsForWellPaths( exportFolder, - wellPaths, - eclipseCase, - m_timeStep, - lgrCellCounts, - m_splitType(), - { RigCompletionData::CompletionType::PERFORATION, - RigCompletionData::CompletionType::FRACTURE, - RigCompletionData::CompletionType::FISHBONES }, - &wellsIntersectingOtherLgrs ); + auto result = method.execute(); + if ( !result ) return RicfForwarding::errorResponse( result.error(), commandName ); caf::PdmScriptResponse response; - if ( !wellsIntersectingOtherLgrs.empty() ) + if ( !method.wellsIntersectingOtherLgrs().empty() ) { - auto wellsList = wellsIntersectingOtherLgrs.join( ", " ); - QString warning( "exportLgrForCompletions: No export for some wells due to existing intersecting LGR(s).Affected wells : " + wellsList ); - RiaLogging::warning( warning.toStdString() ); + QString warning = QString( "%1: No export for some wells due to existing intersecting LGR(s). Affected wells: %2" ) + .arg( commandName ) + .arg( method.wellsIntersectingOtherLgrs().join( ", " ) ); response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, warning ); } return response; diff --git a/GrpcInterface/Python/rips/tests/test_commands.py b/GrpcInterface/Python/rips/tests/test_commands.py index fde5a1c08c..951971fcff 100644 --- a/GrpcInterface/Python/rips/tests/test_commands.py +++ b/GrpcInterface/Python/rips/tests/test_commands.py @@ -1,5 +1,7 @@ import sys import os +import pytest +import tempfile sys.path.insert(1, os.path.join(sys.path[0], "../../")) @@ -30,6 +32,48 @@ def test_create_lgr_well(rips_instance, initialize_test): assert len(case.grids()) == 3 +def test_create_and_export_lgr_for_completions(rips_instance, initialize_test): + case = rips_instance.project.load_case( + dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID" + ) + assert len(case.grids()) == 2 + + well_files = [dataroot.PATH + "/TEST10K_FLT_LGR_NNC/wellpath_a.dev"] + rips_instance.project.import_well_paths(well_path_files=well_files) + well_path = rips_instance.project.well_path_by_name("Well Path A") + assert well_path is not None + + case.create_lgr_for_completions( + well_paths=[well_path], + time_step=5, + refinement_i=2, + refinement_j=3, + refinement_k=1, + split_type=rips.LgrSplitType.LGR_PER_WELL, + ) + assert len(case.grids()) == 3 + + with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname: + case.export_lgr_for_completions( + well_paths=[well_path], + time_step=5, + export_folder=tmpdirname, + refinement_i=2, + refinement_j=2, + refinement_k=2, + split_type=rips.LgrSplitType.LGR_PER_WELL, + ) + files = os.listdir(tmpdirname) + assert len(files) == 1 + with open(os.path.join(tmpdirname, files[0])) as f: + assert "CARFIN" in f.read() + + with pytest.raises(rips.RipsError): + case.create_lgr_for_completions(well_paths=[], time_step=0) + with pytest.raises(rips.RipsError): + case.export_lgr_for_completions(well_paths=[well_path], time_step=0) + + def test_create_multiple_fractures(rips_instance, initialize_test): case = rips_instance.project.load_case( dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"