Example #1
0
 def setEliminateComments(self, newValue):
     self._eliminateComments == True
     if newValue == True:
         self.linesDeck = deckUtils.loadDeck(
             nameDck,
             eraseBeginComment=self._eliminateComments,
             eliminateComments=self._eliminateComments)
Example #2
0
    def checkTrnsysDeck(self, nameDck, check=True):

        # self.readTrnsyDeck()
        # deckUtils.checkEquationsAndConstants(self.linesDeckReaded)

        lines = deckUtils.loadDeck(nameDck,
                                   eraseBeginComment=True,
                                   eliminateComments=True)
        if (check):
            deckUtils.checkEquationsAndConstants(lines, self.nameDeck)

        self.linesDeckReaded = lines
Example #3
0
    def loadFile(self, useDeckName=False, eraseBeginComment=True, eliminateComments=True, useDeckOutputPath=False):
        """
        It reads the deck  removing files starting with \*\*\*.

        Return
        ----------
        linesDeck : list of str
            list containing the lines of the deck from the read deck.
        """

        lines = deckUtils.loadDeck(
            self.nameWithPath, eraseBeginComment=self._eliminateComments, eliminateComments=self._eliminateComments
        )

        self.linesDeck = [line.lower() for line in lines]

        self.ignoreOnlinePlotter()
Example #4
0
    def loadDeck(self,
                 useDeckName=False,
                 eraseBeginComment=True,
                 eliminateComments=True,
                 useDeckOutputPath=False):
        """
        It reads the deck  removing files starting with \*\*\*.

        Return
        ----------
        linesDeck : list of str
            list containing the lines of the deck from the read deck.
        """

        if (useDeckName == False):

            if (useDeckOutputPath == True):
                nameDck = self.nameDckPathOutput
            else:
                nameDck = self.nameDck

            logger.debug("DECK TRNSYS::LOAD DECK nameDeck:%s" % (self.nameDck))

        else:
            logger.debug("DECK TRNSYS::LOAD DECK nameDeck:%s USEDECKNAME:%s" %
                         (self.nameDck, useDeckName))

            # self.nameDck = useDeckName
            # self.nameDckPathOutput = useDeckName
            nameDck = useDeckName
        lines = deckUtils.loadDeck(nameDck,
                                   eraseBeginComment=eraseBeginComment,
                                   eliminateComments=eliminateComments)

        self.linesDeck = lines

        return lines
Example #5
0
    def exportHydraulics(self, exportTo=_tp.Literal["ddck", "mfs"]):
        assert exportTo in ["ddck", "mfs"]

        if not self._isHydraulicConnected():
            messageBox = QMessageBox()
            messageBox.setWindowTitle("Hydraulic not connected")
            messageBox.setText(
                "You need to connect all port items before you can export the hydraulics."
            )
            messageBox.setStandardButtons(QMessageBox.Ok)
            messageBox.exec()
            return

        self.logger.info(
            "------------------------> START OF EXPORT <------------------------"
        )

        self.sortTrnsysObj()

        fullExportText = ""

        ddckFolder = os.path.join(self.projectFolder, "ddck")

        if exportTo == "mfs":
            mfsFileName = self.diagramName.split(".")[0] + "_mfs.dck"
            exportPath = os.path.join(self.projectFolder, mfsFileName)
        elif exportTo == "ddck":
            exportPath = os.path.join(ddckFolder, "hydraulic\\hydraulic.ddck")

        if self._doesFileExistAndDontOverwrite(exportPath):
            return None

        self.logger.info("Printing the TRNSYS file...")

        if exportTo == "mfs":
            header = open(os.path.join(ddckFolder, "generic\\head.ddck"), "r")
            headerLines = header.readlines()
            for line in headerLines:
                if line[:4] == "STOP":
                    fullExportText += "STOP = 1 \n"
                else:
                    fullExportText += line
            header.close()
        elif exportTo == "ddck":
            fullExportText += "*************************************\n"
            fullExportText += "** BEGIN hydraulic.ddck\n"
            fullExportText += "*************************************\n\n"
            fullExportText += "*************************************\n"
            fullExportText += "** Outputs to energy balance in kWh\n"
            fullExportText += (
                "** Following this naming standard : qSysIn_name, qSysOut_name, elSysIn_name, elSysOut_name\n"
            )
            fullExportText += "*************************************\n"
            fullExportText += "EQUATIONS 1\n"
            fullExportText += "qSysOut_PipeLoss = PipeLossTot\n"

        simulationUnit = 450
        simulationType = 935
        descConnLength = 20

        exporter = self._createExporter()

        blackBoxProblem, blackBoxText = exporter.exportBlackBox(
            exportTo=exportTo)
        if blackBoxProblem:
            return None

        fullExportText += blackBoxText
        if exportTo == "mfs":
            fullExportText += exporter.exportMassFlows()
            fullExportText += exporter.exportPumpOutlets()
            fullExportText += exporter.exportDivSetting(simulationUnit - 10)

        fullExportText += exporter.exportDoublePipeParameters(
            exportTo=exportTo)

        fullExportText += exporter.exportParametersFlowSolver(
            simulationUnit, simulationType, descConnLength)

        fullExportText += exporter.exportInputsFlowSolver()
        fullExportText += exporter.exportOutputsFlowSolver(simulationUnit)
        fullExportText += exporter.exportFluids() + "\n"
        fullExportText += exporter.exportHydraulicLoops() + "\n"
        fullExportText += exporter.exportPipeAndTeeTypesForTemp(
            simulationUnit + 1)  # DC-ERROR
        fullExportText += exporter.exportPrintPipeLosses()

        fullExportText += exporter.exportMassFlowPrinter(
            self.printerUnitnr, 15)
        fullExportText += exporter.exportTempPrinter(self.printerUnitnr + 1,
                                                     15)

        if exportTo == "mfs":
            fullExportText += "CONSTANTS 1\nTRoomStore=1\n"
            fullExportText += "ENDS"

        self.logger.info(
            "------------------------> END OF EXPORT <------------------------"
        )

        if exportTo == "mfs":
            f = open(exportPath, "w")
            f.truncate(0)
            f.write(fullExportText)
            f.close()
        elif exportTo == "ddck":
            if fullExportText[:1] == "\n":
                fullExportText = fullExportText[1:]
            hydraulicFolder = os.path.split(exportPath)[0]
            if not (os.path.isdir(hydraulicFolder)):
                os.makedirs(hydraulicFolder)
            f = open(exportPath, "w")
            f.truncate(0)
            f.write(fullExportText)
            f.close()

        try:
            lines = _du.loadDeck(exportPath,
                                 eraseBeginComment=True,
                                 eliminateComments=True)
            _du.checkEquationsAndConstants(lines, exportPath)
        except Exception as error:
            errorMessage = f"An error occurred while exporting the system hydraulics: {error}"
            _errs.showErrorMessageBox(errorMessage)
            return None

        return exportPath