コード例 #1
0
    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])))
コード例 #2
0
ファイル: test_basecvalue.py プロジェクト: bramirex/ert
    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)")
コード例 #3
0
ファイル: test_basecvalue.py プロジェクト: danielfmva/ert
    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)")
コード例 #4
0
ファイル: ert_test_context.py プロジェクト: danielfmva/ert
        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 )")
コード例 #5
0
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

           v = IntVector()
           v[0] = 1
コード例 #6
0
            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 )")
コード例 #7
0
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()
コード例 #8
0
ファイル: job_queue_manager.py プロジェクト: danielfmva/ert
    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(
コード例 #9
0
ファイル: geo_polygon.py プロジェクト: danielfmva/ert
#  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 )")
コード例 #10
0
    def hasKey(self, key):
        return key in self

    def getValue(self, key, item_index=-1, node_index=0):
        item = self[key]
        return item.getValue(item_index, node_index)

    def isValid(self):
        return ConfigContent.cNamespace().is_valid(self)

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


cwrapper = CWrapper(CONFIG_LIB)
cwrapper.registerObjectType("config_content", ConfigContent)
cwrapper.registerObjectType("content_item", ContentItem)
cwrapper.registerObjectType("content_node", ContentNode)

ConfigContent.cNamespace().free = cwrapper.prototype(
    "void config_content_free( config_content )")
ConfigContent.cNamespace().is_valid = cwrapper.prototype(
    "bool config_content_is_valid( config_content )")
ConfigContent.cNamespace().has_key = cwrapper.prototype(
    "bool config_content_has_item( config_content , char*)")
ConfigContent.cNamespace().get_item = cwrapper.prototype(
    "content_item_ref config_content_get_item( config_content , char*)")

ContentItem.cNamespace().size = cwrapper.prototype(
    "int config_content_item_get_size( content_item )")
コード例 #11
0
ファイル: basecenum.py プロジェクト: danielfmva/ert
 def registerEnum(cls, library, enum_name):
     cwrapper = CWrapper(library)
     cwrapper.registerType(enum_name, cls)
コード例 #12
0
            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 )")
コード例 #13
0
            self.setValue(self.value() + CTime(other).value())
            return self

    def __add__(self, other):
        copy = CTime(self)
        copy += other
        return copy

    def __radd__(self, other):
        return self + other

    def __mul__(self, other):
        copy = CTime(self)
        copy *= other
        return copy

    def __rmul__(self, other):
        return self * other

    def timetuple(self):
        # this function is a requirement for comparing against datetime objects where the CTime is on the right side
        pass

    @property
    def stripped(self):
        return time.strptime(self, "%Y-%m-%d %H:%M:S%")


cwrapper = CWrapper(None)
cwrapper.registerType("time_t", CTime)
コード例 #14
0
ファイル: analysis_module.py プロジェクト: imclab/ResInsight
        test = AnalysisModule.cNamespace().get_str(self, var)
        return str(test)

    def initUpdate(self, mask, S, R, dObs, E, D):
        print "Running initUpdate"
        AnalysisModule.cNamespace().init_update(self, mask, S, R, dObs, E, D)

    def updateA(self, A, S, R, dObs, E, D):
        print "Running updateA"
        AnalysisModule.cNamespace().updateA(self, A, S, R, dObs, E, D)

    def initX(self, X, A, S, R, dObs, E, D):
        AnalysisModule.cNamespace().init_update(self, X, A, S, R, dObs, E, D)


cwrapper = CWrapper(ANALYSIS_LIB)
cwrapper.registerObjectType("analysis_module", AnalysisModule)

AnalysisModule.cNamespace().alloc_external = cwrapper.prototype(
    "c_void_p analysis_module_alloc_external(rng, char*, char*)")
AnalysisModule.cNamespace().free = cwrapper.prototype(
    "void analysis_module_free(analysis_module)")
AnalysisModule.cNamespace().get_lib_name = cwrapper.prototype(
    "char* analysis_module_get_lib_name(analysis_module)")
AnalysisModule.cNamespace().get_module_internal = cwrapper.prototype(
    "bool analysis_module_internal(analysis_module)")
AnalysisModule.cNamespace().set_var = cwrapper.prototype(
    "bool analysis_module_set_var(analysis_module, char*, char*)")
AnalysisModule.cNamespace().get_table_name = cwrapper.prototype(
    "char* analysis_module_get_table_name(analysis_module)")
AnalysisModule.cNamespace().get_name = cwrapper.prototype(
コード例 #15
0
ファイル: test_indexed_read.py プロジェクト: danielfmva/ert
import ctypes
from ert.cwrap import clib, CWrapper
from ert.ecl import EclKW, EclFile, EclTypeEnum, FortIO
from ert.test import ExtendedTestCase, TestAreaContext
from ert.util import IntVector

ecl_lib = clib.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)