import matplotlib.pyplot as plt import scipy.integrate as integr # JModelica from jmodelica.jmi import compile_jmu from jmodelica.jmi import JMUModel import jmodelica # CasADi from casadi import * curr_dir = os.path.dirname(os.path.abspath(__file__)) try: # Try the old Jmodelica syntax jmu_name = compile_jmu("QuadTank_pack.QuadTank_Opt", curr_dir+"/QuadTank.mop",'optimica','ipopt',{'generate_xml_equations':True, 'generate_fmi_xml':True}) except jmodelica.compiler.UnknownOptionError: # Try the new jmodelica syntax jmu_name = compile_jmu("QuadTank_pack.QuadTank_Opt", curr_dir+"/QuadTank.mop",'optimica','ipopt',{'generate_xml_equations':True, 'generate_fmi_me_xml':True}) import zipfile sfile = zipfile.ZipFile(curr_dir+'/QuadTank_pack_QuadTank_Opt.jmu','r') mfile = sfile.extract('modelDescription.xml','.') # Allocate a parser and load the xml parser = FMIParser('modelDescription.xml') # Dump representation to screen print "XML representation" print parser
""" # 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)
import zipfile # JModelica from jmodelica.jmi import compile_jmu from jmodelica.jmi import JMUModel import jmodelica # CasADi from casadi import * curr_dir = os.path.dirname(os.path.abspath(__file__)) try: # 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
import zipfile import time # JModelica from jmodelica.jmi import compile_jmu from jmodelica.jmi import JMUModel import jmodelica # CasADi from casadi import * curr_dir = os.path.dirname(os.path.abspath(__file__)) try: # Try the old Jmodelica syntax jmu_name = compile_jmu("CSTR.CSTR_Opt", curr_dir+"/CSTR.mop",'optimica','ipopt',{'generate_xml_equations':True, 'generate_fmi_xml':False}) except jmodelica.compiler.UnknownOptionError: # Try the new jmodelica syntax jmu_name = compile_jmu("CSTR.CSTR_Opt", curr_dir+"/CSTR.mop",'optimica','ipopt',{'generate_xml_equations':True, 'generate_fmi_me_xml':False}) Tc_ref = 280 c_ref = 338.775766 T_ref = 280.099198 c_init = 956.271065 T_init = 250.051971 sfile = zipfile.ZipFile(curr_dir+'/CSTR_CSTR_Opt.jmu','r') mfile = sfile.extract('modelDescription.xml','.') # Allocate a parser and load the xml
# JModelica from jmodelica.jmi import compile_jmu from jmodelica.jmi import JMUModel import jmodelica # CasADi from casadi import * curr_dir = os.path.dirname(os.path.abspath(__file__)) try: # 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)
# JModelica from jmodelica.jmi import compile_jmu from jmodelica.jmi import JMUModel import jmodelica # CasADi from casadi import * curr_dir = os.path.dirname(os.path.abspath(__file__)) try: # Try the old Jmodelica syntax jmu_name = compile_jmu("QuadTank_pack.QuadTank_Opt", curr_dir + "/QuadTank.mop", 'optimica', 'ipopt', { 'generate_xml_equations': True, 'generate_fmi_xml': True }) except jmodelica.compiler.UnknownOptionError: # Try the new jmodelica syntax jmu_name = compile_jmu("QuadTank_pack.QuadTank_Opt", curr_dir + "/QuadTank.mop", 'optimica', 'ipopt', { 'generate_xml_equations': True, 'generate_fmi_me_xml': True }) import zipfile sfile = zipfile.ZipFile(curr_dir + '/QuadTank_pack_QuadTank_Opt.jmu', 'r') mfile = sfile.extract('modelDescription.xml', '.') # Allocate a parser and load the xml
import numpy as NP import matplotlib.pyplot as plt import zipfile # JModelica from jmodelica.jmi import compile_jmu from jmodelica.jmi import JMUModel import jmodelica # CasADi from casadi import * curr_dir = os.path.dirname(os.path.abspath(__file__)); try: # 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']
Why oh-why does this not work? TypeError: 'list' object is not callable """ # 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']
# JModelica from jmodelica.jmi import compile_jmu from jmodelica.jmi import JMUModel import jmodelica # CasADi from casadi import * curr_dir = os.path.dirname(os.path.abspath(__file__)) try: # Try the old Jmodelica syntax jmu_name = compile_jmu("CSTR.CSTR_Opt", curr_dir + "/CSTR.mop", 'optimica', 'ipopt', { 'generate_xml_equations': True, 'generate_fmi_xml': False }) except jmodelica.compiler.UnknownOptionError: # Try the new jmodelica syntax jmu_name = compile_jmu("CSTR.CSTR_Opt", curr_dir + "/CSTR.mop", 'optimica', 'ipopt', { 'generate_xml_equations': True, 'generate_fmi_me_xml': False }) Tc_ref = 280 c_ref = 338.775766 T_ref = 280.099198 c_init = 956.271065
# JModelica from jmodelica.jmi import compile_jmu from jmodelica.jmi import JMUModel import jmodelica # CasADi from casadi import * curr_dir = os.path.dirname(os.path.abspath(__file__)) try: # Try the old Jmodelica syntax jmu_name = compile_jmu( "QuadTank_pack.QuadTank_Opt", curr_dir + "/QuadTank.mop", "optimica", "ipopt", {"generate_xml_equations": True, "generate_fmi_xml": True}, ) except jmodelica.compiler.UnknownOptionError: # Try the new jmodelica syntax jmu_name = compile_jmu( "QuadTank_pack.QuadTank_Opt", curr_dir + "/QuadTank.mop", "optimica", "ipopt", {"generate_xml_equations": True, "generate_fmi_me_xml": True}, ) import zipfile