RPA-C Scripting Utility

RPA-C Scripting Utility is available as a part of RPA-C and implements object-oriented binding from JavaScript (ECMAScript) to many internal objects and functions of RPA-C.

Key features of RPA-C Scripting Utility

For more information see also

Download

Scripting Utility is an integral part of RPA-C and available since v.1.0.

Examples

/***************************************************
 RPA-C - tool for the thermodynamic analysis.
  
 This script loads existing configuration file,
 solves the configured problem and prints out the results.
****************************************************/
// Load configuration file
c = new ConfigFile("examples/HMX.cfg");
c.read();
// Create and run combustion analysis
ca = new CombustionAnalysis();
ca.run(c);
if (ca.getCombustorsListSize()>0) {
    printf("Initial mixture:\n");
    ca.getMixture().print();
    tUnit = "K";
    printf("T   = %10.5f %s\n", ca.getCombustor(0).getEquilibrium().getT(tUnit), tUnit);
    hexUnit = "kJ/kg";
    printf("HEX = %10.5f %s\n", ca.getHEX(hexUnit), hexUnit);
} else {
    printf("Could not solve!\n");
}

/***************************************************
 RPA-C - tool for the thermodynamic analysis.
  
 This script demonstrates how to prepare the mixture of 
 ingredients and run the combustion problem using object Combustor.
****************************************************/
// Prepare the mixture of ingredients
mix = new Mixture();
mix.addSpecies("NH4CLO4(cr)", 0.7); 
mix.addSpecies("AL(cr)", 0.2); 
mix.addSpecies("HTPB+Curative", 0.9, "g/cm^3", 0.1); 
printf("Initial mixture:");
mix.print();
// Solve problem (p,H)=const using object Combustor
printf("Solve problem (p,H)=const");
c1 = new Combustor(mix, true, true);
c1.setP(20.7, "MPa"); 
c1.solve(true, false);
c1.getEquilibrium().print("SI");
c1.getDerivatives().print("SI");
// Solve problem (p,T)=const using object Combustor
p = 20.7;
T = 1400;
printf("Solve problem (p,T)=const at p=%4.1f MPa T=%8.3f K", p, T);
c2 = new Combustor(mix, true, true);
c2.setPT(p, "MPa", T, "K"); 
c2.solve(true, false);
c2.getEquilibrium().print("SI");
c2.getDerivatives().print("SI");
// Solve problem (p,H)=const using object Combustor
printf("Solve problem (p,H)=const at p=%4.1f MPa", p);
c3 = new Combustor(mix, true, true);
c3.setP(p, "MPa"); 
c3.solve(true, false);
c3.getEquilibrium().print("SI");
c3.getDerivatives().print("SI");

/***************************************************
 RPA-C - tool for the thermodynamic analysis.
  
 This script demonstrates how to prepare the mixture of 
 ingredients and run nested combustion problems using 
 object Combustor.
****************************************************/
// Prepare the mixture of ingredients
mix = new Mixture();
mix.addSpecies("NH4CLO4(cr)", 0.7); 
mix.addSpecies("AL(cr)", 0.2); 
mix.addSpecies("HTPB+Curative", 0.9, "g/cm^3", 0.1); 
printf("Initial mixture:\n");
mix.print();
// Nested analysis
// Array of pressure values in MPa
p = [10, 15, 20];
// Array of temperature values in K
// "-1" means the temperature won't be assigned 
// (see the code below)
T = [-1, 1000, 1400, 1800]; 
for (var i=0; i<p.length; i++) {
    printf("Pressure p=%10.5f MPa\n", p[i]);
    for (var j=0; j<T.length; j++) {
        c = new Combustor(mix, true, true);
        if (T[j]>0) {
            printf("Temperature T=%10.5f K\n", T[j]);
            c.setPT(p[i], "MPa", T[j], "K"); 
        } else {
            c.setP(p[i], "MPa"); 
        }
        c.solve(true, false);
        c.getEquilibrium().print("SI");
        c.getDerivatives().print("SI");
        printf("\n*************************************************************\n");
    }
}

/***************************************************
 RPA-C - tool for the thermodynamic analysis.
  
 This script demonstrates how to write results in required
 format into the file "log.txt".
****************************************************/
// Open the  file "log.txt" in the mode "w" ("write")
var f = new File("log.txt", "w"); 
// Define variable with the name of configuration file
configName = "examples/HMX.cfg";
// Open configuration file
c = new ConfigFile(configName);
c.read();
f.printf("# Configuration file: %s\n\n", configName);
// Prepare and run combustion analysis
ca = new CombustionAnalysis();
ca.run(c);
if (ca.getCombustorsListSize()>0) {
    combustor = ca.getCombustor(0);
    r = combustor.getEquilibrium();
    products = r.getResultingMixture();
    unit = "MPa";
    f.printf("p   = %10.5f %s\n", combustor.getEquilibrium().getP(unit), unit);
    unit = "K";
    f.printf("T   = %10.5f %s\n", combustor.getEquilibrium().getT(unit), unit);
    unit = "kJ/kg";
    f.printf("HEX = %10.5f %s\n", ca.getHEX(unit), unit);
   
    f.printf("\n# %13s %9s %9s %4s\n", "Name", "Mass Frac", "Mole Frac", "Cond");
    sum1 = 0;
    sum2 = 0; 
    for (i=0; i<products.size(); ++i) {
        // Reaction product
        s = products.getSpecies(i);
        massFraction = products.getFraction(i, "mass"); 
        moleFraction = products.getFraction(i, "mole");; 
        sum1 += massFraction;
        sum2 += moleFraction;
        // We are printing out mass fraction in  format "%9.7f",
        // so skip all products with massFraction<1e-7
        if (massFraction<1e-7) {
            continue;
        }
        f.printf("%15s %9.7f %9.7f %4d\n",
            s.getName(),
            massFraction,
            moleFraction,
            s.getCondensed()
        );
    }
    f.printf("%15s %9.7f %9.7f\n",
        "Summ:",
        sum1,
        sum2
    );
    
}
// Close the file
f.close();

More examples can be found in RPA-C distribution package.


Copyright © 2009 - 2017 Alexander Ponomarenko