コード例 #1
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')
コード例 #2
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')
コード例 #3
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')
コード例 #4
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')
コード例 #5
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()
コード例 #6
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()        
コード例 #7
0
    # 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]
        m_flow_discomfort = r['mDHW'][TDHW_too_low]
        m_flow_discomfort_weighted = (r['mDHW'] * (273.15+45.-r['TMixed']))[TDHW_too_low]
        DHW_discomfort = sum(m_flow_discomfort)/sum(r['mDHW'])
コード例 #8
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')
コード例 #9
0
#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)])

# there are different ways to create a simdex

s1 = Simdex()  # an empty simdex object
s1.scan(
)  # scan current folder and add all found simulation files to the simdex

s2 = Simdex('SubfolderWithCrappyFiles')
# create a simdex directly from a folder
コード例 #10
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')
コード例 #11
0
    # 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]
        m_flow_discomfort = r['mDHW'][TDHW_too_low]
        m_flow_discomfort_weighted = (
            r['mDHW'] * (273.15 + 45. - r['TMixed']))[TDHW_too_low]
コード例 #12
0
    
    # 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]
        DHW_discomfort = sum(m_flow_discomfort)/sum(r['m_flowTotal'])
        dT_discomfort = sum(m_flow_discomfort_weighted)/sum(m_flow_discomfort)
        r['DHW_discomfort'] = DHW_discomfort
コード例 #13
0
#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)])


# there are different ways to create a simdex

s1 = Simdex() # an empty simdex object
s1.scan() # scan current folder and add all found simulation files to the simdex

s2 = Simdex('SubfolderWithCrappyFiles')
    # create a simdex directly from a folder
コード例 #14
0
    # 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]
        DHW_discomfort = sum(m_flow_discomfort) / sum(r['m_flowTotal'])
        dT_discomfort = sum(m_flow_discomfort_weighted) / sum(
コード例 #15
0
    # 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
        
    fig = plt.figure()
    ax1 = plt.subplot(211)