def __init__(self, ert, function_name, argument_types, argument_count): super(FunctionErtScript, self).__init__(ert) lib = ert_module.load(None) wrapper = CWrapper(lib) parsed_argument_types = [] if ert is not None: self.__function = wrapper.prototype("c_void_p %s(c_void_p, stringlist)" % function_name) else: for arg in argument_types: if arg is bool: parsed_argument_types.append("bool") elif arg is str: parsed_argument_types.append("char*") elif arg is int: parsed_argument_types.append("int") elif arg is float: parsed_argument_types.append("float") else: raise TypeError("Unknown type: %s" % arg) self.__function = wrapper.prototype("c_void_p %s(%s)" % (function_name, ", ".join(parsed_argument_types[:argument_count])))
def test_method_type(self): wrapper = CWrapper(test_lib) def stringObj(c_ptr): char_ptr = ctypes.c_char_p( c_ptr ) python_string = char_ptr.value test_lib.free(c_ptr) return python_string wrapper.registerType("string_obj", stringObj) dateStamp = wrapper.prototype("string_obj util_alloc_date_stamp_utc()") date_stamp = dateStamp() self.assertIsInstance(date_stamp, str)
def free(self): GenData.cNamespace().free(self) def export(self, file_name, file_format_type, fortio): """ @type: str @type: GenDataFileType @type: FortIO """ GenData.cNamespace().export(self, file_name, file_format_type, fortio) def getData(self): data = DoubleVector() GenData.cNamespace().export_data(self, data) return data cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("gen_data", GenData) GenData.cNamespace().alloc = cwrapper.prototype("c_void_p gen_data_alloc()") GenData.cNamespace().free = cwrapper.prototype("void gen_data_free(gen_data)") GenData.cNamespace().size = cwrapper.prototype( "int gen_data_get_size(gen_data)") GenData.cNamespace().export = cwrapper.prototype( "void gen_data_export(gen_data , char*, gen_data_file_format_type, fortio)" ) GenData.cNamespace().export_data = cwrapper.prototype( "void gen_data_export_data(gen_data , double_vector)")
return EnKFMain.cNamespace().alloc_run_context_ENSEMBLE_EXPERIMENT( self , fs , iactive , init_mode , iteration ) def getRunpathList(self): return EnKFMain.cNamespace().get_runpath_list( self ) def addNode(self, enkf_config_node): EnKFMain.cNamespace().add_node(self, enkf_config_node) ################################################################## cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("enkf_main", EnKFMain) EnKFMain.cNamespace().bootstrap = cwrapper.prototype("c_void_p enkf_main_bootstrap(char*, bool, bool)") EnKFMain.cNamespace().free = cwrapper.prototype("void enkf_main_free(enkf_main)") EnKFMain.cNamespace().get_ensemble_size = cwrapper.prototype("int enkf_main_get_ensemble_size( enkf_main )") EnKFMain.cNamespace().get_ens_config = cwrapper.prototype("ens_config_ref enkf_main_get_ensemble_config( enkf_main )") EnKFMain.cNamespace().get_model_config = cwrapper.prototype("model_config_ref enkf_main_get_model_config( enkf_main )") EnKFMain.cNamespace().get_local_config = cwrapper.prototype("local_config_ref enkf_main_get_local_config( enkf_main )") EnKFMain.cNamespace().get_analysis_config = cwrapper.prototype("analysis_config_ref enkf_main_get_analysis_config( enkf_main)") EnKFMain.cNamespace().get_site_config = cwrapper.prototype("site_config_ref enkf_main_get_site_config( enkf_main)") EnKFMain.cNamespace().get_ecl_config = cwrapper.prototype("ecl_config_ref enkf_main_get_ecl_config( enkf_main)") EnKFMain.cNamespace().get_plot_config = cwrapper.prototype("plot_config_ref enkf_main_get_plot_config( enkf_main)") EnKFMain.cNamespace().set_eclbase = cwrapper.prototype("ui_return_obj enkf_main_set_eclbase( enkf_main, char*)") EnKFMain.cNamespace().set_datafile = cwrapper.prototype("void enkf_main_set_data_file( enkf_main, char*)")
else: raise IndexError("Invalid index") def attachMinistep(self, ministep): assert isinstance(ministep, LocalMinistep) LocalUpdateStep.cNamespace().attach_ministep(self, ministep) def getName(self): """ @rtype: str """ return LocalUpdateStep.cNamespace().name(self) def free(self): LocalUpdateStep.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("local_updatestep", LocalUpdateStep) LocalUpdateStep.cNamespace().alloc = cwrapper.prototype( "c_void_p local_updatestep_alloc(char*)") LocalUpdateStep.cNamespace().size = cwrapper.prototype( "int local_updatestep_get_num_ministep(local_updatestep)") LocalUpdateStep.cNamespace().iget_ministep = cwrapper.prototype( "local_ministep_ref local_updatestep_iget_ministep(local_updatestep, int)") LocalUpdateStep.cNamespace().free = cwrapper.prototype( "void local_updatestep_free(local_updatestep)") LocalUpdateStep.cNamespace().attach_ministep = cwrapper.prototype( "void local_updatestep_add_ministep(local_updatestep,local_ministep)") LocalUpdateStep.cNamespace().name = cwrapper.prototype( "char* local_updatestep_get_name(local_updatestep)")
def getJobNames(self): """ @rtype: StringList """ return ErtWorkflowList.cNamespace().get_job_names(self) def getPluginJobs(self): """ @rtype: list of WorkflowJob """ plugins = [] for job_name in self.getJobNames(): job = self.getJob(job_name) if job.isPlugin(): plugins.append(job) return plugins cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("ert_workflow_list", ErtWorkflowList) ErtWorkflowList.cNamespace().free = cwrapper.prototype( "void ert_workflow_list_free(ert_workflow_list)") ErtWorkflowList.cNamespace().alloc_namelist = cwrapper.prototype( "stringlist_obj ert_workflow_list_alloc_namelist(ert_workflow_list)") ErtWorkflowList.cNamespace().has_workflow = cwrapper.prototype( "bool ert_workflow_list_has_workflow(ert_workflow_list, char*)") ErtWorkflowList.cNamespace().get_workflow = cwrapper.prototype( "workflow_ref ert_workflow_list_get_workflow(ert_workflow_list, char*)") ErtWorkflowList.cNamespace().get_context = cwrapper.prototype( "subst_list_ref ert_workflow_list_get_context(ert_workflow_list)") ErtWorkflowList.cNamespace().add_job = cwrapper.prototype(
def __eq__(self, other): return WellConnection.cNamespace().equal(self, other) def __ne__(self, other): return not self == other def free(self): pass def isMultiSegmentWell(self): """ @rtype: bool """ return WellConnection.cNamespace().is_msw(self) CWrapper.registerObjectType("well_connection", WellConnection) cwrapper = CWrapper(ECL_WELL_LIB) WellConnection.cNamespace().i = cwrapper.prototype("int well_conn_get_i(well_connection)") WellConnection.cNamespace().j = cwrapper.prototype("int well_conn_get_j(well_connection)") WellConnection.cNamespace().k = cwrapper.prototype("int well_conn_get_k(well_connection)") WellConnection.cNamespace().get_dir = cwrapper.prototype("well_connection_dir_enum well_conn_get_dir(well_connection)") WellConnection.cNamespace().segment_id = cwrapper.prototype("int well_conn_get_segment_id(well_connection)") WellConnection.cNamespace().is_open = cwrapper.prototype("bool well_conn_open(well_connection)") WellConnection.cNamespace().is_msw = cwrapper.prototype("bool well_conn_MSW(well_connection)") WellConnection.cNamespace().fracture_connection = cwrapper.prototype("bool well_conn_fracture_connection(well_connection)") WellConnection.cNamespace().matrix_connection = cwrapper.prototype("bool well_conn_matrix_connection(well_connection)") WellConnection.cNamespace().connection_factor = cwrapper.prototype("double well_conn_get_connection_factor(well_connection)")
if 0 <= index < self.totalSize(): value = ObsBlock.cNamespace().iget_value(self, index) std = ObsBlock.cNamespace().iget_std(self, index) return (value, std) else: raise IndexError("Invalid index:%d - valid range: [0,%d)" % (index, self.totalSize())) else: raise TypeError("The index item must be integer") def free(self): ObsBlock.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("obs_block", ObsBlock) ObsBlock.cNamespace().alloc = cwrapper.prototype( "c_void_p obs_block_alloc(char*, int, matrix, bool, double)") ObsBlock.cNamespace().free = cwrapper.prototype( "void obs_block_free(obs_block)") ObsBlock.cNamespace().total_size = cwrapper.prototype( "int obs_block_get_size( obs_block )") ObsBlock.cNamespace().active_size = cwrapper.prototype( "int obs_block_get_active_size( obs_block )") ObsBlock.cNamespace().iset = cwrapper.prototype( "void obs_block_iset( obs_block , int , double , double)") ObsBlock.cNamespace().iget_value = cwrapper.prototype( "double obs_block_iget_value( obs_block , int)") ObsBlock.cNamespace().iget_std = cwrapper.prototype(
@classmethod def convertDefinition(cls, definition): """ @rtype: IntegerHash """ type_hash = IntegerHash() for key, value_type in definition.iteritems(): if value_type == float: value_type = 1 else: value_type = 0 #str type_hash[key] = value_type return type_hash cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("custom_kw_config", CustomKWConfig) CustomKWConfig.cNamespace().free = cwrapper.prototype("void custom_kw_config_free(custom_kw_config)") CustomKWConfig.cNamespace().alloc_empty = cwrapper.prototype("void* custom_kw_config_alloc_empty(char*, char*, char*)") CustomKWConfig.cNamespace().alloc_with_definition = cwrapper.prototype("void* custom_kw_config_alloc_with_definition(char*, integer_hash)") CustomKWConfig.cNamespace().get_name = cwrapper.prototype("char* custom_kw_config_get_name(custom_kw_config)") CustomKWConfig.cNamespace().get_result_file = cwrapper.prototype("char* custom_kw_config_get_result_file(custom_kw_config)") CustomKWConfig.cNamespace().get_output_file = cwrapper.prototype("char* custom_kw_config_get_output_file(custom_kw_config)") CustomKWConfig.cNamespace().parse_result_file = cwrapper.prototype("bool custom_kw_config_parse_result_file(custom_kw_config, char*, stringlist)") CustomKWConfig.cNamespace().has_key = cwrapper.prototype("bool custom_kw_config_has_key(custom_kw_config, char*)") CustomKWConfig.cNamespace().key_is_double = cwrapper.prototype("bool custom_kw_config_key_is_double(custom_kw_config, char*)") CustomKWConfig.cNamespace().index_of_key = cwrapper.prototype("int custom_kw_config_index_of_key(custom_kw_config, char*)") CustomKWConfig.cNamespace().size = cwrapper.prototype("int custom_kw_config_size(custom_kw_config)") CustomKWConfig.cNamespace().keys = cwrapper.prototype("stringlist_obj custom_kw_config_get_keys(custom_kw_config)")
def getData(self, state, obs_index, node_id): """ @type state: c_void_p @type obs_index: int @type node_id: NodeId @rtype: float """ return BlockObservation.cNamespace().iget_data(self, state, obs_index, node_id) def free(self): BlockObservation.cNamespace().free(self) ################################################################## cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("block_obs", BlockObservation) cwrapper.registerType("block_data_config", BlockDataConfig) BlockObservation.cNamespace().alloc = cwrapper.prototype("c_void_p block_obs_alloc( char* , block_data_config , ecl_grid )") BlockObservation.cNamespace().free = cwrapper.prototype("void block_obs_free( block_obs )") BlockObservation.cNamespace().iget_i = cwrapper.prototype("int block_obs_iget_i(block_obs, int)") BlockObservation.cNamespace().iget_j =cwrapper.prototype("int block_obs_iget_j( block_obs, int)") BlockObservation.cNamespace().iget_k = cwrapper.prototype("int block_obs_iget_k( block_obs , int)") BlockObservation.cNamespace().get_size = cwrapper.prototype("int block_obs_get_size( block_obs )") BlockObservation.cNamespace().get_std = cwrapper.prototype("double block_obs_iget_std( block_obs, int )") BlockObservation.cNamespace().get_std_scaling = cwrapper.prototype("double block_obs_iget_std_scaling( block_obs, int )") BlockObservation.cNamespace().update_std_scaling = cwrapper.prototype("void block_obs_update_std_scale(block_obs , double , active_list)") BlockObservation.cNamespace().get_value = cwrapper.prototype("double block_obs_iget_value( block_obs, int)") BlockObservation.cNamespace().get_depth = cwrapper.prototype("double block_obs_iget_depth( block_obs, int)") BlockObservation.cNamespace().add_field_point = cwrapper.prototype("void block_obs_append_field_obs( block_obs, int,int,int,double,double)")
def __exit__(self, exc_type, exc_val, exc_tb): del self.__test_context return False def getErt(self): return self.__test_context.getErt() def getCwd(self): """ Returns the current working directory of this context. @rtype: string """ return self.__test_context.getCwd() cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("ert_test", ErtTest) ErtTest.cNamespace().alloc = cwrapper.prototype("c_void_p ert_test_context_alloc_python( 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 )") ErtTest.cNamespace().get_cwd = cwrapper.prototype("char* ert_test_context_get_cwd( ert_test )")
else: raise TypeError("Index should be integer type") def getLayer(self , k): """ @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)")
def free(self): LocalObsdataNode.cNamespace().free(self) def tstepActive(self , tstep): return LocalObsdataNode.cNamespace().tstep_active( self , tstep) def getActiveList(self): return LocalObsdataNode.cNamespace().get_active_list( self ) def allTimeStepActive(self): return LocalObsdataNode.cNamespace().all_timestep_active( self ) def setAllTimeStepActive(self, flag): return LocalObsdataNode.cNamespace().set_all_timestep_active( self, flag ) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("local_obsdata_node", LocalObsdataNode) LocalObsdataNode.cNamespace().alloc = cwrapper.prototype("c_void_p local_obsdata_node_alloc(char* , bool)") LocalObsdataNode.cNamespace().free = cwrapper.prototype("void local_obsdata_node_free(local_obsdata_node)") LocalObsdataNode.cNamespace().get_key = cwrapper.prototype("char* local_obsdata_node_get_key(local_obsdata_node)") LocalObsdataNode.cNamespace().add_range = cwrapper.prototype("void local_obsdata_node_add_range(local_obsdata_node, int, int)") LocalObsdataNode.cNamespace().add_step = cwrapper.prototype("void local_obsdata_node_add_tstep(local_obsdata_node, int)") LocalObsdataNode.cNamespace().tstep_active = cwrapper.prototype("bool local_obsdata_node_tstep_active(local_obsdata_node, int)") LocalObsdataNode.cNamespace().get_active_list = cwrapper.prototype("active_list_ref local_obsdata_node_get_active_list(local_obsdata_node)") LocalObsdataNode.cNamespace().all_timestep_active = cwrapper.prototype("bool local_obsdata_node_all_timestep_active(local_obsdata_node)") LocalObsdataNode.cNamespace().set_all_timestep_active = cwrapper.prototype("void local_obsdata_node_set_all_timestep_active(local_obsdata_node, bool)")
return GenDataConfig.cNamespace().has_report_step(self, report_step) def getNumReportStep(self): """ @rtype: int """ return GenDataConfig.cNamespace().get_num_report_step(self) def getReportStep(self, index): """ @rtype: int """ return GenDataConfig.cNamespace().iget_report_step(self, index) def getReportSteps(self): """ @rtype: list of int """ return [self.getReportStep(index) for index in range(self.getNumReportStep())] cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("gen_data_config", GenDataConfig) GenDataConfig.cNamespace().alloc = cwrapper.prototype("c_void_p gen_data_config_alloc_GEN_DATA_result( char* , gen_data_file_format_type)") GenDataConfig.cNamespace().free = cwrapper.prototype("void gen_data_config_free( gen_data_config )") GenDataConfig.cNamespace().get_output_format = cwrapper.prototype("gen_data_file_format_type gen_data_config_get_output_format(gen_data_config)") GenDataConfig.cNamespace().get_input_format = cwrapper.prototype("gen_data_file_format_type gen_data_config_get_input_format(gen_data_config)") GenDataConfig.cNamespace().get_template_file = cwrapper.prototype("char* gen_data_config_get_template_file(gen_data_config)") GenDataConfig.cNamespace().get_template_key = cwrapper.prototype("char* gen_data_config_get_template_key(gen_data_config)") GenDataConfig.cNamespace().get_initial_size = cwrapper.prototype("int gen_data_config_get_initial_size(gen_data_config)") GenDataConfig.cNamespace().has_report_step = cwrapper.prototype("bool gen_data_config_has_report_step(gen_data_config, int)") GenDataConfig.cNamespace().get_data_size = cwrapper.prototype("int gen_data_config_get_data_size__(gen_data_config , int)") GenDataConfig.cNamespace().get_key = cwrapper.prototype("char* gen_data_config_get_key(gen_data_config)") GenDataConfig.cNamespace().get_active_mask = cwrapper.prototype("bool_vector_ref gen_data_config_get_active_mask(gen_data_config)")
Will add a key -> value pair which can be used for search replace operations in the data file. Observe that the key will be surrounded by \'<\' and \'>\'. """ doc_string = None if isinstance(value , str): EnKFState.cNamespace().add_subst_kw( self , key , value , doc_string ) else: raise TypeError("The value argument must be a string") def getDataKW(self): """ Will return the substitution map for this realisation. """ return EnKFState.cNamespace().get_subst_list( self ) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("enkf_state", EnKFState) cwrapper.registerType("enkf_state_obj", EnKFState.createPythonObject) cwrapper.registerType("enkf_state_ref", EnKFState.createCReference) EnKFState.cNamespace().free = cwrapper.prototype("void enkf_state_free( enkf_state )") EnKFState.cNamespace().has_key = cwrapper.prototype("bool enkf_state_has_node( enkf_state , char* )") EnKFState.cNamespace().get_node = cwrapper.prototype("enkf_node_ref enkf_state_get_node( enkf_state , char* )") EnKFState.cNamespace().add_subst_kw = cwrapper.prototype("void enkf_state_add_subst_kw( enkf_state , char* , char* , char*)") EnKFState.cNamespace().get_subst_list = cwrapper.prototype("subst_list_ref enkf_state_get_subst_list( enkf_state )")
yield self[cur] cur += 1 def getObservation(self): """ @rtype: float """ return PcaPlotVector.cNamespace().get_obs(self) def getSingularValue(self): """ @rtype: float """ return PcaPlotVector.cNamespace().get_singular_value(self) def free(self): PcaPlotVector.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("pca_plot_vector", PcaPlotVector) cwrapper.registerType("pca_plot_vector_obj", PcaPlotVector.createPythonObject) cwrapper.registerType("pca_plot_vector_ref", PcaPlotVector.createCReference) PcaPlotVector.cNamespace().alloc = cwrapper.prototype( "c_void_p pca_plot_vector_alloc(int, matrix, matrix)") PcaPlotVector.cNamespace().free = cwrapper.prototype( "void pca_plot_vector_free(pca_plot_vector)") PcaPlotVector.cNamespace().size = cwrapper.prototype( "int pca_plot_vector_get_size(pca_plot_vector)") PcaPlotVector.cNamespace().get = cwrapper.prototype( "double pca_plot_vector_iget_sim_value(pca_plot_vector, int)") PcaPlotVector.cNamespace().get_obs = cwrapper.prototype( "double pca_plot_vector_get_obs_value(pca_plot_vector)") PcaPlotVector.cNamespace().get_singular_value = cwrapper.prototype(
return EnsemblePlotDataVector.cNamespace().size(self) def getValue(self, index): """ @rtype: float """ return EnsemblePlotDataVector.cNamespace().get_value(self, index) def getTime(self, index): """ @rtype: CTime """ return EnsemblePlotDataVector.cNamespace().get_time(self, index) def isActive(self, index): """ @rtype: bool """ return EnsemblePlotDataVector.cNamespace().is_active(self, index) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("ensemble_plot_data_vector", EnsemblePlotDataVector) cwrapper.registerType("ensemble_plot_data_vector_obj", EnsemblePlotDataVector.createPythonObject) cwrapper.registerType("ensemble_plot_data_vector_ref", EnsemblePlotDataVector.createCReference) EnsemblePlotDataVector.cNamespace().size = cwrapper.prototype( "int enkf_plot_tvector_size(ensemble_plot_data_vector)") EnsemblePlotDataVector.cNamespace().get_value = cwrapper.prototype( "double enkf_plot_tvector_iget_value(ensemble_plot_data_vector, int)") EnsemblePlotDataVector.cNamespace().get_time = cwrapper.prototype( "time_t enkf_plot_tvector_iget_time(ensemble_plot_data_vector, int)") EnsemblePlotDataVector.cNamespace().is_active = cwrapper.prototype( "bool enkf_plot_tvector_iget_active(ensemble_plot_data_vector, int)")
def getMaxValues(self): """ @rtype: DoubleVector """ return EnsemblePlotGenData.cNamespace().max_values(self).setParent(self) def getMinValues(self): """ @rtype: DoubleVector """ return EnsemblePlotGenData.cNamespace().min_values(self).setParent(self) def free(self): EnsemblePlotGenData.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("ensemble_plot_gen_data", EnsemblePlotGenData) cwrapper.registerType("ensemble_plot_gen_data_obj", EnsemblePlotGenData.createPythonObject) cwrapper.registerType("ensemble_plot_gen_data_ref", EnsemblePlotGenData.createCReference) EnsemblePlotGenData.cNamespace().free = cwrapper.prototype("void enkf_plot_gendata_free(ensemble_plot_gen_data)") EnsemblePlotGenData.cNamespace().alloc = cwrapper.prototype("c_void_p enkf_plot_gendata_alloc(enkf_config_node)") EnsemblePlotGenData.cNamespace().size = cwrapper.prototype("int enkf_plot_gendata_get_size(ensemble_plot_gen_data)") EnsemblePlotGenData.cNamespace().load = cwrapper.prototype("void enkf_plot_gendata_load(ensemble_plot_gen_data, enkf_fs, int, bool_vector)") EnsemblePlotGenData.cNamespace().get = cwrapper.prototype("ensemble_plot_gen_data_vector_ref enkf_plot_gendata_iget(ensemble_plot_gen_data, int)") EnsemblePlotGenData.cNamespace().min_values = cwrapper.prototype("double_vector_ref enkf_plot_gendata_get_min_values(ensemble_plot_gen_data)") EnsemblePlotGenData.cNamespace().max_values = cwrapper.prototype("double_vector_ref enkf_plot_gendata_get_max_values(ensemble_plot_gen_data)")
return WellSegment.cNamespace().depth(self) def length(self): """ @rtype: float """ return WellSegment.cNamespace().length(self) def totalLength(self): """ @rtype: float """ return WellSegment.cNamespace().total_length(self) def diameter(self): """ @rtype: float """ return WellSegment.cNamespace().diameter(self) CWrapper.registerObjectType("well_segment", WellSegment) cwrapper = CWrapper(ECL_WELL_LIB) WellSegment.cNamespace().active = cwrapper.prototype("bool well_segment_active(well_segment)") WellSegment.cNamespace().main_stem = cwrapper.prototype("bool well_segment_main_stem(well_segment)") WellSegment.cNamespace().nearest_wellhead = cwrapper.prototype("bool well_segment_nearest_wellhead(well_segment)") WellSegment.cNamespace().id = cwrapper.prototype("int well_segment_get_id(well_segment)") WellSegment.cNamespace().link_count = cwrapper.prototype("int well_segment_get_link_count(well_segment)") WellSegment.cNamespace().branch_id = cwrapper.prototype("int well_segment_get_branch_id(well_segment)") WellSegment.cNamespace().outlet_id = cwrapper.prototype("int well_segment_get_outlet_id(well_segment)") WellSegment.cNamespace().depth = cwrapper.prototype("double well_segment_get_depth(well_segment)") WellSegment.cNamespace().length = cwrapper.prototype("double well_segment_get_length(well_segment)") WellSegment.cNamespace().total_length = cwrapper.prototype("double well_segment_get_total_length(well_segment)")
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> # for more details. """ Create a polygon """ from cwrap import CClass, CWrapper, CWrapperNameSpace from ert.geo import ERT_GEOMETRY_LIB class GeoPolygon(CClass): def __init__(self, points): c_ptr = cfunc.alloc_new() self.init_cobj(c_ptr, cfunc.free) for (xc, yc) in points: self.add_point(xc, yc) def add_point( self, xc, yc ): cfunc.add_point(self, xc, yc) ################################################################# cwrapper = CWrapper(ERT_GEOMETRY_LIB) cwrapper.registerType("geo_polygon", GeoPolygon) cfunc = CWrapperNameSpace("geo_polygon") cfunc.alloc_new = cwrapper.prototype("c_void_p geo_polygon_alloc( )") cfunc.add_point = cwrapper.prototype("void geo_polygon_add_point( geo_polygon , double , double )") cfunc.free = cwrapper.prototype("void geo_polygon_free( geo_polygon )")
return PcaPlotData.cNamespace().get(self, index).setParent(self) def __iter__(self): cur = 0 while cur < len(self): yield self[cur] cur += 1 def getSingularValues(self): """ @rtype: DoubleVector """ return PcaPlotData.cNamespace().get_singular_values(self).setParent(self) def free(self): PcaPlotData.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("pca_plot_data", PcaPlotData) cwrapper.registerType("pca_plot_data_obj", PcaPlotData.createPythonObject) cwrapper.registerType("pca_plot_data_ref", PcaPlotData.createCReference) PcaPlotData.cNamespace().alloc = cwrapper.prototype("c_void_p pca_plot_data_alloc(char*, matrix, matrix , double_vector)") PcaPlotData.cNamespace().free = cwrapper.prototype("void pca_plot_data_free(pca_plot_data)") PcaPlotData.cNamespace().component_count = cwrapper.prototype("int pca_plot_data_get_size(pca_plot_data)") PcaPlotData.cNamespace().realization_count = cwrapper.prototype("int pca_plot_data_get_ens_size(pca_plot_data)") PcaPlotData.cNamespace().get = cwrapper.prototype("pca_plot_vector_ref pca_plot_data_iget_vector(pca_plot_data, int)") PcaPlotData.cNamespace().get_name = cwrapper.prototype("char* pca_plot_data_get_name(pca_plot_data)") PcaPlotData.cNamespace().get_singular_values = cwrapper.prototype("double_vector_ref pca_plot_data_get_singular_values(pca_plot_data)")
def clear_static_kw(self): EclConfig.cNamespace().clear_static_kw(self) def add_static_kw(self, kw): EclConfig.cNamespace().add_static_kw(self, kw) #----------------------------------------------------------------- def getDepthUnit(self): return EclConfig.cNamespace().get_depth_unit(self) def getPressureUnit(self): return EclConfig.cNamespace().get_pressure_unit(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("ecl_config", EclConfig) cwrapper.registerType("ecl_config_obj", EclConfig.createPythonObject) cwrapper.registerType("ecl_config_ref", EclConfig.createCReference) EclConfig.cNamespace().alloc = cwrapper.prototype( "c_void_p ecl_config_alloc( )") EclConfig.cNamespace().free = cwrapper.prototype( "void ecl_config_free( ecl_config )") EclConfig.cNamespace().get_eclbase = cwrapper.prototype( "char* ecl_config_get_eclbase( ecl_config )") EclConfig.cNamespace().validate_eclbase = cwrapper.prototype( "ui_return_obj ecl_config_validate_eclbase( ecl_config , char*)") EclConfig.cNamespace().set_eclbase = cwrapper.prototype( "void ecl_config_set_eclbase( ecl_config , char*)")
from ert.util import Matrix , DoubleVector class EnkfLinalg(object): __namespace = CNamespace("EnkfLinalg") @classmethod def calculatePrincipalComponents(cls, S0, D_obs, truncation, ncomp, PC, PC_obs, singular_values): assert isinstance(S0, Matrix) assert isinstance(D_obs, Matrix) assert isinstance(truncation, (float, int)) assert isinstance(ncomp, int) assert isinstance(PC, Matrix) assert isinstance(PC_obs, Matrix) assert isinstance(singular_values , DoubleVector) EnkfLinalg.cNamespace().get_PC(S0, D_obs, truncation, ncomp, PC, PC_obs , singular_values) @classmethod def cNamespace(cls): return EnkfLinalg.__namespace cwrapper = CWrapper(ENKF_LIB) EnkfLinalg.cNamespace().get_PC = cwrapper.prototype("void enkf_linalg_get_PC(matrix, matrix, double, int, matrix, matrix, double_vector)")
from ert.util import Matrix, DoubleVector class EnkfLinalg(object): __namespace = CNamespace("EnkfLinalg") @classmethod def calculatePrincipalComponents(cls, S0, D_obs, truncation, ncomp, PC, PC_obs, singular_values): assert isinstance(S0, Matrix) assert isinstance(D_obs, Matrix) assert isinstance(truncation, (float, int)) assert isinstance(ncomp, int) assert isinstance(PC, Matrix) assert isinstance(PC_obs, Matrix) assert isinstance(singular_values, DoubleVector) EnkfLinalg.cNamespace().get_PC(S0, D_obs, truncation, ncomp, PC, PC_obs, singular_values) @classmethod def cNamespace(cls): return EnkfLinalg.__namespace cwrapper = CWrapper(ENKF_LIB) EnkfLinalg.cNamespace().get_PC = cwrapper.prototype( "void enkf_linalg_get_PC(matrix, matrix, double, int, matrix, matrix, double_vector)" )
def getActiveList(self, key): """ @rtype: ActiveList """ if key in self: return LocalDataset.cNamespace().active_list(self , key) else: raise KeyError("Local key:%s not recognized" % key) def free(self): LocalDataset.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("local_dataset", LocalDataset) LocalDataset.cNamespace().alloc = cwrapper.prototype("c_void_p local_dataset_alloc(char*)") LocalDataset.cNamespace().size = cwrapper.prototype("c_void_p local_dataset_get_size(char*)") LocalDataset.cNamespace().has_key = cwrapper.prototype("bool local_dataset_has_key(local_dataset, char*)") LocalDataset.cNamespace().free = cwrapper.prototype("void local_dataset_free(local_dataset)") LocalDataset.cNamespace().name = cwrapper.prototype("char* local_dataset_get_name(local_dataset)") LocalDataset.cNamespace().active_list = cwrapper.prototype("active_list_ref local_dataset_get_node_active_list(local_dataset, char*)") LocalDataset.cNamespace().add_node = cwrapper.prototype("void local_dataset_add_node(local_dataset, char*)") LocalDataset.cNamespace().del_node = cwrapper.prototype("void local_dataset_del_node(local_dataset, char*)")
""" @rtype: str """ return EnkfNode.cNamespace().get_name(self) def load(self, fs, node_id): if not self.tryLoad(fs, node_id): raise Exception("Could not load node: %s iens: %d report: %d" % (self.name(), node_id.iens, node_id.report_step)) def save(self, fs, node_id): assert isinstance(fs, EnkfFs) assert isinstance(node_id, NodeId) return EnkfNode.cNamespace().store(self, fs, False, node_id) def free(self): EnkfNode.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("enkf_node", EnkfNode) EnkfNode.cNamespace().free = cwrapper.prototype("void enkf_node_free(enkf_node)") EnkfNode.cNamespace().alloc = cwrapper.prototype("void* enkf_node_alloc(enkf_config_node)") EnkfNode.cNamespace().alloc_private = cwrapper.prototype("void* enkf_node_alloc_private_container(enkf_config_node)") EnkfNode.cNamespace().get_name = cwrapper.prototype("char* enkf_node_get_key(enkf_node)") EnkfNode.cNamespace().value_ptr = cwrapper.prototype("void* enkf_node_value_ptr(enkf_node)") EnkfNode.cNamespace().try_load = cwrapper.prototype("bool enkf_node_try_load(enkf_node, enkf_fs, node_id)") EnkfNode.cNamespace().get_impl_type = cwrapper.prototype("ert_impl_type_enum enkf_node_get_impl_type(enkf_node)") EnkfNode.cNamespace().store = cwrapper.prototype("bool enkf_node_store(enkf_node, enkf_fs, bool, node_id)")
def scale(self, S, E=None, D=None, R=None, D_obs=None): assert isinstance(S, Matrix) assert isinstance(E, (Matrix, NoneType)) assert isinstance(D, (Matrix, NoneType)) assert isinstance(R, (Matrix, NoneType)) assert isinstance(D_obs, (Matrix, NoneType)) ObsData.cNamespace().scale(self, S, E, D, R, D_obs) def free(self): ObsData.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("obs_data", ObsData) ObsData.cNamespace().alloc = cwrapper.prototype("c_void_p obs_data_alloc(double)") ObsData.cNamespace().free = cwrapper.prototype("void obs_data_free(obs_data)") ObsData.cNamespace().total_size = cwrapper.prototype("int obs_data_get_total_size(obs_data)") ObsData.cNamespace().iget_value = cwrapper.prototype("double obs_data_iget_value(obs_data)") ObsData.cNamespace().iget_std = cwrapper.prototype("double obs_data_iget_std(obs_data)") ObsData.cNamespace().add_block = cwrapper.prototype("obs_block_ref obs_data_add_block(obs_data , char* , int , matrix , bool)") ObsData.cNamespace().allocdObs = cwrapper.prototype("matrix_obj obs_data_allocdObs(obs_data)") ObsData.cNamespace().allocR = cwrapper.prototype("matrix_obj obs_data_allocR(obs_data)") ObsData.cNamespace().allocD = cwrapper.prototype("matrix_obj obs_data_allocD(obs_data , matrix , matrix)") ObsData.cNamespace().allocE = cwrapper.prototype("matrix_obj obs_data_allocE(obs_data , rng , int)") ObsData.cNamespace().scale = cwrapper.prototype("void obs_data_scale(obs_data, matrix, matrix, matrix, matrix, matrix)") ObsData.cNamespace().scale_matrix = cwrapper.prototype("void obs_data_scale_matrix(obs_data, matrix)")
def __len__(self): return GenKwConfig.cNamespace().size(self) def __getitem__(self, index): """ @rtype: str """ return GenKwConfig.cNamespace().iget_name(self, index) def __iter__(self): index = 0 while index < len(self): yield self[index] index += 1 cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("gen_kw_config", GenKwConfig) GenKwConfig.cNamespace().free = cwrapper.prototype( "void gen_kw_config_free( gen_kw_config )") GenKwConfig.cNamespace().alloc_empty = cwrapper.prototype( "c_void_p gen_kw_config_alloc_empty( char*, char* )") GenKwConfig.cNamespace().get_template_file = cwrapper.prototype( "char* gen_kw_config_get_template_file(gen_kw_config)") GenKwConfig.cNamespace().set_template_file = cwrapper.prototype( "void gen_kw_config_set_template_file(gen_kw_config , char*)") GenKwConfig.cNamespace().get_parameter_file = cwrapper.prototype( "char* gen_kw_config_get_parameter_file(gen_kw_config)") GenKwConfig.cNamespace().set_parameter_file = cwrapper.prototype( "void gen_kw_config_set_parameter_file( gen_kw_config, char* )") GenKwConfig.cNamespace().alloc_name_list = cwrapper.prototype(
import ctypes import ert from cwrap import CWrapper from ert.ecl import EclKW, EclFile, EclTypeEnum, FortIO from ert.test import ExtendedTestCase, TestAreaContext from ert.util import IntVector ecl_lib = ert.load("libecl") ecl_wrapper = CWrapper(ecl_lib) freadIndexedData = ecl_wrapper.prototype("void ecl_kw_fread_indexed_data(fortio, int, int, int, int_vector, char*)") # fortio, offset, type, count, index_map, buffer eclFileIndexedRead = ecl_wrapper.prototype("void ecl_file_indexed_read(ecl_file, char*, int, int_vector, char*)") # ecl_file, kw, index, index_map, buffer class EclIndexedReadTest(ExtendedTestCase): def test_ecl_kw_indexed_read(self): with TestAreaContext("ecl_kw_indexed_read") as area: fortio = FortIO("index_test", mode=FortIO.WRITE_MODE) element_count = 100000 ecl_kw = EclKW.create("TEST", element_count, EclTypeEnum.ECL_INT_TYPE) for index in range(element_count): ecl_kw[index] = index ecl_kw.fwrite(fortio) fortio.close()
def keys(self): """ @rtype: StringList """ return SummaryKeySet.cNamespace().keys(self) def isReadOnly(self): """ @rtype: bool """ return SummaryKeySet.cNamespace().is_read_only(self) def writeToFile(self, filename): assert isinstance(filename, str) SummaryKeySet.cNamespace().fwrite(self, filename) def free(self): SummaryKeySet.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("summary_key_set", SummaryKeySet) SummaryKeySet.cNamespace().alloc = cwrapper.prototype("c_void_p summary_key_set_alloc()") SummaryKeySet.cNamespace().alloc_from_file = cwrapper.prototype("c_void_p summary_key_set_alloc_from_file(char*, bool)") SummaryKeySet.cNamespace().free = cwrapper.prototype("void summary_key_set_free(summary_key_set)") SummaryKeySet.cNamespace().size = cwrapper.prototype("int summary_key_set_get_size(summary_key_set)") SummaryKeySet.cNamespace().add_key = cwrapper.prototype("bool summary_key_set_add_summary_key(summary_key_set, char*)") SummaryKeySet.cNamespace().has_key = cwrapper.prototype("bool summary_key_set_has_summary_key(summary_key_set, char*)") SummaryKeySet.cNamespace().keys = cwrapper.prototype("stringlist_obj summary_key_set_alloc_keys(summary_key_set)") SummaryKeySet.cNamespace().is_read_only = cwrapper.prototype("bool summary_key_set_is_read_only(summary_key_set)") SummaryKeySet.cNamespace().fwrite = cwrapper.prototype("void summary_key_set_fwrite(summary_key_set, char*)")
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
return SummaryKeyMatcher.cNamespace().add_key(self, key) def __len__(self): return SummaryKeyMatcher.cNamespace().size(self) def __contains__(self, key): return SummaryKeyMatcher.cNamespace().match_key(self, key) def isRequired(self, key): """ @rtype: bool """ return SummaryKeyMatcher.cNamespace().is_required(self, key) def keys(self): """ @rtype: StringList """ return SummaryKeyMatcher.cNamespace().keys(self) def free(self): SummaryKeyMatcher.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("summary_key_matcher", SummaryKeyMatcher) SummaryKeyMatcher.cNamespace().alloc = cwrapper.prototype("c_void_p summary_key_matcher_alloc()") SummaryKeyMatcher.cNamespace().free = cwrapper.prototype("void summary_key_matcher_free(summary_key_matcher)") SummaryKeyMatcher.cNamespace().size = cwrapper.prototype("int summary_key_matcher_get_size(summary_key_matcher)") SummaryKeyMatcher.cNamespace().add_key = cwrapper.prototype("void summary_key_matcher_add_summary_key(summary_key_matcher, char*)") SummaryKeyMatcher.cNamespace().match_key = cwrapper.prototype("bool summary_key_matcher_match_summary_key(summary_key_matcher, char*)") SummaryKeyMatcher.cNamespace().keys = cwrapper.prototype("stringlist_obj summary_key_matcher_get_keys(summary_key_matcher)") SummaryKeyMatcher.cNamespace().is_required = cwrapper.prototype("bool summary_key_matcher_summary_key_is_required(summary_key_matcher, char*)")
""" @rtype: IntegerHash """ host_list = SiteConfig.cNamespace().get_rsh_host_list(self) return host_list def addRshHost(self, host, max_running): SiteConfig.cNamespace().add_rsh_host(self, host, max_running) def getLocation(self): """ @rtype: str """ return SiteConfig.cNamespace().get_location(self) def free(self): SiteConfig.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("site_config", SiteConfig) cwrapper.registerType("site_config_obj", SiteConfig.createPythonObject) cwrapper.registerType("site_config_ref", SiteConfig.createCReference) SiteConfig.cNamespace().free = cwrapper.prototype( "void site_config_free( site_config )") SiteConfig.cNamespace().get_queue_name = cwrapper.prototype( "char* site_config_get_queue_name(site_config)") SiteConfig.cNamespace().get_lsf_queue = cwrapper.prototype( "char* site_config_get_lsf_queue(site_config)") SiteConfig.cNamespace().set_lsf_queue = cwrapper.prototype( "void site_config_set_lsf_queue(site_config, char*)") SiteConfig.cNamespace().get_max_running_lsf = cwrapper.prototype( "int site_config_get_max_running_lsf(site_config)") SiteConfig.cNamespace().set_max_running_lsf = cwrapper.prototype(
[ (10, datetime.datetime( 2010 , 1 , 1 , 0 , 0 , 0 ) , 100.0), (15, datetime.datetime( 2010 , 3 , 1 , 0 , 0 , 0 ) , 160.0), (20, datetime.datetime( 2010 , 5 , 1 , 0 , 0 , 0 ) , 220.0) ] For a non-unified restart file the list will have only one element. """ self.assertHeaders() time_list = [] for header in self.rst_headers: time_list.append((header.getReportStep(), header.getSimDate(), header.getSimDays())) return time_list CWrapper.registerObjectType("ecl_rsthead", EclRestartHead) cwrapper = CWrapper(ECL_LIB) EclRestartHead.cNamespace().alloc = cwrapper.prototype( "c_void_p ecl_rsthead_ialloc(ecl_file , int )") EclRestartHead.cNamespace().alloc_from_kw = cwrapper.prototype( "c_void_p ecl_rsthead_alloc_from_kw(int , ecl_kw , ecl_kw , ecl_kw )") EclRestartHead.cNamespace().free = cwrapper.prototype( "void ecl_rsthead_free(ecl_rsthead)") EclRestartHead.cNamespace().get_report_step = cwrapper.prototype( "int ecl_rsthead_get_report_step(ecl_rsthead)") EclRestartHead.cNamespace().get_sim_time = cwrapper.prototype( "time_t ecl_rsthead_get_sim_time(ecl_rsthead)") EclRestartHead.cNamespace().get_sim_days = cwrapper.prototype( "double ecl_rsthead_get_sim_days(ecl_rsthead)")
def getCaseFormat(self): """ @rtype: str """ return AnalysisIterConfig.cNamespace().get_case_fmt(self) def setCaseFormat(self, case_fmt): AnalysisIterConfig.cNamespace().set_case_fmt(self, case_fmt) def caseFormatSet(self): return AnalysisIterConfig.cNamespace().case_fmt_set(self) def free(self): AnalysisIterConfig.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("analysis_iter_config", AnalysisIterConfig) AnalysisIterConfig.cNamespace().alloc = cwrapper.prototype("c_void_p analysis_iter_config_alloc( )") AnalysisIterConfig.cNamespace().free = cwrapper.prototype("void analysis_iter_config_free( analysis_iter_config )") AnalysisIterConfig.cNamespace().set_num_iterations = cwrapper.prototype( "void analysis_iter_config_set_num_iterations(analysis_iter_config, int)" ) AnalysisIterConfig.cNamespace().get_num_iterations = cwrapper.prototype( "int analysis_iter_config_get_num_iterations(analysis_iter_config)" ) AnalysisIterConfig.cNamespace().get_num_retries = cwrapper.prototype( "int analysis_iter_config_get_num_retries_per_iteration(analysis_iter_config)" ) AnalysisIterConfig.cNamespace().num_iterations_set = cwrapper.prototype(
from os import path, symlink, remove import ert from cwrap import CWrapper from ert.test import ExtendedTestCase, TestAreaContext,ErtTestContext from ert.enkf import RunpathList, RunpathNode from ert.util import BoolVector test_lib = ert.load("libenkf") # create a local namespace cwrapper = CWrapper(test_lib) runpath_list_alloc = cwrapper.prototype("runpath_list_obj runpath_list_alloc(char*)") class RunpathListTest(ExtendedTestCase): def test_runpath_list(self): runpath_list = runpath_list_alloc("") """ @type runpath_list: RunpathList """ self.assertEqual(len(runpath_list), 0) test_runpath_nodes = [RunpathNode(0, 0, "runpath0", "basename0"), RunpathNode(1, 0, "runpath1", "basename0")] runpath_node = test_runpath_nodes[0] runpath_list.add(runpath_node.realization, runpath_node.iteration, runpath_node.runpath, runpath_node.basename) self.assertEqual(len(runpath_list), 1) self.assertEqual(runpath_list[0], test_runpath_nodes[0]) runpath_node = test_runpath_nodes[1] runpath_list.add(runpath_node.realization, runpath_node.iteration, runpath_node.runpath, runpath_node.basename)
mask = BoolVector(False, len(self)) self.selectMatching(mask, state_value) return BoolVector.createActiveList(mask) def free(self): StateMap.cNamespace().free(self) def load(self, filename): if not self.cNamespace().fread(self, filename): raise IOError("Failed to load state map from:%s" % filename) def save(self, filename): self.cNamespace().fwrite(self, filename) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("state_map", StateMap) StateMap.cNamespace().alloc = cwrapper.prototype("c_void_p state_map_alloc()") StateMap.cNamespace().fread = cwrapper.prototype( "bool state_map_fread(state_map , char*)") StateMap.cNamespace().fwrite = cwrapper.prototype( "void state_map_fwrite(state_map , char*)") StateMap.cNamespace().equal = cwrapper.prototype( "bool state_map_equal(state_map , state_map)") StateMap.cNamespace().free = cwrapper.prototype( "void state_map_free(state_map)") StateMap.cNamespace().size = cwrapper.prototype( "int state_map_get_size(state_map)") StateMap.cNamespace().iget = cwrapper.prototype( "realisation_state_enum state_map_iget(state_map, int)")
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() def getCwd(self): """ Returns the current working directory of this context. @rtype: string """ return self.__test_context.getCwd() cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("ert_test", ErtTest) ErtTest.cNamespace().alloc = cwrapper.prototype( "c_void_p ert_test_context_alloc_python( 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 )") ErtTest.cNamespace().get_cwd = cwrapper.prototype( "char* ert_test_context_get_cwd( ert_test )")
def __contains__(self, key): return SummaryKeyMatcher.cNamespace().match_key(self, key) def isRequired(self, key): """ @rtype: bool """ return SummaryKeyMatcher.cNamespace().is_required(self, key) def keys(self): """ @rtype: StringList """ return SummaryKeyMatcher.cNamespace().keys(self) def free(self): SummaryKeyMatcher.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("summary_key_matcher", SummaryKeyMatcher) SummaryKeyMatcher.cNamespace().alloc = cwrapper.prototype( "c_void_p summary_key_matcher_alloc()") SummaryKeyMatcher.cNamespace().free = cwrapper.prototype( "void summary_key_matcher_free(summary_key_matcher)") SummaryKeyMatcher.cNamespace().size = cwrapper.prototype( "int summary_key_matcher_get_size(summary_key_matcher)") SummaryKeyMatcher.cNamespace().add_key = cwrapper.prototype( "void summary_key_matcher_add_summary_key(summary_key_matcher, char*)") SummaryKeyMatcher.cNamespace().match_key = cwrapper.prototype( "bool summary_key_matcher_match_summary_key(summary_key_matcher, char*)") SummaryKeyMatcher.cNamespace().keys = cwrapper.prototype( "stringlist_obj summary_key_matcher_get_keys(summary_key_matcher)") SummaryKeyMatcher.cNamespace().is_required = cwrapper.prototype(
# Copyright (C) 2012 Statoil ASA, Norway. # # The file 'field_config.py' is part of ERT - Ensemble based Reservoir Tool. # # ERT is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # ERT is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> # for more details. from cwrap import BaseCClass, CWrapper from ert.enkf import ENKF_LIB class SummaryConfig(BaseCClass): def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("summary_config", SummaryConfig) cwrapper.registerType("summary_config", SummaryConfig.createPythonObject) cwrapper.registerType("summary_config", SummaryConfig.createCReference)
import ert from cwrap import clib, CWrapper from ert.enkf.data.enkf_node import EnkfNode from ert.enkf.node_id import NodeId from ert.test import ErtTestContext from ert.test.extended_testcase import ExtendedTestCase from ert.util import BoolVector test_lib = ert.load("libenkf") cwrapper = CWrapper(test_lib) class GenDataTest(ExtendedTestCase): def setUp(self): self.config_file = self.createTestPath( "Statoil/config/with_GEN_DATA/config") def test_create(self): with ErtTestContext("gen_data_test", self.config_file) as test_context: ert = test_context.getErt() fs1 = ert.getEnkfFsManager().getCurrentFileSystem() config_node = ert.ensembleConfig().getNode("TIMESHIFT") data_node = EnkfNode(config_node) data_node.tryLoad(fs1, NodeId(60, 0)) gen_data = data_node.asGenData() data = gen_data.getData() self.assertEqual(len(data), 2560)
from cwrap import BaseCClass, CWrapper from ert.enkf import ENKF_LIB class RunArg(BaseCClass): def __init__(self): raise NotImplementedError("Class can not be instantiated directly") @classmethod def createEnsembleExperimentRunArg(cls, fs, iens, runpath, iter=0): return RunArg.cNamespace().alloc_ENSEMBLE_EXPERIMENT(fs, iens, iter, runpath) def free(self): RunArg.cNamespace().free(self) def getQueueIndex(self): return RunArg.cNamespace().get_queue_index(self) def isSubmitted(self): return RunArg.cNamespace().is_submitted(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("run_arg", RunArg) RunArg.cNamespace().alloc_ENSEMBLE_EXPERIMENT = cwrapper.prototype("run_arg_obj run_arg_alloc_ENSEMBLE_EXPERIMENT(enkf_fs , int, int, char*)") RunArg.cNamespace().free = cwrapper.prototype("void run_arg_free(run_arg)") RunArg.cNamespace().get_queue_index = cwrapper.prototype("int run_arg_get_queue_index(run_arg)") RunArg.cNamespace().is_submitted = cwrapper.prototype("bool run_arg_is_submitted(run_arg)")
assert isinstance(mini_step, LocalMinistep) assert isinstance(update_step, LocalUpdateStep) LocalConfig.cNamespace().attach_ministep(update_step, mini_step) def writeSummaryFile(self, filename): """ Writes a summary of the local config object The summary contains the Obsset with their respective number of observations and the Datasets with the number of active indices """ assert isinstance(filename, str) LocalConfig.cNamespace().write_local_config_summary_file(self, filename) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("local_config", LocalConfig) LocalConfig.cNamespace().free = cwrapper.prototype("void local_config_free( local_config )") LocalConfig.cNamespace().clear = cwrapper.prototype("void local_config_clear( local_config )") LocalConfig.cNamespace().get_updatestep = cwrapper.prototype("local_updatestep_ref local_config_get_updatestep( local_config )") LocalConfig.cNamespace().get_ministep = cwrapper.prototype("local_ministep_ref local_config_get_ministep( local_config, char*)") LocalConfig.cNamespace().create_ministep = cwrapper.prototype("void local_config_alloc_ministep( local_config, char*, analysis_module)") LocalConfig.cNamespace().attach_ministep = cwrapper.prototype("void local_updatestep_add_ministep( local_updatestep, local_ministep)") LocalConfig.cNamespace().get_obsdata = cwrapper.prototype("local_obsdata_ref local_config_get_obsdata( local_config, char*)") LocalConfig.cNamespace().create_obsdata = cwrapper.prototype("void local_config_alloc_obsdata( local_config, char*)") LocalConfig.cNamespace().copy_obsdata = cwrapper.prototype("local_obsdata_ref local_config_alloc_obsdata_copy( local_config, char*, char*)") LocalConfig.cNamespace().has_obsdata = cwrapper.prototype("bool local_config_has_obsdata( local_config, char*)") LocalConfig.cNamespace().get_dataset = cwrapper.prototype("local_dataset_ref local_config_get_dataset( local_config, char*)") LocalConfig.cNamespace().create_dataset = cwrapper.prototype("void local_config_alloc_dataset( local_config, char*)") LocalConfig.cNamespace().copy_dataset = cwrapper.prototype("local_dataset_ref local_config_alloc_dataset_copy( local_config, char*, char*)")
active_region = ecl_region.getActiveList() for i in active_region: active_list.addActiveIndex(i) def getActiveList(self, key): """ @rtype: ActiveList """ if key in self: return LocalDataset.cNamespace().active_list(self, key) else: raise KeyError("Local key:%s not recognized" % key) def free(self): LocalDataset.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("local_dataset", LocalDataset) LocalDataset.cNamespace().alloc = cwrapper.prototype( "c_void_p local_dataset_alloc(char*)") LocalDataset.cNamespace().size = cwrapper.prototype( "c_void_p local_dataset_get_size(char*)") LocalDataset.cNamespace().has_key = cwrapper.prototype( "bool local_dataset_has_key(local_dataset, char*)") LocalDataset.cNamespace().free = cwrapper.prototype( "void local_dataset_free(local_dataset)") LocalDataset.cNamespace().name = cwrapper.prototype( "char* local_dataset_get_name(local_dataset)") LocalDataset.cNamespace().active_list = cwrapper.prototype( "active_list_ref local_dataset_get_node_active_list(local_dataset, char*)") LocalDataset.cNamespace().add_node = cwrapper.prototype(
def tstepActive(self, tstep): return LocalObsdataNode.cNamespace().tstep_active(self, tstep) def getActiveList(self): return LocalObsdataNode.cNamespace().get_active_list(self) def allTimeStepActive(self): return LocalObsdataNode.cNamespace().all_timestep_active(self) def setAllTimeStepActive(self, flag): return LocalObsdataNode.cNamespace().set_all_timestep_active( self, flag) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("local_obsdata_node", LocalObsdataNode) LocalObsdataNode.cNamespace().alloc = cwrapper.prototype( "c_void_p local_obsdata_node_alloc(char* , bool)") LocalObsdataNode.cNamespace().free = cwrapper.prototype( "void local_obsdata_node_free(local_obsdata_node)") LocalObsdataNode.cNamespace().get_key = cwrapper.prototype( "char* local_obsdata_node_get_key(local_obsdata_node)") LocalObsdataNode.cNamespace().add_range = cwrapper.prototype( "void local_obsdata_node_add_range(local_obsdata_node, int, int)") LocalObsdataNode.cNamespace().add_step = cwrapper.prototype( "void local_obsdata_node_add_tstep(local_obsdata_node, int)") LocalObsdataNode.cNamespace().tstep_active = cwrapper.prototype( "bool local_obsdata_node_tstep_active(local_obsdata_node, int)") LocalObsdataNode.cNamespace().get_active_list = cwrapper.prototype(
scale_factor) def load(self, config_file): if not os.path.isfile(config_file): raise IOError("The observation config file:%s does not exist" % config_file) return EnkfObs.cNamespace().load(self, config_file) def clear(self): EnkfObs.cNamespace().clear(self) def free(self): EnkfObs.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("enkf_obs", EnkfObs) EnkfObs.cNamespace().alloc = cwrapper.prototype( "c_void_p enkf_obs_alloc( history , time_map , ecl_grid , ecl_sum , ens_config )" ) 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().load = cwrapper.prototype( "bool enkf_obs_load( enkf_obs , char*)") EnkfObs.cNamespace().clear = cwrapper.prototype( "void enkf_obs_clear( enkf_obs )") EnkfObs.cNamespace().alloc_typed_keylist = cwrapper.prototype( "stringlist_obj enkf_obs_alloc_typed_keylist(enkf_obs, enkf_obs_impl_type)"
config = self.getConfig() if not key in config: raise KeyError("The key: '%s' is not available!" % key) if isinstance(value, (float, int, long)): CustomKW.cNamespace().set_double(self, key, value) else: CustomKW.cNamespace().set_string(self, key, str(value)) def getConfig(self): """ @rtype: CustomKWConfig """ return CustomKW.cNamespace().get_config(self) def free(self): CustomKW.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("custom_kw", CustomKW) CustomKW.cNamespace().free = cwrapper.prototype("void custom_kw_free(custom_kw)") CustomKW.cNamespace().alloc = cwrapper.prototype("void* custom_kw_alloc(custom_kw_config)") CustomKW.cNamespace().fload = cwrapper.prototype("bool custom_kw_fload(custom_kw, char*)") CustomKW.cNamespace().get_config = cwrapper.prototype("custom_kw_config_ref custom_kw_get_config(custom_kw)") CustomKW.cNamespace().key_is_null = cwrapper.prototype("bool custom_kw_key_is_null(custom_kw, char*)") CustomKW.cNamespace().iget_as_double = cwrapper.prototype("double custom_kw_iget_as_double(custom_kw, int)") CustomKW.cNamespace().iget_as_string = cwrapper.prototype("char* custom_kw_iget_as_string(custom_kw, int)") CustomKW.cNamespace().set_string = cwrapper.prototype("void custom_kw_set_string(custom_kw, char*, char*)") CustomKW.cNamespace().set_double = cwrapper.prototype("void custom_kw_set_double(custom_kw, char*, double)")
return ObsVector.cNamespace().create_local_node( self ) def hasData(self, active_mask, fs): """ @rtype: bool """ return ObsVector.cNamespace().has_data(self, active_mask, fs) def free(self): ObsVector.cNamespace().free(self) def getTotalChi2(self, fs, realization_number): """ @rtype: float """ return ObsVector.cNamespace().get_total_chi2(self, fs, realization_number) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("obs_vector", ObsVector) ObsVector.cNamespace().alloc = cwrapper.prototype("c_void_p obs_vector_alloc(enkf_obs_impl_type, char*, enkf_config_node, int)") ObsVector.cNamespace().free = cwrapper.prototype("void obs_vector_free( obs_vector )") ObsVector.cNamespace().get_state_kw = cwrapper.prototype("char* obs_vector_get_state_kw( obs_vector )") ObsVector.cNamespace().get_observation_key = cwrapper.prototype("char* obs_vector_get_key( obs_vector )") ObsVector.cNamespace().iget_node = cwrapper.prototype("c_void_p obs_vector_iget_node( obs_vector, int)") ObsVector.cNamespace().get_num_active = cwrapper.prototype("int obs_vector_get_num_active( obs_vector )") ObsVector.cNamespace().iget_active = cwrapper.prototype("bool obs_vector_iget_active( obs_vector, int)") ObsVector.cNamespace().get_impl_type = cwrapper.prototype("enkf_obs_impl_type obs_vector_get_impl_type( obs_vector)") ObsVector.cNamespace().install_node = cwrapper.prototype("void obs_vector_install_node(obs_vector, int, c_void_p)") ObsVector.cNamespace().get_next_active_step = cwrapper.prototype("int obs_vector_get_next_active_step(obs_vector, int)") ObsVector.cNamespace().has_data = cwrapper.prototype("bool obs_vector_has_data(obs_vector , bool_vector , enkf_fs)") ObsVector.cNamespace().get_config_node = cwrapper.prototype("enkf_config_node_ref obs_vector_get_config_node(obs_vector)") ObsVector.cNamespace().get_total_chi2 = cwrapper.prototype("double obs_vector_total_chi2(obs_vector, enkf_fs, int)")
def getMaxValues(self): """ @rtype: DoubleVector """ return EnsemblePlotGenData.cNamespace().max_values(self).setParent( self) def getMinValues(self): """ @rtype: DoubleVector """ return EnsemblePlotGenData.cNamespace().min_values(self).setParent( self) def free(self): EnsemblePlotGenData.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("ensemble_plot_gen_data", EnsemblePlotGenData) cwrapper.registerType("ensemble_plot_gen_data_obj", EnsemblePlotGenData.createPythonObject) cwrapper.registerType("ensemble_plot_gen_data_ref", EnsemblePlotGenData.createCReference) EnsemblePlotGenData.cNamespace().free = cwrapper.prototype( "void enkf_plot_gendata_free(ensemble_plot_gen_data)") EnsemblePlotGenData.cNamespace().alloc = cwrapper.prototype( "c_void_p enkf_plot_gendata_alloc(enkf_config_node)") EnsemblePlotGenData.cNamespace().size = cwrapper.prototype( "int enkf_plot_gendata_get_size(ensemble_plot_gen_data)") EnsemblePlotGenData.cNamespace().load = cwrapper.prototype( "void enkf_plot_gendata_load(ensemble_plot_gen_data, enkf_fs, int, bool_vector)"
cur = 0 while cur < len(self): yield self[cur] cur += 1 def getObservation(self): """ @rtype: float """ return PcaPlotVector.cNamespace().get_obs(self) def getSingularValue(self): """ @rtype: float """ return PcaPlotVector.cNamespace().get_singular_value(self) def free(self): PcaPlotVector.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("pca_plot_vector", PcaPlotVector) cwrapper.registerType("pca_plot_vector_obj", PcaPlotVector.createPythonObject) cwrapper.registerType("pca_plot_vector_ref", PcaPlotVector.createCReference) PcaPlotVector.cNamespace().alloc = cwrapper.prototype("c_void_p pca_plot_vector_alloc(int, matrix, matrix)") PcaPlotVector.cNamespace().free = cwrapper.prototype("void pca_plot_vector_free(pca_plot_vector)") PcaPlotVector.cNamespace().size = cwrapper.prototype("int pca_plot_vector_get_size(pca_plot_vector)") PcaPlotVector.cNamespace().get = cwrapper.prototype("double pca_plot_vector_iget_sim_value(pca_plot_vector, int)") PcaPlotVector.cNamespace().get_obs = cwrapper.prototype("double pca_plot_vector_get_obs_value(pca_plot_vector)") PcaPlotVector.cNamespace().get_singular_value = cwrapper.prototype( "double pca_plot_vector_get_singular_value(pca_plot_vector)" )
import ert from cwrap import clib, CWrapper from ert.enkf.data import EnkfNode from ert.enkf.config import GenDataConfig from ert.enkf import NodeId from ert.enkf import ForwardLoadContext from ert.test import ErtTestContext, ExtendedTestCase from ert.util import BoolVector test_lib = ert.load("libenkf") cwrapper = CWrapper(test_lib) get_active_mask = cwrapper.prototype("bool_vector_ref gen_data_config_get_active_mask( gen_data_config )") update_active_mask = cwrapper.prototype( "void gen_data_config_update_active( gen_data_config, forward_load_context , bool_vector)" ) alloc_run_arg = cwrapper.prototype("run_arg_obj run_arg_alloc_ENSEMBLE_EXPERIMENT( enkf_fs , int , int , char*) ") def updateMask(gen_data_config, report_step, fs, active_mask): run_arg = alloc_run_arg(fs, 0, 0, "Path") load_context = ForwardLoadContext(run_arg=run_arg, report_step=report_step) update_active_mask(gen_data_config, load_context, active_mask) class GenDataConfigTest(ExtendedTestCase): def setUp(self): self.config_file = self.createTestPath("Statoil/config/with_GEN_DATA/config") def load_active_masks(self, case1, case2):
return MeasBlock.cNamespace().iget_mean(self, iobs) else: raise IndexError( "Invalid observation index:%d valid range: [0,%d)" % (iobs, self.getObsSize())) def igetStd(self, iobs): if 0 <= iobs < self.getObsSize(): return MeasBlock.cNamespace().iget_std(self, iobs) else: raise IndexError( "Invalid observation index:%d valid range: [0,%d)" % (iobs, self.getObsSize())) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("meas_block", MeasBlock) MeasBlock.cNamespace().alloc = cwrapper.prototype( "c_void_p meas_block_alloc( char* , bool_vector , int)") MeasBlock.cNamespace().free = cwrapper.prototype( "void meas_block_free( meas_block )") MeasBlock.cNamespace().get_active_ens_size = cwrapper.prototype( "int meas_block_get_active_ens_size( meas_block )") MeasBlock.cNamespace().get_total_ens_size = cwrapper.prototype( "int meas_block_get_total_ens_size( meas_block )") MeasBlock.cNamespace().get_total_obs_size = cwrapper.prototype( "int meas_block_get_total_obs_size( meas_block )") MeasBlock.cNamespace().iget_value = cwrapper.prototype( "double meas_block_iget( meas_block , int , int)") MeasBlock.cNamespace().iset_value = cwrapper.prototype(
elif implementation_type == ErtImplType.CUSTOM_KW: return self.getCustomKeywordModelConfig() elif implementation_type == ErtImplType.SUMMARY: return SummaryConfig.createCReference(self.getPointerReference(), parent=self) else: print( "[EnkfConfigNode::getModelConfig()] Unhandled implementation model type: %i" % implementation_type) # raise NotImplementedError("Unknown model type: %i" % type) def getKey(self): return EnkfConfigNode.cNamespace().get_key(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("enkf_config_node", EnkfConfigNode) EnkfConfigNode.cNamespace().free = cwrapper.prototype( "void enkf_config_node_free(enkf_config_node)") EnkfConfigNode.cNamespace().get_ref = cwrapper.prototype( "c_void_p enkf_config_node_get_ref(enkf_config_node)" ) #todo: fix return type EnkfConfigNode.cNamespace().get_impl_type = cwrapper.prototype( "ert_impl_type_enum enkf_config_node_get_impl_type(enkf_config_node)") EnkfConfigNode.cNamespace().get_enkf_outfile = cwrapper.prototype( "char* enkf_config_node_get_enkf_outfile(enkf_config_node)") EnkfConfigNode.cNamespace().get_min_std_file = cwrapper.prototype( "char* enkf_config_node_get_min_std_file(enkf_config_node)") EnkfConfigNode.cNamespace().get_enkf_infile = cwrapper.prototype(