def test_translate_simulate(self): ''' Tests the :mod:`buildingspy.simulate.Simulator.translate` and the :mod:`buildingspy.simulate.Simulator.simulate_translated` method. ''' import numpy as np from buildingspy.io.outputfile import Reader s = Simulator("MyModelicaLibrary.MyModel", "dymola", packagePath=self._packagePath) s.addModelModifier( "redeclare Modelica.Blocks.Sources.Step source(offset=-0.1, height=1.1, startTime=0.5)" ) s.setStartTime(-1) s.setStopTime(5) s.setTimeOut(600) s.setTolerance(1e-4) s.setSolver("dassl") s.setNumberOfIntervals(50) s.setResultFile("myResults") s.translate() s.simulate_translated() # Read the result and test their validity outDir = s.getOutputDirectory() resultFile = os.path.abspath(os.path.join(outDir, "myResults.mat")) r = Reader(resultFile, "dymola") np.testing.assert_allclose(1.0, r.max('source.y')) np.testing.assert_allclose(-0.1, r.min('source.y')) np.testing.assert_allclose(0.725, r.mean('source.y')) np.testing.assert_allclose(0.725 * 6, r.integral('source.y')) # Delete output files s.deleteOutputFiles() s.deleteLogFiles() # Make another simulation, but now the start time is at -2, and the height is 2.1 s.setStartTime(-2) s.addParameters({'source.height': 2.1}) s.simulate_translated() outDir = s.getOutputDirectory() resultFile = os.path.abspath(os.path.join(outDir, "myResults.mat")) r = Reader(resultFile, "dymola") np.testing.assert_allclose(2.0, r.max('source.y')) np.testing.assert_allclose(-0.1, r.min('source.y')) np.testing.assert_allclose(1.25, r.mean('source.y')) np.testing.assert_allclose(7 * 1.25, r.integral('source.y')) # clean up translate temporary dir s.deleteOutputFiles() s.deleteLogFiles() s.deleteTranslateDirectory()
def test_translate_simulate(self): """ Tests the :mod:`buildingspy.simulate.Simulator.translate` and the :mod:`buildingspy.simulate.Simulator.simulate_translated` method. """ import numpy as np from buildingspy.io.outputfile import Reader s = Simulator("MyModelicaLibrary.MyModel", "dymola", packagePath=self._packagePath) s.addModelModifier( "redeclare Modelica.Blocks.Sources.Step source(offset=-0.1, height=1.1, startTime=0.5)") s.setStartTime(-1) s.setStopTime(5) s.setTimeOut(600) s.setTolerance(1e-4) s.setSolver("dassl") s.setNumberOfIntervals(50) s.setResultFile("myResults") s.translate() s.simulate_translated() # Read the result and test their validity outDir = s.getOutputDirectory() resultFile = os.path.abspath(os.path.join(outDir, "myResults.mat")) r = Reader(resultFile, "dymola") np.testing.assert_allclose(1.0, r.max('source.y')) np.testing.assert_allclose(-0.1, r.min('source.y')) np.testing.assert_allclose(0.725, r.mean('source.y')) np.testing.assert_allclose(0.725 * 6, r.integral('source.y')) # Delete output files s.deleteOutputFiles() s.deleteLogFiles() # Make another simulation, but now the start time is at -2, and the height is 2.1 s.setStartTime(-2) s.addParameters({'source.height': 2.1}) s.simulate_translated() outDir = s.getOutputDirectory() resultFile = os.path.abspath(os.path.join(outDir, "myResults.mat")) r = Reader(resultFile, "dymola") np.testing.assert_allclose(2.0, r.max('source.y')) np.testing.assert_allclose(-0.1, r.min('source.y')) np.testing.assert_allclose(1.25, r.mean('source.y')) np.testing.assert_allclose(7 * 1.25, r.integral('source.y')) # clean up translate temporary dir s.deleteOutputFiles() s.deleteLogFiles() s.deleteTranslateDirectory()
def ReadMat(dirname, matFileName, readVar, pipeList, modellist):#, lifetime, upv_File, co2_rate_file, co2_pricing_file, startYear): # read the MAT_Result File of the Modelica Simulation TA_data = [] for case in os.listdir(dirname): if 'case' in case: matFile = dirname + "/" + case + "/" + matFileName r = Reader(matFile, "dymola") data = {'name': case} for v in readVar: if v[1] == 'max': data.update({v[2]: r.max(v[0])}) elif v[1] == 'min': data.update({v[2]: r.min(v[0])}) elif v[1] == 'integral': data.update({v[2]: r.integral(v[0])}) # if pipe is active, add its pipe length to the total pipe length pipeLength = 0 for pipe in pipeList: data.update({pipe.name: r.max((pipe.name + ".active"))}) if data[pipe.name] == 1: pipeLength += r.max((pipe.name + ".length")) pipeDiameter = r.max((pipe.name + ".diameter")) data.update({'Total_Pipe_Length': pipeLength}) for m in modellist: data.update({m.name: r.max((m.name + ".connected"))}) TA_data.append(data) return TA_data
def test_addMethods(self): """ Tests the various add methods. """ import numpy as np from buildingspy.io.outputfile import Reader s = Simulator("MyModelicaLibrary.MyModel", packagePath=self._packagePath) s.addModelModifier( "redeclare Modelica.Blocks.Sources.Step source(offset=-0.1, height=1.1, startTime=0.5)" ) s.setStartTime(-1) s.setStopTime(5) s.setTimeOut(600) s.setTolerance(1e-8) s.setSolver("Radau5ODE") s.setNumberOfIntervals(50) s.setResultFile("myResults") s.simulate() # Read the result and test their validity outDir = s.getOutputDirectory() resultFile = os.path.abspath(os.path.join(outDir, "myResults.mat")) r = Reader(resultFile, "dymola") np.testing.assert_allclose(1.0, r.max('source.y')) np.testing.assert_allclose(0.725, r.mean('source.y')) np.testing.assert_allclose(0.725 * 6, r.integral('source.y')) np.testing.assert_allclose(-0.1, r.min('source.y')) # Delete output files s.deleteOutputFiles()
def test_addMethods(self): ''' Tests the various add methods. ''' import numpy as np from buildingspy.io.outputfile import Reader s = Simulator("MyModelicaLibrary.MyModel", "dymola", packagePath=self._packagePath) s.addPreProcessingStatement("Advanced.StoreProtectedVariables:= true;") s.addPostProcessingStatement( "Advanced.StoreProtectedVariables:= false;") s.addModelModifier( "redeclare Modelica.Blocks.Sources.Step source(offset=-0.1, height=1.1, startTime=0.5)" ) s.setStartTime(-1) s.setStopTime(5) s.setTimeOut(600) s.setTolerance(1e-4) s.setSolver("dassl") s.setNumberOfIntervals(50) s.setResultFile("myResults") s.exitSimulator(True) # s.deleteOutputFiles() s.showGUI(False) # s.printModelAndTime() s.showProgressBar(False) s.simulate() # Read the result and test their validity outDir = s.getOutputDirectory() resultFile = os.path.abspath(os.path.join(outDir, "myResults.mat")) r = Reader(resultFile, "dymola") np.testing.assert_allclose(1.0, r.max('source.y')) np.testing.assert_allclose(0.725, r.mean('source.y')) np.testing.assert_allclose(0.725 * 6, r.integral('source.y')) np.testing.assert_allclose(-0.1, r.min('source.y')) # Delete output files s.deleteOutputFiles() s.deleteLogFiles()
def test_addMethods(self): ''' Tests the various add methods. ''' import os import numpy as np from buildingspy.io.outputfile import Reader s = Simulator("MyModelicaLibrary.MyModel", "dymola") s.addPreProcessingStatement("Advanced.StoreProtectedVariables:= true;") s.addPostProcessingStatement("Advanced.StoreProtectedVariables:= false;") s.addModelModifier('redeclare Modelica.Blocks.Sources.Step source(offset=-0.1, height=1.1, startTime=0.5)') s.setStartTime(-1) s.setStopTime(5) s.setTimeOut(600) s.setTolerance(1e-4) s.setSolver("dassl") s.setNumberOfIntervals(50) s.setResultFile("myResults") s.exitSimulator(True) s.deleteOutputFiles() s.showGUI(False) # s.printModelAndTime() s.showProgressBar(False) s.simulate() # Read the result and test their validity outDir = s.getOutputDirectory() resultFile = os.path.abspath(os.path.join(outDir, "myResults.mat")) r=Reader(resultFile, "dymola") np.testing.assert_allclose(1.0, r.max('source.y')) np.testing.assert_allclose(0.725, r.mean('source.y')) np.testing.assert_allclose(0.725*6, r.integral('source.y')) np.testing.assert_allclose(-0.1, r.min('source.y')) # Delete output files s.deleteOutputFiles() s.deleteLogFiles()
def ReadMat(dirname, matFileName, resultVar, pipeList, modellist): TA_data = [] for case in os.listdir(dirname): if 'case' in case: matFile = dirname + "/" + case + "/" + matFileName r = Reader(matFile, "dymola") data = {'name': case} for v in resultVar: if v[1] == 'max': data.update({v[0]: r.max(v[0])}) elif v[1] == 'min': data.update({v[0]: r.min(v[0])}) elif v[1] == 'integral': data.update({v[0]: r.integral(v[0])}) pipeLength = 0 for pipe in pipeList: data.update({pipe.name: r.max((pipe.name + ".active"))}) if data[pipe.name] == 1: pipeLength += r.max((pipe.name + ".length")) data.update({'Total_Pipe_Length': pipeLength}) for m in modellist: data.update({m.name: r.max((m.name + ".connected"))}) TA_data.append(data) return TA_data
E_htf = [] vector = [0, 1] for KKK in range(len(Nodes)): resultFile = ( 'C:\Users\susanna\Documents\GitHub\PSA_SFERAII\Modelling\ModelicaResults\20160704_NodeAnalysis/' + FileSimulation + Nodes[KKK] + ".mat") r = Reader(resultFile, "dymola") DNI.append(r.values('DNI.y')) NN.append(r.values('EuroTrough.N')) T_su.append(r.values('SensTsu.fluidState.T')) T_ex.append(r.values('SensTex.fluidState.T')) TimeSim.append(T_ex[KKK][0]) T_ex_exp.append(r.values('t_htf_ex.y')) Delta_T.append(r.values('DeltaT.Delta')) m_wf.append(r.values('m_dot_htf.y')) E_htf.append(r.integral('EuroTrough.Summary.Q_htf_tot')) TimeExp.append( np.linspace(StartModTime[0], StopModTime[0], num=int((StopModTime[0] - StartModTime[0]) / 10))) # Interpolate the Modelica results over the Time vector DNIExp.append(Plotter.interpolate(TimeExp[KKK], DNI[KKK][0], DNI[KKK][1])) T_suExp.append( Plotter.interpolate(TimeExp[KKK], T_su[KKK][0], T_su[KKK][1] - 273.15)) T_exExp.append( Plotter.interpolate(TimeExp[KKK], T_ex_exp[KKK][0], T_ex_exp[KKK][1] - 273.15)) m_wfExp.append( Plotter.interpolate(TimeExp[KKK], m_wf[KKK][0], m_wf[KKK][1]))
m_wfExp = [] E_htf = [] vector = [ 0, 1] for KKK in range(len(Nodes)): resultFile=('C:\Users\susanna\Documents\GitHub\PSA_SFERAII\Modelling\ModelicaResults\20160704_NodeAnalysis/'+FileSimulation+Nodes[KKK]+".mat") r=Reader(resultFile, "dymola") DNI.append(r.values('DNI.y')) NN.append(r.values('EuroTrough.N')) T_su.append(r.values('SensTsu.fluidState.T')) T_ex.append(r.values('SensTex.fluidState.T')) TimeSim.append(T_ex[KKK][0]) T_ex_exp.append(r.values('t_htf_ex.y')) Delta_T.append(r.values('DeltaT.Delta')) m_wf.append(r.values('m_dot_htf.y')) E_htf.append(r.integral('EuroTrough.Summary.Q_htf_tot')) TimeExp.append(np.linspace(StartModTime[0],StopModTime[0],num=int((StopModTime[0]-StartModTime[0])/10))) # Interpolate the Modelica results over the Time vector DNIExp.append(Plotter.interpolate(TimeExp[KKK], DNI[KKK][0], DNI[KKK][1])) T_suExp.append(Plotter.interpolate(TimeExp[KKK],T_su[KKK][0],T_su[KKK][1]-273.15)) T_exExp.append(Plotter.interpolate(TimeExp[KKK],T_ex_exp[KKK][0],T_ex_exp[KKK][1]-273.15)) m_wfExp.append(Plotter.interpolate(TimeExp[KKK],m_wf[KKK][0],m_wf[KKK][1])) #r.integral('preHea.port.Q_flow') # Compute percentage difference between total energy absorbed with the different CVs taking the 50 CVs as the reference PDTE = []