13.8.3. Macro “relauncherCodeFlowrateSequential.py”
13.8.3.1. Objective
The goal of this macro is to show how to handle a code with a sequential runner. The flowrate code
is provided with Uranie and has been also used and discussed throughout these macros.
13.8.3.2. Macro
"""
Example of code launching in sequential mode
"""
from URANIE import DataServer, Relauncher
import ROOT
# Create the DataServer.TDataServer
tds = DataServer.TDataServer("foo", "test")
tds.fileDataRead("flowrateUniformDesign.dat")
# Get the attributes
rw = tds.getAttribute("rw")
r = tds.getAttribute("r")
tu = tds.getAttribute("tu")
tl = tds.getAttribute("tl")
hu = tds.getAttribute("hu")
hl = tds.getAttribute("hl")
lvar = tds.getAttribute("l")
kw = tds.getAttribute("kw")
# Create the output attribute
yhat = DataServer.TAttribute("yhat")
d = DataServer.TAttribute("d")
# Set the reference input file and the key for each input attributes
fin = Relauncher.TFlatScript("flowrate_input_with_values_rows.in")
fin.addInput(rw)
fin.addInput(r)
fin.addInput(tu)
fin.addInput(tl)
fin.addInput(hu)
fin.addInput(hl)
fin.addInput(lvar)
fin.addInput(kw)
# The output file of the code
fout = Relauncher.TFlatResult("_output_flowrate_withRow_.dat")
fout.addOutput(yhat)
fout.addOutput(d) # Passing the attributes to the output file
# Constructing the code
mycode = Relauncher.TCodeEval("flowrate -s -r")
mycode.setOldTmpDir()
mycode.addInputFile(fin) # Adding the input file
mycode.addOutputFile(fout) # Adding the output file
# Create the sequential runner
run = Relauncher.TSequentialRun(mycode)
run.startSlave() # Start the master (necessary even for a sequential)
if run.onMaster():
lanceur = Relauncher.TLauncher2(tds, run)
# resolution
lanceur.solverLoop()
run.stopSlave() # Stop the slaves (necessary even for a sequential)
# Draw the result
can = ROOT.TCanvas("pouet", "foo", 1)
tds.Draw("yhat:rw", "", "colZ")
Here again, a comparison is drawn with the first Relauncher macro (see Macro) and only the differences are pointed out. The first obvious one, in the very first steps in defining the dataserver and the attributes, is that there are two output attributes. The second one (called ‘d’) will not be used here. The second (and only other difference) with respect to the CINT function code, is the assessor creation shown below:
# Set the reference input file and the key for each input attributes
fin = Relauncher.TFlatScript("flowrate_input_with_values_rows.in")
fin.addInput(rw)
fin.addInput(r)
fin.addInput(tu)
fin.addInput(tl)
fin.addInput(hu)
fin.addInput(hl)
fin.addInput(lvar)
fin.addInput(kw)
# The output file of the code
fout = Relauncher.TFlatResult("_output_flowrate_withRow_.dat")
fout.addOutput(yhat)
fout.addOutput(d) # Passing the attributes to the output file
# Constructing the code
mycode = Relauncher.TCodeEval("flowrate -s -r")
mycode.setOldTmpDir()
mycode.addInputFile(fin) # Adding the input file
mycode.addOutputFile(fout) # Adding the output file
The first three lines create the input file instance. It is here a TFlatScript object which can
basically be compared to a DataServer (or Salome-table) format of the Launcher module for its
organisation (particularly with vectors and strings) but without the compulsory header: the order in
which you introduce the attribute is then of uttermost importance. The second block of lines is
creating the output file object from the TFlatResult class (the same remark applies to this object).
Finally the assessor itself is created as an instance of the TCodeEval class. The only argument is
the command to be run, and it needs at least one input and output file. Apart from that, the runner
is created and the rest is crystal clear, leading to the following plot.
13.8.3.3. Graph
Figure 13.48 Representation of the output as a function of the first input with a colZ option