Tony's implementation of electric current.

Test case current1.

git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10550 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
David L Parkhurst 2015-12-08 16:54:38 +00:00
parent 2fe6313f47
commit fb18be24e2
20 changed files with 1399 additions and 711 deletions

View File

@ -1620,6 +1620,21 @@ listtokens(FILE * f, tokenrec * l_buf)
case toksa_declercq:
output_msg("SA_DECLERCQ");
break;
case tokviscos:
output_msg("VISCOS");
break;
case tokviscos_0:
output_msg("VISCOS_0");
break;
case tokrho_0:
output_msg("RHO_0");
break;
case tokcurrent_a:
output_msg("CURRENT_A");
break;
case tokpot_v:
output_msg("POT_V");
break;
}
l_buf = l_buf->next;
}
@ -2251,7 +2266,7 @@ factor(struct LOC_exec * LINK)
break;
}
else
n.UU.val = PhreeqcPtr->cell_data[i - 1].por;
n.UU.val = PhreeqcPtr->cell_data[i].por;
break;
}
else
@ -3152,7 +3167,7 @@ factor(struct LOC_exec * LINK)
}
else if (PhreeqcPtr->state == TRANSPORT)
{
n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_data[PhreeqcPtr->cell - 1].mid_cell_x;
n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_data[PhreeqcPtr->cell].mid_cell_x;
}
else if (PhreeqcPtr->state == ADVECTION)
{
@ -3518,6 +3533,33 @@ factor(struct LOC_exec * LINK)
case toksoln_vol:
n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_solution_volume();
break;
case tokvm:
{
const char * str = stringfactor(STR1, LINK);
n.UU.val = (parse_all) ? 1 : PhreeqcPtr->aqueous_vm(str);
}
break;
case tokviscos:
{
n.UU.val = (parse_all) ? 1 : PhreeqcPtr->viscos;
}
break;
case tokviscos_0:
{
n.UU.val = (parse_all) ? 1 : PhreeqcPtr->viscos_0;
}
break;
case tokrho_0:
n.UU.val = (parse_all) ? 1 : PhreeqcPtr->rho_0;
break;
case tokcurrent_a:
//n.UU.val = (parse_all) ? 1 : PhreeqcPtr->current_x;
n.UU.val = (parse_all) ? 1 : PhreeqcPtr->current_A;
break;
case tokpot_v:
n.UU.val = (parse_all) ? 1 : PhreeqcPtr->use.Get_solution_ptr()->Get_potV();
break;
case toklog10:
{
LDBLE t = realfactor(LINK);
@ -3531,12 +3573,6 @@ factor(struct LOC_exec * LINK)
//}
}
break;
case tokvm:
{
const char * str = stringfactor(STR1, LINK);
n.UU.val = (parse_all) ? 1 : PhreeqcPtr->aqueous_vm(str);
}
break;
case toksin:
n.UU.val = sin(realfactor(LINK));
@ -4507,7 +4543,7 @@ cmdchange_por(struct LOC_exec *LINK)
require(tokrp, LINK);
if (j > 0 && j <= PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1
&& j != PhreeqcPtr->count_cells + 1)
PhreeqcPtr->cell_data[j - 1].por = TEMP;
PhreeqcPtr->cell_data[j].por = TEMP;
}
void PBasic::
@ -7118,7 +7154,12 @@ const std::map<const std::string, PBasic::BASIC_TOKEN>::value_type temp_tokens[]
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("callback", PBasic::tokcallback),
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("diff_c", PBasic::tokdiff_c),
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("sa_declercq", PBasic::toksa_declercq),
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("edl_species", PBasic::tokedl_species)
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("edl_species", PBasic::tokedl_species),
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("viscos", PBasic::tokviscos),
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("viscos_0", PBasic::tokviscos_0),
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("rho_0", PBasic::tokrho_0),
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("current_a", PBasic::tokcurrent_a),
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("pot_v", PBasic::tokpot_v)
};
std::map<const std::string, PBasic::BASIC_TOKEN> PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]);

View File

@ -324,7 +324,12 @@ public:
tokcallback,
tokdiff_c,
toksa_declercq,
tokedl_species
tokedl_species,
tokviscos,
tokviscos_0,
tokrho_0,
tokcurrent_a,
tokpot_v
};
#if !defined(PHREEQCI_GUI)

View File

@ -196,7 +196,8 @@ void Phreeqc::init(void)
current_pa = NAN;
current_mu = NAN;
mu_terms_in_logk = true;
current_A = 0.0;
current_x = 0.0;
/* ----------------------------------------------------------------------
* STRUCTURES
* ---------------------------------------------------------------------- */
@ -406,6 +407,7 @@ void Phreeqc::init(void)
tk_x = 0;
patm_x = 1;
last_patm_x = 1;
potV_x = 0;
numerical_fixed_volume = false;
force_numerical_fixed_volume = false;
//switch_numerical = false;
@ -713,7 +715,9 @@ void Phreeqc::init(void)
/* from float.h, sets tolerance for cl1 routine */
ineq_tol = pow((long double) 10, (long double) -LDBL_DIG);
#else
ineq_tol = pow((double) 10, (double) -DBL_DIG);
//ineq_tol = pow((double) 10, (double) -DBL_DIG);
// appt:
ineq_tol = pow((double) 10, (double) -DBL_DIG + 2);
#endif
convergence_tolerance = 1e-8;
step_size = 100.;
@ -787,6 +791,7 @@ void Phreeqc::init(void)
user_database = NULL;
//have_punch_name = FALSE;
print_density = 0;
print_viscosity = 0;
zeros = NULL;
zeros_max = 1;
cell_pore_volume = 0;
@ -799,6 +804,8 @@ void Phreeqc::init(void)
sys_tot = 0;
V_solutes = 0.0;
viscos = 0.0;
viscos_0 = 0.0;
rho_0 = 0;
kappa_0 = 0.0;
p_sat = 0.0;
@ -981,7 +988,7 @@ void Phreeqc::init(void)
/* phrq_io_output.cpp ------------------------------- */
forward_output_to_log = 0;
/* phreeqc_files.cpp ------------------------------- */
default_data_base = string_duplicate("phreeqc.dat");
default_data_base = string_duplicate("phreeqc.dat");
#ifdef PHREEQ98
int outputlinenr;
char *LogFileNameC;
@ -1357,9 +1364,9 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
if (count_cells > 0)
{
cell_data = (struct cell_data *) free_check_null(cell_data);
cell_data = (struct cell_data *) PHRQ_malloc((size_t) (count_cells * sizeof(struct cell_data)));
cell_data = (struct cell_data *) PHRQ_malloc((size_t) ((count_cells + 2) * sizeof(struct cell_data)));
if (cell_data == NULL) malloc_error();
memcpy(cell_data, pSrc->cell_data, ((size_t) (count_cells * sizeof(struct cell_data))));
memcpy(cell_data, pSrc->cell_data, ((size_t) ((count_cells + 2) * sizeof(struct cell_data))));
}
old_cells = pSrc->old_cells;
max_cells = pSrc->max_cells;

View File

@ -702,6 +702,7 @@ public:
/* VP: Density Start */
int read_millero_abcdef (char *ptr, LDBLE * abcdef);
/* VP: Density End */
int read_viscosity_parms(char *ptr, LDBLE * Jones_Dole);
int read_copy(void);
int read_debug(void);
int read_delta_h_only(char *ptr, LDBLE * delta_h,
@ -1050,9 +1051,11 @@ public:
int reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name,
LDBLE new_Dw, int cell);
LDBLE viscosity(void);
LDBLE calc_vm_Cl(void);
int multi_D(LDBLE DDt, int mobile_cell, int stagnant);
int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant);
int fill_spec(int cell_no);
void define_ct_structures(void);
int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec);
static int sort_species_name(const void *ptr1, const void *ptr2);
int disp_surf(LDBLE stagkin_time);
@ -1335,6 +1338,7 @@ protected:
LDBLE tk_x;
LDBLE patm_x;
LDBLE last_patm_x;
LDBLE potV_x;
bool numerical_fixed_volume;
bool force_numerical_fixed_volume;
//bool switch_numerical;
@ -1703,9 +1707,11 @@ protected:
int print_density;
/* VP: Density End */
int print_viscosity;
LDBLE *zeros;
int zeros_max;
LDBLE viscos, viscos_0, viscos_0_25; // viscosity of the solution, of pure water, of pure water at 25 C
LDBLE cell_pore_volume;
LDBLE cell_porosity;
LDBLE cell_volume;
@ -1931,6 +1937,7 @@ protected:
int nmix, heat_nmix;
LDBLE heat_mix_f_imm, heat_mix_f_m;
int warn_MCD_X, warn_fixed_Surf;
LDBLE current_x, current_A; // current: coulomb * s, ampere
#ifdef PHREEQ98
int AutoLoadOutputFile, CreateToC;

View File

@ -29,6 +29,7 @@ cxxSolution::cxxSolution(PHRQ_io * io)
this->io = io;
this->new_def = false;
this->patm = 1.0;
this->potV = 0.0;
this->tc = 25.0;
this->ph = 7.0;
this->pe = 4.0;
@ -62,6 +63,7 @@ cxxSolution::operator =(const cxxSolution &rhs)
this->description = rhs.description;
this->new_def = rhs.new_def;
this->patm = rhs.patm;
this->potV = rhs.potV;
this->tc = rhs.tc;
this->ph = rhs.ph;
this->pe = rhs.pe;
@ -229,6 +231,9 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con
s_oss << indent1;
s_oss << "-pressure " << this->patm << "\n";
s_oss << indent1;
s_oss << "-potential " << this->potV << "\n";
// new identifier
s_oss << indent1;
s_oss << "-total_h " << this->total_h << "\n";
@ -996,6 +1001,18 @@ cxxSolution::read_raw(CParser & parser, bool check)
opt_save = 25;
}
break;
case 26: // potential
if (!(parser.get_iss() >> this->potV))
{
this->potV = 0.0;
parser.incr_input_error();
parser.error_msg("Expected numeric value for potential (V).",
PHRQ_io::OT_CONTINUE);
}
opt_save = CParser::OPT_DEFAULT;
break;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
@ -1335,6 +1352,7 @@ cxxSolution::zero()
this->master_activity.type = cxxNameDouble::ND_SPECIES_LA;
this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA;
this->patm = 1.0;
this->potV = 0.0;
this->initial_data = NULL;
}
@ -1360,6 +1378,7 @@ cxxSolution::add(const cxxSolution & addee, LDBLE extensive)
this->cb += addee.cb * extensive;
this->density = f1 * this->density + f2 * addee.density;
this->patm = f1 * this->patm + f2 * addee.patm;
this->potV = f1 * this->potV + f2 * addee.potV;
this->mass_water += addee.mass_water * extensive;
this->soln_vol += addee.soln_vol * extensive;
this->total_alkalinity += addee.total_alkalinity * extensive;

View File

@ -29,6 +29,8 @@ class cxxSolution:public cxxNumKeyword
void Set_new_def(bool p) {this->new_def = p;}
LDBLE Get_patm() const {return this->patm;}
void Set_patm(LDBLE p) {this->patm = p;}
LDBLE Get_potV() const {return this->potV;}
void Set_potV(LDBLE p) {this->potV = p;}
LDBLE Get_tc() const {return this->tc;}
void Set_tc(LDBLE l_tc) {this->tc = l_tc;}
LDBLE Get_ph() const {return this->ph;}
@ -115,6 +117,7 @@ class cxxSolution:public cxxNumKeyword
protected:
bool new_def;
LDBLE patm;
LDBLE potV;
LDBLE tc;
LDBLE ph;
LDBLE pe;

View File

@ -161,6 +161,9 @@ diff_c(const char *species_name)
if (s_ptr != NULL && s_ptr->in != FALSE && s_ptr->type < EMINUS)
{
g = s_ptr->dw;
if (s_ptr->dw_t)
g *= exp(s_ptr->dw_t / tk_x - s_ptr->dw_t / 298.15);
g *= viscos_0_25 / viscos;
}
else
{
@ -177,6 +180,7 @@ calc_SC(void)
LDBLE lm, a, l_z, Dw, SC, ff;
SC = 0;
# ifdef SKIP
for (i = 0; i < count_species_list; i++)
{
if (species_list[i].s->type == EX)
@ -197,33 +201,204 @@ calc_SC(void)
lm = species_list[i].s->lm;
if (lm > -9)
{
/*
if (l_z < 1.5) {
ff = (mu_x < 0.36 ? 0.6 :
sqrt(mu_x));
}
else {
ff = (mu_x < pow(0.4*l_z, 2.0) ? 0.4 :
sqrt(mu_x) / l_z);
}
*/
ff = (mu_x < .36 * l_z ? 0.6 / sqrt(l_z) : sqrt(mu_x) / l_z);
ff *= species_list[i].s->lg;
if (ff > 0) ff = 0;
a = under(lm + ff);
if (species_list[i].s->dw_t)
Dw *= exp(species_list[i].s->dw_t / tk_x - species_list[i].s->dw_t / 298.15); // the viscosity multiplier is done in SC
SC += a * l_z * l_z * Dw;
}
}
SC *= 1e7 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0);
/* correct for temperature dependency...
/* correct for temperature dependency...
SC_T = SC_298 * (Dw_T / T) * (298 / Dw_298) and
Dw_T = Dw_298 * (T / 298) * (viscos_298 / viscos_T) give:
SC_T = SC_298 * (viscos_298 / viscos_T)
*/
SC *= 0.88862 / viscosity();
SC *= viscos_0_25 / viscos;
return (SC);
# endif
for (i = 0; i < count_s_x; i++)
{
if (s_x[i]->type != AQ && s_x[i]->type != HPLUS)
continue;
if ((Dw = s_x[i]->dw) == 0)
continue;
if ((l_z = fabs(s_x[i]->z)) == 0)
continue;
lm = s_x[i]->lm;
if (lm > -9)
{
ff = (mu_x < .36 * l_z ? 0.6 / sqrt(l_z) : sqrt(mu_x) / l_z);
ff *= s_x[i]->lg;
if (ff > 0) ff = 0;
a = under(lm + ff);
if (s_x[i]->dw_t)
Dw *= exp(s_x[i]->dw_t / tk_x - s_x[i]->dw_t / 298.15); // the viscosity multiplier is done in SC
SC += a * l_z * l_z * Dw;
}
}
SC *= 1e7 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0);
/* correct for temperature dependency...
SC_T = SC_298 * (Dw_T / T) * (298 / Dw_298) and
Dw_T = Dw_298 * (T / 298) * (viscos_298 / viscos_T) give:
SC_T = SC_298 * (viscos_298 / viscos_T)
*/
SC *= viscos_0_25 / viscos;
return (SC);
#ifdef SKIP
int i;
LDBLE lm, a, ka, l_z, Dw, SC, ff, sqrt_mu;
boolean DebOns_sc = false;
sqrt_mu = sqrt(mu_x);
SC = 0;
for (i = 0; i < count_species_list; i++)
{
if (species_list[i].s->dw_a || species_list[i].s->dw_a_exp)
{
DebOns_sc = true;
break;
}
if (species_list[i].s->type > HPLUS)
continue;
if (i > 0
&& strcmp(species_list[i].s->name,
species_list[i - 1].s->name) == 0)
continue;
if (species_list[i].s == s_h2o)
continue;
if ((Dw = species_list[i].s->dw) == 0)
continue;
if ((l_z = fabs(species_list[i].s->z)) == 0)
continue;
lm = species_list[i].s->lm;
if (lm > -9)
{
ka = DH_B * (species_list[i].s->dha ? species_list[i].s->dha : 4.0);
if (mu_x > 1)
ka *= pow(mu_x, 0.25 / mu_x);
else
ka *= pow(mu_x, 0.25); //sqrt_mu;
ff = pow((int) 10, -l_z * l_z * DH_A * sqrt_mu / (1 + ka));
ff = pow(ff, 0.7 / sqrt(l_z));
//ff = pow(ff, 0.6);
a = species_list[i].s->moles / mass_water_aq_x * ff;
if (species_list[i].s->dw_t)
Dw *= exp(species_list[i].s->dw_t / tk_x - species_list[i].s->dw_t / 298.15); // the viscosity multiplier is done in SC
SC += a * l_z * l_z * Dw;
}
}
if (!DebOns_sc)
{
SC *= 1e7 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0);
SC *= viscos_0_25 / viscos_0;
return (SC);
}
/*Debye-Onsager according to Robinson and Stokes, 1954, JACS 75, 1991,
but with sqrt charge multiplier for B2 and mu^ff dependent ka */
LDBLE q, B1, B2, m_plus, m_min, eq_plus, eq_min, eq_dw_plus, eq_dw_min, z_plus, z_min, t1, t2, t2a, Dw_SC;
m_plus = m_min = eq_plus = eq_min = eq_dw_plus = eq_dw_min = z_plus = z_min = 0;
SC = 0;
for (i = 0; i < count_species_list; i++)
{
if (species_list[i].s->type > HPLUS)
continue;
if (i > 0
&& strcmp(species_list[i].s->name,
species_list[i - 1].s->name) == 0)
continue;
if (species_list[i].s == s_h2o)
continue;
if ((Dw = species_list[i].s->dw) == 0)
continue;
if ((l_z = species_list[i].s->z) == 0)
continue;
if ((lm = species_list[i].s->lm) < -9)
continue;
// ** for optimizing...
if (!strcmp(species_list[i].s->name, "H+"))
t2a = species_list[i].s->Jones_Dole[2];
//
if (species_list[i].s->dw_t)
Dw *= exp(species_list[i].s->dw_t / tk_x - species_list[i].s->dw_t / 298.15); // the viscosity multiplier cancels in q...
if (l_z > 0)
{
m_plus += species_list[i].s->moles;
t1 = species_list[i].s->moles * l_z;
eq_plus += t1;
eq_dw_plus += t1 * Dw;
}
else
{
m_min += species_list[i].s->moles;
t1 = species_list[i].s->moles * l_z;
eq_min -= t1;
eq_dw_min -= t1 * Dw;
}
}
// Dw's weighted by eq...
eq_dw_plus /= eq_plus; eq_dw_min /= eq_min;
z_plus = eq_plus / m_plus; // |z1|
z_min = eq_min / m_min; // |z2|
q = z_plus * z_min / (z_plus + z_min) * (eq_dw_plus + eq_dw_min) / (z_min * eq_dw_plus + z_plus * eq_dw_min);
t1 = pow(1.60218e-19, 2) / (6 * pi);
B1 = t1 / (2 * 8.8542e-12 * eps_r * 1.38066e-23 * tk_x) *
q / (1 + sqrt(q)) * DH_B * 1e10 * z_plus * z_min; // DH_B is per Angstrom (*1e10)
t2 = 1e3 * calc_solution_volume();
t2 = (1 - t2a) * viscos_0 + t2a * viscos;
B2 = t1 * AVOGADRO / t2 * DH_B * 1e17; // DH_B per Angstrom (*1e10), viscos in mPa.s (*1e3), B2 in cm2 (*1e4)
Dw_SC = viscos_0_25 / t2 * 1e4 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0);
for (i = 0; i < count_species_list; i++)
{
if (species_list[i].s->type > HPLUS)
continue;
if (i > 0
&& strcmp(species_list[i].s->name,
species_list[i - 1].s->name) == 0)
continue;
if (species_list[i].s == s_h2o)
continue;
if ((Dw = species_list[i].s->dw) == 0)
continue;
if ((l_z = fabs(species_list[i].s->z)) == 0)
continue;
if ((lm = species_list[i].s->lm) < -9)
continue;
Dw *= Dw_SC;
if (species_list[i].s->dw_t)
Dw *= exp(species_list[i].s->dw_t / tk_x - species_list[i].s->dw_t / 298.15); // the viscosity factor is in Dw_SC
a = (species_list[i].s->dw_a ? species_list[i].s->dw_a : 3.5);
ka = DH_B * a;
if (species_list[i].s->dw_a_exp)
ka *= pow((double) mu_x, species_list[i].s->dw_a_exp);
else
ka *= sqrt_mu;
// Falkenhagen...
/*SC += under(lm) * l_z * l_z * (Dw - B2 * l_z * sqrt_mu / (1 + ka)) * (1 - B1 * sqrt_mu /
((1 + ka) * (1 + ka * sqrt(q) + ka * ka / 6)));*/
t1 = (Dw - (B1 * Dw + B2) * sqrt_mu / (1 + ka));
//t1 = (Dw - (B1 * Dw + B2 * sqrt(l_z)) * sqrt_mu / (1 + ka));
//t1 = (Dw - (B1 * Dw + B2 * l_z * l_z) * sqrt_mu / (1 + ka));
if (t1 > 0)
SC += under(lm) * l_z * l_z * t1;
}
return (SC * 1e3);
#endif
}
/* VP: Density Start */
@ -2708,7 +2883,7 @@ edl_species(const char *surf_name, LDBLE * count, char ***names, LDBLE ** moles,
PHRQ_free(sys);
return (sys_tot);
}
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
LDBLE Phreeqc::
system_total(const char *total_name, LDBLE * count, char ***names,
char ***types, LDBLE ** moles)

View File

@ -277,7 +277,7 @@ write_banner(void)
/* version */
#ifdef NPP
len = sprintf(buffer, "* PHREEQC-%s *", "3.0.5");
len = sprintf(buffer, "* PHREEQC-%s *", "3.2.2a AmpŠre");
#else
len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@");
#endif
@ -301,7 +301,7 @@ write_banner(void)
/* date */
#ifdef NPP
len = sprintf(buffer, "%s", "May 11, 2013");
len = sprintf(buffer, "%s", "November 25, 2015");
#else
len = sprintf(buffer, "%s", "@VER_DATE@");
#endif
@ -331,7 +331,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
* Prepare error handling
*/
try {
if (phrq_io == NULL)
if (phrq_io == NULL)
{
std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n";
}
@ -440,7 +440,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
error_string = sformatf( "Error opening file, %s.", in_file);
error_msg(error_string, STOP);
}
/*
* Open data base
*/
@ -487,7 +487,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
screen_msg(sformatf("Database file: %s\n\n", token));
strcpy(db_file, token);
#ifdef NPP
output_msg(sformatf("Using PHREEQC: version 3.0.5, compiled on May 29, 2013\n"));
output_msg(sformatf("Using PHREEQC: version 3.2.2a Ampère, compiled November 25, 2015\n"));
#endif
output_msg(sformatf(" Input file: %s\n", in_file));
output_msg(sformatf(" Output file: %s\n", out_file));
@ -528,7 +528,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
* Prepare error handling
*/
try {
if (phrq_io == NULL)
if (phrq_io == NULL)
{
std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n";
}
@ -636,7 +636,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
error_string = sformatf( "Error opening file, %s.", in_file);
error_msg(error_string, STOP);
}
/*
* Open data base
*/
@ -762,7 +762,7 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode,
#endif
error_flush();
batch = FALSE;
continue;
continue;
}
break;
}
@ -791,7 +791,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode
#else
FILE * error_file_save = phrq_io->Get_error_file();
#endif
for (;;)
{
/*
@ -805,7 +805,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode
#else
phrq_io->Set_error_file(stderr);
#endif
screen_msg(sformatf("%s\n", query));
if (default_name[0] != '\0')
{
@ -834,7 +834,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode
screen_msg(error_string);
error_flush();
batch = FALSE;
continue;
continue;
}
break;
}
@ -863,7 +863,7 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode,
#else
FILE * error_file_save = phrq_io->Get_error_file();
#endif
for (;;)
{
@ -906,7 +906,7 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode,
screen_msg(error_string);
error_flush();
batch = FALSE;
continue;
continue;
}
break;
}

View File

@ -459,10 +459,10 @@ calc_PR(void)
while (P <= 0)
{
P = R_TK / (V_m - b_sum) - a_aa_sum / (V_m * (V_m + 2 * b_sum) - b2);
if (P <= 0.0)
if (P <= 0.0)
{
V_m *= 2.0;
//a_aa_sum /= 2.0;
//a_aa_sum /= 2.0;
}
}
if (iterations > 0 && P < 150 && V_m < 1.01)

View File

@ -540,8 +540,9 @@ struct cell_data
LDBLE mid_cell_x;
LDBLE disp;
LDBLE temp;
LDBLE por; /* free (uncharged) porewater porosities */
LDBLE por_il; /* interlayer water porosities */
LDBLE por; /* free (uncharged) porewater porosities */
LDBLE por_il; /* interlayer water porosities */
LDBLE potV; /* potential (V) */
int punch;
int print;
};
@ -666,6 +667,9 @@ struct species
LDBLE gfw; /* gram formula wt of species */
LDBLE z; /* charge of species */
LDBLE dw; /* tracer diffusion coefficient in water at 25oC, m2/s */
LDBLE dw_t; /* correct Dw for temperature: Dw(TK) = Dw(298.15) * exp(dw_t / TK - dw_t / 298.15) */
LDBLE dw_a; /* ion size parm for calc'ng SC = SC0 - (B1 * SC0 + B2) * kk * dw_a / (1 + kk * dw_a) */
LDBLE dw_a_exp; /* power term for ionic strength correction of dw_a */
LDBLE erm_ddl; /* enrichment factor in DDL */
LDBLE equiv; /* equivalents in exchange species */
LDBLE alk; /* alkalinity of species, used for cec in exchange */
@ -676,6 +680,7 @@ struct species
LDBLE dha, dhb, a_f; /* WATEQ Debye Huckel a and b-dot; active_fraction coef for exchange species */
LDBLE lk; /* log10 k at working temperature */
LDBLE logk[MAX_LOG_K_INDICES]; /* log kt0, delh, 6 coefficients analytical expression + volume terms */
LDBLE Jones_Dole[10]; /* 7 coefficients analytical expression for B, D, anion terms and pressure in Jones_Dole viscosity eqn */
/* VP: Density Start */
LDBLE millero[7]; /* regression coefficients to calculate temperature dependent phi_0 and b_v of Millero density model */
/* VP: Density End */
@ -1031,13 +1036,14 @@ struct sol_D
{
int count_spec; /* number of aqueous + exchange species */
int count_exch_spec; /* number of exchange species */
LDBLE exch_total, x_max; /* total moles of X-, max X- in transport step in sol_D[1] */
LDBLE exch_total, x_max, tk_x; /* total moles of X-, max X- in transport step in sol_D[1], tk */
struct spec *spec;
};
struct J_ij
{
const char *name;
LDBLE tot1, tot2;
LDBLE tot1, tot2; /* species change in cells i and j */
int sol_D_number; /* the number of the species in sol_D */
};
struct M_S
{

View File

@ -44,7 +44,7 @@ initialize(void)
/*
* Allocate space
*/
space((void **) ((void *) &cell_data), INIT, &count_cells,
space((void **) ((void *) &cell_data), INIT, &count_cells + 2,
sizeof(struct cell_data));
space((void **) ((void *) &elements), INIT, &max_elements,
@ -630,6 +630,7 @@ initial_solutions(int print)
}
converge1 = check_residuals();
sum_species();
viscosity();
add_isotopes(solution_ref);
punch_all();
print_all();
@ -751,6 +752,7 @@ initial_exchangers(int print)
converge = model();
converge1 = check_residuals();
sum_species();
viscosity();
species_list_sort();
print_exchange();
xexchange_save(n_user);
@ -1445,6 +1447,7 @@ xsolution_save(int n_user)
temp_solution.Set_description(description_x);
temp_solution.Set_tc(tc_x);
temp_solution.Set_patm(patm_x);
temp_solution.Set_potV(potV_x);
temp_solution.Set_ph(ph_x);
temp_solution.Set_pe(solution_pe_x);
temp_solution.Set_mu(mu_x);

View File

@ -4713,6 +4713,7 @@ set(int initial)
tk_x = tc_x + 273.15;
patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa)
potV_x = solution_ptr->Get_potV();
/*
* H+, e-, H2O

View File

@ -1281,14 +1281,14 @@ pitzer(void)
F = F1 = F2 = -A0 * (DI / (1.0 + B * DI) + 2.0 * log(1.0 + B * DI) / B);
if (patm_x > 1.0)
{
LDBLE pap = 0.0;
LDBLE pap;
pap = (7e-5 + 1.93e-9 * pow(TK - 250.0, 2.0)) * patm_x;
B1 = B - (pap > 0.2 ? 0.2 : pap);
if (TK > 263.0)
{
if (TK <= 263)
pap = 0;
else
pap = (9.65e-10 * pow(TK - 263.0, 2.773)) * pow(patm_x, 0.623);
//pap = (-5.22e-4 + 7.19e-8 * pow(TK - 263.0, 2.0)) * pow(patm_x, 0.623);
}
//pap = (-5.22e-4 + 7.19e-8 * pow(TK - 263.0, 2.0)) * pow(patm_x, 0.623);
B2 = B - (pap > 0.2 ? 0.2 : pap);
if (B1 != 0)
F1 = -A0 * (DI / (1.0 + B1 * DI) + 2.0 * log(1.0 + B1 * DI) / B1);
@ -1709,6 +1709,7 @@ set_pz(int initial)
tk_x = tc_x + 273.15;
patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa)
potV_x = solution_ptr->Get_potV();
/*
* H+, e-, H2O

View File

@ -2975,7 +2975,7 @@ punch_identifiers(void)
else if (state == TRANSPORT)
{
fpunchf(PHAST_NULL("dist_x"), gformat,
(double) cell_data[cell - 1].mid_cell_x);
(double) cell_data[cell].mid_cell_x);
}
else
{

View File

@ -3157,6 +3157,35 @@ read_millero_abcdef (char *ptr, LDBLE * abcdef)
}
/* VP: Density End */
/* ---------------------------------------------------------------------- */
int Phreeqc::
read_viscosity_parms(char *ptr, LDBLE * Jones_Dole)
/* ---------------------------------------------------------------------- */
{
int j;
/*
* Read .
*/
for (j = 0; j <= 9; j++)
{
Jones_Dole[j] = 0.0;
}
j =
sscanf (ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT,
&(Jones_Dole[0]), &(Jones_Dole[1]), &(Jones_Dole[2]), &(Jones_Dole[3]), &(Jones_Dole[4]), &(Jones_Dole[5]), &(Jones_Dole[6]), &(Jones_Dole[7]), &(Jones_Dole[8]), &(Jones_Dole[9]));
if (j < 1)
{
input_error++;
error_msg ("Expecting numeric values for viscosity calculation.",
CONTINUE);
return (ERROR);
}
// The B0 are for 25°C, subtract the temperature factor...
if (Jones_Dole[1] != 0)
Jones_Dole[0] -= Jones_Dole[1] * exp(Jones_Dole[2] * 25.0);
return (OK);
}
/* ---------------------------------------------------------------------- */
int Phreeqc::
read_incremental_reactions(void)
@ -5615,9 +5644,10 @@ read_solution(void)
"isotope", /* 9 */
"water", /* 10 */
"press", /* 11 */
"pressure" /* 12 */
"pressure", /* 12 */
"potential" /* 13 */
};
int count_opt_list = 13;
int count_opt_list = 14;
/*
* Read solution number and description
*/
@ -5856,6 +5886,18 @@ read_solution(void)
}
}
break;
case 13: /* potential, Volt */
{
if (sscanf(next_char, SCANFORMAT, &dummy) != 1)
{
temp_solution.Set_potV(0);
}
else
{
temp_solution.Set_potV(dummy);
}
}
break;
case OPTION_DEFAULT:
/*
* Read concentration
@ -5956,9 +5998,10 @@ read_species(void)
/* VP: Density Start */
"millero", /* 21 */
/* VP: Density End */
"vm" /* 22, parms for molar volume, a1..a4 and w_ref from supcrt, I terms */
"vm", /* 22, parms for molar volume, a1..a4 and w_ref from supcrt, I terms */
"viscosity" /* 23, b and d parms for viscosity, (b1 + b2 * exp(-b3 * tc)) * c + (d1 * exp(-d2 * tc)) * c ^ d3 */
};
int count_opt_list = 23;
int count_opt_list = 24;
association = TRUE;
s_ptr = NULL;
@ -6265,7 +6308,9 @@ read_species(void)
input_error++;
break;
}
i = sscanf(next_char, SCANFORMAT, &s_ptr->dw);
s_ptr->dw_t = s_ptr->dw_a = s_ptr->dw_a_exp = 0;
i = sscanf(next_char, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, &s_ptr->dw, &s_ptr->dw_t,
&s_ptr->dw_a, &s_ptr->dw_a_exp);
opt_save = OPTION_DEFAULT;
break;
case 20: /* enrichment factor in the DDL */
@ -6325,6 +6370,20 @@ read_species(void)
print_density = OK;
opt_save = OPTION_DEFAULT;
break;
case 23: /* viscosity parms for the Jones-Dole eqn */
if (s_ptr == NULL)
{
error_string = sformatf(
"No reaction defined before option, %s.",
opt_list[opt]);
error_msg(error_string, CONTINUE);
input_error++;
break;
}
read_viscosity_parms(next_char, &s_ptr->Jones_Dole[0]);
print_viscosity = OK;
opt_save = OPTION_DEFAULT;
break;
case OPTION_DEFAULT:
/*
* Get space for species information and parse equation

View File

@ -193,7 +193,7 @@ read_transport(void)
case 2: /* print */
case 20: /* print_cells */
print_temp =
read_list_ints_range(&next_char, &count_print, TRUE,
read_list_ints_range(&next_char, &count_print, FALSE,
print_temp);
opt_save = 2;
break;
@ -353,7 +353,7 @@ read_transport(void)
case 21: /* selected_cells */
case 30: /* punch_cells */
punch_temp =
read_list_ints_range(&next_char, &count_punch, TRUE,
read_list_ints_range(&next_char, &count_punch, FALSE,
punch_temp);
opt_save = 10;
break;
@ -662,12 +662,12 @@ read_transport(void)
* Allocate space for cell_data
*/
cell_data = (struct cell_data *) PHRQ_realloc(cell_data,
(size_t) (max_cells * (1 + stag_data->count_stag) + 1) * sizeof(struct cell_data));
(size_t) (max_cells * (1 + stag_data->count_stag) + 2) * sizeof(struct cell_data));
if (cell_data == NULL)
malloc_error();
// initialize new cells
int all_cells_now = max_cells * (1 + stag_data->count_stag) + 1;
int all_cells_now = max_cells * (1 + stag_data->count_stag) + 2;
if (all_cells_now > all_cells)
{
for (int i = all_cells; i < all_cells_now; i++)
@ -678,6 +678,7 @@ read_transport(void)
cell_data[i].temp = 25.0;
cell_data[i].por = 0.1;
cell_data[i].por_il = 0.01;
cell_data[i].potV = 0;
cell_data[i].punch = FALSE;
cell_data[i].print = FALSE;
}
@ -694,15 +695,15 @@ read_transport(void)
error_string = sformatf(
"No cell-lengths were read; length = 1 m assumed.");
warning_msg(error_string);
for (i = 0; i < max_cells; i++)
for (i = 1; i <= max_cells; i++)
cell_data[i].length = 1.0;
}
}
else
{
for (i = 0; i < count_length; i++)
for (i = 1; i <= count_length; i++)
{
cell_data[i].length = length[i];
cell_data[i].length = length[i - 1];
}
if (max_cells > count_length)
{
@ -710,18 +711,19 @@ read_transport(void)
"Cell-lengths were read for %d cells. Last value is used till cell %d.",
count_length, max_cells);
warning_msg(error_string);
for (i = count_length - 1; i < max_cells; i++)
cell_data[i].length = length[count_length - 1];
for (i = count_length; i <= max_cells; i++)
cell_data[i + 1].length = length[count_length - 1];
}
}
cell_data[0].mid_cell_x = cell_data[0].length / 2;
for (i = 1; i < max_cells; i++)
cell_data[0].mid_cell_x = 0;
cell_data[1].mid_cell_x = cell_data[1].length / 2;
for (i = 2; i <= max_cells; i++)
{
cell_data[i].mid_cell_x = cell_data[i - 1].mid_cell_x +
(cell_data[i - 1].length + cell_data[i].length) / 2;
}
cell_data[max_cells].mid_cell_x =
cell_data[max_cells - 1].mid_cell_x + cell_data[max_cells - 1].length;
cell_data[max_cells + 1].mid_cell_x =
cell_data[max_cells].mid_cell_x + cell_data[max_cells].length / 2;
/*
* Fill in data for dispersivities
*/
@ -732,22 +734,22 @@ read_transport(void)
error_string = sformatf(
"No dispersivities were read; disp = 0 assumed.");
warning_msg(error_string);
for (i = 0; i < max_cells; i++)
for (i = 1; i <= max_cells; i++)
cell_data[i].disp = 0.0;
}
}
else
{
for (i = 0; i < count_disp; i++)
cell_data[i].disp = disp[i];
for (i = 1; i <= count_disp; i++)
cell_data[i].disp = disp[i - 1];
if (max_cells > count_disp)
{
error_string = sformatf(
"Dispersivities were read for %d cells. Last value is used till cell %d.",
count_disp, max_cells);
warning_msg(error_string);
for (i = count_disp - 1; i < max_cells; i++)
cell_data[i].disp = disp[count_disp - 1];
for (i = count_disp; i <= max_cells; i++)
cell_data[i + 1].disp = disp[count_disp - 1];
}
}
count_cells = max_cells;
@ -756,8 +758,8 @@ read_transport(void)
*/
if (stag_data->count_stag > 0)
{
max_cells = count_cells * (1 + stag_data->count_stag) + 1;
for (i = 0; i < count_cells; i++)
max_cells = count_cells * (1 + stag_data->count_stag) + 2;
for (i = 1; i <= count_cells; i++)
{
for (l = 1; l <= stag_data->count_stag; l++)
cell_data[i + 1 + l * count_cells].mid_cell_x =
@ -769,11 +771,11 @@ read_transport(void)
*/
if (count_punch != 0)
{
for (i = 0; i < max_cells; i++)
for (i = 0; i < all_cells; i++)
cell_data[i].punch = FALSE;
for (i = 0; i < count_punch; i++)
{
if (punch_temp[i] > max_cells || punch_temp[i] < 1)
if (punch_temp[i] > all_cells - 1 || punch_temp[i] < 0)
{
error_string = sformatf(
"Cell number for punch is out of range, %d. Request ignored.",
@ -781,22 +783,22 @@ read_transport(void)
warning_msg(error_string);
}
else
cell_data[punch_temp[i] - 1].punch = TRUE;
cell_data[punch_temp[i]].punch = TRUE;
}
}
else if (simul_tr == 1)
for (i = 0; i < max_cells; i++)
for (i = 1; i < all_cells; i++)
cell_data[i].punch = TRUE;
/*
* Fill in data for print
*/
if (count_print != 0)
{
for (i = 0; i < max_cells; i++)
for (i = 0; i < all_cells; i++)
cell_data[i].print = FALSE;
for (i = 0; i < count_print; i++)
{
if (print_temp[i] > max_cells || print_temp[i] < 1)
if (print_temp[i] > all_cells - 1 || print_temp[i] < 0)
{
error_string = sformatf(
"Cell number for print is out of range, %d. Request ignored.",
@ -804,11 +806,11 @@ read_transport(void)
warning_msg(error_string);
}
else
cell_data[print_temp[i] - 1].print = TRUE;
cell_data[print_temp[i]].print = TRUE;
}
}
else if (simul_tr == 1)
for (i = 0; i < max_cells; i++)
for (i = 1; i < all_cells; i++)
cell_data[i].print = TRUE;
/*
* Fill in porosities
@ -821,7 +823,7 @@ read_transport(void)
error_msg(error_string, CONTINUE);
}
for (i = 0; i < max_cells; i++)
for (i = 1; i < all_cells; i++)
{
multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor);
interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor);
@ -1175,7 +1177,7 @@ dump_cpp(void)
}
sprintf(token, "\t-length\n");
fs << token;
for (int i = 0; i < count_cells; i++)
for (int i = 1; i <= count_cells; i++)
{
sprintf(token, "%12.3e", (double) cell_data[i].length);
fs << token;
@ -1189,7 +1191,7 @@ dump_cpp(void)
fs << token;
sprintf(token, "\t-disp\n");
fs << token;
for (int i = 0; i < count_cells; i++)
for (int i = 1; i <= count_cells; i++)
{
if (!high_precision)
{
@ -1216,7 +1218,7 @@ dump_cpp(void)
else
j = count_cells;
l = 0;
for (int i = 0; i < j; i++)
for (int i = 1; i <= j; i++)
{
if (cell_data[i].punch != TRUE)
continue;
@ -1238,7 +1240,7 @@ dump_cpp(void)
else
j = count_cells;
l = 0;
for (int i = 0; i < j; i++)
for (int i = 1; i <= j; i++)
{
if (cell_data[i].print != TRUE)
continue;

View File

@ -737,6 +737,7 @@ set_sit(int initial)
tk_x = tc_x + 273.15;
patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa)
potV_x = solution_ptr->Get_potV();
/*
* H+, e-, H2O

View File

@ -547,9 +547,10 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
"desc", /* 12 */
"descriptor", /* 13 */
"pressure", /* 14 */
"press" /* 15 */
"press", /* 15 */
"potential" /* 16 */
};
int count_opt_list = 16;
int count_opt_list = 17;
/*
* look for solution number
@ -613,6 +614,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
temp_solution.Set_description(description);
temp_solution.Set_tc(defaults.temp);
temp_solution.Set_patm(defaults.pressure);
temp_solution.Set_potV(0);
temp_solution.Set_ph(defaults.ph);
temp_solution.Set_density(defaults.density);
temp_solution.Set_pe(defaults.pe);
@ -927,6 +929,14 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
}
}
break;
case 16: /* pote, V */
{
if (sscanf(next_char, SCANFORMAT, &dummy) == 1)
{
temp_solution.Set_potV(dummy);
}
}
break;
case OPTION_DEFAULT:
/*
* Read concentration

View File

@ -106,11 +106,11 @@ step(LDBLE step_fraction)
tc_x = t_ptr->Temperature_for_step(step_number);
}
if ((state == TRANSPORT) && (transport_step != 0) &&
(cell > 0) && (cell != count_cells + 1))
(cell > 0) && (cell != count_cells + 1)) // ** needs potV correction
{
difftemp = tc_x - cell_data[cell - 1].temp;
cell_data[cell - 1].temp += difftemp / tempr;
tc_x = cell_data[cell - 1].temp;
difftemp = tc_x - cell_data[cell].temp;
cell_data[cell].temp += difftemp / tempr;
tc_x = cell_data[cell].temp;
}
/*
* Pressure
@ -305,6 +305,7 @@ xsolution_zero(void)
tc_x = 0.0;
patm_x = 0;
potV_x = 0;
ph_x = 0.0;
solution_pe_x = 0.0;
mu_x = 0.0;
@ -357,6 +358,7 @@ add_solution(cxxSolution *solution_ptr, LDBLE extensive, LDBLE intensive)
tc_x += solution_ptr->Get_tc() * intensive;
ph_x += solution_ptr->Get_ph() * intensive;
patm_x += solution_ptr->Get_patm() * intensive;
potV_x += solution_ptr->Get_potV() * intensive;
solution_pe_x += solution_ptr->Get_pe() * intensive;
mu_x += solution_ptr->Get_mu() * intensive;
ah2o_x += solution_ptr->Get_ah2o() * intensive;

File diff suppressed because it is too large Load Diff