Parametric studies: Difference between revisions

From ASCEND
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
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.


<div class="thumb tleft"><div class="thumbinner" style="width:402px;">[[Image:Parameter-study.png]] <div class="thumbcaption"><div class="magnify">[[File:Parameter-study.png|<img src="/skins/common/images/magnify-clip.png" width="15" height="11" alt="" />]]</div>Results of parametric study using [[ExtPy]] functionality</div></div></div>
[[Image:Parameter-study.png]|thumb|400|none|Results of parametric study using [[ExtPy]] functionality]]
<source lang="a4c">import extpy;
<source lang="py">import extpy;


from pylab import *
from pylab import *
from solverreporter import *
from solverreporter import *


def studyplot(self):
def studyplot(self):


       # following is an unfortunate necessity in the current system architecture:
       # following is an unfortunate necessity in the current system architecture:
Line 25: Line 25:
       figure()
       figure()


       #self.inlet.p.setRealValueWithUnits(20,&quot;bar&quot;);
       #self.inlet.p.setRealValueWithUnits(20,"bar");
       #self.inlet.T.setRealValueWithUnits(100+273.15,&quot;K&quot;)
       #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 &quot;BETA =&nbsp;%f&quot; % beta
           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,&quot;kg/s&quot;)
                 self.mdot.setRealValueWithUnits(mdot,"kg/s")


                 try:
                 try:
                     browser.sim.solve(browser.solver,SimpleSolverReporter(browser,&quot;beta =&nbsp;%f, mdot =&nbsp;%f&quot;%(beta,mdot)))
                     browser.sim.solve(browser.solver,SimpleSolverReporter(browser,"beta = %f, mdot = %f"%(beta,mdot)))


                 except:
                 except:
                     browser.reporter.reportError('Failed to solve for mdot =&nbsp;%d' % mdot)
                     browser.reporter.reportError('Failed to solve for mdot = %d' % mdot)


                     continue
                     continue


                 xdata.append(mdot)
                 xdata.append(mdot)
                 ydata.append(-self.dp.as(&quot;bar&quot;))
                 ydata.append(-self.dp.as("bar"))


           if xdata:
           if xdata:
Line 64: Line 64:
       if plots:
       if plots:


           xlabel(&quot;Mass flow rate / [kg/s]&quot;)
           xlabel("Mass flow rate / [kg/s]")
           ylabel(&quot;Pressure drop / [bar]&quot;)
           ylabel("Pressure drop / [bar]")
           title(&quot;Pressure drop vs flow rate, various orifice ratios&quot;)
           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(&quot;NO PLOTS CREATED&quot;)
           browser.reporter.reportError("NO PLOTS CREATED")


extpy.registermethod(studyplot)
extpy.registermethod(studyplot)
#the above method can be called using &quot;EXTERNAL studyplot(SELF)&quot; in ASCEND.</source>
#the above method can be called using "EXTERNAL studyplot(SELF)" in ASCEND.</source>


[[Category:Experimental]]
[[Category:Documentation]]
[[Category:Documentation]]

Latest revision as of 08:13, 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]]

Invalid language.

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

a4c, abap, abc, abnf, actionscript, ada, agda, alan, algol, ampl, amtrix, applescript, arc, arm, as400cl, ascend, asciidoc, asp, aspect, assembler, ats, autohotkey, autoit, avenue, awk, ballerina, bat, bbcode, bcpl, bibtex, biferno, bison, blitzbasic, bms, bnf, boo, c, carbon, ceylon, charmm, chill, chpl, clean, clearbasic, clipper, clojure, clp, cmake, cobol, coffeescript, coldfusion, conf, cpp2, critic, crk, crystal, cs_block_regex, csharp, css, d, dart, delphi, diff, dockerfile, dts, dylan, ebnf, ebnf2, eiffel, elixir, elm, email, erb, erlang, euphoria, exapunks, excel, express, factor, fame, fasm, felix, fish, fortran77, fortran90, frink, fsharp, fstab, fx, gambas, gdb, gdscript, go, graphviz, haml, hare, haskell, haxe, hcl, html, httpd, hugo, icon, idl, idlang, inc_luatex, informix, ini, innosetup, interlis, io, jam, jasmin, java, javascript, js_regex, json, jsp, jsx, julia, kotlin, ldif, less, lhs, lilypond, limbo, lindenscript, lisp, logtalk, lotos, lotus, lua, luban, makefile, maple, markdown, matlab, maya, mercury, meson, miranda, mod2, mod3, modelica, moon, ms, msl, mssql, mxml, n3, nasal, nbc, nemerle, netrexx, nginx, nice, nim, nix, nsis, nxc, oberon, objc, ocaml, octave, oorexx, org, os, oz, paradox, pas, pdf, perl, php, pike, pl1, plperl, plpython, pltcl, po, polygen, pony, pov, powershell, pro, progress, ps, psl, pure, purebasic, purescript, pyrex, python, q, qmake, qml, qu, r, rebol, rego, rexx, rnc, rpg, rpl, rst, ruby, rust, s, sam, sas, scad, scala, scilab, scss, shellscript, slim, small, smalltalk, sml, snmp, snobol, solidity, spec, spn, sql, squirrel, styl, svg, swift, sybase, tcl, tcsh, terraform, tex, toml, tsql, tsx, ttcn3, txt, typescript, upc, vala, vb, verilog, vhd, vimscript, vue, wat, whiley, wren, xml, xpp, yaiff, yaml, yaml_ansible, yang, zig, znn