# Parametric studies

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.
```