changed C++ demos

This commit is contained in:
Dave Goodwin 2005-01-24 15:06:36 +00:00
parent 61e70d29c2
commit 4158c19375
12 changed files with 157 additions and 114 deletions

View file

@ -8,11 +8,11 @@
############################################################################# #############################################################################
# the name of the executable program to be created # the name of the executable program to be created
PROG_NAME = kinetics1@EXE_EXT@ PROG_NAME = demos@EXE_EXT@
# the object files to be linked together. List those generated from Fortran # the object files to be linked together. List those generated from Fortran
# and from C/C++ separately # and from C/C++ separately
OBJS = kinetics1.o OBJS = demos.o
# additional flags to be passed to the linker. If your program # additional flags to be passed to the linker. If your program
# requires other external libraries, put them here # requires other external libraries, put them here
@ -62,7 +62,7 @@ $(PROGRAM): $(OBJS) $(CANTERA_LIBDIR)/libcantera.a
test: test:
@MAKE@ $(PROGRAM) @MAKE@ $(PROGRAM)
./runtest echo 100 | $(PROGRAM) > $(PROGRAM).out
install: install:
@INSTALL@ -d @ct_demodir@/cxx @INSTALL@ -d @ct_demodir@/cxx

View file

@ -8,48 +8,66 @@
#include "flamespeed.cpp" #include "flamespeed.cpp"
#include "kinetics1.cpp" #include "kinetics1.cpp"
typedef int (*exfun)(); #include <time.h>
typedef int (*exfun)(int, void*);
int run_example(int n, exfun f, int job = 2) {
cout << "\n\n\n\n>>>>> example " << n+1 << "\n\nDescription: ";
int i = f(job);
showErrors(cout);
return i;
}
// array of demo functions // array of demo functions
exfun fex[] = {kinetics1, rankine, flamespeed}; exfun fex[] = {kinetics1, openRankine, flamespeed};
string demostr[] = {"zero-D kinetics ", string demostr[] = {"zero-D kinetics ",
"open Rankine cycle ", "open Rankine cycle ",
"flamespeed "}; "flamespeed "};
int np[] = {0, 0, 1};
double p[] = {0, 0, 0.9};
#define NDEMOS 3 #define NDEMOS 3
main() { int mainmenu() {
int i, idemo; int i, idemo;
cout << "C++ Demo Programs " << endl;
for (i = 0; i < NDEMOS; i++) { for (i = 0; i < NDEMOS; i++) {
cout << i << ") " << demostr[i] << endl; cout << " " << i+1 << ") " << demostr[i] << endl;
} }
cout << i << ")" << "run all demos" << endl; cout << " " << i+1 << ")" << " run all demos" << endl;
cout << "Enter demo number: " << endl; cout << "Enter demo number (or 0 to quit): ";
cin >> idemo; cin >> idemo;
if (idemo <= 0) return -99;
int iout = 0;
try { try {
if (idemo > 0 && idemo < NDEMOS) { if (idemo > 0 && idemo < NDEMOS+1) {
return fex[idemo](); 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) { else if (idemo >= NDEMOS+1) {
int iout = 0; clock_t t0 = clock();
for (i = 0; i < NDEMOS; i++) for (i = 0; i < NDEMOS; i++)
iout = fex[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 iout;
} }
return 0;
} }
catch (CanteraError) { catch (CanteraError) {
showErrors(cerr); showErrors(cerr);
appDelete();
return -1; return -1;
} }
} }
int main() {
int i;
while (1 > 0) {
i = mainmenu();
appdelete();
if (i == -99) break;
}
return 0;
}

View file

@ -17,7 +17,7 @@
using namespace Cantera; using namespace Cantera;
int demo() { int flamespeed(int np, void* p) {
try { try {
int i; int i;
IdealGasMix gas("gri30.cti","gri30_mix"); IdealGasMix gas("gri30.cti","gri30_mix");
@ -32,9 +32,12 @@ int demo() {
vector_fp x; vector_fp x;
x.resize(nsp); x.resize(nsp);
doublereal phi=1.1; double phi = 0.0;
cout << "Enter phi: "; if (np > 0) phi = *(double*)(p);
cin >> phi; if (phi == 0.0) {
cout << "Enter phi: ";
cin >> phi;
}
doublereal C_atoms=1.0; doublereal C_atoms=1.0;
doublereal H_atoms=4.0; doublereal H_atoms=4.0;
@ -65,9 +68,9 @@ int demo() {
doublereal Tad=gas.temperature(); doublereal Tad=gas.temperature();
cout << phi<<' '<<Tad<<endl; cout << phi<<' '<<Tad<<endl;
double Tin=temp; //double Tin=temp;
double Tout=Tad; //double Tout=Tad;
double breakpt=0.2; //double breakpt=0.2;
//============= build each domain ======================== //============= build each domain ========================
@ -212,8 +215,9 @@ int demo() {
} }
} }
#ifndef CXX_DEMO
int main() { int main() {
return demo(); return flamespeed(0, 0);
} }
#endif

View file

@ -24,7 +24,7 @@
#include "example_utils.h" #include "example_utils.h"
int kinetics1() { int kinetics1(int np, void* p) {
cout << "Constant-pressure ignition of a " cout << "Constant-pressure ignition of a "
<< "hydrogen/oxygen/nitrogen" << "hydrogen/oxygen/nitrogen"
@ -113,7 +113,7 @@ int kinetics1() {
int main() { int main() {
try { try {
return kinetics1(); return kinetics1(0, 0);
} }
// handle exceptions thrown by Cantera // handle exceptions thrown by Cantera
catch (CanteraError) { catch (CanteraError) {

View file

@ -36,7 +36,7 @@ void printStates() {
} }
} }
void openRankine() { int openRankine(int np, void* p) {
double etap = 0.6; // pump isentropic efficiency double etap = 0.6; // pump isentropic efficiency
double etat = 0.8; // turbine isentropic efficiency double etat = 0.8; // turbine isentropic efficiency
@ -71,23 +71,27 @@ void openRankine() {
double heat_in = h["3"] - h["2"]; double heat_in = h["3"] - h["2"];
double efficiency = work/heat_in; double efficiency = work/heat_in;
cout << "efficiency = " << efficiency << endl; cout << "efficiency = " << efficiency << endl;
#ifdef WIN32 #ifdef WIN32
cout << "press any key to end" << endl; #ifndef CXX_DEMO
char ch; cout << "press any key to end" << endl;
cin >> ch; char ch;
cin >> ch;
#endif #endif
#endif
return 0;
} }
#ifndef CXX_DEMO #ifndef CXX_DEMO
int main() { int main() {
try { try {
openRankine(); return openRankine(0, 0);
} }
catch (CanteraError) { catch (CanteraError) {
showErrors(cout); showErrors(cout);
return -1;
} }
} }
#endif #endif

View file

@ -1,86 +1,90 @@
/* ../config.h. Generated by configure. */ #include "../../config.h"
//
// Run the 'configure' script to generate 'config.h' from this input file.
//
#ifndef CT_CONFIG_H
#define CT_CONFIG_H
//------------------------ Development flags ------------------//
//
// These flags turn on or off features that are still in
// development and are not yet stable.
#undef DEV_EQUIL
//------------------------ Fortran settings -------------------//
// define types doublereal, integer, and ftnlen to match the
// corresponding Fortran data types on your system. The defaults
// are OK for most systems
typedef double doublereal; // Fortran double precision
typedef int integer; // Fortran integer
typedef int ftnlen; // Fortran hidden string length type
// Fortran compilers pass character strings in argument lists by // /* ../config.h. Generated by configure. */
// adding a hidden argement with the length of the string. Some // //
// compilers add the hidden length argument immediately after the // // Run the 'configure' script to generate 'config.h' from this input file.
// CHARACTER variable being passed, while others put all of the hidden // //
// length arguments at the end of the argument list. Define this if // #ifndef CT_CONFIG_H
// the lengths are at the end of the argument list. This is usually the // #define CT_CONFIG_H
// case for most unix Fortran compilers, but is (by default) false for
// Visual Fortran under Windows.
#define STRING_LEN_AT_END
// Define this if Fortran adds a trailing underscore to names in object files. // //------------------------ Development flags ------------------//
// For linux and most unix systems, this is the case. // //
#define FTN_TRAILING_UNDERSCORE // // These flags turn on or off features that are still in
// // development and are not yet stable.
// #undef DEV_EQUIL
//-------- LAPACK / BLAS --------- // //------------------------ Fortran settings -------------------//
// Define if you are using LAPACK and BLAS from the Intel Math Kernel
// Library
/* #undef HAVE_INTEL_MKL */
#define LAPACK_FTN_STRING_LEN_AT_END
#define LAPACK_NAMES_LOWERCASE
#define LAPACK_FTN_TRAILING_UNDERSCORE
//--------- operating system -------------------------------------- // // define types doublereal, integer, and ftnlen to match the
// // corresponding Fortran data types on your system. The defaults
// // are OK for most systems
// The configure script defines this if the operatiing system is Mac // typedef double doublereal; // Fortran double precision
// OS X, This used to add some Mac-specific directories to the default // typedef int integer; // Fortran integer
// data file search path. // typedef int ftnlen; // Fortran hidden string length type
#define DARWIN 0
/* #undef HAS_SSTREAM */
// Identify whether the operating system is cygwin's overlay of
// windows, with gcc being used as the compiler.
/* #undef CYGWIN */
// Identify whether the operating system is windows based, with
// microsoft vc++ being used as the compiler
#define WINMSVC
//--------- Fonts for reaction path diagrams ---------------------- // // Fortran compilers pass character strings in argument lists by
#define RXNPATH_FONT "Helvetica" // // adding a hidden argement with the length of the string. Some
// // compilers add the hidden length argument immediately after the
// // CHARACTER variable being passed, while others put all of the hidden
// // length arguments at the end of the argument list. Define this if
// // the lengths are at the end of the argument list. This is usually the
// // case for most unix Fortran compilers, but is (by default) false for
// // Visual Fortran under Windows.
// #define STRING_LEN_AT_END
//--------------------- Python ------------------------------------
// If this is defined, the Cantera Python interface will use the
// Numeric package; otherwise, it will use numarray.
/* #define HAS_NUMERIC 1 */
#define INCL_PURE_FLUIDS 1 // // Define this if Fortran adds a trailing underscore to names in object files.
// // For linux and most unix systems, this is the case.
// #define FTN_TRAILING_UNDERSCORE
//--------------------- compile options ----------------------------
/* #define USE_PCH 1 */
#endif // //-------- LAPACK / BLAS ---------
// // Define if you are using LAPACK and BLAS from the Intel Math Kernel
// // Library
// /* #undef HAVE_INTEL_MKL */
// #define LAPACK_FTN_STRING_LEN_AT_END
// #define LAPACK_NAMES_LOWERCASE
// #define LAPACK_FTN_TRAILING_UNDERSCORE
// //--------- operating system --------------------------------------
// // The configure script defines this if the operatiing system is Mac
// // OS X, This used to add some Mac-specific directories to the default
// // data file search path.
// #define DARWIN 0
// /* #undef HAS_SSTREAM */
// // Identify whether the operating system is cygwin's overlay of
// // windows, with gcc being used as the compiler.
// /* #undef CYGWIN */
// // Identify whether the operating system is windows based, with
// // microsoft vc++ being used as the compiler
// #define WINMSVC
// //--------- Fonts for reaction path diagrams ----------------------
// #define RXNPATH_FONT "Helvetica"
// //--------------------- Python ------------------------------------
// // If this is defined, the Cantera Python interface will use the
// // Numeric package; otherwise, it will use numarray.
// /* #define HAS_NUMERIC 1 */
// #define INCL_PURE_FLUIDS 1
// //--------------------- compile options ----------------------------
// /* #define USE_PCH 1 */
// #endif

View file

@ -359,7 +359,7 @@ namespace Cantera {
// //
// add a default data location for Mac OS X // add a default data location for Mac OS X
// //
if (DARWIN == 1) if (DARWIN > 0)
dirs.push_back("/Applications/Cantera/data"); dirs.push_back("/Applications/Cantera/data");
#endif #endif

View file

@ -279,6 +279,7 @@ docs:
depends: depends:
cd Cantera; @MAKE@ depends cd Cantera; @MAKE@ depends
cd tools; @MAKE@ depends cd tools; @MAKE@ depends
cd ext; @MAKE@ depends
ifeq ($(build_particles),1) ifeq ($(build_particles),1)
cd Cantera/cads; @MAKE@ depends cd Cantera/cads; @MAKE@ depends
endif endif

2
configure vendored
View file

@ -323,7 +323,7 @@ F77=${F77:=g77}
# Fortran 77 compiler flags. Note that the Fortran compiler flags must be set # Fortran 77 compiler flags. Note that the Fortran compiler flags must be set
# to produce object code compatible with the C/C++ compiler you are using. # to produce object code compatible with the C/C++ compiler you are using.
FFLAGS=${FFLAGS:='-O2'} FFLAGS=${FFLAGS:='-O2 -g'}
# the additional Fortran flags required for linking, if any. Leave commented # the additional Fortran flags required for linking, if any. Leave commented
# out if no additional flags are required. # out if no additional flags are required.

View file

@ -1 +1,11 @@
HFC134a.o: HFC134a.cpp HFC134a.h sub.h
Hydrogen.o: Hydrogen.cpp Hydrogen.h Sub.h
Methane.o: Methane.cpp Methane.h Sub.h
Nitrogen.o: Nitrogen.cpp Nitrogen.h Sub.h
Oxygen.o: Oxygen.cpp Oxygen.h Sub.h
RedlichKwong.o: RedlichKwong.cpp RedlichKwong.h Sub.h
Sub.o: Sub.cpp Sub.h
Water.o: Water.cpp Water.h Sub.h
lk.o: lk.cpp lk.h Sub.h
utils.o: utils.cpp subs.h HFC134a.h sub.h Hydrogen.h Methane.h Nitrogen.h \
Oxygen.h Water.h RedlichKwong.h utils.h

View file

@ -26,6 +26,8 @@ namespace tpx {
return new HFC134a; return new HFC134a;
else if (lcname == "rk") else if (lcname == "rk")
return new RedlichKwong; return new RedlichKwong;
else
return 0;
} }
Substance * GetSub(int isub) { Substance * GetSub(int isub) {

View file

@ -1,9 +1,9 @@
#!/bin/sh #!/bin/sh
if test $# = 0; then if test $# = 0; then
echo 'usage: erase <file>' echo 'usage: erase <file>'
fi else
file=$1 file=$1
erased_dir=$HOME/erased erased_dir=$HOME/erased
mv -f $file erased_dir mv -f $file erased_dir
cvs remove $file cvs remove $file
fi