Gems3k
3.1
GEMS3K standalone solver for geochemical equilibria
|
00001 //------------------------------------------------------------------- 00002 // $Id: s_sorption.h 725 2012-10-02 15:43:37Z kulik $ 00003 // 00004 // Stub declaration of new versions of SCMs (TSorpMod class) 00005 // Template: s_fgl.h (declarations of TSolMod class) 00006 // 00007 // Copyright (C) 2010-2012 D.Kulik, T.Wagner 00008 // <GEMS Development Team, mailto:gems2.support@psi.ch> 00009 // 00010 // This file is part of the GEMS3K code for thermodynamic modelling 00011 // by Gibbs energy minimization <http://gems.web.psi.ch/GEMS3K/> 00012 // 00013 // GEMS3K is free software: you can redistribute it and/or modify 00014 // it under the terms of the GNU Lesser General Public License as 00015 // published by the Free Software Foundation, either version 3 of 00016 // the License, or (at your option) any later version. 00017 00018 // GEMS3K is distributed in the hope that it will be useful, 00019 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 // GNU Lesser General Public License for more details. 00022 00023 // You should have received a copy of the GNU General Public License 00024 // along with GEMS3K code. If not, see <http://www.gnu.org/licenses/>. 00025 //------------------------------------------------------------------ 00026 // 00027 #ifndef S_SORPTION_H 00028 #define S_SORPTION_H 00029 00030 //#include "s_fgl.h" 00031 00032 const int MAXDCNAME = 16, MAXPHASENAME = 16, MST = 6, MAXEILAYERS = 4; 00033 00034 struct SorptionSiteData { 00035 char SiteT_; // Site type code, see SITETYPECODES 00036 char SACTC_; // SACT equation code, see SACTCODES 00037 long int NSpec_; // Number of surface species that can bind to this site (>=1; 0 if the site ignored) 00038 00039 double qC_; // site capacity parameter in mol/kg (CEC in eq/kg) 00040 double GamC_; // site density parameter in mol/m2 (CEC in eq/m2) 00041 double AlphaF_; // Frumkin interaction parameter; 00042 double BETp_; // BET isotherm parameter p 00043 double BETq_; // BET isotherm parameter q 00044 00045 double *arDent; // Species denticity or coordination number on this site type [NSpecies] 00046 double *arSpDUL; // temporary upper constraint on species amount for SAT calculations [NSpecies] 00047 double *ar_nxs; // moles of sites taken by a surface species [NSpecies] 00048 long int *ar_xst; // Index of surface species on surface tile (phase) [NSpecies] 00049 double *arlnSACT; // ln of SACT [NSpecies] - output (direct access, incremental) ????? 00050 double *arlnGamF; // ln of Frumkin or BET term [NSpecies] - output (direct access, incremental) ???? 00051 00052 double *OccTot; // Total amount of occupied sites (output scalar) 00053 double *FreTot; // Total amount of free sites (output scalar) 00054 }; 00055 00056 class TSurfSiteMod 00057 { 00058 protected: 00059 00060 char SiteT; // Site type code, see SITETYPECODES 00061 char SACTC; // SACT equation code, see SACTCODES 00062 00063 long int NSpec; // Number of surface species on this site (at least 1; 0 if site to be ignored) 00064 00065 double qC, // site capacity parameter in mol/kg (CEC in eq/kg) 00066 GamC, // site density parameter in mol/m2 (CEC in eq/m2) 00067 AlphaF, // Frumkin interaction parameter; 00068 BETp, // BET isotherm parameter 00069 BETq; // BET isotherm parameter 00070 00071 double XSsI, // total mole amount of surface species on this site 00072 XSsM, // maximum (limiting) amount of sites 00073 OcTot, // Total amount of occupied sites 00074 FrTot; // Total amount of free sites 00075 00076 // double MASDJ[DFCN]; Parameters of surface species in surface complexation models 00077 // enum { 00078 // //[0] - max site density in mkmol/(g sorbent); [1] - species charge allocated to 0 plane; 00079 // //[2] - surface species charge allocated to beta -or third plane; [3] - Frumkin interaction parameter; 00080 // //[4] species denticity or coordination number; [5] - reserved parameter (e.g. species charge on 3rd EIL plane)] 00081 // XL_ST = 0, XL_EM, XL_SI, XL_SP 00082 // }; 00083 00084 double Dent[]; // Species denticity or coordination number [NSpec] 00085 double SpDUL[]; // temporary upper constraint on species amount for SAT calculations [NSpec] 00086 double nxs[]; // moles of surface species on this site (picked up) [NSpec] 00087 long int xst[]; // Index of surface species on surface tile (phase) [NSpec] 00088 // results 00089 // double (*D)[MST]; // Reserved; new work array for calc. surface act.coeff. 00090 // double lnSAC[4]; // former lnSAT ln surface activity coeff and Coulomb's term [Lads][4] 00091 double ISAT[]; // ISAT for each species (in SACT calculations) [NSpec] 00092 double eF[]; // Frumkin exponent acting on species [NSpec] 00093 double SACT[]; // Surface activity coefficient terms (config. entropy terms) [NSpec] 00094 double lnSACT[]; // ln of SACT on this site type [NSpec] - output 00095 double lnGamF[]; // ln activity coefficient due to Frumkin or BET isotherm - output 00096 00097 public: 00098 00099 // Generic constructor 00100 TSurfSiteMod( SorptionSiteData ssd ); 00101 00102 // Destructor 00103 virtual ~TSurfSiteMod(); 00104 00105 // Other methods 00106 00107 }; 00108 00109 struct SorptionData { 00110 00111 char Mod_Code_; // Code of the sorption phase model - see SORPPHASECODES 00112 char EIL_Code_; // Code for specific EIL model- see EILMODCODES (before: SCMC) 00113 char PhasNam_[MAXPHASENAME]; // Phase name (for specific built-in models) 00114 00115 long int NSpec_; // Total number of species assigned to this surface tile or Donnan phase 00116 long int nlPh_; // number of linked phases (cf. lPh), default 1 (the sorbent phase) 00117 long int nlPhC_; // number of linked phase parameter coefficient per link (default 0) 00118 00119 long int nEIml_; // number of EIL model layers (default 0, maximum MAXEILAYERS=4); 00120 long int nEIpl_; // number of EIL params per layer (default 0); 00121 long int nCDcf_; // number of CD coefs per DC (default 0); 00122 long int nEIres_; // reserved 00123 00124 long int NsiteTs_; // number of surface sites; (default 1) 00125 long int nISTcf_; // number of isotherm coeffs per site (default 1) 00126 long int nISDcf_; // number of isotherm coeffs per DC (default 1) 00127 long int DelMax_; // max.denticity of DC (default 1) 00128 00129 long int kSorPh_; // Index of the sorbent phase in GEM IPM work structure (MULTI) 00130 // if -1 then this is a site-balance based approach; SSa_ or sVp_ must be provided here 00131 00132 long int NsiteTs_; // Number of surface site types per this surface patch (min 1 max 6), for Donnan 1 00133 // (if 0 then this sorption phase model is ignored) 00134 long int *xsMd_; // denticity of surface species per surface site (site allocation) [NSpec][NsiteTs] 00135 00136 // long int *arPsDiS_; // array of DC denticity and indexes of binding sites [NSpec*(DelMax+1)] 00137 00138 char *DC_Cods_; // DC class codes for species [NSpec_] 00139 char *IsoCt_; // isotherm and SATC codes for surface site types [2*NsiteTs_] 00140 00141 long int *arPhLin_; // indexes of linked (sorbent) phase(s) and link type code(s) [nlPh*2] read-only 00142 00143 double T_k_; // Temperature, K (initial) 00144 double P_bar_; // Pressure, bar (initial) 00145 double IS_; // Effective molal ionic strength of aqueous electrolyte 00146 double pH_; // pH of aqueous solution 00147 double pe_; // pe of aqueous solution 00148 double Eh_; // Eh of aqueous solution, V 00149 00150 // This is taken over from the aSorMc[16] piece from MULTI 00151 double *arSorMc; 00152 // double sSA_, // Specific surface area, m2/g, default: 0. 00153 // sgw_, // Standard mean surface energy of solid-aqueous interface, J/m2 00154 // sgg_, // Standard mean surface energy of gas-aqueous interface, J/m2 00155 // rX0_, // Mean radius r0 for (spherical or cylindrical) particles, nm (reserved) 00156 // hX0_, // Mean thickness h0 for cylindrical or 0 for spherical particles, nm (reserved) 00157 // 00158 // sVp_, // Specific pore volume of phase, m3/g (default: 0) 00159 // frSA_, // reactive fraction of surface area (def. 1) 00160 00161 // nPh_, // current amount of this phase, mol (read-only) 00162 // mPh_, // current mass of this phase, g (read-only) 00163 // vPh_, // current volume of this phase, cm3 (read-only) 00164 // sAPh_, // current surface of this phase, m2 00165 // OmPh_, // phase stability index (lg scale), input 00166 // 00167 // *nPul_, // pointer to upper restriction to this phase amount, mol (calculated here) 00168 // *nPll_, // pointer to lower restriction to this phase amount, mol (calculated here) 00169 // *sGP_; // pointer to surface free energy of the phase, J (YOF*PhM) 00170 00171 double N_Cst_; // Standard surface number density, 1/nm2 00172 double G_Cst_; // Standard surface density, mol/m2 00173 double q_Cst_; // Standard sorption capacity, mol/kg(sorbent) or eq/kg(sorbent) 00174 00175 double Nfsp_, // Fraction of the sorbent specific surface area or volume allocated to surface type (>0 <10000) 00176 MASDT_, // Total sorption capacity for this surface type (mol/kg), before was (mkmol/g) 00177 XetaC_, // Total permanent charge capacity CEC, mol/kg 00178 VetaP_, // Total permanent volume charge density (eq/m3) 00179 XetaP_, // Total density of permanent charge (eq/m2), before mkeq/m2 00180 ValP_, // Porosity of the Donnan sorbent (d/less) 00181 ParD1_, // Donnan model parameter 1 00182 ParD2_, // Donnan model parameter 2 00183 XlamA_; // Factor of EDL discretness A < 1, reserved 00184 00185 double *Xcap_, // Capacitance density of EIL layers, F/m2 [MAXEILAYERS] 00186 *Xdl_; // Effective thickness of EIL layers, nm, reserved 00187 double (*CD)[MAXEILAYERS]; // Species charges allocated to EIL planes [NspT] 00188 00189 double *arlPhc; // array of phase link parameters (sum(LsPhl[k][1] over Fi) 00190 00191 double *arEImc; // EIL model coefficients table [nEIml_*nEIpl] 00192 double *armCDc; // CD EIL model coefficients table [NSpec_*nCDcf_] 00193 double *IsoPc; // Isotherm equation coefficients table [NSpec_*nISDcf_] 00194 double *IsoSc; // Isotherm equation coeffs per surface site type [NsiteTs*nISTcf_] 00195 00196 double *arPparc; // Partial pressures -> NSpecies 00197 double *arWx; // Species mole fractions ->NSpec_ read-only 00198 double *arnx; // Pointer to mole amounts of phase components (provided) [NSpec_] read-only 00199 // output 00200 double *arlnScalT; // Surface/volume scaling activity correction terms [NSpec_] direct access 00201 double *arlnSACT; // Pointer to ln SACT for surface species [NSpec_] direct access 00202 double *arlnGammaF; // Pointer to Frumkin or BET non-electrostatic activity coefficients [NSpec_] direct access 00203 double *arCTerms; // Pointer to Coulombic correction terms (electrostatic activity coefficients) [NSpec_] direct access 00204 double *arlnGamma; // Pointer to ln activity coefficients of sorption phase components mixing [NSpec_] direct access 00205 // (memory under pointers must be provided from the calling program) 00206 00207 double *arVol; // molar volumes of end-members (species) cm3/mol [NSpec_] read-inly 00208 char (*arSM)[MAXDCNAME]; // pointer to the list of DC names in the phase [NSpec_] read-only 00209 char *arDCC; // pointer to the classifier of DCs involved in this phase [NSpec_] read-only 00210 00211 }; 00212 00213 class TSorpMod 00214 { // Treatment of surface tile (patch) or Donnan volume phases in sorption models 00215 protected: 00216 00217 char Mod_Code; // Code of the sorption phase model - see SORPPHASECODES 00218 char EIL_Code; // Code for specific EIL model- see EILMODCODES (before: SCMC) 00219 char PhasNam_[MAXPHASENAME]; // Phase name (for specific built-in models) 00220 00221 long int NSpec; // Total number of species assigned to this surface tile or Donnan phase 00222 long int nlPh; // number of linked phases (cf. lPh), default 1 (the sorbent phase) 00223 long int nlPhC; // number of linked phase parameter coefficient per link (default 0) 00224 00225 long int nEIml; // number of EIL model layers (default 0); 00226 long int nEIpl; // number of EIL params per layer (default 0); 00227 long int nCDcf; // number of CD coefs per DC (default 0); 00228 long int nEIres; // reserved 00229 00230 long int NsiteTs; // number of surface sites; (default 1) 00231 long int nISTcf; // number of isotherm coeffs per site (default 1) 00232 long int nISDcf; // number of isotherm coeffs per DC (default 1) 00233 long int DelMax; // max.denticity of DC (default 1) 00234 00235 long int kSorPh; // Index of the sorbent phase in GEM IPM work structure (MULTI) 00236 // if -1 then this is a site-balance based approach; SSa_ or sVp_ must be provided 00237 00238 long int NsiteTs; // Number of surface site types per surface patch type (min 1 max 6), for Donnan 1 00239 // (if 0 then this sorption phase model is ignored) 00240 long int **xsMd; // denticity of surface species per surface site (site allocation) [NSpec][NsiteTs] 00241 // long int **PsDS; // array of DC denticity and indexes of binding sites [NSpec][DelMax+1] 00242 long int (*PhLin)[2]; // indexes of linked (sorbent) phase(s) and link type code(s) [nlPh][2] read-only 00243 char DCCs[]; // DC class codes for species [NSpec_] 00244 char (*IsoCt)[2]; // isotherm and SATC codes for surface site types NsiteTs][2] 00245 00246 double T_k; // Temperature, K (initial) 00247 double P_bar; // Pressure, bar (initial) 00248 double IS; // Effective molal ionic strength of aqueous electrolyte 00249 double pH; // pH of aqueous solution 00250 double pe; // pe of aqueous solution 00251 double Eh; // Eh of aqueous solution, V 00252 00253 // This is taken over from the aSorMc[16] piece from MULTI 00254 double sSA, // Specific surface area, m2/g, default: 0. 00255 sgw, // Standard mean surface energy of solid-aqueous interface, J/m2 00256 sgg, // Standard mean surface energy of gas-aqueous interface, J/m2 00257 // rX0, // Mean radius r0 for (spherical or cylindrical) particles, nm (reserved) 00258 // hX0, // Mean thickness h0 for cylindrical or 0 for spherical particles, nm (reserved) 00259 // 00260 sVp, // Specific pore volume of phase, m3/g (default: 0) 00261 frSA, // reactive fraction of surface area (def. 1) 00262 00263 // nPh, // current amount of this phase, mol (read-only) 00264 // mPh, // current mass of this phase, g (read-only) 00265 // vPh, // current volume of this phase, cm3 (read-only) 00266 // sAPh, // current surface of this phase, m2 00267 // OmPh, // phase stability index (lg scale), input 00268 // 00269 sGP_; // surface free energy of the phase, J (YOF*PhM) 00270 00271 double N_Cst; // Standard surface number density, 1/nm2 00272 double G_Cst; // Standard surface density, mol/m2 00273 double q_Cst; // Standard sorption capacity, mol/kg(sorbent) or eq/kg(sorbent) 00274 00275 double R_CONST; // R constant 00276 double F_CONST; // F (Faraday's) constant 00277 00278 // model parameters 00279 double Nfsp, // Fraction of the sorbent specific surface area or volume allocated to surface type (>0 <10000) 00280 MASDT, // Total sorption capacity for this surface type (mol/kg), before was (mkmol/g) 00281 XetaC, // Total permanent charge capacity CEC, mol/kg 00282 VetaP, // Total permanent volume charge density (eq/m3) 00283 XetaP, // Total density of surface permanent charge (eq/m2), before mkeq/m2 00284 ValP, // Porosity of the Donnan sorbent (d/less) 00285 ParD1, // Donnan model parameter 1 00286 ParD2, // Donnan model parameter 2 00287 Xcap[], // Capacitance density of EIL layers 0 1 2 3 ... , F/m2 [nEIml] 00288 Xdl[], // Effective thicknesses of EIL layers, nm, reserved 00289 XdlD, // Effective thickness of diffuse layer, nm, reserved 00290 XlamA; // Factor of EDL discretness A < 1, reserved 00291 double (*CD)[MAXEILAYERS]; // Species charges allocated to 0, 1 and 2 planes [NspT] 00292 00293 TSurfSiteMod* sitMod[]; // Pointer to array of TSurfSiteMod instances - [NsiT] 00294 00295 // current values 00296 double XsTs, // Total number of moles of species in this tile or Donnan volume 00297 XaTs, // Total moles of 'solvent' (e.g. >OH group or H2O in Donnan phase) 00298 Sarea, // Current area occupied by this surface tile, (m2) 00299 Volum, // Current volume (if this is Donnan electrolyte), (m3) 00300 Xeta[MAXEILAYERS], // Total charge of surface species on EIL planes 0,1,2, ..., equiv 00301 Xpsi[MAXEILAYERS], // Relative potential at EIL planes, V 00302 VetaD, // Total charge in the Donnan volume, moles 00303 VPsiD, // Relative Donnan potential, V 00304 IS; // Ionic strength (for Donnan electrolyte, or in bulk electrolyte for surface tile) 00305 00306 double nx[]; // pointer to moles of surface species on this surface tile (read-only) [Nspec] 00307 00308 double **lnSACTs; // Work array of ln SACT for surface species on sites [Nspec][NsiteTs] 00309 double *(XTS[2]); // Total number of moles of surface DC and 'solvent' DC at surface site [2][NsiteTs] 00310 00311 // current results 00312 double Gex, Hex, Sex, CPex, Vex, Aex, Uex; // molar electrostatic excess properties for surface species 00313 // double Gid, Hid, Sid, CPid, Vid, Aid, Uid; // molar ideal mixing properties for surface species 00314 00315 double *lnScalT; // Surface/volume scaling activity correction terms [Nspec] 00316 double *lnSACT; // Pointer to ln SACT for surface species [Nspec] 00317 double *lnGammaF; // Pointer to Frumkin or BET non-electrostatic activity coefficients [Nspec] 00318 double *CTerms; // Pointer to Coulombic correction terms (electrostatic activity coefficients) [Nspec] 00319 double *lnGamma; // Pointer to ln activity coefficients of sorption phase components mixing [Nspec] 00320 // (memory under pointers must be provided from the calling program) 00321 00322 public: 00323 // Generic constructor 00324 TSorpMod( SorptionData sds ); 00325 00326 // Destructor 00327 virtual ~TSorpMod(); 00328 00329 00330 virtual long int SorptionSpecies() 00331 { 00332 return 0; 00333 }; 00334 00335 virtual long int PTparam() 00336 { 00337 return 0; 00338 }; 00339 00340 virtual long int IsothermMod() 00341 { 00342 return 0; 00343 }; 00344 00345 virtual long int ElstatMod() 00346 { 00347 return 0; 00348 }; 00349 /* 00350 virtual long int ExcessProp( double *Zex ) 00351 { 00352 return 0; 00353 }; 00354 00355 virtual long int IsothermProp( double *Zid ) 00356 { 00357 return 0; 00358 }; 00359 */ 00360 // set new system state 00361 long int UpdatePT ( double T_k, double P_bar ); 00362 00363 bool testSizes( long int NSpecies, long int NSurSpecies, long int NSorbentEMs, 00364 long int NSurfTypes, char Mod_Code, char EIL_Code ); 00365 00366 // getting phase name 00367 void GetPhaseName( const char *PhName ); 00368 00369 }; 00370 00371 00372 class TNEMcalc: public TSorpMod // Non-electrostatic sorption phase model without site balances 00373 { 00374 protected: 00375 00376 double Xcond, // conductivity of phase carrier, sm/m2, reserved 00377 Xeps, // rel. diel. permeability of phase carrier (solvent), reserved 00378 Aalp, // Specific surface area of phase carrier (sorbent) (m2/g) !!! m2/kg 00379 Sigw, // Specific surface free energy for phase-water interface (J/m2) 00380 Sigg, // Specific surface free energy for phase-gas interface (J/m2) (not yet used) 00381 Xr0, // Mean radius r0 for (spherical or cylindrical) particles, nm (reserved) Xr0h0[2] 00382 Xh0; // Mean thickness h0 for cylindrical or 0 for spherical particles, nm (reserved) 00383 00384 // TSurfPatchMod* patchMod[]; // Pointer to array of TSurfPatch instances - size NsurT 00385 00386 // internal functions 00387 void alloc_internal(); 00388 void free_internal(); 00389 00390 00391 public: 00392 // Constructor 00393 TNEMcalc( long int NCmp, double Pp, double Tkp ); 00394 TNEMcalc( long int NSpecies, long int NSurSpecies, long int NSorbentEMs, long int NSurfTypes, 00395 char Mod_Code, char *Phase_Name, char **SM3_, char *DCC_, char **SCM_, char **SATT_, 00396 double Aalp_, double *arnx_, double *arlnGam, double *arlnSACT, double T_k, double P_bar ); 00397 // Destructor 00398 ~TNEMcalc(); 00399 00400 // Calculates pure species properties (pure fugacities) 00401 long int PureSpecies(); 00402 00403 // Calculates T,P corrected interaction parameters 00404 long int PTparam(); 00405 00406 // Calculates activity coefficients 00407 long int MixMod(); 00408 00409 // calculates excess properties 00410 long int ExcessProp( double *Zex ); 00411 00412 // calculates ideal mixing properties 00413 long int IdealProp( double *Zid ); 00414 00415 // Calculates pure species properties (called from DCthermo) 00416 long int SRKCalcFugPure( double Tmin, float *Cpg, double *FugProps ); 00417 00418 }; 00419 00420 00421 #endif // S_SORPTION_H