def __init__(self, ert, function_name, argument_types, argument_count): super(FunctionErtScript, self).__init__(ert) lib = clib.ert_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 setUp(self): ert = clib.ert_load("libert_util") self.ert_wrapper = CWrapper(ert) self.ert_wrapper.registerType("pow_double", MaxDouble) self.double_max = self.ert_wrapper.prototype( "pow_double util_double_max(double, double)")
def setUp(self): ert = clib.ert_load("libert_util") self.ert_wrapper = CWrapper(ert) self.ert_wrapper.registerType("time_t", TimeTValue) self.make_date = self.ert_wrapper.prototype( "time_t util_make_date(int, int, int)")
class BaseCValueTest(ExtendedTestCase): def setUp(self): ert = clib.ert_load("libert_util") self.ert_wrapper = CWrapper(ert) self.ert_wrapper.registerType("time_t", TimeTValue) self.make_date = self.ert_wrapper.prototype("time_t util_make_date(int, int, int)") def test_illegal_type(self): class ExceptionValueTest(BaseCValue): DATA_TYPE = str def __init__(self, value): super(ExceptionValueTest, self).__init__(value) with self.assertRaises(ValueError): test = ExceptionValueTest("Failure") class NoDataTypeTest(BaseCValue): def __init__(self, value): super(NoDataTypeTest, self).__init__(value) with self.assertRaises(ValueError): test = ExceptionValueTest(0) def test_creation(self): test_value = UnsignedByteValue(255) self.assertEqual(test_value.value(), 255) test_value.setValue(256) self.assertEqual(test_value.value(), 0) self.assertEqual(test_value.type(), c_ubyte) def test_from_param(self): test_value = UnsignedByteValue(127) self.assertEqual(UnsignedByteValue.from_param(test_value).value, 127) with self.assertRaises(AttributeError): UnsignedByteValue.from_param(None) with self.assertRaises(ValueError): UnsignedByteValue.from_param("exception") def test_time_t(self): future = self.make_date(1, 1, 2050) self.assertIsInstance(future, TimeTValue) self.assertEqual(future.value(), 2524604400)
class BaseCValueTest(ExtendedTestCase): def setUp(self): ert = clib.ert_load("libert_util") self.ert_wrapper = CWrapper(ert) self.ert_wrapper.registerType("pow_double", MaxDouble) self.double_max = self.ert_wrapper.prototype("pow_double util_double_max(double, double)") def test_illegal_type(self): class ExceptionValueTest(BaseCValue): DATA_TYPE = str def __init__(self, value): super(ExceptionValueTest, self).__init__(value) with self.assertRaises(ValueError): test = ExceptionValueTest("Failure") class NoDataTypeTest(BaseCValue): def __init__(self, value): super(NoDataTypeTest, self).__init__(value) with self.assertRaises(ValueError): test = ExceptionValueTest(0) def test_creation(self): test_value = UnsignedByteValue(255) self.assertEqual(test_value.value(), 255) test_value.setValue(256) self.assertEqual(test_value.value(), 0) self.assertEqual(test_value.type(), c_ubyte) def test_from_param(self): test_value = UnsignedByteValue(127) self.assertEqual(UnsignedByteValue.from_param(test_value).value, 127) with self.assertRaises(AttributeError): UnsignedByteValue.from_param(None) with self.assertRaises(ValueError): UnsignedByteValue.from_param("exception") def test_double_max(self): double_max = self.double_max(2.97, 2.98) self.assertIsInstance(double_max, MaxDouble) self.assertEqual(double_max.value(), 2.98)
class BaseCValueTest(ExtendedTestCase): def setUp(self): ert = clib.ert_load("libert_util") self.ert_wrapper = CWrapper(ert) self.ert_wrapper.registerType("pow_double", MaxDouble) self.double_max = self.ert_wrapper.prototype( "pow_double util_double_max(double, double)") def test_illegal_type(self): class ExceptionValueTest(BaseCValue): DATA_TYPE = str def __init__(self, value): super(ExceptionValueTest, self).__init__(value) with self.assertRaises(ValueError): test = ExceptionValueTest("Failure") class NoDataTypeTest(BaseCValue): def __init__(self, value): super(NoDataTypeTest, self).__init__(value) with self.assertRaises(ValueError): test = ExceptionValueTest(0) def test_creation(self): test_value = UnsignedByteValue(255) self.assertEqual(test_value.value(), 255) test_value.setValue(256) self.assertEqual(test_value.value(), 0) self.assertEqual(test_value.type(), c_ubyte) def test_from_param(self): test_value = UnsignedByteValue(127) self.assertEqual(UnsignedByteValue.from_param(test_value).value, 127) with self.assertRaises(AttributeError): UnsignedByteValue.from_param(None) with self.assertRaises(ValueError): UnsignedByteValue.from_param("exception") def test_double_max(self): double_max = self.double_max(2.97, 2.98) self.assertIsInstance(double_max, MaxDouble) self.assertEqual(double_max.value(), 2.98)
class BaseCValueTest(ExtendedTestCase): def setUp(self): ert = clib.ert_load("libert_util") self.ert_wrapper = CWrapper(ert) self.ert_wrapper.registerType("time_t", TimeTValue) self.make_date = self.ert_wrapper.prototype( "time_t util_make_date(int, int, int)") def test_illegal_type(self): class ExceptionValueTest(BaseCValue): DATA_TYPE = str def __init__(self, value): super(ExceptionValueTest, self).__init__(value) with self.assertRaises(ValueError): test = ExceptionValueTest("Failure") class NoDataTypeTest(BaseCValue): def __init__(self, value): super(NoDataTypeTest, self).__init__(value) with self.assertRaises(ValueError): test = ExceptionValueTest(0) def test_creation(self): test_value = UnsignedByteValue(255) self.assertEqual(test_value.value(), 255) test_value.setValue(256) self.assertEqual(test_value.value(), 0) self.assertEqual(test_value.type(), c_ubyte) def test_from_param(self): test_value = UnsignedByteValue(127) self.assertEqual(UnsignedByteValue.from_param(test_value).value, 127) with self.assertRaises(AttributeError): UnsignedByteValue.from_param(None) with self.assertRaises(ValueError): UnsignedByteValue.from_param("exception") def test_time_t(self): future = self.make_date(1, 1, 2050) self.assertIsInstance(future, TimeTValue) self.assertEqual(future.value(), 2524604400)
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()") date_stamp = dateStamp() self.assertIsInstance(date_stamp, str)
def setUp(self): ert = clib.ert_load("libert_util") self.ert_wrapper = CWrapper(ert) self.ert_wrapper.registerType("pow_double", MaxDouble) self.double_max = self.ert_wrapper.prototype("pow_double util_double_max(double, double)")
def setUp(self): ert = clib.ert_load("libert_util") self.ert_wrapper = CWrapper(ert) self.ert_wrapper.registerType("time_t", TimeTValue) self.make_date = self.ert_wrapper.prototype("time_t util_make_date(int, int, int)")
for index in range(self.getKeyWordCount()): kw = self.getKeyWordForIndex(index) if kw == keyword: return index return None def shouldUseLogScale(self, index): """ @rtype: bool """ return bool(EnsemblePlotGenKW.cNamespace().should_use_log_scale( self, index)) def free(self): EnsemblePlotGenKW.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("ensemble_plot_gen_kw", EnsemblePlotGenKW) cwrapper.registerType("ensemble_plot_gen_kw_obj", EnsemblePlotGenKW.createPythonObject) cwrapper.registerType("ensemble_plot_gen_kw_ref", EnsemblePlotGenKW.createCReference) EnsemblePlotGenKW.cNamespace().free = cwrapper.prototype( "void enkf_plot_gen_kw_free(ensemble_plot_gen_kw)") EnsemblePlotGenKW.cNamespace().alloc = cwrapper.prototype( "c_void_p enkf_plot_gen_kw_alloc(enkf_config_node)") EnsemblePlotGenKW.cNamespace().size = cwrapper.prototype( "int enkf_plot_gen_kw_get_size(ensemble_plot_gen_kw)") EnsemblePlotGenKW.cNamespace().load = cwrapper.prototype( "void enkf_plot_gen_kw_load(ensemble_plot_gen_kw, enkf_fs, bool, int, bool_vector)"
return ModelConfig.cNamespace().get_case_table_file(self) def get_runpath_as_char(self): """ @rtype: str """ return ModelConfig.cNamespace().get_runpath_as_char(self) def select_runpath(self, path_key): """ @rtype: bool """ return ModelConfig.cNamespace().select_runpath(self, path_key) def free(self): ModelConfig.cNamespace().free(self) ################################################################## cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("model_config", ModelConfig) cwrapper.registerType("model_config_obj", ModelConfig.createPythonObject) cwrapper.registerType("model_config_ref", ModelConfig.createCReference) ################################################################## ################################################################## ModelConfig.cNamespace().free = cwrapper.prototype("void model_config_free( model_config )") ModelConfig.cNamespace().get_enkf_sched_file = cwrapper.prototype("char* model_config_get_enkf_sched_file( model_config )") ModelConfig.cNamespace().set_enkf_sched_file = cwrapper.prototype("void model_config_set_enkf_sched_file( model_config, char*)") 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)")
import sys from types import IntType, SliceType from ert.cwrap import CWrapper, CFILE, BaseCClass from ert.util import UTIL_LIB class PermutationVector(BaseCClass): def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def free(self): PermutationVector.cNamespace().free(self) CWrapper.registerObjectType("permutation_vector", PermutationVector) cwrapper = CWrapper(UTIL_LIB) PermutationVector.cNamespace().free = cwrapper.prototype( "void util_safe_free(permutation_vector)") # TVector takes advantage of the fact that self.cNamespace belongs to the inheriting class class VectorTemplate(BaseCClass): @classmethod def strided_copy(cls, obj, slice_range): """ Will create a new copy according to @slice. Mainly a support function to support slice based lookup like
from ert.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 = clib.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 ): with ErtTestContext("gen_data_config_test", self.config_file) as test_context: ert = test_context.getErt()
returned. The (i,j,k) input values should be zero offset, i.e. you must subtract 1 from the (i,j,k) values given in the ECLIPSE input. """ cell_ptr = cfunc_rft.lookup_ijk( self , ijk[0] , ijk[1] , ijk[2]) if cell_ptr: return self.__cell_ref( cell_ptr ) else: return None # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_rft_file" , EclRFTFile ) cwrapper.registerType( "ecl_rft" , EclRFT ) cfunc_file = CWrapperNameSpace("ecl_rft_file") cfunc_rft = CWrapperNameSpace("ecl_rft") cfunc_file.load = cwrapper.prototype("c_void_p ecl_rft_file_alloc_case( char* )") cfunc_file.has_rft = cwrapper.prototype("bool ecl_rft_file_case_has_rft( char* )") cfunc_file.free = cwrapper.prototype("void ecl_rft_file_free( ecl_rft_file )") cfunc_file.get_size = cwrapper.prototype("int ecl_rft_file_get_size__( ecl_rft_file , char* , time_t)") cfunc_file.iget = cwrapper.prototype("c_void_p ecl_rft_file_iget_node( ecl_rft_file , int )") cfunc_file.get_num_wells = cwrapper.prototype("int ecl_rft_file_get_num_wells( ecl_rft_file )") cfunc_file.get_rft = cwrapper.prototype("c_void_p ecl_rft_file_get_well_time_rft( ecl_rft_file , char* , time_t)") cfunc_rft.get_type = cwrapper.prototype("int ecl_rft_node_get_type( ecl_rft )")
def registerEnum(cls, library, enum_name): cwrapper = CWrapper(library) cwrapper.registerType(enum_name, cls)
from ert.cwrap import BaseCClass, CWrapper from ert.enkf import ENKF_LIB class ActiveList(BaseCClass): def __init__(self): c_ptr = ActiveList.cNamespace().alloc() super(ActiveList, self).__init__(c_ptr) def getMode(self): return ActiveList.cNamespace().get_mode(self) def addActiveIndex(self, index): ActiveList.cNamespace().add_index(self, index) def free(self): ActiveList.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("active_list", ActiveList) ActiveList.cNamespace().alloc = cwrapper.prototype( "c_void_p active_list_alloc()") ActiveList.cNamespace().free = cwrapper.prototype( "void active_list_free(active_list)") ActiveList.cNamespace().get_mode = cwrapper.prototype( "active_mode_enum active_list_get_mode(active_list)") ActiveList.cNamespace().add_index = cwrapper.prototype( "void active_list_add_index(active_list , int)")
# # See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> # for more details. from ert.cwrap import CWrapper from ert.util import UTIL_LIB, VectorTemplate class DoubleVector(VectorTemplate): default_format = "%8.4f" def __init__(self, default_value=0, initial_size=0): super(DoubleVector, self).__init__(default_value, initial_size) cwrapper = CWrapper(UTIL_LIB) CWrapper.registerObjectType("double_vector", DoubleVector) DoubleVector.cNamespace().alloc = cwrapper.prototype( "c_void_p double_vector_alloc( int , double )") DoubleVector.cNamespace().alloc_copy = cwrapper.prototype( "double_vector_obj double_vector_alloc_copy( double_vector )") DoubleVector.cNamespace().strided_copy = cwrapper.prototype( "double_vector_obj double_vector_alloc_strided_copy( double_vector , int , int , int)" ) DoubleVector.cNamespace().free = cwrapper.prototype( "void double_vector_free( double_vector )") DoubleVector.cNamespace().iget = cwrapper.prototype( "double double_vector_iget( double_vector , int )") DoubleVector.cNamespace().safe_iget = cwrapper.prototype( "double double_vector_safe_iget(double_vector , int )")
""" @rtype: JobQueue """ return SiteConfig.cNamespace().get_job_queue(self).setParent(self) def getRshHostList(self): """ @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 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().set_job_queue = cwrapper.prototype( "void site_config_set_job_queue(site_config, char*)") 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(
else: raise TypeError("The kw type must be string. Input:%s" % kw) def __contains__(self , kw): return EnKFState.cNamespace().has_key( self , kw ) def hasKey(self , kw): return kw in self def getNode(self , kw): return self[kw] def free(self): EnKFState.cNamespace().free(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* )")
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)")
ecl_type = self.getEclType() if ecl_type == EclTypeEnum.ECL_INT_TYPE: return cfunc.int_ptr(self) elif ecl_type == EclTypeEnum.ECL_FLOAT_TYPE: return cfunc.float_ptr(self) elif ecl_type == EclTypeEnum.ECL_DOUBLE_TYPE: return cfunc.double_ptr(self) else: raise ValueError("Only numeric types can export data pointer") ################################################################# # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW cwrapper = CWrapper(ECL_LIB) cwrapper.registerType("ecl_kw", EclKW) # 3. Installing the c-functions used to manipulate ecl_kw instances. # These functions are used when implementing the EclKW class, not # used outside this scope. cfunc = CWrapperNameSpace("ecl_kw") cfunc.load_grdecl = cwrapper.prototype( "c_void_p ecl_kw_fscanf_alloc_grdecl_dynamic__( FILE , char* , bool , int )" ) cfunc.fseek_grdecl = cwrapper.prototype( "bool ecl_kw_grdecl_fseek_kw(char* , bool , FILE )") cfunc.fprintf_grdecl = cwrapper.prototype( "void ecl_kw_fprintf_grdecl( ecl_kw , FILE )") cfunc.fprintf_data = cwrapper.prototype(
def runPostWorkflow(self): post_simulation_hook = self.ert.getPostSimulationHook() if post_simulation_hook.hasWorkflow(): post_simulation_hook.checkRunpathListFile() workflow = post_simulation_hook.getWorkflow() workflow_list = self.ert.getWorkflowList() workflow.run(self.ert, context=workflow_list.getContext()) def smootherUpdate(self, target_fs): """ @rtype: bool """ assert isinstance(target_fs, EnkfFs) return EnkfSimulationRunner.cNamespace().smoother_update( self, target_fs) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("enkf_simulation_runner", EnkfSimulationRunner) EnkfSimulationRunner.cNamespace().run_assimilation = cwrapper.prototype( "void enkf_main_run_assimilation(enkf_simulation_runner, bool_vector, int, int, int)" ) EnkfSimulationRunner.cNamespace().run_smoother = cwrapper.prototype( "void enkf_main_run_smoother(enkf_simulation_runner, char*, bool)") EnkfSimulationRunner.cNamespace().run_simple_step = cwrapper.prototype( "bool enkf_main_run_simple_step(enkf_simulation_runner, bool_vector, enkf_init_mode_enum, int)" ) EnkfSimulationRunner.cNamespace().smoother_update = cwrapper.prototype( "bool enkf_main_smoother_update(enkf_simulation_runner, enkf_fs)")
kw_copy.assign( default_value ) cfunc.global_kw_copy( self , kw_copy , kw) return kw_copy else: raise ValueError("The input keyword must have nx*n*nz or nactive elements. Size:%d invalid" % len(kw)) def exportACTNUMKw(self): actnum = EclKW.create("ACTNUM" , self.getGlobalSize() , EclTypeEnum.ECL_INT_TYPE) cfunc.init_actnum( self , actnum.getDataPtr() ) return actnum # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_grid" , EclGrid ) # 3. Installing the c-functions used to manipulate ecl_kw instances. # These functions are used when implementing the EclKW class, not # used outside this scope. cfunc = CWrapperNameSpace("ecl_grid") cfunc.fread_alloc = cwrapper.prototype("c_void_p ecl_grid_load_case( char* )") cfunc.grdecl_create = cwrapper.prototype("c_void_p ecl_grid_alloc_GRDECL_kw( int , int , int , ecl_kw , ecl_kw , ecl_kw , ecl_kw)") cfunc.get_lgr = cwrapper.prototype("c_void_p ecl_grid_get_lgr( ecl_grid , char* )") cfunc.get_cell_lgr = cwrapper.prototype("c_void_p ecl_grid_get_cell_lgr1( ecl_grid , int )") cfunc.alloc_rectangular = cwrapper.prototype("c_void_p ecl_grid_alloc_rectangular( int , int , int , double , double , double , int*)")
from ctypes import Structure, c_int from ert.cwrap import CWrapper from ert.enkf.enums import EnkfStateType class NodeId(Structure): """ NodeId is specified in enkf_types.h """ _fields_ = [("report_step", c_int), ("iens", c_int), ("state", c_int)] def __init__(self, report_step, realization_number, state): """ @type report_step: int @type realization_number: int @type state: EnkfStateType """ super(NodeId, self).__init__(report_step, realization_number, state) CWrapper.registerType("node_id", NodeId)
result = super(EclSum, cls).createCReference(c_pointer, parent) result._initialize() return result @classmethod def createPythonObject(cls, c_pointer): result = super(EclSum, cls).createPythonObject(c_pointer) result._initialize() return result ################################################################# # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_sum" , EclSum ) cwrapper.registerType( "ecl_sum_obj" , EclSum.createPythonObject ) cwrapper.registerType( "ecl_sum_ref" , EclSum.createCReference ) # 3. Installing the c-functions used to manipulate ecl_kw instances. # These functions are used when implementing the EclKW class, not # used outside this scope. EclSum.cNamespace().fread_alloc = cwrapper.prototype("c_void_p ecl_sum_fread_alloc_case__( char* , char* , bool)") EclSum.cNamespace().iiget = cwrapper.prototype("double ecl_sum_iget( ecl_sum , int , int)") EclSum.cNamespace().free = cwrapper.prototype("void ecl_sum_free( ecl_sum )") EclSum.cNamespace().data_length = cwrapper.prototype("int ecl_sum_get_data_length( ecl_sum )") EclSum.cNamespace().iget_sim_days = cwrapper.prototype("double ecl_sum_iget_sim_days( ecl_sum , int) ")
@type realization_number: int @type iteration_number: int @type runpath: int @type basename: int """ RunpathList.cNamespace().add(self, realization_number, iteration_number, runpath, basename) def clear(self): RunpathList.cNamespace().clear(self) def free(self): RunpathList.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerObjectType("runpath_list", RunpathList) RunpathList.cNamespace().free = cwrapper.prototype( "void runpath_list_free(runpath_list)") RunpathList.cNamespace().add = cwrapper.prototype( "void runpath_list_add(runpath_list, int, int, char*, char*)") RunpathList.cNamespace().clear = cwrapper.prototype( "void runpath_list_clear(runpath_list)") RunpathList.cNamespace().size = cwrapper.prototype( "int runpath_list_size(runpath_list)") RunpathList.cNamespace().iens = cwrapper.prototype( "int runpath_list_iget_iens(runpath_list, int)") RunpathList.cNamespace().iteration = cwrapper.prototype(
def getNumRetries(self): """ @rtype: int """ return AnalysisIterConfig.cNamespace().get_num_retries(self) 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("bool analysis_iter_config_num_iterations_set(analysis_iter_config)") AnalysisIterConfig.cNamespace().set_case_fmt = cwrapper.prototype("void analysis_iter_config_set_case_fmt( analysis_iter_config , char* )") AnalysisIterConfig.cNamespace().get_case_fmt = cwrapper.prototype("char* analysis_iter_config_get_case_fmt( analysis_iter_config)") AnalysisIterConfig.cNamespace().case_fmt_set = cwrapper.prototype("bool analysis_iter_config_case_fmt_set(analysis_iter_config)")
for index in range(self.getKeyWordCount()): kw = self.getKeyWordForIndex(index) if kw == keyword: return index return None def shouldUseLogScale(self, index): """ @rtype: bool """ return bool(EnsemblePlotGenKW.cNamespace().should_use_log_scale(self, index)) def free(self): EnsemblePlotGenKW.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("ensemble_plot_gen_kw", EnsemblePlotGenKW) cwrapper.registerType("ensemble_plot_gen_kw_obj", EnsemblePlotGenKW.createPythonObject) cwrapper.registerType("ensemble_plot_gen_kw_ref", EnsemblePlotGenKW.createCReference) EnsemblePlotGenKW.cNamespace().free = cwrapper.prototype("void enkf_plot_gen_kw_free(ensemble_plot_gen_kw)") EnsemblePlotGenKW.cNamespace().alloc = cwrapper.prototype("c_void_p enkf_plot_gen_kw_alloc(enkf_config_node)") EnsemblePlotGenKW.cNamespace().size = cwrapper.prototype("int enkf_plot_gen_kw_get_size(ensemble_plot_gen_kw)") EnsemblePlotGenKW.cNamespace().load = cwrapper.prototype("void enkf_plot_gen_kw_load(ensemble_plot_gen_kw, enkf_fs, bool, int, enkf_state_type_enum, bool_vector)") EnsemblePlotGenKW.cNamespace().get = cwrapper.prototype("ensemble_plot_gen_kw_vector_ref enkf_plot_gen_kw_iget(ensemble_plot_gen_kw, int)") EnsemblePlotGenKW.cNamespace().iget_key = cwrapper.prototype("char* enkf_plot_gen_kw_iget_key(ensemble_plot_gen_kw, int)") EnsemblePlotGenKW.cNamespace().get_keyword_count = cwrapper.prototype("int enkf_plot_gen_kw_get_keyword_count(ensemble_plot_gen_kw)") EnsemblePlotGenKW.cNamespace().should_use_log_scale = cwrapper.prototype("bool enkf_plot_gen_kw_should_use_log_scale(ensemble_plot_gen_kw, int)")
return EclConfig.cNamespace().has_refcase(self) #----------------------------------------------------------------- def get_static_kw_list(self): """ @rtype: StringList """ return EclConfig.cNamespace().get_static_kw_list(self).setParent(self) def clear_static_kw(self): EclConfig.cNamespace().clear_static_kw(self) def add_static_kw(self, kw): EclConfig.cNamespace().add_static_kw(self, kw) 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*)") EclConfig.cNamespace().get_data_file = cwrapper.prototype("char* ecl_config_get_data_file(ecl_config)") EclConfig.cNamespace().set_data_file = cwrapper.prototype("void ecl_config_set_data_file(ecl_config , char*)") EclConfig.cNamespace().validate_data_file = cwrapper.prototype("ui_return_obj ecl_config_validate_data_file(ecl_config , char*)")
def submitSimulation(self , run_arg): EnKFMain.cNamespace().submit_simulation( self , run_arg) def getRunContextENSEMPLE_EXPERIMENT(self , fs , iactive , init_mode = EnkfInitModeEnum.INIT_CONDITIONAL , iteration = 0): return EnKFMain.cNamespace().alloc_run_context_ENSEMBLE_EXPERIMENT( self , fs , iactive , init_mode , iteration ) def getRunpathList(self): return EnKFMain.cNamespace().get_runpath_list( self ) ################################################################## 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*)")
bool_vector = BoolVector(False, size) for index in source_list: index = int(index) bool_vector[index] = True return bool_vector @classmethod def createActiveList(cls, mask): """ @rtype: IntVectorTemplate """ assert isinstance(mask, BoolVector) return cls.cNamespace().active_list(mask) cwrapper = CWrapper(UTIL_LIB) CWrapper.registerObjectType("bool_vector", BoolVector) BoolVector.cNamespace().alloc = cwrapper.prototype("c_void_p bool_vector_alloc( int , bool )") BoolVector.cNamespace().alloc_copy = cwrapper.prototype("bool_vector_obj bool_vector_alloc_copy( bool_vector )") BoolVector.cNamespace().strided_copy = cwrapper.prototype("bool_vector_obj bool_vector_alloc_strided_copy( bool_vector , int , int , int)") BoolVector.cNamespace().free = cwrapper.prototype("void bool_vector_free( bool_vector )") BoolVector.cNamespace().iget = cwrapper.prototype("bool bool_vector_iget( bool_vector , int )") BoolVector.cNamespace().safe_iget = cwrapper.prototype("bool bool_vector_safe_iget( bool_vector , int )") BoolVector.cNamespace().iset = cwrapper.prototype("void bool_vector_iset( bool_vector , int , bool)") BoolVector.cNamespace().size = cwrapper.prototype("int bool_vector_size( bool_vector )") BoolVector.cNamespace().append = cwrapper.prototype("void bool_vector_append( bool_vector , bool )") BoolVector.cNamespace().idel_block = cwrapper.prototype("void bool_vector_idel_block( bool_vector , bool , bool )") BoolVector.cNamespace().idel = cwrapper.prototype("void bool_vector_idel( bool_vector , int )") BoolVector.cNamespace().pop = cwrapper.prototype("bool bool_vector_pop( bool_vector )")
def __getitem__(self, index): if not isinstance(index, int): raise IndexError("Index must be a number!") if index < 0 or index >= len(self): raise IndexError("Index must be in the range: [%i, %i]" % (0, len(self) - 1)) key = SubstitutionList.cNamespace().get_key(self, index) value = SubstitutionList.cNamespace().get_value(self, index) doc_string = SubstitutionList.cNamespace().get_doc_string(self, index) return key, value, doc_string def free(self): SubstitutionList.cNamespace().free(self) cwrapper = CWrapper(UTIL_LIB) CWrapper.registerType("subst_list", SubstitutionList) CWrapper.registerType("subst_list_obj", SubstitutionList.createPythonObject) CWrapper.registerType("subst_list_ref", SubstitutionList.createCReference) SubstitutionList.cNamespace().alloc = cwrapper.prototype("c_void_p subst_list_alloc(c_void_p)") SubstitutionList.cNamespace().free = cwrapper.prototype("void subst_list_free(subst_list)") SubstitutionList.cNamespace().size = cwrapper.prototype("int subst_list_get_size(subst_list)") SubstitutionList.cNamespace().get_key = cwrapper.prototype("char* subst_list_iget_key(subst_list, int)") SubstitutionList.cNamespace().get_value = cwrapper.prototype("char* subst_list_iget_value(subst_list, int)") SubstitutionList.cNamespace().get_doc_string = cwrapper.prototype("char* subst_list_iget_doc_string(subst_list, int)") SubstitutionList.cNamespace().append_copy = cwrapper.prototype("void subst_list_append_copy(subst_list, char*, char*, char*)")
# See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> # for more details. """ Create a polygon """ from ert.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 )")
from ert.cwrap import clib, CWrapper from ert.job_queue import WorkflowJob from ert.test import TestAreaContext, ExtendedTestCase from ert_tests.job_queue.workflow_common import WorkflowCommon test_lib = clib.ert_load("libjob_queue") # create a local namespace cwrapper = CWrapper(test_lib) alloc_config = cwrapper.prototype("c_void_p workflow_job_alloc_config()") alloc_from_file = cwrapper.prototype( "workflow_job_obj workflow_job_config_alloc(char*, c_void_p, char*)") class WorkflowJobTest(ExtendedTestCase): def test_workflow_job_creation(self): workflow_job = WorkflowJob("Test") self.assertTrue(workflow_job.isInternal()) self.assertEqual(workflow_job.name(), "Test") def test_read_internal_function(self): with TestAreaContext("python/job_queue/workflow_job") as work_area: WorkflowCommon.createInternalFunctionJob() WorkflowCommon.createErtScriptsJob() config = alloc_config() workflow_job = alloc_from_file("SELECT_CASE", config, "select_case_job") self.assertEqual(workflow_job.name(), "SELECT_CASE") self.assertTrue(workflow_job.isInternal())
raise ValueError("Cell %s is not equal to %d \n" % (ij, org_value)) def cellsEqual(self, value): """ Will return a list [(i1,j1),(i2,j2) , ...(in,jn)] of all cells with value @value. """ i_list = IntVector() j_list = IntVector() Layer.cNamespace().cells_equal(self, value, i_list, j_list) ij_list = [] for (i, j) in zip(i_list, j_list): ij_list.append((i, j)) return ij_list cwrapper = CWrapper(ECL_LIB) CWrapper.registerObjectType("layer", Layer) Layer.cNamespace().alloc = cwrapper.prototype( "c_void_p layer_alloc(int, int)") Layer.cNamespace().copy = cwrapper.prototype( "void layer_memcpy(layer , layer)") Layer.cNamespace().free = cwrapper.prototype("void layer_free(layer)") Layer.cNamespace().get_nx = cwrapper.prototype("int layer_get_nx(layer)") Layer.cNamespace().get_ny = cwrapper.prototype("int layer_get_ny(layer)") Layer.cNamespace().set_cell = cwrapper.prototype( "void layer_iset_cell_value(layer , int , int , int)") Layer.cNamespace().get_cell = cwrapper.prototype( "int layer_iget_cell_value(layer , int , int )") Layer.cNamespace().get_bottom_barrier = cwrapper.prototype( "bool layer_iget_bottom_barrier(layer , int , int )") Layer.cNamespace().get_left_barrier = cwrapper.prototype(
self.__ecl_file = ecl_file def __enter__(self): return self.__ecl_file def __exit__(self, exc_type, exc_val, exc_tb): self.__ecl_file.close() return False def openEclFile(file_name, flags=0): return EclFileContextManager(EclFile(file_name, flags)) # 2. Creating a wrapper object around the libecl library, cwrapper = CWrapper(ECL_LIB) cwrapper.registerType("ecl_file", EclFile) # 3. Installing the c-functions used to manipulate ecl_file instances. # These functions are used when implementing the EclFile class, not # used outside this scope. cfunc = CWrapperNameSpace("ecl_file") cfunc.open = cwrapper.prototype("c_void_p ecl_file_open( char* , int )") cfunc.writable = cwrapper.prototype( "bool ecl_file_writable( ecl_file )") cfunc.new = cwrapper.prototype("c_void_p ecl_file_alloc_empty( )") cfunc.save_kw = cwrapper.prototype( "void ecl_file_save_kw( ecl_file , ecl_kw )") cfunc.select_block = cwrapper.prototype(
def getNumComplete(self): return JobQueueManager.cNamespace().get_num_complete(self) def isRunning(self): return JobQueueManager.cNamespace().is_running(self) def free(self): JobQueueManager.cNamespace().free(self) def jobComplete(self, job_index): return JobQueueManager.cNamespace().job_complete(self, job_index) ################################################################# cwrapper = CWrapper(JOB_QUEUE_LIB) cwrapper.registerObjectType("job_queue_manager", JobQueueManager) JobQueueManager.cNamespace().alloc = cwrapper.prototype( "c_void_p job_queue_manager_alloc( job_queue) ") JobQueueManager.cNamespace().free = cwrapper.prototype( "void job_queue_manager_free( job_queue_manager )") JobQueueManager.cNamespace().start_queue = cwrapper.prototype( "void job_queue_manager_start_queue( job_queue_manager , int , bool)") JobQueueManager.cNamespace().get_num_running = cwrapper.prototype( "int job_queue_manager_get_num_running( job_queue_manager )") JobQueueManager.cNamespace().get_num_complete = cwrapper.prototype( "int job_queue_manager_get_num_complete( job_queue_manager )") JobQueueManager.cNamespace().is_running = cwrapper.prototype( "bool job_queue_manager_is_running( job_queue_manager )") JobQueueManager.cNamespace().job_complete = cwrapper.prototype(
return self.getDataModelConfig() elif implementation_type == ErtImplType.GEN_KW: return self.getKeywordModelConfig() 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("char* enkf_config_node_get_enkf_infile(enkf_config_node)") EnkfConfigNode.cNamespace().get_init_file_fmt = cwrapper.prototype("char* enkf_config_node_get_init_file_fmt(enkf_config_node)") EnkfConfigNode.cNamespace().get_var_type = cwrapper.prototype("enkf_var_type_enum enkf_config_node_get_var_type(enkf_config_node)") #todo: fix return type as enum EnkfConfigNode.cNamespace().get_key = cwrapper.prototype("char* enkf_config_node_get_key(enkf_config_node)") EnkfConfigNode.cNamespace().get_obs_keys = cwrapper.prototype("stringlist_ref enkf_config_node_get_obs_keys(enkf_config_node)") EnkfConfigNode.cNamespace().alloc_summary_node = cwrapper.prototype("enkf_config_node_obj enkf_config_node_alloc_summary(char*, load_fail_type)") EnkfConfigNode.cNamespace().alloc_field_node = cwrapper.prototype("enkf_config_node_obj enkf_config_node_alloc_field(char*, ecl_grid, c_void_p, bool)")
return FieldConfig.cNamespace().get_nx(self) 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
def __len__(self): """ @rtype: int """ return WellTimeLine.cNamespace().size(self) def __getitem__(self, index): """ @type index: int @rtype: WellState """ if index < 0: index += len(self) if not 0 <= index < len(self): raise IndexError("Index must be in range 0 <= %d < %d" % (index, len(self))) return WellTimeLine.cNamespace().iget(self, index).setParent(self) def free(self): pass CWrapper.registerObjectType("well_time_line", WellTimeLine) cwrapper = CWrapper(ECL_WELL_LIB) WellTimeLine.cNamespace().size = cwrapper.prototype( "int well_ts_get_size(well_time_line)") WellTimeLine.cNamespace().iget = cwrapper.prototype( "well_state_ref well_ts_iget_state(well_time_line, int)")
value = float(value) if isinstance(value, float): DoubleHash.cNamespace().insert_double(self, key, value) else: raise ValueError("DoubleHash does not support type: %s" % value.__class__) def __getitem__(self, key): if key in self: return DoubleHash.cNamespace().get_double(self, key) else: raise KeyError("Hash does not have key: %s" % key) cwrapper = CWrapper(UTIL_LIB) CWrapper.registerObjectType("hash", Hash) # c_void_p type CWrapper.registerObjectType("integer_hash", IntegerHash) CWrapper.registerObjectType("string_hash", StringHash) CWrapper.registerObjectType("double_hash", DoubleHash) Hash.cNamespace().alloc = cwrapper.prototype("long hash_alloc()") Hash.cNamespace().free = cwrapper.prototype("void hash_free(hash)") Hash.cNamespace().size = cwrapper.prototype("int hash_get_size(hash)") Hash.cNamespace().keys = cwrapper.prototype( "stringlist_obj hash_alloc_stringlist(hash)") Hash.cNamespace().has_key = cwrapper.prototype( "bool hash_has_key(hash, char*)") Hash.cNamespace().get = cwrapper.prototype("c_void_p hash_get(hash, char*)") IntegerHash.cNamespace().get_int = cwrapper.prototype(
self.__test_name = test_name self.__model_config = model_config self.__site_config = site_config self.__store_area = store_area self.__test_context = ErtTest(self.__test_name, self.__model_config, site_config=self.__site_config, store_area=self.__store_area) def __enter__(self): """ @rtype: ErtTest """ 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.registerObjectType("ert_test", ErtTest) 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 )")
raise NotImplementedError("Class can not be instantiated directly!") def joblist(self): """ @rtype: StringList """ return ForwardModel.cNamespace().alloc_joblist(self) def iget_job(self, index): """ @rtype: ExtJob """ return ForwardModel.cNamespace().iget_job(self, index).setParent(self) def add_job(self, name): """ @rtype: ExtJob """ return ForwardModel.cNamespace().add_job(self, name).setParent(self) def clear(self): ForwardModel.cNamespace().clear(self) def free(self): ForwardModel.cNamespace().free(self) cwrapper = CWrapper(JOB_QUEUE_LIB) cwrapper.registerType("forward_model", ForwardModel) cwrapper.registerType("forward_model_obj", ForwardModel.createPythonObject) cwrapper.registerType("forward_model_ref", ForwardModel.createCReference) ForwardModel.cNamespace().free = cwrapper.prototype("void forward_model_free( forward_model )") ForwardModel.cNamespace().clear = cwrapper.prototype("void forward_model_clear(forward_model)") ForwardModel.cNamespace().add_job = cwrapper.prototype("ext_job_ref forward_model_add_job(forward_model, char*)") ForwardModel.cNamespace().alloc_joblist = cwrapper.prototype("stringlist_obj forward_model_alloc_joblist(forward_model)") ForwardModel.cNamespace().iget_job = cwrapper.prototype("ext_job_ref forward_model_iget_job( forward_model, int)")
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("stringlist_obj gen_kw_config_alloc_name_list(gen_kw_config)") GenKwConfig.cNamespace().should_use_log_scale = cwrapper.prototype("bool gen_kw_config_should_use_log_scale(gen_kw_config, int)") GenKwConfig.cNamespace().get_key = cwrapper.prototype("char* gen_kw_config_get_key(gen_kw_config)") GenKwConfig.cNamespace().size = cwrapper.prototype("int gen_kw_config_get_data_size(gen_kw_config)") GenKwConfig.cNamespace().iget_name = cwrapper.prototype("char* gen_kw_config_iget_name(gen_kw_config, int)")
if os.path.exists(config_file): config_content = ConfigParser.cNamespace().parse(self, config_file, comment_string, include_kw, define_kw, unrecognized, validate) if config_content.isValid(): return config_content else: raise Exception("Parsing:%s failed" % config_file) else: raise IOError("File: %s does not exists" % config_file) def free(self): ConfigParser.cNamespace().free(self) cwrapper = CWrapper(CONFIG_LIB) cwrapper.registerObjectType("config_parser", ConfigParser) cwrapper.registerObjectType("schema_item", SchemaItem) ConfigParser.cNamespace().alloc = cwrapper.prototype("c_void_p config_alloc( )") ConfigParser.cNamespace().add = cwrapper.prototype("schema_item_ref config_add_schema_item( config_parser , char* , bool)") ConfigParser.cNamespace().free = cwrapper.prototype("void config_free( config_parser )") ConfigParser.cNamespace().parse = cwrapper.prototype("config_content_obj config_parse( config_parser , char* , char* , char* , char* , config_unrecognized_enum , bool )") ConfigParser.cNamespace().get_schema_item = cwrapper.prototype("schema_item_ref config_get_schema_item( config_parser , char*)") ConfigParser.cNamespace().has_schema_item = cwrapper.prototype("bool config_has_schema_item( config_parser , char*)") SchemaItem.cNamespace().alloc = cwrapper.prototype("c_void_p config_schema_item_alloc( char* , bool )") SchemaItem.cNamespace().free = cwrapper.prototype("void config_schema_item_free( schema_item )") SchemaItem.cNamespace().iget_type = cwrapper.prototype("config_content_type_enum config_schema_item_iget_type( schema_item, int)") SchemaItem.cNamespace().iset_type = cwrapper.prototype("void config_schema_item_iset_type( schema_item , int , config_content_type_enum)")
""" @rtype: EnkfConfigNode """ return EnsConfig.cNamespace().add_gen_data(self, key).setParent(self) def add_field(self, key, eclipse_grid): """ @rtype: EnkfConfigNode """ return EnsConfig.cNamespace().add_field(self, key, eclipse_grid).setParent(self) def getKeylistFromVarType(self, var_mask): """ @rtype: StringList """ assert isinstance(var_mask, EnkfVarType) return EnsConfig.cNamespace().alloc_keylist_from_var_type(self, var_mask).setParent(self) def free(self): EnsConfig.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("ens_config", EnsConfig) cwrapper.registerType("ens_config_obj", EnsConfig.createPythonObject) cwrapper.registerType("ens_config_ref", EnsConfig.createCReference) EnsConfig.cNamespace().free = cwrapper.prototype("void ensemble_config_free( ens_config )") EnsConfig.cNamespace().has_key = cwrapper.prototype("bool ensemble_config_has_key( ens_config , char* )") EnsConfig.cNamespace().get_node = cwrapper.prototype("enkf_config_node_ref ensemble_config_get_node( ens_config , char*)") EnsConfig.cNamespace().alloc_keylist = cwrapper.prototype("stringlist_ref ensemble_config_alloc_keylist( ens_config )") EnsConfig.cNamespace().add_summary = cwrapper.prototype("enkf_config_node_ref ensemble_config_add_summary( ens_config, char*, int)") EnsConfig.cNamespace().add_gen_kw = cwrapper.prototype("enkf_config_node_ref ensemble_config_add_gen_kw( ens_config, char*)") EnsConfig.cNamespace().add_gen_data = cwrapper.prototype("enkf_config_node_ref ensemble_config_add_gen_data( ens_config, char*)") EnsConfig.cNamespace().add_field = cwrapper.prototype("enkf_config_node_ref ensemble_config_add_field( ens_config, char*, ecl_grid)") EnsConfig.cNamespace().alloc_keylist_from_var_type = cwrapper.prototype("stringlist_ref ensemble_config_alloc_keylist_from_var_type(ens_config, enkf_var_type_enum)")
def igetMean(self , iobs): if 0 <= iobs < self.getObsSize(): 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("void meas_block_iset( meas_block , int , int , double)") MeasBlock.cNamespace().iget_mean = cwrapper.prototype("double meas_block_iget_ens_mean( meas_block , int )") MeasBlock.cNamespace().iget_std = cwrapper.prototype("double meas_block_iget_ens_std( meas_block , int )") MeasBlock.cNamespace().iens_active = cwrapper.prototype("bool meas_block_iens_active( meas_block , int )")
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*)")
def iget_node(self, index): ObsVector.cNamespace().iget_node(self, index) #warn: should return something! def get_num_active(self): """ @rtype: int """ return ObsVector.cNamespace().get_num_active(self) def iget_active(self, index): """ @rtype: bool """ return ObsVector.cNamespace().iget_active(self, index) def free(self): ObsVector.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("obs_vector", ObsVector) cwrapper.registerType("obs_vector_obj", ObsVector.createPythonObject) cwrapper.registerType("obs_vector_ref", ObsVector.createCReference) # 3. Installing the c-functions used to manipulate ecl_kw instances. # These functions are used when implementing the EclKW class, not # used outside this scope. 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().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)")
def get_template_file(self): """ @rtype: str """ return ErtTemplate.cNamespace().get_template_file(self) def get_target_file(self): """ @rtype: str """ return ErtTemplate.cNamespace().get_target_file(self) def get_args_as_string(self): """ @rtype: str """ return ErtTemplate.cNamespace().get_args_as_string(self) def free(self): ErtTemplate.cNamespace().free(self) cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("ert_template", ErtTemplate) cwrapper.registerType("ert_template_obj", ErtTemplate.createPythonObject) cwrapper.registerType("ert_template_ref", ErtTemplate.createCReference) ErtTemplate.cNamespace().free = cwrapper.prototype( "void ert_template_free( ert_template )") ErtTemplate.cNamespace().get_template_file = cwrapper.prototype( "char* ert_template_get_template_file(ert_template)") ErtTemplate.cNamespace().get_target_file = cwrapper.prototype( "char* ert_template_get_target_file(ert_template)") ErtTemplate.cNamespace().get_args_as_string = cwrapper.prototype( "char* ert_template_get_args_as_string(ert_template)")
def getModuleList(self): return AnalysisConfig.cNamespace().get_module_list(self) def getModule(self, module_name): """ @rtype: AnalysisModule """ return AnalysisConfig.cNamespace().get_module(self, module_name) def selectModule(self, module_name): """ @rtype: bool """ return AnalysisConfig.cNamespace().select_module(self, module_name) ################################################################## cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("analysis_config", AnalysisConfig) cwrapper.registerType("analysis_config_obj", AnalysisConfig.createPythonObject) cwrapper.registerType("analysis_config_ref", AnalysisConfig.createCReference) AnalysisConfig.cNamespace().alloc = cwrapper.prototype("c_void_p analysis_config_alloc()") AnalysisConfig.cNamespace().free = cwrapper.prototype("void analysis_config_free( analysis_config )") AnalysisConfig.cNamespace().get_rerun = cwrapper.prototype("int analysis_config_get_rerun( analysis_config )") AnalysisConfig.cNamespace().set_rerun = cwrapper.prototype("void analysis_config_set_rerun( analysis_config, bool)") AnalysisConfig.cNamespace().get_rerun_start = cwrapper.prototype("int analysis_config_get_rerun_start( analysis_config )") AnalysisConfig.cNamespace().set_rerun_start = cwrapper.prototype("void analysis_config_set_rerun_start( analysis_config, int)") AnalysisConfig.cNamespace().get_log_path = cwrapper.prototype("char* analysis_config_get_log_path( analysis_config)") AnalysisConfig.cNamespace().set_log_path = cwrapper.prototype("void analysis_config_set_log_path( analysis_config, char*)") AnalysisConfig.cNamespace().get_alpha = cwrapper.prototype("double analysis_config_get_alpha(analysis_config)") AnalysisConfig.cNamespace().set_alpha = cwrapper.prototype("void analysis_config_set_alpha(analysis_config, double)") AnalysisConfig.cNamespace().get_merge_observations = cwrapper.prototype("bool analysis_config_get_merge_observations(analysis_config)")
else: super(EclSumKeyWordVector, self).__init__(c_pointer) def __len__(self): return EclSumKeyWordVector.cNamespace().get_size(self) def free(self): EclSumKeyWordVector.cNamespace().free(self) def addKeyword(self, keyword): success = EclSumKeyWordVector.cNamespace().add(self, keyword) if not success: raise KeyError("Failed to add keyword to vector") def addKeywords(self, keyword_pattern): EclSumKeyWordVector.cNamespace().add_multiple(self, keyword_pattern) cwrapper = CWrapper(ECL_LIB) cwrapper.registerType("ecl_sum_vector", EclSumKeyWordVector) cwrapper.registerType("ecl_sum_vector_obj", EclSumKeyWordVector.createPythonObject) cwrapper.registerType("ecl_sum_vector_ref", EclSumKeyWordVector.createCReference) EclSumKeyWordVector.cNamespace().alloc = cwrapper.prototype("c_void_p ecl_sum_vector_alloc(ecl_sum )") EclSumKeyWordVector.cNamespace().free = cwrapper.prototype("void ecl_sum_vector_free(ecl_sum_vector )") EclSumKeyWordVector.cNamespace().add = cwrapper.prototype("bool ecl_sum_vector_add_key( ecl_sum_vector , char* )") EclSumKeyWordVector.cNamespace().add_multiple = cwrapper.prototype( "void ecl_sum_vector_add_keys( ecl_sum_vector , char* )" ) EclSumKeyWordVector.cNamespace().get_size = cwrapper.prototype("int ecl_sum_vector_get_size( ecl_sum_vector )")
return kw_copy else: raise ValueError( "The input keyword must have nx*n*nz or nactive elements. Size:%d invalid" % len(kw)) def exportACTNUMKw(self): actnum = EclKW.create("ACTNUM", self.getGlobalSize(), EclTypeEnum.ECL_INT_TYPE) cfunc.init_actnum(self, actnum.getDataPtr()) return actnum # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW cwrapper = CWrapper(ECL_LIB) cwrapper.registerType("ecl_grid", EclGrid) # 3. Installing the c-functions used to manipulate ecl_kw instances. # These functions are used when implementing the EclKW class, not # used outside this scope. cfunc = CWrapperNameSpace("ecl_grid") cfunc.fread_alloc = cwrapper.prototype("c_void_p ecl_grid_load_case( char* )") cfunc.grdecl_create = cwrapper.prototype( "c_void_p ecl_grid_alloc_GRDECL_kw( int , int , int , ecl_kw , ecl_kw , ecl_kw , ecl_kw)" ) cfunc.get_lgr = cwrapper.prototype( "c_void_p ecl_grid_get_lgr( ecl_grid , char* )") cfunc.get_cell_lgr = cwrapper.prototype( "c_void_p ecl_grid_get_cell_lgr1( ecl_grid , int )")
def runIteratedEnsembleSmoother(self, last_report_step): #warn: Remember to select correct analysis module RML EnKFMain.cNamespace().run_iterated_ensemble_smoother(self, last_report_step) def runOneMoreIteration(self, last_report_step): #warn: need some way of validating that the case has run EnKFMain.cNamespace().run_one_more_iteration(self, last_report_step) def isCaseInitialized(self, case): return EnKFMain.cNamespace().is_case_initialized(self, case, None) ################################################################## cwrapper = CWrapper(ENKF_LIB) cwrapper.registerType("enkf_main", EnKFMain) EnKFMain.cNamespace().bootstrap = cwrapper.prototype("c_void_p enkf_main_bootstrap(char*, 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("void enkf_main_set_eclbase( enkf_main, char*)")
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* , 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 )")
class SchedFile(BaseCClass): def __init__(self, filename, start_time): if os.path.isfile(filename): c_ptr = SchedFile.cNamespace().parse(filename, CTime(start_time)) super(SchedFile, self).__init__(c_ptr) else: raise IOError("No such file: %s" % filename) @property def length(self): """ @rtype: int """ return SchedFile.cNamespace().length(self) def write(self, filename, num_dates, add_end=True): SchedFile.cNamespace().write(self, num_dates, filename, add_end) def free(self): SchedFile.cNamespace().free(self) cwrapper = CWrapper(SCHED_LIB) cwrapper.registerType("sched_file", SchedFile) cwrapper.registerType("sched_file_obj", SchedFile.createPythonObject) cwrapper.registerType("sched_file_ref", SchedFile.createCReference) SchedFile.cNamespace().parse = cwrapper.prototype("c_void_p sched_file_parse_alloc( char*, time_t )") SchedFile.cNamespace().write = cwrapper.prototype("void sched_file_fprintf_i( sched_file , int , char* , bool)") SchedFile.cNamespace().length = cwrapper.prototype("int sched_file_get_num_restart_files( sched_file )") SchedFile.cNamespace().free = cwrapper.prototype("void sched_file_free( sched_file )")