def furuta_dfo_cost(x): # We need to scale the inputs x down since they are scaled up # versions of the parameters (x = scalefactor*[param1 param2]) armFrictionCoefficient = x[0] / 1e3 pendulumFrictionCoefficient = x[1] / 1e3 model = load_fmu( os.path.join(curr_dir, '..', 'examples', 'files', 'FMUs', 'Furuta.fmu')) # Set new parameter values into the model model.set('armFriction', armFrictionCoefficient) model.set('pendulumFriction', pendulumFrictionCoefficient) # Create options object and set verbosity to zero to disable printouts opts = model.simulate_options() opts['CVode_options']['verbosity'] = 50 # Simulate model response with new parameter values res = model.simulate(start_time=0., final_time=40, options=opts) # Load simulation result phi_sim = res['armJoint.phi'] theta_sim = res['pendulumJoint.phi'] t_sim = res['time'] # Evaluate the objective function y_meas = N.vstack((phi_meas, theta_meas)) y_sim = N.vstack((phi_sim, theta_sim)) obj = dfo.quad_err(t_meas, y_meas, t_sim, y_sim) return obj
def f1(x): model = load_fmu(fmu_name) # We need to scale the inputs x down since they are scaled up # versions of a1 and a2 (x = scalefactor*[a1 a2]) a1 = x[0] / 1e6 a2 = x[1] / 1e6 # Set new values for a1 and a2 into the model model.set('qt.a1', a1) model.set('qt.a2', a2) # Create options object and set verbosity to zero to disable printouts opts = model.simulate_options() opts['CVode_options']['verbosity'] = 0 # Simulate model response with new parameters a1 and a2 res = model.simulate(input=(['u1', 'u2'], u), start_time=0., final_time=60, options=opts) # Load simulation result x1_sim = res['qt.x1'] x2_sim = res['qt.x2'] t_sim = res['time'] # Evaluate the objective function y_meas = N.vstack((y1_meas, y2_meas)) y_sim = N.vstack((x1_sim, x2_sim)) obj = dfo.quad_err(t_meas, y_meas, t_sim, y_sim) return obj
def furuta_dfo_cost(x): # We need to scale the inputs x down since they are scaled up # versions of the parameters (x = scalefactor*[param1 param2]) armFrictionCoefficient = x[0]/1e3 pendulumFrictionCoefficient = x[1]/1e3 model = load_fmu(os.path.join(curr_dir, '..', 'examples', 'files', 'FMUs', 'Furuta.fmu')) # Set new parameter values into the model model.set('armFriction', armFrictionCoefficient) model.set('pendulumFriction', pendulumFrictionCoefficient) # Create options object and set verbosity to zero to disable printouts opts = model.simulate_options() opts['CVode_options']['verbosity'] = 0 # Simulate model response with new parameter values res = model.simulate(start_time=0., final_time=40, options=opts) # Load simulation result phi_sim = res['armJoint.phi'] theta_sim = res['pendulumJoint.phi'] t_sim = res['time'] # Evaluate the objective function y_meas = N.vstack((phi_meas, theta_meas)) y_sim = N.vstack((phi_sim, theta_sim)) obj = dfo.quad_err(t_meas, y_meas, t_sim, y_sim) return obj
def f1(x): model = load_fmu(fmu_name) # We need to scale the inputs x down since they are scaled up # versions of a1 and a2 (x = scalefactor*[a1 a2]) a1 = x[0]/1e6 a2 = x[1]/1e6 # Set new values for a1 and a2 into the model model.set('qt.a1',a1) model.set('qt.a2',a2) # Create options object and set verbosity to zero to disable printouts opts = model.simulate_options() opts['CVode_options']['verbosity'] = 0 # Simulate model response with new parameters a1 and a2 res = model.simulate(input=(['u1','u2'],u),start_time=0.,final_time=60,options=opts) # Load simulation result x1_sim = res['qt.x1'] x2_sim = res['qt.x2'] t_sim = res['time'] # Evaluate the objective function y_meas = N.vstack((y1_meas,y2_meas)) y_sim = N.vstack((x1_sim,x2_sim)) obj = dfo.quad_err(t_meas,y_meas,t_sim,y_sim) return obj
def f2(x): model = load_fmu(fmu_name) # We need to scale the inputs x down since they are scaled up # versions of a1, a2, a3 and a4 (x = scalefactor*[a1 a2 a3 a4]) a1 = x[0] / 1e6 a2 = x[1] / 1e6 a3 = x[2] / 1e6 a4 = x[3] / 1e6 # Set new values for a1, a2, a3 and a4 into the model model.set('qt.a1', a1) model.set('qt.a2', a2) model.set('qt.a3', a3) model.set('qt.a4', a4) # Create options object and set verbosity to zero to disable printouts opts = model.simulate_options() opts['CVode_options']['verbosity'] = 0 # Simulate model response with the new parameters res = model.simulate(input=(['u1', 'u2'], u), start_time=0., final_time=60, options=opts) # Load simulation result x1_sim = res['qt.x1'] x2_sim = res['qt.x2'] x3_sim = res['qt.x3'] x4_sim = res['qt.x4'] t_sim = res['time'] # Evaluate the objective function y_meas = [y1_meas, y2_meas, y3_meas, y4_meas] y_sim = [x1_sim, x2_sim, x3_sim, x4_sim] obj = dfo.quad_err(t_meas, y_meas, t_sim, y_sim) return obj
def f2(x): model = load_fmu(fmu_name) # We need to scale the inputs x down since they are scaled up # versions of a1, a2, a3 and a4 (x = scalefactor*[a1 a2 a3 a4]) a1 = x[0]/1e6 a2 = x[1]/1e6 a3 = x[2]/1e6 a4 = x[3]/1e6 # Set new values for a1, a2, a3 and a4 into the model model.set('qt.a1',a1) model.set('qt.a2',a2) model.set('qt.a3',a3) model.set('qt.a4',a4) # Create options object and set verbosity to zero to disable printouts opts = model.simulate_options() opts['CVode_options']['verbosity'] = 0 # Simulate model response with the new parameters res = model.simulate(input=(['u1','u2'],u),start_time=0.,final_time=60,options=opts) # Load simulation result x1_sim = res['qt.x1'] x2_sim = res['qt.x2'] x3_sim = res['qt.x3'] x4_sim = res['qt.x4'] t_sim = res['time'] # Evaluate the objective function y_meas = [y1_meas,y2_meas,y3_meas,y4_meas] y_sim = [x1_sim,x2_sim,x3_sim,x4_sim] obj = dfo.quad_err(t_meas,y_meas,t_sim,y_sim) return obj