New class for simulator -> output data exchange.
This commit is contained in:
parent
eb929077a2
commit
c60f21af84
81
opm/output/data/CellDataContainer.hpp
Normal file
81
opm/output/data/CellDataContainer.hpp
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OPM_OUTPUT_CELL_DATA_CONTAINER_HPP
|
||||
#define OPM_OUTPUT_CELL_DATA_CONTAINER_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
|
||||
#include <opm/output/data/Cells.hpp>
|
||||
|
||||
|
||||
namespace Opm {
|
||||
|
||||
/*
|
||||
The CelDataContainer class is a small class whose only purpose
|
||||
is to transport cell data, i.e. pressure, saturations and
|
||||
auxillary properties like fluid in place from the simulator to
|
||||
output layer.
|
||||
|
||||
The container consist of instances of struct data::CellData.
|
||||
*/
|
||||
|
||||
class CellDataContainer {
|
||||
public:
|
||||
/*
|
||||
The initializer_list based constructor can be used as:
|
||||
|
||||
CellDataContainer cd = {{ "PRESSURE" , UnitSystem::measure::pressure , pressure_data , true},
|
||||
{ "SWAT" , UnitSystem::measure::unity , swat_data , true}};
|
||||
*/
|
||||
CellDataContainer( std::initializer_list<data::CellData> init_list );
|
||||
CellDataContainer( std::vector<data::CellData> init_list );
|
||||
|
||||
/*
|
||||
Default constructor - create a valid empty container.
|
||||
*/
|
||||
CellDataContainer( ) = default;
|
||||
|
||||
size_t size() const;
|
||||
bool hasKeyword(const std::string& keyword) const;
|
||||
const data::CellData& getKeyword(const std::string& keyword) const;
|
||||
|
||||
/*
|
||||
Construct a struct data::CellData instance based on the
|
||||
input arguments and insert it in the container.
|
||||
*/
|
||||
void insert(const std::string& keyword, UnitSystem::measure dim, const std::vector<double>& data , bool enable_in_restart = true);
|
||||
void insert(data::CellData cell_data);
|
||||
|
||||
/*
|
||||
Iterate over the struct data::CellData instances in the container.
|
||||
*/
|
||||
std::vector<data::CellData>::const_iterator begin() const ;
|
||||
std::vector<data::CellData>::const_iterator end() const;
|
||||
private:
|
||||
std::vector<data::CellData> data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -42,6 +42,7 @@ namespace data {
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct Solution {
|
||||
/* data::Solution supports writing only some information,
|
||||
* distinguished by keys. When adding support for more values in
|
||||
|
82
src/opm/output/data/CellDataContainer.cpp
Normal file
82
src/opm/output/data/CellDataContainer.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <opm/output/data/CellDataContainer.hpp>
|
||||
#include <opm/output/data/Cells.hpp>
|
||||
|
||||
|
||||
namespace Opm {
|
||||
|
||||
CellDataContainer::CellDataContainer( std::initializer_list<data::CellData> init_list )
|
||||
: data( init_list )
|
||||
{ }
|
||||
|
||||
|
||||
CellDataContainer::CellDataContainer( std::vector<data::CellData> init_list )
|
||||
: data(std::move(init_list))
|
||||
{ }
|
||||
|
||||
|
||||
|
||||
size_t CellDataContainer::size() const {
|
||||
return this->data.size();
|
||||
}
|
||||
|
||||
|
||||
bool CellDataContainer::hasKeyword(const std::string& keyword) const {
|
||||
const auto iter = std::find_if( this->data.begin() , this->data.end() , [&keyword](const data::CellData& cd) { return cd.name == keyword; });
|
||||
return (iter != this->data.end());
|
||||
}
|
||||
|
||||
void CellDataContainer::insert(const std::string& keyword, UnitSystem::measure dim, const std::vector<double>& data , bool enable_in_restart) {
|
||||
data::CellData cd { keyword, dim , data , enable_in_restart };
|
||||
this->insert( cd );
|
||||
}
|
||||
|
||||
|
||||
void CellDataContainer::insert(data::CellData cell_data) {
|
||||
this->data.push_back( std::move(cell_data) );
|
||||
}
|
||||
|
||||
|
||||
const data::CellData& CellDataContainer::getKeyword(const std::string& keyword) const {
|
||||
const auto iter = std::find_if( this->data.begin() , this->data.end() , [&keyword](const data::CellData& cd) { return cd.name == keyword; });
|
||||
if (iter == this->data.end())
|
||||
throw std::invalid_argument("No such keyword in container: " + keyword);
|
||||
else
|
||||
return *iter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::vector<data::CellData>::const_iterator CellDataContainer::begin() const {
|
||||
return this->data.begin();
|
||||
}
|
||||
|
||||
|
||||
std::vector<data::CellData>::const_iterator CellDataContainer::end() const {
|
||||
return this->data.end();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user