示例#1
0
def read_devicefile(filename):
    devFile = open(filename, 'r')
    discardHeader = devFile.readline()
    Comps = {}
    i = 0
    begId = 3
    for line in devFile:
        dev = line.split(',')

        if dev[1] == "TURBINE-EX1":
            Comps[dev[0]] = Turbine(dev[0], int(dev[begId]),  int(
                dev[begId + 1]), int(dev[begId + 2]), ef=float(dev[2]))
        elif dev[1] == "TURBINE-EX0":
            Comps[dev[0]] = Turbine(dev[0], int(
                dev[begId]),  int(dev[begId + 1]), ef=float(dev[2]))
        elif dev[1] == "BOILER":
            Comps[dev[0]] = Boiler(
                dev[0], int(dev[begId]), int(dev[begId + 1]))
        elif dev[1] == "CONDENSER":
            Comps[dev[0]] = Condenser(
                dev[0], int(dev[begId]), int(dev[begId + 1]))
        elif dev[1] == "PUMP":
            Comps[dev[0]] = Pump(dev[0], int(
                dev[begId]),  int(dev[begId + 1]), ef=float(dev[2]))
        elif dev[1] == "OH-FEEDWATER-DW0":
            Comps[dev[0]] = Openedheater(dev[0], int(
                dev[begId]), int(dev[begId + 1]), int(dev[begId + 2]))

        i = i + 1

    devFile.close()

    DevNum = i
    return Comps, DevNum
示例#2
0
    def setUp(self):

        self.samplenodes = [{
            "name": "Boiler to Turbine",
            "id": 0,
            "p": 8.0,
            "t": 480.0,
            "x": 1.0,
            "fdot": 1.0,
            "h": 3349.5266902175404,
            "s": 6.661057438926857,
            "v": 0.040364941230239954,
            "mdot": 368813.0888854596
        }, {
            "name": "FW Pump to Boiler",
            "id": 1,
            "p": 8.0,
            "t": 165.85457047406948,
            "x": 0.0,
            "fdot": 1.0,
            "h": 705.2157182424864,
            "s": 1.9920831369740433,
            "v": 0.0011036643191215912,
            "mdot": 368813.0888854596
        }]

        self.samplecase = {
            "name": "Boiler",
            "inNode": 1,
            "outNode": 0,
            "heatAdded": 2644.3109719750537,
            "QAdded": 270.9045826521754
        }

        self.nodes = [None for i in range(len(self.samplenodes))]
        oID = 0
        iID = 1
        self.nodes[iID] = Node(self.samplenodes[iID])
        self.nodes[oID] = Node(self.samplenodes[oID])

        self.dictDev = {"name": "Boiler1", "inNode": iID, "outNode": oID}
        self.testcase = Boiler(self.dictDev)
示例#3
0
def read_jsonfile(filename):
    """ rankine cycle in json file"""

    # 1 read json file to dict
    with open(filename, 'r') as f:
        rkcyc = json.loads(f.read())

    # print(rkcyc)
    name = rkcyc["name"]
    dictnodes = rkcyc["nodes"]
    dictcomps = rkcyc["comps"]

    # 2 convert dict nodes to the object nodes
    countNodes = len(dictnodes)
    nodes = [None for i in range(countNodes)]
    for curnode in dictnodes:
        i = int(curnode['id'])
        nodes[i] = Node(curnode['name'], i)
        try:
            nodes[i].p = float(curnode['p'])
        except:
            nodes[i].p = None
        try:
            nodes[i].t = float(curnode['t'])
        except:
            nodes[i].t = None
        try:
            nodes[i].x = float(curnode['x'])
        except:
            nodes[i].x = None
        try:
            nodes[i].fdot = float(curnode['fdot'])
        except:
            nodes[i].fdot = None

        if nodes[i].p != None and nodes[i].t != None:
            nodes[i].pt()
        elif nodes[i].p != None and nodes[i].x != None:
            nodes[i].px()
        elif nodes[i].t != None and nodes[i].x != None:
            nodes[i].tx()

    # 3 convert dict Comps to the object Comps
    DevNum = len(dictcomps)
    Comps = {}
    for curdev in dictcomps:
        if curdev['type'] == "TURBINE-EX1":
            Comps[curdev['name']] = Turbine(curdev['name'],
                                            curdev['inNode'],
                                            curdev['outNode'],
                                            curdev['extNode'],
                                            ef=curdev['eff'])
        elif curdev['type'] == "TURBINE-EX0":
            Comps[curdev['name']] = Turbine(curdev['name'],
                                            curdev['inNode'],
                                            curdev['outNode'],
                                            ef=curdev['eff'])
        elif curdev['type'] == "BOILER":
            Comps[curdev['name']] = Boiler(curdev['name'], curdev['inNode'],
                                           curdev['outNode'])
        elif curdev['type'] == "CONDENSER":
            Comps[curdev['name']] = Condenser(curdev['name'], curdev['inNode'],
                                              curdev['outNode'])
        elif curdev['type'] == "PUMP":
            Comps[curdev['name']] = Pump(curdev['name'], curdev['inNode'],
                                         curdev['outNode'], curdev['eff'])
        elif curdev['type'] == "OH-FEEDWATER-DW0":
            Comps[curdev['name']] = Openedheater(curdev['name'],
                                                 curdev['inNode'],
                                                 curdev['inNode_fw'],
                                                 curdev['outNode_fw'])

    return name, nodes, countNodes, Comps, DevNum
示例#4
0
class BoilerTest(unittest.TestCase):
    def setUp(self):

        self.samplenodes = [{
            "name": "Boiler to Turbine",
            "id": 0,
            "p": 8.0,
            "t": 480.0,
            "x": 1.0,
            "fdot": 1.0,
            "h": 3349.5266902175404,
            "s": 6.661057438926857,
            "v": 0.040364941230239954,
            "mdot": 368813.0888854596
        }, {
            "name": "FW Pump to Boiler",
            "id": 1,
            "p": 8.0,
            "t": 165.85457047406948,
            "x": 0.0,
            "fdot": 1.0,
            "h": 705.2157182424864,
            "s": 1.9920831369740433,
            "v": 0.0011036643191215912,
            "mdot": 368813.0888854596
        }]

        self.samplecase = {
            "name": "Boiler",
            "inNode": 1,
            "outNode": 0,
            "heatAdded": 2644.3109719750537,
            "QAdded": 270.9045826521754
        }

        self.nodes = [None for i in range(len(self.samplenodes))]
        oID = 0
        iID = 1
        self.nodes[iID] = Node(self.samplenodes[iID])
        self.nodes[oID] = Node(self.samplenodes[oID])

        self.dictDev = {"name": "Boiler1", "inNode": iID, "outNode": oID}
        self.testcase = Boiler(self.dictDev)

    def test_state(self):
        self.testcase.state(self.nodes)

    def test_balance(self):
        places = 6
        self.testcase.state(self.nodes)
        self.testcase.balance()
        self.assertAlmostEqual(self.testcase.heatAdded,
                               self.samplecase["heatAdded"], places)

    def test_sm_energy(self):
        places = 6
        self.testcase.state(self.nodes)
        self.testcase.balance()
        self.testcase.sm_energy()
        self.assertAlmostEqual(self.testcase.QAdded, self.samplecase["QAdded"],
                               places)