def test_filter_similar_single_result(self): """ Simdex.get_identical() for Array.mat should return only Array.mat""" SID_array = self.simdex.get_SID('array') self.simdex_array = self.simdex.filter_similar(SID_array[0]) self.assertEqual(['Array.mat'], self.simdex_array.get_filenames(), 'get_identical on array should only return Array.mat') # check if the self.simdex and sim objects have the same parameters sim_array = Simulation('Array.mat') sim_array.separate() sim_array_pars = sim_array.parameters sim_array_pars.sort() self.simdex_array_pars = self.simdex_array.parameters self.simdex_array_pars.sort() self.assertEqual(self.simdex_array_pars, sim_array_pars, 'the self.simdex and sim objects should have the same \ parameters') # check if the self.simdex and sim objects have the same variables sim_array_vars = sim_array.variables sim_array_vars.sort() self.simdex_array_vars = self.simdex_array.variables self.simdex_array_vars.sort() self.assertEqual(self.simdex_array_vars, sim_array_vars, 'the self.simdex and sim objects should have the same \ variables') self.simdex.h5.close()
def test_filter_similar_single_result(self): """ Simdex.get_identical() for Array.mat should return only Array.mat""" SID_array = self.simdex.get_SID('array') self.simdex_array = self.simdex.filter_similar(SID_array[0]) self.assertEqual(['Array.mat'], self.simdex_array.get_filenames(), 'get_identical on array should only return Array.mat') # check if the self.simdex and sim objects have the same parameters sim_array = Simulation('Array.mat') sim_array.separate() sim_array_pars = sim_array.parameters sim_array_pars.sort() self.simdex_array_pars = self.simdex_array.parameters self.simdex_array_pars.sort() self.assertEqual( self.simdex_array_pars, sim_array_pars, 'the self.simdex and sim objects should have the same \ parameters') # check if the self.simdex and sim objects have the same variables sim_array_vars = sim_array.variables sim_array_vars.sort() self.simdex_array_vars = self.simdex_array.variables self.simdex_array_vars.sort() self.assertEqual( self.simdex_array_vars, sim_array_vars, 'the self.simdex and sim objects should have the same \ variables') self.simdex.h5.close()
def test_filter_similar_multiple_results(self): """ Simdex.get_identical() for LinkedCapacities_C.mat should return all LinkedCapacities* except LinkedCapacities_F Attention: currently, the String parameter that is defined in the Modelica files is NOT present in the .mat files. If this would be changed (desirable) than the result of this test should also exclude LinkedCapacities.mat """ SID_lc = self.simdex.get_SID('_C') self.simdex_lc = self.simdex.filter_similar(SID_lc[0]) exp_results = ['LinkedCapacities.mat', \ 'LinkedCapacities_A.mat', 'LinkedCapacities_B.mat', \ 'LinkedCapacities_C.mat', 'LinkedCapacities_D.mat', \ 'LinkedCapacities_E.mat'] exp_results.sort() self.simdex_lc_fn = self.simdex_lc.get_filenames() self.simdex_lc_fn.sort() self.assertEqual( exp_results, self.simdex_lc_fn, 'get_identical on LinkedCapacities_C.mat should \ return the files mentioned in exp_results') # check if the self.simdex and sim objects have the same parameters sim_lc = Simulation('LinkedCapacities_A.mat') sim_lc.separate() sim_lc_pars = sim_lc.parameters sim_lc_pars.sort() self.simdex_lc_pars = self.simdex_lc.parameters self.simdex_lc_pars.sort() self.assertEqual( self.simdex_lc_pars, sim_lc_pars, 'the self.simdex and sim objects should have the same \ parameters') # check if the self.simdex and sim objects have the same variables sim_lc_vars = sim_lc.variables sim_lc_vars.sort() self.simdex_lc_vars = self.simdex_lc.variables self.simdex_lc_vars.sort() self.assertEqual( self.simdex_lc_vars, sim_lc_vars, 'the self.simdex and sim objects should have the same \ variables') self.simdex.h5.close()
def test_separate_attributes_present(self): """ Tests if the right attributes are created """ sim = Simulation('LinkedCapacities') sim.separate() self.assertTrue(isinstance(sim.parameters, list), 'Simulation.separate() should create attribute \ parameters as list') self.assertTrue(isinstance(sim.variables, list), 'Simulation.separate() should create attribute \ variables as list') self.assertTrue(isinstance(sim.parametervalues, np.ndarray), 'Simulation.separate() should create attribute \ parametervalues as numpy array')
def test_filter_similar_multiple_results(self): """ Simdex.get_identical() for LinkedCapacities_C.mat should return all LinkedCapacities* except LinkedCapacities_F Attention: currently, the String parameter that is defined in the Modelica files is NOT present in the .mat files. If this would be changed (desirable) than the result of this test should also exclude LinkedCapacities.mat """ SID_lc = self.simdex.get_SID('_C') self.simdex_lc = self.simdex.filter_similar(SID_lc[0]) exp_results = ['LinkedCapacities.mat', \ 'LinkedCapacities_A.mat', 'LinkedCapacities_B.mat', \ 'LinkedCapacities_C.mat', 'LinkedCapacities_D.mat', \ 'LinkedCapacities_E.mat'] exp_results.sort() self.simdex_lc_fn = self.simdex_lc.get_filenames() self.simdex_lc_fn.sort() self.assertEqual(exp_results, self.simdex_lc_fn, 'get_identical on LinkedCapacities_C.mat should \ return the files mentioned in exp_results') # check if the self.simdex and sim objects have the same parameters sim_lc = Simulation('LinkedCapacities_A.mat') sim_lc.separate() sim_lc_pars = sim_lc.parameters sim_lc_pars.sort() self.simdex_lc_pars = self.simdex_lc.parameters self.simdex_lc_pars.sort() self.assertEqual(self.simdex_lc_pars, sim_lc_pars, 'the self.simdex and sim objects should have the same \ parameters') # check if the self.simdex and sim objects have the same variables sim_lc_vars = sim_lc.variables sim_lc_vars.sort() self.simdex_lc_vars = self.simdex_lc.variables self.simdex_lc_vars.sort() self.assertEqual(self.simdex_lc_vars, sim_lc_vars, 'the self.simdex and sim objects should have the same \ variables') self.simdex.h5.close()
def test_separate_attributes_correct(self): """ Tests if the created attributes are correct """ sim = Simulation('LinkedCapacities') sim.separate() parameters = np.array([600.0, 1000.0, 3]) self.assertEqual([u'c1.C', u'c2.C', u'r.R'], sim.parameters) self.assertTrue((parameters == sim.parametervalues).all()) variables = sorted([ u'Time', u'c1.heatPort.T', u'c1.heatPort.Q_flow', u'c1.T', u'c1.der(T)', u'c2.heatPort.T', u'c2.heatPort.Q_flow', u'c2.T', u'c2.der(T)', u'r.heatPort_a.T', u'r.heatPort_a.Q_flow', u'r.heatPort_b.T', u'r.heatPort_b.Q_flow' ]) self.assertEqual(variables, sim.variables)
def test_separate_attributes_correct(self): """ Tests if the created attributes are correct """ sim = Simulation('LinkedCapacities') sim.separate() parameters = np.array([600.0, 1000.0, 3]) self.assertEqual([u'c1.C', u'c2.C', u'r.R'], sim.parameters) self.assertTrue((parameters == sim.parametervalues).all()) variables = sorted([u'Time', u'c1.heatPort.T', u'c1.heatPort.Q_flow', u'c1.T', u'c1.der(T)', u'c2.heatPort.T', u'c2.heatPort.Q_flow', u'c2.T', u'c2.der(T)', u'r.heatPort_a.T', u'r.heatPort_a.Q_flow', u'r.heatPort_b.T', u'r.heatPort_b.Q_flow']) self.assertEqual(variables, sim.variables)
def test_separate_twice(self): """ Tests if all goes fine if Simulation.separate() is called twice """ sim = Simulation('LinkedCapacities') sim.separate() sim.separate() parameters = np.array([600.0, 1000.0, 3]) self.assertEqual([u'c1.C', u'c2.C', u'r.R'], sim.parameters) self.assertTrue((parameters == sim.parametervalues).all()) variables = sorted([ u'Time', u'c1.heatPort.T', u'c1.heatPort.Q_flow', u'c1.T', u'c1.der(T)', u'c2.heatPort.T', u'c2.heatPort.Q_flow', u'c2.T', u'c2.der(T)', u'r.heatPort_a.T', u'r.heatPort_a.Q_flow', u'r.heatPort_b.T', u'r.heatPort_b.Q_flow' ]) self.assertEqual(variables, sim.variables)
def test_separate_twice(self): """ Tests if all goes fine if Simulation.separate() is called twice """ sim = Simulation('LinkedCapacities') sim.separate() sim.separate() parameters = np.array([600.0, 1000.0, 3]) self.assertEqual([u'c1.C', u'c2.C', u'r.R'], sim.parameters) self.assertTrue((parameters == sim.parametervalues).all()) variables = sorted([u'Time', u'c1.heatPort.T', u'c1.heatPort.Q_flow', u'c1.T', u'c1.der(T)', u'c2.heatPort.T', u'c2.heatPort.Q_flow', u'c2.T', u'c2.der(T)', u'r.heatPort_a.T', u'r.heatPort_a.Q_flow', u'r.heatPort_b.T', u'r.heatPort_b.Q_flow']) self.assertEqual(variables, sim.variables)
@author: RDC """ import numpy as np import os from simman import Simulation, Simdex, Process, load_simdex # first, test the package #runfile(r'C:\Workspace\Python\SimulationManagement\test_simman.py', # wdir=r'C:\Workspace\Python\SimulationManagement') # a Simulation is a python object for 1 simulation result file sim = Simulation('LinkedCapacities_A') #with our without .mat extension sim.separate() # optional, makes attributes for parameters and variables sim.parameters sim.variables # in big simulation files, it's not always easy to find the right parameter # or variable sim.exist('q_flow') time = sim.get_value('Time') Q = sim.get_value(u'r.heatPort_a.Q_flow') Q_sum = np.trapz(Q, time) print "The total energy that flowed through the resistance is %.1f J" % Q_sum for p, v in zip(sim.parameters, sim.parametervalues): print ''.join([p, ' = ', str(v)])
@author: RDC """ import numpy as np import os from simman import Simulation, Simdex, Process, load_simdex # first, test the package #runfile(r'C:\Workspace\Python\SimulationManagement\test_simman.py', # wdir=r'C:\Workspace\Python\SimulationManagement') # a Simulation is a python object for 1 simulation result file sim=Simulation('LinkedCapacities_A') #with our without .mat extension sim.separate() # optional, makes attributes for parameters and variables sim.parameters sim.variables # in big simulation files, it's not always easy to find the right parameter # or variable sim.exist('q_flow') time = sim.get_value('Time') Q = sim.get_value(u'r.heatPort_a.Q_flow') Q_sum = np.trapz(Q, time) print "The total energy that flowed through the resistance is %.1f J" %Q_sum for p,v in zip(sim.parameters, sim.parametervalues): print ''.join([p, ' = ', str(v)])