Skip to content
Snippets Groups Projects
Commit 88193229 authored by Martín Moraga's avatar Martín Moraga
Browse files

update examples

parent c23ebf0e
No related branches found
No related tags found
No related merge requests found
......@@ -24,20 +24,26 @@ except Exception as err:
try:
#change working directory
cwd = os.getcwd()
wd=os.path.join(cwd, 'test_simulateModel')
wd=os.path.join(cwd, 'test_simflag_override')
if not os.path.exists(wd):
os.makedirs(wd)
modelica.changeWorkingDirectory(wd.replace("\\","/"))
#build model
print("Build model Modelica.Blocks.Examples.PID_Controller")
modelica.buildModel("Modelica.Blocks.Examples.PID_Controller", startTime=5, stopTime=10)
#simulate model
#you can edit the initial values with the sim flag -override
modelica.simulateModel("Modelica.Blocks.Examples.PID_Controller", startTime=0.0, stopTime=25.0,
simflags="-override=spring.w_rel=10,PI.Dzero.k=5.0")
modelica.simulate(simflags="-override=spring.w_rel=20,PI.Dzero.k=5.0,stopTime=50")
#check start value of spring.w_rel and inertia1.a
test = modelica.getSolutions("spring.w_rel", "PI.Dzero.k")
print('\nspring.w_rel[0]: {}'.format(test['spring.w_rel'][0]))
print('PI.Dzero.k[0]: {}'.format(test['PI.Dzero.k'][0]))
#check start value of spring.w_rel and PI.Dzero.k
test = modelica.getResults(["spring.w_rel", "PI.Dzero.k", "time"])
print('\nspring.w_rel[0]: {}'.format(test[0][0]))
print('PI.Dzero.k[0]: {}'.format(test[1][0]))
print('time: {}'.format(test[2]))
print("\n")
except Exception as err:
......
......@@ -23,11 +23,15 @@ except Exception as err:
try:
#change working directory
cwd = os.getcwd()
wd=os.path.join(cwd, 'test_simulateModel2')
wd=os.path.join(cwd, 'test_simflag_overrideFile')
if not os.path.exists(wd):
os.makedirs(wd)
modelica.changeWorkingDirectory(wd.replace("\\","/"))
#build model
print("Build model Modelica.Blocks.Examples.PID_Controller")
modelica.buildModel("Modelica.Blocks.Examples.PID_Controller")
#simulate model
#you can use one file to set initial values
#Note that: -overrideFile CANNOT be used with -override. Use when variables for -override are too many.
......@@ -38,18 +42,19 @@ try:
#OpenModelica compiler does not inherit the parameters in the model.
initFile=os.path.join(wd, 'init_values.csv')
f = open(initFile,'w')
f.write('spring.w_rel=20.0\nPI.Dzero.k=10.0\n')
file='startTime=0 \n stopTime=30 \n spring.w_rel=20.0 \n PI.Dzero.k=10.0 \n'.replace(" ", "")
f.write(file)
f.close()
sim_flags='-overrideFile {}'.format(initFile).replace("\\","/")
print(sim_flags)
modelica.simulateModel("Modelica.Blocks.Examples.PID_Controller", startTime=0.0, stopTime=25.0,
simflags=sim_flags)
#check start value of spring.w_rel and inertia1.a
test = modelica.getSolutions("spring.w_rel", "PI.Dzero.k")
print('\nspring.w_rel[0]: {}'.format(test['spring.w_rel'][0]))
print('PI.Dzero.k[0]: {}'.format(test['PI.Dzero.k'][0]))
print("Simulate Model:")
modelica.simulate(simflags=sim_flags)
#check start value of spring.w_rel and PI.Dzero.k and time
test = modelica.getResults(["spring.w_rel", "PI.Dzero.k", "time"])
print('\nspring.w_rel[0]: {}'.format(test[0][0]))
print('PI.Dzero.k[0]: {}'.format(test[1][0]))
print('time: {}'.format(test[2]))
print("\n")
except Exception as err:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment