コード例 #1
0
    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()
コード例 #2
0
 def test_get_objects(self):
     """Test if get_objects works with empty mother model"""
     
     sim = Simulation('LinkedCapacities') 
     obj = sim.get_objects()
     obj_sorted = sorted(obj)
     self.assertEqual(obj_sorted, sorted([u'c1', u'c2','r']))
コード例 #3
0
    def test_postprocess_nopp(self):
        """Try a basic extraction via a post processing on a simulation"""

        sim = Simulation('LinkedCapacities')
        process = Process(mothers=['c1', 'c2'], sub_vars={'T': 'T'})
        result_pp = sim.postprocess(process)
        self.assertTrue(result_pp.has_key('c1_T'))
コード例 #4
0
    def test_get_objects(self):
        """Test if get_objects works with empty mother model"""

        sim = Simulation('LinkedCapacities')
        obj = sim.get_objects()
        obj_sorted = sorted(obj)
        self.assertEqual(obj_sorted, sorted([u'c1', u'c2', 'r']))
コード例 #5
0
    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()
コード例 #6
0
    def test_postprocess_integration(self):
        """Postprocessing with integration on standard variables and mothers"""

        J2kWh = 1e-6 / 3.6
        vars_to_integrate = {'Q': J2kWh, 'Time': 1}

        sim = Simulation('LinkedCapacities')
        process = Process(mothers=['c1', 'c2'],
                          sub_vars={
                              'T': 'T',
                              'Q': 'heatPort.Q_flow'
                          },
                          sub_pars={'cap': 'C'},
                          pp=[
                              'T_degC = T + 273.15',
                              'T_max =  np.amax( T_degC )',
                              'Thigh = np.nonzero( T_degC > 640)[0]',
                              'Qsel = Q [ Thigh ]'
                          ],
                          integrate=vars_to_integrate)
        result_pp = sim.postprocess(process)
        self.assertAlmostEqual(result_pp['c1_T_max'], 673.15, 2)
        self.assertEqual(len(result_pp['c1_Qsel']), len(result_pp['c1_Thigh']))
        self.assertAlmostEqual(result_pp['c1_Q_Int'], -result_pp['c2_Q_Int'],
                               10)
        self.assertIsNotNone(result_pp['Time_Int'])
コード例 #7
0
 def test_get_objects_with_mother(self):
     """Test if get_objects works with empty mother model"""
     
     sim = Simulation('LinkedCapacities') 
     obj = sim.get_objects(mother = 'c1')
     obj_sorted = sorted(obj)
     self.assertEqual(obj_sorted, sorted(['heatPort', 'C', u'T', u'der(T)']))                
コード例 #8
0
 def test_get_objects_with_mother(self):
     """Test if get_objects works with empty mother model"""
     
     sim = Simulation('LinkedCapacities') 
     obj = sim.get_objects(mother = 'c1')
     obj_sorted = sorted(obj)
     self.assertEqual(obj_sorted, sorted(['heatPort', 'C', u'T', u'der(T)']))                
コード例 #9
0
 def test_postprocess_aggregation(self):
     """Postprocessing with aggregation"""
     
     vars_to_aggregate = {'Q': ['sum', 'mean', 'each'], 'T': 'mean'}
     J2kWh = 1e-6/3.6
     vars_to_integrate = {'Q':J2kWh, 'Time':1}
     
     sim = Simulation('LinkedCapacities')
     process = Process(mothers=['c1', 'c2'], sub_vars={'T':'T', 'Q':'heatPort.Q_flow'},
                       sub_pars={'cap':'C'},
                       pp = ['T_degC = T + 273.15', 
                             'T_max =  np.amax( T_degC )',
                             'Thigh = np.nonzero( T_degC > 640)[0]',
                             'Qsel = Q [ Thigh ]'],
                       integrate = vars_to_integrate,
                       aggregate = vars_to_aggregate)
     result_pp = sim.postprocess(process)
     self.assertAlmostEqual(result_pp['c1_T_max'], 673.15, 2)
     self.assertEqual(len(result_pp['c1_Qsel']), len(result_pp['c1_Thigh']))
     self.assertAlmostEqual(result_pp['c1_Q_Int'], -result_pp['c2_Q_Int'], 10)
     self.assertIsNotNone(result_pp['Time_Int'])
     self.assertAlmostEqual(result_pp['Q_Total'][3],
                            result_pp['c1_Q'][3] + result_pp['c2_Q'][3])
     self.assertAlmostEqual(result_pp['Q_Mean'][3],
                            (result_pp['c1_Q'][3] + result_pp['c2_Q'][3])/2.)
     self.assertEqual(np.sum(result_pp['Q_Each'], axis=0)[3], result_pp['Q_Total'][3])
     self.assertAlmostEqual(result_pp['T_Mean'][16],
                            (result_pp['c1_T'][16] + result_pp['c2_T'][16])/2.)
コード例 #10
0
 def test_postprocess_nopp(self):
     """Try a basic extraction via a post processing on a simulation"""
     
     sim = Simulation('LinkedCapacities')
     process = Process(mothers=['c1', 'c2'], sub_vars={'T':'T'})
     result_pp = sim.postprocess(process)
     self.assertTrue(result_pp.has_key('c1_T'))
コード例 #11
0
 def test_postprocess_nomothers(self):
     """Try a basic postprocessing without mothers on a simulation"""
     
     sim = Simulation('LinkedCapacities')
     process = Process(mothers=['c1', 'c2'], sub_vars={'T':'T'},
                       pp = ['timehours = Time / 3600'])
     result_pp = sim.postprocess(process)
     self.assertTrue(np.all(result_pp['timehours']==result_pp['Time']/3600))
コード例 #12
0
 def test_postprocess_nomothers(self):
     """Try a basic postprocessing without mothers on a simulation"""
     
     sim = Simulation('LinkedCapacities')
     process = Process(mothers=['c1', 'c2'], sub_vars={'T':'T'},
                       pp = ['timehours = Time / 3600'])
     result_pp = sim.postprocess(process)
     self.assertTrue(np.all(result_pp['timehours']==result_pp['Time']/3600))
コード例 #13
0
 def test_postprocess_recurring(self):
     """Some advanced postprocessing using previous results with mothers"""
     
     sim = Simulation('LinkedCapacities')
     process = Process(mothers=['c1', 'c2'], sub_vars={'T':'T'},
                       sub_pars={'cap':'C'},
                       pp = ['T_degC = T + 273.15', 'T_degC2 =  T_degC '])
     result_pp = sim.postprocess(process)
     self.assertTrue(np.all(result_pp['c1_T_degC2']==result_pp['c1_T_degC']))
コード例 #14
0
 def test_postprocess_recurring(self):
     """Some advanced postprocessing using previous results with mothers"""
     
     sim = Simulation('LinkedCapacities')
     process = Process(mothers=['c1', 'c2'], sub_vars={'T':'T'},
                       sub_pars={'cap':'C'},
                       pp = ['T_degC = T + 273.15', 'T_degC2 =  T_degC '])
     result_pp = sim.postprocess(process)
     self.assertTrue(np.all(result_pp['c1_T_degC2']==result_pp['c1_T_degC']))
コード例 #15
0
 def test_postprocess_mothers(self):
     """Try a basic postprocessing with mothers on a simulation"""
     
     sim = Simulation('LinkedCapacities')
     process = Process(mothers=['c1', 'c2'], sub_vars={'T':'T'},
                       sub_pars={'cap':'C'},
                       pp = ['T_degC = T + 273.15'])
     result_pp = sim.postprocess(process)
     self.assertTrue(np.all(result_pp['c1_T_degC'] == result_pp['c1_T']+273.15))
     self.assertEqual(result_pp['c1_cap'], 600.0)
コード例 #16
0
 def test_postprocess_mothers(self):
     """Try a basic postprocessing with mothers on a simulation"""
     
     sim = Simulation('LinkedCapacities')
     process = Process(mothers=['c1', 'c2'], sub_vars={'T':'T'},
                       sub_pars={'cap':'C'},
                       pp = ['T_degC = T + 273.15'])
     result_pp = sim.postprocess(process)
     self.assertTrue(np.all(result_pp['c1_T_degC'] == result_pp['c1_T']+273.15))
     self.assertEqual(result_pp['c1_cap'], 600.0)
コード例 #17
0
 def test_postprocess_advanced(self):
     """Some more advanced postprocessing with mothers"""
     
     sim = Simulation('LinkedCapacities')
     process = Process(mothers=['c1', 'c2'], sub_vars={'T':'T', 'Q':'heatPort.Q_flow'},
                       sub_pars={'cap':'C'},
                       pp = ['T_degC = T + 273.15', 
                             'T_max =  np.amax( T_degC )',
                             'Thigh = np.nonzero( T_degC > 640)[0]',
                             'Qsel = Q [ Thigh ]'])
     result_pp = sim.postprocess(process)
     self.assertAlmostEqual(result_pp['c1_T_max'], 673.15, 2)
     self.assertEqual(len(result_pp['c1_Qsel']), len(result_pp['c1_Thigh']))
コード例 #18
0
 def test_postprocess_advanced(self):
     """Some more advanced postprocessing with mothers"""
     
     sim = Simulation('LinkedCapacities')
     process = Process(mothers=['c1', 'c2'], sub_vars={'T':'T', 'Q':'heatPort.Q_flow'},
                       sub_pars={'cap':'C'},
                       pp = ['T_degC = T + 273.15', 
                             'T_max =  np.amax( T_degC )',
                             'Thigh = np.nonzero( T_degC > 640)[0]',
                             'Qsel = Q [ Thigh ]'])
     result_pp = sim.postprocess(process)
     self.assertAlmostEqual(result_pp['c1_T_max'], 673.15, 2)
     self.assertEqual(len(result_pp['c1_Qsel']), len(result_pp['c1_Thigh']))
コード例 #19
0
    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()
コード例 #20
0
    def test_get_value_time1(self):
        """ 
        Tests get_value on the variable 'Time'
        The testes file is the result of a simulation over 10000s with fixed 
        interval of 200s 
        """

        sim = Simulation('LinkedCapacities')
        time = np.array(np.arange(0., 10200., 200.))
        sim_time = sim.get_value('Time')

        self.assertTrue((time == sim_time).all(),
                        'Time should contain exactly 51 values, \
                        from 0 to 10000 (incl.) in steps of 200')
コード例 #21
0
 def test_get_value_time2(self):
     """ 
     Tests get_value on the variable 'Time'
     The testes file is the result of a simulation over 10000s with fixed 
     amount of intervals (50) 
     """
     
     sim = Simulation('Array')
     time = np.array(np.arange(0., 10200., 200.))
     Time = sim.get_value('Time')
     
     self.assertTrue((time == Time).all(), 
                     'Time should contain exactly 51 values, \
                     from 0 to 10000 (incl.) in steps of 200')
コード例 #22
0
 def test_get_value_time1(self):
     """ 
     Tests get_value on the variable 'Time'
     The testes file is the result of a simulation over 10000s with fixed 
     interval of 200s 
     """
     
     sim = Simulation('LinkedCapacities')
     time = np.array(np.arange(0., 10200., 200.))
     sim_time = sim.get_value('Time')
     
     self.assertTrue((time == sim_time).all(), 
                     'Time should contain exactly 51 values, \
                     from 0 to 10000 (incl.) in steps of 200')
コード例 #23
0
    def test_get_value_time2(self):
        """ 
        Tests get_value on the variable 'Time'
        The testes file is the result of a simulation over 10000s with fixed 
        amount of intervals (50) 
        """

        sim = Simulation('Array')
        time = np.array(np.arange(0., 10200., 200.))
        Time = sim.get_value('Time')

        self.assertTrue((time == Time).all(),
                        'Time should contain exactly 51 values, \
                        from 0 to 10000 (incl.) in steps of 200')
コード例 #24
0
 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')                        
コード例 #25
0
 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')                        
コード例 #26
0
    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()
コード例 #27
0
 def test_exist_array(self):
     """
     For a simulation file which uses arrays, Test if :
     1) running Simulation.exist() gives a match when it should
        (different cases are tested)
     2) running Simulation.exist() gives a zero list for non-pressent regex
     
     """
     
     sim = Simulation('Array')
     self.assertEqual(sim.names[1], sim.exist(sim.names[1])[0], 
                      'Simulation.exist() does NOT return a present name')
     self.assertEqual(4, len(sim.exist('heatport.q_flow')), 
                      "sim.exist('heatport.q_flow') should give 4 matches")
     self.assertEqual(12, len(sim.exist('[1]')), 
                      "sim.exist('[1]') should give 12 matches")
コード例 #28
0
 def test_exist_array(self):
     """
     For a simulation file which uses arrays, Test if :
     1) running Simulation.exist() gives a match when it should
        (different cases are tested)
     2) running Simulation.exist() gives a zero list for non-pressent regex
     
     """
     
     sim = Simulation('Array')
     self.assertEqual(sim.names[1], sim.exist(sim.names[1])[0], 
                      'Simulation.exist() does NOT return a present name')
     self.assertEqual(4, len(sim.exist('heatport.q_flow')), 
                      "sim.exist('heatport.q_flow') should give 4 matches")
     self.assertEqual(12, len(sim.exist('[1]')), 
                      "sim.exist('[1]') should give 12 matches")
コード例 #29
0
    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)
コード例 #30
0
 def test_exist(self):
     """
     Test if :
     1) running Simulation.exist() gives a match when it should
        (different cases are tested)
     2) running Simulation.exist() gives a zero list for non-present regex
     
     """
     
     sim = Simulation('LinkedCapacities')
     self.assertEqual(sim.names[1], sim.exist(sim.names[1])[0], 
                      'Simulation.exist() does NOT return a present name')
     self.assertEqual(5, len(sim.exist('c1')), "sim.exist('c1') should give \
                      5 matches")
     self.assertEqual(u'Time', sim.exist('time')[0], 
                      'Simulation.exist() should ignore case' )
     self.assertEqual([], sim.exist('something that does not exist'))
コード例 #31
0
    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) 
コード例 #32
0
 def test_postprocess_integration(self):
     """Postprocessing with integration on standard variables and mothers"""
     
     J2kWh = 1e-6/3.6
     vars_to_integrate = {'Q':J2kWh, 'Time':1}
     
     sim = Simulation('LinkedCapacities')
     process = Process(mothers=['c1', 'c2'], sub_vars={'T':'T', 'Q':'heatPort.Q_flow'},
                       sub_pars={'cap':'C'},
                       pp = ['T_degC = T + 273.15', 
                             'T_max =  np.amax( T_degC )',
                             'Thigh = np.nonzero( T_degC > 640)[0]',
                             'Qsel = Q [ Thigh ]'],
                       integrate = vars_to_integrate)
     result_pp = sim.postprocess(process)
     self.assertAlmostEqual(result_pp['c1_T_max'], 673.15, 2)
     self.assertEqual(len(result_pp['c1_Qsel']), len(result_pp['c1_Thigh']))
     self.assertAlmostEqual(result_pp['c1_Q_Int'], -result_pp['c2_Q_Int'], 10)
     self.assertIsNotNone(result_pp['Time_Int'])     
コード例 #33
0
    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)
コード例 #34
0
    def test_get_shortnames(self):
        """Simdex.get() should return correctly for shortnames too"""

        self.simdex.h5.close()
        vardic = {'T2': 'c2.T'}
        pardic = {'parc': 'c1.C'}
        process = Process(parameters=pardic, variables=vardic)
        self.simdex = Simdex(folder=getcwd(), process=process)
        result = self.simdex.get('T2')
        expectedsids = self.simdex.get_SID('linkedcapacities')
        self.assertEqual(sorted(result.keys()), sorted(expectedsids))
        sim = Simulation('LinkedCapacities_B.mat')
        sid = self.simdex.get_SID('LinkedCapacities_B')[0]
        self.assertTrue(np.all(result[sid] == sim.get_value('c2.T')))

        c1_C = self.simdex.get('parc').values()
        c1_C.sort()
        exp_result_sorted = [None, 600., 600., 800., 800., 800., 800., 1000.]
        self.assertTrue(exp_result_sorted == c1_C)
        self.simdex.h5.close()
コード例 #35
0
    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)
コード例 #36
0
    def test___init__attributes(self):
        """
        Tests creation of Simulation object from well known file.
        Checks if attributes are present 
        Make sure the file LinkedCapacities.mat is in the current work directory

        """
        sim = Simulation('LinkedCapacities')
        for attr in ['dataInfo', 'data_1', 'data_2', 'filename', 'names']:
            self.assertTrue(sim.__dict__.has_key(attr), 
                            'Simulation.__init__() dit not create \
                            attribute %s' % attr)
コード例 #37
0
 def test_get_shortnames(self):
     """Simdex.get() should return correctly for shortnames too"""
     
     self.simdex.h5.close()
     vardic = {'T2': 'c2.T'}
     pardic = {'parc': 'c1.C'}
     process=Process(parameters=pardic, variables=vardic)
     self.simdex = Simdex(folder=getcwd(), process=process)        
     result = self.simdex.get('T2')
     expectedsids = self.simdex.get_SID('linkedcapacities')
     self.assertEqual(sorted(result.keys()), sorted(expectedsids))
     sim = Simulation('LinkedCapacities_B.mat')
     sid = self.simdex.get_SID('LinkedCapacities_B')[0]
     self.assertTrue(np.all(result[sid]==sim.get_value('c2.T')))
     
     c1_C = self.simdex.get('parc').values()
     c1_C.sort()
     exp_result_sorted = [None,   600.,   600.,   800.,  
                                   800.,   800.,   800., 1000.]
     self.assertTrue(exp_result_sorted == c1_C)
     self.simdex.h5.close()        
コード例 #38
0
    def test_postprocess_aggregation(self):
        """Postprocessing with aggregation"""

        vars_to_aggregate = {'Q': ['sum', 'mean', 'each'], 'T': 'mean'}
        J2kWh = 1e-6 / 3.6
        vars_to_integrate = {'Q': J2kWh, 'Time': 1}

        sim = Simulation('LinkedCapacities')
        process = Process(mothers=['c1', 'c2'],
                          sub_vars={
                              'T': 'T',
                              'Q': 'heatPort.Q_flow'
                          },
                          sub_pars={'cap': 'C'},
                          pp=[
                              'T_degC = T + 273.15',
                              'T_max =  np.amax( T_degC )',
                              'Thigh = np.nonzero( T_degC > 640)[0]',
                              'Qsel = Q [ Thigh ]'
                          ],
                          integrate=vars_to_integrate,
                          aggregate=vars_to_aggregate)
        result_pp = sim.postprocess(process)
        self.assertAlmostEqual(result_pp['c1_T_max'], 673.15, 2)
        self.assertEqual(len(result_pp['c1_Qsel']), len(result_pp['c1_Thigh']))
        self.assertAlmostEqual(result_pp['c1_Q_Int'], -result_pp['c2_Q_Int'],
                               10)
        self.assertIsNotNone(result_pp['Time_Int'])
        self.assertAlmostEqual(result_pp['Q_Total'][3],
                               result_pp['c1_Q'][3] + result_pp['c2_Q'][3])
        self.assertAlmostEqual(result_pp['Q_Mean'][3],
                               (result_pp['c1_Q'][3] + result_pp['c2_Q'][3]) /
                               2.)
        self.assertEqual(
            np.sum(result_pp['Q_Each'], axis=0)[3], result_pp['Q_Total'][3])
        self.assertAlmostEqual(
            result_pp['T_Mean'][16],
            (result_pp['c1_T'][16] + result_pp['c2_T'][16]) / 2.)
コード例 #39
0
    def test___init__subfolder_with_spaces(self):
        """
        Tests creation of Simulation object from well known file with full
        pathname including spaces.
        Checks if attributes are present 
        Make sure the file LinkedCapacities.mat is in the folder 
        'Subfolder with spaces' of the current work directory

        """
        cwd = getcwd()
        filename = path.join(cwd, 'A Subfolder with Spaces', 'LinkedCapacities')
        sim = Simulation(filename)
        for attr in ['dataInfo', 'data_1', 'data_2', 'filename', 'names']:
            self.assertTrue(sim.__dict__.has_key(attr), 
                            'Simulation.__init__() dit not create \
                            attribute %s' % attr)
コード例 #40
0
 def test_exist(self):
     """
     Test if :
     1) running Simulation.exist() gives a match when it should
        (different cases are tested)
     2) running Simulation.exist() gives a zero list for non-present regex
     
     """
     
     sim = Simulation('LinkedCapacities')
     self.assertEqual(sim.names[1], sim.exist(sim.names[1])[0], 
                      'Simulation.exist() does NOT return a present name')
     self.assertEqual(5, len(sim.exist('c1')), "sim.exist('c1') should give \
                      5 matches")
     self.assertEqual(u'Time', sim.exist('time')[0], 
                      'Simulation.exist() should ignore case' )
     self.assertEqual([], sim.exist('something that does not exist'))
コード例 #41
0
                                        '.mat').replace('dslog', 'result')
        results.append(summary)
    # suc6 = [l['successful'] for l in logs]    checked, all are successful!

    # second, get the used parameters and simulation results

    # paramaeteres = contains short and long names of the parameters we need.
    # The data will be extracted from the .mat files and put in a dictionary
    # The short names will be the keys in that dictionary
    parameters = {}
    for par in pars:
        parameters[par[2]] = par[0]

    for r in results:
        # r is the dictionary containing all results for this specific run
        sim = Simulation(r['mat_file'])
        # we add info to the dictionary: key = var, values = value for var
        for k, v in parameters.iteritems():
            r[k] = sim.get_value(v)
        for k, v in variables.iteritems():
            r[k] = sim.get_value(v)
        # we also get Time
        r['Time'] = sim.get_value('Time')

###############################################################################
if analyse_results:
    for r in results:
        # analyse what you want and add results to the dictionary
        TDHW_too_low = np.nonzero(r['TMixed'] < (273.15 + 45.))[0]
        m_flow_discomfort = r['m_flowTotal'][TDHW_too_low]
        m_flow_discomfort_weighted = (
コード例 #42
0
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 10 09:39:55 2011

@author: RBa
"""

import os
import simviz, simviz_2
import numpy as np
from simman import Simulation, Simdex
path = r'E:\6_Teaching\2011_RobKenneth\result'
os.chdir(path)

s1 = Simulation('HydronischHoutK14')

# simviz.plt_comfort(s1)
simviz_2.plt_scattercomfort(s1)
コード例 #43
0
Created on Thu Feb 17 11:36:47 2011

@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):
コード例 #44
0
ファイル: DemoProcess.py プロジェクト: adamwwt/awesim
                    sub_pars=sub_pars, variables=variables, 
                    sub_vars=sub_vars, pp=pp)

class DummyProcess(object):
    def invoke_upper(self):
        print locals()
        


class MyClass(object):
    
    def __init__(self, process):
        self.process=process
        
    def my_method(self, a, b):
        print 'return the sum of ', a, ' and ', b        
        return a+b
        

dummyprocess=DummyProcess()

myclass=MyClass(dummyprocess)

c= myclass.my_method(3, 5.67)
print c

sim=Simulation('LinkedCapacities.mat', verbose = True)
processed = sim.postprocess(process)

simdex=Simdex(process=process, verbose = False)
simdex.scan()
コード例 #45
0
        summary['mat_file'] = l.replace('.txt','.mat').replace('dslog', 'result')
        results.append(summary)
    # suc6 = [l['successful'] for l in logs]    checked, all are successful!  
    
    # second, get the used parameters and simulation results
    
    # paramaeteres = contains short and long names of the parameters we need.
    # The data will be extracted from the .mat files and put in a dictionary
    # The short names will be the keys in that dictionary     
    parameters = {}
    for par in pars:
        parameters[par[2]] = par[0]
    
    for r in results:
        # r is the dictionary containing all results for this specific run
        sim = Simulation(r['mat_file'])
         # we add info to the dictionary: key = var, values = value for var        
        for k,v in parameters.iteritems():
            r[k] = sim.get_value(v)
        for k,v in variables.iteritems():
            r[k] = sim.get_value(v)
        # we also get Time 
        r['Time'] = sim.get_value('Time')

###############################################################################        
if analyse_results:        
    for r in results:          
        # analyse what you want and add results to the dictionary        
        TDHW_too_low = np.nonzero(r['TMixed'] < (273.15+45.))[0]
        m_flow_discomfort = r['m_flowTotal'][TDHW_too_low]
        m_flow_discomfort_weighted = (r['m_flowTotal'] * (273.15+45.-r['TMixed']))[TDHW_too_low]
コード例 #46
0
                  variables=variables,
                  sub_vars=sub_vars,
                  pp=pp)


class DummyProcess(object):
    def invoke_upper(self):
        print locals()


class MyClass(object):
    def __init__(self, process):
        self.process = process

    def my_method(self, a, b):
        print 'return the sum of ', a, ' and ', b
        return a + b


dummyprocess = DummyProcess()

myclass = MyClass(dummyprocess)

c = myclass.my_method(3, 5.67)
print c

sim = Simulation('LinkedCapacities.mat', verbose=True)
processed = sim.postprocess(process)

simdex = Simdex(process=process, verbose=False)
simdex.scan()
コード例 #47
0
        results.append(summary)
    # suc6 = [l['successful'] for l in logs]    checked, all are successful!

    # second, get the used parameters and simulation results

    # paramaeteres = contains short and long names of the parameters we need.
    # The data will be extracted from the .mat files and put in a dictionary
    # The short names will be the keys in that dictionary
    parameters = {}
    for par in pars:
        parameters[par[2]] = par[0]

    for r in results:
        print ''.join(['\t - ', r['mat_file']])
        # r is the dictionary containing all results for this specific run
        sim = Simulation(r['mat_file'])
        # we add info to the dictionary: key = var, values = value for var
        for k, v in parameters.iteritems():
            r[k] = sim.get_value(v)
        for k, v in variables.iteritems():
            r[k] = sim.get_value(v)
        # we also get Time
        r['Time'] = sim.get_value('Time')

###############################################################################
if analyse_results:
    print 'Analyzing results for:'
    for r in results:
        print ''.join(['\t - ', r['mat_file']])
        # DHW analysis
        TDHW_too_low = np.nonzero(r['TMixed'] < (273.15 + 45.))[0]
コード例 #48
0
 def test_get_value_par(self):
     """ Tests get_value on a parameter  """
     
     sim = Simulation('LinkedCapacities')
     self.assertEqual(600.0, sim.get_value('c1.C'), 'c1.C should be 600.0')
コード例 #49
0
    def test_get_value_par(self):
        """ Tests get_value on a parameter  """

        sim = Simulation('LinkedCapacities')
        self.assertEqual(600.0, sim.get_value('c1.C'), 'c1.C should be 600.0')
コード例 #50
0
    def test_get_value_wrongname(self):
        """ Tests get_value with a wrong or empty name """

        sim = Simulation('LinkedCapacities')
        self.assertRaises(ValueError, sim.get_value, 'wrongname')
        self.assertRaises(ValueError, sim.get_value, '')
コード例 #51
0
Created on Thu Feb 17 11:36:47 2011

@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):
コード例 #52
0
        results.append(summary)
    # suc6 = [l['successful'] for l in logs]    checked, all are successful!  
    
    # second, get the used parameters and simulation results
    
    # paramaeteres = contains short and long names of the parameters we need.
    # The data will be extracted from the .mat files and put in a dictionary
    # The short names will be the keys in that dictionary     
    parameters = {}
    for par in pars:
        parameters[par[2]] = par[0]
    
    for r in results:
        print ''.join(['\t - ', r['mat_file']])
        # r is the dictionary containing all results for this specific run
        sim = Simulation(r['mat_file'])
         # we add info to the dictionary: key = var, values = value for var        
        for k,v in parameters.iteritems():
            r[k] = sim.get_value(v)
        for k,v in variables.iteritems():
            r[k] = sim.get_value(v)
        # we also get Time 
        r['Time'] = sim.get_value('Time')

###############################################################################        
if analyse_results:  
    print 'Analyzing results for:'      
    for r in results:          
        print ''.join(['\t - ', r['mat_file']])
        # DHW analysis
        TDHW_too_low = np.nonzero(r['TMixed'] < (273.15+45.))[0]
コード例 #53
0
if analyse_results:
    # the principle of the data organisation is as follows
    # every simulation has a simulation summary which is a dictionary
    # ALL information that is linked to a simulation is added to this 
    # dictionary
    # All these dictionaries are grouped in lists.  There can be different
    # lists, grouping eg the summaries according to successfulness, or sorting
    # them according to a certain criteria
    
    results_successful = [s for s in results if s['successful'] == True]
    
    # now create a sim object, and add the info we need from the result file
    # to the summary dictionary
    vars_to_check.append('Time')
    for summary in results_successful:
        sim = Simulation(summary['result file'])        
        for var in vars_to_check:
            summary[var] = sim.get_value(var)
            
    res_suc_sortedCPU = sorted(results_successful, 
                          key = lambda x: float(x['CPU_time']))
    
    algos = [s['solver ID'] for s in res_suc_sortedCPU]
    CPU_time = [s['CPU_time'] for s in res_suc_sortedCPU]    
    perc_wrong = [s['perc_wrong'] for s in res_suc_sortedCPU]
    alg = [s['algorithm'] for s in res_suc_sortedCPU]
    algorithm = [''.join(['ID = ', ID, ' - ', a]) for ID, a in zip(algos, alg)]

    # now, make graph of ALL successfull simulations, whether they have many
    # rejected timesteps or not