2019-02-01 01:57:05 -06:00
|
|
|
/*
|
|
|
|
Copyright 2019 Equinor 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-05-02 08:01:20 -05:00
|
|
|
#ifndef OPM_IO_ECLFILE_HPP
|
|
|
|
#define OPM_IO_ECLFILE_HPP
|
2019-03-28 05:55:50 -05:00
|
|
|
|
|
|
|
#include <opm/common/ErrorMacros.hpp>
|
2019-02-01 01:57:05 -06:00
|
|
|
|
2019-05-02 08:01:20 -05:00
|
|
|
#include <opm/io/eclipse/EclIOdata.hpp>
|
|
|
|
|
2019-02-01 01:57:05 -06:00
|
|
|
#include <fstream>
|
2019-05-02 08:01:20 -05:00
|
|
|
#include <string>
|
|
|
|
#include <stdexcept>
|
2019-05-02 13:33:37 -05:00
|
|
|
#include <tuple>
|
2019-03-28 05:55:50 -05:00
|
|
|
#include <unordered_map>
|
2019-05-02 08:01:20 -05:00
|
|
|
#include <vector>
|
2019-02-01 01:57:05 -06:00
|
|
|
|
2019-05-02 08:01:20 -05:00
|
|
|
namespace Opm { namespace ecl {
|
2019-02-01 01:57:05 -06:00
|
|
|
|
2019-03-28 05:55:50 -05:00
|
|
|
class EclFile
|
2019-02-01 01:57:05 -06:00
|
|
|
{
|
|
|
|
public:
|
2019-02-27 04:04:52 -06:00
|
|
|
explicit EclFile(const std::string& filename);
|
2019-03-28 05:55:50 -05:00
|
|
|
bool formattedInput() { return formatted; }
|
|
|
|
|
|
|
|
void loadData(); // load all data
|
|
|
|
void loadData(const std::string& arrName); // load all arrays with array name equal to arrName
|
|
|
|
void loadData(int arrIndex); // load data based on array indices in vector arrIndex
|
|
|
|
void loadData(const std::vector<int>& arrIndex); // load data based on array indices in vector arrIndex
|
|
|
|
|
|
|
|
void clearData()
|
|
|
|
{
|
|
|
|
inte_array.clear();
|
|
|
|
real_array.clear();
|
|
|
|
doub_array.clear();
|
|
|
|
logi_array.clear();
|
|
|
|
char_array.clear();
|
|
|
|
}
|
|
|
|
|
2019-05-02 08:01:20 -05:00
|
|
|
using EclEntry = std::tuple<std::string, eclArrType, int>;
|
2019-03-28 05:55:50 -05:00
|
|
|
std::vector<EclEntry> getList() const;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
const std::vector<T>& get(int arrIndex);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
const std::vector<T>& get(const std::string& name);
|
|
|
|
|
|
|
|
bool hasKey(const std::string &name) const;
|
|
|
|
|
|
|
|
const std::vector<std::string>& arrayNames() const { return array_name; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool formatted;
|
|
|
|
std::string inputFilename;
|
|
|
|
|
|
|
|
std::unordered_map<int, std::vector<int>> inte_array;
|
|
|
|
std::unordered_map<int, std::vector<bool>> logi_array;
|
|
|
|
std::unordered_map<int, std::vector<double>> doub_array;
|
|
|
|
std::unordered_map<int, std::vector<float>> real_array;
|
|
|
|
std::unordered_map<int, std::vector<std::string>> char_array;
|
|
|
|
|
|
|
|
std::vector<std::string> array_name;
|
2019-05-02 08:01:20 -05:00
|
|
|
std::vector<eclArrType> array_type;
|
2019-03-28 05:55:50 -05:00
|
|
|
std::vector<int> array_size;
|
|
|
|
|
|
|
|
std::vector<unsigned long int> ifStreamPos;
|
|
|
|
|
|
|
|
std::map<std::string, int> array_index;
|
|
|
|
|
|
|
|
template<class T>
|
2019-05-02 08:01:20 -05:00
|
|
|
const std::vector<T>& getImpl(int arrIndex, eclArrType type,
|
2019-03-28 05:55:50 -05:00
|
|
|
const std::unordered_map<int, std::vector<T>>& array,
|
|
|
|
const std::string& typeStr)
|
|
|
|
{
|
|
|
|
if (array_type[arrIndex] != type) {
|
|
|
|
std::string message = "Array with index " + std::to_string(arrIndex) + " is not of type " + typeStr;
|
|
|
|
OPM_THROW(std::runtime_error, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!arrayLoaded[arrIndex]) {
|
|
|
|
loadData(arrIndex);
|
|
|
|
}
|
|
|
|
|
2019-05-02 08:01:20 -05:00
|
|
|
return array.at(arrIndex);
|
2019-03-28 05:55:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<bool> arrayLoaded;
|
2019-02-01 01:57:05 -06:00
|
|
|
|
2019-03-28 05:55:50 -05:00
|
|
|
void loadArray(std::fstream& fileH, int arrIndex);
|
|
|
|
};
|
2019-02-01 01:57:05 -06:00
|
|
|
|
2019-05-02 08:01:20 -05:00
|
|
|
}} // namespace Opm::ecl
|
|
|
|
|
|
|
|
#endif // OPM_IO_ECLFILE_HPP
|