How to use the ert.cwrap.CWrapper function in ert

To help you get started, we’ve selected a few ert examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Ensembles / ert / devel / python / python / ert / enkf / ert_test_context.py View on Github external
def __enter__(self):
        return self.test_context
        
        
    def __exit__(self , exc_type, exc_val, exc_tb):
        del self.test_context
        return False

    
    def getErt(self):
        return self.test_context.getErt()



cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerType("ert_test", ErtTest)
cwrapper.registerType("ert_test_obj", ErtTest.createPythonObject)
cwrapper.registerType("ert_test_ref", ErtTest.createCReference)


ErtTest.cNamespace().alloc = cwrapper.prototype("c_void_p ert_test_context_alloc( char* , char* , char*)")
ErtTest.cNamespace().set_store = cwrapper.prototype("c_void_p ert_test_context_set_store( ert_test , bool)")
ErtTest.cNamespace().free = cwrapper.prototype("void ert_test_context_free( ert_test )")
ErtTest.cNamespace().get_enkf_main = cwrapper.prototype("enkf_main_ref ert_test_context_get_main( ert_test )")
github Ensembles / ert / devel / python / python / ert / enkf / model_config.py View on Github external
return ModelConfig.cNamespace().runpath_requires_iterations(self)

    def getJobnameFormat(self):
        """ @rtype: str """
        return ModelConfig.cNamespace().get_jobname_fmt(self)

    def getEnspath(self):
        """ @rtype: str """
        return ModelConfig.cNamespace().get_enspath(self)

    def getRunpathFormat(self):
        """ @rtype: PathFormat """
        return ModelConfig.cNamespace().get_runpath_fmt(self)


cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("model_config", ModelConfig)

ModelConfig.cNamespace().free = cwrapper.prototype("void model_config_free( model_config )")
ModelConfig.cNamespace().get_forward_model = cwrapper.prototype("forward_model_ref model_config_get_forward_model(model_config)")
ModelConfig.cNamespace().get_max_internal_submit = cwrapper.prototype("int model_config_get_max_internal_submit(model_config)")
ModelConfig.cNamespace().set_max_internal_submit = cwrapper.prototype("void model_config_set_max_internal_submit(model_config, int)")
ModelConfig.cNamespace().get_case_table_file = cwrapper.prototype("char* model_config_get_case_table_file(model_config)")
ModelConfig.cNamespace().get_runpath_as_char = cwrapper.prototype("char* model_config_get_runpath_as_char(model_config)")
ModelConfig.cNamespace().select_runpath = cwrapper.prototype("bool model_config_select_runpath(model_config, char*)")
ModelConfig.cNamespace().set_runpath = cwrapper.prototype("void model_config_set_runpath(model_config, char*)")
ModelConfig.cNamespace().get_fs_type = cwrapper.prototype("enkf_fs_type_enum model_config_get_dbase_type(model_config)")

ModelConfig.cNamespace().get_history = cwrapper.prototype("history_ref model_config_get_history(model_config)")
ModelConfig.cNamespace().get_history_source = cwrapper.prototype("history_source_enum model_config_get_history_source(model_config)")
ModelConfig.cNamespace().select_history = cwrapper.prototype("bool model_config_select_history(model_config, history_source_enum, sched_file, ecl_sum)")
ModelConfig.cNamespace().has_history = cwrapper.prototype("bool model_config_has_history(model_config)")
github Ensembles / ert / devel / python / python / ert / ecl / ecl_region.py View on Github external
c_ptr = cfunc.get_kw_index_list( self , ecl_kw , force_active)
        index_list = IntVector.asPythonReference( c_ptr , self )
        return index_list


    def set_name( self , name ):
        cfunc.set_name( self , name )

    def get_name( self ):
        return cfunc.get_name( self )
        
    name = property( get_name , set_name )


# 2. Creating a wrapper object around the libecl library.
cwrapper = CWrapper(ECL_LIB)
cwrapper.registerType( "ecl_region" , EclRegion )

# 3. Installing the c-functions used to manipulate.
cfunc = CWrapperNameSpace("ecl_region")

cfunc.alloc                      = cwrapper.prototype("c_void_p ecl_region_alloc( ecl_grid , bool )")
cfunc.free                       = cwrapper.prototype("void ecl_region_free( ecl_region )")     
cfunc.reset                      = cwrapper.prototype("void ecl_region_reset( ecl_region )")

cfunc.select_all                 = cwrapper.prototype("void ecl_region_select_all( ecl_region )")
cfunc.deselect_all               = cwrapper.prototype("void ecl_region_deselect_all( ecl_region )")

cfunc.select_equal               = cwrapper.prototype("void ecl_region_select_equal( ecl_region , ecl_kw , int )")
cfunc.deselect_equal             = cwrapper.prototype("void ecl_region_deselect_equal( ecl_region , ecl_kw , int)")

cfunc.select_less                = cwrapper.prototype("void ecl_region_select_smaller( ecl_region , ecl_kw , float )")
github Ensembles / ert / devel / python / python / ert / enkf / hook_manager.py View on Github external
def getRunpathList(self):
        """ @rtype: RunpathList """
        return HookManager.cNamespace().get_runpath_list(self)
        
    def runWorkflows(self , run_time , ert_self):
        
        workflow_list = ert_self.getWorkflowList()
        for hook_workflow in self:
            
            if (hook_workflow.getRunMode() is not run_time):
                continue
            
            workflow = hook_workflow.getWorkflow()            
            workflow.run(ert_self, context=workflow_list.getContext())       
    
cwrapper = CWrapper(ENKF_LIB)

cwrapper.registerObjectType("hook_manager", HookManager)

HookManager.cNamespace().get_runpath_list_file = cwrapper.prototype("char* hook_manager_get_runpath_list_file(hook_manager)")
HookManager.cNamespace().iget_hook_workflow    = cwrapper.prototype("hook_workflow_ref hook_manager_iget_hook_workflow(hook_manager, int)")
HookManager.cNamespace().size                  = cwrapper.prototype("int hook_manager_get_size(hook_manager)")
github Ensembles / ert / devel / python / python / ert / ecl / faults / fault_block_layer.py View on Github external
def insertBlockContent(self , block):
        self.cNamespace().insert_block_content(self , block)

    def exportKeyword(self , kw):
        if len(kw) != self.grid_ref.getGlobalSize():
            raise ValueError("The size of the target keyword must be equal to the size of the grid. Got:%d Expected:%d" % (len(kw) , self.grid_ref.getGlobalSize()))

        if kw.getEclType() != EclTypeEnum.ECL_INT_TYPE:
            raise TypeError("The target kewyord must be of integer type")
            
        self.cNamespace().export_kw( self , kw )


cwrapper = CWrapper(ECL_LIB)
CWrapper.registerObjectType("fault_block_layer", FaultBlockLayer)


FaultBlockLayer.cNamespace().alloc      = cwrapper.prototype("c_void_p         fault_block_layer_alloc(ecl_grid ,  int)")
FaultBlockLayer.cNamespace().free       = cwrapper.prototype("void             fault_block_layer_free(fault_block_layer)")
FaultBlockLayer.cNamespace().size       = cwrapper.prototype("int              fault_block_layer_get_size(fault_block_layer)")
FaultBlockLayer.cNamespace().iget_block = cwrapper.prototype("fault_block_ref  fault_block_layer_iget_block(fault_block_layer, int)")
FaultBlockLayer.cNamespace().add_block  = cwrapper.prototype("fault_block_ref  fault_block_layer_add_block(fault_block_layer, int)")
FaultBlockLayer.cNamespace().get_block  = cwrapper.prototype("fault_block_ref  fault_block_layer_get_block(fault_block_layer, int)")
FaultBlockLayer.cNamespace().del_block  = cwrapper.prototype("void  fault_block_layer_del_block(fault_block_layer, int)")
FaultBlockLayer.cNamespace().has_block  = cwrapper.prototype("bool  fault_block_layer_has_block(fault_block_layer, int)")
FaultBlockLayer.cNamespace().scan_keyword  = cwrapper.prototype("bool  fault_block_layer_scan_kw(fault_block_layer, ecl_kw)")
FaultBlockLayer.cNamespace().load_keyword  = cwrapper.prototype("bool  fault_block_layer_load_kw(fault_block_layer, ecl_kw)")
FaultBlockLayer.cNamespace().getK          = cwrapper.prototype("int   fault_block_layer_get_k(fault_block_layer)")
FaultBlockLayer.cNamespace().get_next_id   = cwrapper.prototype("int   fault_block_layer_get_next_id(fault_block_layer)")
FaultBlockLayer.cNamespace().scan_layer    = cwrapper.prototype("void  fault_block_layer_scan_layer( fault_block_layer , layer)")
FaultBlockLayer.cNamespace().insert_block_content = cwrapper.prototype("void  fault_block_layer_insert_block_content( fault_block_layer , fault_block)")
github OPM / ResInsight / ThirdParty / Ert / devel / python / python / ert / enkf / enkf_obs.py View on Github external
def getObservationAndMeasureData(self, fs, local_obsdata, state, active_list, meas_data, obs_data):
        assert isinstance(fs, EnkfFs)
        assert isinstance(local_obsdata, LocalObsdata)
        assert isinstance(state, EnkfStateType)
        assert isinstance(active_list, IntVector)
        assert isinstance(meas_data, MeasData)
        assert isinstance(obs_data, ObsData)

        EnkfObs.cNamespace().get_obs_and_measure_data(self, fs, local_obsdata, state, active_list, meas_data, obs_data)


    def free(self):
        EnkfObs.cNamespace().free(self)


cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerType("enkf_obs", EnkfObs)
cwrapper.registerType("enkf_obs_obj", EnkfObs.createPythonObject)
cwrapper.registerType("enkf_obs_ref", EnkfObs.createCReference)

EnkfObs.cNamespace().free = cwrapper.prototype("void enkf_obs_free( enkf_obs )")
EnkfObs.cNamespace().get_size = cwrapper.prototype("int enkf_obs_get_size( enkf_obs )")
EnkfObs.cNamespace().get_config_file = cwrapper.prototype("char* enkf_obs_get_config_file( enkf_obs )")
EnkfObs.cNamespace().alloc_typed_keylist = cwrapper.prototype("stringlist_obj enkf_obs_alloc_typed_keylist(enkf_obs, enkf_obs_impl_type)")
EnkfObs.cNamespace().has_key = cwrapper.prototype("bool enkf_obs_has_key(enkf_obs, char*)")
EnkfObs.cNamespace().get_vector = cwrapper.prototype("obs_vector_ref enkf_obs_get_vector(enkf_obs, char*)")
EnkfObs.cNamespace().iget_vector = cwrapper.prototype("obs_vector_ref enkf_obs_iget_vector(enkf_obs, int)")
EnkfObs.cNamespace().iget_obs_time = cwrapper.prototype("time_t enkf_obs_iget_obs_time(enkf_obs, int)")
EnkfObs.cNamespace().add_obs_vector = cwrapper.prototype("void enkf_obs_add_obs_vector(enkf_obs, char*, obs_vector)")

EnkfObs.cNamespace().get_obs_and_measure_data = cwrapper.prototype("void enkf_obs_get_obs_and_measure_data(enkf_obs, enkf_fs, local_obsdata, enkf_state_type_enum, int_vector, meas_data, obs_data)")
github Ensembles / ert / devel / python / python / ert / enkf / local_obsdata.py View on Github external
""" @rtype: str """
        return LocalObsdata.cNamespace().name(self)
    
    def getActiveList(self, key):
        """ @rtype: ActiveList """
        if key in self:
            return LocalObsdata.cNamespace().active_list(self , key)
        else:
            raise KeyError("Local key:%s not recognized" % key)      

    def free(self):
        LocalObsdata.cNamespace().free(self)



cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("local_obsdata", LocalObsdata)

LocalObsdata.cNamespace().alloc     = cwrapper.prototype("c_void_p local_obsdata_alloc(char*)")
LocalObsdata.cNamespace().free      = cwrapper.prototype("void local_obsdata_free(local_obsdata)")
LocalObsdata.cNamespace().size      = cwrapper.prototype("int local_obsdata_get_size(local_obsdata)")
LocalObsdata.cNamespace().has_node  = cwrapper.prototype("bool local_obsdata_has_node(local_obsdata, char*)")
LocalObsdata.cNamespace().add_node  = cwrapper.prototype("bool local_obsdata_add_node(local_obsdata, local_obsdata_node)")
LocalObsdata.cNamespace().del_node  = cwrapper.prototype("void local_obsdata_del_node(local_obsdata, char*)")
LocalObsdata.cNamespace().clear     = cwrapper.prototype("void local_dataset_clear(local_obsdata)")
LocalObsdata.cNamespace().iget_node = cwrapper.prototype("local_obsdata_node_ref local_obsdata_iget(local_obsdata, int)")
LocalObsdata.cNamespace().get_node  = cwrapper.prototype("local_obsdata_node_ref local_obsdata_get(local_obsdata, char*)")
LocalObsdata.cNamespace().name      = cwrapper.prototype("char* local_obsdata_get_name(local_obsdata)")
LocalObsdata.cNamespace().active_list    = cwrapper.prototype("active_list_ref local_obsdata_get_node_active_list(local_obsdata, char*)")
github Ensembles / ert / devel / python / python / ert / enkf / plot_data / ensemble_plot_gen_data_vector.py View on Github external
return self[index]

    def __iter__(self):
        cur = 0
        while cur < len(self):
            yield self[cur]
            cur += 1

    def __getitem__(self, index):
        """ @rtype: float """
        return EnsemblePlotGenDataVector.cNamespace().get_value(self, index)




cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerType("ensemble_plot_gen_data_vector", EnsemblePlotGenDataVector)
cwrapper.registerType("ensemble_plot_gen_data_vector_obj", EnsemblePlotGenDataVector.createPythonObject)
cwrapper.registerType("ensemble_plot_gen_data_vector_ref", EnsemblePlotGenDataVector.createCReference)

EnsemblePlotGenDataVector.cNamespace().size = cwrapper.prototype("int enkf_plot_genvector_get_size(ensemble_plot_gen_data_vector)")
EnsemblePlotGenDataVector.cNamespace().get_value = cwrapper.prototype("double enkf_plot_genvector_iget(ensemble_plot_gen_data_vector, int)")
github Ensembles / ert / devel / python / python / ert / ecl / faults / fault_block_collection.py View on Github external
        @rtype: FaultBlockLayer
        """
        return self[k]

    def free(self):
        self.cNamespace().free(self)


    def scanKeyword(self , fault_block_kw):
        ok = self.cNamespace().scan_keyword( self , fault_block_kw )
        if not ok:
            raise ValueError("The fault block keyword had wrong type/size")

    

cwrapper = CWrapper(ECL_LIB)
CWrapper.registerObjectType("fault_block_collection", FaultBlockCollection)


FaultBlockCollection.cNamespace().alloc      = cwrapper.prototype("c_void_p         fault_block_collection_alloc(ecl_grid )")
FaultBlockCollection.cNamespace().free       = cwrapper.prototype("void             fault_block_collection_free(fault_block_collection)")
FaultBlockCollection.cNamespace().num_layers = cwrapper.prototype("int              fault_block_collection_num_layers(fault_block_collection)")
FaultBlockCollection.cNamespace().get_layer  = cwrapper.prototype("fault_block_layer_ref  fault_block_collection_get_layer(fault_block_collection, int)")
FaultBlockCollection.cNamespace().scan_keyword  = cwrapper.prototype("bool          fault_block_collection_scan_kw(fault_block_collection, ecl_kw)")
github Ensembles / ert / devel / python / python / ert / enkf / config / field_config.py View on Github external
def get_ny(self):
        return FieldConfig.cNamespace().get_ny(self)

    def get_nz(self):
        return FieldConfig.cNamespace().get_nz(self)

    def ijk_active(self, i, j, k):
        return FieldConfig.cNamespace().ijk_active(self, i, j, k)

    def free(self):
        FieldConfig.cNamespace().free(self)

    

        
cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("field_config", FieldConfig)

FieldConfig.cNamespace().alloc = cwrapper.prototype("c_void_p field_config_alloc_empty(char* , ecl_grid , c_void_p , bool)")  
FieldConfig.cNamespace().free = cwrapper.prototype("void field_config_free( field_config )")
FieldConfig.cNamespace().get_type = cwrapper.prototype("int field_config_get_type(field_config)")
FieldConfig.cNamespace().get_truncation_mode = cwrapper.prototype("int field_config_get_truncation_mode(field_config)")
FieldConfig.cNamespace().get_truncation_min = cwrapper.prototype("double field_config_get_truncation_min(field_config)")
FieldConfig.cNamespace().get_truncation_max = cwrapper.prototype("double field_config_get_truncation_max(field_config)")
FieldConfig.cNamespace().get_init_transform_name = cwrapper.prototype("char* field_config_get_init_transform_name(field_config)")
FieldConfig.cNamespace().get_output_transform_name = cwrapper.prototype("char* field_config_get_output_transform_name(field_config)")
FieldConfig.cNamespace().ijk_active = cwrapper.prototype("bool field_config_ijk_active(field_config, int, int, int)")
FieldConfig.cNamespace().get_nx = cwrapper.prototype("int field_config_get_nx(field_config)")
FieldConfig.cNamespace().get_ny = cwrapper.prototype("int field_config_get_ny(field_config)")
FieldConfig.cNamespace().get_nz = cwrapper.prototype("int field_config_get_nz(field_config)")
FieldConfig.cNamespace().get_grid = cwrapper.prototype("c_void_p field_config_get_grid(field_config)")  #todo: fix return type