From 278f1f9a8160b0a0bacfdbe53dbe785be36ea331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Eide?= Date: Thu, 1 Oct 2020 14:00:30 +0200 Subject: [PATCH] Add PRE_FIRST_UPDATE hook There is sometimes a need for a hook that will only run before the first update and not subsequent times for an iterative algorithm. This is for example relevant if scaling observations, as doing that for each iteration could lead to numeric instabilities. --- lib/enkf/hook_workflow.cpp | 3 +++ lib/enkf/site_config.cpp | 1 + lib/include/ert/enkf/config_keys.hpp | 1 + lib/include/ert/enkf/hook_workflow.hpp | 9 +++++---- python/res/enkf/enums/hook_runtime_enum.py | 2 ++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/enkf/hook_workflow.cpp b/lib/enkf/hook_workflow.cpp index 7463c1c4ad..461269499c 100644 --- a/lib/enkf/hook_workflow.cpp +++ b/lib/enkf/hook_workflow.cpp @@ -27,6 +27,7 @@ #include #include +#define RUN_MODE_PRE_FIRST_UPDATE_NAME "PRE_FIRST_UPDATE" #define RUN_MODE_PRE_SIMULATION_NAME "PRE_SIMULATION" #define RUN_MODE_POST_SIMULATION_NAME "POST_SIMULATION" #define RUN_MODE_PRE_UPDATE_NAME "PRE_UPDATE" @@ -88,6 +89,8 @@ hook_run_mode_enum hook_workflow_run_mode_from_name( const char * run_mode ) { mode = PRE_UPDATE; else if (strcmp( run_mode , RUN_MODE_POST_UPDATE_NAME) == 0) mode = POST_UPDATE; + else if (strcmp( run_mode , RUN_MODE_PRE_FIRST_UPDATE_NAME) == 0) + mode = PRE_FIRST_UPDATE; else { util_abort("%s: unrecognized run mode :%s \n",__func__ , run_mode); mode = POST_UPDATE; /* Dummy */ diff --git a/lib/enkf/site_config.cpp b/lib/enkf/site_config.cpp index 9be42ec689..e03fa4c5f9 100644 --- a/lib/enkf/site_config.cpp +++ b/lib/enkf/site_config.cpp @@ -425,6 +425,7 @@ void site_config_add_config_items(config_parser_type * config, bool site_mode) { stringlist_append_copy(argv, RUN_MODE_POST_SIMULATION_NAME); stringlist_append_copy(argv, RUN_MODE_PRE_UPDATE_NAME); stringlist_append_copy(argv, RUN_MODE_POST_UPDATE_NAME); + stringlist_append_copy(argv, RUN_MODE_PRE_FIRST_UPDATE_NAME); config_schema_item_set_indexed_selection_set(item, 1, argv); stringlist_free( argv ); } diff --git a/lib/include/ert/enkf/config_keys.hpp b/lib/include/ert/enkf/config_keys.hpp index 3ce9782fdb..1ed204fefc 100644 --- a/lib/include/ert/enkf/config_keys.hpp +++ b/lib/include/ert/enkf/config_keys.hpp @@ -117,6 +117,7 @@ extern "C" { #define RUN_MODE_POST_SIMULATION_NAME "POST_SIMULATION" #define RUN_MODE_PRE_UPDATE_NAME "PRE_UPDATE" #define RUN_MODE_POST_UPDATE_NAME "POST_UPDATE" +#define RUN_MODE_PRE_FIRST_UPDATE_NAME "PRE_FIRST_UPDATE" #define STOP_LONG_RUNNING_KEY "STOP_LONG_RUNNING" #define MAX_RUNTIME_KEY "MAX_RUNTIME" #define TIME_MAP_KEY "TIME_MAP" diff --git a/lib/include/ert/enkf/hook_workflow.hpp b/lib/include/ert/enkf/hook_workflow.hpp index dc0c6ae944..9462b88dfe 100644 --- a/lib/include/ert/enkf/hook_workflow.hpp +++ b/lib/include/ert/enkf/hook_workflow.hpp @@ -29,10 +29,11 @@ extern "C" { #include - typedef enum {PRE_SIMULATION = 0, - POST_SIMULATION = 1, - PRE_UPDATE = 2, - POST_UPDATE = 3} hook_run_mode_enum; + typedef enum {PRE_SIMULATION = 0, + POST_SIMULATION = 1, + PRE_UPDATE = 2, + POST_UPDATE = 3, + PRE_FIRST_UPDATE = 4} hook_run_mode_enum; typedef struct hook_workflow_struct hook_workflow_type; diff --git a/python/res/enkf/enums/hook_runtime_enum.py b/python/res/enkf/enums/hook_runtime_enum.py index 034553c5ed..17c00a73e8 100644 --- a/python/res/enkf/enums/hook_runtime_enum.py +++ b/python/res/enkf/enums/hook_runtime_enum.py @@ -21,9 +21,11 @@ class HookRuntime(BaseCEnum): POST_SIMULATION = None PRE_UPDATE = None POST_UPDATE = None + PRE_FIRST_UPDATE = None HookRuntime.addEnum("PRE_SIMULATION" , 0) HookRuntime.addEnum("POST_SIMULATION" , 1) HookRuntime.addEnum("PRE_UPDATE" , 2) HookRuntime.addEnum("POST_UPDATE" , 3) +HookRuntime.addEnum("PRE_FIRST_UPDATE", 4)