From 215808605393c5be80840eadc4676086e4a91042 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Wed, 6 Aug 2003 17:32:02 +0000 Subject: [PATCH] Added a simple test that calculate a rate of production for a surface mechanism --- test_problems/surfkin/.cvsignore | 5 ++ test_problems/surfkin/Interface.h | 100 +++++++++++++++++++++++ test_problems/surfkin/Makefile.in | 84 +++++++++++++++++++ test_problems/surfkin/output_blessed.txt | 55 +++++++++++++ test_problems/surfkin/runtest | 32 ++++++++ test_problems/surfkin/surface.xml | 87 ++++++++++++++++++++ test_problems/surfkin/surfdemo.cpp | 41 ++++++++++ 7 files changed, 404 insertions(+) create mode 100644 test_problems/surfkin/.cvsignore create mode 100644 test_problems/surfkin/Interface.h create mode 100644 test_problems/surfkin/Makefile.in create mode 100644 test_problems/surfkin/output_blessed.txt create mode 100755 test_problems/surfkin/runtest create mode 100644 test_problems/surfkin/surface.xml create mode 100644 test_problems/surfkin/surfdemo.cpp diff --git a/test_problems/surfkin/.cvsignore b/test_problems/surfkin/.cvsignore new file mode 100644 index 000000000..0dfb823ee --- /dev/null +++ b/test_problems/surfkin/.cvsignore @@ -0,0 +1,5 @@ +surfdemo +Makefile +csvCode.txt +diff_test.out +output.txt diff --git a/test_problems/surfkin/Interface.h b/test_problems/surfkin/Interface.h new file mode 100644 index 000000000..75703bdac --- /dev/null +++ b/test_problems/surfkin/Interface.h @@ -0,0 +1,100 @@ +#ifndef CXX_INTERFACE +#define CXX_INTERFACE + +#include + +#include "kernel/SurfPhase.h" +#include "kernel/InterfaceKinetics.h" +#include "kernel/importCTML.h" + +namespace Cantera { + + /** + * The class interface inherits from both SurfPhase and + * InterferFaceKinetics + */ + class Interface : + public SurfPhase, public InterfaceKinetics + { + public: + /** + * + * Constructor for the interface class: + * + * infile = name of the file to get information about the + * surface. + * id = name of the surface phase. + * phases = Pointer to the list of volume phases that participate + * in the interface + * + */ + Interface(string infile, string id, vector phases) + : m_ok(false), m_r(0) { + string path = findInputFile(infile); + ifstream fin(path.c_str()); + if (!fin) { + throw CanteraError("Interface","could not open " + +path+" for reading."); + } + + + /* + * Create a top level xml node + */ + m_r = new XML_Node("-"); + /* + * Fill the XML_Node with all of the information in the + * xml file + */ + m_r->build(fin); + + + /* + * Find the start of the surface phase data in the xml file + * Store a pointer to the position in the tree. + */ + XML_Node* x = find_XML("", m_r, id, "", ""); + if (!x) { + throw CanteraError("Interface","error in find_XML"); + } + + /* + * Import the values of the surface into the current object. + * Note, since the current object inherits from SurfPhase + * object, it contains all of the surfphase fields of the + * object. This operation fills all of those fields. + */ + importPhase(*x, this); + + phases.push_back(this); + importKinetics(*x, phases, this); + m_ok = true; + } + + /** + * Destructor for the Interface class. This is a virtual function, meaning + * that after, it finishes with this class, it will call the destructor + * functions for the two classes that Interface inherits from. + */ + virtual ~Interface() { + /* + * We created the XML data tree structure for the Interface object + * in the constructor. Here, we delete the top level. of the structure. + * I believe this delete all of the daughter elements as well. + */ + delete m_r; + } + + bool operator!() { return !m_ok;} + bool ready() { return m_ok; } + + protected: + bool m_ok; + XML_Node* m_r; + + private: + }; +} + + +#endif diff --git a/test_problems/surfkin/Makefile.in b/test_problems/surfkin/Makefile.in new file mode 100644 index 000000000..24f6130ed --- /dev/null +++ b/test_problems/surfkin/Makefile.in @@ -0,0 +1,84 @@ +#!/bin/sh + +############################################################################ +# +# Makefile to compile and link a C++ application to +# Cantera. +# +############################################################################# + +# the name of the executable program to be created +PROG_NAME = surfdemo + +# the object files to be linked together. List those generated from Fortran +# and from C/C++ separately +OBJS = surfdemo.o + +# additional flags to be passed to the linker. If your program +# requires other external libraries, put them here +LINK_OPTIONS = + +############################################################################# + +# Fortran libraries +FORT_LIBS = @FLIBS@ + +# the C++ compiler +CXX = @CXX@ + +# C++ compile flags +CXX_FLAGS = @CXXFLAGS@ + +# external libraries +EXT_LIBS = @LOCAL_LIBS@ -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 = + +# the directory where Cantera include files may be found. +CANTERA_INCDIR=@ctroot@/build/include/cantera + +# flags passed to the C++ compiler/linker for the linking step +LCXX_FLAGS = -L$(CANTERA_LIBDIR) @CXXFLAGS@ + +# how to compile C++ source files to object files +.@CXX_EXT@.@OBJ_EXT@: + $(CXX) -c $< -I$(CANTERA_INCDIR) $(CXX_FLAGS) + +PROGRAM = $(PROG_NAME)$(EXE_EXT) + +all: $(PROGRAM) + +$(PROGRAM): $(OBJS) $(CANTERA_LIBDIR)/libcantera.a Interface.h + $(CXX) -o $(PROGRAM) $(OBJS) $(LCXX_FLAGS) $(CANTERA_LIBS) \ + $(LINK_OPTIONS) $(EXT_LIBS) @LIBS@ $(FORT_LIBS) \ + $(LCXX_END_LIBS) + +$(OBJS): Interface.h + +test: + @MAKE@ $(PROGRAM) + ./runtest +clean: + $(RM) $(OBJS) $(PROGRAM) + ../../bin/rm_cvsignore + + + + + + + + + + + + + + diff --git a/test_problems/surfkin/output_blessed.txt b/test_problems/surfkin/output_blessed.txt new file mode 100644 index 000000000..35908b4a5 --- /dev/null +++ b/test_problems/surfkin/output_blessed.txt @@ -0,0 +1,55 @@ +H2 0.000670367 +H -0.000670367 +O 0 +O2 0 +OH 0 +H2O 0 +HO2 0 +H2O2 0 +C 0 +CH 0 +CH2 0 +CH2(S) 0 +CH3 0 +CH4 0 +CO 0 +CO2 0 +HCO 0 +CH2O 0 +CH2OH 0 +CH3O 0 +CH3OH 0 +C2H 0 +C2H2 0 +C2H3 0 +C2H4 0 +C2H5 0 +C2H6 0 +HCCO 0 +CH2CO 0 +HCCOH 0 +N 0 +NH 0 +NH2 0 +NH3 0 +NNH 0 +NO 0 +NO2 0 +N2O 0 +HNO 0 +CN 0 +HCN 0 +H2CN 0 +HCNN 0 +HCNO 0 +HOCN 0 +HNCO 0 +NCO 0 +N2 0 +AR 0 +C3H7 0 +C3H8 0 +CH2CHO 0 +CH3CHO 0 +surf-* 0.000670367 +surf-H -0.000670367 diff --git a/test_problems/surfkin/runtest b/test_problems/surfkin/runtest new file mode 100755 index 000000000..2e7059a68 --- /dev/null +++ b/test_problems/surfkin/runtest @@ -0,0 +1,32 @@ +#!/bin/sh +# +# + +temp_success="1" +/bin/rm -f output.txt + +################################################################# +# +################################################################# + +CANTERA_BIN=${CANTERA_BIN:=../../bin} +./surfdemo > output.txt +retnStat=$? +if [ $retnStat != "0" ] +then + temp_success="0" + echo "surfdemo returned with bad status, $retnStat, check output" +fi + + +diff output.txt output_blessed.txt > diff_test.out +retnStat=$? +if [ $retnStat = "0" ] +then + echo "successful diff comparison on surfdemo test" +else + echo "unsuccessful diff comparison on surfdemo test" + echo "FAILED" > csvCode.txt + temp_success="0" +fi + diff --git a/test_problems/surfkin/surface.xml b/test_problems/surfkin/surface.xml new file mode 100644 index 000000000..ecf7eca89 --- /dev/null +++ b/test_problems/surfkin/surface.xml @@ -0,0 +1,87 @@ + + + + + + 500 + + + 1.0e-9 + + H C + + surf-* surf-H + + + + + + gri30 + + + + + + + + open site + + + + + 2.344331120E+000, 7.980520750E-003, -1.947815100E-005, + 2.015720940E-008, -7.376117610E-012, -9.179351730E+002, + 6.830102380E-001 + + + 3.337279200E+000, -4.940247310E-005, 4.994567780E-007, + -1.795663940E-010, 2.002553760E-014, -9.501589220E+002, + -3.205023310E+000 + + + + + + + surface H + H:1 + + + + 2.500000000E+000, 7.053328190E-013, -1.995919640E-015, + 2.300816320E-018, -9.277323320E-022, 2.547365990E+004, + -4.466828530E-001 + + + 2.500000010E+000, -2.308429730E-011, 1.615619480E-014, + -4.735152350E-018, 4.981973570E-022, 2.547365990E+004, + -4.466829140E-001 + + + + + + + + + + + + + H + surf-H [=] H2 + surf-* + H:1 surf-H:1 + H2:1 surf-*:1 + + + 1.0E14 + 0.0 + 0.0 + + + + + + diff --git a/test_problems/surfkin/surfdemo.cpp b/test_problems/surfkin/surfdemo.cpp new file mode 100644 index 000000000..75a3fc7c4 --- /dev/null +++ b/test_problems/surfkin/surfdemo.cpp @@ -0,0 +1,41 @@ +// +// Replace this sample main program with your program +// +// + +#include "Cantera.h" +#include "IdealGasMix.h" +#include "Interface.h" + +using namespace Cantera; + +int main() { + + try { + IdealGasMix gas("gri30.xml"); + gas.setState_TPX(1200.0, OneAtm, + "H2:2, O2:1, OH:0.01, H:0.01, O:0.01"); + + vector phases; + phases.push_back(&gas); + Interface surf("surface.xml", "surface", phases); + vector_fp cov; + cov.push_back(0.8); + cov.push_back(0.2); + surf.setCoverages(cov.begin()); + vector_fp wdot(gas.nSpecies() + surf.nSpecies()); + surf.getNetProductionRates(wdot.begin()); + int k; + for (k = 0; k < gas.nSpecies(); k++) + cout << gas.speciesName(k) << " " << wdot[k] << endl; + for (k = 0; k < surf.nSpecies(); k++) + cout << surf.speciesName(k) << " " + << wdot[k+gas.nSpecies()] << endl; + + } + catch (CanteraError) { + showErrors(cout); + } + +} +