Parametric studies: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
The following code snippet implements something like the old <tt>[[STUDY]]</tt> method from the Tcl/Tk GUI. In this version, it is implemented as a plot, as shown above. At present the python script must be modified each time you want to change the parameters in your study. With some work, we hope to encapsulate this so that the [[STUDY]] can be created with only a METHOD call in the .a4l file. | The following code snippet implements something like the old <tt>[[STUDY]]</tt> method from the Tcl/Tk GUI. In this version, it is implemented as a plot, as shown above. At present the python script must be modified each time you want to change the parameters in your study. With some work, we hope to encapsulate this so that the [[STUDY]] can be created with only a METHOD call in the .a4l file. | ||
[[Image:Parameter-study.png]|thumb|400|none|Results of parametric study using [[ExtPy]] functionality]] | |||
<source lang="a4c">import extpy; | <source lang="a4c">import extpy; | ||
| Line 25: | Line 25: | ||
figure() | figure() | ||
#self.inlet.p.setRealValueWithUnits(20, | #self.inlet.p.setRealValueWithUnits(20,"bar"); | ||
#self.inlet.T.setRealValueWithUnits(100+273.15, | #self.inlet.T.setRealValueWithUnits(100+273.15,"K") | ||
betavals = [0.2177, 0.25, 0.275,0.3, 0.325,0.35,0.4,0.45,0.5, 0.7,0.9] | betavals = [0.2177, 0.25, 0.275,0.3, 0.325,0.35,0.4,0.45,0.5, 0.7,0.9] | ||
| Line 34: | Line 34: | ||
plots = 0 | plots = 0 | ||
for beta in betavals: | for beta in betavals: | ||
print | print "BETA = %f" % beta | ||
self.OP.beta.setRealValue(beta) | self.OP.beta.setRealValue(beta) | ||
| Line 43: | Line 43: | ||
mdot = mdot_min + (mdot_max-mdot_min)*i/n | mdot = mdot_min + (mdot_max-mdot_min)*i/n | ||
self.mdot.setRealValueWithUnits(mdot, | self.mdot.setRealValueWithUnits(mdot,"kg/s") | ||
try: | try: | ||
browser.sim.solve(browser.solver,SimpleSolverReporter(browser, | browser.sim.solve(browser.solver,SimpleSolverReporter(browser,"beta = %f, mdot = %f"%(beta,mdot))) | ||
except: | except: | ||
browser.reporter.reportError('Failed to solve for mdot = | browser.reporter.reportError('Failed to solve for mdot = %d' % mdot) | ||
continue | continue | ||
xdata.append(mdot) | xdata.append(mdot) | ||
ydata.append(-self.dp.as( | ydata.append(-self.dp.as("bar")) | ||
if xdata: | if xdata: | ||
| Line 64: | Line 64: | ||
if plots: | if plots: | ||
xlabel( | xlabel("Mass flow rate / [kg/s]") | ||
ylabel( | ylabel("Pressure drop / [bar]") | ||
title( | title("Pressure drop vs flow rate, various orifice ratios") | ||
legend(loc='upper left') | legend(loc='upper left') | ||
| Line 74: | Line 74: | ||
show() | show() | ||
else: | else: | ||
browser.reporter.reportError( | browser.reporter.reportError("NO PLOTS CREATED") | ||
extpy.registermethod(studyplot) | extpy.registermethod(studyplot) | ||
#the above method can be called using | #the above method can be called using "EXTERNAL studyplot(SELF)" in ASCEND.</source> | ||
Revision as of 08:12, 29 March 2011
This page documents an experimental feature. Please tell us if you experience any problems.
If you are interested in parametric models, see the page on object-oriented modelling instead.
The following code snippet implements something like the old STUDY method from the Tcl/Tk GUI. In this version, it is implemented as a plot, as shown above. At present the python script must be modified each time you want to change the parameters in your study. With some work, we hope to encapsulate this so that the STUDY can be created with only a METHOD call in the .a4l file.
[[Image:Parameter-study.png]|thumb|400|none|Results of parametric study using ExtPy functionality]]
import extpy; from pylab import * from solverreporter import * def studyplot(self): # following is an unfortunate necessity in the current system architecture: browser = extpy.getbrowser() # just check that all is ok browser.do_solve() ioff() n = 20; mdot_min = 1.7 mdot_max = 12 figure() #self.inlet.p.setRealValueWithUnits(20,"bar"); #self.inlet.T.setRealValueWithUnits(100+273.15,"K") betavals = [0.2177, 0.25, 0.275,0.3, 0.325,0.35,0.4,0.45,0.5, 0.7,0.9] betalines = ['b.-','g.-','r.-' ,'c-','m-','y-','b--','g--','r--','c:','m:','y:'] plots = 0 for beta in betavals: print "BETA = %f" % beta self.OP.beta.setRealValue(beta) xdata = [] ydata = [] for i in range(n): mdot = mdot_min + (mdot_max-mdot_min)*i/n self.mdot.setRealValueWithUnits(mdot,"kg/s") try: browser.sim.solve(browser.solver,SimpleSolverReporter(browser,"beta = %f, mdot = %f"%(beta,mdot))) except: browser.reporter.reportError('Failed to solve for mdot = %d' % mdot) continue xdata.append(mdot) ydata.append(-self.dp.as("bar")) if xdata: plot(xdata,ydata,betalines[plots],label='%0.3f'%beta) hold(1) plots += 1 if plots: xlabel("Mass flow rate / [kg/s]") ylabel("Pressure drop / [bar]") title("Pressure drop vs flow rate, various orifice ratios") legend(loc='upper left') ylim(ymax=4.0) ion() show() else: browser.reporter.reportError("NO PLOTS CREATED") extpy.registermethod(studyplot) #the above method can be called using "EXTERNAL studyplot(SELF)" in ASCEND.