From 5f327277b0fcdb391c13efdab9a22f1711246483 Mon Sep 17 00:00:00 2001 From: Christopher Lueth Date: Mon, 1 Mar 2010 23:35:35 +0000 Subject: [PATCH] Corrected memory allocation for ionConductivity, mobRatio, selfDiffusion, etc. that may not be required as input. --- Cantera/src/transport/LiquidTransport.cpp | 11 ++++- Cantera/src/transport/LiquidTransportData.cpp | 2 + .../src/transport/LiquidTransportParams.cpp | 11 ++++- Cantera/src/transport/TransportFactory.cpp | 40 +++++++++++-------- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/Cantera/src/transport/LiquidTransport.cpp b/Cantera/src/transport/LiquidTransport.cpp index 262b12f0f..8833140b0 100644 --- a/Cantera/src/transport/LiquidTransport.cpp +++ b/Cantera/src/transport/LiquidTransport.cpp @@ -263,6 +263,7 @@ namespace Cantera { int k; // constant substance attributes m_thermo = tr.thermo; + tr.thermo = 0; m_velocityBasis = tr.velocityBasis_; m_nsp = m_thermo->nSpecies(); m_nBinInt = m_nsp*(m_nsp-1)/2; @@ -310,11 +311,13 @@ namespace Cantera { //first populate mixing rules and indices for (k = 0; k < m_nsp; k++) { - m_selfDiffMixModel[k] = tr.selfDiffusion[k]; + m_selfDiffMixModel[k] = tr.selfDiffusion[k]; + tr.selfDiffusion[k] = 0; m_selfDiffMixModelIndex[k] = tr.selfDiffIndex[k]; } for (k = 0; k < m_nBinInt; k++) { m_mobRatMixModel[k] = tr.mobilityRatio[k]; + tr.mobilityRatio[k] = 0; m_mobRatMixModelIndex[k] = tr.mobRatIndex[k]; } @@ -322,11 +325,14 @@ namespace Cantera { for (k = 0; k < m_nsp; k++) { Cantera::LiquidTransportData <d = tr.LTData[k]; m_viscTempDep_Ns[k] = ltd.viscosity; + ltd.viscosity = 0; m_ionCondTempDep_Ns[k] = ltd.ionConductivity; + ltd.ionConductivity = 0; for (int j = 0; j < m_nBinInt; j++){ for (int l=0; l < m_nBinInt; l++){ if (m_mobRatMixModelIndex[j] == ltd.mobRatIndex[l]) { m_mobRatTempDep_Ns[j][k] = ltd.mobilityRatio[l]; + ltd.mobilityRatio[l] = 0; m_mobRatTempDepIndex[j] = ltd.mobRatIndex[l]; break; } @@ -336,13 +342,16 @@ namespace Cantera { for (int l=0; l < (int) m_selfDiffMixModelIndex.size(); l++){ if (m_selfDiffMixModelIndex[j] == ltd.selfDiffIndex[l]) { m_selfDiffTempDep_Ns[j][k] = ltd.selfDiffusion[l]; + ltd.selfDiffusion[l] = 0; m_selfDiffTempDepIndex[j] = ltd.selfDiffIndex[l]; break; } } } m_lambdaTempDep_Ns[k] = ltd.thermalCond; + ltd.thermalCond = 0; m_radiusTempDep_Ns[k] = ltd.hydroRadius; + ltd.hydroRadius = 0; } diff --git a/Cantera/src/transport/LiquidTransportData.cpp b/Cantera/src/transport/LiquidTransportData.cpp index 496fb7c95..e801adf5b 100644 --- a/Cantera/src/transport/LiquidTransportData.cpp +++ b/Cantera/src/transport/LiquidTransportData.cpp @@ -49,6 +49,7 @@ namespace Cantera { speciesName("-"), hydroRadius(0), viscosity(0), + ionConductivity(0), thermalCond(0), electCond(0), speciesDiffusivity(0) @@ -61,6 +62,7 @@ namespace Cantera { speciesName("-"), hydroRadius(0), viscosity(0), + ionConductivity(0), thermalCond(0), electCond(0), speciesDiffusivity(0) diff --git a/Cantera/src/transport/LiquidTransportParams.cpp b/Cantera/src/transport/LiquidTransportParams.cpp index 41cebab6a..446639def 100644 --- a/Cantera/src/transport/LiquidTransportParams.cpp +++ b/Cantera/src/transport/LiquidTransportParams.cpp @@ -224,7 +224,7 @@ namespace Cantera { //==================================================================================================================== LiquidTransportParams::LiquidTransportParams() : - viscosity(0), thermalCond(0), speciesDiffusivity(0), electCond(0), hydroRadius(0), model_viscosity(LTI_MODEL_NOTSET), + viscosity(0), ionConductivity(0), thermalCond(0), speciesDiffusivity(0), electCond(0), hydroRadius(0), model_viscosity(LTI_MODEL_NOTSET), model_speciesDiffusivity(LTI_MODEL_NOTSET), model_hydroradius(LTI_MODEL_NOTSET) { @@ -233,6 +233,7 @@ namespace Cantera { LiquidTransportParams::~LiquidTransportParams() { delete viscosity; + delete ionConductivity; delete thermalCond; delete speciesDiffusivity; delete electCond; @@ -616,6 +617,7 @@ namespace Cantera { m_ionCondMix = 0; m_ionCondMixModel = trParam.ionConductivity; + trParam.ionConductivity = 0; m_ionCondSpecies.resize(nsp,0); m_mobRatMix.resize(nsp,nsp,0.0); m_mobRatMixModel.resize(nBinInt); @@ -628,11 +630,13 @@ namespace Cantera { for ( int k = 0; k < nBinInt; k++ ) { m_mobRatMixModel[k] = trParam.mobilityRatio[k]; + trParam.mobilityRatio[k] = 0; m_mobRatSpecies[k].resize(nsp,0); m_mobRatIndex[k] = trParam.mobRatIndex[k]; } for ( int k = 0; k < nsp; k++ ) { m_selfDiffMixModel[k] = trParam.selfDiffusion[k]; + trParam.selfDiffusion[k] = 0; m_selfDiffSpecies[k].resize(nsp,0); m_selfDiffIndex[k] = trParam.selfDiffIndex[k]; } @@ -640,11 +644,14 @@ namespace Cantera { for (int k = 0; k < nsp; k++) { Cantera::LiquidTransportData <d = trParam.LTData[k]; m_ionCondSpecies[k] = ltd.ionConductivity; + ltd.ionConductivity = 0; for ( int j = 0; j < nBinInt; j++ ){ m_mobRatSpecies[j][k] = ltd.mobilityRatio[j]; + ltd.mobilityRatio[j] = 0; } for ( int j = 0; j < nsp; j++ ){ - m_selfDiffSpecies[j][k] = ltd.selfDiffusion[j]; + m_selfDiffSpecies[j][k] = ltd.selfDiffusion[j]; + ltd.selfDiffusion[j] = 0; } } } diff --git a/Cantera/src/transport/TransportFactory.cpp b/Cantera/src/transport/TransportFactory.cpp index f000345e2..81c0d0bc8 100644 --- a/Cantera/src/transport/TransportFactory.cpp +++ b/Cantera/src/transport/TransportFactory.cpp @@ -958,7 +958,8 @@ namespace Cantera { */ std::map datatable; - int nsp = static_cast(xspecies.size()); + int nsp = trParam.nsp_;//static_cast(xspecies.size()); + int nBinInt = nsp*(nsp-1)/2; // read all entries in database into 'datatable' and check for // errors. Note that this procedure validates all entries, not @@ -982,6 +983,14 @@ namespace Cantera { LiquidTransportData data; data.speciesName = name; + //data.viscosity = 0; + //data.ionConductivity = 0; + + data.mobRatIndex.resize(nBinInt,""); + data.mobilityRatio.resize(nBinInt,0); + data.selfDiffIndex.resize(nsp,""); + data.selfDiffusion.resize(nsp,0); + //////// new stuff int num = trNode.nChildren(); for (int iChild = 0; iChild < num; iChild++) { @@ -1004,10 +1013,7 @@ namespace Cantera { case TP_MOBILITYRATIO: { int iSpec; - int numSpec = xmlChild.nChildren(); - data.mobRatIndex.resize(numSpec); - data.mobilityRatio.resize(numSpec); - for (iSpec = 0; iSpec< numSpec; iSpec++){ + for (iSpec = 0; iSpec< nBinInt; iSpec++){ XML_Node &propSpecNode = xmlChild.child(iSpec); std::string specName = propSpecNode.name(); data.mobRatIndex[iSpec] = specName; @@ -1021,10 +1027,7 @@ namespace Cantera { case TP_SELFDIFFUSION: { int iSpec; - int numSpec = xmlChild.nChildren(); - data.selfDiffIndex.resize(numSpec); - data.selfDiffusion.resize(numSpec); - for (iSpec = 0; iSpec< numSpec; iSpec++){ + for (iSpec = 0; iSpec< nsp; iSpec++){ XML_Node &propSpecNode = xmlChild.child(iSpec); std::string specName = propSpecNode.name(); data.selfDiffIndex[iSpec] = specName; @@ -1116,11 +1119,20 @@ namespace Cantera { { try { + int nsp = trParam.nsp_; + int nBinInt = nsp*(nsp-1)/2; + int num = transportNode.nChildren(); for (int iChild = 0; iChild < num; iChild++) { //tranTypeNode is a type of transport property like viscosity XML_Node &tranTypeNode = transportNode.child(iChild); std::string nodeName = tranTypeNode.name(); + + trParam.mobRatIndex.resize(nBinInt,""); + trParam.mobilityRatio.resize(nBinInt,0); + trParam.selfDiffIndex.resize(nsp,""); + trParam.selfDiffusion.resize(nsp,0); + if ( tranTypeNode.hasChild("compositionDependence")) { //compDepNode contains the interaction model XML_Node &compDepNode = tranTypeNode.child("compositionDependence"); @@ -1139,10 +1151,7 @@ namespace Cantera { case TP_MOBILITYRATIO: { int iSpec; - int numSpec = compDepNode.nChildren(); - trParam.mobRatIndex.resize(numSpec); - trParam.mobilityRatio.resize(numSpec); - for (iSpec = 0; iSpec< numSpec; iSpec++){ + for (iSpec = 0; iSpec< nBinInt; iSpec++){ XML_Node &propSpecNode = compDepNode.child(iSpec); std::string specName = propSpecNode.name(); trParam.mobRatIndex[iSpec] = specName; @@ -1155,10 +1164,7 @@ namespace Cantera { case TP_SELFDIFFUSION: { int iSpec; - int numSpec = compDepNode.nChildren(); - trParam.selfDiffIndex.resize(numSpec); - trParam.selfDiffusion.resize(numSpec); - for (iSpec = 0; iSpec< numSpec; iSpec++){ + for (iSpec = 0; iSpec< nsp; iSpec++){ XML_Node &propSpecNode = compDepNode.child(iSpec); std::string specName = propSpecNode.name(); trParam.selfDiffIndex[iSpec] = specName;