Made an all: rule

This commit is contained in:
Harry Moffat 2009-03-16 20:04:32 +00:00
parent 112a71013e
commit a2b2c9a7e0
4 changed files with 6 additions and 240 deletions

View file

@ -5,6 +5,12 @@
#
#############################################################################
all:
cd combustor; @MAKE@ test
cd kinetics1; @MAKE@ test
cd flamespeed; @MAKE@ test
cd NASA_coeffs; @MAKE@ test
test:
cd combustor; @MAKE@ test
cd kinetics1; @MAKE@ test

View file

@ -1,75 +0,0 @@
//
// main program to run all C++ demos.
//
#include <cantera/Cantera.h>
#define CXX_DEMO
#include "rankine.cpp"
#include "flamespeed.cpp"
#include "hydrogen_flamespeed.cpp"
#include "kinetics1.cpp"
#include <time.h>
typedef int (*exfun)(int, void*);
// array of demo functions
exfun fex[] = {kinetics1, openRankine, flamespeed, h2_flamespeed};
string demostr[] = {"zero-D kinetics ",
"open Rankine cycle ",
"CH4 flamespeed ",
"H2 flamespeed "};
int np[] = {0, 0, 1, 1};
double p[] = {0, 0, 0.9, 0.9};
#define NDEMOS 4
int mainmenu() {
int i, idemo;
cout << "C++ Demo Programs " << endl;
for (i = 0; i < NDEMOS; i++) {
cout << " " << i+1 << ") " << demostr[i] << endl;
}
cout << " " << i+1 << ")" << " run all demos" << endl;
cout << "Enter demo number (or 0 to quit): ";
cin >> idemo;
if (idemo <= 0) return -99;
int iout = 0;
try {
if (idemo > 0 && idemo < NDEMOS+1) {
clock_t t0 = clock();
iout = fex[idemo-1](0, 0);
clock_t t1 = clock();
cout << endl << "elapsed time: "
<< 1.0*(t1 - t0)/CLOCKS_PER_SEC << " s " << endl;
return idemo;
}
else if (idemo >= NDEMOS+1) {
clock_t t0 = clock();
for (i = 0; i < NDEMOS; i++)
iout = fex[i](np[i], &p[i]);
clock_t t1 = clock();
cout << "time: " << 1.0*(t1 - t0)/CLOCKS_PER_SEC << " s " << endl;
return iout;
}
return 0;
}
catch (CanteraError) {
showErrors(cerr);
return -1;
}
}
int main() {
int i;
while (1 > 0) {
i = mainmenu();
appdelete();
if (i == -99) break;
}
return 0;
}

View file

@ -1,65 +0,0 @@
#ifndef CT_EXAMPLE_UTILS_H
#define CT_EXAMPLE_UTILS_H
#include <cantera/kernel/Array.h>
#include <cantera/kernel/plots.h>
namespace Cantera{}
using namespace Cantera;
namespace std{}
using namespace std;
namespace CanteraZeroD{}
using namespace CanteraZeroD;
// Save the temperature, density, pressure, and mole fractions at one
// time
template<class G, class A>
void saveSoln(int i, double time, const G& gas, A& soln) {
soln(0,i) = time;
soln(1,i) = gas.temperature();
soln(2,i) = gas.density();
soln(3,i) = gas.pressure();
gas.getMoleFractions(&soln(4,i));
}
template<class G, class A>
void saveSoln(double time, const G& gas, A& soln) {
soln.resize(soln.nRows(), soln.nColumns() + 1);
int back = soln.nColumns() - 1;
soln(0,back) = time;
soln(1,back) = gas.temperature();
soln(2,back) = gas.density();
soln(3,back) = gas.pressure();
int nsp = gas.nSpecies();
for (int k = 0; k < nsp; k++)
soln(4+k,back) = gas.moleFraction(k);
}
template<class G, class V>
void makeDataLabels(const G& gas, V& names) {
int nsp = gas.nSpecies();
names.resize(nsp + 4);
names[0] = "time (s)";
names[1] = "Temperature (K)";
names[2] = "Density (kg/m3)";
names[3] = "Pressure (Pa)";
int k;
for (k = 0; k < nsp; k++) names[4+k] = gas.speciesName(k);
}
template<class G, class A>
void plotSoln(string fname, string fmt, string title, const G& gas, const A& soln) {
vector<string> names;
makeDataLabels(gas, names);
writePlotFile(fname, fmt, title, names, soln);
}
inline void writeCanteraHeader(ostream& s) {
s << endl;
s << " Cantera version " << "CANTERA_VERSION" << endl;
s << " Copyright California Institute of Technology, 2002." << endl;
s << " http://www.cantera.org" << endl;
s << endl;
}
#endif

View file

@ -1,100 +0,0 @@
// An open Rankine cycle
#include <string>
#include <map>
#include <cantera/Cantera.h>
#include <cantera/PureFluid.h> // defines class Water
using namespace Cantera;
using namespace std;
map<string,double> h;
map<string,double> s;
map<string,double> T;
map<string,double> P;
map<string,double> x;
vector<string> states;
template<class F>
void saveState(F& fluid, string name) {
h[name] = fluid.enthalpy_mass();
s[name] = fluid.entropy_mass();
T[name] = fluid.temperature();
P[name] = fluid.pressure();
x[name] = fluid.vaporFraction();
states.push_back(name);
}
void printStates() {
string name;
int n;
int nStates = states.size();
for (n = 0; n < nStates; n++) {
name = states[n];
printf(" %5s %10.6g %10.6g %12.6g %12.6g %5.2g \n",
name.c_str(), T[name], P[name], h[name], s[name], x[name]);
}
}
int openRankine(int np, void* p) {
double etap = 0.6; // pump isentropic efficiency
double etat = 0.8; // turbine isentropic efficiency
double phigh = 8.0e5; // high pressure
Water w;
// begin with water at 300 K, 1 atm
w.setState_TP(300.0, OneAtm);
saveState(w,"1");
// pump water to 0.8 MPa
w.setState_SP(s["1"], phigh);
saveState(w,"2s");
double h2 = (h["2s"] - h["1"])/etap + h["1"];
w.setState_HP(h2, phigh);
saveState(w,"2");
// heat to saturated vapor
w.setState_Psat(phigh, 1.0);
saveState(w,"3");
// expand to 1 atm
w.setState_SP(s["3"], OneAtm);
saveState(w,"4s");
double work_s = h["3"] - h["4s"];
double work = etat*work_s;
w.setState_HP(h["3"] - work, OneAtm);
saveState(w,"4");
printStates();
double heat_in = h["3"] - h["2"];
double efficiency = work/heat_in;
cout << "efficiency = " << efficiency << endl;
#ifdef WIN32
#ifndef CXX_DEMO
cout << "press any key to end" << endl;
char ch;
cin >> ch;
#endif
#endif
return 0;
}
#ifndef CXX_DEMO
int main() {
try {
return openRankine(0, 0);
}
catch (CanteraError) {
showErrors(cout);
return -1;
}
}
#endif