Merge pull request #466 from joakim-hove/remove-ert-cpp
Removed ERT Cxx wrappers
This commit is contained in:
@@ -10,7 +10,6 @@ add_subdirectory(EclipseState/Tables/tests)
|
||||
add_subdirectory(EclipseState/Grid/tests)
|
||||
add_subdirectory(EclipseState/Util/tests)
|
||||
add_subdirectory(EclipseState/IOConfig/tests)
|
||||
add_subdirectory(ert/tests)
|
||||
|
||||
add_subdirectory( Applications )
|
||||
|
||||
@@ -107,10 +106,7 @@ EclipseState/Grid/FaultCollection.cpp
|
||||
EclipseState/SimulationConfig/SimulationConfig.cpp
|
||||
EclipseState/SimulationConfig/ThresholdPressure.cpp
|
||||
#
|
||||
EclipseState/IOConfig/IOConfig.cpp
|
||||
#
|
||||
ert/EclKW.cpp
|
||||
ert/FortIO.cpp)
|
||||
EclipseState/IOConfig/IOConfig.cpp)
|
||||
|
||||
|
||||
set( HEADER_FILES
|
||||
@@ -245,11 +241,7 @@ Utility/GruptreeWrapper.hpp
|
||||
Utility/WelspecsWrapper.hpp
|
||||
Utility/EquilWrapper.hpp
|
||||
Utility/EndscaleWrapper.hpp
|
||||
Utility/ScalecrsWrapper.hpp
|
||||
#
|
||||
ert/EclKW.hpp
|
||||
ert/FortIO.hpp
|
||||
)
|
||||
Utility/ScalecrsWrapper.hpp)
|
||||
|
||||
add_library(buildParser STATIC ${rawdeck_source} ${build_parser_source} ${deck_source} ${unit_source})
|
||||
target_link_libraries(buildParser opmjson ${Boost_LIBRARIES})
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
#include <unordered_map>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/ert/EclKW.hpp>
|
||||
#include <ert/ecl/EclKW.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/Box.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#include <opm/parser/eclipse/ert/EclKW.hpp>
|
||||
|
||||
|
||||
namespace ERT {
|
||||
template <>
|
||||
EclKW<int>::EclKW(const std::string& kw, int size_) {
|
||||
ecl_kw_type * c_ptr = ecl_kw_alloc( kw.c_str() , size_ , ECL_INT_TYPE );
|
||||
reset( c_ptr );
|
||||
}
|
||||
|
||||
template <>
|
||||
EclKW<float>::EclKW(const std::string& kw, int size_) {
|
||||
ecl_kw_type * c_ptr = ecl_kw_alloc( kw.c_str() , size_ , ECL_FLOAT_TYPE );
|
||||
reset( c_ptr );
|
||||
}
|
||||
|
||||
template <>
|
||||
EclKW<double>::EclKW(const std::string& kw, int size_) {
|
||||
ecl_kw_type * c_ptr = ecl_kw_alloc( kw.c_str() , size_ , ECL_DOUBLE_TYPE );
|
||||
reset( c_ptr );
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <>
|
||||
EclKW<double> EclKW<double>::load(FortIO& fortio) {
|
||||
return checkedLoad(fortio , ECL_DOUBLE_TYPE);
|
||||
}
|
||||
|
||||
template <>
|
||||
EclKW<int> EclKW<int>::load(FortIO& fortio) {
|
||||
return checkedLoad(fortio , ECL_INT_TYPE);
|
||||
}
|
||||
|
||||
template <>
|
||||
EclKW<float> EclKW<float>::load(FortIO& fortio) {
|
||||
return checkedLoad(fortio , ECL_FLOAT_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OPM_ERT_ECL_KW
|
||||
#define OPM_ERT_ECL_KW
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include <opm/parser/eclipse/ert/FortIO.hpp>
|
||||
|
||||
#include <ert/ecl/ecl_kw.h>
|
||||
#include <ert/ecl/ecl_util.h>
|
||||
|
||||
|
||||
|
||||
namespace ERT {
|
||||
template <typename T>
|
||||
class EclKW
|
||||
{
|
||||
public:
|
||||
EclKW(const std::string& kw, int size_);
|
||||
EclKW() { ; }
|
||||
|
||||
static EclKW load(FortIO& fortio);
|
||||
|
||||
size_t size() const {
|
||||
return static_cast<size_t>( ecl_kw_get_size( m_kw.get() ));
|
||||
}
|
||||
|
||||
T& operator[](size_t index) {
|
||||
return *( static_cast<T *>( ecl_kw_iget_ptr( m_kw.get() , index) ));
|
||||
}
|
||||
|
||||
|
||||
void fwrite(FortIO& fortio) const {
|
||||
ecl_kw_fwrite( m_kw.get() , fortio.getPointer() );
|
||||
}
|
||||
|
||||
|
||||
void assignVector(const std::vector<T>& data) {
|
||||
if (data.size() == size())
|
||||
ecl_kw_set_memcpy_data( m_kw.get() , data.data() );
|
||||
else
|
||||
throw std::invalid_argument("Size error");
|
||||
}
|
||||
|
||||
private:
|
||||
EclKW(ecl_kw_type * c_ptr) {
|
||||
reset(c_ptr);
|
||||
}
|
||||
|
||||
void reset(ecl_kw_type * c_ptr) {
|
||||
m_kw.reset( c_ptr , ecl_kw_free);
|
||||
}
|
||||
|
||||
|
||||
static EclKW checkedLoad(FortIO& fortio, ecl_type_enum expectedType) {
|
||||
ecl_kw_type * c_ptr = ecl_kw_fread_alloc( fortio.getPointer() );
|
||||
if (c_ptr) {
|
||||
if (ecl_kw_get_type( c_ptr ) == expectedType)
|
||||
return EclKW( c_ptr );
|
||||
else
|
||||
throw std::invalid_argument("Type error");
|
||||
} else
|
||||
throw std::invalid_argument("fread kw failed - EOF?");
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<ecl_kw_type> m_kw;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define BOOST_NO_CXX11_SCOPED_ENUMS
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <ert/ecl/fortio.h>
|
||||
|
||||
#include <opm/parser/eclipse/ert/FortIO.hpp>
|
||||
|
||||
namespace ERT {
|
||||
|
||||
FortIO::FortIO(const std::string& filename , std::ios_base::openmode mode , bool fmt_file , bool endian_flip_header) {
|
||||
if (mode == std::ios_base::in) {
|
||||
if (boost::filesystem::exists( filename )) {
|
||||
fortio_type * c_ptr = fortio_open_reader( filename.c_str() , fmt_file , endian_flip_header);
|
||||
m_fortio.reset( c_ptr , fortio_fclose );
|
||||
} else
|
||||
throw std::invalid_argument("File " + filename + " does not exist");
|
||||
} else {
|
||||
fortio_type * c_ptr = fortio_open_writer( filename.c_str() , fmt_file , endian_flip_header);
|
||||
m_fortio.reset( c_ptr , fortio_fclose );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FortIO::close() {
|
||||
if (m_fortio)
|
||||
m_fortio.reset( );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fortio_type * FortIO::getPointer() const {
|
||||
return m_fortio.get();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OPM_ERT_FORTIO_KW
|
||||
#define OPM_ERT_FORTIO_KW
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include <ert/ecl/fortio.h>
|
||||
#include <ert/ecl/ecl_endian_flip.h>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace ERT {
|
||||
class FortIO
|
||||
{
|
||||
public:
|
||||
FortIO(const std::string& filename , std::ios_base::openmode mode , bool fmt_file = false , bool endian_flip_header = ECL_ENDIAN_FLIP);
|
||||
fortio_type * getPointer() const;
|
||||
void close();
|
||||
void reset() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<fortio_type> m_fortio;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,2 +0,0 @@
|
||||
opm_add_test(runErtTests SOURCES test_ert_wrapper.cpp
|
||||
LIBRARIES opmparser ${Boost_LIBRARIES})
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 Statoil ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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.
|
||||
|
||||
OPM 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE ERT_WRAPPER_TESTS
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <ert/util/test_work_area.h>
|
||||
|
||||
#include <opm/parser/eclipse/ert/EclKW.hpp>
|
||||
#include <opm/parser/eclipse/ert/FortIO.hpp>
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(KWTEST) {
|
||||
ERT::EclKW<int> kw("XYZ" , 1000);
|
||||
BOOST_CHECK_EQUAL( kw.size() , 1000U );
|
||||
|
||||
kw[0] = 1;
|
||||
kw[10] = 77;
|
||||
|
||||
BOOST_CHECK_EQUAL( kw[0] , 1 );
|
||||
BOOST_CHECK_EQUAL( kw[10] , 77 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(FortioTEST) {
|
||||
test_work_area_type * work_area = test_work_area_alloc("fortio");
|
||||
|
||||
ERT::FortIO fortio("new_file" , std::fstream::out );
|
||||
{
|
||||
std::vector<int> data;
|
||||
for (size_t i=0; i < 1000; i++)
|
||||
data.push_back(i);
|
||||
|
||||
fortio_fwrite_record( fortio.getPointer() , reinterpret_cast<char *>(data.data()) , 1000 * 4 );
|
||||
}
|
||||
fortio.close();
|
||||
|
||||
fortio = ERT::FortIO("new_file" , std::fstream::in );
|
||||
{
|
||||
std::vector<int> data;
|
||||
for (size_t i=0; i < 1000; i++)
|
||||
data.push_back(99);
|
||||
|
||||
BOOST_CHECK( fortio_fread_buffer( fortio.getPointer() , reinterpret_cast<char *>(data.data()) , 1000 * 4 ));
|
||||
for (size_t i =0; i < 1000; i++)
|
||||
BOOST_CHECK_EQUAL( data[i] , i );
|
||||
|
||||
}
|
||||
fortio.close();
|
||||
test_work_area_free( work_area );
|
||||
|
||||
BOOST_CHECK_THROW( ERT::FortIO fortio("file/does/not/exists" , std::fstream::in) , std::invalid_argument );
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Fortio_kw_TEST) {
|
||||
test_work_area_type * work_area = test_work_area_alloc("fortio_kw");
|
||||
ERT::EclKW<int> kw("XYZ" , 1000);
|
||||
for (size_t i =0 ; i < kw.size(); i++)
|
||||
kw[i] = i;
|
||||
|
||||
{
|
||||
ERT::FortIO fortio("new_file" , std::fstream::out );
|
||||
kw.fwrite( fortio );
|
||||
fortio.close();
|
||||
}
|
||||
|
||||
{
|
||||
ERT::FortIO fortio("new_file" , std::fstream::in );
|
||||
ERT::EclKW<int> kw2 = ERT::EclKW<int>::load( fortio );
|
||||
fortio.close( );
|
||||
for (size_t i =0 ; i < kw.size(); i++)
|
||||
BOOST_CHECK_EQUAL(kw[i] , kw2[i]);
|
||||
|
||||
|
||||
fortio = ERT::FortIO("new_file" , std::fstream::in );
|
||||
BOOST_CHECK_THROW( ERT::EclKW<float>::load(fortio) , std::invalid_argument );
|
||||
fortio.close();
|
||||
}
|
||||
|
||||
test_work_area_free( work_area );
|
||||
}
|
||||
Reference in New Issue
Block a user