-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#10437 Add utility for exporting Abaqus INP files.
- Loading branch information
Showing
5 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
///////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (C) 2023- Equinor ASA | ||
// | ||
// 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. | ||
// | ||
// 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> | ||
// for more details. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "RifInpExportTools.h" | ||
#include <iomanip> | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
bool RifInpExportTools::printLine( std::ostream& stream, const std::string& heading ) | ||
{ | ||
stream << heading << std::endl; | ||
return stream.good(); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
bool RifInpExportTools::printHeading( std::ostream& stream, const std::string& heading ) | ||
{ | ||
return printLine( stream, "*" + heading ); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
bool RifInpExportTools::printComment( std::ostream& stream, const std::string& comment ) | ||
{ | ||
return printLine( stream, "** " + comment ); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
bool RifInpExportTools::printNodes( std::ostream& stream, const std::vector<cvf::Vec3d>& nodes ) | ||
{ | ||
if ( !printHeading( stream, "Node" ) ) return false; | ||
|
||
for ( size_t i = 0; i < nodes.size(); i++ ) | ||
{ | ||
stream << i + 1 << ", " << std::setprecision( 10 ) << nodes[i].x() << ", " << nodes[i].y() << ", " << nodes[i].z() << std::endl; | ||
} | ||
|
||
return stream.good(); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
bool RifInpExportTools::printElements( std::ostream& stream, const std::vector<std::vector<unsigned int>>& elements ) | ||
{ | ||
std::string heading = "Element, type=C3D8P"; | ||
if ( !printHeading( stream, heading ) ) return false; | ||
|
||
for ( size_t i = 0; i < elements.size(); i++ ) | ||
{ | ||
stream << i + 1; | ||
for ( size_t j = 0; j < elements[i].size(); j++ ) | ||
{ | ||
stream << ", " << elements[i][j] + 1; | ||
} | ||
stream << std::endl; | ||
} | ||
|
||
return stream.good(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
///////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (C) 2023- Equinor ASA | ||
// | ||
// 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. | ||
// | ||
// 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> | ||
// for more details. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
#include "cvfVector3.h" | ||
|
||
//#include <map> | ||
#include <ostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
//================================================================================================== | ||
/// | ||
//================================================================================================== | ||
class RifInpExportTools | ||
{ | ||
public: | ||
static bool printLine( std::ostream& stream, const std::string& line ); | ||
static bool printHeading( std::ostream& stream, const std::string& heading ); | ||
static bool printComment( std::ostream& stream, const std::string& comment ); | ||
static bool printNodes( std::ostream& stream, const std::vector<cvf::Vec3d>& nodes ); | ||
static bool printElements( std::ostream& stream, const std::vector<std::vector<unsigned int>>& elements ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
ApplicationLibCode/UnitTests/RifInpExportTools-Test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include "RifInpExportTools.h" | ||
|
||
#include <sstream> | ||
#include <string> | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
TEST( RifInpExportTools, PrintLine ) | ||
{ | ||
std::string line = "this is the line"; | ||
|
||
std::stringstream stream; | ||
ASSERT_TRUE( RifInpExportTools::printLine( stream, line ) ); | ||
|
||
std::string res = stream.str(); | ||
ASSERT_TRUE( res.find( line ) != std::string::npos ); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
TEST( RifInpExportTools, PrintHeading ) | ||
{ | ||
std::string line = "this is the heading"; | ||
|
||
std::stringstream stream; | ||
ASSERT_TRUE( RifInpExportTools::printHeading( stream, line ) ); | ||
|
||
std::string res = stream.str(); | ||
ASSERT_TRUE( res.find( '*' + line ) != std::string::npos ); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
TEST( RifInpExportTools, PrintComment ) | ||
{ | ||
std::string line = "this is the comment"; | ||
|
||
std::stringstream stream; | ||
ASSERT_TRUE( RifInpExportTools::printComment( stream, line ) ); | ||
|
||
std::string expectedString = std::string( "** " ).append( line ); | ||
std::string res = stream.str(); | ||
ASSERT_TRUE( res.find( expectedString ) != std::string::npos ); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
TEST( RifInpExportTools, PrintNodes ) | ||
{ | ||
std::vector<cvf::Vec3d> nodes = { | ||
cvf::Vec3d( 1.0, 1.1, 1.2 ), | ||
cvf::Vec3d( 2.0, 2.1, 2.2 ), | ||
cvf::Vec3d( 3.0, 3.1, 3.2 ), | ||
cvf::Vec3d( 4.0, 4.1, 4.2 ), | ||
}; | ||
|
||
std::stringstream stream; | ||
ASSERT_TRUE( RifInpExportTools::printNodes( stream, nodes ) ); | ||
|
||
auto splitLines = []( const std::string& input ) | ||
{ | ||
std::istringstream stream( input ); | ||
std::string line; | ||
std::vector<std::string> lines; | ||
|
||
while ( std::getline( stream, line ) ) | ||
{ | ||
lines.push_back( line ); | ||
} | ||
return lines; | ||
}; | ||
|
||
auto lines = splitLines( stream.str() ); | ||
ASSERT_EQ( 5u, lines.size() ); | ||
|
||
std::string res = stream.str(); | ||
ASSERT_TRUE( res.find( std::string( "*Node" ) ) != std::string::npos ); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
TEST( RifInpExportTools, Elements ) | ||
{ | ||
std::vector<std::vector<unsigned int>> elements = { | ||
{ 1, 1, 1, 1 }, | ||
{ 2, 2, 2, 2 }, | ||
{ 3, 3, 3, 3 }, | ||
{ 4, 4, 4, 4 }, | ||
{ 5, 5, 5, 5 }, | ||
}; | ||
|
||
std::stringstream stream; | ||
ASSERT_TRUE( RifInpExportTools::printElements( stream, elements ) ); | ||
|
||
auto splitLines = []( const std::string& input ) | ||
{ | ||
std::istringstream stream( input ); | ||
std::string line; | ||
std::vector<std::string> lines; | ||
|
||
while ( std::getline( stream, line ) ) | ||
{ | ||
lines.push_back( line ); | ||
} | ||
return lines; | ||
}; | ||
|
||
auto lines = splitLines( stream.str() ); | ||
ASSERT_EQ( 6u, lines.size() ); | ||
|
||
std::string res = stream.str(); | ||
ASSERT_TRUE( res.find( std::string( "*Element" ) ) != std::string::npos ); | ||
} |