コード例 #1
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'))
コード例 #2
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'])
コード例 #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_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.)
コード例 #5
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))
コード例 #6
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))
コード例 #7
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']))
コード例 #8
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']))
コード例 #9
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)
コード例 #10
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)
コード例 #11
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']))
コード例 #12
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']))
コード例 #13
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'])     
コード例 #14
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.)
コード例 #15
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()
コード例 #16
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()