-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathFieldProps.cpp
2344 lines (1975 loc) · 81.6 KB
/
FieldProps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
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/>.
*/
#include <opm/input/eclipse/EclipseState/Grid/FieldProps.hpp>
#include <opm/common/ErrorMacros.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/utility/OpmInputError.hpp>
#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/NumericalAquifers.hpp>
#include <opm/input/eclipse/EclipseState/Grid/Box.hpp>
#include <opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/input/eclipse/EclipseState/Grid/FieldPropsManager.hpp> // Layering violation. Needed for apply_tran() function.
#include <opm/input/eclipse/EclipseState/Grid/Keywords.hpp>
#include <opm/input/eclipse/EclipseState/Grid/SatfuncPropertyInitializers.hpp>
#include <opm/input/eclipse/EclipseState/Runspec.hpp>
#include <opm/input/eclipse/EclipseState/Tables/RtempvdTable.hpp>
#include <opm/input/eclipse/EclipseState/Tables/TableManager.hpp>
#include <opm/input/eclipse/EclipseState/Util/OrderedMap.hpp>
#include <opm/input/eclipse/Units/UnitSystem.hpp>
#include <opm/input/eclipse/Deck/Deck.hpp>
#include <opm/input/eclipse/Parser/ParserKeywords/A.hpp>
#include <opm/input/eclipse/Parser/ParserKeywords/B.hpp>
#include <opm/input/eclipse/Parser/ParserKeywords/C.hpp>
#include <opm/input/eclipse/Parser/ParserKeywords/E.hpp>
#include <opm/input/eclipse/Parser/ParserKeywords/M.hpp>
#include <opm/input/eclipse/Parser/ParserKeywords/O.hpp>
#include <opm/input/eclipse/Parser/ParserKeywords/P.hpp>
#include <opm/input/eclipse/Parser/ParserKeywords/T.hpp>
#include "Operate.hpp"
#include <algorithm>
#include <array>
#include <cstddef>
#include <functional>
#include <optional>
#include <set>
#include <stdexcept>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <fmt/format.h>
namespace {
Opm::Box makeGlobalGridBox(const Opm::EclipseGrid* gridPtr,
const std::vector<int>* actnum = nullptr,
const std::unordered_map<int, int>* index = nullptr)
{
return Opm::Box {
*gridPtr,
[gridPtr, actnum](const std::size_t global_index)
{
if (!actnum || actnum->empty()) {
return gridPtr->cellActive(global_index);
}
if (actnum->empty()) {
return true;
} else if (global_index >= actnum->size()) {
return false;
} else {
return (*actnum)[global_index] > 0;
}
},
[gridPtr, index](const std::size_t global_index) -> std::size_t
{
if (!index || index->empty()) {
return gridPtr->activeIndex(global_index);
}
const auto it = index->find(global_index);
assert(it != index->end());
return it->second;
}
};
}
bool is_capillary_pressure(const std::string& keyword)
{
return (keyword == "PCW") || (keyword == "PCG")
|| (keyword == "IPCG") || (keyword == "IPCW");
}
} // Anonymous namespace
namespace Opm {
namespace Fieldprops { namespace keywords {
namespace {
std::string get_keyword_from_alias(const std::string& name)
{
auto kwPos = ALIAS::aliased_keywords.find(name);
return (kwPos == ALIAS::aliased_keywords.end())
? name : kwPos->second;
}
} // Anonymous namespace
static const std::set<std::string> oper_keywords = {"ADD", "EQUALS", "MAXVALUE", "MINVALUE", "MULTIPLY"};
static const std::set<std::string> region_oper_keywords = {"MULTIREG", "ADDREG", "EQUALREG", "OPERATER"};
static const std::set<std::string> box_keywords = {"BOX", "ENDBOX"};
bool is_oper_keyword(const std::string& name)
{
return (oper_keywords.find(name) != oper_keywords.end()
|| region_oper_keywords.find(name) != region_oper_keywords.end());
}
template <>
keyword_info<double>
global_kw_info(const std::string& name, const bool allow_unsupported)
{
if (auto kwPos = GRID::double_keywords.find(name);
kwPos != GRID::double_keywords.end())
{
return kwPos->second;
}
if (auto kwPos = EDIT::double_keywords.find(name);
kwPos != EDIT::double_keywords.end())
{
return kwPos->second;
}
if (auto kwPos = PROPS::double_keywords.find(name);
kwPos != PROPS::double_keywords.end())
{
return kwPos->second;
}
if (PROPS::satfunc.count(name)) {
return keyword_info<double>{};
}
if (auto kwPos = SOLUTION::double_keywords.find(name);
kwPos != SOLUTION::double_keywords.end())
{
return kwPos->second;
}
if (auto kwPos = SOLUTION::composition_keywords.find(name);
kwPos != SOLUTION::composition_keywords.end())
{
return kwPos->second;
}
if (auto kwPos = SCHEDULE::double_keywords.find(name);
kwPos != SCHEDULE::double_keywords.end())
{
return kwPos->second;
}
if (allow_unsupported) {
return keyword_info<double>{};
}
throw std::out_of_range {
fmt::format("INFO: '{}' is not a double precision property.", name)
};
}
template <>
keyword_info<int>
global_kw_info(const std::string& name, bool)
{
if (auto kwPos = GRID::int_keywords.find(name);
kwPos != GRID::int_keywords.end())
{
return kwPos->second;
}
if (auto kwPos = EDIT::int_keywords.find(name);
kwPos != EDIT::int_keywords.end())
{
return kwPos->second;
}
if (auto kwPos = PROPS::int_keywords.find(name);
kwPos != PROPS::int_keywords.end())
{
return kwPos->second;
}
if (auto kwPos = REGIONS::int_keywords.find(name);
kwPos != REGIONS::int_keywords.end())
{
return kwPos->second;
}
if (auto kwPos = SCHEDULE::int_keywords.find(name);
kwPos != SCHEDULE::int_keywords.end())
{
return kwPos->second;
}
if (isFipxxx(name)) {
return keyword_info<int>{}.init(1);
}
throw std::out_of_range {
fmt::format("INFO: '{}' is not an integer property", name)
};
}
}} // namespace Fieldprops::keywords
namespace {
// The EQUALREG, MULTREG, COPYREG, ... keywords are used to manipulate
// vectors based on region values; for instance the statement
//
// EQUALREG
// PORO 0.25 3 / -- Region array not specified
// PERMX 100 3 F /
// /
//
// will set the PORO field to 0.25 for all cells in region 3 and the PERMX
// value to 100 mD for the same cells. The fourth optional argument to the
// EQUALREG keyword is used to indicate which REGION array should be used
// for the selection.
//
// If the REGION array is not indicated (as in the PORO case) above, the
// default region to use in the xxxREG keywords depends on the GRIDOPTS
// keyword:
//
// 1. If GRIDOPTS is present, and the NRMULT item is greater than zero,
// the xxxREG keywords will default to use the MULTNUM region.
//
// 2. If the GRIDOPTS keyword is not present - or the NRMULT item equals
// zero, the xxxREG keywords will default to use the FLUXNUM keyword.
//
// This quite weird behaviour comes from reading the GRIDOPTS and MULTNUM
// documentation, and practical experience with ECLIPSE simulations.
// Unfortunately the documentation of the xxxREG keywords does not confirm
// this.
std::string default_region_keyword(const Deck& deck)
{
if (deck.hasKeyword("GRIDOPTS")) {
const auto& gridOpts = deck["GRIDOPTS"].back();
const auto& record = gridOpts.getRecord(0);
const auto& nrmult_item = record.getItem("NRMULT");
if (nrmult_item.get<int>(0) > 0) {
return "MULTNUM"; // GRIDOPTS and positive NRMULT
}
}
return "FLUXNUM";
}
void reject_undefined_operation(const KeywordLocation& loc,
const std::size_t numUnInit,
const std::size_t numElements,
std::string_view operation,
std::string_view arrayName)
{
const auto* plural = (numElements > 1) ? "s" : "";
throw OpmInputError {
fmt::format
(R"({0} operation on array {1} would
generate an undefined result in {2} out of {3} block{4}.)",
operation, arrayName, numUnInit, numElements, plural),
loc
};
}
template <typename T>
void verify_deck_data(const Fieldprops::keywords::keyword_info<T>& kw_info,
const DeckKeyword& keyword,
const std::vector<T>& deck_data,
const Box& box)
{
// there can be multiple values for each grid cell
if (box.size() * kw_info.num_value != deck_data.size()) {
const auto& location = keyword.location();
std::string msg = "Fundamental error with keyword: " + keyword.name() +
" at: " + location.filename + ", line: " + std::to_string(location.lineno) +
" got " + std::to_string(deck_data.size()) + " elements - expected : " + std::to_string(box.size() * kw_info.num_value);
throw std::invalid_argument(msg);
}
}
void log_empty_region(const DeckKeyword& keyword,
const std::string& region_name,
const int region_id,
const std::string& array_name)
{
const auto message =
fmt::format(R"(Region {} of {} has no active cells when processing operation {} on array {}.
Please check whether this is on purpose or if you did not properly define this region set.)",
region_id, region_name, keyword.name(), array_name);
OpmLog::warning(Log::fileMessage(keyword.location(), message));
}
template <typename T>
void assign_deck(const Fieldprops::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)
{
verify_deck_data(kw_info, keyword, deck_data, box);
for (const auto& cell_index : box.index_list()) {
auto active_index = cell_index.active_index;
auto data_index = cell_index.data_index;
for (size_t i = 0; i < kw_info.num_value; ++i) {
auto deck_data_index = i* box.size() + data_index;
if (value::has_value(deck_status[deck_data_index])) {
auto data_active_index = i * box.size() + active_index;
if (deck_status[deck_data_index] == value::status::deck_value ||
field_data.value_status[data_active_index] == value::status::uninitialized) {
field_data.data[data_active_index] = deck_data[deck_data_index];
field_data.value_status[data_active_index] = deck_status[deck_data_index];
}
}
}
}
if (kw_info.global) {
auto& global_data = field_data.global_data.value();
auto& global_status = field_data.global_value_status.value();
const auto& index_list = box.global_index_list();
for (const auto& cell : index_list) {
if ((deck_status[cell.data_index] == value::status::deck_value) ||
(global_status[cell.global_index] == value::status::uninitialized))
{
global_data[cell.global_index] = deck_data[cell.data_index];
global_status[cell.global_index] = deck_status[cell.data_index];
}
}
}
}
template <typename T>
void multiply_deck(const Fieldprops::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)
{
verify_deck_data(kw_info, keyword, deck_data, box);
for (const auto& cell_index : box.index_list()) {
auto active_index = cell_index.active_index;
auto data_index = cell_index.data_index;
if (value::has_value(deck_status[data_index]) &&
value::has_value(field_data.value_status[active_index]))
{
field_data.data[active_index] *= deck_data[data_index];
field_data.value_status[active_index] = deck_status[data_index];
}
}
if (kw_info.global) {
auto& global_data = field_data.global_data.value();
auto& global_status = field_data.global_value_status.value();
const auto& index_list = box.global_index_list();
for (const auto& cell : index_list) {
if ((deck_status[cell.data_index] == value::status::deck_value) ||
(global_status[cell.global_index] == value::status::uninitialized))
{
global_data[cell.global_index] *= deck_data[cell.data_index];
global_status[cell.global_index] = deck_status[cell.data_index];
}
}
}
}
template <typename T>
void assign_scalar(std::vector<T>& data,
std::vector<value::status>& value_status,
const T value,
const std::vector<Box::cell_index>& index_list)
{
for (const auto& cell_index : index_list) {
data[cell_index.active_index] = value;
value_status[cell_index.active_index] = value::status::deck_value;
}
}
template <typename T>
void multiply_scalar(const KeywordLocation& loc,
std::string_view arrayName,
std::vector<T>& data,
std::vector<value::status>& value_status,
const T value,
const std::vector<Box::cell_index>& index_list)
{
auto unInit = 0;
for (const auto& cell_index : index_list) {
const auto ix = cell_index.active_index;
if (value::has_value(value_status[ix])) {
data[ix] *= value;
}
else {
++unInit;
}
}
if (unInit > 0) {
reject_undefined_operation(loc, unInit,
index_list.size(),
"Multiplication", arrayName);
}
}
template <typename T>
void add_scalar(const KeywordLocation& loc,
std::string_view arrayName,
std::vector<T>& data,
std::vector<value::status>& value_status,
const T value,
const std::vector<Box::cell_index>& index_list)
{
auto unInit = 0;
for (const auto& cell_index : index_list) {
const auto ix = cell_index.active_index;
if (value::has_value(value_status[ix])) {
data[ix] += value;
}
else {
++unInit;
}
}
if (unInit > 0) {
reject_undefined_operation(loc, unInit,
index_list.size(),
"Addition", arrayName);
}
}
template <typename T>
void min_value(const KeywordLocation& loc,
std::string_view arrayName,
std::vector<T>& data,
std::vector<value::status>& value_status,
const T value,
const std::vector<Box::cell_index>& index_list)
{
auto unInit = 0;
for (const auto& cell_index : index_list) {
const auto ix = cell_index.active_index;
if (value::has_value(value_status[ix])) {
data[ix] = std::max(data[ix], value);
}
else {
++unInit;
}
}
if (unInit > 0) {
reject_undefined_operation(loc, unInit,
index_list.size(),
"Minimum threshold",
arrayName);
}
}
template <typename T>
void max_value(const KeywordLocation& loc,
std::string_view arrayName,
std::vector<T>& data,
std::vector<value::status>& value_status,
const T value,
const std::vector<Box::cell_index>& index_list)
{
auto unInit = 0;
for (const auto& cell_index : index_list) {
const auto ix = cell_index.active_index;
if (value::has_value(value_status[ix])) {
data[ix] = std::min(data[ix], value);
}
else {
++unInit;
}
}
if (unInit > 0) {
reject_undefined_operation(loc, unInit,
index_list.size(),
"Maximum threshold",
arrayName);
}
}
template<typename T>
void update_global_from_local(Fieldprops::FieldData<T>& data,
const std::vector<Box::cell_index>& index_list)
{
if(data.global_data)
{
auto& to = *data.global_data;
auto to_st = *data.global_value_status;
const auto& from = data.data;
const auto& from_st = data.value_status;
for (const auto& cell_index : index_list) {
to[cell_index.global_index] = from[cell_index.active_index];
to_st[cell_index.global_index] = from_st[cell_index.active_index];
}
}
}
template <typename T>
void apply(const Fieldprops::ScalarOperation op,
const KeywordLocation& loc,
std::string_view arrayName,
std::vector<T>& data,
std::vector<value::status>& value_status,
const T scalar_value,
const std::vector<Box::cell_index>& index_list)
{
switch (op) {
case Fieldprops::ScalarOperation::EQUAL:
assign_scalar(data, value_status, scalar_value, index_list);
return;
case Fieldprops::ScalarOperation::MUL:
multiply_scalar(loc, arrayName, data, value_status, scalar_value, index_list);
return;
case Fieldprops::ScalarOperation::ADD:
add_scalar(loc, arrayName, data, value_status, scalar_value, index_list);
return;
case Fieldprops::ScalarOperation::MIN:
min_value(loc, arrayName, data, value_status, scalar_value, index_list);
return;
case Fieldprops::ScalarOperation::MAX:
max_value(loc, arrayName, data, value_status, scalar_value, index_list);
return;
}
throw std::invalid_argument {
fmt::format("'{}' is not a known operation.", static_cast<int>(op))
};
}
std::string make_region_name(const std::string& deck_value)
{
if (deck_value == "O") { return "OPERNUM"; }
if (deck_value == "F") { return "FLUXNUM"; }
if (deck_value == "M") { return "MULTNUM"; }
throw std::invalid_argument {
fmt::format("Input string '{}' is not a valid "
"region set name. Expected 'O'/'F'/'M'", deck_value)
};
}
Fieldprops::ScalarOperation fromString(const std::string& keyword)
{
if ((keyword == ParserKeywords::ADD::keywordName) ||
(keyword == ParserKeywords::ADDREG::keywordName))
{
return Fieldprops::ScalarOperation::ADD;
}
if ((keyword == ParserKeywords::EQUALS::keywordName) ||
(keyword == ParserKeywords::EQUALREG::keywordName))
{
return Fieldprops::ScalarOperation::EQUAL;
}
if ((keyword == ParserKeywords::MULTIPLY::keywordName) ||
(keyword == ParserKeywords::MULTIREG::keywordName))
{
return Fieldprops::ScalarOperation::MUL;
}
if (keyword == ParserKeywords::MINVALUE::keywordName) {
return Fieldprops::ScalarOperation::MIN;
}
if (keyword == ParserKeywords::MAXVALUE::keywordName) {
return Fieldprops::ScalarOperation::MAX;
}
throw std::invalid_argument {
fmt::format("Keyword operation ({}) not recognized", keyword)
};
}
void handle_box_keyword(const DeckKeyword& deckKeyword, Box& box)
{
if (deckKeyword.name() == ParserKeywords::BOX::keywordName) {
const auto& record = deckKeyword.getRecord(0);
box.update(record);
}
else {
box.reset();
}
}
std::vector<double> extract_cell_volume(const EclipseGrid& grid)
{
return grid.activeVolume();
}
std::vector<double> extract_cell_depth(const EclipseGrid& grid)
{
std::vector<double> cell_depth(grid.getNumActive());
for (std::size_t active_index = 0; active_index < grid.getNumActive(); ++active_index) {
cell_depth[active_index] = grid.getCellDepth(grid.getGlobalIndex(active_index));
}
return cell_depth;
}
// The rst_compare_data function compares the main std::map<std::string,
// std::vector<T>> data containers. If one of the containers contains a keyword
// *which is fully defaulted* and the other container does not contain said
// keyword - the containers are considered to be equal.
template <typename T>
bool rst_compare_data(const std::unordered_map<std::string, Fieldprops::FieldData<T>>& data1,
const std::unordered_map<std::string, Fieldprops::FieldData<T>>& data2)
{
std::unordered_set<std::string> keys;
for (const auto& [key, _] : data1) {
(void)_;
keys.insert(key);
}
for (const auto& [key, _] : data2) {
(void)_;
keys.insert(key);
}
for (const auto& key : keys) {
const auto& d1 = data1.find(key);
const auto& d2 = data2.find(key);
if (d1 == data1.end()) {
if (!d2->second.valid_default())
return false;
continue;
}
if (d2 == data2.end()) {
if (!d1->second.valid_default())
return false;
continue;
}
if (!(d1->second == d2->second))
return false;
}
return true;
}
} // Anonymous namespace
bool FieldProps::operator==(const FieldProps& other) const
{
return (this->unit_system == other.unit_system)
&& (this->nx == other.nx)
&& (this->ny == other.ny)
&& (this->nz == other.nz)
&& (this->m_phases == other.m_phases)
&& (this->m_satfuncctrl == other.m_satfuncctrl)
&& (this->m_actnum == other.m_actnum)
&& (this->cell_volume == other.cell_volume)
&& (this->cell_depth == other.cell_depth)
&& (this->m_default_region == other.m_default_region)
&& (this->m_rtep == other.m_rtep)
&& (this->tables == other.tables)
&& (this->multregp == other.multregp)
&& (this->int_data == other.int_data)
&& (this->double_data == other.double_data)
&& (this->fipreg_shortname_translation == other.fipreg_shortname_translation)
&& (this->tran == other.tran)
;
}
bool FieldProps::rst_cmp(const FieldProps& full_arg, const FieldProps& rst_arg)
{
if (!rst_compare_data(full_arg.double_data, rst_arg.double_data)) {
return false;
}
if (!rst_compare_data(full_arg.int_data, rst_arg.int_data)) {
return false;
}
if (!UnitSystem::rst_cmp(full_arg.unit_system, rst_arg.unit_system)) {
return false;
}
return (full_arg.nx == rst_arg.nx)
&& (full_arg.ny == rst_arg.ny)
&& (full_arg.nz == rst_arg.nz)
&& (full_arg.m_phases == rst_arg.m_phases)
&& (full_arg.m_satfuncctrl == rst_arg.m_satfuncctrl)
&& (full_arg.m_actnum == rst_arg.m_actnum)
&& (full_arg.cell_volume == rst_arg.cell_volume)
&& (full_arg.cell_depth == rst_arg.cell_depth)
&& (full_arg.m_default_region == rst_arg.m_default_region)
&& (full_arg.m_rtep == rst_arg.m_rtep)
&& (full_arg.tables == rst_arg.tables)
&& (full_arg.multregp == rst_arg.multregp)
&& (full_arg.tran == rst_arg.tran)
;
}
FieldProps::FieldProps(const Deck& deck,
const Phases& phases,
EclipseGrid& grid,
const TableManager& tables_arg,
const std::size_t ncomps)
: active_size(grid.getNumActive())
, global_size(grid.getCartesianSize())
, unit_system(deck.getActiveUnitSystem())
, nx(grid.getNX())
, ny(grid.getNY())
, nz(grid.getNZ())
, m_phases(phases)
, m_satfuncctrl(deck)
, m_actnum(grid.getACTNUM())
, cell_volume(extract_cell_volume(grid))
, cell_depth(extract_cell_depth(grid))
, m_default_region(default_region_keyword(deck))
, grid_ptr(&grid)
, tables(tables_arg)
{
this->tran.emplace("TRANX", "TRANX");
this->tran.emplace("TRANY", "TRANY");
this->tran.emplace("TRANZ", "TRANZ");
if (deck.hasKeyword<ParserKeywords::MULTREGP>()) {
this->processMULTREGP(deck);
}
if (DeckSection::hasGRID(deck)) {
this->scanGRIDSection(GRIDSection(deck));
}
if (DeckSection::hasEDIT(deck)) {
this->scanEDITSection(EDITSection(deck));
}
grid.resetACTNUM(this->actnum());
this->reset_actnum(grid.getACTNUM());
if (DeckSection::hasREGIONS(deck)) {
this->scanREGIONSSection(REGIONSSection(deck));
}
// Update PVTNUM/SATNUM for numerical aquifer cells
{
const auto& aqcell_tabnums = grid.getAquiferCellTabnums();
const bool has_pvtnum = this->int_data.count("PVTNUM") != 0;
const bool has_satnum = this->int_data.count("SATNUM") != 0;
std::vector<int>* pvtnum = has_pvtnum ? &(this->int_data["PVTNUM"].data) : nullptr;
std::vector<int>* satnum = has_satnum ? &(this->int_data["SATNUM"].data) : nullptr;
for (const auto& [globCell, regionID] : aqcell_tabnums) {
const auto aix = grid.activeIndex(globCell);
if (has_pvtnum) { (*pvtnum)[aix] = std::max(regionID[0], (*pvtnum)[aix]); }
if (has_satnum) { (*satnum)[aix] = std::max(regionID[1], (*satnum)[aix]); }
}
}
if (DeckSection::hasPROPS(deck)) {
this->scanPROPSSection(PROPSSection(deck));
}
if (DeckSection::hasSOLUTION(deck)) {
this->scanSOLUTIONSection(SOLUTIONSection(deck), ncomps);
}
}
// Special constructor ONLY used to get the correct ACTNUM.
// The grid argument should have all active cells.
FieldProps::FieldProps(const Deck& deck, const EclipseGrid& grid)
: active_size(grid.getNumActive())
, global_size(grid.getCartesianSize())
, unit_system(deck.getActiveUnitSystem())
, nx(grid.getNX())
, ny(grid.getNY())
, nz(grid.getNZ())
, m_phases()
, m_satfuncctrl(deck)
, m_actnum(global_size, 1) // NB! activates all at start!
, cell_volume() // NB! empty for this purpose.
, cell_depth() // NB! empty for this purpose.
, m_default_region(default_region_keyword(deck))
, grid_ptr(&grid)
, tables() // NB! empty for this purpose.
{
if (this->active_size != this->global_size) {
throw std::logic_error {
"Programmer error: FieldProps special case processing for ACTNUM "
"called with grid object that already had deactivated cells."
};
}
if (DeckSection::hasGRID(deck)) {
this->scanGRIDSectionOnlyACTNUM(GRIDSection(deck));
}
}
void FieldProps::deleteMINPVV()
{
double_data.erase("MINPVV");
}
void FieldProps::reset_actnum(const std::vector<int>& new_actnum)
{
if (this->global_size != new_actnum.size()) {
throw std::logic_error {
"reset_actnum() must be called with "
"the same number of global cells"
};
}
if (new_actnum == this->m_actnum) {
return;
}
std::vector<bool> active_map(this->active_size, true);
std::size_t active_index = 0;
std::size_t new_active_size = 0;
for (std::size_t g = 0; g < this->m_actnum.size(); ++g) {
if (this->m_actnum[g] != 0) {
if (new_actnum[g] == 0) {
active_map[active_index] = false;
}
else {
new_active_size += 1;
}
active_index += 1;
}
else if (new_actnum[g] != 0) {
throw std::logic_error {
"It is not possible to activate cells"
};
}
}
for (auto& data : this->double_data) {
data.second.compress(active_map);
}
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);
this->m_actnum = std::move(new_actnum);
this->active_size = new_active_size;
}
void FieldProps::prune_global_for_schedule_run()
{
for (auto& data : this->double_data) {
if(data.second.kw_info.local_in_schedule) {
data.second.global_data.reset();
data.second.global_value_status.reset();
}
}
for (auto& data : this->int_data) {
if(data.second.kw_info.local_in_schedule) {
data.second.global_data.reset();
data.second.global_value_status.reset();
}
}
}
void FieldProps::distribute_toplayer(Fieldprops::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);
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];
toplayer.value_status[cell_index.global_index] = value::status::deck_value;
}
}
std::size_t active_index = 0;
for (std::size_t k = 0; k < this->nz; k++) {
for (std::size_t j = 0; j < this->ny; j++) {
for (std::size_t i = 0; i < this->nx; i++) {
std::size_t g = i + j*this->nx + k*this->nx*this->ny;
if (this->m_actnum[g]) {
if (field_data.value_status[active_index] == value::status::uninitialized) {
std::size_t layer_index = i + j*this->nx;
if (toplayer.value_status[layer_index] == value::status::deck_value) {
field_data.data[active_index] = toplayer.data[layer_index];
field_data.value_status[active_index] = value::status::valid_default;
}
}
active_index += 1;
}
}
}
}
}
template <>
bool FieldProps::supported<double>(const std::string& keyword)
{
if (Fieldprops::keywords::GRID::double_keywords.count(keyword) != 0) {
return true;
}
if (Fieldprops::keywords::EDIT::double_keywords.count(keyword) != 0) {
return true;
}
if (Fieldprops::keywords::PROPS::double_keywords.count(keyword) != 0) {
return true;
}
if (Fieldprops::keywords::PROPS::satfunc.count(keyword) != 0) {
return true;
}
if (Fieldprops::keywords::SOLUTION::double_keywords.count(keyword) != 0 ||
Fieldprops::keywords::SOLUTION::composition_keywords.count(keyword) != 0) {
return true;
}
return false;
}
template <>
bool FieldProps::supported<int>(const std::string& keyword)
{
if (Fieldprops::keywords::REGIONS::int_keywords.count(keyword) != 0) {
return true;
}
if (Fieldprops::keywords::GRID::int_keywords.count(keyword) != 0) {
return true;
}
if (Fieldprops::keywords::SCHEDULE::int_keywords.count(keyword) != 0) {
return true;
}
return Fieldprops::keywords::isFipxxx(keyword);
}
template <>
Fieldprops::FieldData<double>&
FieldProps::init_get(const std::string& keyword_name,
const Fieldprops::keywords::keyword_info<double>& kw_info,