Skip to content

Commit

Permalink
Move ECLIPSE I/O Into Main OPM Common Library
Browse files Browse the repository at this point in the history
This makes the facility usable for the restart read/write code.

Specifically, import the I/O classes into namespace Opm::ecl, and
place the files in physical location opm/io/eclipse, and move the
test utilities to new top-level directory 'test_util/'.  While here,
discontinue the 'testutil' static library since most of its features
are now available in the main 'opmcommon' library.  This does entail
compiling a few of the test_util/ CPP files multiple times, and
adding the objects to each executable independently.
  • Loading branch information
bska committed May 23, 2019
1 parent 464bc4b commit e654915
Show file tree
Hide file tree
Showing 31 changed files with 525 additions and 420 deletions.
54 changes: 39 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,27 +157,51 @@ endif()

# Build the compare utilities
if(ENABLE_ECL_INPUT)
add_library(testutil STATIC
examples/test_util/EclFile.cpp
examples/test_util/EclFilesComparator.cpp
examples/test_util/EclOutput.cpp
examples/test_util/EclRegressionTest.cpp
examples/test_util/EclUtil.cpp
examples/test_util/EGrid.cpp
examples/test_util/ERft.cpp
examples/test_util/ERst.cpp
examples/test_util/ESmry.cpp)
add_executable(compareECL
test_util/EclFilesComparator.cpp
test_util/EclRegressionTest.cpp
test_util/compareECL.cpp
)

add_executable(convertECL
test_util/convertECL.cpp
)

foreach(target compareECL convertECL)
add_executable(${target} examples/test_util/${target}.cpp)
target_link_libraries(${target} testutil opmcommon)
target_link_libraries(${target} opmcommon)
install(TARGETS ${target} DESTINATION bin)
endforeach()

# Add the tests
set(_libs testutil opmcommon
set(_libs opmcommon
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
foreach(test test_EclFilesComparator test_EclIO test_EclRegressionTest
test_EGrid test_ERft test_ERst test_ESmry)

opm_add_test(test_EclFilesComparator
CONDITION
ENABLE_ECL_INPUT
SOURCES
tests/test_EclFilesComparator.cpp
test_util/EclFilesComparator.cpp
LIBRARIES
${_libs}
WORKING_DIRECTORY
${PROJECT_BINARY_DIR}/tests
)

opm_add_test(test_EclRegressionTest
CONDITION
ENABLE_ECL_INPUT
SOURCES
tests/test_EclRegressionTest.cpp
test_util/EclFilesComparator.cpp
test_util/EclRegressionTest.cpp
LIBRARIES
${_libs}
WORKING_DIRECTORY
${PROJECT_BINARY_DIR}/tests
)

foreach(test test_EclIO test_EGrid test_ERft test_ERst test_ESmry)
opm_add_test(${test} CONDITION ENABLE_ECL_INPUT
LIBRARIES ${_libs}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
Expand Down
15 changes: 15 additions & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ if(ENABLE_ECL_INPUT)
endif()
if(ENABLE_ECL_OUTPUT)
list( APPEND MAIN_SOURCE_FILES
src/opm/io/eclipse/EclFile.cpp
src/opm/io/eclipse/EclOutput.cpp
src/opm/io/eclipse/EclUtil.cpp
src/opm/io/eclipse/EGrid.cpp
src/opm/io/eclipse/ERft.cpp
src/opm/io/eclipse/ERst.cpp
src/opm/io/eclipse/ESmry.cpp
src/opm/output/eclipse/AggregateConnectionData.cpp
src/opm/output/eclipse/AggregateGroupData.cpp
src/opm/output/eclipse/AggregateMSWData.cpp
Expand Down Expand Up @@ -562,6 +569,14 @@ if(ENABLE_ECL_INPUT)
endif()
if(ENABLE_ECL_OUTPUT)
list(APPEND PUBLIC_HEADER_FILES
opm/io/eclipse/EclFile.hpp
opm/io/eclipse/EclIOdata.hpp
opm/io/eclipse/EclOutput.hpp
opm/io/eclipse/EclUtil.hpp
opm/io/eclipse/EGrid.hpp
opm/io/eclipse/ERft.hpp
opm/io/eclipse/ERst.hpp
opm/io/eclipse/ESmry.hpp
opm/output/data/Cells.hpp
opm/output/data/Solution.hpp
opm/output/data/Wells.hpp
Expand Down
11 changes: 7 additions & 4 deletions examples/test_util/EGrid.hpp → opm/io/eclipse/EGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef EGRID_HPP
#define EGRID_HPP
#ifndef OPM_IO_EGRID_HPP
#define OPM_IO_EGRID_HPP

#include "EclFile.hpp"
#include <opm/io/eclipse/EclFile.hpp>

#include <array>
#include <iostream>
Expand All @@ -29,6 +29,7 @@
#include <ctime>
#include <map>

namespace Opm { namespace ecl {

class EGrid : public EclFile
{
Expand Down Expand Up @@ -59,4 +60,6 @@ class EGrid : public EclFile
std::vector<float> zcorn_array;
};

#endif
}} // namespace Opm::ecl

#endif // OPM_IO_EGRID_HPP
19 changes: 10 additions & 9 deletions examples/test_util/ERft.hpp → opm/io/eclipse/ERft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ERFT_HPP
#define ERFT_HPP
#ifndef OPM_IO_ERFT_HPP
#define OPM_IO_ERFT_HPP

#include <opm/io/eclipse/EclFile.hpp>

#include "EclFile.hpp"

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

namespace Opm { namespace ecl {

class ERft : public EclFile
{
Expand Down Expand Up @@ -79,5 +79,6 @@ class ERft : public EclFile
const RftDate& date) const;
};

#endif
}} // namespace Opm::ecl

#endif // OPM_IO_ERFT_HPP
18 changes: 9 additions & 9 deletions examples/test_util/ERst.hpp → opm/io/eclipse/ERst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ERST_HPP
#define ERST_HPP
#ifndef OPM_IO_ERST_HPP
#define OPM_IO_ERST_HPP

#include <opm/io/eclipse/EclFile.hpp>

#include "EclFile.hpp"

#include <iostream>
#include <map>
#include <string>
#include <fstream>
#include <unordered_map>
#include <vector>
#include <ctime>
#include <map>

namespace Opm { namespace ecl {

class ERst : public EclFile
{
Expand All @@ -54,4 +52,6 @@ class ERst : public EclFile
int getArrayIndex(const std::string& name, int seqnum) const;
};

#endif
}} // namespace Opm::ecl

#endif // OPM_IO_ERST_HPP
14 changes: 6 additions & 8 deletions examples/test_util/ESmry.hpp → opm/io/eclipse/ESmry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ESMRY_HPP
#define ESMRY_HPP
#ifndef OPM_IO_ESMRY_HPP
#define OPM_IO_ESMRY_HPP

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <ctime>
#include <map>

namespace Opm { namespace ecl {

class ESmry
{
Expand Down Expand Up @@ -55,6 +53,6 @@ class ESmry
std::string makeKeyString(const std::string& keyword, const std::string& wgname, int num);
};

#endif

}} // namespace Opm::ecl

#endif // OPM_IO_ESMRY_HPP
30 changes: 15 additions & 15 deletions examples/test_util/EclFile.hpp → opm/io/eclipse/EclFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ECLFILE_HPP
#define ECLFILE_HPP
#ifndef OPM_IO_ECLFILE_HPP
#define OPM_IO_ECLFILE_HPP

#include <opm/common/ErrorMacros.hpp>
#include <examples/test_util/data/EclIOdata.hpp>

#include <iostream>
#include <string>
#include <opm/io/eclipse/EclIOdata.hpp>

#include <fstream>
#include <vector>
#include <ctime>
#include <map>
#include <string>
#include <stdexcept>
#include <unordered_map>
#include <stdio.h>
#include <vector>

namespace EIOD = Opm::ecl;
namespace Opm { namespace ecl {

class EclFile
{
Expand All @@ -53,7 +51,7 @@ class EclFile
char_array.clear();
}

using EclEntry = std::tuple<std::string, EIOD::eclArrType, int>;
using EclEntry = std::tuple<std::string, eclArrType, int>;
std::vector<EclEntry> getList() const;

template <typename T>
Expand All @@ -77,15 +75,15 @@ class EclFile
std::unordered_map<int, std::vector<std::string>> char_array;

std::vector<std::string> array_name;
std::vector<EIOD::eclArrType> array_type;
std::vector<eclArrType> array_type;
std::vector<int> array_size;

std::vector<unsigned long int> ifStreamPos;

std::map<std::string, int> array_index;

template<class T>
const std::vector<T>& getImpl(int arrIndex, EIOD::eclArrType type,
const std::vector<T>& getImpl(int arrIndex, eclArrType type,
const std::unordered_map<int, std::vector<T>>& array,
const std::string& typeStr)
{
Expand All @@ -98,7 +96,7 @@ class EclFile
loadData(arrIndex);
}

return array.find(arrIndex)->second;
return array.at(arrIndex);
}

private:
Expand All @@ -107,4 +105,6 @@ class EclFile
void loadArray(std::fstream& fileH, int arrIndex);
};

#endif
}} // namespace Opm::ecl

#endif // OPM_IO_ECLFILE_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef OPM_ECLIO_DATA_HPP
#define OPM_ECLIO_DATA_HPP
#ifndef OPM_IO_ECLIODATA_HPP
#define OPM_IO_ECLIODATA_HPP

#include <tuple>


namespace Opm {

namespace ecl {
namespace Opm { namespace ecl {

// type MESS have no assisiated data

enum eclArrType {
INTE, REAL, DOUB, CHAR, LOGI, MESS
};

// named constants related to binary file format

const unsigned int true_value = 0xffffffff;
const unsigned int false_value = 0x00000000;

Expand All @@ -51,7 +46,6 @@ namespace Opm {
const int MaxBlockSizeChar = 840; // Maximum block size for CHAR arrays in binary files

// named constants related to formatted file file format

const int MaxNumBlockInte = 1000; // maximum number of Inte values in block => hard line shift
const int MaxNumBlockReal = 1000; // maximum number of Real values in block => hard line shift
const int MaxNumBlockDoub = 1000; // maximum number of Doub values in block => hard line shift
Expand All @@ -69,8 +63,7 @@ namespace Opm {
const int columnWidthDoub = 23; // number of characters fore each Inte Element
const int columnWidthLogi = 3; // number of characters fore each Inte Element
const int columnWidthChar = 11; // number of characters fore each Inte Element

} // ecl
} // Opm

#endif // OPM_ECLIO_DATA_HPP
}} // namespace Opm::ecl

#endif // OPM_IO_ECLIODATA_HPP
Loading

0 comments on commit e654915

Please sign in to comment.