Move FieldData to its own header for usage from simulator.

We need to refactor to make FieldData accessible from the simulator
for running in parallel with the TranCalculator.
This commit is contained in:
Markus Blatt
2020-09-17 11:46:17 +02:00
parent 1bb4c937a2
commit 967f63479d
6 changed files with 158 additions and 120 deletions
+1
View File
@@ -572,6 +572,7 @@ if(ENABLE_ECL_INPUT)
opm/parser/eclipse/EclipseState/Util/OrderedMap.hpp
opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp
opm/parser/eclipse/EclipseState/Edit/EDITNNC.hpp
opm/parser/eclipse/EclipseState/Grid/FieldData.hpp
opm/parser/eclipse/EclipseState/Grid/Keywords.hpp
opm/parser/eclipse/EclipseState/Grid/GridDims.hpp
opm/parser/eclipse/EclipseState/Grid/TranCalculator.hpp
@@ -0,0 +1,143 @@
/*
Copyright 2020 Equinor AS.
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 FIELD_DATA_HPP
#define FIELD_DATA_HPP
#include <opm/parser/eclipse/EclipseState/Grid/Box.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/Keywords.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/FieldData.hpp>
#include <opm/parser/eclipse/Deck/value_status.hpp>
#include<string>
#include<vector>
#include<optional>
#include<array>
namespace Opm
{
template<typename T>
static void fieldprops_compress(std::vector<T>& data, const std::vector<bool>& active_map) {
std::size_t shift = 0;
for (std::size_t g = 0; g < active_map.size(); g++) {
if (active_map[g] && shift > 0) {
data[g - shift] = data[g];
continue;
}
if (!active_map[g])
shift += 1;
}
data.resize(data.size() - shift);
}
template<typename T>
struct FieldData {
std::vector<T> data;
std::vector<value::status> value_status;
keywords::keyword_info<T> kw_info;
std::optional<std::vector<T>> global_data;
std::optional<std::vector<value::status>> global_value_status;
mutable bool all_set;
FieldData() = default;
FieldData(const keywords::keyword_info<T>& info, std::size_t active_size, std::size_t global_size) :
data(std::vector<T>(active_size)),
value_status(active_size, value::status::uninitialized),
kw_info(info),
all_set(false)
{
if (global_size != 0) {
this->global_data = std::vector<T>(global_size);
this->global_value_status = std::vector<value::status>(global_size, value::status::uninitialized);
}
if (info.scalar_init)
this->default_assign( *info.scalar_init );
}
std::size_t size() const {
return this->data.size();
}
bool valid() const {
if (this->all_set)
return true;
static const std::array<value::status,2> invalid_value = {value::status::uninitialized, value::status::empty_default};
const auto& it = std::find_first_of(this->value_status.begin(), this->value_status.end(), invalid_value.begin(), invalid_value.end());
this->all_set = (it == this->value_status.end());
return this->all_set;
}
void compress(const std::vector<bool>& active_map) {
fieldprops_compress(this->data, active_map);
fieldprops_compress(this->value_status, active_map);
}
void copy(const FieldData<T>& src, const std::vector<Box::cell_index>& index_list) {
for (const auto& ci : index_list) {
this->data[ci.active_index] = src.data[ci.active_index];
this->value_status[ci.active_index] = src.value_status[ci.active_index];
}
}
void default_assign(T value) {
std::fill(this->data.begin(), this->data.end(), value);
std::fill(this->value_status.begin(), this->value_status.end(), value::status::valid_default);
if (this->global_data) {
std::fill(this->global_data->begin(), this->global_data->end(), value);
std::fill(this->global_value_status->begin(), this->global_value_status->end(), value::status::valid_default);
}
}
void default_assign(const std::vector<T>& src) {
if (src.size() != this->size())
throw std::invalid_argument("Size mismatch got: " + std::to_string(src.size()) + " expected: " + std::to_string(this->size()));
std::copy(src.begin(), src.end(), this->data.begin());
std::fill(this->value_status.begin(), this->value_status.end(), value::status::valid_default);
}
void default_update(const std::vector<T>& src) {
if (src.size() != this->size())
throw std::invalid_argument("Size mismatch got: " + std::to_string(src.size()) + " expected: " + std::to_string(this->size()));
for (std::size_t i = 0; i < src.size(); i++) {
if (!value::has_value(this->value_status[i])) {
this->value_status[i] = value::status::valid_default;
this->data[i] = src[i];
}
}
}
void update(std::size_t index, T value, value::status status) {
this->data[index] = value;
this->value_status[index] = status;
}
};
} // end namespace Opm
#endif // FIELD_DATA_HPP
@@ -22,6 +22,7 @@
#include <memory>
#include <vector>
#include <opm/parser/eclipse/EclipseState/Grid/TranCalculator.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/FieldData.hpp>
namespace Opm {
@@ -152,7 +152,7 @@ void verify_deck_data(const DeckKeyword& keyword, const std::vector<T>& deck_dat
template <typename T>
void assign_deck(const keywords::keyword_info<T>& kw_info, const DeckKeyword& keyword, FieldProps::FieldData<T>& field_data, const std::vector<T>& deck_data, const std::vector<value::status>& deck_status, const Box& box) {
void assign_deck(const keywords::keyword_info<T>& kw_info, const DeckKeyword& keyword, FieldData<T>& field_data, const std::vector<T>& deck_data, const std::vector<value::status>& deck_status, const Box& box) {
verify_deck_data(keyword, deck_data, box);
for (const auto& cell_index : box.index_list()) {
auto active_index = cell_index.active_index;
@@ -182,7 +182,7 @@ void assign_deck(const keywords::keyword_info<T>& kw_info, const DeckKeyword& ke
template <typename T>
void multiply_deck(const keywords::keyword_info<T>& kw_info, const DeckKeyword& keyword, FieldProps::FieldData<T>& field_data, const std::vector<T>& deck_data, const std::vector<value::status>& deck_status, const Box& box) {
void multiply_deck(const keywords::keyword_info<T>& kw_info, const DeckKeyword& keyword, FieldData<T>& field_data, const std::vector<T>& deck_data, const std::vector<value::status>& deck_status, const Box& box) {
verify_deck_data(keyword, deck_data, box);
for (const auto& cell_index : box.index_list()) {
auto active_index = cell_index.active_index;
@@ -400,17 +400,17 @@ void FieldProps::reset_actnum(const std::vector<int>& new_actnum) {
for (auto& data : this->int_data)
data.second.compress(active_map);
FieldProps::compress(this->cell_volume, active_map);
FieldProps::compress(this->cell_depth, active_map);
fieldprops_compress(this->cell_volume, active_map);
fieldprops_compress(this->cell_depth, active_map);
this->m_actnum = std::move(new_actnum);
this->active_size = new_active_size;
}
void FieldProps::distribute_toplayer(FieldProps::FieldData<double>& field_data, const std::vector<double>& deck_data, const Box& box) {
void FieldProps::distribute_toplayer(FieldData<double>& field_data, const std::vector<double>& deck_data, const Box& box) {
const std::size_t layer_size = this->nx * this->ny;
FieldProps::FieldData<double> toplayer(field_data.kw_info, layer_size, 0);
FieldData<double> toplayer(field_data.kw_info, layer_size, 0);
for (const auto& cell_index : box.index_list()) {
if (cell_index.global_index < layer_size) {
toplayer.data[cell_index.global_index] = deck_data[cell_index.data_index];
@@ -475,7 +475,7 @@ bool FieldProps::supported<int>(const std::string& keyword) {
template <>
FieldProps::FieldData<double>& FieldProps::init_get(const std::string& keyword, const keywords::keyword_info<double>& kw_info) {
FieldData<double>& FieldProps::init_get(const std::string& keyword, const keywords::keyword_info<double>& kw_info) {
auto iter = this->double_data.find(keyword);
if (iter != this->double_data.end())
return iter->second;
@@ -495,14 +495,14 @@ FieldProps::FieldData<double>& FieldProps::init_get(const std::string& keyword,
}
template <>
FieldProps::FieldData<double>& FieldProps::init_get(const std::string& keyword) {
FieldData<double>& FieldProps::init_get(const std::string& keyword) {
keywords::keyword_info<double> kw_info = keywords::global_kw_info<double>(keyword);
return this->init_get(keyword, kw_info);
}
template <>
FieldProps::FieldData<int>& FieldProps::init_get(const std::string& keyword, const keywords::keyword_info<int>& kw_info) {
FieldData<int>& FieldProps::init_get(const std::string& keyword, const keywords::keyword_info<int>& kw_info) {
auto iter = this->int_data.find(keyword);
if (iter != this->int_data.end())
return iter->second;
@@ -512,7 +512,7 @@ FieldProps::FieldData<int>& FieldProps::init_get(const std::string& keyword, con
}
template <>
FieldProps::FieldData<int>& FieldProps::init_get(const std::string& keyword) {
FieldData<int>& FieldProps::init_get(const std::string& keyword) {
if (keywords::isFipxxx(keyword)) {
auto kw_info = keywords::keyword_info<int>{};
kw_info.init(1);
@@ -34,6 +34,7 @@
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/Keywords.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/TranCalculator.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/FieldData.hpp>
namespace Opm {
@@ -262,21 +263,6 @@ public:
};
template<typename T>
static void compress(std::vector<T>& data, const std::vector<bool>& active_map) {
std::size_t shift = 0;
for (std::size_t g = 0; g < active_map.size(); g++) {
if (active_map[g] && shift > 0) {
data[g - shift] = data[g];
continue;
}
if (!active_map[g])
shift += 1;
}
data.resize(data.size() - shift);
}
enum class GetStatus {
OK = 1,
@@ -287,99 +273,6 @@ public:
template<typename T>
struct FieldData {
std::vector<T> data;
std::vector<value::status> value_status;
keywords::keyword_info<T> kw_info;
std::optional<std::vector<T>> global_data;
std::optional<std::vector<value::status>> global_value_status;
mutable bool all_set;
FieldData() = default;
FieldData(const keywords::keyword_info<T>& info, std::size_t active_size, std::size_t global_size) :
data(std::vector<T>(active_size)),
value_status(active_size, value::status::uninitialized),
kw_info(info),
all_set(false)
{
if (global_size != 0) {
this->global_data = std::vector<T>(global_size);
this->global_value_status = std::vector<value::status>(global_size, value::status::uninitialized);
}
if (info.scalar_init)
this->default_assign( *info.scalar_init );
}
std::size_t size() const {
return this->data.size();
}
bool valid() const {
if (this->all_set)
return true;
static const std::array<value::status,2> invalid_value = {value::status::uninitialized, value::status::empty_default};
const auto& it = std::find_first_of(this->value_status.begin(), this->value_status.end(), invalid_value.begin(), invalid_value.end());
this->all_set = (it == this->value_status.end());
return this->all_set;
}
void compress(const std::vector<bool>& active_map) {
FieldProps::compress(this->data, active_map);
FieldProps::compress(this->value_status, active_map);
}
void copy(const FieldData<T>& src, const std::vector<Box::cell_index>& index_list) {
for (const auto& ci : index_list) {
this->data[ci.active_index] = src.data[ci.active_index];
this->value_status[ci.active_index] = src.value_status[ci.active_index];
}
}
void default_assign(T value) {
std::fill(this->data.begin(), this->data.end(), value);
std::fill(this->value_status.begin(), this->value_status.end(), value::status::valid_default);
if (this->global_data) {
std::fill(this->global_data->begin(), this->global_data->end(), value);
std::fill(this->global_value_status->begin(), this->global_value_status->end(), value::status::valid_default);
}
}
void default_assign(const std::vector<T>& src) {
if (src.size() != this->size())
throw std::invalid_argument("Size mismatch got: " + std::to_string(src.size()) + " expected: " + std::to_string(this->size()));
std::copy(src.begin(), src.end(), this->data.begin());
std::fill(this->value_status.begin(), this->value_status.end(), value::status::valid_default);
}
void default_update(const std::vector<T>& src) {
if (src.size() != this->size())
throw std::invalid_argument("Size mismatch got: " + std::to_string(src.size()) + " expected: " + std::to_string(this->size()));
for (std::size_t i = 0; i < src.size(); i++) {
if (!value::has_value(this->value_status[i])) {
this->value_status[i] = value::status::valid_default;
this->data[i] = src[i];
}
}
}
void update(std::size_t index, T value, value::status status) {
this->data[index] = value;
this->value_status[index] = status;
}
};
template<typename T>
struct FieldDataManager {
const std::string& keyword;
@@ -580,7 +473,7 @@ private:
void handle_operation(const DeckKeyword& keyword, Box box);
void handle_region_operation(const DeckKeyword& keyword);
void handle_COPY(const DeckKeyword& keyword, Box box, bool region);
void distribute_toplayer(FieldProps::FieldData<double>& field_data, const std::vector<double>& deck_data, const Box& box);
void distribute_toplayer(FieldData<double>& field_data, const std::vector<double>& deck_data, const Box& box);
double get_beta(const std::string& func_name, const std::string& target_array, double raw_beta);
double get_alpha(const std::string& func_name, const std::string& target_array, double raw_alpha);
+1 -1
View File
@@ -208,7 +208,7 @@ ADDREG
BOOST_AUTO_TEST_CASE(ASSIGN) {
FieldProps::FieldData<int> data({}, 100, 0);
FieldData<int> data({}, 100, 0);
std::vector<int> wrong_size(50);
BOOST_CHECK_THROW( data.default_assign( wrong_size ), std::invalid_argument );