diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 42bccbafe..352f728b3 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -21,7 +21,6 @@ # the library needs it. list (APPEND MAIN_SOURCE_FILES - src/opm/common/data/SimulationDataContainer.cpp src/opm/common/OpmLog/CounterLog.cpp src/opm/common/OpmLog/EclipsePRTLog.cpp src/opm/common/OpmLog/LogBackend.cpp @@ -304,7 +303,6 @@ list (APPEND TEST_SOURCE_FILES tests/test_OpmLog.cpp tests/test_param.cpp tests/test_RootFinders.cpp - tests/test_SimulationDataContainer.cpp tests/test_sparsevector.cpp tests/test_uniformtablelinear.cpp ) @@ -508,7 +506,6 @@ endif() list( APPEND PUBLIC_HEADER_FILES opm/common/ErrorMacros.hpp opm/common/Exceptions.hpp - opm/common/data/SimulationDataContainer.hpp opm/common/OpmLog/CounterLog.hpp opm/common/OpmLog/EclipsePRTLog.hpp opm/common/OpmLog/LogBackend.hpp diff --git a/opm/common/data/SimulationDataContainer.hpp b/opm/common/data/SimulationDataContainer.hpp deleted file mode 100644 index 45ddee3b4..000000000 --- a/opm/common/data/SimulationDataContainer.hpp +++ /dev/null @@ -1,191 +0,0 @@ -/* - Copyright 2016 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 . - */ - -#ifndef SIMULATION_DATA_CONTAINER_HPP -#define SIMULATION_DATA_CONTAINER_HPP - -#include -#include -#include -#include - -namespace Opm { - - - /// The SimulationDataContainer is a simple container to manage - /// simulation data. The container is instantiated with information - /// of how many cells, faces and phases are present in the - /// reservoirmodel. You can then add data to the container by using the - /// - /// registerCellData() - /// registerFaceData() - /// - /// functions. The container owns and manages the data, but - /// mutable references are returned with the getCellData() and - /// getFaceData() methods, and the content will typically be - /// modified by external scope. - class SimulationDataContainer - { - public: - /// Main constructor setting the sizes for the contained data - /// types. - /// \param num_cells number of elements in cell data vectors - /// \param num_faces number of elements in face data vectors - /// \param num_phases number of phases, the number of components - /// in any data vector must equal 1 or this - /// number (this behaviour and argument is deprecated). - SimulationDataContainer(size_t num_cells, size_t num_faces, size_t num_phases); - - /// Copy constructor. - /// Must be defined explicitly because class contains non-value objects - /// (the reference pointers pressure_ref_ etc.) that should not simply - /// be copied. - SimulationDataContainer(const SimulationDataContainer&); - - /// Copy assignment operator. - /// Must be defined explicitly because class contains non-value objects - /// (the reference pointers pressure_ref_ etc.) that should not simply - /// be copied. - SimulationDataContainer& operator=(const SimulationDataContainer&); - - /// Efficient O(1) swap. - void swap(SimulationDataContainer& other); - - size_t numPhases() const; - size_t numFaces() const; - size_t numCells() const; - - bool hasCellData( const std::string& name ) const; - - /// Will register a data vector of size numCells() * - /// components. - void registerCellData( const std::string& name , size_t components , double initialValue = 0.0 ); - std::vector& getCellData( const std::string& name ); - const std::vector& getCellData( const std::string& name ) const; - - bool hasFaceData( const std::string& name ) const; - void registerFaceData( const std::string& name , size_t components , double initialValue = 0.0 ); - std::vector& getFaceData( const std::string& name ); - const std::vector& getFaceData( const std::string& name ) const; - - /// Will return the number of components of the celldata with - /// name @name: - /// - /// numCellDataComponents( "PRESSURE" ) -> 1 - /// numCellDataComponents( "SATURATION" ) -> 3 - /// - /// for a three phase model. - size_t numCellDataComponents( const std::string& name ) const; - bool equal(const SimulationDataContainer& other) const; - - - /// Will set the values of component nr @component in the - /// field @key. All the cells in @cells will be set to the - /// values in @values. - void setCellDataComponent( const std::string& key , size_t component , const std::vector& cells , const std::vector& values); - - // Direct explicit field access for certain default fields. - // These methods are all deprecated, and will eventually be moved to - // concrete subclasses. - - std::vector& pressure (); - std::vector& temperature (); - std::vector& saturation (); - - std::vector& facepressure(); - std::vector& faceflux (); - - const std::vector& pressure () const; - const std::vector& temperature () const; - const std::vector& saturation () const; - - const std::vector& facepressure() const; - const std::vector& faceflux () const; - - const std::map>& cellData() const; - std::map>& cellData(); - - private: - void addDefaultFields(); - void setReferencePointers(); - - size_t m_num_cells; - size_t m_num_faces; - size_t m_num_phases; - - std::map< std::string , std::vector > m_cell_data; - std::map< std::string , std::vector > m_face_data; - - std::vector* pressure_ref_; - std::vector* temperature_ref_; - std::vector* saturation_ref_; - std::vector* facepressure_ref_; - std::vector* faceflux_ref_; - }; - - - // Inline implementations of the direct accessors required to guarantee - // performance. - - - inline std::vector& SimulationDataContainer::pressure( ) { - return *pressure_ref_; - } - - inline std::vector& SimulationDataContainer::temperature() { - return *temperature_ref_; - } - - inline std::vector& SimulationDataContainer::saturation() { - return *saturation_ref_; - } - - inline std::vector& SimulationDataContainer::facepressure() { - return *facepressure_ref_; - } - - inline std::vector& SimulationDataContainer::faceflux() { - return *faceflux_ref_; - } - - inline const std::vector& SimulationDataContainer::pressure( ) const { - return *pressure_ref_; - } - - inline const std::vector& SimulationDataContainer::temperature() const { - return *temperature_ref_; - } - - inline const std::vector& SimulationDataContainer::saturation() const { - return *saturation_ref_; - } - - inline const std::vector& SimulationDataContainer::facepressure() const { - return *facepressure_ref_; - } - - inline const std::vector& SimulationDataContainer::faceflux() const { - return *faceflux_ref_; - } - - - -} - -#endif diff --git a/tests/test_SimulationDataContainer.cpp b/tests/test_SimulationDataContainer.cpp deleted file mode 100644 index 9b6474dda..000000000 --- a/tests/test_SimulationDataContainer.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - Copyright 2016 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 . - */ - -#include - -#define BOOST_TEST_MODULE SIMULATION_DATA_CONTAINER_TESTS -#include - -#include -#include -#include - -using namespace Opm; - - -BOOST_AUTO_TEST_CASE(TestCreate) { - SimulationDataContainer container(1000 , 10 , 2); - - BOOST_CHECK_EQUAL( 2U , container.numPhases() ); - BOOST_CHECK_EQUAL( 1000U , container.numCells() ); - BOOST_CHECK_EQUAL( 10U , container.numFaces() ); -} - - - - -/* - This test verifies that the default fields are correctly registered; - this special behavior is deprecated - and the test should die; along - with the behavior. -*/ - -BOOST_AUTO_TEST_CASE(TestRegisterDefaults) { - SimulationDataContainer container(1000 , 10 , 2); - - BOOST_CHECK( container.hasCellData("PRESSURE") ); - BOOST_CHECK( container.hasCellData("SATURATION") ); - - { - auto pressure = container.getCellData("PRESSURE"); - BOOST_CHECK_EQUAL( pressure.size() , 1000U ); - BOOST_CHECK_EQUAL( container.numCellDataComponents( "PRESSURE") , 1U); - - auto sat = container.getCellData("SATURATION"); - BOOST_CHECK_EQUAL( sat.size() , 1000U*2 ); - BOOST_CHECK_EQUAL( container.numCellDataComponents( "SATURATION") , 2U); - } - - { - auto pressure = container.pressure(); - BOOST_CHECK_EQUAL( pressure.size() , 1000U ); - - auto sat = container.saturation(); - BOOST_CHECK_EQUAL( sat.size() , 1000U*2 ); - } - - BOOST_CHECK( container.hasFaceData("FACEPRESSURE") ); - BOOST_CHECK( container.hasFaceData("FACEFLUX") ); -} - - - - -BOOST_AUTO_TEST_CASE(TestRegisterFaceData) { - SimulationDataContainer container(100 , 10 , 2); - BOOST_CHECK( !container.hasFaceData("FLUX")); - BOOST_CHECK_THROW( container.getFaceData("FLUX") , std::invalid_argument ); - - container.registerFaceData("FLUX" , 1 , 99 ); - auto& flux = container.getFaceData("FLUX"); - BOOST_CHECK_EQUAL( flux.size() , 10U ); - BOOST_CHECK_EQUAL( flux[0] , 99 ); -} - - - -BOOST_AUTO_TEST_CASE(TestRegisterCellData) { - - SimulationDataContainer container(100 , 10 , 2); - BOOST_CHECK( !container.hasCellData("FIELDX")); - BOOST_CHECK_THROW( container.getCellData("FIELDX") , std::invalid_argument ); - - container.registerCellData("FIELDX" , 1 , 123 ); - { - auto& fieldx = container.getCellData("FIELDX"); - BOOST_CHECK_EQUAL( fieldx.size() , 100U ); - for (auto v : fieldx) - BOOST_CHECK_EQUAL( v , 123 ); - - fieldx[0] *= 2; - } - - { - auto fieldx = container.getCellData("FIELDX"); - BOOST_CHECK_EQUAL( fieldx[0] , 246 ); - BOOST_CHECK_EQUAL( fieldx[1] , 123 ); - } - -} - - -BOOST_AUTO_TEST_CASE(Test_Equal) { - { - SimulationDataContainer container1(100 , 10 , 2); - SimulationDataContainer container2(100 , 10 , 2); - BOOST_CHECK( container1.equal( container2 )); - } - - { - SimulationDataContainer container1(100 , 10 , 2); - SimulationDataContainer container2(100 , 10 , 1); - BOOST_CHECK( !container1.equal( container2 )); - } - - { - SimulationDataContainer container1(100 , 10 , 2); - SimulationDataContainer container2(100 , 10 , 2); - - container1.registerCellData( "FIELDX" , 1 , 123 ); - BOOST_CHECK( !container1.equal( container2 )); - container2.registerCellData( "FIELDX" , 1 , 123 ); - BOOST_CHECK( container1.equal( container2 )); - - container1.registerFaceData( "FACEX" , 1 , 123 ); - BOOST_CHECK( !container1.equal( container2 )); - container2.registerFaceData( "FACEX" , 1 , 123 ); - BOOST_CHECK( container1.equal( container2 )); - } - - { - SimulationDataContainer container1(100 , 10 , 2); - SimulationDataContainer container2(100 , 10 , 2); - - container1.registerCellData( "FIELD1" , 1 , 123 ); - container2.registerCellData( "FIELD2" , 1 , 123 ); - BOOST_CHECK( !container1.equal( container2 )); - } - - { - SimulationDataContainer container1(100 , 10 , 2); - SimulationDataContainer container2(100 , 10 , 2); - - container1.registerFaceData( "FIELD1" , 1 , 123 ); - container2.registerFaceData( "FIELD2" , 1 , 123 ); - BOOST_CHECK( !container1.equal( container2 )); - } - - { - SimulationDataContainer container1(100 , 10 , 2); - SimulationDataContainer container2(100 , 10 , 2); - - container1.registerFaceData( "FIELD1" , 1 , 123 ); - container2.registerFaceData( "FIELD1" , 1 , 123 ); - BOOST_CHECK( container1.equal( container2 )); - - std::vector& f = container1.getFaceData( "FIELD1" ); - f[0] *= 1.1; - BOOST_CHECK( !container1.equal( container2 )); - } -} - - - -BOOST_AUTO_TEST_CASE(TestSetComponent) { - - SimulationDataContainer container(100 , 10 , 2); - container.registerCellData("FIELDX" , 2 , 123 ); - std::vector cells = { 1,2,3}; - std::vector cells2 = { 1,2,3,4}; - std::vector cells3 = { 1,2,100}; - std::vector values0 = {20,30,40}; - std::vector values1 = {2,3,4}; - - BOOST_CHECK_THROW( container.setCellDataComponent( "FIELDY" , 0 , cells , values0 ) , std::invalid_argument ); - BOOST_CHECK_THROW( container.setCellDataComponent( "FIELDX" , 2 , cells , values0 ) , std::invalid_argument ); - BOOST_CHECK_THROW( container.setCellDataComponent( "FIELDX" , 0 , cells2 , values0 ) , std::invalid_argument ); - BOOST_CHECK_THROW( container.setCellDataComponent( "FIELDX" , 0 , cells3 , values0 ) , std::invalid_argument ); - - container.setCellDataComponent( "FIELDX" , 0 , cells , values0 ); - container.setCellDataComponent( "FIELDX" , 1 , cells , values1 ); - const auto& data = container.getCellData( "FIELDX" ); - - BOOST_CHECK_EQUAL( data[1*2 + 1] , 2 ); - BOOST_CHECK_EQUAL( data[2*2 + 1] , 3 ); - BOOST_CHECK_EQUAL( data[3*2 + 1] , 4 ); - - BOOST_CHECK_EQUAL( data[1*2] , 20 ); - BOOST_CHECK_EQUAL( data[2*2] , 30 ); - BOOST_CHECK_EQUAL( data[3*2] , 40 ); - -}