예제 #1
0
def read_jsonfile(filename):
    """ rankine cycle in json file"""

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

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

    # 2 convert dict to the object of 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 to the object of Comps
    DevNum = len(dictcomps)
    Comps = {}
    for curdev in dictcomps:
        Comps[curdev['name']] = compdict[curdev['type']](curdev)

    return name, nodes, countNodes, Comps, DevNum
예제 #2
0
def read_jsonfile(filename):
    """ rankine cycle in json file"""

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

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

    # 2 convert dict to the object of nodes
    countNodes = len(dictnodes)
    nodes = [None for i in range(countNodes)]
    for curnode in dictnodes:
        nodes[int(curnode['id'])] = Node(curnode)

    # 3 convert dict to the object of Comps
    DevNum = len(dictcomps)
    Comps = {}
    for curdev in dictcomps:
        Comps[curdev['name']] = compdict[curdev['type']](curdev)

    return name, nodes, countNodes, Comps, DevNum
예제 #3
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)
예제 #4
0
def make_grid(rows, width):
    grid = []
    node_width = width // rows

    for row in range(rows):
        grid.append([])
        for col in range(rows):
            node = Node(row, col, node_width, rows)
            grid[row].append(node)

    return grid
예제 #5
0
def read_nodesfile(filename):
    """ csvfile:node's info in the file"""

    countNodes = len(open(filename, 'r').readlines()) - 1
    nodes = [None for i in range(countNodes)]

    csvfile = open(filename, 'r')
    reader = csv.DictReader(csvfile)
    for line in reader:
        i = int(line['NID'])
        nodes[i] = Node(line['NAME'], i)
        try:
            nodes[i].p = float(line['p'])
        except:
            nodes[i].p = None
        try:
            nodes[i].t = float(line['t'])
        except:
            nodes[i].t = None
        try:
            nodes[i].x = float(line['x'])
        except:
            nodes[i].x = None
        try:
            nodes[i].fdot = float(line['fdot'])
        except:
            nodes[i].fdot = None

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

    csvfile.close()
    return nodes, countNodes
예제 #6
0
def read_nodesfile(filename):
    """ csvfile:node's info in the file"""
    countNodes = len(open(filename, 'r').readlines()) - 1
    nodes = [None for i in range(countNodes)]

    ndsFile = open(filename, 'r')
    discardHeader = ndsFile.readline()
    for line in ndsFile:
        NAME, NID, p, t, x, fdot = line.split(',')
        i = int(NID)
        nodes[i] = Node(NAME, i)
        try:
            nodes[i].p = float(p)
        except:
            nodes[i].p = None
        try:
            nodes[i].t = float(t)
        except:
            nodes[i].t = None
        try:
            nodes[i].x = float(x)
        except:
            nodes[i].x = None
        try:
            nodes[i].fdot = float(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()

    ndsFile.close()
    return nodes, countNodes
예제 #7
0
def read_nodesfile(filename):
    """ csvfile:node's info in the file"""
    countNodes = len(open(filename, 'r').readlines()) - 1
    nodes = [None for i in range(countNodes)]

    ndsFile = open(filename, 'r')
    discardHeader = ndsFile.readline()
    for line in ndsFile:
        NAME, NID, p, t, x, fdot = line.split(',')
        i = int(NID)
        nodes[i] = Node(NAME, i)
        try:
            nodes[i].p = float(p)
        except:
            nodes[i].p = None
        try:
            nodes[i].t = float(t)
        except:
            nodes[i].t = None
        try:
            nodes[i].x = float(x)
        except:
            nodes[i].x = None
        try:
            nodes[i].fdot = float(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()

    ndsFile.close()
    return nodes, countNodes
예제 #8
0
    def __init__(self, dictcycle):
        """
          dictcycle={"name":namestring,
                     "nodes":[{node1},{node2},...],
                     "comps":[{node1},{node2},...]
                     }
          TO:           
             self.nodes : dict of all node objects
             self.comps : dict of all component objects
        """
        self.name = dictcycle["name"]
        dictnodes = dictcycle["nodes"]
        dictcomps = dictcycle["comps"]

        # 1 convert dict to the object of nodes
        self.NodeNum = len(dictnodes)
        self.nodes = {}
        for curnode in dictnodes:
            self.nodes[curnode["id"]] = Node(curnode)

        # 2 convert dict to the object of Comps
        self.DevNum = len(dictcomps)
        self.comps = {}
        for curdev in dictcomps:
            self.comps[curdev['name']] = compdict[curdev['devtype']](
                curdev, self.nodes)

        self.totalworkExtracted = 0
        self.totalworkRequired = 0
        self.totalheatAdded = 0

        self.netpoweroutput = 0
        self.efficiency = 100.0
        self.HeatRate = 0.0
        self.SteamRate = 0.0

        self.mdot = None
        self.Wcycledot = None

        self.totalWExtracted = 0
        self.totalWRequired = 0
        self.totalQAdded = 0
예제 #9
0
    def __init__(self, dictcycle):
        """
        Create the node and comp objects from the dict of cycle
             self.nodes : list of all node objects
             self.comps : dict of all component objects
        """
        self.name = dictcycle["name"]
        dictnodes = dictcycle["nodes"]
        dictcomps = dictcycle["comps"]

        # 1 convert dict to the object of nodes
        self.NodeNum = len(dictnodes)
        self.nodes = [None for i in range(self.NodeNum)]
        for curnode in dictnodes:
            self.nodes[int(curnode['id'])] = Node(curnode)

        # 2 convert dict to the object of Comps
        self.DevNum = len(dictcomps)
        self.comps = {}
        for curdev in dictcomps:
            self.comps[curdev['name']] = compdict[curdev['type']](curdev,
                                                                  self.nodes)

        self.totalworkExtracted = 0
        self.totalworkRequired = 0
        self.totalheatAdded = 0

        self.netpoweroutput = 0
        self.efficiency = 100.0
        self.HeatRate = 0.0
        self.SteamRate = 0.0

        self.mdot = None
        self.Wcycledot = None

        self.totalWExtracted = 0
        self.totalWRequired = 0
        self.totalQAdded = 0
예제 #10
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