Parametric studies: Difference between revisions

From ASCEND
Jump to navigation Jump to search
Restored page from Google Cache, uploaded by John Pye
 
No edit summary
Line 1: Line 1:
<div class="pageexperimental">''This page documents an '''experimental''' feature. You can help out by '''testing it''' and <span class="plainlinks">[http://ascendwiki.cheme.cmu.edu/index.php?title=Parametric_studies&action=edit recording]</span> your experiences.''</div>
{{experimental}}
''If you are interested in '''parametric models''', see the page on [[object-oriented modelling]] instead.''


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.

Revision as of 09:37, 31 July 2010

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.

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,&quot;bar&quot;);
      #self.inlet.T.setRealValueWithUnits(100+273.15,&quot;K&quot;)

      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 &quot;BETA =&nbsp;%f&quot; % 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,&quot;kg/s&quot;)

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

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

                     continue

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

           if xdata:
                plot(xdata,ydata,betalines[plots],label='%0.3f'%beta)

                hold(1)
                plots += 1

      if plots:

           xlabel(&quot;Mass flow rate / [kg/s]&quot;)
           ylabel(&quot;Pressure drop / [bar]&quot;)
           title(&quot;Pressure drop vs flow rate, various orifice ratios&quot;)

           legend(loc='upper left')
           ylim(ymax=4.0)
           ion()

           show()
      else:
           browser.reporter.reportError(&quot;NO PLOTS CREATED&quot;)

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