From 406c208b3308a1c89a6d394bd7347f9e70926c6c Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Wed, 6 Sep 2023 10:20:24 +0200 Subject: [PATCH] Refactor: Split INP exporter into parts. --- .../RifFaultReactivationModelExporter.cpp | 213 +++++++++++++----- .../RifFaultReactivationModelExporter.h | 26 ++- 2 files changed, 184 insertions(+), 55 deletions(-) diff --git a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp index d87a0bdf41..8c4065213d 100644 --- a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp +++ b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.cpp @@ -33,29 +33,83 @@ //-------------------------------------------------------------------------------------------------- std::pair 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> borders = { { PartBorderSurface::UpperSurface, "top" }, + { PartBorderSurface::FaultSurface, "fault" }, + { PartBorderSurface::LowerSurface, "base" } }; + using FaultGridPart = RigFaultReactivationModel::GridPart; + std::map, 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 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 RifFaultReactivationModelExporter::exportToFile( const std::string& filePath, + const RigFaultReactivationModel& model ) +{ + std::ofstream stream( filePath ); + return exportToStream( stream, model ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::pair 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 RifFaultReactivationModelExporter::printParts( + std::ostream& stream, + const RigFaultReactivationModel& model, + const std::vector>& borders, + const std::map, int>& faces ) +{ RifInpExportTools::printSectionComment( stream, "PARTS" ); - auto parts = model.allGridParts(); - - std::vector> borders = { { RigGriddedPart3d::BorderSurface::UpperSurface, "top" }, - { RigGriddedPart3d::BorderSurface::FaultSurface, "fault" }, - { RigGriddedPart3d::BorderSurface::LowerSurface, "base" } }; - - std::map, 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 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 RifFaultReactivationModelExporter::exportToStream( partIndex++; } + return { true, "" }; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::pair + RifFaultReactivationModelExporter::printAssembly( std::ostream& stream, + const RigFaultReactivationModel& model, + const std::map& boundaries ) + +{ // ASSEMBLY part RifInpExportTools::printSectionComment( stream, "ASSEMBLY" ); RifInpExportTools::printHeading( stream, "Assembly, name=Assembly" ); - std::map 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 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 RifFaultReactivationModelExporter::exportToStream( } partIndex++; } + RifInpExportTools::printHeading( stream, "End Assembly" ); + return { true, "" }; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::pair RifFaultReactivationModelExporter::printMaterials( std::ostream& stream ) +{ // MATERIALS PART struct Material { @@ -178,7 +250,14 @@ std::pair RifFaultReactivationModelExporter::exportToStream( RifInpExportTools::printNumbers( stream, { mat.permeability1, mat.permeability2 } ); } - double faultFriction = 0.0; + return { true, "" }; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::pair RifFaultReactivationModelExporter::printInteractionProperties( std::ostream& stream, double faultFriction ) +{ RifInpExportTools::printSectionComment( stream, "INTERACTION PROPERTIES" ); // Fault interaction @@ -192,6 +271,16 @@ std::pair RifFaultReactivationModelExporter::exportToStream( RifInpExportTools::printNumber( stream, 1.0 ); RifInpExportTools::printHeading( stream, "Cohesive Behavior" ); + return { true, "" }; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::pair + RifFaultReactivationModelExporter::printBoundaryConditions( std::ostream& stream, + const std::map& boundaries ) +{ auto printBoundaryCondition = []( std::ostream& stream, const std::string& boundaryConditionName, const std::string& boundaryName, const std::string& symmetryType ) { @@ -221,6 +310,14 @@ std::pair RifFaultReactivationModelExporter::exportToStream( printBoundaryCondition( stream, "z1", "Part-1-1.part1", partSymmetry ); printBoundaryCondition( stream, "z2", "Part-2-1.part2", partSymmetry ); + return { true, "" }; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::pair RifFaultReactivationModelExporter::printPredefinedFields( std::ostream& stream ) +{ // PREDEFINED FIELDS struct PredefinedField { @@ -256,27 +353,14 @@ std::pair 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 RifFaultReactivationModelExporter::printSteps( std::ostream& stream ) +{ int numSteps = 2; for ( int i = 0; i < numSteps; i++ ) @@ -315,9 +399,30 @@ std::pair RifFaultReactivationModelExporter::exportToStream( //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::pair RifFaultReactivationModelExporter::exportToFile( const std::string& filePath, - const RigFaultReactivationModel& model ) +std::pair + RifFaultReactivationModelExporter::printInteractions( std::ostream& stream, + const std::vector>& 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, "" }; } diff --git a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.h b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.h index f82b9357c6..cad6195b96 100644 --- a/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.h +++ b/ApplicationLibCode/FileInterface/RifFaultReactivationModelExporter.h @@ -18,8 +18,11 @@ #pragma once -#include "cvfVector3.h" +#include "RigFaultReactivationModel.h" +#include "RigGriddedPart3d.h" + +#include #include #include #include @@ -34,4 +37,25 @@ class RifFaultReactivationModelExporter public: static std::pair exportToStream( std::ostream& stream, const RigFaultReactivationModel& model ); static std::pair exportToFile( const std::string& filePath, const RigFaultReactivationModel& model ); + +private: + static std::pair printHeading( std::ostream& stream, const std::string& applicationNameAndVersion ); + static std::pair + printParts( std::ostream& stream, + const RigFaultReactivationModel& model, + const std::vector>& borders, + const std::map, int>& faces ); + static std::pair printAssembly( std::ostream& stream, + const RigFaultReactivationModel& model, + const std::map& boundaries ); + + static std::pair printMaterials( std::ostream& stream ); + + static std::pair printInteractionProperties( std::ostream& stream, double faultFriction ); + static std::pair printBoundaryConditions( std::ostream& stream, + const std::map& boundaries ); + static std::pair printPredefinedFields( std::ostream& stream ); + static std::pair printSteps( std::ostream& stream ); + static std::pair + printInteractions( std::ostream& stream, const std::vector>& borders ); };