def _simulate(cas): """ Class to simulate models. This needs to be at the top-level for multiprocessing to be able to serialize it. """ from buildingspy.simulate.Dymola import Simulator packagePath = os.path.abspath( os.path.join("buildingspy", "tests", "MyModelicaLibrary")) s = Simulator(cas['model'], outputDirectory=f"out-{cas['tol']}", packagePath=packagePath) s.setTolerance(cas['tol']) s.simulate()
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.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()