mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Refactor: Split INP exporter into parts.
This commit is contained in:
@@ -33,29 +33,83 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToStream( std::ostream& stream, const RigFaultReactivationModel& model )
|
||||
{
|
||||
RifInpExportTools::printHeading( stream, "Heading" );
|
||||
RifInpExportTools::printComment( stream, std::string( "Generated by: " ).append( STRPRODUCTVER ) );
|
||||
std::string applicationNameAndVersion = STRPRODUCTVER;
|
||||
|
||||
RifInpExportTools::printHeading( stream, "Preprint, echo=NO, model=NO, history=NO, contact=NO" );
|
||||
using PartBorderSurface = RigGriddedPart3d::BorderSurface;
|
||||
std::vector<std::pair<PartBorderSurface, std::string>> borders = { { PartBorderSurface::UpperSurface, "top" },
|
||||
{ PartBorderSurface::FaultSurface, "fault" },
|
||||
{ PartBorderSurface::LowerSurface, "base" } };
|
||||
|
||||
using FaultGridPart = RigFaultReactivationModel::GridPart;
|
||||
std::map<std::pair<FaultGridPart, PartBorderSurface>, int> faces = { { { FaultGridPart::PART1, PartBorderSurface::FaultSurface }, 4 },
|
||||
{ { FaultGridPart::PART1, PartBorderSurface::UpperSurface }, 4 },
|
||||
{ { FaultGridPart::PART1, PartBorderSurface::LowerSurface }, 4 },
|
||||
{ { FaultGridPart::PART2, PartBorderSurface::FaultSurface }, 6 },
|
||||
{ { FaultGridPart::PART2, PartBorderSurface::UpperSurface }, 6 },
|
||||
{ { FaultGridPart::PART2, PartBorderSurface::LowerSurface }, 6 } };
|
||||
|
||||
std::map<RigGriddedPart3d::Boundary, std::string> boundaries = {
|
||||
{ RigGriddedPart3d::Boundary::Bottom, "bottom" },
|
||||
{ RigGriddedPart3d::Boundary::Back, "back" },
|
||||
{ RigGriddedPart3d::Boundary::Front, "front" },
|
||||
{ RigGriddedPart3d::Boundary::FarSide, "farside" },
|
||||
};
|
||||
|
||||
double faultFriction = 0.0;
|
||||
|
||||
printHeading( stream, applicationNameAndVersion );
|
||||
printParts( stream, model, borders, faces );
|
||||
printAssembly( stream, model, boundaries );
|
||||
printMaterials( stream );
|
||||
printInteractionProperties( stream, faultFriction );
|
||||
printBoundaryConditions( stream, boundaries );
|
||||
printPredefinedFields( stream );
|
||||
printInteractions( stream, borders );
|
||||
printSteps( stream );
|
||||
|
||||
// TODO: improve error handling
|
||||
return { true, "" };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToFile( const std::string& filePath,
|
||||
const RigFaultReactivationModel& model )
|
||||
{
|
||||
std::ofstream stream( filePath );
|
||||
return exportToStream( stream, model );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::string> RifFaultReactivationModelExporter::printHeading( std::ostream& stream, const std::string& applicationNameAndVersion )
|
||||
{
|
||||
if ( RifInpExportTools::printHeading( stream, "Heading" ) &&
|
||||
RifInpExportTools::printComment( stream, std::string( "Generated by: " ).append( applicationNameAndVersion ) ) &&
|
||||
RifInpExportTools::printHeading( stream, "Preprint, echo=NO, model=NO, history=NO, contact=NO" ) )
|
||||
{
|
||||
return { true, "" };
|
||||
}
|
||||
|
||||
return { false, "Failed to write header to fault reactivation INP." };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::string> RifFaultReactivationModelExporter::printParts(
|
||||
std::ostream& stream,
|
||||
const RigFaultReactivationModel& model,
|
||||
const std::vector<std::pair<RigGriddedPart3d::BorderSurface, std::string>>& borders,
|
||||
const std::map<std::pair<RigFaultReactivationModel::GridPart, RigGriddedPart3d::BorderSurface>, int>& faces )
|
||||
{
|
||||
RifInpExportTools::printSectionComment( stream, "PARTS" );
|
||||
|
||||
auto parts = model.allGridParts();
|
||||
|
||||
std::vector<std::pair<RigGriddedPart3d::BorderSurface, std::string>> borders = { { RigGriddedPart3d::BorderSurface::UpperSurface, "top" },
|
||||
{ RigGriddedPart3d::BorderSurface::FaultSurface, "fault" },
|
||||
{ RigGriddedPart3d::BorderSurface::LowerSurface, "base" } };
|
||||
|
||||
std::map<std::pair<RigFaultReactivationModel::GridPart, RigGriddedPart3d::BorderSurface>, int> faces =
|
||||
{ { { RigFaultReactivationModel::GridPart::PART1, RigGriddedPart3d::BorderSurface::FaultSurface }, 4 },
|
||||
{ { RigFaultReactivationModel::GridPart::PART1, RigGriddedPart3d::BorderSurface::UpperSurface }, 4 },
|
||||
{ { RigFaultReactivationModel::GridPart::PART1, RigGriddedPart3d::BorderSurface::LowerSurface }, 4 },
|
||||
{ { RigFaultReactivationModel::GridPart::PART2, RigGriddedPart3d::BorderSurface::FaultSurface }, 6 },
|
||||
{ { RigFaultReactivationModel::GridPart::PART2, RigGriddedPart3d::BorderSurface::UpperSurface }, 6 },
|
||||
{ { RigFaultReactivationModel::GridPart::PART2, RigGriddedPart3d::BorderSurface::LowerSurface }, 6 } };
|
||||
|
||||
int partIndex = 1;
|
||||
for ( auto part : parts )
|
||||
auto parts = model.allGridParts();
|
||||
int partIndex = 1;
|
||||
for ( const auto& part : parts )
|
||||
{
|
||||
std::string partNameHeading = "Part-" + std::to_string( partIndex );
|
||||
RifInpExportTools::printHeading( stream, "Part, name=" + partNameHeading );
|
||||
@@ -76,7 +130,9 @@ std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToStream(
|
||||
|
||||
for ( auto [border, borderName] : borders )
|
||||
{
|
||||
int elementSide = faces[{ part, border }];
|
||||
auto elementIt = faces.find( { part, border } );
|
||||
CAF_ASSERT( elementIt != faces.end() );
|
||||
int elementSide = elementIt->second;
|
||||
|
||||
std::string sideName = "S" + std::to_string( elementSide );
|
||||
auto surfaceElements = borderSurfaceElements.find( border );
|
||||
@@ -97,19 +153,26 @@ std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToStream(
|
||||
partIndex++;
|
||||
}
|
||||
|
||||
return { true, "" };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::string>
|
||||
RifFaultReactivationModelExporter::printAssembly( std::ostream& stream,
|
||||
const RigFaultReactivationModel& model,
|
||||
const std::map<RigGriddedPart3d::Boundary, std::string>& boundaries )
|
||||
|
||||
{
|
||||
// ASSEMBLY part
|
||||
RifInpExportTools::printSectionComment( stream, "ASSEMBLY" );
|
||||
RifInpExportTools::printHeading( stream, "Assembly, name=Assembly" );
|
||||
|
||||
std::map<RigGriddedPart3d::Boundary, std::string> boundaries = {
|
||||
{ RigGriddedPart3d::Boundary::Bottom, "bottom" },
|
||||
{ RigGriddedPart3d::Boundary::Back, "back" },
|
||||
{ RigGriddedPart3d::Boundary::Front, "front" },
|
||||
{ RigGriddedPart3d::Boundary::FarSide, "farside" },
|
||||
};
|
||||
auto parts = model.allGridParts();
|
||||
|
||||
partIndex = 1;
|
||||
for ( auto part : parts )
|
||||
int partIndex = 1;
|
||||
for ( const auto& part : parts )
|
||||
{
|
||||
std::string partName = "Part-" + std::to_string( partIndex );
|
||||
std::string instanceName = partName + "-1";
|
||||
@@ -127,7 +190,7 @@ std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToStream(
|
||||
}
|
||||
|
||||
partIndex = 1;
|
||||
for ( auto part : parts )
|
||||
for ( const auto& part : parts )
|
||||
{
|
||||
std::string partName = "Part-" + std::to_string( partIndex );
|
||||
std::string instanceName = partName + "-1";
|
||||
@@ -149,8 +212,17 @@ std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToStream(
|
||||
}
|
||||
partIndex++;
|
||||
}
|
||||
|
||||
RifInpExportTools::printHeading( stream, "End Assembly" );
|
||||
|
||||
return { true, "" };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::string> RifFaultReactivationModelExporter::printMaterials( std::ostream& stream )
|
||||
{
|
||||
// MATERIALS PART
|
||||
struct Material
|
||||
{
|
||||
@@ -178,7 +250,14 @@ std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToStream(
|
||||
RifInpExportTools::printNumbers( stream, { mat.permeability1, mat.permeability2 } );
|
||||
}
|
||||
|
||||
double faultFriction = 0.0;
|
||||
return { true, "" };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::string> RifFaultReactivationModelExporter::printInteractionProperties( std::ostream& stream, double faultFriction )
|
||||
{
|
||||
RifInpExportTools::printSectionComment( stream, "INTERACTION PROPERTIES" );
|
||||
|
||||
// Fault interaction
|
||||
@@ -192,6 +271,16 @@ std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToStream(
|
||||
RifInpExportTools::printNumber( stream, 1.0 );
|
||||
RifInpExportTools::printHeading( stream, "Cohesive Behavior" );
|
||||
|
||||
return { true, "" };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::string>
|
||||
RifFaultReactivationModelExporter::printBoundaryConditions( std::ostream& stream,
|
||||
const std::map<RigGriddedPart3d::Boundary, std::string>& boundaries )
|
||||
{
|
||||
auto printBoundaryCondition =
|
||||
[]( std::ostream& stream, const std::string& boundaryConditionName, const std::string& boundaryName, const std::string& symmetryType )
|
||||
{
|
||||
@@ -221,6 +310,14 @@ std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToStream(
|
||||
printBoundaryCondition( stream, "z1", "Part-1-1.part1", partSymmetry );
|
||||
printBoundaryCondition( stream, "z2", "Part-2-1.part2", partSymmetry );
|
||||
|
||||
return { true, "" };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::string> RifFaultReactivationModelExporter::printPredefinedFields( std::ostream& stream )
|
||||
{
|
||||
// PREDEFINED FIELDS
|
||||
struct PredefinedField
|
||||
{
|
||||
@@ -256,27 +353,14 @@ std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToStream(
|
||||
RifInpExportTools::printLine( stream, field.partName + ", " + std::to_string( field.value ) );
|
||||
}
|
||||
|
||||
RifInpExportTools::printSectionComment( stream, "INTERACTIONS" );
|
||||
for ( auto [border, borderName] : borders )
|
||||
{
|
||||
RifInpExportTools::printHeading( stream, "Interaction: " + borderName );
|
||||
|
||||
std::string interactionName = "non-fault";
|
||||
std::string extra;
|
||||
if ( border == RigGriddedPart3d::BorderSurface::FaultSurface )
|
||||
{
|
||||
interactionName = "fault";
|
||||
extra = ", adjust=0.0";
|
||||
}
|
||||
|
||||
RifInpExportTools::printHeading( stream,
|
||||
"Contact Pair, interation=" + interactionName + ", small sliding, type=SURFACE TO SURFACE" + extra );
|
||||
|
||||
std::string part1Name = "Part1-1";
|
||||
std::string part2Name = "Part2-1";
|
||||
RifInpExportTools::printLine( stream, part1Name + "." + borderName + ", " + part2Name + "." + borderName );
|
||||
}
|
||||
return { true, "" };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::string> RifFaultReactivationModelExporter::printSteps( std::ostream& stream )
|
||||
{
|
||||
int numSteps = 2;
|
||||
|
||||
for ( int i = 0; i < numSteps; i++ )
|
||||
@@ -315,9 +399,30 @@ std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToStream(
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<bool, std::string> RifFaultReactivationModelExporter::exportToFile( const std::string& filePath,
|
||||
const RigFaultReactivationModel& model )
|
||||
std::pair<bool, std::string>
|
||||
RifFaultReactivationModelExporter::printInteractions( std::ostream& stream,
|
||||
const std::vector<std::pair<RigGriddedPart3d::BorderSurface, std::string>>& borders )
|
||||
{
|
||||
std::ofstream stream( filePath );
|
||||
return exportToStream( stream, model );
|
||||
RifInpExportTools::printSectionComment( stream, "INTERACTIONS" );
|
||||
for ( const auto& [border, borderName] : borders )
|
||||
{
|
||||
RifInpExportTools::printHeading( stream, "Interaction: " + borderName );
|
||||
|
||||
std::string interactionName = "non-fault";
|
||||
std::string extra;
|
||||
if ( border == RigGriddedPart3d::BorderSurface::FaultSurface )
|
||||
{
|
||||
interactionName = "fault";
|
||||
extra = ", adjust=0.0";
|
||||
}
|
||||
|
||||
RifInpExportTools::printHeading( stream,
|
||||
"Contact Pair, interation=" + interactionName + ", small sliding, type=SURFACE TO SURFACE" + extra );
|
||||
|
||||
std::string part1Name = "Part1-1";
|
||||
std::string part2Name = "Part2-1";
|
||||
RifInpExportTools::printLine( stream, part1Name + "." + borderName + ", " + part2Name + "." + borderName );
|
||||
}
|
||||
|
||||
return { true, "" };
|
||||
}
|
||||
|
||||
@@ -18,8 +18,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfVector3.h"
|
||||
#include "RigFaultReactivationModel.h"
|
||||
|
||||
#include "RigGriddedPart3d.h"
|
||||
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -34,4 +37,25 @@ class RifFaultReactivationModelExporter
|
||||
public:
|
||||
static std::pair<bool, std::string> exportToStream( std::ostream& stream, const RigFaultReactivationModel& model );
|
||||
static std::pair<bool, std::string> exportToFile( const std::string& filePath, const RigFaultReactivationModel& model );
|
||||
|
||||
private:
|
||||
static std::pair<bool, std::string> printHeading( std::ostream& stream, const std::string& applicationNameAndVersion );
|
||||
static std::pair<bool, std::string>
|
||||
printParts( std::ostream& stream,
|
||||
const RigFaultReactivationModel& model,
|
||||
const std::vector<std::pair<RigGriddedPart3d::BorderSurface, std::string>>& borders,
|
||||
const std::map<std::pair<RigFaultReactivationModel::GridPart, RigGriddedPart3d::BorderSurface>, int>& faces );
|
||||
static std::pair<bool, std::string> printAssembly( std::ostream& stream,
|
||||
const RigFaultReactivationModel& model,
|
||||
const std::map<RigGriddedPart3d::Boundary, std::string>& boundaries );
|
||||
|
||||
static std::pair<bool, std::string> printMaterials( std::ostream& stream );
|
||||
|
||||
static std::pair<bool, std::string> printInteractionProperties( std::ostream& stream, double faultFriction );
|
||||
static std::pair<bool, std::string> printBoundaryConditions( std::ostream& stream,
|
||||
const std::map<RigGriddedPart3d::Boundary, std::string>& boundaries );
|
||||
static std::pair<bool, std::string> printPredefinedFields( std::ostream& stream );
|
||||
static std::pair<bool, std::string> printSteps( std::ostream& stream );
|
||||
static std::pair<bool, std::string>
|
||||
printInteractions( std::ostream& stream, const std::vector<std::pair<RigGriddedPart3d::BorderSurface, std::string>>& borders );
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user