diff --git a/test_problems/Makefile.in b/test_problems/Makefile.in index 50e4a7617..b40876249 100644 --- a/test_problems/Makefile.in +++ b/test_problems/Makefile.in @@ -8,15 +8,17 @@ test_python=@BUILD_PYTHON@ all: cd cxx_ex; @MAKE@ all -# cd silane_equil; @MAKE@ all + cd silane_equil; @MAKE@ all cd surfkin; @MAKE@ all + cd fracCoeff; @MAKE@ all cd diamondSurf; @MAKE@ all cd ck2cti_test; @MAKE@ all test: cd cxx_ex; @MAKE@ test -# cd silane_equil; @MAKE@ test + cd silane_equil; @MAKE@ test cd surfkin; @MAKE@ test + cd fracCoeff; @MAKE@ test cd diamondSurf; @MAKE@ test cd ck2cti_test; @MAKE@ test ifeq ($(test_python),2) @@ -26,8 +28,9 @@ endif clean: $(RM) *.*~ cd cxx_ex; @MAKE@ clean -# cd silane_equil; @MAKE@ clean + cd silane_equil; @MAKE@ clean cd surfkin; @MAKE@ clean + cd fracCoeff; @MAKE@ clean cd diamondSurf; @MAKE@ clean cd ck2cti_test; @MAKE@ clean ifeq ($(test_python),2) @@ -36,8 +39,9 @@ endif depends: cd cxx_ex; @MAKE@ depends -# cd silane_equil; @MAKE@ depends + cd silane_equil; @MAKE@ depends cd surfkin; @MAKE@ depends + cd fracCoeff; @MAKE@ depends cd diamondSurf; @MAKE@ depends cd ck2cti_test; @MAKE@ depends diff --git a/test_problems/cxx_ex/Makefile.in b/test_problems/cxx_ex/Makefile.in index 4f5887b4c..cff1beeef 100644 --- a/test_problems/cxx_ex/Makefile.in +++ b/test_problems/cxx_ex/Makefile.in @@ -10,6 +10,7 @@ test: ./runtest clean: + (cd ../../examples/cxx ; @MAKE@ clean ) ../../bin/rm_cvsignore depends: diff --git a/test_problems/fracCoeff/.cvsignore b/test_problems/fracCoeff/.cvsignore new file mode 100644 index 000000000..73444decc --- /dev/null +++ b/test_problems/fracCoeff/.cvsignore @@ -0,0 +1,20 @@ +Makefile +csvCode.txt +diff_test.out +output.txt +runDiamond +ct2ctml.log +diamond.xml +xml_diff_test.out +.depends +*.d +.cttmp.py +runDiamond.ilk +diamondSurf.pdb +diamonda.xml +outputa.txt +test.xml +fracCoeff +Sun* +frac.xml +fraca.xml diff --git a/test_problems/fracCoeff/Makefile.in b/test_problems/fracCoeff/Makefile.in new file mode 100644 index 000000000..9ae17e3d2 --- /dev/null +++ b/test_problems/fracCoeff/Makefile.in @@ -0,0 +1,113 @@ +#!/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 = fracCoeff + +# the object files to be linked together. List those generated from Fortran +# and from C/C++ separately +OBJS = fracCoeff.o + +# Location of the current build. Will assume that tests are run +# in the source directory tree location +src_dir_tree = 1 + +# additional flags to be passed to the linker. If your program +# requires other external libraries, put them here +LINK_OPTIONS = @EXTRA_LINK@ + +############################################################################# + +# 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@ + +# C++ compile flags +ifeq ($(src_dir_tree), 1) +CXX_FLAGS = -DSRCDIRTREE @CXXFLAGS@ +else +CXX_FLAGS = @CXXFLAGS@ +endif + +# 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 = @LOCAL_LIBS@ -lctcxx + +# the directory where Cantera include files may be found. +ifeq ($(src_dir_tree), 1) +CANTERA_INCDIR=../../Cantera/src +else +CANTERA_INCDIR=@ctroot@/build/include/cantera +endif + +# 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@: Interface.h + $(CXX) -c $< -I$(CANTERA_INCDIR) $(CXX_FLAGS) + +# How to compile the dependency file +.cpp.d: + g++ -MM -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 rule makes a single program +all: $(PROGRAM) + +# Rule to make the program +$(PROGRAM): $(OBJS) $(CANTERA_LIBDIR)/libcantera.a + $(CXX) -o $(PROGRAM) $(OBJS) $(LCXX_FLAGS) $(LINK_OPTIONS) \ + $(CANTERA_LIBS) @LIBS@ $(FORT_LIBS) \ + $(LCXX_END_LIBS) + +# depends target +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 target -> clean up +clean: + $(RM) $(OBJS) $(PROGRAM) $(DEPENDS) .depends + ../../bin/rm_cvsignore + (if test -d SunWS_cache ; then \ + $(RM) -rf SunWS_cache ; \ + fi ) + diff --git a/test_problems/fracCoeff/frac.cti b/test_problems/fracCoeff/frac.cti new file mode 100644 index 000000000..15d3edf0f --- /dev/null +++ b/test_problems/fracCoeff/frac.cti @@ -0,0 +1,106 @@ +# +# Input file to test use of non-integral stoichiometric +# coefficients. Used with script frac.py. +# + +units(length = "cm", time = "s", quantity = "mol", act_energy = "cal/mol") + + +ideal_gas(name = "gas", + elements = " O H ", + species = """ H2 H O O2 OH H2O """, + reactions = "all", + initial_state = state(temperature = 300.0, + pressure = OneAtm) ) + + + +#------------------------------------------------------------------------------- +# Species data +#------------------------------------------------------------------------------- + +species(name = "H2", + atoms = " H:2 ", + thermo = ( + NASA( [ 200.00, 1000.00], [ 2.344331120E+00, 7.980520750E-03, + -1.947815100E-05, 2.015720940E-08, -7.376117610E-12, + -9.179351730E+02, 6.830102380E-01] ), + NASA( [ 1000.00, 3500.00], [ 3.337279200E+00, -4.940247310E-05, + 4.994567780E-07, -1.795663940E-10, 2.002553760E-14, + -9.501589220E+02, -3.205023310E+00] ) + ) +) + +species(name = "H", + atoms = " H:1 ", + thermo = ( + NASA( [ 200.00, 1000.00], [ 2.500000000E+00, 7.053328190E-13, + -1.995919640E-15, 2.300816320E-18, -9.277323320E-22, + 2.547365990E+04, -4.466828530E-01] ), + NASA( [ 1000.00, 3500.00], [ 2.500000010E+00, -2.308429730E-11, + 1.615619480E-14, -4.735152350E-18, 4.981973570E-22, + 2.547365990E+04, -4.466829140E-01] ) + ) + ) + +species(name = "O", + atoms = " O:1 ", + thermo = ( + NASA( [ 200.00, 1000.00], [ 3.168267100E+00, -3.279318840E-03, + 6.643063960E-06, -6.128066240E-09, 2.112659710E-12, + 2.912225920E+04, 2.051933460E+00] ), + NASA( [ 1000.00, 3500.00], [ 2.569420780E+00, -8.597411370E-05, + 4.194845890E-08, -1.001777990E-11, 1.228336910E-15, + 2.921757910E+04, 4.784338640E+00] ) + ) + ) + +species(name = "O2", + atoms = " O:2 ", + thermo = ( + NASA( [ 200.00, 1000.00], [ 3.782456360E+00, -2.996734160E-03, + 9.847302010E-06, -9.681295090E-09, 3.243728370E-12, + -1.063943560E+03, 3.657675730E+00] ), + NASA( [ 1000.00, 3500.00], [ 3.282537840E+00, 1.483087540E-03, + -7.579666690E-07, 2.094705550E-10, -2.167177940E-14, + -1.088457720E+03, 5.453231290E+00] ) + ) + ) + +species(name = "OH", + atoms = " O:1 H:1 ", + thermo = ( + NASA( [ 200.00, 1000.00], [ 3.992015430E+00, -2.401317520E-03, + 4.617938410E-06, -3.881133330E-09, 1.364114700E-12, + 3.615080560E+03, -1.039254580E-01] ), + NASA( [ 1000.00, 3500.00], [ 3.092887670E+00, 5.484297160E-04, + 1.265052280E-07, -8.794615560E-11, 1.174123760E-14, + 3.858657000E+03, 4.476696100E+00] ) + ) + ) + +species(name = "H2O", + atoms = " H:2 O:1 ", + thermo = ( + NASA( [ 200.00, 1000.00], [ 4.198640560E+00, -2.036434100E-03, + 6.520402110E-06, -5.487970620E-09, 1.771978170E-12, + -3.029372670E+04, -8.490322080E-01] ), + NASA( [ 1000.00, 3500.00], [ 3.033992490E+00, 2.176918040E-03, + -1.640725180E-07, -9.704198700E-11, 1.682009920E-14, + -3.000429710E+04, 4.966770100E+00] ) + ) + ) + + +# An irreversible reaction with fractional product coefficients. +reaction( "H2O => 1.4 H + 0.6 OH + 0.2 O2", [1.0e13, 0.0, 0.0]) + +# A reversible reaction with fractional product coefficients. This is +# not allowed, and uncommenting this reaction will result in an error. +#reaction( "H2O <=> 1.3 H + 0.7 OH + 0.15 O2", [1.0e13, 0.0, 0.0]) + +# A reaction with fractional reactant stoichiometric +# coefficients. +reaction( "0.7 H2 + 0.6 OH + 0.2 O2 => H2O", [1.0e13, 0.0, 0.0], + order = "H2:0.8 OH:2 O2:1") + diff --git a/test_problems/fracCoeff/fracCoeff.cpp b/test_problems/fracCoeff/fracCoeff.cpp new file mode 100644 index 000000000..557fe0460 --- /dev/null +++ b/test_problems/fracCoeff/fracCoeff.cpp @@ -0,0 +1,185 @@ +/** + * @file runDiamond.cpp + * + */ + +// Example +// +// Note that this example needs updating. It works fine, but is +// written in a way that is less than transparent or +// user-friendly. This could be rewritten using class Interface to +// make things simpler. + + +#include +#include +#include +#include +#include + +using namespace std; + +#ifdef DEBUG_HKM +int iDebug_HKM = 0; +#endif + +/*****************************************************************/ +/*****************************************************************/ +/*****************************************************************/ + +#ifdef SRCDIRTREE +#include "ct_defs.h" +#include "ctml.h" +#include "GasKinetics.h" +#include "importCTML.h" +#include "ThermoPhase.h" +#include "InterfaceKinetics.h" +#else +#include "Cantera.h" +#include "kernel/ct_defs.h" +#include "kernel/ctml.h" +#include "kernel/GasKinetics.h" +#include "kernel/importCTML.h" +#include "kernel/ThermoPhase.h" +#include "kernel/InterfaceKinetics.h" +#endif + +using namespace Cantera; + +void printDbl(double val) { + if (fabs(val) < 5.0E-200) { + cout << " nil"; + } else { + cout << val; + } +} + +int main(int argc, char** argv) { + int i, k; + string infile = "frac.cti"; + double x[10], kc[10]; + double cdot[10], ddot[10]; + //double fwd_rop[10]; + try { + XML_Node *xc = new XML_Node(); + string path = findInputFile(infile); + ctml::get_CTML_Tree(xc, path); + + XML_Node * const xg = xc->findNameID("phase", "gas"); + ThermoPhase *gasTP = newPhase(*xg); + int nsp = gasTP->nSpecies(); + cout << "Number of species = " << nsp << endl; + + + + vector phaseList; + phaseList.push_back(gasTP); + GasKinetics *iKin_ptr = new GasKinetics(); + importKinetics(*xg, phaseList, iKin_ptr); + int nr = iKin_ptr->nReactions(); + cout << "Number of reactions = " << nr << endl; + + int iH2 = gasTP->speciesIndex("H2"); + int iH = gasTP->speciesIndex("H"); + int iO2 = gasTP->speciesIndex("O2"); + int iOH = gasTP->speciesIndex("OH"); + int iH2O = gasTP->speciesIndex("H2O"); + + + for (i = 0; i < nsp; i++) { + x[i] = 0.0; + } + x[iH2O] = 1.0/2.0; + x[iOH] = 0.1/2.0; + x[iH] = 0.2/2.0; + x[iO2] = 0.3/2.0; + x[iH2] = 0.4/2.0; + + double p = OneAtm; + + gasTP->setState_TPX(2000., p, x); + + + double src[20]; + for (i = 0; i < 20; i++) src[i] = 0.0; + iKin_ptr->getNetProductionRates(src); + + double fwd_rop[10]; + iKin_ptr->getFwdRatesOfProgress(fwd_rop); + cout << "fwd_rop[0] = " << fwd_rop[0] << endl; + cout << "fwd_rop[1] = " << fwd_rop[1] << endl; + + iKin_ptr->getCreationRates(cdot); + iKin_ptr->getDestructionRates(ddot); + + for (k = 0; k < nsp; k++) { + string sss = gasTP->speciesName(k); + cout << k << " " << sss << " "; + printDbl(src[k]); + cout << endl; + } + + printf("Creation Rates: \n"); + for (k = 0; k < nsp - 1; k++) { + string sss = gasTP->speciesName(k); + cout << k << " " << sss << " "; + cout << cdot[k] << " "; + cout << cdot[k] / fwd_rop[0] << " "; + cout << endl; + } + string sss = gasTP->speciesName(iH2O); + cout << iH2O << " " << sss << " "; + cout << cdot[iH2O] << " "; + cout << cdot[iH2O] / fwd_rop[1] << " "; + cout << endl; + + + printf("Destruction Rates: \n"); + for (k = 0; k < nsp-1; k++) { + string sss = gasTP->speciesName(k); + cout << k << " " << sss << " "; + cout << ddot[k] << " "; + cout << ddot[k] / fwd_rop[1] << " "; + cout << endl; + } + sss = gasTP->speciesName(iH2O); + cout << iH2O << " " << sss << " "; + cout << ddot[iH2O] << " "; + cout << ddot[iH2O] / fwd_rop[0] << " "; + cout << endl; + + + double c[10]; + gasTP->getConcentrations(c); + + double order_H2 = 0.8; + double order_OH = 2.0; + double order_O2 = 1.0; + + double kf[10]; + iKin_ptr->getFwdRateConstants(kf); + printf("kf[0] = %g\n", kf[0]); + printf("kf[1] = %g\n", kf[1]); + + //double cprod0 = c[iH2O]; + double cprod1 = pow(c[iH2], order_H2) * pow(c[iOH], order_OH) * pow(c[iO2], order_O2); + + printf("equal numbers 0: %g %g \n", kf[0] * c[iH2O], fwd_rop[0]); + + printf("equal numbers 1: %g %g\n", kf[1] * cprod1, fwd_rop[1]); + + iKin_ptr->getEquilibriumConstants(kc); + + printf("Equilibrium constants for irreversible fractional rxns:\n"); + printf("Kc[0] = %g\n", kc[0]); + printf("Kc[1] = %g\n", kc[1]); + + + } + catch (CanteraError) { + showErrors(cout); + } + + return 0; +} +/***********************************************************/ diff --git a/test_problems/fracCoeff/frac_blessed.out b/test_problems/fracCoeff/frac_blessed.out new file mode 100644 index 000000000..60d05791e --- /dev/null +++ b/test_problems/fracCoeff/frac_blessed.out @@ -0,0 +1,31 @@ +Number of species = 6 +Number of reactions = 2 +fwd_rop[0] = 3.04665e+10 +fwd_rop[1] = 1.57504e-08 +0 H2 -1.10253e-08 +1 H 4.2653e+10 +2 O nil +3 O2 6.09329e+09 +4 OH 1.82799e+10 +5 H2O -3.04665e+10 +Creation Rates: +0 H2 0 0 +1 H 4.2653e+10 1.4 +2 O 0 0 +3 O2 6.09329e+09 0.2 +4 OH 1.82799e+10 0.6 +5 H2O 1.57504e-08 1 +Destruction Rates: +0 H2 1.10253e-08 0.7 +1 H 0 0 +2 O 0 0 +3 O2 3.15009e-09 0.2 +4 OH 9.45026e-09 0.6 +5 H2O 3.04665e+10 1 +kf[0] = 1e+13 +kf[1] = 39810.7 +equal numbers 0: 3.04665e+10 3.04665e+10 +equal numbers 1: 1.57504e-08 1.57504e-08 +Equilibrium constants for irreversible fractional rxns: +Kc[0] = 5.60014e-11 +Kc[1] = 62705 diff --git a/test_problems/fracCoeff/frac_blessed.xml b/test_problems/fracCoeff/frac_blessed.xml new file mode 100644 index 000000000..8b09e3c3c --- /dev/null +++ b/test_problems/fracCoeff/frac_blessed.xml @@ -0,0 +1,157 @@ + + + + + + + O H + H2 H O O2 OH H2O + + + 300.0 + 101325.0 + + + + + + + + + + + + H:2 + + + + 2.344331120E+00, 7.980520750E-03, -1.947815100E-05, 2.015720940E-08, + -7.376117610E-12, -9.179351730E+02, 6.830102380E-01 + + + + 3.337279200E+00, -4.940247310E-05, 4.994567780E-07, -1.795663940E-10, + 2.002553760E-14, -9.501589220E+02, -3.205023310E+00 + + + + + + + H:1 + + + + 2.500000000E+00, 7.053328190E-13, -1.995919640E-15, 2.300816320E-18, + -9.277323320E-22, 2.547365990E+04, -4.466828530E-01 + + + + 2.500000010E+00, -2.308429730E-11, 1.615619480E-14, -4.735152350E-18, + 4.981973570E-22, 2.547365990E+04, -4.466829140E-01 + + + + + + + O:1 + + + + 3.168267100E+00, -3.279318840E-03, 6.643063960E-06, -6.128066240E-09, + 2.112659710E-12, 2.912225920E+04, 2.051933460E+00 + + + + 2.569420780E+00, -8.597411370E-05, 4.194845890E-08, -1.001777990E-11, + 1.228336910E-15, 2.921757910E+04, 4.784338640E+00 + + + + + + + O:2 + + + + 3.782456360E+00, -2.996734160E-03, 9.847302010E-06, -9.681295090E-09, + 3.243728370E-12, -1.063943560E+03, 3.657675730E+00 + + + + 3.282537840E+00, 1.483087540E-03, -7.579666690E-07, 2.094705550E-10, + -2.167177940E-14, -1.088457720E+03, 5.453231290E+00 + + + + + + + H:1 O:1 + + + + 3.992015430E+00, -2.401317520E-03, 4.617938410E-06, -3.881133330E-09, + 1.364114700E-12, 3.615080560E+03, -1.039254580E-01 + + + + 3.092887670E+00, 5.484297160E-04, 1.265052280E-07, -8.794615560E-11, + 1.174123760E-14, 3.858657000E+03, 4.476696100E+00 + + + + + + + H:2 O:1 + + + + 4.198640560E+00, -2.036434100E-03, 6.520402110E-06, -5.487970620E-09, + 1.771978170E-12, -3.029372670E+04, -8.490322080E-01 + + + + 3.033992490E+00, 2.176918040E-03, -1.640725180E-07, -9.704198700E-11, + 1.682009920E-14, -3.000429710E+04, 4.966770100E+00 + + + + + + + + + H2O =] 1.4 H + 0.6 OH + 0.2 O2 + + + 1.000000E+13 + 0.0 + 0.000000 + + + H2O:1.0 + H:1.3999999999999999 O2:0.20000000000000001 OH:0.59999999999999998 + + + + + 0.7 H2 + 0.6 OH + 0.2 O2 =] H2O + 0.80000000000000004 + 1.0 + 2.0 + + + 3.981072E+04 + 0.0 + 0.000000 + + + H2:0.69999999999999996 O2:0.20000000000000001 OH:0.59999999999999998 + H2O:1.0 + + + diff --git a/test_problems/fracCoeff/runtest b/test_problems/fracCoeff/runtest new file mode 100755 index 000000000..8746b8cd9 --- /dev/null +++ b/test_problems/fracCoeff/runtest @@ -0,0 +1,46 @@ +#!/bin/sh +# +# + +temp_success="1" +/bin/rm -f output.txt outputa.txt frac.xml + +################################################################# +# +################################################################# +CANTERA_DATA=${CANTERA_DATA:=../../data/inputs}; export CANTERA_DATA + +CANTERA_BIN=${CANTERA_BIN:=../../bin} +./fracCoeff > output.txt +retnStat=$? +if [ $retnStat != "0" ] +then + temp_success="0" + echo "fracCoeff returned with bad status, $retnStat, check output" +fi + +../../bin/exp3to2.sh output.txt > outputa.txt +diff -w outputa.txt frac_blessed.out > diff_test.out +retnStat=$? +if [ $retnStat = "0" ] +then + echo "successful diff comparison on fracCoeff test" +else + echo "unsuccessful diff comparison on fracCoeff test" + echo "FAILED" > csvCode.txt + temp_success="0" +fi + +../../bin/exp3to2.sh frac.xml > fraca.xml +diff -w fraca.xml frac_blessed.xml > xml_diff_test.out +retnStat=$? +if [ $retnStat = "0" ] +then + echo "successful diff comparison on fracCoeff.xml test" +else + echo "unsuccessful diff comparison on fracCoeff.xml test" + echo "FAILED" > csvCode.txt + temp_success="0" +fi + +