From 582816d3f7394dace5194cd1e3350244e46b4b10 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 25 Jan 2008 20:32:29 +0000 Subject: [PATCH] Simplification - Took out vcs_TV.cpp method for calculating TV problems. It was a duplicate. --- Cantera/src/equil/.cvsignore | 1 + Cantera/src/equil/Makefile.in | 4 +- Cantera/src/equil/vcs_TV.cpp | 112 ----------------------------- Cantera/src/equil/vcs_defs.h | 10 +-- Cantera/src/equil/vcs_funcVtot.cpp | 68 ------------------ Cantera/src/equil/vcs_internal.h | 23 ------ Cantera/src/equil/vcs_solve.cpp | 56 +++++++++++---- Cantera/src/equil/vcs_solve.h | 1 - 8 files changed, 45 insertions(+), 230 deletions(-) delete mode 100644 Cantera/src/equil/vcs_TV.cpp delete mode 100644 Cantera/src/equil/vcs_funcVtot.cpp diff --git a/Cantera/src/equil/.cvsignore b/Cantera/src/equil/.cvsignore index 615a00414..2b40c6379 100644 --- a/Cantera/src/equil/.cvsignore +++ b/Cantera/src/equil/.cvsignore @@ -2,3 +2,4 @@ Makefile *.d .depends TODO.txt +old diff --git a/Cantera/src/equil/Makefile.in b/Cantera/src/equil/Makefile.in index b63177f73..34da95186 100644 --- a/Cantera/src/equil/Makefile.in +++ b/Cantera/src/equil/Makefile.in @@ -63,11 +63,11 @@ endif ifeq ($(do_VCSnonideal), 1) VCSNONIDEAL_OBJ = vcs_solve_TP.o vcs_VolPhase.o vcs_solve.o vcs_prob.o \ - vcs_TP.o vcs_TV.o vcs_report.o vcs_util.o \ + vcs_TP.o vcs_report.o vcs_util.o \ vcs_IntStarStar.o vcs_DoubleStarStar.o vcs_elem.o \ vcs_elem_rearrange.o vcs_MultiPhaseEquil.o \ vcs_nasa_poly.o vcs_nondim.o vcs_Exception.o \ - vcs_funcVtot.o vcs_inest.o vcs_rearrange.o \ + vcs_inest.o vcs_rearrange.o \ vcs_root1d.o vcs_rxnadj.o \ vcs_SpeciesProperties.o vcs_equilibrate.o \ vcs_prep.o vcs_species_thermo.o vcs_Gibbs.o \ diff --git a/Cantera/src/equil/vcs_TV.cpp b/Cantera/src/equil/vcs_TV.cpp deleted file mode 100644 index 941e00af8..000000000 --- a/Cantera/src/equil/vcs_TV.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* ======================================================================= */ -/* -------------------------------------------------- */ -/* | RCS Head Information on zuzax.pchem.sandia.gov | */ -/* -------------------------------------------------- */ -/* $RCSfile$ */ -/* $Author$ */ -/* $Date$ */ -/* $Revision$ */ -/* ======================================================================= */ -#include -#include -#include - -#include "vcs_solve.h" -#include "vcs_internal.h" -#include "vcs_VolPhase.h" -#include "vcs_species_thermo.h" - -namespace VCSnonideal { - -/************************************************************************** - * - * vcs_TV: - * - * Solve an equilibrium problem at a particular fixed temperature - * and volume. - * This is done as a root finder problem, solving repetative - * calls to solve_TP. - * - * ipr = 1 -> Print results to standard output - * 0 -> don't report on anything - * ip1 = 1 -> Print intermediate results. - * maxit -> Maximum number of iterations for the algorithm - * T = Temperature (Kelvin) - * Pres = Pressure (units specififed by if__ variable) - */ -int VCS_SOLVE::vcs_TV(int ipr, int ip1, int maxit, double T_arg, double VolRequest) -{ - int iconv, varID; - double Pmin, Pmax, Preturn; - VCS_FUNC_PTR func; - - /* - * Store the temperature in the private global variables - */ - T = T_arg; - - /* - * Set the unknown variable to the pressure - */ - varID = 1; - - /* - * Set the function to the volume function - */ - func = vcs_funcVtot; - - /* - * Set max and min Pressures - */ - Pmin = 0.0; - Pmax = 1.0E30; - Preturn = 1.0; - - iconv = vcsUtil_root1d(Pmin, Pmax, maxit, func, (void *) this, - VolRequest, varID, &Preturn); - - /* - * Return the convergence success flag. - */ - return iconv; -} - - /************************************************************************** - * - * vcs_VolTotal - * - * This function calculates the partial molar volume - * for all species, kspec, in the thermo problem - * at the temperature TKelvin and pressure, Pres, pres is in atm. - * And, it calculates the total volume of the combined system. - * - * Input - * iphase - * TKelvin - * pres - * w[] => vector containing the current mole numbers. - * - * Output - * VolPM[] => For species in all phase, the entries are the - * partial molar volumes - * return value = Total volume of the phase in L**3 / MOL_UNITS - * - * (L and MOL_UNITS determined from global units value if__) - */ -double VCS_SOLVE::vcs_VolTotal(double tkelvin, double pres, double w[], - double volPM[]) -{ - double volTot = 0.0; - for (int iphase = 0; iphase < NPhase; iphase++) { - vcs_VolPhase *Vphase = VPhaseList[iphase]; - Vphase->setState_TP(tkelvin, pres); - Vphase->setMolesFromVCS(w); - double volp = Vphase->VolPM_calc(); - (void) Vphase->sendToVCSVolPM(volPM); - volTot += volp; - } - return volTot; -} -/**************************************************************************/ -} - diff --git a/Cantera/src/equil/vcs_defs.h b/Cantera/src/equil/vcs_defs.h index f69bfd5e2..2d75a3f3e 100644 --- a/Cantera/src/equil/vcs_defs.h +++ b/Cantera/src/equil/vcs_defs.h @@ -74,15 +74,6 @@ namespace VCSnonideal { #define VCS_FAILED_LOOKUP -5 #define VCS_MP_FAIL -6 -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ -/* - * Problem Types - */ -#define VCS_PROBTYPE_TP 0 -#define VCS_PROBTYPE_TV 1 - /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ @@ -93,6 +84,7 @@ namespace VCSnonideal { #define VCS_MAX_NAME_LEN_P1 32 +#define VCS_PROBTYPE_TP 0 /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ diff --git a/Cantera/src/equil/vcs_funcVtot.cpp b/Cantera/src/equil/vcs_funcVtot.cpp deleted file mode 100644 index 2931d66b0..000000000 --- a/Cantera/src/equil/vcs_funcVtot.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @file vcs_funcVtot.cpp - * Routine to calculate tht total volume of an extrinsic system. - */ -/* - * $Id$ - */ -/* - * Copywrite (2006) Sandia Corporation. Under the terms of - * Contract DE-AC04-94AL85000 with Sandia Corporation, the - * U.S. Government retains certain rights in this software. - */ - -#include -#include -#include - -#include "vcs_solve.h" -#include "vcs_internal.h" - -#define TOL_CONV 1.0E-5 - -namespace VCSnonideal { - -/************************************************************************** - * - * vcs_funcVtot: - * - * This is the rootfinder function call for the function vcs_TV(). - * - */ -double vcs_funcVtot(double xval, double Vtarget, int varID, void *fptrPassthrough, int *err) -{ - VCS_SOLVE *vptr = (VCS_SOLVE *) fptrPassthrough; - static int first_time = TRUE; - int retn; - double vol; - if (varID == 0) { - vptr->T = xval; - } else if (varID == 1) { - vptr->Pres = xval; - } -#ifdef DEBUG_MODE - retn = vptr->vcs_TP(1, 1, 10000, vptr->T, vptr->Pres); -#else - retn = vptr->vcs_TP(0, 0, 10000, vptr->T, vptr->Pres); -#endif - if (retn != VCS_SUCCESS) { - plogf("vcs_funcVtot ERROR: vcs_TP returned error condition, %d\n", - retn); - *err = retn; - } - vol = vptr->vcs_VolTotal(vptr->T, vptr->Pres, VCS_DATA_PTR(vptr->soln), - VCS_DATA_PTR(vptr->VolPM)); -#ifdef DEBUG_MODE - vptr->vcs_report(retn); -#endif - - - if (first_time) { - first_time = FALSE; - vptr->iest = FALSE; - } - return (vol - Vtarget); -} -/*****************************************************************************/ -} - diff --git a/Cantera/src/equil/vcs_internal.h b/Cantera/src/equil/vcs_internal.h index e914b6b63..006096df5 100644 --- a/Cantera/src/equil/vcs_internal.h +++ b/Cantera/src/equil/vcs_internal.h @@ -102,29 +102,6 @@ namespace VCSnonideal { double T_Time_vcs; }; - //! This is the rootfinder function call for the function vcs_TV() - /*! - * The function is of type VCS_FUNC_PTR - * It's the function call for the vcs_TV(). - * Solves for the total volume of the system, by first calculating - * the equilibrium wrt T,P. - * Routine then returns - * - * \f[ - * f(x) = V(T,P) - Vtarget - * \f] - * - * @param xval Currently value of the independent variable - * @param Vtarget Target value of the volume - * @param varID If 0, xval is temperature, If 1, xval is pressure. - * @param fptrPassthrough Pointer to VCS_SOLVE object - * @param err Return 0 for success. Anything else is an error code. - * - */ - double vcs_funcVtot(double xval, double Vtarget, int varID, - void *fptrPassthrough, int *err); - - //! Returns the value of the gas constant in the units specified by parameter /*! * @param mu_units Specifies the units. diff --git a/Cantera/src/equil/vcs_solve.cpp b/Cantera/src/equil/vcs_solve.cpp index 96c931e85..21d4ae096 100644 --- a/Cantera/src/equil/vcs_solve.cpp +++ b/Cantera/src/equil/vcs_solve.cpp @@ -387,18 +387,9 @@ namespace VCSnonideal { * a 2x2 Newton's method, using loops over vcs_TP() to * calculate the residual and Jacobian) */ - switch (vprob->prob_type) { - case VCS_PROBTYPE_TP: - iconv = vcs_TP(ipr, ip1, maxit, vprob->T, vprob->Pres); - break; - case VCS_PROBTYPE_TV: - iconv = vcs_TV(ipr, ip1, maxit, vprob->T, vprob->Vol); - break; - default: - plogf("Unknown or unimplemented problem type: %d\n", - vprob->prob_type); - return VCS_PUB_BAD; - } + + iconv = vcs_TP(ipr, ip1, maxit, vprob->T, vprob->Pres); + /* * If requested to print anything out, go ahead and do so; @@ -994,9 +985,7 @@ namespace VCSnonideal { return VCS_SUCCESS; } - /*****************************************************************************/ - /*****************************************************************************/ - /*****************************************************************************/ + // Initialize the internal counters /* * Initialize the internal counters containing the subroutine call @@ -1023,6 +1012,43 @@ namespace VCSnonideal { } } + /************************************************************************** + * + * vcs_VolTotal + * + * This function calculates the partial molar volume + * for all species, kspec, in the thermo problem + * at the temperature TKelvin and pressure, Pres, pres is in atm. + * And, it calculates the total volume of the combined system. + * + * Input + * iphase + * TKelvin + * pres + * w[] => vector containing the current mole numbers. + * + * Output + * VolPM[] => For species in all phase, the entries are the + * partial molar volumes + * return value = Total volume of the phase in L**3 / MOL_UNITS + * + * (L and MOL_UNITS determined from global units value if__) + */ +double VCS_SOLVE::vcs_VolTotal(double tkelvin, double pres, double w[], + double volPM[]) +{ + double volTot = 0.0; + for (int iphase = 0; iphase < NPhase; iphase++) { + vcs_VolPhase *Vphase = VPhaseList[iphase]; + Vphase->setState_TP(tkelvin, pres); + Vphase->setMolesFromVCS(w); + double volp = Vphase->VolPM_calc(); + (void) Vphase->sendToVCSVolPM(volPM); + volTot += volp; + } + return volTot; +} + } diff --git a/Cantera/src/equil/vcs_solve.h b/Cantera/src/equil/vcs_solve.h index 3e3039df6..0c85cc6c8 100644 --- a/Cantera/src/equil/vcs_solve.h +++ b/Cantera/src/equil/vcs_solve.h @@ -166,7 +166,6 @@ public: int vcs_evalSS_TP(int ipr, int ip1, double Temp, double pres); void vcs_fePrep_TP(void); - int vcs_TV(int ipr, int ip1, int maxit, double T, double VolRequest); double vcs_VolTotal(double, double, double [], double []); int vcs_prep_oneTime(int printLvl);