13.7.15. Macro “relauncherCodeFlowrateSequential_TemporaryVar.C”
13.7.15.1. Objective
The goal of this macro is to show how to hide one of the evaluator’s attribute and not to store it in
the final dataserver. This is considered when a composition is done for instance, in which many
variables might be intermediate needed ones, resulting from an assessor and used as input to one of
the following, but of no interest to the user at the end. The flowrate code is provided with
Uranie and has been also used and discussed throughout these macros.
13.7.15.2. Macro
void IncreaseD(double *x, double *y)
{
y[0] = x[0] + 1;
}
void relauncherCodeFlowrateSequential_TemporaryVar(const int seed=0)
{
// Create the TDataServer
TDataServer *tds = new TDataServer("foo","test");
// Define the attribute that should be considered as constant
TAttribute r("r");
// Add the study attributes ( min, max and nominal values)
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
// The reference input file
TString sIn = TString("flowrate_input_with_keys.in");
int nS=15;
// Generate the Design of Experiments
TSampling *sampling = new TSampling(tds, "lhs", nS);
sampling->generateSample();
// Create the input files
TKeyScript inputFile( sIn.Data() );
inputFile.addInput(tds->getAttribute("rw"),"Rw");
inputFile.addInput(&r,"R");
inputFile.addInput(tds->getAttribute("tu"),"Tu");
inputFile.addInput(tds->getAttribute("tl"),"Tl");
inputFile.addInput(tds->getAttribute("hu"),"Hu");
inputFile.addInput(tds->getAttribute("hl"),"Hl");
inputFile.addInput(tds->getAttribute("l"),"L");
inputFile.addInput(tds->getAttribute("kw"),"Kw");
// Create the output attributes
TAttribute *yhat = new TAttribute("yhat");
TAttribute *d = new TAttribute("d");
// Create the output files
TKeyResult outputFile("_output_flowrate_withKey_.dat");
outputFile.addOutput(yhat, "yhat");
outputFile.addOutput(d, "d");
// Create the user's evaluation function
TCodeEval eval1("flowrate -s -k");
eval1.addInputFile(&inputFile);
eval1.addOutputFile(&outputFile);
// Create a second evaluation function that uses d to change it slightly
TAttribute *incd = new TAttribute("incd");
TCIntEval eval2("IncreaseD");
eval2.addInput(d);
eval2.addOutput(incd);
// Create the composition
TComposeEval eval;
// Add the code one-by-one, in the right order
eval.addEval(&eval1);
eval.addEval(&eval2);
// Create the sequential runner
TSequentialRun run(&eval);
run.startSlave(); //Start the master (necessary even for a sequential)
if (run.onMaster())
{
TLauncher2 lanceur(tds, &run);
// State to the master : d is an output attribute and I'm interested in its value
// but I don't want to keep it in the end. It might be usefull for another evaluator
lanceur.addTemporary(d);
lanceur.addConstantValue(&r,108);
// resolution
lanceur.solverLoop();
run.stopSlave(); // Stop the slaves (necessary even for a sequential)
}
tds->scan("*", "", "colsize=6");
}
Here again, a comparison is drawn with the macro in which we set an attribute to a constant value (see Macro “relauncherCodeFlowrateSequential_ConstantVar.C”), so only the differences are pointed out. The very first one is contained in the beginning lines: a new dummy function, so that we can have a composition of two assessors, this function only adding one to the provided parameter.
void IncreaseD(double *x, double *y)
{
y[0] = x[0] + 1;
}
The rest is exactly as for Macro “relauncherCodeFlowrateSequential_ConstantVar.C”, up to the interface with the newy create function:
// Create a second evaluation function that uses d to change it slightly
TAttribute *incd = new TAttribute("incd");
TCIntEval eval2("IncreaseD");
eval2.addInput(d);
eval2.addOutput(incd);
// Create the composition
TComposeEval eval;
// Add the code one-by-one, in the right order
eval.addEval(&eval1);
eval.addEval(&eval2);
A new output attribute is created, called incd for increased d, and the dummy function is
defined as taking d as input and incd as output. Then the composition is done by chaining
flowrate with the new dummy function. The rest is fairly common, up to the TMaster-inheriting
object specification: the addTemporary method is called to specify that d is read from the
output of flowrate and can be pass to the rest of the chain, but it will not be kept in the final
dataserver. The addConstantValue is also used just changing the final parameters to show that if
nothing is specified, then the value of r is not stored and this might be tricky for bookkeeping.
The results is shown in the next section (from the scan method) and can be compared to
Console for consistency check.
TLauncher2 lanceur(tds, &run);
// State to the master : d is an output attribute and I'm interested in its value
// but I don't want to keep it in the end. It might be usefull for another evaluator
lanceur.addTemporary(d);
lanceur.addConstantValue(&r,108);
13.7.15.3. Console
******************************************************************************************************
* Row * foo__n * rw.rw * tu.tu * tl.tl * hu.hu * hl.hl * l.l * kw.kw * yhat.y * incd.i *
******************************************************************************************************
* 0 * 0 * 0.1495 * 111790 * 73.820 * 990.90 * 779.83 * 1474.3 * 11220. * 112.01 * 3589.9 *
* 1 * 1 * 0.1394 * 104140 * 95.150 * 1101.5 * 707.21 * 1422.7 * 11493. * 193.62 * 6598.5 *
* 2 * 2 * 0.0557 * 95387. * 84.809 * 1056.2 * 752.94 * 1184.6 * 11967. * 29.880 * 331.58 *
* 3 * 3 * 0.0836 * 74144. * 103.17 * 1051.6 * 819.27 * 1587.4 * 11031. * 35.400 * 2432.1 *
* 4 * 4 * 0.0586 * 65396. * 72.161 * 1003.1 * 710.34 * 1327.5 * 10484. * 24.990 * 5758 *
* 5 * 5 * 0.1203 * 92149. * 65.263 * 1031.6 * 797.34 * 1265.5 * 11638. * 97.386 * 1085.8 *
* 6 * 6 * 0.1319 * 67464. * 93.378 * 1039.4 * 722.54 * 1514.3 * 10996. * 125.33 * 2363.4 *
* 7 * 7 * 0.1059 * 80448. * 112.87 * 1027.1 * 794.32 * 1555.4 * 11846 * 62.403 * 1117.3 *
* 8 * 8 * 0.0784 * 100260 * 105.79 * 1072.7 * 767.70 * 1304.1 * 10152. * 45.867 * 522.41 *
* 9 * 9 * 0.0697 * 105158 * 82.544 * 1020.4 * 726.05 * 1640.3 * 10380. * 28.412 * 2803.5 *
* 10 * 10 * 0.1252 * 89522. * 100.65 * 1006.2 * 742.35 * 1123.9 * 10743. * 123.70 * 2677.1 *
* 11 * 11 * 0.1165 * 73139. * 69.083 * 1108.5 * 809.59 * 1199.0 * 10620. * 112.27 * 4992.3 *
* 12 * 12 * 0.0992 * 86004. * 112.12 * 1069.4 * 763.84 * 1345.2 * 9951.0 * 69.808 * 415.71 *
* 13 * 13 * 0.0718 * 113775 * 90.580 * 1079.1 * 782.95 * 1416.6 * 10076. * 34.135 * 1017.8 *
* 14 * 14 * 0.0902 * 83779. * 80.244 * 1090.6 * 734.33 * 1644.2 * 11443 * 63.236 * 2923.3 *
******************************************************************************************************