def main():
    
    # Assign an existing FMU to the model
    filePath = "../../../modelica/FmuExamples/Resources/FMUs/Pump_MBL3.fmu"
    
    # Initialize the FMU model empty
    m = Model.Model(filePath, atol=1e-4, rtol=1e-3)
    
    # Path of the csv file containing the data series
    #csvPath = "../../../modelica/FmuExamples/Resources/data/DataPumpVeryShort.csv"
    #csvPath = "../../../modelica/FmuExamples/Resources/data/DataPump_16to19_Oct2012.csv"
    csvPath = "../../../modelica/FmuExamples/Resources/data/DataPump_16to19_Oct2012_variableStep.csv"
    
    # Set the CSV file associated to the input, and its covariance
    input = m.GetInputByName("Nrpm")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("Pump.Speed")
    
    
    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("P_el")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("Pump.kW")
    output.SetMeasuredOutput()
    output.SetCovariance(0.15)
    
    """
    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("V_flow")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("Pump.gpm")
    output.SetMeasuredOutput()
    output.SetCovariance(50.0)
    """
    p_start = [0.30000000, 0.40000000, 0.60000000, 0.8] # 0
    #p_start = [0.20000000, 0.40000000, 0.60000000, 0.8] # 0
    #p_start = [0.28538255, 0.50017618, 0.71668581, 1.] # 7
    #p_start = [0.21517598, 0.50276898, 0.79260251, 1.] # 25
    #p_start = [0.19080228, 0.50549745, 0.81889495, 1.] # 35
    #p_start = [0.11824324, 0.5869894,  0.8849001,  1.]
    #p_start = [0.11574544, 0.67699191, 0.8862938, 1.]
    
    cov = 0.1
    
    #################################################################
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[1]"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[0]
    par.SetInitialValue(p_start[0])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[2]"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[1]
    par.SetInitialValue(p_start[1])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[3]"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[2]
    par.SetInitialValue(p_start[2])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[4]"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[3]
    par.SetInitialValue(p_start[3])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    # Initialize the model for the simulation
    m.InitializeSimulator()
    
    # instantiate the UKF for the FMU
    ukf_FMU = ukfFMU(m, augmented = False)
    ukf_FMU.setUKFparams()
    
    pars = ukf_FMU.ParameterEstimation(maxIter = 500)
    print(pars)
    
    ShowResults(pars)
示例#2
0
def main():
    
    # Assign an existing FMU to the model
    filePath = "../../../modelica/FmuExamples/Resources/FMUs/Pump_MBL3.fmu"
    
    # Initialize the FMU model empty
    m = Model.Model(filePath, atol=1e-4, rtol=1e-3)
    
    # Path of the csv file containing the data series
    #csvPath = "../../../modelica/FmuExamples/Resources/data/DataPumpVeryShort.csv"
    #csvPath = "../../../modelica/FmuExamples/Resources/data/DataPump_16to19_Oct2012.csv"
    csvPath = "../../../modelica/FmuExamples/Resources/data/DataPump_16to19_Oct2012_variableStep.csv"
    
    # Set the CSV file associated to the input, and its covariance
    input = m.GetInputByName("Nrpm")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("Pump.Speed")
    
    
    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("P_el")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("Pump.kW")
    output.SetMeasuredOutput()
    output.SetCovariance(0.15)
    
    """
    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("V_flow")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("Pump.gpm")
    output.SetMeasuredOutput()
    output.SetCovariance(50.0)
    """
    
    #################################################################
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[1]"))
    
    ppp = [0.3, 0.5, 0.7, 0.9]
    ppp = [0.2970953,  0.50003122, 0.70334771, 0.94678875]
    ppp = [0.294192,   0.50006441, 0.7066786,  0.97122915]
    ppp = [0.29129089, 0.5000997,  0.70999068, 0.98621258]
    ppp = [0.28839297, 0.50013721, 0.71328358, 0.99633567]
    ppp = [0.28549929, 0.50017709, 0.71655701, 1.        ]
    ppp = [0.28261104, 0.50021948, 0.71981114, 1.        ]
    ppp = [0.27972849, 0.50026454, 0.72306009, 1.        ]
    ppp = [0.27683613, 0.50031244, 0.72630686, 1.        ]
    ppp = [0.27393511, 0.50036335, 0.72955037, 1.        ]
    ppp = [0.106,  0.50041746, 0.9, 1.        ]
    ppp = [0.28538255, 0.50017618, 0.71668581, 1.]
    
    cov = 0.005
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[0]
    par.SetInitialValue(ppp[0])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[2]"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[1]
    par.SetInitialValue(ppp[1])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[3]"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[2]
    par.SetInitialValue(ppp[2])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[4]"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[3]
    par.SetInitialValue(ppp[3])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    # Initialize the model for the simulation
    m.InitializeSimulator()
    
    # instantiate the UKF for the FMU
    ukf_FMU = ukfFMU(m, augmented = False)
    ukf_FMU.setUKFparams()
    
    # start filter
    time, x, sqrtP, y, Sy, y_full, Xsmooth, Ssmooth, Yfull_smooth = ukf_FMU.filterAndSmooth(0.0, 5.0, verbose=False)
    
    # Get the measured outputs
    showResults(time, x, sqrtP, y, Sy, y_full, Xsmooth, Ssmooth, Yfull_smooth, csvPath)
示例#3
0
def main():
    # Assign an existing FMU to the model, depending on the platform identified
    dir_path = os.path.dirname(__file__)
    if platform.architecture()[0] == "32bit":
        print "32-bit architecture"
        filePath = os.path.join(dir_path, "..", "..", "..", "modelica",
                                "FmuExamples", "Resources", "FMUs",
                                "ChillerFDD.fmu")
    else:
        print "64-bit architecture"
        filePath = os.path.join(dir_path, "..", "..", "..", "modelica",
                                "FmuExamples", "Resources", "FMUs",
                                "ChillerFDD_64bit.fmu")

    # Initialize the FMU model empty
    m = Model.Model(filePath)

    # Description of the model
    print m

    # Show the inputs
    print "The names of the FMU inputs are: ", m.GetInputNames(), "\n"

    # Show the outputs
    print "The names of the FMU outputs are:", m.GetOutputNames(), "\n"

    # Path of the csv file containing the data series
    #csvPath = os.path.join(dir_path, "ChillerResults7.csv")
    #csvPath = os.path.join(dir_path, "ChillerResults1_noisyLow.csv")
    #csvPath = os.path.join(dir_path, "ChillerResults1_noisyHigh.csv")
    #csvPath = os.path.join(dir_path, "ChillerResults7_noisyLow.csv")
    #csvPath = os.path.join(dir_path, "ChillerResults7_noisyHigh.csv")
    csvPath = os.path.join(dir_path, "ChillerResults7_noisyHigh.csv")

    input = m.GetInputByName("m_flow_CW")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("m_flow_CW")

    input = m.GetInputByName("m_flow_CH")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("m_flow_CH")

    input = m.GetInputByName("T_CW_in")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("T_CW_in")

    input = m.GetInputByName("T_CH_in")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("T_CH_in")

    input = m.GetInputByName("Pin")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("P")

    # Set the CSV file associated to the output, and its covariance

    output = m.GetOutputByName("T_CH_Lea")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("T_CH_Lea")
    output.SetMeasuredOutput()
    output.SetCovariance(0.5)

    output = m.GetOutputByName("T_CW_lea")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("T_CW_lea")
    output.SetMeasuredOutput()
    output.SetCovariance(0.5)

    # Select the states to be identified, and add it to the list
    m.AddVariable(m.GetVariableObject("chi.vol1.dynBal.medium.T"))
    m.AddVariable(m.GetVariableObject("chi.vol2.dynBal.medium.T"))

    # Set initial value of state, and its covariance and the limits (if any)
    var = m.GetVariables()[0]
    var.SetInitialValue(300)
    var.SetCovariance(0.5)
    var.SetMinValue(273.15)
    var.SetConstraintLow(True)

    var = m.GetVariables()[1]
    var.SetInitialValue(279)
    var.SetCovariance(0.5)
    var.SetMinValue(273.15)
    var.SetConstraintLow(True)

    # Select the states to be identified, and add it to the list
    m.AddParameter(m.GetVariableObject("eta_PL"))

    # Set initial value of state, and its covariance and the limits (if any)
    par = m.GetParameters()[0]
    par.SetInitialValue(0.5)
    par.SetCovariance(0.02)
    par.SetMinValue(0.0)
    par.SetMaxValue(1.2)
    par.SetConstraintLow(True)
    par.SetConstraintHigh(True)

    # Initialize the model for the simulation
    m.InitializeSimulator()

    # Allow to identify eta PL externally
    #m.SetReal(m.GetVariableObject("chi.external_etaPL"), True)
    #m.SetReal(m.GetVariableObject("chi.external_COP"), False)

    # Change the nominal power of the compressor
    m.SetReal(m.GetVariableObject("P_nominal"), 1500e3)

    # Instantiate the UKF for the FMU
    ukf_FMU = ukfFMU(m, augmented=False)

    # Start filter
    t0 = pd.to_datetime(0.0, unit="s")
    t1 = pd.to_datetime(3600.0 * 12, unit="s")
    time, x, sqrtP, y, Sy, y_full = ukf_FMU.filter(start=t0,
                                                   stop=t1,
                                                   verbose=False)

    # Get the measured outputs
    showResults(time, x, sqrtP, y, Sy, y_full, csvPath, m)
示例#4
0
def main():

    # Assign an existing FMU to the model
    filePath = "../../../modelica/FmuExamples/Resources/FMUs/Pump_MBL3.fmu"

    # Initialize the FMU model empty
    m = Model.Model(filePath, atol=1e-4, rtol=1e-3)

    # Path of the csv file containing the data series
    #csvPath = "../../../modelica/FmuExamples/Resources/data/DataPumpVeryShort.csv"
    #csvPath = "../../../modelica/FmuExamples/Resources/data/DataPump_16to19_Oct2012.csv"
    csvPath = "../../../modelica/FmuExamples/Resources/data/DataPump_16to19_Oct2012_variableStep.csv"

    # Set the CSV file associated to the input, and its covariance
    input = m.GetInputByName("Nrpm")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("Pump.Speed")

    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("P_el")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("Pump.kW")
    output.SetMeasuredOutput()
    output.SetCovariance(0.15)
    """
    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("V_flow")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("Pump.gpm")
    output.SetMeasuredOutput()
    output.SetCovariance(50.0)
    """

    #################################################################
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[1]"))

    ppp = [0.3, 0.5, 0.7, 0.9]
    ppp = [0.2970953, 0.50003122, 0.70334771, 0.94678875]
    ppp = [0.294192, 0.50006441, 0.7066786, 0.97122915]
    ppp = [0.29129089, 0.5000997, 0.70999068, 0.98621258]
    ppp = [0.28839297, 0.50013721, 0.71328358, 0.99633567]
    ppp = [0.28549929, 0.50017709, 0.71655701, 1.]
    ppp = [0.28261104, 0.50021948, 0.71981114, 1.]
    ppp = [0.27972849, 0.50026454, 0.72306009, 1.]
    ppp = [0.27683613, 0.50031244, 0.72630686, 1.]
    ppp = [0.27393511, 0.50036335, 0.72955037, 1.]
    ppp = [0.106, 0.50041746, 0.9, 1.]
    ppp = [0.28538255, 0.50017618, 0.71668581, 1.]

    cov = 0.005
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[0]
    par.SetInitialValue(ppp[0])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)

    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[2]"))

    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[1]
    par.SetInitialValue(ppp[1])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)

    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[3]"))

    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[2]
    par.SetInitialValue(ppp[2])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)

    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[4]"))

    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[3]
    par.SetInitialValue(ppp[3])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)

    # Initialize the model for the simulation
    m.InitializeSimulator()

    # instantiate the UKF for the FMU
    ukf_FMU = ukfFMU(m, augmented=False)
    ukf_FMU.setUKFparams()

    # start filter
    time, x, sqrtP, y, Sy, y_full, Xsmooth, Ssmooth, Yfull_smooth = ukf_FMU.filterAndSmooth(
        0.0, 5.0, verbose=False)

    # Get the measured outputs
    showResults(time, x, sqrtP, y, Sy, y_full, Xsmooth, Ssmooth, Yfull_smooth,
                csvPath)
示例#5
0
def main():

    # Assign an existing FMU to the model
    filePath = "../../../modelica/FmuExamples/Resources/FMUs/HeatExchanger.fmu"

    # Initialize the FMU model empty
    m = Model.Model(filePath, atol=1e-5, rtol=1e-6)

    # Path of the csv file containing the data series
    csvPath = "../../../modelica/FmuExamples/Resources/data/NoisySimulationData_HeatExchanger.csv"

    ###################################################################
    # Set the CSV file associated to the input, and its covariance
    input = m.GetInputByName("mFlow_cold")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("heatExchanger.mFlow_COLD")
    input.SetCovariance(2.0)

    # Set the CSV file associated to the input, and its covariance
    input = m.GetInputByName("mFlow_hot")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("heatExchanger.mFlow_HOT")
    input.SetCovariance(2.0)

    # Set the CSV file associated to the input, and its covariance
    input = m.GetInputByName("T_hot")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("heatExchanger.Thot_IN")
    input.SetCovariance(1.0)

    # Set the CSV file associated to the input, and its covariance
    input = m.GetInputByName("T_cold")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("heatExchanger.Tcold_IN")
    input.SetCovariance(1.0)

    #################################################################
    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("Tcold_OUT")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("heatExchanger.Tcold_OUT")
    output.SetMeasuredOutput()
    output.SetCovariance(1.0)

    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("Thot_OUT")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("heatExchanger.Thot_OUT")
    output.SetMeasuredOutput()
    output.SetCovariance(1.0)

    #################################################################
    # Select the states to be estimated
    m.AddVariable(m.GetVariableObject("metal.T"))

    # Set initial value of state, and its covariance and the limits (if any)
    var = m.GetVariables()[0]
    var.SetInitialValue(310.15)
    var.SetCovariance(1.5)
    var.SetMinValue(273.15)
    var.SetConstraintLow(True)

    # show the info about the variable to be estimated
    print var.Info()

    #################################################################
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("G_hot"))

    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[0]
    par.SetInitialValue(1000.0)
    par.SetCovariance(50.0)
    par.SetMinValue(50.0)
    par.SetConstraintLow(True)

    # show the info about the parameter to be identified
    print par.Info()

    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("G_cold"))

    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[1]
    par.SetInitialValue(1000.0)
    par.SetCovariance(50.0)
    par.SetMinValue(50.0)
    par.SetConstraintLow(True)

    # show the info about the parameter to be identified
    print par.Info()

    #################################################################
    # Initialize the model for the simulation
    #print "Before initialization: ", m.GetState()
    #print "State observed:",m.GetStateObservedValues()
    #print "Parameters estimated:",m.GetParametersValues()
    m.InitializeSimulator()
    print "After initialization: ", m.GetState()
    print "State observed:", m.GetStateObservedValues()
    print "Parameters estimated:", m.GetParametersValues()

    #################################################################
    # instantiate the UKF for the FMU
    ukf_FMU = ukfFMU(m, augmented=False)

    # Show details
    print ukf_FMU

    # start filter
    time, x, sqrtP, y, Sy, y_full = ukf_FMU.filter(0.0, 5.0)

    # Path of the csv file containing the True data series
    csvTrue = "../../../modelica/FmuExamples/Resources/data/SimulationData_HeatExchanger.csv"

    # Get the measured outputs
    showResults(time, x, sqrtP, y, Sy, y_full, csvTrue)
示例#6
0
def main():
    
    # Assign an existing FMU to the model
    filePath = "../../../modelica/FmuExamples/Resources/FMUs/HeatExchanger.fmu"
    
    # Initialize the FMU model empty
    m = Model.Model(filePath, atol=1e-5, rtol=1e-6)
    
    # Path of the csv file containing the data series
    csvPath = "../../../modelica/FmuExamples/Resources/data/NoisySimulationData_HeatExchanger.csv"
    
    ###################################################################
    # Set the CSV file associated to the input, and its covariance
    input = m.GetInputByName("mFlow_cold")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("heatExchanger.mFlow_COLD")
    input.SetCovariance(2.0)
    
    # Set the CSV file associated to the input, and its covariance 
    input = m.GetInputByName("mFlow_hot")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("heatExchanger.mFlow_HOT")
    input.SetCovariance(2.0)
    
    # Set the CSV file associated to the input, and its covariance  
    input = m.GetInputByName("T_hot")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("heatExchanger.Thot_IN")
    input.SetCovariance(1.0)
    
    # Set the CSV file associated to the input, and its covariance    
    input = m.GetInputByName("T_cold")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("heatExchanger.Tcold_IN")
    input.SetCovariance(1.0)
    
    #################################################################
    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("Tcold_OUT")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("heatExchanger.Tcold_OUT")
    output.SetMeasuredOutput()
    output.SetCovariance(1.0)
    
    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("Thot_OUT")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("heatExchanger.Thot_OUT")
    output.SetMeasuredOutput()
    output.SetCovariance(1.0)
    
    #################################################################
    # Select the states to be estimated
    m.AddVariable(m.GetVariableObject("metal.T"))
    
    # Set initial value of state, and its covariance and the limits (if any)
    var = m.GetVariables()[0]
    var.SetInitialValue(310.15)
    var.SetCovariance(1.5)
    var.SetMinValue(273.15)
    var.SetConstraintLow(True)
    
    # show the info about the variable to be estimated
    print var.Info()
    
    #################################################################
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("G_hot"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[0]
    par.SetInitialValue(1000.0)
    par.SetCovariance(50.0)
    par.SetMinValue(50.0)
    par.SetConstraintLow(True)
    
    # show the info about the parameter to be identified
    print par.Info()
    
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("G_cold"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[1]
    par.SetInitialValue(1000.0)
    par.SetCovariance(50.0)
    par.SetMinValue(50.0)
    par.SetConstraintLow(True)
    
    # show the info about the parameter to be identified
    print par.Info()
    
    #################################################################
    # Initialize the model for the simulation
    #print "Before initialization: ", m.GetState()
    #print "State observed:",m.GetStateObservedValues()
    #print "Parameters estimated:",m.GetParametersValues()
    m.InitializeSimulator()
    print "After initialization: ", m.GetState()
    print "State observed:",m.GetStateObservedValues()
    print "Parameters estimated:",m.GetParametersValues()
    
    #################################################################
    # instantiate the UKF for the FMU
    ukf_FMU = ukfFMU(m, augmented = False)
    
    # Show details
    print ukf_FMU
    
    # start filter
    time, x, sqrtP, y, Sy, y_full  = ukf_FMU.filter(0.0, 5.0)
    
    # Path of the csv file containing the True data series
    csvTrue = "../../../modelica/FmuExamples/Resources/data/SimulationData_HeatExchanger.csv"
    
    # Get the measured outputs
    showResults(time, x, sqrtP, y, Sy, y_full, csvTrue)
def main():
    
    # Assign an existing FMU to the model
    filePath = "../../../modelica/FmuExamples/Resources/FMUs/Pump_MBL3.fmu"
    
    # Initialize the FMU model empty
    m = Model.Model(filePath, atol=1e-4, rtol=1e-3)
    
    # Path of the csv file containing the data series
    #csvPath = "../../../modelica/FmuExamples/Resources/data/DataPumpVeryShort.csv"
    #csvPath = "../../../modelica/FmuExamples/Resources/data/DataPump_16to19_Oct2012.csv"
    csvPath = "../../../modelica/FmuExamples/Resources/data/DataPump_16to19_Oct2012_variableStep.csv"
    
    # Set the CSV file associated to the input, and its covariance
    input = m.GetInputByName("Nrpm")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("Pump.Speed")
    
    
    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("P_el")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("Pump.kW")
    output.SetMeasuredOutput()
    output.SetCovariance(0.15)
    
    """
    # Set the CSV file associated to the output, and its covariance
    output = m.GetOutputByName("V_flow")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("Pump.gpm")
    output.SetMeasuredOutput()
    output.SetCovariance(50.0)
    """
    p_start = [0.30000000, 0.40000000, 0.60000000, 0.8] # 0
    #p_start = [0.20000000, 0.40000000, 0.60000000, 0.8] # 0
    #p_start = [0.28538255, 0.50017618, 0.71668581, 1.] # 7
    #p_start = [0.21517598, 0.50276898, 0.79260251, 1.] # 25
    #p_start = [0.19080228, 0.50549745, 0.81889495, 1.] # 35
    #p_start = [0.11824324, 0.5869894,  0.8849001,  1.]
    #p_start = [0.11574544, 0.67699191, 0.8862938, 1.]
    
    cov = 0.1
    
    #################################################################
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[1]"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[0]
    par.SetInitialValue(p_start[0])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[2]"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[1]
    par.SetInitialValue(p_start[1])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[3]"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[2]
    par.SetInitialValue(p_start[2])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    # Select the parameter to be identified
    m.AddParameter(m.GetVariableObject("pump.power.P[4]"))
    
    # Set initial value of parameter, and its covariance and the limits (if any)
    par = m.GetParameters()[3]
    par.SetInitialValue(p_start[3])
    par.SetCovariance(cov)
    par.SetMinValue(0.0)
    par.SetConstraintLow(True)
    par.SetMaxValue(1.0)
    par.SetConstraintHigh(True)
    
    # Initialize the model for the simulation
    m.InitializeSimulator()
    
    # instantiate the UKF for the FMU
    ukf_FMU = ukfFMU(m, augmented = False)
    ukf_FMU.setUKFparams()
    
    pars = ukf_FMU.ParameterEstimation(maxIter = 500)
    print pars
    
    ShowResults(pars)
示例#8
0
def main():
    
    # Assign an existing FMU to the model, depending on the platform identified
    dir_path = os.path.dirname(__file__)
    if platform.architecture()[0]=="32bit":
        print "32-bit architecture"
        filePath = os.path.join(dir_path, "..", "..","..", "modelica", "FmuExamples", "Resources", "FMUs", "ChillerFDD.fmu")
    else:
        print "64-bit architecture"
        filePath = os.path.join(dir_path, "..", "..","..", "modelica", "FmuExamples", "Resources", "FMUs", "ChillerFDD_cop_64bit.fmu")
    
    # Initialize the FMU model empty
    m = Model.Model(filePath)
    
    # Description of the model
    print m
    
    # Show the inputs
    print "The names of the FMU inputs are: ", m.GetInputNames(), "\n"
    
    # Show the outputs
    print "The names of the FMU outputs are:", m.GetOutputNames(), "\n"
    
    # Path of the csv file containing the data series
    #csvPath = os.path.join(dir_path, "ChillerResults7.csv")
    #csvPath = os.path.join(dir_path, "ChillerResults1_noisyLow.csv")
    #csvPath = os.path.join(dir_path, "ChillerResults1_noisyHigh.csv")
    #csvPath = os.path.join(dir_path, "ChillerResults7_noisyLow.csv")
    #csvPath = os.path.join(dir_path, "ChillerResults7_noisyHigh.csv")
    csvPath = os.path.join(dir_path, "ChillerResults7_noisyHigh.csv")
       
    input = m.GetInputByName("m_flow_CW")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("m_flow_CW")
    
    input = m.GetInputByName("m_flow_CH")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("m_flow_CH")
    
    input = m.GetInputByName("T_CW_in")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("T_CW_in")
    
    input = m.GetInputByName("T_CH_in")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("T_CH_in")
    
    input = m.GetInputByName("Pin")
    input.GetCsvReader().OpenCSV(csvPath)
    input.GetCsvReader().SetSelectedColumn("P")
    
    # Set the CSV file associated to the output, and its covariance
    
    output = m.GetOutputByName("T_CH_Lea")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("T_CH_Lea")
    output.SetMeasuredOutput()
    output.SetCovariance(0.5)
    
    output = m.GetOutputByName("T_CW_lea")
    output.GetCsvReader().OpenCSV(csvPath)
    output.GetCsvReader().SetSelectedColumn("T_CW_lea")
    output.SetMeasuredOutput()
    output.SetCovariance(0.5)
    
    # Select the states to be identified, and add it to the list
    m.AddVariable(m.GetVariableObject("chi.vol1.dynBal.medium.T"))
    m.AddVariable(m.GetVariableObject("chi.vol2.dynBal.medium.T"))
    
    # Set initial value of state, and its covariance and the limits (if any)
    var = m.GetVariables()[0]
    var.SetInitialValue(300)
    var.SetCovariance(0.5)
    var.SetMinValue(273.15)
    var.SetConstraintLow(True)
    
    var = m.GetVariables()[1]
    var.SetInitialValue(279)
    var.SetCovariance(0.5)
    var.SetMinValue(273.15)
    var.SetConstraintLow(True)
    
    # Select the states to be identified, and add it to the list
    m.AddParameter(m.GetVariableObject("ext_COP"))
    
    # Set initial value of state, and its covariance and the limits (if any)
    par = m.GetParameters()[0]
    par.SetInitialValue(2)
    par.SetCovariance(0.1)
    par.SetMinValue(0.5)
    par.SetMaxValue(10.0)
    par.SetConstraintLow(True)
    par.SetConstraintHigh(True)
    
    # Allow to identify eta PL externally
    m.SetReal(m.GetVariableObject("chi.external_etaPL"), False)
    m.SetReal(m.GetVariableObject("chi.external_COP"), True)
    
    # Initialize the model for the simulation
    m.InitializeSimulator()
    
    # Change the nominal power of the compressor
    m.SetReal(m.GetVariableObject("P_nominal"), 1500e3)
    
    # instantiate the UKF for the FMU
    ukf_FMU = ukfFMU(m, augmented = False)
    
    # Start filter
    t0 = pd.to_datetime(0.0, unit = "s")
    t1 = pd.to_datetime(3600.0*12, unit = "s")
    time, x, sqrtP, y, Sy, y_full = ukf_FMU.filter(start = t0, stop = t1, verbose=False)
    
    # Get the measured outputs
    showResults(time, x, sqrtP, y, Sy, y_full, csvPath, m)