ecl_sum_file_data.hpp
Go to the documentation of this file.
1#include <vector>
2#include <memory>
3#include <array>
4
5#include <ert/util/vector.hpp>
6
10
11namespace ecl {
12
13#define INVALID_MINISTEP_NR -1
14#define INVALID_TIME_T 0
15
16
17struct IndexNode {
18
23{}
24
25 time_t sim_time;
28};
29
30
31class TimeIndex {
32public:
33
34 void add(time_t sim_time, double sim_seconds, int report_step) {
35 int internal_index = static_cast<int>(this->nodes.size());
36 this->nodes.emplace_back(sim_time, sim_seconds, report_step);
37
38 /* Indexing internal_index - report_step */
39 if (static_cast<int>(this->report_map.size()) <= report_step)
40 this->report_map.resize( report_step + 1, std::pair<int,int>(std::numeric_limits<int>::max(), -1));
41
42 auto& range = this->report_map[report_step];
43 range.first = std::min(range.first, internal_index);
44 range.second = std::max(range.second, internal_index);
45 }
46
47
48 bool has_report(int report_step) const {
49 if (report_step >= static_cast<int>(this->report_map.size()))
50 return false;
51
52 const auto& range_pair = this->report_map[report_step];
53 if (range_pair.second < 0)
54 return false;
55
56 return true;
57 }
58
59
60 void clear() {
61 this->nodes.clear();
62 this->report_map.clear();
63 }
64
65 const IndexNode& operator[](size_t index) const {
66 return this->nodes[index];
67 }
68
69 const IndexNode& back() const {
70 return this->nodes.back();
71 }
72
73 size_t size() const {
74 return this->nodes.size();
75 }
76
77 std::pair<int,int>& report_range(int report_step) {
78 return this->report_map[report_step];
79 }
80
81 const std::pair<int,int>& report_range(int report_step) const {
82 return this->report_map[report_step];
83 }
84
85private:
86 std::vector<IndexNode> nodes;
87 std::vector<std::pair<int,int>> report_map;
88};
89
90
91class unsmry_loader;
92
94
95public:
98 const ecl_smspec_type * smspec() const;
99
100 int length_before(time_t end_time) const;
101 void get_time(int length, time_t *data);
102 void get_data(int params_index, int length, double *data);
103 int length() const;
104 time_t get_data_start() const;
105 time_t get_sim_end() const;
106 double iget( int time_index , int params_index ) const;
107 time_t iget_sim_time(int time_index ) const;
108 double iget_sim_days(int time_index ) const;
109 double iget_sim_seconds(int time_index ) const;
110 ecl_sum_tstep_type * iget_ministep( int internal_index ) const;
111 double get_days_start() const;
112 double get_sim_length() const;
113
114 std::pair<int,int> report_range(int report_step) const;
115 bool report_step_equal( const ecl_sum_file_data& other, bool strict) const;
116 int report_before(time_t end_time) const;
117 int get_time_report(int max_internal_index, time_t *data);
118 int get_data_report(int params_index, int max_internal_index, double *data, double default_value);
119 int first_report() const;
120 int last_report() const;
121 int iget_report(int time_index) const;
122 bool has_report(int report_step ) const;
123 int report_step_from_days(double sim_days) const;
124 int report_step_from_time(time_t sim_time) const;
125
126 ecl_sum_tstep_type * add_new_tstep(int report_step , double sim_seconds);
127 bool can_write() const;
128 void fwrite_unified( fortio_type * fortio ) const;
129 void fwrite_multiple( const char * ecl_case , bool fmt_case ) const;
130 bool fread(const stringlist_type * filelist, bool lazy_load, int file_options);
131
132private:
133 const ecl_smspec_type * ecl_smspec;
134
135 TimeIndex index;
136 vector_type * data;
137
138 std::unique_ptr<ecl::unsmry_loader> loader;
139
140 void append_tstep(ecl_sum_tstep_type * tstep);
141 void build_index();
142 void fwrite_report( int report_step , fortio_type * fortio) const;
143 bool check_file( ecl_file_type * ecl_file );
144 void add_ecl_file(int report_step, const ecl_file_view_type * summary_view);
145};
146
147
148
149
150}
struct ecl_file_struct ecl_file_type
Definition: ECLResultData.hpp:39
int index
Definition: cJSON.h:168
Definition: ecl_sum_file_data.hpp:31
bool has_report(int report_step) const
Definition: ecl_sum_file_data.hpp:48
std::pair< int, int > & report_range(int report_step)
Definition: ecl_sum_file_data.hpp:77
void add(time_t sim_time, double sim_seconds, int report_step)
Definition: ecl_sum_file_data.hpp:34
const std::pair< int, int > & report_range(int report_step) const
Definition: ecl_sum_file_data.hpp:81
void clear()
Definition: ecl_sum_file_data.hpp:60
const IndexNode & back() const
Definition: ecl_sum_file_data.hpp:69
size_t size() const
Definition: ecl_sum_file_data.hpp:73
const IndexNode & operator[](size_t index) const
Definition: ecl_sum_file_data.hpp:65
Definition: ecl_sum_file_data.hpp:93
int report_before(time_t end_time) const
void fwrite_multiple(const char *ecl_case, bool fmt_case) const
void get_time(int length, time_t *data)
bool has_report(int report_step) const
double iget_sim_seconds(int time_index) const
int report_step_from_days(double sim_days) const
double iget_sim_days(int time_index) const
const ecl_smspec_type * smspec() const
double iget(int time_index, int params_index) const
int report_step_from_time(time_t sim_time) const
int get_data_report(int params_index, int max_internal_index, double *data, double default_value)
std::pair< int, int > report_range(int report_step) const
ecl_sum_tstep_type * iget_ministep(int internal_index) const
bool report_step_equal(const ecl_sum_file_data &other, bool strict) const
int iget_report(int time_index) const
time_t iget_sim_time(int time_index) const
time_t get_data_start() const
double get_days_start() const
bool fread(const stringlist_type *filelist, bool lazy_load, int file_options)
bool can_write() const
ecl_sum_tstep_type * add_new_tstep(int report_step, double sim_seconds)
ecl_sum_file_data(const ecl_smspec_type *smspec)
int first_report() const
int get_time_report(int max_internal_index, time_t *data)
void get_data(int params_index, int length, double *data)
double get_sim_length() const
void fwrite_unified(fortio_type *fortio) const
int length_before(time_t end_time) const
time_t get_sim_end() const
struct ecl_file_view_struct ecl_file_view_type
Definition: ecl_file_view.hpp:50
struct ecl_smspec_struct ecl_smspec_type
Definition: ecl_smspec.hpp:32
struct ecl_sum_tstep_struct ecl_sum_tstep_type
Definition: ecl_sum_tstep.hpp:31
struct fortio_struct fortio_type
Definition: include/ert/ecl/fortio.h:42
Definition: ecl_box.hpp:26
T min(const T v0, const T v1)
Definition: exprtk.hpp:1400
T max(const T v0, const T v1)
Definition: exprtk.hpp:1407
struct stringlist_struct stringlist_type
Definition: stringlist.hpp:34
Definition: ecl_sum_file_data.hpp:17
int report_step
Definition: ecl_sum_file_data.hpp:27
double sim_seconds
Definition: ecl_sum_file_data.hpp:26
IndexNode(time_t sim_time, double sim_seconds, int report_step)
Definition: ecl_sum_file_data.hpp:19
time_t sim_time
Definition: ecl_sum_file_data.hpp:25
struct vector_struct vector_type
Definition: vector.hpp:33