Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Revert local_config_clear()
Browse files Browse the repository at this point in the history
This commit reverts the changes in behavior in the local_config_clear() function
from commit: 7d29fdf and also introduces a new function
local_config_clear_active() which lets retains the named ministep, local_data
and obsdata objects for later reuse.
  • Loading branch information
joakim-hove authored and lars-petter-hauge committed Apr 27, 2021
1 parent 7168d27 commit 3e329f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
24 changes: 22 additions & 2 deletions lib/enkf/local_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,32 @@ static local_updatestep_type * local_config_alloc_updatestep( local_config_type



/*
The local_config_clear() function will remove all current local configuration,
and then reallocate a new empty updatestep configuration.
*/
void local_config_clear( local_config_type * local_config ) {
hash_clear( local_config->updatestep_storage );
local_config->default_updatestep = local_config_alloc_updatestep(local_config, "DEFAULT");
local_config->default_updatestep = NULL;
hash_clear( local_config->updatestep_storage );
hash_clear( local_config->ministep_storage );
hash_clear( local_config->dataset_storage );
hash_clear( local_config->obsdata_storage );
local_config->default_updatestep = local_config_alloc_updatestep(local_config, "DEFAULT");
}


/*
The local_config_clear_active() function will reset the current active
updatestep, but the named building blocks of type ministep, local_dataset and
obsdata will be retained and can be reused through name based lookup when we
create a new local configuration.
*/

void local_config_clear_active( local_config_type * local_config ) {
hash_clear( local_config->updatestep_storage );
local_config->default_updatestep = local_config_alloc_updatestep(local_config, "DEFAULT");
}



local_config_type * local_config_alloc( ) {
Expand Down
1 change: 1 addition & 0 deletions lib/include/ert/enkf/local_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct local_config_struct local_config_type;

local_config_type * local_config_alloc( );
void local_config_clear( local_config_type * local_config );
void local_config_clear_active( local_config_type * local_config );
void local_config_free( local_config_type * local_config );
local_ministep_type * local_config_alloc_ministep( local_config_type * local_config , const char * key, analysis_module_type* analysis_module );
local_updatestep_type * local_config_get_updatestep( const local_config_type * local_config );
Expand Down
4 changes: 4 additions & 0 deletions python/res/enkf/local_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class LocalConfig(BaseCClass):

_free = ResPrototype("void local_config_free(local_config)")
_clear = ResPrototype("void local_config_clear(local_config)")
_clear_active = ResPrototype("void local_config_clear_active(local_config)")
_create_ministep = ResPrototype(
"local_ministep_ref local_config_alloc_ministep(local_config, char*, analysis_module)"
)
Expand Down Expand Up @@ -99,6 +100,9 @@ def free(self):
def clear(self):
self._clear()

def clear_active(self):
self._clear_active()

def createMinistep(self, mini_step_key, analysis_module=None):
"""@rtype: Ministep"""
assert isinstance(mini_step_key, str)
Expand Down
2 changes: 1 addition & 1 deletion tests/res/enkf/test_row_scaling_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def test_reuse_ALL_ACTIVE(self):
es_update.smootherUpdate(run_context)

local_config = main.getLocalConfig()
local_config.clear()
local_config.clear_active()
with self.assertRaises(KeyError):
obs_data = local_config.copyObsdata("NO_SUCH_OBS", "my_obs")

Expand Down

0 comments on commit 3e329f0

Please sign in to comment.