示例#1
0
    def init_hotstart(self, file):
        """
        Initalize water quality state in a network

        :param file: a JSON file or readable binary stream
        :return: None

        {
        "quality": [1,2,3,4,5,...],
        ...
        }

        """
        fh = None
        # get data vector from file (JSON file handle)
        if isinstance(file, str):
            fh = open(file, 'rb')
        elif isinstance(file, io.IOBase):
            fh = file

        state = json.load(fh)
        quality_state = state["quality"]
        n_nodes = toolkit.getcount(self.ph, toolkit.NODECOUNT)
        for component in zip(range(1, n_nodes + 1), quality_state):
            toolkit.setnodevalue(self.ph, component[0], toolkit.QUALITY,
                                 component[1])
示例#2
0
 def set(self, key, value):
     k = key.key if isinstance(key, KeyPath) else key
     idx = toolkit.getnodeindex(self._p, self._n)
     toolkit.setnodevalue(self._p, idx, NodeModifier.keys[k], value)
     if debug:
         print("set {} to {} -> epanet value is {}".format(
             key, value,
             toolkit.getnodevalue(self._p, idx, NodeModifier.keys[k])))
 def setNodeSourceQuality(self, nodeID, sourceStrength):
     """
     Set the node with  nodeID as the quality source type value
     """
     index = self.getNodeIndexbyID(nodeID)
     en.setnodevalue(ph=self.epanet_proj,
                     index=index,
                     property=en.SOURCEQUAL,
                     value=sourceStrength)
 def setNodeSourceType_Quality(self, nodeID, sourceTypeString,
                               sourceStrength):
     index = self.getNodeIndexbyID(nodeID)
     assert isinstance(sourceTypeString, str)
     sourceType = self.TYPESOURCE.index(sourceTypeString)
     en.setnodevalue(ph=self.epanet_proj,
                     index=index,
                     property=en.SOURCETYPE,
                     value=sourceType)
     en.setnodevalue(ph=self.epanet_proj,
                     index=index,
                     property=en.SOURCEQUAL,
                     value=sourceStrength)
 def setNodeSourceType(self, nodeID, sourceType):
     """
     Set the node with  nodeID as the quality source type value
     0. CONCEN
     1. MASS
     2. SETPOINT
     3. FLOWPACED
     """
     index = self.getNodeIndexbyID(nodeID)
     en.setnodevalue(ph=self.epanet_proj,
                     index=index,
                     property=en.SOURCETYPE,
                     value=sourceType)
def inject_chlorine(str_nodeID, booster_val):
    epanet_proj = en.createproject()
    en.open(ph=epanet_proj,
            inpFile=example_1_path,
            rptFile='report.rpt',
            outFile='output.out')
    en.setqualtype(ph=epanet_proj,
                   qualType=1,
                   chemName='Chlorine',
                   chemUnits='mg/L',
                   traceNode=None)
    num_nodes = en.getcount(ph=epanet_proj, object=en.NODECOUNT)
    num_links = en.getcount(ph=epanet_proj, object=en.LINKCOUNT)
    tlist = []
    en.openH(ph=epanet_proj)
    en.initH(ph=epanet_proj, initFlag=0)
    en.openQ(ph=epanet_proj)
    booster_node = en.getnodeindex(ph=epanet_proj, id=str_nodeID)
    print('Booster node index is %d' % (booster_node))
    #sets node as Mass Booster
    en.setnodevalue(ph=epanet_proj,
                    index=booster_node,
                    property=en.SOURCETYPE,
                    value=1)
    en.setnodevalue(ph=epanet_proj,
                    index=booster_node,
                    property=en.SOURCEQUAL,
                    value=booster_val)
    nodetype = en.getnodevalue(ph=epanet_proj,
                               index=booster_node,
                               property=en.SOURCETYPE)
    obj = QualityControl(1)  #seems to set nodetype to 1
    #obj.set_nodetype(1) runs automatically
    print(obj.get_nodetype())  #checking
    en.initQ(ph=epanet_proj, saveFlag=1)
    node_qual = en.getnodevalue(ph=epanet_proj,
                                index=booster_node,
                                property=en.SOURCEQUAL)
    print('Booster node source quality: %5.2f' % (node_qual))
    #print('End of inject chlorine function.')
    en.closeH(ph=epanet_proj)
    en.closeQ(ph=epanet_proj)
    en.close(ph=epanet_proj)
    clean_dir()
def setNodeSourceQuality(str_nodeID, booster_val):
    epanet_proj = en.createproject()
    en.open(ph=epanet_proj,
            inpFile=example_1_path,
            rptFile='report.rpt',
            outFile='output.out')
    en.setqualtype(ph=epanet_proj,
                   qualType=1,
                   chemName='Chlorine',
                   chemUnits='mg/L',
                   traceNode=None)
    num_nodes = en.getcount(ph=epanet_proj, object=en.NODECOUNT)
    num_links = en.getcount(ph=epanet_proj, object=en.LINKCOUNT)
    source_ind = en.getnodeindex(ph=epanet_proj, id=str_nodeID)
    '''en.openH(ph=epanet_proj)
    en.initH(ph=epanet_proj, initFlag=0)
    en.openQ(ph=epanet_proj)
    en.initQ(ph=epanet_proj, saveFlag=1)'''
    #setting source_ind as booster, need to find a way to acknowledge pre-set boosters
    #en.setnodevalue(ph=epanet_proj, index=source_ind, property=en.SOURCETYPE, value=1)
    node_type = en.getnodevalue(ph=epanet_proj,
                                index=source_ind,
                                property=en.SOURCETYPE)
    if node_type == 1:
        en.setnodevalue(ph=epanet_proj,
                        index=source_ind,
                        property=en.SOURCEQUAL,
                        value=booster_val)
        print('Node (index %d) source quality set to value %5.2f' %
              (source_ind, booster_val))
    else:
        print('Specified node is not designated as mass booster.')
    print('End of setNodeSourceQuality function.')
    '''en.closeH(ph=epanet_proj)
    en.closeQ(ph=epanet_proj)
    en.close(ph=epanet_proj)'''
    clean_dir()
def test_setnodevalue():
    epanet_proj = en.createproject()
    en.open(ph=epanet_proj, inpFile=example_1_path, rptFile='report.rpt', outFile='output.out')
    num_nodes = en.getcount(ph=epanet_proj, object=en.NODECOUNT)
    elev_list = []
    demand_list = []
    pattern_list=[]
    emitter_list = []
    initqual_list = []
    tank_level_list = []
    for node_ind in range(1, num_nodes+1):
        # elevation
        elev = en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.ELEVATION)
        en.setnodevalue(ph=epanet_proj, index=node_ind, property=en.ELEVATION, value=elev + 1)
        elev_list.append(en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.ELEVATION))
        # base demand
        demand = en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.BASEDEMAND)
        en.setnodevalue(ph=epanet_proj, index=node_ind, property=en.BASEDEMAND, value=demand + 1)
        demand_list.append(en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.BASEDEMAND))
        # pattern
        en.setnodevalue(ph=epanet_proj, index=node_ind, property=en.PATTERN, value=0)
        pattern_list.append(en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.PATTERN))
        # emitter
        en.setnodevalue(ph=epanet_proj, index=node_ind, property=en.EMITTER, value=0.01)
        emitter_list.append(en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.EMITTER))
        # initqual
        initqual = en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.INITQUAL)
        en.setnodevalue(ph=epanet_proj, index=node_ind, property=en.INITQUAL, value=initqual + 0.1)
        initqual_list.append(en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.INITQUAL))
        # tanklevel
        if en.getnodetype(ph=epanet_proj, index=node_ind) == en.TANK:
            tank_level = en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.TANKLEVEL)
            en.setnodevalue(ph=epanet_proj, index=node_ind, property=en.TANKLEVEL, value=tank_level + 1)
            tank_level_list.append(en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.TANKLEVEL))
    assert elev_list == [711.0, 711.0, 701.0, 696.0, 701.0, 696.0, 691.0, 701.0, 711.0, 801.0, 851.0]
    assert demand_list == [1.0, 151.0, 151.0, 101.0, 151.0, 201.0, 151.0, 101.0, 101.0, 0.0, 0.0]
    assert pattern_list == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    assert emitter_list == [0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.0, 0.0]
    assert initqual_list == [0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 1.1, 1.1]
    assert tank_level_list ==[121.0]
    clean_dir()