From 9c984d804712a9c55eb0c8d72dc91984fa5fbbff Mon Sep 17 00:00:00 2001 From: PeterMeisrimelModelon <92585725+PeterMeisrimelModelon@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:45:51 +0100 Subject: [PATCH] various renaming of private variables --- setup.cfg | 2 +- src/pyfmi/fmi.pxd | 16 +++++++------- src/pyfmi/fmi.pyx | 24 ++++++++++----------- src/pyfmi/simulation/assimulo_interface.pyx | 4 ++-- tests/test_fmi.py | 6 +++--- tests/test_util.py | 8 +++---- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/setup.cfg b/setup.cfg index 0460464e..bc2634d6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,4 +10,4 @@ install_requires = cython >= 3.0.7 nose-py3 >= 1.6.3 matplotlib > 3 - assimulo >= 3.5.0 \ No newline at end of file + assimulo >= 3.5.0 diff --git a/src/pyfmi/fmi.pxd b/src/pyfmi/fmi.pxd index 59403d86..be1988e9 100644 --- a/src/pyfmi/fmi.pxd +++ b/src/pyfmi/fmi.pxd @@ -158,11 +158,11 @@ cdef class FMUModelME1(FMUModelBase): cpdef _get_time(self) cpdef _set_time(self, FMIL.fmi1_real_t t) cpdef get_derivatives(self) - cdef int __get_nominal_continuous_states(self, FMIL.fmi1_real_t* xnominal, size_t nx) + cdef int _get_nominal_continuous_states_fmil(self, FMIL.fmi1_real_t* xnominal, size_t nx) cdef public object _preinit_nominal_continuous_states -cdef class __ForTestingFMUModelME1(FMUModelME1): - cdef int __get_nominal_continuous_states(self, FMIL.fmi1_real_t* xnominal, size_t nx) +cdef class _ForTestingFMUModelME1(FMUModelME1): + cdef int _get_nominal_continuous_states_fmil(self, FMIL.fmi1_real_t* xnominal, size_t nx) cpdef set_allocated_fmu(self, int value) cdef class FMUModelBase2(ModelBase): @@ -256,11 +256,11 @@ cdef class FMUModelME2(FMUModelBase2): cpdef get_derivatives(self) cdef public object force_finite_differences cdef int _get_derivatives(self, FMIL.fmi2_real_t[:] values) - cdef int __get_continuous_states(self, FMIL.fmi2_real_t[:] ndx) - cdef int __set_continuous_states(self, FMIL.fmi2_real_t[:] ndx) + cdef int _get_continuous_states_fmil(self, FMIL.fmi2_real_t[:] ndx) + cdef int _set_continuous_states_fmil(self, FMIL.fmi2_real_t[:] ndx) cdef int _get_event_indicators(self, FMIL.fmi2_real_t[:] values) cdef int _completed_integrator_step(self, int* enter_event_mode, int* terminate_simulation) - cdef int __get_nominal_continuous_states(self, FMIL.fmi2_real_t* xnominal, size_t nx) + cdef int _get_nominal_continuous_states_fmil(self, FMIL.fmi2_real_t* xnominal, size_t nx) cdef public object _preinit_nominal_continuous_states cdef class WorkerClass2: @@ -275,11 +275,11 @@ cdef class WorkerClass2: cdef N.ndarray get_real_numpy_vector(self, int index) cpdef verify_dimensions(self, int dim) -cdef class __ForTestingFMUModelME2(FMUModelME2): +cdef class _ForTestingFMUModelME2(FMUModelME2): cdef int _get_real_by_ptr(self, FMIL.fmi2_value_reference_t* vrefs, size_t size, FMIL.fmi2_real_t* values) cdef int _set_real(self, FMIL.fmi2_value_reference_t* vrefs, FMIL.fmi2_real_t* values, size_t size) cdef int _get_real_by_list(self, FMIL.fmi2_value_reference_t[:] valueref, size_t size, FMIL.fmi2_real_t[:] values) cdef int _get_integer(self, FMIL.fmi2_value_reference_t[:] valueref, size_t size, FMIL.fmi2_integer_t[:] values) cdef int _get_boolean(self, FMIL.fmi2_value_reference_t[:] valueref, size_t size, FMIL.fmi2_real_t[:] values) - cdef int __get_nominal_continuous_states(self, FMIL.fmi2_real_t* xnominal, size_t nx) + cdef int _get_nominal_continuous_states_fmil(self, FMIL.fmi2_real_t* xnominal, size_t nx) cpdef set_initialized_fmu(self, int value) diff --git a/src/pyfmi/fmi.pyx b/src/pyfmi/fmi.pyx index f2ac4163..fbe29415 100644 --- a/src/pyfmi/fmi.pyx +++ b/src/pyfmi/fmi.pyx @@ -3445,7 +3445,7 @@ cdef class FMUModelME1(FMUModelBase): """) - cdef int __get_nominal_continuous_states(self, FMIL.fmi1_real_t* xnominal, size_t nx): + cdef int _get_nominal_continuous_states_fmil(self, FMIL.fmi1_real_t* xnominal, size_t nx): return FMIL.fmi1_import_get_nominal_continuous_states(self._fmu, xnominal, nx) def _get_nominal_continuous_states(self): @@ -3458,7 +3458,7 @@ cdef class FMUModelME1(FMUModelBase): cdef int status cdef N.ndarray[FMIL.fmi1_real_t, ndim=1, mode='c'] xn = N.zeros(self._nContinuousStates, dtype=N.double) - status = self.__get_nominal_continuous_states( xn.data, self._nContinuousStates) + status = self._get_nominal_continuous_states_fmil( xn.data, self._nContinuousStates) if status != 0: raise FMUException('Failed to get the nominal values.') @@ -3955,9 +3955,9 @@ cdef class FMUModelME1(FMUModelBase): self._instantiated_fmu = 0 -cdef class __ForTestingFMUModelME1(FMUModelME1): +cdef class _ForTestingFMUModelME1(FMUModelME1): - cdef int __get_nominal_continuous_states(self, FMIL.fmi1_real_t* xnominal, size_t nx): + cdef int _get_nominal_continuous_states_fmil(self, FMIL.fmi1_real_t* xnominal, size_t nx): for i in range(nx): if self._allocated_fmu == 1: # If initialized # Set new values to test that atol gets auto-corrected. @@ -8014,7 +8014,7 @@ cdef class FMUModelME2(FMUModelBase2): return enterEventMode==FMI2_TRUE, terminateSimulation==FMI2_TRUE - cdef int __get_continuous_states(self, FMIL.fmi2_real_t[:] ndx): + cdef int _get_continuous_states_fmil(self, FMIL.fmi2_real_t[:] ndx): if self._nContinuousStates > 0: return FMIL.fmi2_import_get_continuous_states(self._fmu, &ndx[0] ,self._nContinuousStates) else: @@ -8030,14 +8030,14 @@ cdef class FMUModelME2(FMUModelBase2): """ cdef int status cdef N.ndarray[FMIL.fmi2_real_t, ndim=1, mode='c'] ndx = N.zeros(self._nContinuousStates, dtype=N.double) - status = self.__get_continuous_states(ndx) + status = self._get_continuous_states_fmil(ndx) if status != 0: raise FMUException('Failed to retrieve the continuous states.') return ndx - cdef int __set_continuous_states(self, FMIL.fmi2_real_t[:] ndx): + cdef int _set_continuous_states_fmil(self, FMIL.fmi2_real_t[:] ndx): if self._nContinuousStates > 0: return FMIL.fmi2_import_set_continuous_states(self._fmu, &ndx[0] , self._nContinuousStates) else: @@ -8061,7 +8061,7 @@ cdef class FMUModelME2(FMUModelBase2): 'The number of values are not consistent with the number of '\ 'continuous states.') - status = self.__set_continuous_states(ndx) + status = self._set_continuous_states_fmil(ndx) if status >= 3: raise FMUException('Failed to set the new continuous states.') @@ -8073,7 +8073,7 @@ cdef class FMUModelME2(FMUModelBase2): the low-level FMI function: fmi2SetContinuousStates/fmi2GetContinuousStates. """) - cdef int __get_nominal_continuous_states(self, FMIL.fmi2_real_t* xnominal, size_t nx): + cdef int _get_nominal_continuous_states_fmil(self, FMIL.fmi2_real_t* xnominal, size_t nx): return FMIL.fmi2_import_get_nominals_of_continuous_states(self._fmu, xnominal, nx) def _get_nominal_continuous_states(self): @@ -8086,7 +8086,7 @@ cdef class FMUModelME2(FMUModelBase2): cdef int status cdef N.ndarray[FMIL.fmi2_real_t, ndim=1, mode='c'] xn = N.zeros(self._nContinuousStates, dtype=N.double) - status = self.__get_nominal_continuous_states( xn.data, self._nContinuousStates) + status = self._get_nominal_continuous_states_fmil( xn.data, self._nContinuousStates) if status != 0: raise FMUException('Failed to get the nominal values.') @@ -8517,7 +8517,7 @@ cdef class FMUModelME2(FMUModelBase2): return A -cdef class __ForTestingFMUModelME2(FMUModelME2): +cdef class _ForTestingFMUModelME2(FMUModelME2): cdef int _get_real_by_ptr(self, FMIL.fmi2_value_reference_t* vrefs, size_t size, FMIL.fmi2_real_t* values): vr = N.zeros(size) for i in range(size): @@ -8574,7 +8574,7 @@ cdef class __ForTestingFMUModelME2(FMUModelME2): return FMIL.fmi2_status_error return FMIL.fmi2_status_ok - cdef int __get_nominal_continuous_states(self, FMIL.fmi2_real_t* xnominal, size_t nx): + cdef int _get_nominal_continuous_states_fmil(self, FMIL.fmi2_real_t* xnominal, size_t nx): for i in range(nx): if self._initialized_fmu == 1: # Set new values to test that atol gets auto-corrected. diff --git a/src/pyfmi/simulation/assimulo_interface.pyx b/src/pyfmi/simulation/assimulo_interface.pyx index 4928610a..62d82610 100644 --- a/src/pyfmi/simulation/assimulo_interface.pyx +++ b/src/pyfmi/simulation/assimulo_interface.pyx @@ -729,7 +729,7 @@ cdef class FMIODE2(cExplicit_Problem): self.model_me2._set_time(t) #Check if there are any states if self._f_nbr != 0: - self.model_me2.__set_continuous_states(y) + self.model_me2._set_continuous_states_fmil(y) else: #Moving data to the model self._model.time = t @@ -750,7 +750,7 @@ cdef class FMIODE2(cExplicit_Problem): if self._f_nbr == 0: return 0 - self.model_me2.__get_continuous_states(self._state_temp_1) + self.model_me2._get_continuous_states_fmil(self._state_temp_1) res = FMIL.memcmp(self._state_temp_1.data, y.data, self._f_nbr*sizeof(double)) if res == 0: diff --git a/tests/test_fmi.py b/tests/test_fmi.py index bdc9e4bf..dc8053de 100644 --- a/tests/test_fmi.py +++ b/tests/test_fmi.py @@ -25,7 +25,7 @@ from io import StringIO from pyfmi import testattr -from pyfmi.fmi import FMUException, InvalidOptionException, InvalidXMLException, InvalidBinaryException, InvalidVersionException, FMUModelME1, FMUModelCS1, load_fmu, FMUModelCS2, FMUModelME2, PyEventInfo +from pyfmi.fmi import FMUException, InvalidOptionException, InvalidXMLException, InvalidBinaryException, InvalidVersionException, FMUModelME1, FMUModelCS1, load_fmu, FMUModelCS2, FMUModelME2 import pyfmi.fmi as fmi from pyfmi.fmi_algorithm_drivers import AssimuloFMIAlg, AssimuloFMIAlgOptions, \ PYFMI_JACOBIAN_LIMIT, PYFMI_JACOBIAN_SPARSE_SIZE_LIMIT @@ -538,7 +538,7 @@ def test_get_erroneous_nominals_capi_fmi1(self): logging.basicConfig(stream=log_stream, level=logging.WARNING) model.states_vref = [114, 115, 116, 117, 118, 119, 120, 121] - # NOTE: Property 'nominal_continuous_states' is already overriden in Dummy_FMUModelME1, so just + # NOTE: Property 'nominal_continuous_states' is already overridden in Dummy_FMUModelME1, so just # call the underlying function immediately. xn = model._get_nominal_continuous_states() @@ -1421,7 +1421,7 @@ def test_get_erroneous_nominals_capi(self): log_stream = StringIO() logging.basicConfig(stream=log_stream, level=logging.WARNING) - # NOTE: Property 'nominal_continuous_states' is already overriden in Dummy_FMUModelME2, so just + # NOTE: Property 'nominal_continuous_states' is already overridden in Dummy_FMUModelME2, so just # call the underlying function immediately. xn = model._get_nominal_continuous_states() diff --git a/tests/test_util.py b/tests/test_util.py index 99500ea9..70dfdc1b 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -19,13 +19,13 @@ import os import numpy as np -from pyfmi.fmi import FMUException, FMUModelME1, __ForTestingFMUModelME1, FMUModelCS1, load_fmu, \ - FMUModelCS2, FMUModelME2, __ForTestingFMUModelME2 +from pyfmi.fmi import FMUException, FMUModelME1, _ForTestingFMUModelME1, FMUModelCS1, load_fmu, \ + FMUModelCS2, FMUModelME2, _ForTestingFMUModelME2 def get_examples_folder(): return os.path.join(os.path.dirname(__file__), '..', 'examples') -class Dummy_FMUModelME1(__ForTestingFMUModelME1): +class Dummy_FMUModelME1(_ForTestingFMUModelME1): # If true, makes use of the real __ForTesting implementation for nominal_continuous_states, # else just returns 1.0 for each. override_nominal_continuous_states = True @@ -208,7 +208,7 @@ def set_integer(self, vref, values): for i,v in enumerate(vref): self.values[v] = values[i] -class Dummy_FMUModelME2(__ForTestingFMUModelME2): +class Dummy_FMUModelME2(_ForTestingFMUModelME2): # -- Test options --