Committing reworked demos
This commit is contained in:
parent
b65ee445c2
commit
b23586ae14
13 changed files with 5404 additions and 0 deletions
11
Cantera/cxx/demos/combustor/.cvsignore
Normal file
11
Cantera/cxx/demos/combustor/.cvsignore
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
diff_out_0.txt
|
||||
Makefile
|
||||
Makefile.install
|
||||
air.xml
|
||||
combustor
|
||||
combustor_cxx.csv
|
||||
ct2ctml.log
|
||||
diff_csv.txt
|
||||
gri30.xml
|
||||
output_0.txt
|
||||
|
||||
117
Cantera/cxx/demos/combustor/Makefile.in
Normal file
117
Cantera/cxx/demos/combustor/Makefile.in
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
############################################################################
|
||||
#
|
||||
# Makefile to compile and link a C++ application to
|
||||
# Cantera.
|
||||
#
|
||||
#############################################################################
|
||||
.SUFFIXES :
|
||||
.SUFFIXES : .cpp .d .o .dh .h
|
||||
|
||||
# the name of the executable program to be created
|
||||
PROG_NAME = combustor
|
||||
|
||||
# the object files to be linked together. List those generated from Fortran
|
||||
# and from C/C++ separately
|
||||
OBJS = combustor.o
|
||||
|
||||
# additional flags to be passed to the linker. If your program
|
||||
# requires other external libraries, put them here
|
||||
LINK_OPTIONS = @EXTRA_LINK@
|
||||
|
||||
#############################################################################
|
||||
# True if we are in the source directory tree
|
||||
srcdirtree=1
|
||||
|
||||
# Fortran libraries
|
||||
FORT_LIBS = @FLIBS@
|
||||
|
||||
# Purify options
|
||||
PURIFY=@PURIFY@
|
||||
|
||||
# the C++ compiler
|
||||
CXX = @CXX@
|
||||
|
||||
# C++ compile flags
|
||||
CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@
|
||||
|
||||
# external libraries
|
||||
EXT_LIBS = @LOCAL_LIBS@ -ltpx -lctcxx
|
||||
|
||||
# Ending C++ linking libraries
|
||||
LCXX_END_LIBS = @LCXX_END_LIBS@
|
||||
|
||||
# the directory where the Cantera libraries are located
|
||||
CANTERA_LIBDIR=@buildlib@
|
||||
|
||||
# required Cantera libraries
|
||||
CANTERA_LIBS =
|
||||
|
||||
# Depends
|
||||
ifeq ($srcdirtree, 1)
|
||||
LOCAL_DEFNS = -DSRCDIRTREE
|
||||
else
|
||||
LOCAL_DEFNS =
|
||||
endif
|
||||
|
||||
# the directory where Cantera include files may be found.
|
||||
CANTERA_INCDIR=@ctroot@/build/include
|
||||
|
||||
# flags passed to the C++ compiler/linker for the linking step
|
||||
LCXX_FLAGS = -L$(CANTERA_LIBDIR) @LOCAL_LIB_DIRS@ @CXXFLAGS@
|
||||
|
||||
# how to compile C++ source files to object files
|
||||
.@CXX_EXT@.@OBJ_EXT@:
|
||||
$(PURIFY) $(CXX) -c $< -I$(CANTERA_INCDIR) $(CXX_FLAGS) $(LOCAL_DEFNS)
|
||||
|
||||
# how to create a dependency file
|
||||
.@CXX_EXT@.d:
|
||||
@CXX_DEPENDS@ -I$(CANTERA_INCDIR) $(CXX_FLAGS) $(LOCAL_DEFNS) $*.cpp > $*.d
|
||||
|
||||
PROGRAM = $(PROG_NAME)$(EXE_EXT)
|
||||
|
||||
DEPENDS = $(OBJS:.o=.d)
|
||||
|
||||
all: $(PROGRAM)
|
||||
|
||||
$(PROGRAM): $(OBJS)
|
||||
$(PURIFY) $(CXX) -o $(PROGRAM) $(OBJS) $(LCXX_FLAGS) $(CANTERA_LIBS) \
|
||||
$(LINK_OPTIONS) $(EXT_LIBS) @LIBS@ $(FORT_LIBS) \
|
||||
$(LCXX_END_LIBS)
|
||||
|
||||
test:
|
||||
@MAKE@ $(PROGRAM)
|
||||
./runtest
|
||||
|
||||
INSTALL_DIR=@ct_demodir@/cxx/combustor
|
||||
|
||||
install:
|
||||
@INSTALL@ -d $(INSTALL_DIR)
|
||||
@INSTALL@ -c -m ug+rw,o+r Makefile.install $(INSTALL_DIR)/Makefile
|
||||
@(for ihhh in *.cpp *blessed* ; do \
|
||||
@INSTALL@ $${ihhh} -m ug+rw,o+r $(INSTALL_DIR) ; \
|
||||
echo "@INSTALL@ $${ihhh} -m ug+rw,o+r $(INSTALL_DIR)" ; \
|
||||
done )
|
||||
@INSTALL@ runtest $(INSTALL_DIR) ;
|
||||
|
||||
|
||||
depends: $(DEPENDS)
|
||||
@MAKE@ .depends
|
||||
|
||||
.depends: $(DEPENDS)
|
||||
cat $(DEPENDS) > .depends
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) $(PROGRAM) .depends *.d
|
||||
$(RM) ct2ctml.log diff* output_0.txt transport_log.xml \
|
||||
combustor_cxx.csv
|
||||
(if test -d SunWS_cache ; then \
|
||||
$(RM) -rf SunWS_cache ; \
|
||||
fi )
|
||||
|
||||
TAGS:
|
||||
etags *.h *.cpp
|
||||
|
||||
ifeq ($(wildcard .depends), .depends)
|
||||
include .depends
|
||||
endif
|
||||
|
||||
97
Cantera/cxx/demos/combustor/Makefile.install.in
Normal file
97
Cantera/cxx/demos/combustor/Makefile.install.in
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#!/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 = combustor
|
||||
|
||||
# the object files to be linked together. List those generated from Fortran
|
||||
# and from C/C++ separately
|
||||
OBJS = combustor.o
|
||||
|
||||
# additional flags to be passed to the linker. If your program
|
||||
# requires other external libraries, put them here
|
||||
LINK_OPTIONS =
|
||||
|
||||
#############################################################################
|
||||
# These links are to Cantera's install space
|
||||
CANTERA_INCROOT = @ct_incroot@
|
||||
#
|
||||
# Bring in the Cantera includes through the .mak file
|
||||
#
|
||||
include $(CANTERA_INCROOT)/cantera/Cantera.mak
|
||||
|
||||
# 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.
|
||||
#
|
||||
INCLUDE_DIRS = -I../../src -I$(CANTERA_INCROOT)
|
||||
#
|
||||
# C++ compile flags
|
||||
CXX_FLAGS = @CXXFLAGS@ $(INCLUDE_DIRS) -DUSE_VCSNONIDEAL
|
||||
#
|
||||
# Ending C++ linking libraries
|
||||
LCXX_END_LIBS = @LCXX_END_LIBS@
|
||||
|
||||
# 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) $(CXX_FLAGS) -c $<
|
||||
|
||||
# How to compile the dependency file
|
||||
.cpp.d:
|
||||
@CXX_DEPENDS@ $(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_CORE_LIBS_DEP)
|
||||
$(CXX) -o $(PROGRAM) $(OBJS) $(LCXX_FLAGS) $(LINK_OPTIONS) \
|
||||
$(CANTERA_TOTAL_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@ $(PROGRAM)
|
||||
endif
|
||||
./runtest
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) *.o $(PROGRAM) $(DEPENDS) .depends
|
||||
(if test -d SunWS_cache ; then \
|
||||
$(RM) -rf SunWS_cache ; \
|
||||
fi )
|
||||
|
||||
138
Cantera/cxx/demos/combustor/combustor.cpp
Normal file
138
Cantera/cxx/demos/combustor/combustor.cpp
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
|
||||
// A combustor. Two separate stream - one pure methane and the other
|
||||
// air, both at 300 K and 1 atm flow into an adiabatic combustor where
|
||||
// they mix. We are interested in the steady-state burning
|
||||
// solution. Since at 300 K no reaction will occur between methane and
|
||||
// air, we need to use an 'igniter' to initiate the chemistry. A simple
|
||||
// igniter is a pulsed flow of atomic hydrogen. After the igniter is
|
||||
// turned off, the system approaches the steady burning solution."""
|
||||
|
||||
#include <cantera/Cantera.h>
|
||||
#include <cantera/zerodim.h>
|
||||
#include <cantera/IdealGasMix.h>
|
||||
|
||||
using namespace CanteraZeroD;
|
||||
|
||||
void runexample() {
|
||||
|
||||
// use reaction mechanism GRI-Mech 3.0
|
||||
IdealGasMix gas("gri30.cti", "gri30");
|
||||
int nsp = gas.nSpecies();
|
||||
|
||||
// create a reservoir for the fuel inlet, and set to pure methane.
|
||||
Reservoir fuel_in;
|
||||
gas.setState_TPX(300.0, OneAtm, "CH4:1.0");
|
||||
fuel_in.insert(gas);
|
||||
double fuel_mw = gas.meanMolecularWeight();
|
||||
|
||||
// create a reservoir for the air inlet
|
||||
Reservoir air_in;
|
||||
IdealGasMix air("air.cti");
|
||||
gas.setState_TPX(300.0, OneAtm, "N2:0.78, O2:0.21, AR:0.01");
|
||||
double air_mw = air.meanMolecularWeight();
|
||||
air_in.insert(gas);
|
||||
|
||||
// to ignite the fuel/air mixture, we'll introduce a pulse of radicals.
|
||||
// The steady-state behavior is independent of how we do this, so we'll
|
||||
// just use a stream of pure atomic hydrogen.
|
||||
gas.setState_TPX(300.0, OneAtm, "H:1.0");
|
||||
Reservoir igniter;
|
||||
igniter.insert(gas);
|
||||
|
||||
|
||||
// create the combustor, and fill it in initially with N2
|
||||
gas.setState_TPX(300.0, OneAtm, "N2:1.0");
|
||||
Reactor combustor;
|
||||
combustor.insert(gas);
|
||||
combustor.setInitialVolume(1.0);
|
||||
|
||||
|
||||
// create a reservoir for the exhaust. The initial composition
|
||||
// doesn't matter.
|
||||
Reservoir exhaust;
|
||||
exhaust.insert(gas);
|
||||
|
||||
|
||||
// lean combustion, phi = 0.5
|
||||
double equiv_ratio = 0.5;
|
||||
|
||||
// compute fuel and air mass flow rates
|
||||
double factor = 0.1;
|
||||
double air_mdot = factor*9.52*air_mw;
|
||||
double fuel_mdot = factor*equiv_ratio*fuel_mw;
|
||||
|
||||
// create and install the mass flow controllers. Controllers
|
||||
// m1 and m2 provide constant mass flow rates, and m3 provides
|
||||
// a short Gaussian pulse only to ignite the mixture
|
||||
MassFlowController m1;
|
||||
m1.install(fuel_in, combustor);
|
||||
m1.setMassFlowRate(fuel_mdot);
|
||||
|
||||
// Now create the air mass flow controller. Note that this connects
|
||||
// two reactors with different reaction mechanisms and different
|
||||
// numbers of species. Downstream and upstream species are matched by
|
||||
// name.
|
||||
MassFlowController m2;
|
||||
m2.install(air_in, combustor);
|
||||
m2.setMassFlowRate(air_mdot);
|
||||
|
||||
|
||||
// The igniter will use a Guassiam 'functor' object to specify the
|
||||
// time-dependent igniter mass flow rate.
|
||||
double A = 0.1;
|
||||
double FWHM = 0.2;
|
||||
double t0 = 1.0;
|
||||
Gaussian igniter_mdot(A, t0, FWHM);
|
||||
|
||||
MassFlowController m3;
|
||||
m3.install(igniter, combustor);
|
||||
m3.setFunction(&igniter_mdot);
|
||||
|
||||
// put a valve on the exhaust line to regulate the pressure
|
||||
Valve v;
|
||||
v.install(combustor, exhaust);
|
||||
double Kv = 1.0;
|
||||
v.setParameters(1, &Kv);
|
||||
|
||||
// the simulation only contains one reactor
|
||||
ReactorNet sim;
|
||||
sim.addReactor(&combustor);
|
||||
|
||||
// take single steps to 6 s, writing the results to a CSV file
|
||||
// for later plotting.
|
||||
double tfinal = 6.0;
|
||||
double tnow = 0.0;
|
||||
double tres;
|
||||
int k;
|
||||
|
||||
ofstream f("combustor_cxx.csv");
|
||||
|
||||
while (tnow < tfinal) {
|
||||
tnow = sim.step(tfinal);
|
||||
tres = combustor.mass()/v.massFlowRate();
|
||||
f << tnow << ", "
|
||||
<< combustor.temperature() << ", "
|
||||
<< tres << ", ";
|
||||
ThermoPhase& c = combustor.contents();
|
||||
for (k = 0; k < nsp; k++) {
|
||||
f << c.moleFraction(k) << ", ";
|
||||
}
|
||||
f << endl;
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
try {
|
||||
runexample();
|
||||
return 0;
|
||||
}
|
||||
// handle exceptions thrown by Cantera
|
||||
catch (CanteraError) {
|
||||
showErrors(cout);
|
||||
cout << " terminating... " << endl;
|
||||
appdelete();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
4593
Cantera/cxx/demos/combustor/combustor_blessed_0.csv
Normal file
4593
Cantera/cxx/demos/combustor/combustor_blessed_0.csv
Normal file
File diff suppressed because it is too large
Load diff
6
Cantera/cxx/demos/combustor/output_0_blessed.txt
Normal file
6
Cantera/cxx/demos/combustor/output_0_blessed.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Adding reactor (none)
|
||||
Initializing reactor network.
|
||||
Reactor 0: 55 variables.
|
||||
0 sensitivity params.
|
||||
Number of equations: 55
|
||||
Maximum time step: 6
|
||||
63
Cantera/cxx/demos/combustor/runtest
Executable file
63
Cantera/cxx/demos/combustor/runtest
Executable file
|
|
@ -0,0 +1,63 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
#
|
||||
temp_success="1"
|
||||
/bin/rm -f output_0.txt combustor_cxx.csv diff_csv.txt diff_out_0.txt
|
||||
|
||||
##########################################################################
|
||||
|
||||
prog=combustor
|
||||
if test ! -x $prog ; then
|
||||
echo $prog ' does not exist'
|
||||
exit -1
|
||||
fi
|
||||
#################################################################
|
||||
#
|
||||
CANTERA_DATA=${CANTERA_DATA:=../../../data/inputs}; export CANTERA_DATA
|
||||
CANTERA_BIN=${CANTERA_BIN:=../../../bin}
|
||||
|
||||
#################################################################
|
||||
|
||||
$prog > output_0.txt <<+
|
||||
1.0
|
||||
+
|
||||
retnStat=$?
|
||||
if [ $retnStat != "0" ]
|
||||
then
|
||||
temp_success="0"
|
||||
echo "$prog returned with bad status, $retnStat, check output"
|
||||
fi
|
||||
|
||||
diff -w output_0_blessed.txt output_0.txt > diff_out_0.txt
|
||||
retnStat_0=$?
|
||||
|
||||
csvdiff -a 1.0E-50 combustor_blessed_0.csv combustor_cxx.csv > diff_csv.txt
|
||||
retnStat_csv_0=$?
|
||||
|
||||
retnTotal=1
|
||||
if test $retnStat_0 = "0"
|
||||
then
|
||||
retnTotal=0
|
||||
fi
|
||||
|
||||
retnCSVTotal=1
|
||||
if test $retnStat_csv_0 = "1"
|
||||
then
|
||||
retnCSVTotal=0
|
||||
fi
|
||||
|
||||
if test $retnCSVTotal = "0"
|
||||
then
|
||||
echo "Successful test comparison on "`pwd`
|
||||
if test $retnTotal = "1"
|
||||
then
|
||||
echo " But text files show differences see diff_out_0.txt"
|
||||
fi
|
||||
else
|
||||
echo "Unsuccessful test comparison on "`pwd` " test"
|
||||
if test $retnTotal != "0"
|
||||
then
|
||||
echo " files are different - see diff_test*.txt"
|
||||
fi
|
||||
fi
|
||||
|
||||
9
Cantera/cxx/demos/rankine/.cvsignore
Normal file
9
Cantera/cxx/demos/rankine/.cvsignore
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Makefile
|
||||
Makefile.install
|
||||
ct2ctml.log
|
||||
diff_out_0.txt
|
||||
gri30.xml
|
||||
liquidvapor.xml
|
||||
output_0.txt
|
||||
rankine
|
||||
transport_log.xml
|
||||
117
Cantera/cxx/demos/rankine/Makefile.in
Normal file
117
Cantera/cxx/demos/rankine/Makefile.in
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
############################################################################
|
||||
#
|
||||
# Makefile to compile and link a C++ application to
|
||||
# Cantera.
|
||||
#
|
||||
#############################################################################
|
||||
.SUFFIXES :
|
||||
.SUFFIXES : .cpp .d .o .d .h
|
||||
|
||||
|
||||
# the name of the executable program to be created
|
||||
PROG_NAME = rankine
|
||||
|
||||
# the object files to be linked together. List those generated from Fortran
|
||||
# and from C/C++ separately
|
||||
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@
|
||||
|
||||
#############################################################################
|
||||
# True if we are in the source directory tree
|
||||
srcdirtree=1
|
||||
|
||||
# Fortran libraries
|
||||
FORT_LIBS = @FLIBS@
|
||||
|
||||
# Purify options
|
||||
PURIFY=@PURIFY@
|
||||
|
||||
# the C++ compiler
|
||||
CXX = @CXX@
|
||||
|
||||
# C++ compile flags
|
||||
CXX_FLAGS = @CXXFLAGS@ @CXX_INCLUDES@
|
||||
|
||||
# external libraries
|
||||
EXT_LIBS = @LOCAL_LIBS@ -ltpx -lctcxx
|
||||
|
||||
# Ending C++ linking libraries
|
||||
LCXX_END_LIBS = @LCXX_END_LIBS@
|
||||
|
||||
# the directory where the Cantera libraries are located
|
||||
CANTERA_LIBDIR=@buildlib@
|
||||
|
||||
# required Cantera libraries
|
||||
CANTERA_LIBS =
|
||||
|
||||
# Depends
|
||||
ifeq ($srcdirtree, 1)
|
||||
LOCAL_DEFNS = -DSRCDIRTREE
|
||||
else
|
||||
LOCAL_DEFNS =
|
||||
endif
|
||||
|
||||
# the directory where Cantera include files may be found.
|
||||
CANTERA_INCDIR=@ctroot@/build/include
|
||||
|
||||
# flags passed to the C++ compiler/linker for the linking step
|
||||
LCXX_FLAGS = -L$(CANTERA_LIBDIR) @LOCAL_LIB_DIRS@ @CXXFLAGS@
|
||||
|
||||
# how to compile C++ source files to object files
|
||||
.@CXX_EXT@.@OBJ_EXT@:
|
||||
$(PURIFY) $(CXX) -c $< -I$(CANTERA_INCDIR) $(CXX_FLAGS) $(LOCAL_DEFNS)
|
||||
|
||||
# how to create a dependency file
|
||||
.@CXX_EXT@.d:
|
||||
@CXX_DEPENDS@ -I$(CANTERA_INCDIR) $(CXX_FLAGS) $(LOCAL_DEFNS) $*.cpp > $*.d
|
||||
|
||||
PROGRAM = $(PROG_NAME)$(EXE_EXT)
|
||||
|
||||
DEPENDS = $(OBJS:.o=.d)
|
||||
|
||||
all: $(PROGRAM)
|
||||
|
||||
$(PROGRAM): $(OBJS)
|
||||
$(PURIFY) $(CXX) -o $(PROGRAM) $(OBJS) $(LCXX_FLAGS) $(CANTERA_LIBS) \
|
||||
$(LINK_OPTIONS) $(EXT_LIBS) @LIBS@ $(FORT_LIBS) \
|
||||
$(LCXX_END_LIBS)
|
||||
|
||||
test:
|
||||
@MAKE@ $(PROGRAM)
|
||||
./runtest
|
||||
|
||||
INSTALL_DIR=@ct_demodir@/cxx/rankine
|
||||
|
||||
install:
|
||||
@INSTALL@ -d $(INSTALL_DIR)
|
||||
@INSTALL@ -c -m ug+rw,o+r Makefile.install $(INSTALL_DIR)/Makefile
|
||||
@(for ihhh in *.cpp *blessed* ; do \
|
||||
@INSTALL@ $${ihhh} -m ug+rw,o+r $(INSTALL_DIR) ; \
|
||||
echo "@INSTALL@ $${ihhh} -m ug+rw,o+r $(INSTALL_DIR)" ; \
|
||||
done )
|
||||
@INSTALL@ runtest $(INSTALL_DIR) ;
|
||||
|
||||
|
||||
depends: $(DEPENDS)
|
||||
@MAKE@ .depends
|
||||
|
||||
.depends: $(DEPENDS)
|
||||
cat $(DEPENDS) > .depends
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) $(PROGRAM) .depends *.d
|
||||
$(RM) ct2ctml.log diff* output_0.txt transport_log.xml
|
||||
(if test -d SunWS_cache ; then \
|
||||
$(RM) -rf SunWS_cache ; \
|
||||
fi )
|
||||
|
||||
TAGS:
|
||||
etags *.h *.cpp
|
||||
|
||||
ifeq ($(wildcard .depends), .depends)
|
||||
include .depends
|
||||
endif
|
||||
|
||||
97
Cantera/cxx/demos/rankine/Makefile.install.in
Normal file
97
Cantera/cxx/demos/rankine/Makefile.install.in
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#!/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. List those generated from Fortran
|
||||
# and from C/C++ separately
|
||||
OBJS = rankine.o
|
||||
|
||||
# additional flags to be passed to the linker. If your program
|
||||
# requires other external libraries, put them here
|
||||
LINK_OPTIONS =
|
||||
|
||||
#############################################################################
|
||||
# These links are to Cantera's install space
|
||||
CANTERA_INCROOT = @ct_incroot@
|
||||
#
|
||||
# Bring in the Cantera includes through the .mak file
|
||||
#
|
||||
include $(CANTERA_INCROOT)/cantera/Cantera.mak
|
||||
|
||||
# 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.
|
||||
#
|
||||
INCLUDE_DIRS = -I../../src -I$(CANTERA_INCROOT)
|
||||
#
|
||||
# C++ compile flags
|
||||
CXX_FLAGS = @CXXFLAGS@ $(INCLUDE_DIRS) -DUSE_VCSNONIDEAL
|
||||
#
|
||||
# Ending C++ linking libraries
|
||||
LCXX_END_LIBS = @LCXX_END_LIBS@
|
||||
|
||||
# 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) $(CXX_FLAGS) -c $<
|
||||
|
||||
# How to compile the dependency file
|
||||
.cpp.d:
|
||||
@CXX_DEPENDS@ $(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_CORE_LIBS_DEP)
|
||||
$(CXX) -o $(PROGRAM) $(OBJS) $(LCXX_FLAGS) $(LINK_OPTIONS) \
|
||||
$(CANTERA_TOTAL_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@ $(PROGRAM)
|
||||
endif
|
||||
./runtest
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) *.o $(PROGRAM) $(DEPENDS) .depends
|
||||
(if test -d SunWS_cache ; then \
|
||||
$(RM) -rf SunWS_cache ; \
|
||||
fi )
|
||||
|
||||
7
Cantera/cxx/demos/rankine/output_0_blessed.txt
Normal file
7
Cantera/cxx/demos/rankine/output_0_blessed.txt
Normal 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
|
||||
100
Cantera/cxx/demos/rankine/rankine.cpp
Normal file
100
Cantera/cxx/demos/rankine/rankine.cpp
Normal 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
|
||||
|
||||
49
Cantera/cxx/demos/rankine/runtest
Executable file
49
Cantera/cxx/demos/rankine/runtest
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
#
|
||||
temp_success="1"
|
||||
/bin/rm -f output_0.txt diff_csv.txt diff_out_0.txt
|
||||
|
||||
##########################################################################
|
||||
|
||||
prog=rankine
|
||||
if test ! -x $prog ; then
|
||||
echo $prog ' does not exist'
|
||||
exit -1
|
||||
fi
|
||||
#################################################################
|
||||
#
|
||||
CANTERA_DATA=${CANTERA_DATA:=../../../data/inputs}; export CANTERA_DATA
|
||||
CANTERA_BIN=${CANTERA_BIN:=../../../bin}
|
||||
|
||||
#################################################################
|
||||
|
||||
$prog > output_0.txt <<+
|
||||
1.0
|
||||
+
|
||||
retnStat=$?
|
||||
if [ $retnStat != "0" ]
|
||||
then
|
||||
temp_success="0"
|
||||
echo "$prog returned with bad status, $retnStat, check output"
|
||||
fi
|
||||
|
||||
diff -w output_0_blessed.txt output_0.txt > diff_out_0.txt
|
||||
retnStat_0=$?
|
||||
|
||||
|
||||
retnTotal=1
|
||||
if test $retnStat_0 = "0"
|
||||
then
|
||||
retnTotal=0
|
||||
fi
|
||||
|
||||
|
||||
if test $retnTotal = "0"
|
||||
then
|
||||
echo "Successful test comparison on "`pwd`
|
||||
else
|
||||
echo "Unsuccessful test comparison on "`pwd` " test"
|
||||
echo " txt files are different - see diff_test*.txt"
|
||||
fi
|
||||
|
||||
Loading…
Add table
Reference in a new issue