mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
added: check command line parameters when doing a .OPMRST restart
compare command line used to create .OPMRST differ to current run and warn if they differ. safety net to avoid misunderstandings
This commit is contained in:
parent
1003bf7735
commit
c61639251f
@ -22,11 +22,14 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <opm/common/OpmLog/OpmLog.hpp>
|
#include <opm/common/OpmLog/OpmLog.hpp>
|
||||||
|
#include <opm/common/utility/String.hpp>
|
||||||
|
|
||||||
#include <opm/input/eclipse/Units/Units.hpp>
|
#include <opm/input/eclipse/Units/Units.hpp>
|
||||||
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
|
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
|
||||||
|
|
||||||
#include <boost/date_time.hpp>
|
#include <boost/date_time.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -61,4 +64,74 @@ void outputTimestampFIP(const SimulatorTimer& timer,
|
|||||||
OpmLog::note(ss.str());
|
OpmLog::note(ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkSerializedCmdLine(const std::string& current,
|
||||||
|
const std::string& stored)
|
||||||
|
{
|
||||||
|
auto filter_strings = [](const std::vector<std::string>& input)
|
||||||
|
{
|
||||||
|
std::vector<std::string> output;
|
||||||
|
output.reserve(input.size());
|
||||||
|
std::copy_if(input.begin(), input.end(), std::back_inserter(output),
|
||||||
|
[](const std::string& line)
|
||||||
|
{
|
||||||
|
return line.compare(0, 11, "EclDeckFile") != 0 &&
|
||||||
|
line.compare(0, 8, "LoadStep") != 0 &&
|
||||||
|
line.compare(0, 8, "SaveFile") != 0 &&
|
||||||
|
line.compare(0, 8, "SaveStep") != 0;
|
||||||
|
});
|
||||||
|
return output;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto curr_strings = split_string(current, '\n');
|
||||||
|
auto stored_strings = split_string(stored, '\n');
|
||||||
|
std::sort(curr_strings.begin(), curr_strings.end());
|
||||||
|
std::sort(stored_strings.begin(), stored_strings.end());
|
||||||
|
curr_strings = filter_strings(curr_strings);
|
||||||
|
stored_strings = filter_strings(stored_strings);
|
||||||
|
|
||||||
|
std::vector<std::string> difference;
|
||||||
|
std::set_symmetric_difference(stored_strings.begin(), stored_strings.end(),
|
||||||
|
curr_strings.begin(), curr_strings.end(),
|
||||||
|
std::back_inserter(difference));
|
||||||
|
|
||||||
|
std::vector<std::string> only_stored, only_curr;
|
||||||
|
if (!difference.empty()) {
|
||||||
|
for (size_t i = 0; i < difference.size(); ) {
|
||||||
|
auto stored_it = std::find(stored_strings.begin(),
|
||||||
|
stored_strings.end(), difference[i]);
|
||||||
|
auto pos = difference[i].find_first_of('=');
|
||||||
|
if (i < difference.size() - 1 &&
|
||||||
|
difference[i].compare(0, pos, difference[i+1], 0, pos) == 0) {
|
||||||
|
if (stored_it == stored_strings.end()) {
|
||||||
|
std::swap(difference[i], difference[i+1]);
|
||||||
|
}
|
||||||
|
i += 2;
|
||||||
|
} else {
|
||||||
|
if (stored_it == stored_strings.end()) {
|
||||||
|
only_curr.push_back(difference[i]);
|
||||||
|
} else {
|
||||||
|
only_stored.push_back(difference[i]);
|
||||||
|
}
|
||||||
|
difference.erase(difference.begin() + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::stringstream str;
|
||||||
|
str << "Differences:\n";
|
||||||
|
for (std::size_t i = 0; i < difference.size(); ++i) {
|
||||||
|
str << '\t' << (i % 2 == 0 ? '-' : '+') << difference[i] << '\n';
|
||||||
|
}
|
||||||
|
if (!only_stored.empty()) {
|
||||||
|
str << "Only in serialized parameters:\n";
|
||||||
|
for (const std::string& line : only_stored)
|
||||||
|
str << '\t' << line << '\n';
|
||||||
|
}
|
||||||
|
if (!only_curr.empty()) {
|
||||||
|
str << "Only in current parameters:\n";
|
||||||
|
for (const std::string& line : only_curr)
|
||||||
|
str << '\t' << line << '\n';
|
||||||
|
}
|
||||||
|
OpmLog::warning("Command line parameters mismatch:\n" + str.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Opm
|
} // namespace Opm
|
||||||
|
@ -135,6 +135,8 @@ void outputReportStep(const SimulatorTimer& timer);
|
|||||||
void outputTimestampFIP(const SimulatorTimer& timer,
|
void outputTimestampFIP(const SimulatorTimer& timer,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& version);
|
const std::string& version);
|
||||||
|
void checkSerializedCmdLine(const std::string& current,
|
||||||
|
const std::string& stored);
|
||||||
|
|
||||||
/// a simulator for the blackoil model
|
/// a simulator for the blackoil model
|
||||||
template<class TypeTag>
|
template<class TypeTag>
|
||||||
@ -665,6 +667,12 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (EclGenericVanguard::comm().rank() == 0) {
|
||||||
|
std::ostringstream str;
|
||||||
|
Parameters::printValues<TypeTag>(str);
|
||||||
|
checkSerializedCmdLine(str.str(), strings[4]);
|
||||||
|
}
|
||||||
|
|
||||||
OPM_END_PARALLEL_TRY_CATCH("Error loading serialized state: ",
|
OPM_END_PARALLEL_TRY_CATCH("Error loading serialized state: ",
|
||||||
EclGenericVanguard::comm());
|
EclGenericVanguard::comm());
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user