# Try the old Jmodelica syntax jmu_name = compile_jmu("VDP_pack.VDP_Opt", curr_dir + "/VDP.mop", 'optimica', 'ipopt', { 'generate_xml_equations': True, 'generate_fmi_xml': False }) except jmodelica.compiler.UnknownOptionError: # Try the new jmodelica syntax jmu_name = compile_jmu("VDP_pack.VDP_Opt", curr_dir + "/VDP.mop", 'optimica', 'ipopt', { 'generate_xml_equations': True, 'generate_fmi_me_xml': False }) if True: vdp = JMUModel(jmu_name) res = vdp.optimize() # Extract variable profiles x1 = res['x1'] x2 = res['x2'] u = res['u'] t = res['time'] cost = res['cost'] # Plot plt.figure(1) plt.clf() plt.subplot(311) plt.plot(t, x1) plt.grid()
"optimica", "ipopt", {"generate_xml_equations": True, "generate_fmi_xml": False}, ) except jmodelica.compiler.UnknownOptionError: # Try the new jmodelica syntax jmu_name = compile_jmu( "VDP_pack.VDP_Opt", curr_dir + "/VDP.mop", "optimica", "ipopt", {"generate_xml_equations": True, "generate_fmi_me_xml": False}, ) if True: vdp = JMUModel(jmu_name) res = vdp.optimize() # Extract variable profiles x1 = res["x1"] x2 = res["x2"] u = res["u"] t = res["time"] cost = res["cost"] # Plot plt.figure(1) plt.clf() plt.subplot(311) plt.plot(t, x1) plt.grid()
# Import library for path manipulations import os.path # Import numerical libraries import numpy as N from pylab import * # Import the JModelica.org Python packages from jmodelica.jmi import compile_jmu from jmodelica.jmi import JMUModel jmu_name = compile_jmu("opt","ocp.mop") # Load the dynamic library and XML data dyn = JMUModel(jmu_name) dyn.initialize() opts = dyn.optimize_options() opts['n_e'] = 5 # number of elements opts['n_cp'] = 3 # number of collocation points opts['result_mode']='default' opts['IPOPT_options']['max_iter']=100 opt = dyn.optimize(options=opts) t=opt['time'] print t[-1]
# Import library for path manipulations import os.path # Import numerical libraries import numpy as N from pylab import * # Import the JModelica.org Python packages from jmodelica.jmi import compile_jmu from jmodelica.jmi import JMUModel jmu_name = compile_jmu("opt", "ocp.mop") # Load the dynamic library and XML data dyn = JMUModel(jmu_name) dyn.initialize() opts = dyn.optimize_options() opts['n_e'] = 5 # number of elements opts['n_cp'] = 3 # number of collocation points opts['result_mode'] = 'default' opts['IPOPT_options']['max_iter'] = 100 opt = dyn.optimize(options=opts) t = opt['time'] print t[-1] plot(t, opt['sim.y'])