Added another test problem that checks the duplMyselfAsThermoPhase

capability.
This commit is contained in:
Harry Moffat 2007-06-02 00:14:24 +00:00
parent 2b5befcf6b
commit a5cb5b7f8a
11 changed files with 1093 additions and 0 deletions

View file

@ -0,0 +1,11 @@
csvCode.txt
diff_test.out
HMW_dupl_test.d
Makefile
outputa.txt
sortAlgorithms.d
table1.csv
table2.csv
.depends
HMW_dupl_test
output.txt

View file

@ -0,0 +1,243 @@
<?xml version="1.0"?>
<!--
$Id$
$Source$
$Name$
NaCl modeling Based on the Silvester&Pitzer 1977 treatment:
(L. F. Silvester, K. S. Pitzer, "Thermodynamics of Electrolytes:
8. High-Temperature Properties, including Enthalpy and Heat
Capacity, with application to sodium chloride",
J. Phys. Chem., 81, 19 1822 - 1828 (1977)
This modification reworks the Na+ standard state shomate
polynomial, so that the resulting DeltaG0 for the NaCl(s) -> Na+ + Cl-
reaction agrees closely with Silvester and Pitzer. The main
effect that this has is to change the predicted Na+ heat capacity
at low temperatures.
-->
<ctml>
<phase id="NaCl_electrolyte" dim="3">
<speciesArray datasrc="#species_waterSolution">
H2O(L) Cl- H+ Na+ OH-
</speciesArray>
<state>
<temperature units="K"> 298.15 </temperature>
<pressure units="Pa"> 101325.0 </pressure>
<soluteMolalities>
Na+:6.0954
Cl-:6.0954
H+:2.1628E-9
OH-:1.3977E-6
</soluteMolalities>
</state>
<thermo model="HMW">
<standardConc model="solvent_volume" />
<activityCoefficients model="Pitzer" TempModel="complex1">
<!-- Pitzer Coefficients
These coefficients are from Pitzer's main
paper, in his book.
-->
<A_Debye model="water" />
<ionicRadius default="3.042843" units="Angstroms">
</ionicRadius>
<binarySaltParameters cation="Na+" anion="Cl-">
<beta0> 0.0765, 0.008946, -3.3158E-6,
-777.03, -4.4706
</beta0>
<beta1> 0.2664, 6.1608E-5, 1.0715E-6 </beta1>
<beta2> 0.0 </beta2>
<Cphi> 0.00127, -4.655E-5, 0.0,
33.317, 0.09421
</Cphi>
<Alpha1> 2.0 </Alpha1>
</binarySaltParameters>
<binarySaltParameters cation="H+" anion="Cl-">
<beta0> 0.1775, 0.0, 0.0, 0.0, 0.0</beta0>
<beta1> 0.2945, 0.0, 0.0 </beta1>
<beta2> 0.0 </beta2>
<Cphi> 0.0008, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Alpha1> 2.0 </Alpha1>
</binarySaltParameters>
<binarySaltParameters cation="Na+" anion="OH-">
<beta0> 0.0864, 0.0, 0.0, 0.0, 0.0 </beta0>
<beta1> 0.253, 0.0, 0.0 </beta1>
<beta2> 0.0 </beta2>
<Cphi> 0.0044, 0.0, 0.0, 0.0, 0.0 </Cphi>
<Alpha1> 2.0 </Alpha1>
</binarySaltParameters>
<thetaAnion anion1="Cl-" anion2="OH-">
<Theta> -0.05 </Theta>
</thetaAnion>
<psiCommonCation cation="Na+" anion1="Cl-" anion2="OH-">
<Theta> -0.05 </Theta>
<Psi> -0.006 </Psi>
</psiCommonCation>
<thetaCation cation1="Na+" cation2="H+">
<Theta> 0.036 </Theta>
</thetaCation>
<psiCommonAnion anion="Cl-" cation1="Na+" cation2="H+">
<Theta> 0.036 </Theta>
<Psi> -0.004 </Psi>
</psiCommonAnion>
</activityCoefficients>
<solvent> H2O(L) </solvent>
</thermo>
<elementArray datasrc="elements.xml"> O H C E Fe Si N Na Cl </elementArray>
<kinetics model="none" >
</kinetics>
</phase>
<speciesData id="species_waterSolution">
<species name="H2O(L)">
<!-- H2O(L) liquid standard state -> pure H2O
The origin of the NASA polynomial is a bit murky. It does
fit the vapor pressure curve at 298K adequately.
-->
<atomArray>H:2 O:1 </atomArray>
<thermo>
<NASA Tmax="600.0" Tmin="273.14999999999998" P0="100000.0">
<floatArray name="coeffs" size="7">
7.255750050E+01, -6.624454020E-01, 2.561987460E-03, -4.365919230E-06,
2.781789810E-09, -4.188654990E+04, -2.882801370E+02
</floatArray>
</NASA>
</thermo>
<standardState model="waterIAPWS">
<!--
Molar volume in m3 kmol-1.
(this is from Pitzer, Peiper, and Busey. However,
the result can be easily derived from ~ 1gm/cm**3)
<molarVolume> 0.018068 </molarVolume>
-->
</standardState>
</species>
<species name="Na+">
<!-- Na+ rework. Differences in the delta_G0 reaction
for salt formation were dumped into this polynomial.
-->
<atomArray> Na:1 E:-1 </atomArray>
<charge> +1 </charge>
<thermo>
<Shomate Pref="1 bar" Tmax=" 593.15" Tmin=" 293.15">
<floatArray size="7">
-57993.47558 , 305112.6040 , -592222.1591 ,
401977.9827 , 804.4195980 , 10625.24901 ,
-133796.2298
</floatArray>
</Shomate>
</thermo>
<standardState model="constant_incompressible">
<!-- Na+ (aq) molar volume
Molar volume in m3 kmol-1.
(this is from Pitzer, Peiper, and Busey. We divide
NaCl (aq) value by 2 to get this)
-->
<molarVolume> 0.00834 </molarVolume>
</standardState>
</species>
<species name="Cl-">
<!-- Cl- (aq) standard state based on the unity molality convention
The shomate polynomial was created from the SUPCRT92
J. Phys Chem Ref article, and the codata recommended
values. DelHf(298.15) = -167.08 kJ/gmol
S(298.15) = 56.60 J/gmolK
There was a slight discrepency between those two, which was
resolved in favor of codata.
Notes: the order of the polynomials can be decreased by
dropping terms from the complete Shomate poly.
-->
<atomArray> Cl:1 E:1 </atomArray>
<charge> -1 </charge>
<standardState model="constant_incompressible">
<!-- Cl- (aq) molar volume
Molar volume in m3 kmol-1.
(this is from Pitzer, Peiper, and Busey. We divide
NaCl (aq) value by 2 to get this)
-->
<molarVolume> 0.00834 </molarVolume>
</standardState>
<thermo>
<Shomate Pref="1 atm" Tmax=" 623.15" Tmin=" 298.00">
<floatArray size="7">
56696.2042 , -297835.978 , 581426.549 ,
-401759.991 , -804.301136 , -10873.8257 ,
130650.697
</floatArray>
</Shomate>
</thermo>
</species>
<species name="H+">
<!-- H+ (aq) standard state based on the unity molality convention
The H+ standard state is set to zeroes by convention. This
includes it's contribution to the molar volume of solution.
-->
<atomArray> H:1 E:-1 </atomArray>
<charge> +1 </charge>
<standardState model="constant_incompressible">
<molarVolume> 0.0 </molarVolume>
</standardState>
<thermo>
<Mu0 Pref="100000.0" Tmax="625.15." Tmin="273.15">
<H298 units="cal/mol"> 0.0 </H298>
<numPoints> 3 </numPoints>
<floatArray size="3" title="Mu0Values" units="Dimensionless">
0.0 , 0.0, 0.0
</floatArray>
<floatArray size="3" title="Mu0Temperatures">
273.15, 298.15 , 623.15
</floatArray>
</Mu0>
</thermo>
</species>
<species name="OH-">
<!-- OH- (aq) standard state based on the unity molality convention
The shomate polynomial was created with data from the SUPCRT92
J. Phys Chem Ref article, and from the codata recommended
values. DelHf(298.15) = -230.015 kJ/gmol
S(298.15) = -10.90 J/gmolK
There was a slight discrepency between those two, which was
resolved in favor of codata.
Notes: the order of the polynomials can be decreased by
dropping terms from the complete Shomate poly.
-->
<atomArray> O:1 H:1 E:1 </atomArray>
<charge> -1 </charge>
<standardState model="constant_incompressible">
<!-- OH- (aq) molar volume
This value is currently made up.
-->
<molarVolume> 0.00834 </molarVolume>
</standardState>
<thermo>
<Shomate Pref="1 atm" Tmax=" 623.15" Tmin=" 298.00">
<floatArray size="7">
44674.99961 , -234943.0414 , 460522.8260 ,
-320695.1836 , -638.5044716 , -8683.955813 ,
102874.2667
</floatArray>
</Shomate>
</thermo>
</species>
</speciesData>
</ctml>

View file

@ -0,0 +1,354 @@
/**
*
* @file HMW_graph_1.cpp
*/
/*
* $Author$
* $Date$
* $Revision$
*/
#include <stdio.h>
#ifdef SRCDIRTREE
#include "ct_defs.h"
#include "logger.h"
#include "TemperatureTable.h"
#include "ThermoPhase.h"
#include "HMWSoln.h"
#include "importCTML.h"
#else
#include "Cantera.h"
#include "kernel/logger.h"
#include "thermo.h"
#include "TemperatureTable.h"
#include "HMWSoln.h"
#endif
using namespace std;
using namespace Cantera;
class fileLog: public Logger {
public:
fileLog(string fName) {
m_fName = fName;
m_fs.open(fName.c_str());
}
virtual void write(const string& msg) {
m_fs << msg;
m_fs.flush();
}
virtual ~fileLog() {
m_fs.close();
}
string m_fName;
ofstream m_fs;
};
void printUsage() {
cout << "usage: HMW_test " << endl;
cout <<" -> Everything is hardwired" << endl;
}
int main(int argc, char **argv)
{
int retn = 0;
int i;
try {
char iFile[80];
strcpy(iFile, "HMW_NaCl.xml");
if (argc > 1) {
strcpy(iFile, argv[1]);
}
double Cp0_R[20], pmCp[20];
//fileLog *fl = new fileLog("HMW_graph_1.log");
//setLogger(fl);
HMWSoln *HMW = new HMWSoln(iFile, "NaCl_electrolyte");
/*
* Load in and initialize the
*/
Cantera::ThermoPhase *solid = newPhase("NaCl_Solid.xml","NaCl(S)");
int nsp = HMW->nSpecies();
double acMol[100];
double act[100];
double mf[100];
double moll[100];
for (i = 0; i < 100; i++) {
acMol[i] = 1.0;
act[i] = 1.0;
mf[i] = 0.0;
act[i] = 0.0;
}
HMW->getMoleFractions(mf);
string sName;
TemperatureTable TTable(15, false, 273.15, 25., 0, 0);
HMW->setState_TP(298.15, 1.01325E5);
int i1 = HMW->speciesIndex("Na+");
int i2 = HMW->speciesIndex("Cl-");
//int i3 = HMW->speciesIndex("H2O(L)");
for (i = 0; i < nsp; i++) {
moll[i] = 0.0;
}
HMW->setMolalities(moll);
double ISQRT;
double Is = 0.0;
/*
* Set the Pressure
*/
double pres = OneAtm;
/*
* Fix the molality
*/
Is = 6.146;
ISQRT = sqrt(Is);
moll[i1] = Is;
moll[i2] = Is;
HMW->setState_TPM(298.15, pres, moll);
double Xmol[30];
HMW->getMoleFractions(Xmol);
ThermoPhase *hmwtb = (ThermoPhase *)HMW;
ThermoPhase *hmwtbDupl = hmwtb->duplMyselfAsThermoPhase();
HMWSoln *HMW1 = HMW;
HMWSoln *HMW2 = dynamic_cast<HMWSoln *>(hmwtbDupl);
for (int itherms = 0; itherms < 2; itherms++) {
if (itherms ==0) {
HMW = HMW1;
} else {
HMW = HMW2;
}
/*
* ThermoUnknowns
*/
double T;
double Cp0_NaCl = 0.0, Cp0_Naplus = 0.0, Cp0_Clminus = 0.0, Delta_Cp0s = 0.0, Cp0_H2O = 0.0;
double Cp_NaCl = 0.0, Cp_Naplus = 0.0, Cp_Clminus = 0.0, Cp_H2O = 0.0;
double molarCp0;
#ifdef DEBUG_HKM
FILE *ttt;
if (itherms ==0) {
ttt = fopen("table1.csv","w");
} else {
ttt = fopen("table2.csv","w");
}
#endif
printf("A_J/R: Comparison to Pitzer's book, p. 99, can be made.\n");
printf(" Agreement is within 12 pc \n");
printf("\n");
printf("Delta_Cp0: Heat Capacity of Solution per mole of salt (standard states)\n");
printf(" rxn for the ss heat of soln: "
"NaCl(s) -> Na+(aq) + Cl-(aq)\n");
printf("\n");
printf("Delta_Cps: Delta heat Capacity of Solution per mole of salt\n");
printf(" rxn for heat of soln: "
" n1 H2O(l,pure) + n2 NaCl(s) -> n2 MX(aq) + n1 H2O(l) \n");
printf(" Delta_Hs = (n1 h_H2O_bar + n2 h_MX_bar "
"- n1 h_H2O_0 - n2 h_MX_0)/n2\n");
printf("\n");
printf("phiJ: phiJ, calculated from the program, is checked\n");
printf(" against analytical formula in J_standalone program.\n");
printf(" (comparison against Eq. 12, Silvester and Pitzer)\n");
/*
* Create a Table of NaCl Enthalpy Properties as a Function
* of the Temperature
*/
printf("\n\n");
printf(" T, Pres, Aphi, A_J/R,"
" Delta_Cp0,"
" Delta_Cps, J, phiJ,"
" MolarCp, MolarCp0\n");
printf(" Kelvin, bar, sqrt(kg/gmol), sqrt(kg/gmol),"
" kJ/gmolSalt,"
" kJ/gmolSalt, kJ/gmolSoln, kJ/gmolSalt,"
" kJ/gmol, kJ/gmol\n");
#ifdef DEBUG_HKM
fprintf(ttt,"T, Pres, A_J/R, Delta_Cp0, Delta_Cps, J, phiJ\n");
fprintf(ttt,"Kelvin, bar, sqrt(kg/gmol), kJ/gmolSalt, kJ/gmolSalt, kJ/gmolSoln,"
"kJ/gmolSalt\n");
#endif
for (i = 0; i < TTable.NPoints + 1; i++) {
if (i == TTable.NPoints) {
T = 323.15;
} else {
T = TTable.T[i];
}
/*
* RT is in units of J/kmolK
*/
//double RT = GasConstant * T;
/*
* Make sure we are at the saturation pressure or above.
*/
double psat = HMW->satPressure(T);
pres = OneAtm;
if (psat > pres) pres = psat;
HMW->setState_TPM(T, pres, moll);
solid->setState_TP(T, pres);
/*
* Get the Standard State DeltaH
*/
solid->getCp_R(Cp0_R);
Cp0_NaCl = Cp0_R[0] * GasConstant * 1.0E-6;
HMW->getCp_R(Cp0_R);
Cp0_H2O = Cp0_R[0] * GasConstant * 1.0E-6;
Cp0_Naplus = Cp0_R[i1] * GasConstant * 1.0E-6;
Cp0_Clminus = Cp0_R[i2] * GasConstant * 1.0E-6;
/*
* Calculate the standard state heat of solution
* for NaCl(s) -> Na+ + Cl-
* units: kJ/gmolSalt
*/
Delta_Cp0s = Cp0_Naplus + Cp0_Clminus - Cp0_NaCl;
pmCp[0] = solid->cp_mole();
Cp_NaCl = pmCp[0] * 1.0E-6;
HMW->getPartialMolarCp(pmCp);
Cp_H2O = pmCp[0] * 1.0E-6;
Cp_Naplus = pmCp[i1] * 1.0E-6;
Cp_Clminus = pmCp[i2] * 1.0E-6;
//double Delta_Cp_Salt = Cp_NaCl - (Cp_Naplus + Cp_Clminus);
double molarCp = HMW->cp_mole() * 1.0E-6;
/*
* Calculate the heat capacity of solution for the reaction
* NaCl(s) -> Na+ + Cl-
*/
double Delta_Cps = (Xmol[0] * Cp_H2O +
Xmol[i1] * Cp_Naplus +
Xmol[i2] * Cp_Clminus
- Xmol[0] * Cp0_H2O
- Xmol[i1] * Cp_NaCl);
Delta_Cps /= Xmol[i1];
/*
* Calculate the relative heat capacity, J, from the
* partial molar quantities, units J/gmolSolutionK
*/
double J = (Xmol[0] * (Cp_H2O - Cp0_H2O) +
Xmol[i1] * (Cp_Naplus - Cp0_Naplus) +
Xmol[i2] * (Cp_Clminus - Cp0_Clminus));
/*
* Calculate the apparent relative molal heat capacity, phiJ,
* units of J/gmolSaltAddedK
*/
double phiJ = J / Xmol[i1];
double Aphi = HMW->A_Debye_TP(T, pres) / 3.0;
//double AL = HMW->ADebye_L(T,pres);
double AJ = HMW->ADebye_J(T, pres);
for (int k = 0; k < nsp; k++) {
Cp0_R[k] *= GasConstant * 1.0E-6;
}
molarCp0 = 0.0;
for (int k = 0; k < nsp; k++) {
molarCp0 += Xmol[k] * Cp0_R[k];
}
if (i != TTable.NPoints+1) {
printf("%13g, %13g, %13g, %13g, %13g, %13g, "
"%13g, %13g, %13g, %13g\n",
T, pres*1.0E-5, Aphi, AJ/GasConstant, Delta_Cp0s, Delta_Cps,
J, phiJ, molarCp , molarCp0 );
#ifdef DEBUG_HKM
fprintf(ttt,"%g, %g, %g, %g, %g, %g, %g\n",
T, pres*1.0E-5, AJ/GasConstant, Delta_Cp0s, Delta_Cps, J, phiJ);
#endif
}
}
printf("Breakdown of Heat Capacity Calculation at 323.15 K, 1atm:\n");
printf(" Species MoleFrac Molal Cp0 "
" partCp (partCp - Cp0)\n");
printf(" H2O(L)");
printf("%13g %13g %13g %13g %13g\n", Xmol[0], moll[0], Cp0_H2O , Cp_H2O, Cp_H2O-Cp0_H2O);
printf(" Na+ ");
printf("%13g %13g %13g %13g %13g\n", Xmol[i1], moll[i1],
Cp0_Naplus , Cp_Naplus, Cp_Naplus -Cp0_Naplus);
printf(" Cl- ");
printf("%13g %13g %13g %13g %13g\n", Xmol[i2], moll[i2],
Cp0_Clminus , Cp_Clminus, Cp_Clminus - Cp0_Clminus);
printf(" NaCl(s)");
printf("%13g %13g %13g %13g\n", 1.0,
Cp0_NaCl , Cp_NaCl, Cp_NaCl - Cp0_NaCl);
#ifdef DEBUG_HKM
fclose(ttt);
#endif
}
delete HMW1;
HMW = 0;
delete hmwtbDupl;
hmwtbDupl = 0;
delete solid;
solid = 0;
Cantera::appdelete();
return retn;
} catch (CanteraError) {
printf("caught error\n");
showErrors();
Cantera::appdelete();
return -1;
}
}

View file

@ -0,0 +1,120 @@
#!/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 = HMW_dupl_test
# the object files to be linked together. List those generated from Fortran
# and from C/C++ separately
OBJS = HMW_dupl_test.o sortAlgorithms.o
# Location of the current build. Will assume that tests are run
# in the source directory tree location
src_dir_tree = 0
# 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
INCLUDES=-I$(CANTERA_INCDIR) -I$(CANTERA_INCDIR)/thermo
else
CANTERA_INCDIR=@ctroot@/build/include/cantera
INCLUDES=-I$(CANTERA_INCDIR) -I$(CANTERA_INCDIR)/kernel
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@:
$(CXX) -c $< $(INCLUDES) $(CXX_FLAGS)
# How to compile the dependency file
.cpp.d:
@CXX_DEPENDS@ $(INCLUDES) $(CXX_FLAGS) $*.cpp > $*.d
# List of dependency files to be created
DEPENDS=$(OBJS:.o=.d)
# Program Name
PROGRAM = $(PROG_NAME)$(EXE_EXT)
all: $(PROGRAM) .depends
$(PROGRAM): $(OBJS) $(CANTERA_LIBDIR)/libctbase.a \
$(CANTERA_LIBDIR)/libthermo.a
$(CXX) -o $(PROGRAM) $(OBJS) $(LCXX_FLAGS) $(LINK_OPTIONS) \
$(CANTERA_LIBS) @LIBS@ $(FORT_LIBS) \
$(LCXX_END_LIBS)
# Add an additional target for stability:
$(OBJS): $(CANTERA_LIBDIR)/libctbase.a $(CANTERA_LIBDIR)/libthermo.a
# depends target -> forces recalculation of dependencies
depends:
@MAKE@ .depends
.depends: $(DEPENDS)
cat $(DEPENDS) > .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 *.o
../../../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,39 @@
<?xml version="1.0"?>
<ctml>
<validate reactions="yes" species="yes"/>
<!-- phase NaCl(S) -->
<phase dim="3" id="NaCl(S)">
<elementArray datasrc="elements.xml">
O H C Fe Ca N Na Cl
</elementArray>
<speciesArray datasrc="#species_NaCl(S)"> NaCl(S) </speciesArray>
<thermo model="StoichSubstance">
<density units="g/cm3">2.165</density>
</thermo>
<transport model="None"/>
<kinetics model="none"/>
</phase>
<!-- species definitions -->
<speciesData id="species_NaCl(S)">
<!-- species NaCl(S) -->
<species name="NaCl(S)">
<atomArray> Na:1 Cl:1 </atomArray>
<thermo>
<Shomate Pref="1 bar" Tmax="1075.0" Tmin="250.0">
<floatArray size="7">
50.72389, 6.672267, -2.517167,
10.15934, -0.200675, -427.2115,
130.3973
</floatArray>
</Shomate>
</thermo>
<density units="g/cm3">2.165</density>
</species>
</speciesData>
</ctml>

View file

@ -0,0 +1,2 @@
Check on the duplication routines for HMWSoln
In other words, this checks whether duplMyselfAsThermoPhase() works.

View file

@ -0,0 +1,129 @@
/*
* $Id$
*/
/*
* Copywrite 2004 Sandia Corporation. Under the terms of Contract
* DE-AC04-94AL85000, there is a non-exclusive license for use of this
* work by or on behalf of the U.S. Government. Export of this program
* may require a license from the United States Government.
*/
#ifndef TEMPERATURE_TABLE_H
#define TEMPERATURE_TABLE_H
#include "sortAlgorithms.h"
//#include "mdp_allo.h"
#include <vector>
using std::vector;
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/**
* This Class constructs a vector of temperature from which to make
* a table.
*/
class TemperatureTable {
public:
int NPoints;
bool Include298;
double Tlow; //!< Min temperature for thermo data fit
double Thigh; //!< Max temperature for thermo table
double DeltaT;
vector<double> T;
int numAddedTs;
vector<double> AddedTempVector;
public:
/*
* Default constructor for TemperatureTable()
*/
TemperatureTable(const int nPts = 14,
const bool inc298 = true,
const double tlow = 300.,
const double deltaT = 100.,
const int numAdded = 0,
const double *addedTempVector = 0) :
NPoints(nPts),
Include298(inc298),
Tlow(tlow),
DeltaT(deltaT),
T(0),
numAddedTs(numAdded) {
/****************************/
int i;
// AddedTempVector = mdp_alloc_dbl_1(numAdded, 0.0);
AddedTempVector.resize(numAdded, 0.0);
for (int i = 0; i < numAdded; i++) {
AddedTempVector[i] = addedTempVector[i];
}
//mdp_copy_dbl_1(AddedTempVector, addedTempVector, numAdded);
// T = mdp_alloc_dbl_1(NPoints, 0.0);
T.resize(NPoints, 0.0);
double TCurrent = Tlow;
for (i = 0; i < NPoints; i++) {
T[i] = TCurrent;
TCurrent += DeltaT;
}
if (Include298) {
T.push_back(298.15);
//mdp_realloc_dbl_1(&T, NPoints+1, NPoints, 298.15);
NPoints++;
}
if (numAdded > 0) {
//mdp_realloc_dbl_1(&T, NPoints+numAdded, NPoints, 0.0);
T.resize( NPoints+numAdded, 0.0);
for (i = 0; i < numAdded; i++) {
T[i+NPoints] = addedTempVector[i];
}
NPoints += numAdded;
}
sort_dbl_1(DATA_PTR(T), NPoints);
}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/*
* Destructor
*/
~TemperatureTable() {
//mdp_safe_free((void **) &AddedTempVector);
// mdp_safe_free((void **) &T);
}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/*
* Overloaded operator[]
*
* return the array value in the vector
*/
double operator[](const int i) {
return T[i];
}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/*
* size()
*/
int size() {
return NPoints;
}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/*
* Block assignment and copy constructors: not needed.
*/
private:
TemperatureTable(const TemperatureTable &);
TemperatureTable& operator=(const TemperatureTable&);
};
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
#endif

View file

@ -0,0 +1,78 @@
A_J/R: Comparison to Pitzer's book, p. 99, can be made.
Agreement is within 12 pc
Delta_Cp0: Heat Capacity of Solution per mole of salt (standard states)
rxn for the ss heat of soln: NaCl(s) -> Na+(aq) + Cl-(aq)
Delta_Cps: Delta heat Capacity of Solution per mole of salt
rxn for heat of soln: n1 H2O(l,pure) + n2 NaCl(s) -> n2 MX(aq) + n1 H2O(l)
Delta_Hs = (n1 h_H2O_bar + n2 h_MX_bar - n1 h_H2O_0 - n2 h_MX_0)/n2
phiJ: phiJ, calculated from the program, is checked
against analytical formula in J_standalone program.
(comparison against Eq. 12, Silvester and Pitzer)
T, Pres, Aphi, A_J/R, Delta_Cp0, Delta_Cps, J, phiJ, MolarCp, MolarCp0
Kelvin, bar, sqrt(kg/gmol), sqrt(kg/gmol), kJ/gmolSalt, kJ/gmolSalt, kJ/gmolSoln, kJ/gmolSalt, kJ/gmol, kJ/gmol
273.15, 1.01325, 0.376717, 4.08576, -0.158977, -0.0364733, 0.0111048, 0.122504, 0.0634482, 0.0523434
298.15, 1.01325, 0.391447, 4.61226, -0.130795, -0.0199566, 0.0100473, 0.110838, 0.0644397, 0.0543924
323.15, 1.01325, 0.410293, 5.50264, -0.115719, -0.0105888, 0.00952988, 0.10513, 0.065338, 0.0558081
348.15, 1.01325, 0.433273, 6.72554, -0.113771, -0.00869263, 0.00952522, 0.105079, 0.065728, 0.0562028
373.15, 1.01418, 0.460559, 8.35444, -0.124962, -0.0135747, 0.0100971, 0.111387, 0.0656563, 0.0555592
398.15, 2.32238, 0.492454, 10.5438, -0.14929, -0.0237587, 0.0113792, 0.125532, 0.0653078, 0.0539285
423.15, 4.76165, 0.529514, 13.5812, -0.186752, -0.0364892, 0.0136211, 0.150263, 0.0649994, 0.0513783
448.15, 8.92602, 0.572549, 17.9961, -0.237338, -0.0466955, 0.0172814, 0.190643, 0.0652692, 0.0479877
473.15, 15.5493, 0.622769, 24.826, -0.301036, -0.0444443, 0.0232596, 0.256592, 0.0671305, 0.0438709
498.15, 25.4972, 0.682036, 36.2735, -0.377833, -0.00866191, 0.0334648, 0.369171, 0.0726787, 0.0392139
523.15, 39.7617, 0.753389, 57.5198, -0.467713, 0.110207, 0.0523875, 0.57792, 0.0867379, 0.0343503
548.15, 59.4639, 0.842213, 102.542, -0.570661, 0.445824, 0.0921428, 1.01649, 0.122089, 0.0299461
573.15, 85.879, 0.959258, 217.131, -0.68666, 1.43604, 0.19242, 2.1227, 0.219976, 0.0275567
598.15, 120.51, 1.13023, 604.241, -0.815692, 5.02147, 0.52913, 5.83716, 0.560947, 0.0318178
623.15, 165.294, 1.43872, 2813.78, -0.957741, 26.0219, 2.44566, 26.9797, 2.51311, 0.0674475
323.15, 1.01325, 0.410293, 5.50264, -0.115719, -0.0105888, 0.00952988, 0.10513, 0.065338, 0.0558081
Breakdown of Heat Capacity Calculation at 323.15 K, 1atm:
Species MoleFrac Molal Cp0 partCp (partCp - Cp0)
H2O(L) 0.818703 0 0.075328 0.0695928 -0.00573522
Na+ 0.0906484 6.146 0.0284152 0.106879 0.0784643
Cl- 0.0906484 6.146 -0.0930958 -0.0146316 0.0784643
NaCl(s) 1 0.0510383 0.0510383 0
A_J/R: Comparison to Pitzer's book, p. 99, can be made.
Agreement is within 12 pc
Delta_Cp0: Heat Capacity of Solution per mole of salt (standard states)
rxn for the ss heat of soln: NaCl(s) -> Na+(aq) + Cl-(aq)
Delta_Cps: Delta heat Capacity of Solution per mole of salt
rxn for heat of soln: n1 H2O(l,pure) + n2 NaCl(s) -> n2 MX(aq) + n1 H2O(l)
Delta_Hs = (n1 h_H2O_bar + n2 h_MX_bar - n1 h_H2O_0 - n2 h_MX_0)/n2
phiJ: phiJ, calculated from the program, is checked
against analytical formula in J_standalone program.
(comparison against Eq. 12, Silvester and Pitzer)
T, Pres, Aphi, A_J/R, Delta_Cp0, Delta_Cps, J, phiJ, MolarCp, MolarCp0
Kelvin, bar, sqrt(kg/gmol), sqrt(kg/gmol), kJ/gmolSalt, kJ/gmolSalt, kJ/gmolSoln, kJ/gmolSalt, kJ/gmol, kJ/gmol
273.15, 1.01325, 0.376717, 4.08576, -0.158977, -0.0364733, 0.0111048, 0.122504, 0.0634482, 0.0523434
298.15, 1.01325, 0.391447, 4.61226, -0.130795, -0.0199566, 0.0100473, 0.110838, 0.0644397, 0.0543924
323.15, 1.01325, 0.410293, 5.50264, -0.115719, -0.0105888, 0.00952988, 0.10513, 0.065338, 0.0558081
348.15, 1.01325, 0.433273, 6.72554, -0.113771, -0.00869263, 0.00952522, 0.105079, 0.065728, 0.0562028
373.15, 1.01418, 0.460559, 8.35444, -0.124962, -0.0135747, 0.0100971, 0.111387, 0.0656563, 0.0555592
398.15, 2.32238, 0.492454, 10.5438, -0.14929, -0.0237587, 0.0113792, 0.125532, 0.0653078, 0.0539285
423.15, 4.76165, 0.529514, 13.5812, -0.186752, -0.0364892, 0.0136211, 0.150263, 0.0649994, 0.0513783
448.15, 8.92602, 0.572549, 17.9961, -0.237338, -0.0466955, 0.0172814, 0.190643, 0.0652692, 0.0479877
473.15, 15.5493, 0.622769, 24.826, -0.301036, -0.0444443, 0.0232596, 0.256592, 0.0671305, 0.0438709
498.15, 25.4972, 0.682036, 36.2735, -0.377833, -0.00866191, 0.0334648, 0.369171, 0.0726787, 0.0392139
523.15, 39.7617, 0.753389, 57.5198, -0.467713, 0.110207, 0.0523875, 0.57792, 0.0867379, 0.0343503
548.15, 59.4639, 0.842213, 102.542, -0.570661, 0.445824, 0.0921428, 1.01649, 0.122089, 0.0299461
573.15, 85.879, 0.959258, 217.131, -0.68666, 1.43604, 0.19242, 2.1227, 0.219976, 0.0275567
598.15, 120.51, 1.13023, 604.241, -0.815692, 5.02147, 0.52913, 5.83716, 0.560947, 0.0318178
623.15, 165.294, 1.43872, 2813.78, -0.957741, 26.0219, 2.44566, 26.9797, 2.51311, 0.0674475
323.15, 1.01325, 0.410293, 5.50264, -0.115719, -0.0105888, 0.00952988, 0.10513, 0.065338, 0.0558081
Breakdown of Heat Capacity Calculation at 323.15 K, 1atm:
Species MoleFrac Molal Cp0 partCp (partCp - Cp0)
H2O(L) 0.818703 0 0.075328 0.0695928 -0.00573522
Na+ 0.0906484 6.146 0.0284152 0.106879 0.0784643
Cl- 0.0906484 6.146 -0.0930958 -0.0146316 0.0784643
NaCl(s) 1 0.0510383 0.0510383 0

View file

@ -0,0 +1,42 @@
#!/bin/sh
#
#
temp_success="1"
/bin/rm -f output.txt outputa.txt
##########################################################################
prog=HMW_dupl_test
if test ! -x $prog ; then
echo $prog ' does not exist'
exit -1
fi
##########################################################################
/bin/rm -f test.out test.diff output.txt
#################################################################
#
CANTERA_DATA=${CANTERA_DATA:=../../../data/inputs}; export CANTERA_DATA
CANTERA_BIN=${CANTERA_BIN:=../../../bin}
#################################################################
$prog HMW_NaCl_sp1977_alt.xml > output.txt
retnStat=$?
if [ $retnStat != "0" ]
then
temp_success="0"
echo "$prog returned with bad status, $retnStat, check output"
fi
$CANTERA_BIN/exp3to2.sh output.txt > outputa.txt
diff -w outputa.txt output_blessed.txt > diff_test.out
retnStat=$?
if [ $retnStat = "0" ]
then
echo "successful diff comparison on $prog test"
else
echo "unsuccessful diff comparison on $prog test"
echo "FAILED" > csvCode.txt
temp_success="0"
fi

View file

@ -0,0 +1,54 @@
/*
* @file sortAlgorithms.h
*
* $Author$
* $Revision$
* $Date$
*/
/*
* Copywrite 2004 Sandia Corporation. Under the terms of Contract
* DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
* retains certain rights in this software.
* See file License.txt for licensing information.
*/
#include "sortAlgorithms.h"
/**************************************************************/
void sort_dbl_1(double * const x, const int n) {
double rra;
int ll = n/2;
int iret = n - 1;
while (1 > 0) {
if (ll > 0) {
ll--;
rra = x[ll];
} else {
rra = x[iret];
x[iret] = x[0];
iret--;
if (iret == 0) {
x[0] = rra;
return;
}
}
int i = ll;
int j = ll + ll + 1;
while (j <= iret) {
if (j < iret) {
if (x[j] < x[j+1])
j++;
}
if (rra < x[j]) {
x[i] = x[j];
i = j;
j = j + j + 1;
} else {
j = iret + 1;
}
}
x[i] = rra;
}
}
/*****************************************************/

View file

@ -0,0 +1,21 @@
/*
* @file sortAlgorithms.h
*
* $Author$
* $Revision$
* $Date$
*/
/*
* Copywrite 2004 Sandia Corporation. Under the terms of Contract
* DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
* retains certain rights in this software.
* See file License.txt for licensing information.
*/
#ifndef SORTALGORITHMS_H
#define SORTALGORITHMS_H
void sort_dbl_1(double * const x, const int n);
#endif