Added a simple test that calculate a rate of production for a surface

mechanism
This commit is contained in:
Harry Moffat 2003-08-06 17:32:02 +00:00
parent e8d2044302
commit 2158086053
7 changed files with 404 additions and 0 deletions

View file

@ -0,0 +1,5 @@
surfdemo
Makefile
csvCode.txt
diff_test.out
output.txt

View file

@ -0,0 +1,100 @@
#ifndef CXX_INTERFACE
#define CXX_INTERFACE
#include <string>
#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<ThermoPhase*> 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

View file

@ -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

View file

@ -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

32
test_problems/surfkin/runtest Executable file
View file

@ -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

View file

@ -0,0 +1,87 @@
<?xml version="1.0"?>
<ctml>
<phase id="surface" dim="2">
<state>
<temperature units="K">500</temperature>
</state>
<thermo model="Surface">
<site_density>1.0e-9</site_density>
</thermo>
<elementArray datasrc="elements.xml"> H C</elementArray>
<speciesArray datasrc="#surf_species_data">
surf-* surf-H
</speciesArray>
<reactionArray datasrc="#surf_rxn_data">
<include max="1" min="1" prefix="surf_rxn_"/>
</reactionArray>
<kinetics model="Interface"/>
<phaseArray> gri30 </phaseArray>
</phase>
<!-- species data
Note that these entries are for demonstration only, and the thermo
is made up.
-->
<speciesData id="surf_species_data">
<species name="surf-*">
<note>open site</note>
<atomArray> </atomArray>
<thermo>
<NASA Tmax="3500" Tmid="1000" Tmin="200">
<floatArray size="7" title="low">
2.344331120E+000, 7.980520750E-003, -1.947815100E-005,
2.015720940E-008, -7.376117610E-012, -9.179351730E+002,
6.830102380E-001
</floatArray>
<floatArray size="7" title="high">
3.337279200E+000, -4.940247310E-005, 4.994567780E-007,
-1.795663940E-010, 2.002553760E-014, -9.501589220E+002,
-3.205023310E+000
</floatArray>
</NASA>
</thermo>
</species>
<species name="surf-H">
<note>surface H</note>
<atomArray> H:1 </atomArray>
<thermo>
<NASA Tmax="3500" Tmid="1000" Tmin="200">
<floatArray size="7" title="low">
2.500000000E+000, 7.053328190E-013, -1.995919640E-015,
2.300816320E-018, -9.277323320E-022, 2.547365990E+004,
-4.466828530E-001
</floatArray>
<floatArray size="7" title="high">
2.500000010E+000, -2.308429730E-011, 1.615619480E-014,
-4.735152350E-018, 4.981973570E-022, 2.547365990E+004,
-4.466829140E-001
</floatArray>
</NASA>
</thermo>
</species>
</speciesData>
<!-- reaction data -->
<reactionData id="surf_rxn_data">
<!-- reaction 1 -->
<reaction id="surf_rxn_1" reversible="yes">
<equation>H + surf-H [=] H2 + surf-*</equation>
<reactants> H:1 surf-H:1 </reactants>
<products>H2:1 surf-*:1 </products>
<rateCoeff>
<Arrhenius>
<A units="cm3/mol/s">1.0E14</A>
<b>0.0</b>
<E units="cal/mol">0.0</E>
</Arrhenius>
</rateCoeff>
</reaction>
</reactionData>
</ctml>

View file

@ -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<ThermoPhase*> 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);
}
}