Skip to content

Commit

Permalink
Finish Singularity_IX_Results_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
einar90 committed Dec 10, 2018
2 parents 8ff34de + a754dfc commit 804625a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
27 changes: 21 additions & 6 deletions FieldOpt/ERTWrapper/eclsummaryreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void ECLSummaryReader::initializeTimeVector() {
for (int i = 0; i < double_vector_size(time); ++i) {
time_[i] = (double_vector_safe_iget(time, i));
}
time_[0] = 0; // For some reason this is often not 0, but something > 1e8. Probably the time since epoch.
time_[0] = GetFirstReportStep();
double_vector_free(time);
}

Expand Down Expand Up @@ -318,8 +318,11 @@ void ECLSummaryReader::initializeFieldCumulatives() {

fopt_ = std::vector<double>(time_.size(), 0.0);
if (hasFieldVar("FOPT")) {
int fopt_index = ecl_smspec_get_field_var_params_index(smspec, "FOPT");
double_vector_type * fopt = ecl_sum_alloc_data_vector(ecl_sum_, fopt_index, true);
assert(double_vector_size(fopt) == time_.size());
for (int i = 0; i < time_.size(); ++i) {
fopt_[i] = ecl_sum_get_field_var_from_sim_days(ecl_sum_, time_[i], "FOPT");
fopt_[i] = double_vector_safe_iget(fopt, i);
}
fopt_[0] = 0.0;
}
Expand All @@ -334,8 +337,11 @@ void ECLSummaryReader::initializeFieldCumulatives() {

fwpt_ = std::vector<double>(time_.size(), 0.0);
if (hasFieldVar("FWPT")) {
int fwpt_index = ecl_smspec_get_field_var_params_index(smspec, "FWPT");
double_vector_type * fwpt = ecl_sum_alloc_data_vector(ecl_sum_, fwpt_index, true);
assert(double_vector_size(fwpt) == time_.size());
for (int i = 0; i < time_.size(); ++i) {
fwpt_[i] = ecl_sum_get_field_var_from_sim_days(ecl_sum_, time_[i], "FWPT");
fwpt_[i] = double_vector_safe_iget(fwpt, i);
}
fwpt_[0] = 0.0;
}
Expand All @@ -350,8 +356,11 @@ void ECLSummaryReader::initializeFieldCumulatives() {

fgpt_ = std::vector<double>(time_.size(), 0.0);
if (hasFieldVar("FGPT")) {
int fgpt_index = ecl_smspec_get_field_var_params_index(smspec, "FGPT");
double_vector_type * fgpt = ecl_sum_alloc_data_vector(ecl_sum_, fgpt_index, true);
assert(double_vector_size(fgpt) == time_.size());
for (int i = 0; i < time_.size(); ++i) {
fgpt_[i] = ecl_sum_get_field_var_from_sim_days(ecl_sum_, time_[i], "FGPT");
fgpt_[i] = double_vector_safe_iget(fgpt, i);
}
fgpt_[0] = 0.0;
}
Expand All @@ -366,8 +375,11 @@ void ECLSummaryReader::initializeFieldCumulatives() {

fwit_ = std::vector<double>(time_.size(), 0.0);
if (hasFieldVar("FWIT")) {
int fwit_index = ecl_smspec_get_field_var_params_index(smspec, "FWIT");
double_vector_type * fwit = ecl_sum_alloc_data_vector(ecl_sum_, fwit_index, true);
assert(double_vector_size(fwit) == time_.size());
for (int i = 0; i < time_.size(); ++i) {
fwit_[i] = ecl_sum_get_field_var_from_sim_days(ecl_sum_, time_[i], "FWIT");
fwit_[i] = double_vector_safe_iget(fwit, i);
}
fwit_[0] = 0.0;
}
Expand All @@ -382,8 +394,11 @@ void ECLSummaryReader::initializeFieldCumulatives() {

fgit_ = std::vector<double>(time_.size(), 0.0);
if (hasFieldVar("FGIT")) {
int fgit_index = ecl_smspec_get_field_var_params_index(smspec, "FGIT");
double_vector_type * fgit = ecl_sum_alloc_data_vector(ecl_sum_, fgit_index, true);
assert(double_vector_size(fgit) == time_.size());
for (int i = 0; i < time_.size(); ++i) {
fgit_[i] = ecl_sum_get_field_var_from_sim_days(ecl_sum_, time_[i], "FGIT");
fgit_[i] = double_vector_safe_iget(fgit, i);
}
fgit_[0] = 0.0;
}
Expand Down
7 changes: 7 additions & 0 deletions FieldOpt/Optimization/objective/NPV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ double NPV::value() const {
double discount_factor;
int j = 1;
for (int i = 0; i < report_times.size(); i++) {
if (i < report_times.size() - 1 && (report_times[i+1] - report_times[i]) > 365) {
std::stringstream ss;
ss << "Skipping assumed pre-simulation time step " << report_times[i]
<< ". Next time step: " << report_times[i+1] << ". Ignore if this is time 0 in a restart case.";
Printer::ext_warn(ss.str(), "Optimization", "NPV");
continue;
}
if (std::fmod(report_times.at(i), 365) == 0) {
discount_factor = 1 / (1 * (pow(1 + components_->at(k)->discount, j - 1)));
discount_factor_list->append(discount_factor);
Expand Down
33 changes: 29 additions & 4 deletions FieldOpt/Simulation/simulator_interfaces/ix_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ IXSimulator::IXSimulator(Settings::Settings *settings, Model::Model *model)
}
deck_name_ = driver_file_name_.split(".afi").first();
results_ = new Results::ECLResults();
result_path_ = "";
}
void IXSimulator::Evaluate() {
copyDriverFiles();
Expand All @@ -49,8 +50,12 @@ void IXSimulator::Evaluate() {
QString::fromStdString(paths_.GetPath(Paths::SIM_EXEC_SCRIPT_FILE)),
script_args_
);
if (VERB_SIM >= 1) { Printer::info("Unmonitored simulation done. Reading results."); }
results_->ReadResults(QString::fromStdString(paths_.GetPath(Paths::SIM_WORK_DIR)) + "/SUMMARYVECS");
results_->DumpResults();
if (result_path_.size() == 0) {
setResultPath();
}
if (VERB_SIM >= 1) { Printer::info("Unmonitored simulation done. Reading results from " + result_path_.toStdString()); }
results_->ReadResults(result_path_);
updateResultsInModel();
}
bool IXSimulator::Evaluate(int timeout, int threads) {
Expand All @@ -69,9 +74,12 @@ bool IXSimulator::Evaluate(int timeout, int threads) {
QString::fromStdString(paths_.GetPath(Paths::SIM_EXEC_SCRIPT_FILE)),
script_args_, t);
if (success) {
if (VERB_SIM >= 1) { Printer::info("Simulation successful. Reading results."); }
results_->DumpResults();
results_->ReadResults(QString::fromStdString(paths_.GetPath(Paths::SIM_WORK_DIR)) + "/SUMMARYVECS");
if (result_path_.size() == 0) {
setResultPath();
}
if (VERB_SIM >= 1) { Printer::info("Simulation successful. Reading results from " + result_path_.toStdString()); }
results_->ReadResults(result_path_);
}
else {
if (VERB_SIM >= 1) { Printer::info("Simulation failed."); }
Expand Down Expand Up @@ -129,5 +137,22 @@ void IXSimulator::copyDriverFiles() {
"Simulation", "IXSimulator");
}
}
void IXSimulator::setResultPath() {
QString result_dir = QString::fromStdString(paths_.GetPath(Paths::SIM_WORK_DIR));
QString result_name;
if (VERB_SIM >= 2) Printer::ext_info("Setting simulator result path.", "Simulation", "IXSimulator");
if (FileExists(result_dir + "/SUMMARYVECS.SMSPEC")) {
result_name = "/SUMMARYVECS.SMSPEC";
}
else if (FileExists(result_dir + "/" + deck_name_ + "_SUMMARYVECS.SMSPEC")) {
result_name = "/" + deck_name_ + "_SUMMARYVECS.SMSPEC";
}
else {
Printer::error("Unable to find summary file. Aborting.");
exit(1);
}
result_path_ = result_dir + result_name;
if (VERB_SIM >= 2) Printer::ext_info("Set simulator result path to " + result_path_.toStdString(), "Simulation", "IXSimulator");
}

}
2 changes: 2 additions & 0 deletions FieldOpt/Simulation/simulator_interfaces/ix_simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class IXSimulator : public Simulator {
void UpdateFilePaths() override;
private:
void copyDriverFiles();
void setResultPath();

QString deck_name_;
QString result_path_;

};

Expand Down
1 change: 0 additions & 1 deletion FieldOpt/Utilities/printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ inline void error(const std::string &text) {
std::stringstream ss;
ss << FLRED;
std::string content = text;
truncate_text(content, 59);
pad_text(content, 59);
ss << "╔═════════════════════════════════════════════════════════════════════╗" << "\n";
ss << "║ ERROR: " << content << "" << "\n";
Expand Down

0 comments on commit 804625a

Please sign in to comment.