Added a demo program to test suite.

object is to add all demos to test suite
This commit is contained in:
Harry Moffat 2008-01-06 19:48:07 +00:00
parent 1fb1c4367d
commit c271730b49
5 changed files with 275 additions and 0 deletions

View file

@ -0,0 +1,10 @@
.depends
Makefile
csvCode.txt
ct2ctml.log
diff_test.out
liquidvapor.xml
output.txt
rankine
rankine.d

View file

@ -0,0 +1,126 @@
#!/bin/sh
############################################################################
#
# Makefile to compile and link a C++ application to
# Cantera.
#
#############################################################################
# Addition to suffixes
.SUFFIXES : .d
# the name of the executable program to be created
PROG_NAME = rankine
# The object files to be linked together.
OBJS = rankine.o
# additional flags to be passed to the linker. If your program
# requires other external libraries, put them here
LINK_OPTIONS = @EXTRA_LINK@
# This variable determines whether we are making this example in the
# build tree environment or in the install tree environment.
in_CanteraBuildTree = 1
#############################################################################
# Check to see whether we are in the msvc++ environment
os_is_win = @OS_IS_WIN@
# Fortran libraries
FORT_LIBS = @FLIBS@
# the C++ compiler
CXX = @CXX@
# the directory where Cantera include files may be found.
ifeq ($(in_CanteraBuildTree),1)
CANTERA_INCROOTDIR=@ctroot@/build/include
else
CANTERA_INCROOTDIR=@ct_incroot@
endif
CANTERA_INCLUDES=-I$(CANTERA_INCROOTDIR) -I$(CANTERA_INCROOTDIR)/cantera
# LOCAL_DEFS = -DDEBUG_CHEMEQUIL
# LOCAL_DEFS = -DEBUG_BASISOPTIMIZE
#
# C++ compile flags
CXX_FLAGS = @CXXFLAGS@ $(CANTERA_INCLUDES) $(LOCAL_DEFS)
# Ending C++ linking libraries
LCXX_END_LIBS = @LCXX_END_LIBS@
# the directory where the Cantera libraries are located
ifeq ($(in_CanteraBuildTree),1)
CANTERA_LIBDIR=@buildlib@
else
CANTERA_LIBDIR=@ct_libdir@
endif
# required Cantera libraries
CANTERA_LIBS = -L$(CANTERA_LIBDIR) @LOCAL_LIBS@ -lctcxx
ifeq ($(in_CanteraBuildTree),1)
CANTERA_LIBS_DEP = @LOCAL_LIBS_DEP@ $(CANTERA_LIBDIR)/libctcxx.a
else
CANTERA_LIBS_DEP = @INSTALL_LIBS_DEP@ $(CANTERA_LIBDIR)/libctcxx.a
endif
#
# Alternate form of dependencies: (uses a gnu make extensions)
ALT_LIBS_DEP := $(addprefix $(CANTER_LIBDIR), @RAW_LIBS_DEP@ libctcxx.a)
# flags passed to the C++ compiler/linker for the linking step
LCXX_FLAGS = @CXXFLAGS@
# How to compile C++ source files to object files
.cpp.o:
$(CXX) -c $< -I$(CANTERA_INCDIR) $(CXX_FLAGS)
# How to compile the dependency file
.cpp.d:
@CXX_DEPENDS@ -I$(CANTERA_INCDIR) $(CXX_FLAGS) $*.cpp > $*.d
# List of dependency files to be created
DEPENDS=$(OBJS:.o=.d)
# Program Name
PROGRAM = $(PROG_NAME)$(EXE_EXT)
all: $(PROGRAM)
$(PROGRAM): $(OBJS) $(CANTERA_LIBS_DEP)
$(CXX) -o $(PROGRAM) $(OBJS) $(LCXX_FLAGS) $(LINK_OPTIONS) \
$(CANTERA_LIBS) @LIBS@ $(FORT_LIBS) \
$(LCXX_END_LIBS)
#
# depends target -> forces recalculation of dependencies
depends:
$(RM) *.d .depends
@MAKE@ .depends
.depends: $(DEPENDS)
cat *.d > .depends
# Do the test -> For the windows vc++ environment, we have to skip checking on
# whether the program is uptodate, because we don't utilize make
# in that environment to build programs.
test:
ifeq ($(os_is_win), 1)
else
@ @MAKE@ -s $(PROGRAM)
endif
@ ./runtest
clean:
$(RM) $(OBJS) $(PROGRAM) $(DEPENDS) .depends
../../bin/rm_cvsignore
(if test -d SunWS_cache ; then \
$(RM) -rf SunWS_cache ; \
fi )
ifeq ($(wildcard .depends), .depends)
include .depends
endif

View file

@ -0,0 +1,7 @@
1 300 101325 -1.58581e+07 3913.25 0
2s 300.014 800000 -1.58574e+07 3913.25 0
2 300.126 800000 -1.58569e+07 3914.81 0
3 443.624 800000 -1.32016e+07 10183 1
4s 373.177 101325 -1.3553e+07 10183 0.89
4 373.177 101325 -1.34827e+07 10371.4 0.92
efficiency = 0.105873

View file

@ -0,0 +1,100 @@
// 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

View file

@ -0,0 +1,32 @@
#!/bin/sh
#
#
temp_success="1"
/bin/rm -f output.txt outputa.txt
testName="rankine"
#################################################################
#
#################################################################
CANTERA_DATA=${CANTERA_DATA:=../../data/inputs}; export CANTERA_DATA
CANTERA_BIN=${CANTERA_BIN:=../../bin}
./rankine > output.txt
retnStat=$?
if [ $retnStat != "0" ]
then
temp_success="0"
echo "$testName returned with bad status, $retnStat, check output"
fi
diff -w output.txt output_blessed.txt > diff_test.out
retnStat=$?
if [ $retnStat = "0" ]
then
echo "successful diff comparison on $testName test"
else
echo "unsuccessful diff comparison on $testName test"
echo "FAILED" > csvCode.txt
temp_success="0"
fi