@@ -79,8 +79,26 @@ void LBDataRestartReader::startup() {
79
79
}
80
80
81
81
void LBDataRestartReader::readHistory (LBDataHolder const & lbdh) {
82
+ auto find_max_data_phase = [&]() -> PhaseType {
83
+ if (lbdh.node_data_ .empty ()) {
84
+ return 0 ;
85
+ }
86
+ return std::max_element (
87
+ lbdh.node_data_ .begin (), lbdh.node_data_ .end (),
88
+ [](const auto & p1, const auto & p2) { return p1.first < p2.first ; })
89
+ ->first ;
90
+ };
91
+
92
+ // Find last phase number
93
+ auto largest_data = find_max_data_phase ();
94
+ auto largest_identical =
95
+ lbdh.identical_phases_ .size () > 0 ? *lbdh.identical_phases_ .rbegin () : 0 ;
96
+ auto largest_skipped =
97
+ lbdh.skipped_phases_ .size () > 0 ? *lbdh.skipped_phases_ .rbegin () : 0 ;
98
+ num_phases_ =
99
+ std::max (std::max (largest_data, largest_identical), largest_skipped) + 1 ;
100
+
82
101
PhaseType last_found_phase = 0 ;
83
- num_phases_ = lbdh.count_ ;
84
102
for (PhaseType phase = 0 ; phase < num_phases_; phase++) {
85
103
auto iter = lbdh.node_data_ .find (phase);
86
104
if (iter != lbdh.node_data_ .end ()) {
@@ -93,11 +111,13 @@ void LBDataRestartReader::readHistory(LBDataHolder const& lbdh) {
93
111
history_[phase]->insert (obj.first );
94
112
}
95
113
}
96
- } else if (lbdh.identical_phases_ .find (phase) != lbdh.identical_phases_ .end ()) {
114
+ } else if (
115
+ lbdh.identical_phases_ .find (phase) != lbdh.identical_phases_ .end ()) {
97
116
// Phase is identical to previous one, use the shared pointer to data from previous phase
98
117
addIdenticalPhase (phase, last_found_phase);
99
- } else if (lbdh.skipped_phases_ .find (phase) == lbdh.skipped_phases_ .end ()) {
100
- vtAbort (" Could not find data: Skipped phases needs to be listed in file metadata." );
118
+ } else if (lbdh.skipped_phases_ .find (phase) == lbdh.skipped_phases_ .end ()) {
119
+ vtAbort (" Could not find data: Skipped phases needs to be listed in file "
120
+ " metadata." );
101
121
}
102
122
}
103
123
}
0 commit comments