In [1]:
import sys
sys.path.append('C:\Users\u0098668\Documents\Modelica\ModelicaRes')

from modelicares.exps.simulators import dymosim, fmi
from modelicares import SimRes, SimResList, SimResSequence
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
fmu = fmi(results_dir='results-fmu')
dymo = dymosim(results_dir='results-dymo')

In [15]:
dymo.run('dymosim', StartTime=0, StopTime=604800)

In [3]:
dymo.run('dymosim', StartTime=0, StopTime=10000)
fmu.run('CSCVode.fmu', StartTime=0, StopTime=10000)


Simulation interval    : 0 - 10000 seconds.
Elapsed simulation time: 340.363608948 seconds.

In [4]:
results = SimResList('results-dymo/%s/dsres1.mat' % dymo.n_runs, 'results-fmu/%s/dsres1.txt' % fmu.n_runs)

In [9]:
results.plot(['buildingLeft.heatingSystem.TSensor[2]', 'buildingLeft.heatingSystem.TSensor[3]'])


Out[9]:
(<matplotlib.axes.AxesSubplot at 0xfc035d0>, None)

In [17]:
result = SimRes('results-dymo/%s/dsres1.mat' % dymo.n_runs)

In [18]:
result.plot('buildingLeft.heatingSystem.TSensor[2]')


Out[18]:
(<matplotlib.axes.AxesSubplot at 0x9482f30>, None)

In [19]:
dymo.run('dymosim', StartTime=0, StopTime=900)
for i in range(0, 671):
    dymo.continue_run(900)

In [21]:
result = SimResSequence('results-dymo/%s/dsres*.mat' % dymo.n_runs)


---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
<ipython-input-21-6413edffedaf> in <module>()
----> 1 result = SimResSequence('results-dymo/%s/dsres*.mat' % dymo.n_runs)

C:\Users\u0098668\Documents\Modelica\ModelicaRes\modelicares\simres.pyc in __init__(self, *args)
   2204         """
   2205 
-> 2206         simlist = SimResList(*args)
   2207         simlist.sort()
   2208 

C:\Users\u0098668\Documents\Modelica\ModelicaRes\modelicares\simres.pyc in __init__(self, *args)
   1754                     "providing a list of SimRes instances or a series of "
   1755                     "arguments, each of which is a filename or directory.")
-> 1756             list.__init__(self, _get_sims(fnames))
   1757 
   1758         elif len(args) == 1:  # List or iterable of SimRes instances

C:\Users\u0098668\Documents\Modelica\ModelicaRes\modelicares\simres.pyc in _get_sims(fnames)
    469     for fname in fnames:
    470         try:
--> 471             sims.append(SimRes(fname))
    472         except (AssertionError, IndexError, IOError, KeyError, TypeError,
    473                 ValueError):

C:\Users\u0098668\Documents\Modelica\ModelicaRes\modelicares\simres.pyc in __init__(self, fname, constants_only, tool, sequence)
    669                                                '", "'.join(list(loaderdict))))
    670         if not sequence:
--> 671             self._variables = load(fname, constants_only)
    672         else:
    673             self._variables = sequence

C:\Users\u0098668\Documents\Modelica\ModelicaRes\modelicares\_io\dymola.pyc in readsim(fname, constants_only)
    317 
    318     # Load the file.
--> 319     data, Aclass = read(fname, constants_only)
    320 
    321     # Check the type of results.

C:\Users\u0098668\Documents\Modelica\ModelicaRes\modelicares\_io\dymola.pyc in read(fname, constants_only)
    225     try:
    226         data = loadmat(fname, variable_names=variable_names,
--> 227                        chars_as_strings=False, appendmat=False)
    228         binary = True
    229     except ValueError:

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\scipy\io\matlab\mio.pyc in loadmat(file_name, mdict, appendmat, **kwargs)
    173     variable_names = kwargs.pop('variable_names', None)
    174     MR = mat_reader_factory(file_name, appendmat, **kwargs)
--> 175     matfile_dict = MR.get_variables(variable_names)
    176     if mdict is not None:
    177         mdict.update(matfile_dict)

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\scipy\io\matlab\mio4.pyc in get_variables(self, variable_names)
    305                 self.mat_stream.seek(next_position)
    306                 continue
--> 307             mdict[name] = self.read_var_array(hdr)
    308             self.mat_stream.seek(next_position)
    309             if variable_names:

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\scipy\io\matlab\mio4.pyc in read_var_array(self, header, process)
    284            `process`.
    285         '''
--> 286         return self._matrix_reader.array_from_header(header, process)
    287 
    288     def get_variables(self, variable_names=None):

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\scipy\io\matlab\mio4.pyc in array_from_header(self, hdr, process)
    122             arr = self.read_full_array(hdr)
    123         elif mclass == mxCHAR_CLASS:
--> 124             arr = self.read_char_array(hdr)
    125             if process and self.chars_as_strings:
    126                 arr = chars_to_strings(arr)

c:\Users\u0098668\AppData\Local\Continuum\Anaconda\lib\site-packages\scipy\io\matlab\mio4.pyc in read_char_array(self, hdr)
    176         return np.ndarray(shape=hdr.dims,
    177                           dtype=np.dtype('U1'),
--> 178                           buffer = np.array(S)).copy()
    179 
    180     def read_sparse_array(self, hdr):

MemoryError: 

In [13]:
fmu_memory = fmi(results_dir='results-fmu', result_handling='memory', log_level=7)
fmu_memory.run('CSDymola.fmu', StartTime=0, StopTime=900)


---------------------------------------------------------------------------
FMUException                              Traceback (most recent call last)
<ipython-input-13-e266ef2e3162> in <module>()
      1 fmu_memory = fmi(results_dir='results-fmu', result_handling='memory', log_level=7)
----> 2 fmu_memory.run('CSDymola.fmu', StartTime=0, StopTime=900)

C:\Users\u0098668\Documents\Modelica\ModelicaRes\modelicares\exps\simulators.pyc in run(self, model, params, **options)
    950 
    951         # Load the fmu, write the parameters and options, run the model, and save the results.
--> 952         self.load(os.path.join(model_dir, fmu_path), results_dir)
    953         self._run(params, options, model_dir, results_dir)
    954 

C:\Users\u0098668\Documents\Modelica\ModelicaRes\modelicares\exps\simulators.pyc in load(self, fmu_path, results_dir)
    843         # Initialize the fmu
    844         self.fmu.setup_experiment()
--> 845         self.fmu.initialize()
    846 
    847         # Copy the log file to the result directory

C:\JModelica.org-1.14\install\Python\pyfmi\fmi.pyd in pyfmi.fmi.FMUModelBase2.initialize (src\pyfmi\fmi.c:30504)()

FMUException: Enter Initialize returned with a error. Enable logging for more information, (FMUModel(..., enable_logging=True)).

In [14]:
model = fmu_memory.fmu

In [28]:
model.get_version()


Out[28]:
'2.0'

In [ ]: