Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fault reactivation export steps #10653

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <QAction>
#include <QFile>
#include <QMessageBox>
#include <QString>

CAF_CMD_SOURCE_INIT( RicExportInpFileFeature, "RicExportInpFileFeature" );
Expand All @@ -47,8 +48,16 @@ void RicExportInpFileFeature::onActionTriggered( bool isChecked )
auto faultReactivationModel = caf::SelectionManager::instance()->selectedItemOfType<RimFaultReactivationModel>();
if ( faultReactivationModel )
{
QString exportFile = faultReactivationModel->baseDir() + "/faultreactivation.inp";
RifFaultReactivationModelExporter::exportToFile( exportFile.toStdString(), *faultReactivationModel );
QString exportFile = faultReactivationModel->baseDir() + "/faultreactivation.inp";
auto [isOk, errorMessage] = RifFaultReactivationModelExporter::exportToFile( exportFile.toStdString(), *faultReactivationModel );
if ( !isOk )
{
const QString frmTitle( "Fault Reactivation Modeling" );

QString outErrorText =
QString( "Failed to export INP model to file %1.\n\n%2" ).arg( exportFile ).arg( QString::fromStdString( errorMessage ) );
QMessageBox::critical( nullptr, frmTitle, outErrorText );
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,25 @@ std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToStream(

auto model = rimModel.model();
CAF_ASSERT( !model.isNull() );
printHeading( stream, applicationNameAndVersion );
printParts( stream, *model, partNames, borders, faces, boundaries, rimModel.localCoordSysNormalsXY() );
printAssembly( stream, *model, partNames );
printMaterials( stream );
printInteractionProperties( stream, faultFriction );
printBoundaryConditions( stream, *model, partNames, boundaries );
printPredefinedFields( stream, partNames );
printInteractions( stream, partNames, borders );
printSteps( stream, partNames );

// TODO: improve error handling

std::vector<std::function<std::pair<bool, std::string>()>> methods = {
[&]() { return printHeading( stream, applicationNameAndVersion ); },
[&]() { return printParts( stream, *model, partNames, borders, faces, boundaries, rimModel.localCoordSysNormalsXY() ); },
[&]() { return printAssembly( stream, *model, partNames ); },
[&]() { return printMaterials( stream ); },
[&]() { return printInteractionProperties( stream, faultFriction ); },
[&]() { return printBoundaryConditions( stream, *model, partNames, boundaries ); },
[&]() { return printPredefinedFields( stream, partNames ); },
[&]() { return printInteractions( stream, partNames, borders ); },
[&]() { return printSteps( stream, partNames, rimModel.selectedTimeSteps() ); },
};

for ( auto method : methods )
{
auto [isOk, errorMessage] = method();
if ( !isOk ) return { false, errorMessage };
}

return { true, "" };
}

Expand Down Expand Up @@ -184,6 +192,8 @@ std::pair<bool, std::string> RifFaultReactivationModelExporter::printParts(

RifInpExportTools::printLine( stream, "," );
RifInpExportTools::printHeading( stream, "End Part" );

if ( !stream.good() ) return { false, "Failed to write part " + partName + " to fault reactivation INP." };
}

return { true, "" };
Expand Down Expand Up @@ -367,16 +377,19 @@ std::pair<bool, std::string>
//--------------------------------------------------------------------------------------------------
std::pair<bool, std::string>
RifFaultReactivationModelExporter::printSteps( std::ostream& stream,
const std::map<RigFaultReactivationModel::GridPart, std::string>& partNames )
const std::map<RigFaultReactivationModel::GridPart, std::string>& partNames,
const std::vector<QDateTime>& timeSteps )
{
int numSteps = 2;
// First time step has to be selected in order to export currently
if ( timeSteps.size() < 2 ) return { false, "Failed to export fault reactivation INP: needs at least two time steps." };

kriben marked this conversation as resolved.
Show resolved Hide resolved
for ( int i = 0; i < numSteps; i++ )
for ( int i = 0; i < static_cast<int>( timeSteps.size() ); i++ )
{
std::string stepNum = std::to_string( i + 1 );
std::string stepName = "Step-" + stepNum;
RifInpExportTools::printComment( stream, "----------------------------------------------------------------" );
RifInpExportTools::printSectionComment( stream, "STEP: " + stepName );
RifInpExportTools::printComment( stream, "Time step: " + timeSteps[i].toString().toStdString() );

RifInpExportTools::printHeading( stream, "Step, name=" + stepName + ", nlgeom=NO" );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class RifFaultReactivationModelExporter
static std::pair<bool, std::string> printPredefinedFields( std::ostream& stream,
const std::map<RigFaultReactivationModel::GridPart, std::string>& partNames );
static std::pair<bool, std::string> printSteps( std::ostream& stream,
const std::map<RigFaultReactivationModel::GridPart, std::string>& partNames );
const std::map<RigFaultReactivationModel::GridPart, std::string>& partNames,
const std::vector<QDateTime>& timeSteps );

static std::pair<bool, std::string> printInteractions( std::ostream& stream,
const std::map<RigFaultReactivationModel::GridPart, std::string>& partNames,
const std::vector<std::pair<RigGriddedPart3d::BorderSurface, std::string>>& borders );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,16 @@ std::vector<QDateTime> RimFaultReactivationModel::selectedTimeSteps() const
return m_selectedTimeSteps();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFaultReactivationModel::isFirstTimeStepsSelected() const
{
if ( m_availableTimeSteps.empty() || selectedTimeSteps().empty() ) return false;

return m_availableTimeSteps.front() == selectedTimeSteps().front();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class RimFaultReactivationModel : public RimCheckableNamedObject, public RimPoly
void setBaseDir( QString path );

std::vector<QDateTime> selectedTimeSteps() const;
bool isFirstTimeStepsSelected() const;

QStringList commandParameters() const;

Expand Down