コード例 #1
0
ファイル: thermostat.py プロジェクト: dchassin/gridlabd
 def __init__(self, obj):  # this links the thermostat to the house
     self.Tair = gridlabd.property(obj, "air_temperature")
     self.Theat = gridlabd.property(obj, "heating_setpoint")
     self.Tcool = gridlabd.property(obj, "cooling_setpoint")
     self.mode = gridlabd.property(obj, "system_mode")
     self.deadband = gridlabd.property(obj,
                                       "thermostat_deadband").get_value()
コード例 #2
0
def add_property(objname,
                 propname,
                 nonzero=True,
                 noexception=True,
                 onexception=gridlabd.warning):
    """Add a property to the list of properties to consider

    Parameters:
        objname (str): name of object
        propname (str): name of property
        nonzero (bool): flag to restrict addition to properties that have a non-zero base value
        noexception (bool): flag to not raise exception and use `onexception()` instead
        onexception (callable): function to call when noexception is used and add fails
    """
    global property_list

    try:
        # get the property
        prop = gridlabd.property(objname, propname)

        # get the value of the property
        value = prop.get_value()

        # if the value should be added
        if not nonzero or value != 0.0:

            # if the object is not already listed
            if not objname in property_list.keys():

                # create a new entry for the value in the property list
                property_list[objname] = {propname: [prop, value]}

                # create a new entry for the result in the limit list
                limit_list[objname] = {}

            # the object is already list
            else:

                # add the property to the object's property list
                property_list[objname][propname] = [prop, value]
    except:

        # if no exceptions are allowed
        if noexception:

            # call the output function
            onexception(f"unable to add to {objname}.{propname}")

            # continue without further ado
            pass
        else:

            # raise the exception
            raise
コード例 #3
0
def on_term(t):
    last = None
    for obj in gridlabd.get("objects"):
        oclass = gridlabd.get_value(obj, "class")
        prop = gridlabd.property(obj, "py_object")
        if oclass == "test":
            prop = gridlabd.property(obj, "py_object")
        elif oclass == "check":
            prop = gridlabd.property(obj, obj)
        else:
            continue
        prop.rlock()
        value = prop.get_value()
        initv = prop.get_initial()
        text = str(prop)
        info = repr(prop)
        unit = prop.get_unit()
        prop.unlock()
        if obj in test.keys():
            value = test[obj]
            prop.wlock()
            if type(value) is dict:
                goal = value
                check = value
                init = True
            elif type(test[obj]) is list:
                goal = value[0]
                check = value[1]
                init = False
            else:
                goal = value
                check = value
                init = False
            prop.set_value(goal)
            if init:
                result = prop.get_initial()
            else:
                result = prop.get_value()
            if obj in convert.keys():
                check = convert[obj](check)
            if result != check:
                raise Exception(f"set failed ('{result}' != '{check}')")
            prop.unlock()

            for u, v in units.items():
                if prop.get_name() == u:
                    x = prop.convert_unit(v[1])
                    if x != v[0]:
                        raise Exception(
                            f"unit conversion failed ({x} != {u[0]}")
        if prop == last:
            raise Exception("property eq comparison failed unexpectedly")
        if prop != prop:
            raise Exception("property ne comparison failed unexpectedly")
        ok = None
        try:
            prop < last
            prop > last
            prop <= last
            prop >= last
            ok = False
        except:
            ok = True
            pass
        if ok == None:
            raise Exception("property lt/le/gt/ge test inconclusive")
        elif ok == False:
            raise Exception("property lt/le/gt/ge succeeded unexpectedly")
        last = prop
コード例 #4
0
def on_init(t):
    global prop
    prop = gridlabd.property('my_example', 'my_real')
    return True