mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
changed C++ demos
This commit is contained in:
@@ -8,11 +8,11 @@
|
||||
#############################################################################
|
||||
|
||||
# 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
|
||||
# and from C/C++ separately
|
||||
OBJS = kinetics1.o
|
||||
OBJS = demos.o
|
||||
|
||||
# additional flags to be passed to the linker. If your program
|
||||
# requires other external libraries, put them here
|
||||
@@ -62,7 +62,7 @@ $(PROGRAM): $(OBJS) $(CANTERA_LIBDIR)/libcantera.a
|
||||
|
||||
test:
|
||||
@MAKE@ $(PROGRAM)
|
||||
./runtest
|
||||
echo 100 | $(PROGRAM) > $(PROGRAM).out
|
||||
|
||||
install:
|
||||
@INSTALL@ -d @ct_demodir@/cxx
|
||||
|
||||
@@ -8,48 +8,66 @@
|
||||
#include "flamespeed.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
|
||||
exfun fex[] = {kinetics1, rankine, flamespeed};
|
||||
exfun fex[] = {kinetics1, openRankine, flamespeed};
|
||||
|
||||
string demostr[] = {"zero-D kinetics ",
|
||||
"open Rankine cycle ",
|
||||
"flamespeed "};
|
||||
|
||||
int np[] = {0, 0, 1};
|
||||
double p[] = {0, 0, 0.9};
|
||||
|
||||
#define NDEMOS 3
|
||||
|
||||
main() {
|
||||
int mainmenu() {
|
||||
int i, idemo;
|
||||
cout << "C++ Demo Programs " << endl;
|
||||
for (i = 0; i < NDEMOS; i++) {
|
||||
cout << i << ") " << demostr[i] << endl;
|
||||
cout << " " << i+1 << ") " << demostr[i] << endl;
|
||||
}
|
||||
cout << i << ")" << "run all demos" << endl;
|
||||
cout << "Enter demo number: " << 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) {
|
||||
return fex[idemo]();
|
||||
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) {
|
||||
int iout = 0;
|
||||
else if (idemo >= NDEMOS+1) {
|
||||
clock_t t0 = clock();
|
||||
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 0;
|
||||
}
|
||||
catch (CanteraError) {
|
||||
showErrors(cerr);
|
||||
appDelete();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
while (1 > 0) {
|
||||
i = mainmenu();
|
||||
appdelete();
|
||||
if (i == -99) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
using namespace Cantera;
|
||||
|
||||
int demo() {
|
||||
int flamespeed(int np, void* p) {
|
||||
try {
|
||||
int i;
|
||||
IdealGasMix gas("gri30.cti","gri30_mix");
|
||||
@@ -32,9 +32,12 @@ int demo() {
|
||||
vector_fp x;
|
||||
x.resize(nsp);
|
||||
|
||||
doublereal phi=1.1;
|
||||
cout << "Enter phi: ";
|
||||
cin >> phi;
|
||||
double phi = 0.0;
|
||||
if (np > 0) phi = *(double*)(p);
|
||||
if (phi == 0.0) {
|
||||
cout << "Enter phi: ";
|
||||
cin >> phi;
|
||||
}
|
||||
|
||||
doublereal C_atoms=1.0;
|
||||
doublereal H_atoms=4.0;
|
||||
@@ -65,9 +68,9 @@ int demo() {
|
||||
doublereal Tad=gas.temperature();
|
||||
cout << phi<<' '<<Tad<<endl;
|
||||
|
||||
double Tin=temp;
|
||||
double Tout=Tad;
|
||||
double breakpt=0.2;
|
||||
//double Tin=temp;
|
||||
//double Tout=Tad;
|
||||
//double breakpt=0.2;
|
||||
|
||||
|
||||
//============= build each domain ========================
|
||||
@@ -212,8 +215,9 @@ int demo() {
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef CXX_DEMO
|
||||
int main() {
|
||||
return demo();
|
||||
return flamespeed(0, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "example_utils.h"
|
||||
|
||||
|
||||
int kinetics1() {
|
||||
int kinetics1(int np, void* p) {
|
||||
|
||||
cout << "Constant-pressure ignition of a "
|
||||
<< "hydrogen/oxygen/nitrogen"
|
||||
@@ -113,7 +113,7 @@ int kinetics1() {
|
||||
int main() {
|
||||
|
||||
try {
|
||||
return kinetics1();
|
||||
return kinetics1(0, 0);
|
||||
}
|
||||
// handle exceptions thrown by Cantera
|
||||
catch (CanteraError) {
|
||||
|
||||
@@ -36,7 +36,7 @@ void printStates() {
|
||||
}
|
||||
}
|
||||
|
||||
void openRankine() {
|
||||
int openRankine(int np, void* p) {
|
||||
|
||||
double etap = 0.6; // pump isentropic efficiency
|
||||
double etat = 0.8; // turbine isentropic efficiency
|
||||
@@ -71,23 +71,27 @@ void openRankine() {
|
||||
|
||||
double heat_in = h["3"] - h["2"];
|
||||
double efficiency = work/heat_in;
|
||||
cout << "efficiency = " << efficiency << endl;
|
||||
cout << "efficiency = " << efficiency << endl;
|
||||
#ifdef WIN32
|
||||
cout << "press any key to end" << endl;
|
||||
char ch;
|
||||
cin >> ch;
|
||||
#ifndef CXX_DEMO
|
||||
cout << "press any key to end" << endl;
|
||||
char ch;
|
||||
cin >> ch;
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifndef CXX_DEMO
|
||||
int main() {
|
||||
|
||||
try {
|
||||
openRankine();
|
||||
return openRankine(0, 0);
|
||||
}
|
||||
catch (CanteraError) {
|
||||
showErrors(cout);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,86 +1,90 @@
|
||||
/* ../config.h. Generated by configure. */
|
||||
//
|
||||
// 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
|
||||
#include "../../config.h"
|
||||
|
||||
|
||||
|
||||
// Fortran compilers pass character strings in argument lists by
|
||||
// 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
|
||||
// /* ../config.h. Generated by configure. */
|
||||
// //
|
||||
// // Run the 'configure' script to generate 'config.h' from this input file.
|
||||
// //
|
||||
// #ifndef CT_CONFIG_H
|
||||
// #define CT_CONFIG_H
|
||||
|
||||
|
||||
// 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
|
||||
// //------------------------ Development flags ------------------//
|
||||
// //
|
||||
// // These flags turn on or off features that are still in
|
||||
// // development and are not yet stable.
|
||||
|
||||
// #undef DEV_EQUIL
|
||||
|
||||
|
||||
//-------- 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
|
||||
// //------------------------ Fortran settings -------------------//
|
||||
|
||||
|
||||
//--------- 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
|
||||
// OS X, This used to add some Mac-specific directories to the default
|
||||
// data file search path.
|
||||
#define DARWIN 0
|
||||
/* #undef HAS_SSTREAM */
|
||||
// typedef double doublereal; // Fortran double precision
|
||||
// typedef int integer; // Fortran integer
|
||||
// typedef int ftnlen; // Fortran hidden string length type
|
||||
|
||||
// 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"
|
||||
// // Fortran compilers pass character strings in argument lists by
|
||||
// // 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
|
||||
|
||||
@@ -359,7 +359,7 @@ namespace Cantera {
|
||||
//
|
||||
// add a default data location for Mac OS X
|
||||
//
|
||||
if (DARWIN == 1)
|
||||
if (DARWIN > 0)
|
||||
dirs.push_back("/Applications/Cantera/data");
|
||||
#endif
|
||||
|
||||
|
||||
@@ -279,6 +279,7 @@ docs:
|
||||
depends:
|
||||
cd Cantera; @MAKE@ depends
|
||||
cd tools; @MAKE@ depends
|
||||
cd ext; @MAKE@ depends
|
||||
ifeq ($(build_particles),1)
|
||||
cd Cantera/cads; @MAKE@ depends
|
||||
endif
|
||||
|
||||
2
configure
vendored
2
configure
vendored
@@ -323,7 +323,7 @@ F77=${F77:=g77}
|
||||
|
||||
# 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.
|
||||
FFLAGS=${FFLAGS:='-O2'}
|
||||
FFLAGS=${FFLAGS:='-O2 -g'}
|
||||
|
||||
# the additional Fortran flags required for linking, if any. Leave commented
|
||||
# out if no additional flags are required.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -26,6 +26,8 @@ namespace tpx {
|
||||
return new HFC134a;
|
||||
else if (lcname == "rk")
|
||||
return new RedlichKwong;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
Substance * GetSub(int isub) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#!/bin/sh
|
||||
if test $# = 0; then
|
||||
echo 'usage: erase <file>'
|
||||
fi
|
||||
else
|
||||
file=$1
|
||||
erased_dir=$HOME/erased
|
||||
mv -f $file erased_dir
|
||||
cvs remove $file
|
||||
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user