mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 08:38:23 +01:00
Cleaning up code.
Removed PHREEQC2 ifdef. Some SKIP. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7717 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
parent
c9c8a7ac65
commit
c176fe3b2e
82
Form1.h
82
Form1.h
@ -548,89 +548,7 @@ namespace zdg_ui2 {
|
||||
std::cerr << "ERROR: " << estring << std::endl;
|
||||
}
|
||||
}
|
||||
#ifdef SKIP
|
||||
void SaveCurves( System::Object ^sender, System::EventArgs ^e )
|
||||
{
|
||||
std::string file_name = "curves.u_g";
|
||||
// Get the graph curves...
|
||||
std::ofstream f_out(file_name.c_str(), std::ifstream::out);
|
||||
|
||||
if (!f_out.is_open())
|
||||
{
|
||||
std::ostringstream estream;
|
||||
estream << "Could not open csv file for USER_GRAPH " << file_name;
|
||||
form_error_msg(estream.str());
|
||||
return;
|
||||
}
|
||||
|
||||
// write headings
|
||||
size_t max_points = 0;
|
||||
f_out.precision(4);
|
||||
for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++)
|
||||
{
|
||||
LineItem ^curve;
|
||||
curve = (LineItem ^) zg1->GraphPane->CurveList[i];
|
||||
// Get the PointPairList
|
||||
IPointListEdit ^ip = (IPointListEdit^) curve->Points;
|
||||
|
||||
// Calculate max_points
|
||||
if ((size_t) ip->Count > max_points)
|
||||
max_points = ip->Count;
|
||||
|
||||
// write headers
|
||||
std::string s_std;
|
||||
ToString(curve->Label->Text, s_std);
|
||||
f_out.width(12);
|
||||
f_out << "x" << "\t";
|
||||
f_out.width(12);
|
||||
if (s_std.size() > 0)
|
||||
{
|
||||
f_out << s_std << "\t";
|
||||
}
|
||||
else
|
||||
{
|
||||
f_out << "y" << "\t";
|
||||
}
|
||||
}
|
||||
|
||||
f_out << std::endl;
|
||||
|
||||
// write data
|
||||
size_t i2 = 0;
|
||||
f_out << std::scientific;
|
||||
f_out.precision(4);
|
||||
|
||||
while (i2 < max_points)
|
||||
{
|
||||
for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++)
|
||||
{
|
||||
LineItem ^curve;
|
||||
curve = (LineItem ^) zg1->GraphPane->CurveList[i];
|
||||
// Get the PointPairList
|
||||
IPointListEdit ^ip = (IPointListEdit^) curve->Points;
|
||||
if (i2 < (size_t) ip->Count)
|
||||
{
|
||||
//double x = ip[i]->X;
|
||||
f_out.width(12);
|
||||
f_out << ip[i2]->X << "\t";
|
||||
f_out.width(12);
|
||||
f_out << ip[i2]->Y << "\t";
|
||||
}
|
||||
else if (i2 < max_points)
|
||||
{
|
||||
f_out.width(13);
|
||||
f_out << "\t";
|
||||
f_out.width(13);
|
||||
f_out << "\t";
|
||||
}
|
||||
}
|
||||
f_out << std::endl;
|
||||
i2++;
|
||||
}
|
||||
f_out.close();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
void SaveCurves( System::Object ^sender, System::EventArgs ^e )
|
||||
{
|
||||
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
|
||||
|
||||
735
Phreeqc.cpp
735
Phreeqc.cpp
@ -29,98 +29,7 @@ const struct const_iso Phreeqc::iso_defaults[] = {
|
||||
};
|
||||
|
||||
const int Phreeqc::count_iso_defaults = (sizeof(iso_defaults) / sizeof(struct const_iso));
|
||||
#ifdef SKIP
|
||||
Phreeqc::Phreeqc(PHRQ_io *io)
|
||||
{
|
||||
if (io)
|
||||
{
|
||||
phrq_io = io;
|
||||
}
|
||||
else
|
||||
{
|
||||
phrq_io = &this->ioInstance;
|
||||
}
|
||||
|
||||
phast = FALSE;
|
||||
s_pTail = NULL;
|
||||
user_database = NULL;
|
||||
rates = NULL;
|
||||
tally_table = NULL;
|
||||
spec = NULL;
|
||||
cations = NULL;
|
||||
anions = NULL;
|
||||
neutrals = NULL;
|
||||
IPRSNT = NULL;
|
||||
M = NULL;
|
||||
LGAMMA = NULL;
|
||||
sit_params = NULL;
|
||||
sit_LGAMMA = NULL;
|
||||
sit_IPRSNT = NULL;
|
||||
sit_M = NULL;
|
||||
|
||||
// counters for enum KEYWORDS
|
||||
for (int i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++)
|
||||
{
|
||||
keycount.push_back(0);
|
||||
}
|
||||
|
||||
// basic.c
|
||||
basic_interpreter = NULL;
|
||||
|
||||
//cl1.c
|
||||
x_arg = NULL, res_arg = NULL, scratch = NULL;
|
||||
x_arg_max = 0, res_arg_max = 0, scratch_max = 0;
|
||||
|
||||
// dw.c
|
||||
GASCON = 0.461522e0;
|
||||
TZ = 647.073e0;
|
||||
AA = 1.e0;
|
||||
G1 = 11.e0;
|
||||
G2 = 44.333333333333e0;
|
||||
GF = 3.5e0;
|
||||
|
||||
// model.c
|
||||
min_value = 1e-10;
|
||||
normal = NULL;
|
||||
ineq_array = NULL;
|
||||
res = NULL;
|
||||
cu = NULL;
|
||||
zero = NULL;
|
||||
delta1 = NULL;
|
||||
iu = NULL;
|
||||
is = NULL;
|
||||
back_eq = NULL;
|
||||
normal_max = 0;
|
||||
ineq_array_max = 0;
|
||||
res_max = 0;
|
||||
cu_max = 0;
|
||||
zero_max = 0;
|
||||
delta1_max = 0;
|
||||
iu_max = 0;
|
||||
is_max = 0;
|
||||
back_eq_max = 0;
|
||||
|
||||
// output.c
|
||||
forward_output_to_log = 0;
|
||||
|
||||
// phqalloc.c
|
||||
|
||||
// print.c
|
||||
sformatf_buffer = (char *) PHRQ_malloc(256 * sizeof(char));
|
||||
if (sformatf_buffer == NULL)
|
||||
malloc_error();
|
||||
sformatf_buffer_size = 256;
|
||||
|
||||
// transport.c
|
||||
J_ij = NULL;
|
||||
J_ij_il = NULL;
|
||||
m_s = NULL;
|
||||
|
||||
default_data_base = string_duplicate("phreeqc.dat");
|
||||
|
||||
init();
|
||||
}
|
||||
#endif
|
||||
Phreeqc::~Phreeqc(void)
|
||||
{
|
||||
|
||||
@ -259,570 +168,7 @@ size_t Phreeqc::list_components(std::list<std::string> &list_c)
|
||||
}
|
||||
return(list_c.size());
|
||||
}
|
||||
#ifdef SKIP
|
||||
void Phreeqc::init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
moles_per_kilogram_string = 0;
|
||||
pe_string = 0;
|
||||
|
||||
debug_model = FALSE;
|
||||
debug_prep = FALSE;
|
||||
debug_set = FALSE;
|
||||
debug_diffuse_layer = FALSE;
|
||||
debug_inverse = FALSE;
|
||||
itmax = 100;
|
||||
#ifdef USE_LONG_DOUBLE
|
||||
/* 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);
|
||||
#endif
|
||||
convergence_tolerance = 1e-8;
|
||||
#ifdef USE_LONG_DOUBLE
|
||||
/* from float.h, sets tolerance for cl1 routine */
|
||||
inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5);
|
||||
#else
|
||||
inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5);
|
||||
#endif
|
||||
step_size = 100.;
|
||||
pe_step_size = 10.;
|
||||
pp_scale = 1.0;
|
||||
pp_column_scale = 1.0;
|
||||
diagonal_scale = FALSE;
|
||||
censor = 0.0;
|
||||
mass_water_switch = FALSE;
|
||||
delay_mass_water = FALSE;
|
||||
incremental_reactions = FALSE;
|
||||
aqueous_only = 0;
|
||||
negative_concentrations = FALSE;
|
||||
|
||||
LOG_10 = log(10.0);
|
||||
|
||||
max_elements = MAX_ELEMENTS;
|
||||
max_elts = MAX_ELTS;
|
||||
max_line = MAX_LINE;
|
||||
max_master = MAX_MASTER;
|
||||
max_mb_unknowns = MAX_TRXN;
|
||||
max_phases = MAX_PHASES;
|
||||
max_s = MAX_S;
|
||||
max_trxn = MAX_TRXN;
|
||||
max_logk = MAX_S;
|
||||
max_master_isotope = MAX_ELTS;
|
||||
|
||||
count_elements = 0;
|
||||
count_master = 0;
|
||||
count_phases = 0;
|
||||
count_s = 0;
|
||||
count_logk = 0;
|
||||
count_master_isotope = 0;
|
||||
/*
|
||||
* Initialize advection
|
||||
*/
|
||||
count_ad_cells = 1;
|
||||
count_ad_shifts = 1;
|
||||
print_ad_modulus = 1;
|
||||
punch_ad_modulus = 1;
|
||||
|
||||
advection_punch = 0;
|
||||
advection_kin_time = 0.0;
|
||||
advection_kin_time_defined = FALSE;
|
||||
advection_print = 0;
|
||||
advection_warnings = TRUE;
|
||||
/*
|
||||
* Initialize transport
|
||||
*/
|
||||
count_cells = 1;
|
||||
count_shifts = 1;
|
||||
ishift = 1;
|
||||
bcon_first = bcon_last = 3;
|
||||
diffc = 0.3e-9;
|
||||
simul_tr = 0;
|
||||
tempr = 2.0;
|
||||
heat_diffc = -0.1;
|
||||
timest = 0.0;
|
||||
multi_Dflag = FALSE;
|
||||
interlayer_Dflag = FALSE;
|
||||
interlayer_tortf = 100.0;
|
||||
interlayer_Dpor = 0.1;
|
||||
/* !!!! count_stag = 0; */
|
||||
mcd_substeps = 1.0;
|
||||
print_modulus = 1;
|
||||
punch_modulus = 1;
|
||||
dump_modulus = 0;
|
||||
dump_in = FALSE;
|
||||
transport_warnings = TRUE;
|
||||
|
||||
cell_data = 0;
|
||||
elements = 0;
|
||||
elt_list = 0;
|
||||
|
||||
inverse = 0;
|
||||
count_inverse = 0;
|
||||
line = 0;
|
||||
line_save = 0;
|
||||
|
||||
master = 0;
|
||||
|
||||
mb_unknowns = 0;
|
||||
/* !!!! */
|
||||
stag_data = 0;
|
||||
phases = 0;
|
||||
trxn.token = 0;
|
||||
s = 0;
|
||||
logk = 0;
|
||||
master_isotope = 0;
|
||||
|
||||
title_x = NULL;
|
||||
//pe_x = NULL;
|
||||
description_x = NULL;
|
||||
units_x = NULL;
|
||||
s_x = NULL;
|
||||
|
||||
sum_mb1 = NULL;
|
||||
sum_mb2 = NULL;
|
||||
sum_jacob0 = NULL;
|
||||
sum_jacob1 = NULL;
|
||||
sum_jacob2 = NULL;
|
||||
sum_delta = NULL;
|
||||
|
||||
//isotopes_x = 0;
|
||||
|
||||
x = NULL;
|
||||
max_unknowns = 0;
|
||||
|
||||
array = NULL;
|
||||
delta = NULL;
|
||||
residual = NULL;
|
||||
s_h2o = NULL;
|
||||
s_hplus = NULL;
|
||||
s_h3oplus = NULL;
|
||||
s_eminus = NULL;
|
||||
s_co3 = NULL;
|
||||
s_h2 = NULL;
|
||||
s_o2 = NULL;
|
||||
|
||||
logk_hash_table = 0;
|
||||
master_isotope_hash_table = 0;
|
||||
elements_hash_table = 0;
|
||||
species_hash_table = 0;
|
||||
phases_hash_table = 0;
|
||||
/*
|
||||
* Initialize punch
|
||||
*/
|
||||
punch.in = FALSE;
|
||||
punch.count_totals = 0;
|
||||
punch.totals = 0;
|
||||
punch.count_molalities = 0;
|
||||
|
||||
punch.molalities = 0;
|
||||
punch.count_activities = 0;
|
||||
|
||||
punch.activities = 0;
|
||||
punch.count_pure_phases = 0;
|
||||
|
||||
punch.pure_phases = 0;
|
||||
punch.count_si = 0;
|
||||
|
||||
punch.si = 0;
|
||||
punch.count_gases = 0;
|
||||
|
||||
punch.gases = 0;
|
||||
punch.count_s_s = 0;
|
||||
punch.s_s = 0;
|
||||
|
||||
punch.count_kinetics = 0;
|
||||
punch.kinetics = 0;
|
||||
|
||||
punch.count_isotopes = 0;
|
||||
punch.isotopes = 0;
|
||||
|
||||
punch.count_calculate_values = 0;
|
||||
punch.calculate_values = 0;
|
||||
|
||||
count_save_values = 0;
|
||||
save_values = 0;
|
||||
|
||||
|
||||
punch.inverse = TRUE;
|
||||
punch.sim = TRUE;
|
||||
punch.state = TRUE;
|
||||
punch.soln = TRUE;
|
||||
punch.dist = TRUE;
|
||||
punch.time = TRUE;
|
||||
punch.step = TRUE;
|
||||
punch.rxn = FALSE;
|
||||
punch.temp = FALSE;
|
||||
punch.ph = TRUE;
|
||||
punch.pe = TRUE;
|
||||
punch.alk = FALSE;
|
||||
punch.mu = FALSE;
|
||||
punch.water = FALSE;
|
||||
punch.high_precision = FALSE;
|
||||
punch.user_punch = TRUE;
|
||||
punch.charge_balance = FALSE;
|
||||
punch.percent_error = FALSE;
|
||||
/*
|
||||
* last model
|
||||
*/
|
||||
last_model.exchange = NULL;
|
||||
last_model.gas_phase = NULL;
|
||||
last_model.ss_assemblage = NULL;
|
||||
last_model.kinetics = NULL;
|
||||
last_model.pp_assemblage = NULL;
|
||||
last_model.add_formula = NULL;
|
||||
last_model.si = NULL;
|
||||
last_model.surface_comp = NULL;
|
||||
last_model.surface_charge = NULL;
|
||||
/*
|
||||
* rates
|
||||
*/
|
||||
rates = 0;
|
||||
count_rates = 0;
|
||||
initial_total_time = 0;
|
||||
rate_m = 0;
|
||||
rate_m0 = 0;
|
||||
rate_time = 0;
|
||||
rate_sim_time_start = 0;
|
||||
rate_sim_time_end = 0;
|
||||
rate_sim_time = 0;
|
||||
rate_moles = 0;
|
||||
|
||||
/*
|
||||
* user_print, user_punch
|
||||
*/
|
||||
user_print = 0;
|
||||
user_punch = 0;
|
||||
user_punch_headings = 0;
|
||||
user_punch_count_headings = 0;
|
||||
n_user_punch_index = 0;
|
||||
fpunchf_user_s_warning = 0;
|
||||
|
||||
spread_length = 10;
|
||||
/*
|
||||
Initialize llnl aqueous model parameters
|
||||
*/
|
||||
llnl_temp = 0;
|
||||
llnl_count_temp = 0;
|
||||
|
||||
llnl_adh = 0;
|
||||
llnl_count_adh = 0;
|
||||
|
||||
llnl_bdh = 0;
|
||||
llnl_count_bdh = 0;
|
||||
|
||||
llnl_bdot = 0;
|
||||
llnl_count_bdot = 0;
|
||||
|
||||
llnl_co2_coefs = 0;
|
||||
llnl_count_co2_coefs = 0;
|
||||
|
||||
|
||||
change_surf = 0;
|
||||
change_surf_count = 0;
|
||||
|
||||
/* Initialize print here, not in global.h */
|
||||
pr.all = TRUE;
|
||||
pr.initial_solutions = TRUE;
|
||||
pr.initial_exchangers = TRUE;
|
||||
pr.reactions = TRUE;
|
||||
pr.gas_phase = TRUE;
|
||||
pr.ss_assemblage = TRUE;
|
||||
pr.pp_assemblage = TRUE;
|
||||
pr.surface = TRUE;
|
||||
pr.exchange = TRUE;
|
||||
pr.kinetics = TRUE;
|
||||
pr.totals = TRUE;
|
||||
pr.eh = TRUE;
|
||||
pr.species = TRUE;
|
||||
pr.saturation_indices = TRUE;
|
||||
pr.irrev = TRUE;
|
||||
pr.mix = TRUE;
|
||||
pr.reaction = TRUE;
|
||||
pr.use = TRUE;
|
||||
pr.logfile = FALSE;
|
||||
pr.punch = TRUE;
|
||||
if (phast == TRUE)
|
||||
{
|
||||
pr.status = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
pr.status = TRUE;
|
||||
}
|
||||
pr.inverse = TRUE;
|
||||
pr.dump = TRUE;
|
||||
pr.user_print = TRUE;
|
||||
pr.headings = TRUE;
|
||||
pr.user_graph = TRUE;
|
||||
pr.echo_input = TRUE;
|
||||
count_warnings = 0;
|
||||
pr.warnings = 100;
|
||||
pr.initial_isotopes = TRUE;
|
||||
pr.isotope_ratios = TRUE;
|
||||
pr.isotope_alphas = TRUE;
|
||||
pr.hdf = FALSE;
|
||||
pr.alkalinity = FALSE;
|
||||
species_list = NULL;
|
||||
user_database = NULL;
|
||||
first_read_input = TRUE;
|
||||
have_punch_name = FALSE;
|
||||
selected_output_file_name = NULL;
|
||||
dump_file_name = NULL;
|
||||
|
||||
/* calculate_value */
|
||||
max_calculate_value = MAX_ELTS;
|
||||
count_calculate_value = 0;
|
||||
|
||||
calculate_value = 0;
|
||||
calculate_value_hash_table = 0;
|
||||
|
||||
/* isotope_ratio */
|
||||
max_isotope_ratio = MAX_ELTS;
|
||||
count_isotope_ratio = 0;
|
||||
isotope_ratio = 0;
|
||||
isotope_ratio_hash_table = 0;
|
||||
|
||||
/* isotope_value */
|
||||
max_isotope_alpha = MAX_ELTS;
|
||||
count_isotope_alpha = 0;
|
||||
isotope_alpha = 0;
|
||||
isotope_alpha_hash_table = 0;
|
||||
|
||||
phreeqc_mpi_myself = 0;
|
||||
|
||||
copy_solution.n_user = copy_solution.start = copy_solution.end = 0;
|
||||
copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0;
|
||||
copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0;
|
||||
copy_surface.n_user = copy_surface.start = copy_surface.end = 0;
|
||||
copy_ss_assemblage.n_user = copy_ss_assemblage.start = copy_ss_assemblage.end = 0;
|
||||
copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0;
|
||||
copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0;
|
||||
copy_mix.n_user = copy_mix.start = copy_mix.end = 0;
|
||||
copy_reaction.n_user = copy_reaction.start = copy_reaction.end = 0;
|
||||
copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0;
|
||||
copy_pressure.n_user = copy_pressure.start = copy_pressure.end = 0;
|
||||
|
||||
set_forward_output_to_log(FALSE);
|
||||
simulation = 0;
|
||||
/*
|
||||
* cvode
|
||||
*/
|
||||
|
||||
cvode_init();
|
||||
/*
|
||||
* Pitzer
|
||||
*/
|
||||
pitzer_model = FALSE;
|
||||
max_pitz_param = 100;
|
||||
count_pitz_param = 0;
|
||||
use_etheta = TRUE;
|
||||
pitz_params = 0;
|
||||
|
||||
max_theta_param = 100;
|
||||
count_theta_param = 0;
|
||||
theta_params = 0;
|
||||
|
||||
ICON = TRUE;
|
||||
OTEMP = 0.0;
|
||||
for (i = 0; i < 23; i++)
|
||||
{
|
||||
BK[i] = 0.0;
|
||||
DK[i] = 0.0;
|
||||
}
|
||||
pitzer_pe = FALSE;
|
||||
|
||||
count_pp = count_pg = count_ss = 0; // used in store_get_equi_reactants
|
||||
x0_moles = NULL;
|
||||
/*
|
||||
* SIT
|
||||
*/
|
||||
sit_model = FALSE;
|
||||
max_sit_param = 100;
|
||||
count_sit_param = 0;
|
||||
sit_params = 0;
|
||||
|
||||
/*
|
||||
* to facilitate debuging
|
||||
*/
|
||||
dbg_master = master;
|
||||
calculating_deriv = FALSE;
|
||||
numerical_deriv = FALSE;
|
||||
|
||||
zeros = 0;
|
||||
zeros_max = 1;
|
||||
|
||||
cell_pore_volume = 0;
|
||||
cell_volume = 0;
|
||||
cell_porosity = 0;
|
||||
cell_saturation = 0;
|
||||
|
||||
print_density = 0;
|
||||
|
||||
/* basic.c */
|
||||
|
||||
/* dw.c */
|
||||
Q0 = 0;
|
||||
Q5 = 0;
|
||||
Z = 0;
|
||||
DZ = 0;
|
||||
Y = 0;
|
||||
B1 = 0;
|
||||
B2 = 0;
|
||||
B1T = 0;
|
||||
B2T = 0;
|
||||
B1TT = 0;
|
||||
B2TT = 0;
|
||||
|
||||
/* input.c */
|
||||
reading_db = FALSE;
|
||||
|
||||
/* integrate.c */
|
||||
z_global = 0;
|
||||
xd_global = 0;
|
||||
alpha_global = 0;
|
||||
|
||||
/* inverse.c */
|
||||
max_row_count = 50;
|
||||
max_column_count = 50;
|
||||
carbon = FALSE;
|
||||
col_name = NULL;
|
||||
row_name = NULL;
|
||||
count_rows = 0;
|
||||
count_optimize = 0;
|
||||
col_phases = 0;
|
||||
col_redox = 0;
|
||||
col_epsilon = 0;
|
||||
col_ph = 0;
|
||||
col_water = 0;
|
||||
col_isotopes = 0;
|
||||
col_phase_isotopes = 0;
|
||||
row_mb = 0;
|
||||
row_fract = 0;
|
||||
row_charge = 0;
|
||||
row_carbon = 0;
|
||||
row_isotopes = 0;
|
||||
row_epsilon = 0;
|
||||
row_isotope_epsilon = 0;
|
||||
row_water = 0;
|
||||
inv_zero = NULL;
|
||||
array1 = 0;
|
||||
inv_delta1 = NULL;
|
||||
delta2 = NULL;
|
||||
delta3 = NULL;
|
||||
inv_cu = NULL;
|
||||
delta_save = NULL;
|
||||
min_delta = NULL;
|
||||
max_delta = NULL;
|
||||
klmd = 0;
|
||||
nklmd = 0;
|
||||
n2d = 0;
|
||||
kode = 0;
|
||||
iter = 0;
|
||||
toler = 0;
|
||||
error = 0;
|
||||
max_pct = 0;
|
||||
scaled_error = 0;
|
||||
master_alk = NULL;
|
||||
row_back = NULL;
|
||||
col_back = NULL;
|
||||
good = NULL;
|
||||
bad = NULL;
|
||||
minimal = NULL;
|
||||
max_good = 0;
|
||||
max_bad = 0;
|
||||
max_minimal = 0;
|
||||
count_good = 0;
|
||||
count_bad = 0;
|
||||
count_minimal = 0;
|
||||
count_calls = 0;
|
||||
soln_bits = 0;
|
||||
phase_bits = 0;
|
||||
current_bits = 0;
|
||||
temp_bits = 0;
|
||||
netpath_file = NULL;
|
||||
count_inverse_models = 0;
|
||||
count_pat_solutions = 0;
|
||||
inv_res = NULL;
|
||||
inv_iu = NULL;
|
||||
inv_is = NULL;
|
||||
/* kinetics.c */
|
||||
m_original = NULL;
|
||||
m_temp = NULL;
|
||||
rk_moles = NULL;
|
||||
|
||||
/* pitzer.c */
|
||||
A0 = 0;
|
||||
count_cations = 0;
|
||||
count_anions = 0;
|
||||
count_neutrals = 0;
|
||||
MAXCATIONS = 0;
|
||||
FIRSTANION = 0;
|
||||
MAXNEUTRAL = 0;
|
||||
mcb0 = NULL;
|
||||
mcb1 = NULL;
|
||||
mcc0 = NULL;
|
||||
/* read.c */
|
||||
dummy = 0;
|
||||
prev_next_char = NULL;
|
||||
/* sit.c */
|
||||
sit_A0 = 0;
|
||||
sit_count_cations = 0;
|
||||
sit_count_anions = 0;
|
||||
sit_count_neutrals = 0;
|
||||
sit_MAXCATIONS = 0;
|
||||
sit_FIRSTANION = 0;
|
||||
sit_MAXNEUTRAL = 0;
|
||||
/* tidy.c */
|
||||
a0 = 0;
|
||||
a1 = 0;
|
||||
kc = 0;
|
||||
kb = 0;
|
||||
/* tally.c */
|
||||
t_buffer = NULL;
|
||||
tally_count_component = 0;
|
||||
count_tally_table_columns = 0;
|
||||
count_tally_table_rows = 0;
|
||||
/* transport.c */
|
||||
sol_D = NULL;
|
||||
sol_D_dbg = NULL;
|
||||
J_ij_count_spec = 0;
|
||||
count_m_s = 0;
|
||||
tot1_h = 0;
|
||||
tot1_o = 0;
|
||||
tot2_h = 0;
|
||||
tot2_o = 0;
|
||||
diffc_max = 0;
|
||||
diffc_tr = 0;
|
||||
J_ij_sum = 0;
|
||||
transp_surf = FALSE;
|
||||
heat_mix_array = NULL;
|
||||
temp1 = NULL;
|
||||
temp2 = NULL;
|
||||
nmix = 0;
|
||||
heat_nmix = 0;
|
||||
heat_mix_f_imm = 0;
|
||||
heat_mix_f_m = 0;
|
||||
warn_MCD_X = 0;
|
||||
warn_fixed_Surf = 0;
|
||||
/* model.c */
|
||||
gas_in = FALSE;
|
||||
|
||||
/* utilities.c */
|
||||
spinner = 0;
|
||||
|
||||
count_strings = 0;
|
||||
#ifdef MULTICHART
|
||||
chart_handler.Set_io(phrq_io);
|
||||
#endif
|
||||
run_info.Set_io(phrq_io);
|
||||
|
||||
phrq_io->clear_istream();
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
Phreeqc::Phreeqc(PHRQ_io *io)
|
||||
{
|
||||
// phrq_io
|
||||
@ -1207,7 +553,6 @@ void Phreeqc::init(void)
|
||||
solution_phase_boundary_unknown = NULL;
|
||||
surface_unknown = NULL;
|
||||
gas_unknown = NULL;
|
||||
slack_unknown = NULL;
|
||||
ss_unknown = NULL;
|
||||
// auto gas_unknowns;
|
||||
/*----------------------------------------------------------------------
|
||||
@ -1366,7 +711,6 @@ void Phreeqc::init(void)
|
||||
mass_water_switch = FALSE;
|
||||
delay_mass_water = FALSE;
|
||||
dampen_ah2o = false;
|
||||
slack = false;
|
||||
censor = 0.0;
|
||||
aqueous_only = 0;
|
||||
negative_concentrations = FALSE;
|
||||
@ -1438,14 +782,7 @@ void Phreeqc::init(void)
|
||||
count_sys = 0;
|
||||
max_sys = 0;
|
||||
sys_tot = 0;
|
||||
#ifdef PHREEQC2
|
||||
AA_basic = 0;
|
||||
BB_basic = 0;
|
||||
CC = 0;
|
||||
I_m = 0;
|
||||
rho_0 = 0;
|
||||
eps_r = EPSILON;
|
||||
#else
|
||||
|
||||
V_solutes = 0.0;
|
||||
rho_0 = 0;
|
||||
kappa_0 = 0.0;
|
||||
@ -1457,7 +794,7 @@ void Phreeqc::init(void)
|
||||
QBrn = 0.0;
|
||||
ZBrn = 0.0;
|
||||
dgdP = 0.0;
|
||||
#endif
|
||||
|
||||
need_temp_msg = 0;
|
||||
solution_mass = 0;
|
||||
solution_volume = 0;
|
||||
@ -2329,7 +1666,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
solution_phase_boundary_unknown = NULL;
|
||||
surface_unknown = NULL;
|
||||
gas_unknown = NULL;
|
||||
slack_unknown = NULL;
|
||||
ss_unknown = NULL;
|
||||
*/
|
||||
// auto gas_unknowns;
|
||||
@ -2542,7 +1878,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
mass_water_switch = pSrc->mass_water_switch;
|
||||
delay_mass_water = pSrc->delay_mass_water;
|
||||
dampen_ah2o = pSrc->dampen_ah2o;
|
||||
slack = pSrc->slack;
|
||||
censor = pSrc->censor;
|
||||
aqueous_only = pSrc->aqueous_only;
|
||||
negative_concentrations = pSrc->negative_concentrations;
|
||||
@ -2725,14 +2060,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
max_sys = 0;
|
||||
sys_tot = 0;
|
||||
|
||||
#ifdef PHREEQC2
|
||||
AA_basic = 0;
|
||||
BB_basic = 0;
|
||||
CC = 0;
|
||||
I_m = 0;
|
||||
rho_0 = 0;
|
||||
eps_r = EPSILON;
|
||||
#else
|
||||
V_solutes = 0.0;
|
||||
rho_0 = 0;
|
||||
kappa_0 = 0.0;
|
||||
@ -2744,7 +2071,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
QBrn = 0.0;
|
||||
ZBrn = 0.0;
|
||||
dgdP = 0.0;
|
||||
#endif
|
||||
|
||||
need_temp_msg = 0;
|
||||
solution_mass = 0;
|
||||
solution_volume = 0;
|
||||
@ -2921,16 +2248,16 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
pitzer_model = pSrc->pitzer_model;
|
||||
sit_model = pSrc->sit_model;
|
||||
pitzer_pe = pSrc->pitzer_pe;
|
||||
#ifdef SKIP
|
||||
full_pitzer = FALSE;
|
||||
always_full_pitzer = FALSE;
|
||||
ICON = TRUE;
|
||||
IC = -1;
|
||||
COSMOT = 0;
|
||||
AW = 0;
|
||||
VP = 0;
|
||||
DW0 = 0;
|
||||
#endif
|
||||
|
||||
//full_pitzer = FALSE;
|
||||
//always_full_pitzer = FALSE;
|
||||
//ICON = TRUE;
|
||||
//IC = -1;
|
||||
//COSMOT = 0;
|
||||
//AW = 0;
|
||||
//VP = 0;
|
||||
//DW0 = 0;
|
||||
|
||||
ICON = pSrc->ICON;
|
||||
/*
|
||||
pitz_params = NULL;
|
||||
@ -3033,19 +2360,18 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
{
|
||||
sit_param_store(pSrc->sit_params[i], true);
|
||||
}
|
||||
#ifdef SKIP
|
||||
/* tidy.cpp ------------------------------- */
|
||||
a0 = 0;
|
||||
a1 = 0;
|
||||
kc = 0;
|
||||
kb = 0;
|
||||
//a0 = 0;
|
||||
//a1 = 0;
|
||||
//kc = 0;
|
||||
//kb = 0;
|
||||
/* tally.cpp ------------------------------- */
|
||||
t_buffer = NULL;
|
||||
tally_count_component = 0;
|
||||
tally_table = NULL;
|
||||
count_tally_table_columns = 0;
|
||||
count_tally_table_rows = 0;
|
||||
#endif
|
||||
//t_buffer = NULL;
|
||||
//tally_count_component = 0;
|
||||
//tally_table = NULL;
|
||||
//count_tally_table_columns = 0;
|
||||
//count_tally_table_rows = 0;
|
||||
|
||||
/* transport.cpp ------------------------------- */
|
||||
/* storage is created and freed in tranport.cpp */
|
||||
sol_D = NULL;
|
||||
@ -3080,15 +2406,14 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
int stop_calculations;
|
||||
char err_str98[80];
|
||||
#endif
|
||||
#ifdef SKIP
|
||||
/* utilities.cpp ------------------------------- */
|
||||
spinner = 0;
|
||||
// keycount;
|
||||
for (int i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++)
|
||||
{
|
||||
keycount.push_back(0);
|
||||
}
|
||||
#endif
|
||||
//spinner = 0;
|
||||
//// keycount;
|
||||
//for (int i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++)
|
||||
//{
|
||||
// keycount.push_back(0);
|
||||
//}
|
||||
|
||||
// make sure new_model gets set
|
||||
this->keycount[Keywords::KEY_SOLUTION_SPECIES] = 1;
|
||||
this->tidy_model();
|
||||
|
||||
10
Phreeqc.h
10
Phreeqc.h
@ -576,7 +576,6 @@ public:
|
||||
int setup_exchange(void);
|
||||
int setup_gas_phase(void);
|
||||
int setup_fixed_volume_gas(void);
|
||||
int setup_slack(void);
|
||||
int setup_master_rxn(struct master **master_ptr_list,
|
||||
const std::string &pe_rxn);
|
||||
int setup_pure_phases(void);
|
||||
@ -1473,7 +1472,6 @@ protected:
|
||||
struct unknown *solution_phase_boundary_unknown;
|
||||
struct unknown *surface_unknown;
|
||||
struct unknown *gas_unknown;
|
||||
struct unknown *slack_unknown;
|
||||
struct unknown *ss_unknown;
|
||||
std::vector<struct unknown *> gas_unknowns;
|
||||
|
||||
@ -1596,7 +1594,6 @@ protected:
|
||||
int mass_water_switch;
|
||||
int delay_mass_water;
|
||||
bool dampen_ah2o;
|
||||
bool slack;
|
||||
LDBLE censor;
|
||||
int aqueous_only;
|
||||
int negative_concentrations;
|
||||
@ -1676,17 +1673,14 @@ protected:
|
||||
struct system_species *sys;
|
||||
int count_sys, max_sys;
|
||||
LDBLE sys_tot;
|
||||
#ifdef PHREEQC2
|
||||
LDBLE AA_basic, BB_basic, CC, I_m, rho_0;
|
||||
LDBLE eps_r; // relative dielectric permittivity
|
||||
#else
|
||||
|
||||
LDBLE V_solutes, rho_0, kappa_0, p_sat/*, ah2o_x0*/;
|
||||
LDBLE eps_r; // relative dielectric permittivity
|
||||
LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av
|
||||
LDBLE QBrn; // Born function d(ln(eps_r))/dP / eps_r * 41.84004, for supcrt calc'n of molal volume
|
||||
LDBLE ZBrn; // Born function (-1/eps_r + 1) * 41.84004, for supcrt calc'n of molal volume
|
||||
LDBLE dgdP; // dg / dP, pressure derivative of g-function, for supcrt calc'n of molal volume
|
||||
#endif
|
||||
|
||||
int need_temp_msg;
|
||||
LDBLE solution_mass, solution_volume;
|
||||
|
||||
|
||||
233
basicsubs.cpp
233
basicsubs.cpp
@ -155,135 +155,7 @@ calc_SC(void)
|
||||
|
||||
return (SC);
|
||||
}
|
||||
#ifdef PHREEQC2
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
calc_dens(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Calculates density based on the formulas and parameters from Millero,
|
||||
* 2000.
|
||||
*
|
||||
* Millero, F.J. (2000) The equation of state of lakes. Aquatic geochemistry
|
||||
* volume 6, pages 1-17
|
||||
*/
|
||||
int i;
|
||||
/*
|
||||
LDBLE rho_0;
|
||||
LDBLE solution_mass, solution_volume;
|
||||
*/
|
||||
LDBLE rho_new, rho_old;
|
||||
LDBLE M_T;
|
||||
LDBLE a, b, c, d, e, f;
|
||||
LDBLE phi_0_i, b_v_i, s_v_i, PHI_v, B_v, S_v;
|
||||
/*
|
||||
LDBLE k, I_m, I_v;
|
||||
LDBLE AA_basic, BB, CC;
|
||||
*/
|
||||
LDBLE gfw;
|
||||
int l_z;
|
||||
struct species *s_ptr;
|
||||
|
||||
/* Density of pure water (UNESCO, 1983) */
|
||||
//rho_0 = 999.842594 + (6.793952e-2 + (-9.095290e-3 + (1.001685e-4 + (-1.120083e-6 + 6.536332e-9 * tc_x) * tc_x) * tc_x) * tc_x) * tc_x;
|
||||
//rho_0 = calc_rho_0(tc_x, patm_x); // done in k_temp
|
||||
//rho_0 /= 1000;
|
||||
s_v_i = 1.444 + (0.016799 + (-8.4055e-6 + 5.5153e-7 * tc_x) * tc_x) * tc_x;
|
||||
rho_new = rho_0;
|
||||
rho_old = 0.0;
|
||||
|
||||
M_T = 0.0;
|
||||
I_m = 0.0;
|
||||
PHI_v = 0.0;
|
||||
B_v = 0.0;
|
||||
S_v = 0.0;
|
||||
for (i = 0; i < count_species_list; i++)
|
||||
{
|
||||
if (species_list[i].s->type != AQ)
|
||||
continue;
|
||||
if (strcmp(species_list[i].s->name, "CO2") == 0)
|
||||
continue;
|
||||
|
||||
if (species_list[i].master_s->secondary != NULL)
|
||||
gfw = species_list[i].master_s->secondary->gfw;
|
||||
else
|
||||
gfw = species_list[i].master_s->primary->gfw;
|
||||
|
||||
if (species_list[i].s->millero[0] == 0)
|
||||
s_ptr = species_list[i].master_s;
|
||||
else
|
||||
s_ptr = species_list[i].s;
|
||||
|
||||
/* Special case: CO3-2 species */
|
||||
if (strcmp(s_ptr->name, "CO3-2") == 0)
|
||||
{
|
||||
if (strstr(species_list[i].s->name, "HCO3") != NULL)
|
||||
{
|
||||
s_ptr = s_search("HCO3-");
|
||||
} else if (strstr(species_list[i].s->name, "CO3") != NULL)
|
||||
{
|
||||
compute_gfw("CO3-2", &gfw);
|
||||
}
|
||||
}
|
||||
|
||||
l_z = abs((int) s_ptr->z);
|
||||
a = s_ptr->millero[0];
|
||||
b = s_ptr->millero[1];
|
||||
c = s_ptr->millero[2];
|
||||
d = s_ptr->millero[3];
|
||||
e = s_ptr->millero[4];
|
||||
f = s_ptr->millero[5];
|
||||
phi_0_i = a + (b + c * tc_x) * tc_x;
|
||||
b_v_i = d + (e + f * tc_x) * tc_x;
|
||||
|
||||
PHI_v += (species_list[i].s->moles * phi_0_i);
|
||||
B_v += (species_list[i].s->moles * b_v_i);
|
||||
S_v += (species_list[i].s->moles * l_z * (s_v_i * l_z / 2));
|
||||
M_T += (species_list[i].s->moles * gfw);
|
||||
I_m += (species_list[i].s->moles * (l_z * l_z));
|
||||
}
|
||||
|
||||
/* If pure water then return rho_0 */
|
||||
if (PHI_v == 0)
|
||||
return rho_0;
|
||||
|
||||
solution_mass = mass_water_aq_x * 1000 + M_T;
|
||||
I_m /= 2;
|
||||
AA_basic = M_T - rho_0 * PHI_v;
|
||||
BB_basic = -rho_0 * S_v;
|
||||
CC = -rho_0 * B_v;
|
||||
rho_new = halve(f_rho, 0.5, 2.0, 1e-7);
|
||||
/* DP: End Replace Pickard iteration with interval halving */
|
||||
|
||||
/*if (isnan(rho_new) || rho_new > 1.99999) rho_new = 1.99999;*/
|
||||
if (!PHR_ISFINITE(rho_new) || rho_new > 1.99999) rho_new = 1.99999;
|
||||
|
||||
return rho_new; /*(rho_new - rho_0) * 1e3; */
|
||||
}
|
||||
/* VP: Density End */
|
||||
/* DP: Function for interval halving */
|
||||
|
||||
LDBLE Phreeqc::
|
||||
f_rho(LDBLE rho_old, void *cookie)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
LDBLE rho, I_v;
|
||||
Phreeqc * pThis;
|
||||
|
||||
pThis = (Phreeqc *) cookie;
|
||||
|
||||
pThis->solution_volume = pThis->solution_mass / rho_old / 1000;
|
||||
rho = 1e3;
|
||||
if (pThis->solution_volume != 0)
|
||||
{
|
||||
I_v = pThis->I_m / pThis->solution_volume; // Ionic Strength in mol/L
|
||||
rho = (pThis->AA_basic + pThis->BB_basic * sqrt(I_v) + pThis->CC * I_v) / pThis->solution_volume;
|
||||
}
|
||||
rho = rho / 1000 + pThis->rho_0;
|
||||
return (rho - rho_old);
|
||||
}
|
||||
#else
|
||||
/* VP: Density Start */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
@ -396,7 +268,7 @@ f_rho(LDBLE rho_old, void *cookie)
|
||||
rho = rho + pThis->rho_0;
|
||||
return (rho - rho_old);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
calc_solution_volume(void)
|
||||
@ -1471,45 +1343,7 @@ sum_match_gases(const char *mytemplate, const char *name)
|
||||
}
|
||||
return (tot);
|
||||
}
|
||||
#ifdef SKIP
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
sum_match_species(const char *mytemplate, const char *name)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int i;
|
||||
LDBLE tot;
|
||||
struct elt_list *next_elt;
|
||||
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
tot = 0;
|
||||
for (i = 0; i < count_s_x; i++)
|
||||
{
|
||||
if (match_elts_in_species(s_x[i]->name, mytemplate) == TRUE)
|
||||
{
|
||||
if (name == NULL)
|
||||
{
|
||||
tot += s_x[i]->moles;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (next_elt = s_x[i]->next_elt; next_elt->elt != NULL;
|
||||
next_elt++)
|
||||
{
|
||||
if (strcmp(next_elt->elt->name, name) == 0)
|
||||
{
|
||||
tot += next_elt->coef * s_x[i]->moles;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (tot);
|
||||
}
|
||||
#else
|
||||
#ifndef SUM_SPECIES_METHOD_2
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
sum_match_species(const char *mytemplate, const char *name)
|
||||
@ -1559,73 +1393,8 @@ sum_match_species(const char *mytemplate, const char *name)
|
||||
}
|
||||
return (tot);
|
||||
}
|
||||
#else
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
sum_match_species(const char *mytemplate, const char *name)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int i;
|
||||
LDBLE tot;
|
||||
struct elt_list *next_elt;
|
||||
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
tot = 0;
|
||||
if (sum_species_map.find(mytemplate) == sum_species_map.end())
|
||||
{
|
||||
if (sum_species_map_db.find(mytemplate) == sum_species_map_db.end())
|
||||
{
|
||||
std::vector<std::string> species_list_db;
|
||||
for (i = 0; i < count_s; i++)
|
||||
{
|
||||
struct species *s_ptr = s[i];
|
||||
if (match_elts_in_species(s_ptr->name, mytemplate) == TRUE)
|
||||
{
|
||||
species_list_db.push_back(s_ptr->name);
|
||||
}
|
||||
}
|
||||
sum_species_map_db[mytemplate] = species_list_db;
|
||||
}
|
||||
std::vector<std::string> &species_list = (sum_species_map_db.find(mytemplate))->second;
|
||||
std::vector<std::string> species_list_x;
|
||||
for (size_t i=0; i < species_list.size(); i++)
|
||||
{
|
||||
struct species *s_ptr = s_search(species_list[i].c_str());
|
||||
if (s_ptr->in == TRUE)
|
||||
{
|
||||
species_list_x.push_back(species_list[i]);
|
||||
}
|
||||
}
|
||||
sum_species_map[mytemplate] = species_list_x;
|
||||
}
|
||||
std::vector<std::string> &species_list = (sum_species_map.find(mytemplate))->second;
|
||||
for (size_t i=0; i < species_list.size(); i++)
|
||||
{
|
||||
struct species *s_ptr = s_search(species_list[i].c_str());
|
||||
if (s_ptr->in == FALSE) continue;
|
||||
if (name == NULL)
|
||||
{
|
||||
tot += s_ptr->moles;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (next_elt = s_ptr->next_elt; next_elt->elt != NULL;
|
||||
next_elt++)
|
||||
{
|
||||
if (strcmp(next_elt->elt->name, name) == 0)
|
||||
{
|
||||
tot += next_elt->coef * s_ptr->moles;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (tot);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
|
||||
695
mainsubs.cpp
695
mainsubs.cpp
@ -16,702 +16,7 @@
|
||||
#if defined(WINDOWS) || defined(_WINDOWS)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifdef SKIP
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void Phreeqc::
|
||||
initialize(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Initialize global variables
|
||||
*/
|
||||
int i;
|
||||
struct logk *logk_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
|
||||
moles_per_kilogram_string = string_duplicate("Mol/kgw");
|
||||
pe_string = string_duplicate("pe");
|
||||
|
||||
debug_model = FALSE;
|
||||
debug_prep = FALSE;
|
||||
debug_set = FALSE;
|
||||
debug_diffuse_layer = FALSE;
|
||||
debug_inverse = FALSE;
|
||||
itmax = 100;
|
||||
max_tries = 1000;
|
||||
#ifdef USE_LONG_DOUBLE
|
||||
/* 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);
|
||||
#endif
|
||||
convergence_tolerance = 1e-8;
|
||||
#ifdef USE_LONG_DOUBLE
|
||||
/* from float.h, sets tolerance for cl1 routine */
|
||||
inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5);
|
||||
#else
|
||||
inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5);
|
||||
#endif
|
||||
step_size = 100.;
|
||||
pe_step_size = 10.;
|
||||
pp_scale = 1.0;
|
||||
pp_column_scale = 1.0;
|
||||
diagonal_scale = FALSE;
|
||||
censor = 0.0;
|
||||
mass_water_switch = FALSE;
|
||||
/* mass_water_switch = TRUE; */
|
||||
delay_mass_water = FALSE;
|
||||
incremental_reactions = FALSE;
|
||||
aqueous_only = 0;
|
||||
negative_concentrations = FALSE;
|
||||
|
||||
LOG_10 = log(10.0);
|
||||
/* Use space for all memory allocation */
|
||||
max_elements = MAX_ELEMENTS;
|
||||
max_elts = MAX_ELTS;
|
||||
max_line = MAX_LINE;
|
||||
max_master = MAX_MASTER;
|
||||
max_mb_unknowns = MAX_TRXN;
|
||||
max_phases = MAX_PHASES;
|
||||
max_s = MAX_S;
|
||||
max_trxn = MAX_TRXN;
|
||||
max_logk = MAX_S;
|
||||
max_master_isotope = MAX_ELTS;
|
||||
count_elements = 0;
|
||||
count_master = 0;
|
||||
count_phases = 0;
|
||||
count_s = 0;
|
||||
count_logk = 0;
|
||||
count_master_isotope = 0;
|
||||
/*
|
||||
* Initialize advection
|
||||
*/
|
||||
count_ad_cells = 1;
|
||||
count_ad_shifts = 1;
|
||||
print_ad_modulus = 1;
|
||||
punch_ad_modulus = 1;
|
||||
advection_punch = (int *) PHRQ_malloc(sizeof(int));
|
||||
if (advection_punch == NULL)
|
||||
malloc_error();
|
||||
advection_punch[0] = TRUE;
|
||||
advection_kin_time = 0.0;
|
||||
advection_kin_time_defined = FALSE;
|
||||
advection_print = (int *) PHRQ_malloc(sizeof(int));
|
||||
if (advection_print == NULL)
|
||||
malloc_error();
|
||||
advection_print[0] = TRUE;
|
||||
advection_warnings = TRUE;
|
||||
/*
|
||||
* Initialize transport
|
||||
*/
|
||||
count_cells = 1;
|
||||
count_shifts = 1;
|
||||
ishift = 1;
|
||||
bcon_first = bcon_last = 3;
|
||||
diffc = 0.3e-9;
|
||||
simul_tr = 0;
|
||||
tempr = 2.0;
|
||||
heat_diffc = -0.1;
|
||||
timest = 0.0;
|
||||
multi_Dflag = FALSE;
|
||||
interlayer_Dflag = FALSE;
|
||||
interlayer_tortf = 100.0;
|
||||
interlayer_Dpor = 0.1;
|
||||
/* !!!! count_stag = 0; */
|
||||
mcd_substeps = 1.0;
|
||||
print_modulus = 1;
|
||||
punch_modulus = 1;
|
||||
dump_modulus = 0;
|
||||
dump_in = FALSE;
|
||||
transport_warnings = TRUE;
|
||||
/*
|
||||
* Allocate space
|
||||
*/
|
||||
|
||||
space((void **) ((void *) &cell_data), INIT, &count_cells,
|
||||
sizeof(struct cell_data));
|
||||
|
||||
space((void **) ((void *) &elements), INIT, &max_elements,
|
||||
sizeof(struct element *));
|
||||
|
||||
space((void **) ((void *) &elt_list), INIT, &max_elts,
|
||||
sizeof(struct elt_list));
|
||||
|
||||
inverse = (struct inverse *) PHRQ_malloc((size_t) sizeof(struct inverse));
|
||||
if (inverse == NULL)
|
||||
malloc_error();
|
||||
count_inverse = 0;
|
||||
space((void **) ((void *) &line), INIT, &max_line, sizeof(char));
|
||||
|
||||
space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char));
|
||||
|
||||
space((void **) ((void *) &master), INIT, &max_master,
|
||||
sizeof(struct master *));
|
||||
|
||||
space((void **) ((void *) &mb_unknowns), INIT, &max_mb_unknowns,
|
||||
sizeof(struct unknown_list));
|
||||
|
||||
/* !!!! */
|
||||
stag_data = (struct stag_data *) PHRQ_calloc(1, sizeof(struct stag_data));
|
||||
if (stag_data == NULL)
|
||||
malloc_error();
|
||||
stag_data->count_stag = 0;
|
||||
stag_data->exch_f = 0;
|
||||
stag_data->th_m = 0;
|
||||
stag_data->th_im = 0;
|
||||
|
||||
space((void **) ((void *) &phases), INIT, &max_phases,
|
||||
sizeof(struct phase *));
|
||||
|
||||
space((void **) ((void *) &trxn.token), INIT, &max_trxn,
|
||||
sizeof(struct rxn_token_temp));
|
||||
|
||||
space((void **) ((void *) &s), INIT, &max_s, sizeof(struct species *));
|
||||
|
||||
space((void **) ((void *) &logk), INIT, &max_logk, sizeof(struct logk *));
|
||||
|
||||
space((void **) ((void *) &master_isotope), INIT, &max_master_isotope,
|
||||
sizeof(struct master_isotope *));
|
||||
title_x = NULL;
|
||||
description_x = NULL;
|
||||
units_x = NULL;
|
||||
s_x = NULL;
|
||||
/* SRC ADDED */
|
||||
sum_mb1 = NULL;
|
||||
sum_mb2 = NULL;
|
||||
sum_jacob0 = NULL;
|
||||
sum_jacob1 = NULL;
|
||||
sum_jacob2 = NULL;
|
||||
sum_delta = NULL;
|
||||
/* SRC ADDED */
|
||||
x = NULL;
|
||||
max_unknowns = 0;
|
||||
|
||||
array = NULL;
|
||||
delta = NULL;
|
||||
residual = NULL;
|
||||
s_h2o = NULL;
|
||||
s_hplus = NULL;
|
||||
s_h3oplus = NULL;
|
||||
s_eminus = NULL;
|
||||
s_co3 = NULL;
|
||||
s_h2 = NULL;
|
||||
s_o2 = NULL;
|
||||
|
||||
hcreate_multi((unsigned) max_logk, &logk_hash_table);
|
||||
hcreate_multi((unsigned) max_master_isotope, &master_isotope_hash_table);
|
||||
/*
|
||||
* Create hash tables
|
||||
*/
|
||||
hcreate_multi((unsigned) max_elements, &elements_hash_table);
|
||||
hcreate_multi((unsigned) max_s, &species_hash_table);
|
||||
hcreate_multi((unsigned) max_phases, &phases_hash_table);
|
||||
/*
|
||||
* Initialize punch
|
||||
*/
|
||||
punch.in = FALSE;
|
||||
punch.new_def = FALSE;
|
||||
punch.count_totals = 0;
|
||||
punch.totals =
|
||||
(struct name_master *) PHRQ_malloc(sizeof(struct name_master));
|
||||
if (punch.totals == NULL)
|
||||
malloc_error();
|
||||
punch.count_molalities = 0;
|
||||
punch.molalities =
|
||||
(struct name_species *) PHRQ_malloc(sizeof(struct name_species));
|
||||
if (punch.molalities == NULL)
|
||||
malloc_error();
|
||||
punch.count_activities = 0;
|
||||
punch.activities =
|
||||
(struct name_species *) PHRQ_malloc(sizeof(struct name_species));
|
||||
if (punch.activities == NULL)
|
||||
malloc_error();
|
||||
punch.count_pure_phases = 0;
|
||||
punch.pure_phases =
|
||||
(struct name_phase *) PHRQ_malloc(sizeof(struct name_phase));
|
||||
if (punch.pure_phases == NULL)
|
||||
malloc_error();
|
||||
punch.count_si = 0;
|
||||
punch.si = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase));
|
||||
if (punch.si == NULL)
|
||||
malloc_error();
|
||||
punch.count_gases = 0;
|
||||
punch.gases =
|
||||
(struct name_phase *) PHRQ_malloc(sizeof(struct name_phase));
|
||||
if (punch.gases == NULL)
|
||||
malloc_error();
|
||||
punch.count_s_s = 0;
|
||||
punch.s_s = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase));
|
||||
if (punch.s_s == NULL)
|
||||
malloc_error();
|
||||
|
||||
punch.count_kinetics = 0;
|
||||
punch.kinetics =
|
||||
(struct name_phase *) PHRQ_malloc(sizeof(struct name_phase));
|
||||
if (punch.kinetics == NULL)
|
||||
malloc_error();
|
||||
|
||||
punch.count_isotopes = 0;
|
||||
punch.isotopes =
|
||||
(struct name_master *) PHRQ_malloc(sizeof(struct name_master));
|
||||
if (punch.isotopes == NULL)
|
||||
malloc_error();
|
||||
|
||||
punch.count_calculate_values = 0;
|
||||
punch.calculate_values =
|
||||
(struct name_master *) PHRQ_malloc(sizeof(struct name_master));
|
||||
if (punch.calculate_values == NULL)
|
||||
malloc_error();
|
||||
|
||||
count_save_values = 0;
|
||||
save_values =
|
||||
(struct save_values *) PHRQ_malloc(sizeof(struct save_values));
|
||||
if (save_values == NULL)
|
||||
malloc_error();
|
||||
|
||||
punch.inverse = TRUE;
|
||||
|
||||
punch.sim = TRUE;
|
||||
punch.state = TRUE;
|
||||
punch.soln = TRUE;
|
||||
punch.dist = TRUE;
|
||||
punch.time = TRUE;
|
||||
punch.step = TRUE;
|
||||
punch.rxn = FALSE;
|
||||
punch.temp = FALSE;
|
||||
punch.ph = TRUE;
|
||||
punch.pe = TRUE;
|
||||
punch.alk = FALSE;
|
||||
punch.mu = FALSE;
|
||||
punch.water = FALSE;
|
||||
punch.high_precision = FALSE;
|
||||
punch.user_punch = TRUE;
|
||||
punch.charge_balance = FALSE;
|
||||
punch.percent_error = FALSE;
|
||||
/*
|
||||
* last model
|
||||
*/
|
||||
last_model.force_prep = TRUE;
|
||||
last_model.temperature = -100;
|
||||
last_model.pressure = 0;
|
||||
last_model.count_exchange = -1;
|
||||
last_model.exchange = NULL;
|
||||
last_model.count_kinetics = -1;
|
||||
last_model.kinetics = NULL;
|
||||
last_model.count_gas_phase = -1;
|
||||
last_model.gas_phase = NULL;
|
||||
last_model.count_ss_assemblage = -1;
|
||||
last_model.ss_assemblage = NULL;
|
||||
last_model.count_pp_assemblage = -1;
|
||||
last_model.pp_assemblage = NULL;
|
||||
last_model.add_formula = NULL;
|
||||
last_model.si = NULL;
|
||||
last_model.dl_type = cxxSurface::NO_DL;
|
||||
last_model.surface_type = cxxSurface::UNKNOWN_DL;
|
||||
last_model.only_counter_ions = FALSE;
|
||||
last_model.thickness = 1e-8;
|
||||
last_model.count_surface_comp = -1;
|
||||
last_model.surface_comp = NULL;
|
||||
last_model.count_surface_charge = -1;
|
||||
last_model.surface_charge = NULL;
|
||||
/*
|
||||
* rates
|
||||
*/
|
||||
rates = (struct rate *) PHRQ_malloc(sizeof(struct rate));
|
||||
if (rates == NULL)
|
||||
malloc_error();
|
||||
count_rates = 0;
|
||||
initial_total_time = 0;
|
||||
rate_m = 0;
|
||||
rate_m0 = 0;
|
||||
rate_time = 0;
|
||||
rate_sim_time_start = 0;
|
||||
rate_sim_time_end = 0;
|
||||
rate_sim_time = 0;
|
||||
rate_moles = 0;
|
||||
/*
|
||||
* user_print, user_punch
|
||||
*/
|
||||
user_print = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate));
|
||||
if (user_print == NULL)
|
||||
malloc_error();
|
||||
user_print->commands = NULL;
|
||||
user_print->linebase = NULL;
|
||||
user_print->varbase = NULL;
|
||||
user_print->loopbase = NULL;
|
||||
user_punch = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate));
|
||||
if (user_punch == NULL)
|
||||
malloc_error();
|
||||
user_punch->commands = NULL;
|
||||
user_punch->linebase = NULL;
|
||||
user_punch->varbase = NULL;
|
||||
user_punch->loopbase = NULL;
|
||||
user_punch_headings = (const char **) PHRQ_malloc(sizeof(char *));
|
||||
if (user_punch_headings == NULL)
|
||||
malloc_error();
|
||||
user_punch_count_headings = 0;
|
||||
#if defined PHREEQ98
|
||||
/*
|
||||
* user_graph
|
||||
*/
|
||||
user_graph = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate));
|
||||
if (user_graph == NULL)
|
||||
malloc_error();
|
||||
user_graph->commands = NULL;
|
||||
user_graph->linebase = NULL;
|
||||
user_graph->varbase = NULL;
|
||||
user_graph->loopbase = NULL;
|
||||
user_graph_headings = (char **) PHRQ_malloc(sizeof(char *));
|
||||
if (user_graph_headings == NULL)
|
||||
malloc_error();
|
||||
user_graph_count_headings = 0;
|
||||
#endif
|
||||
/*
|
||||
Initialize llnl aqueous model parameters
|
||||
*/
|
||||
llnl_temp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
|
||||
if (llnl_temp == NULL)
|
||||
malloc_error();
|
||||
llnl_count_temp = 0;
|
||||
llnl_adh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
|
||||
if (llnl_adh == NULL)
|
||||
malloc_error();
|
||||
llnl_count_adh = 0;
|
||||
llnl_bdh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
|
||||
if (llnl_bdh == NULL)
|
||||
malloc_error();
|
||||
llnl_count_bdh = 0;
|
||||
llnl_bdot = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
|
||||
if (llnl_bdot == NULL)
|
||||
malloc_error();
|
||||
llnl_count_bdot = 0;
|
||||
llnl_co2_coefs = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
|
||||
if (llnl_co2_coefs == NULL)
|
||||
malloc_error();
|
||||
llnl_count_co2_coefs = 0;
|
||||
/*
|
||||
*
|
||||
*/
|
||||
basic_interpreter = new PBasic(this, phrq_io);
|
||||
|
||||
change_surf =
|
||||
(struct Change_Surf *)
|
||||
PHRQ_malloc((size_t) (2 * sizeof(struct Change_Surf)));
|
||||
if (change_surf == NULL)
|
||||
malloc_error();
|
||||
change_surf[0].cell_no = -99;
|
||||
change_surf[0].next = TRUE;
|
||||
change_surf[1].cell_no = -99;
|
||||
change_surf[1].next = FALSE;
|
||||
change_surf_count = 0;
|
||||
|
||||
|
||||
#if defined(WINDOWS) || defined(_WINDOWS)
|
||||
/* SRC pr.status = FALSE; */
|
||||
#endif
|
||||
/* Initialize print here, not in global.h */
|
||||
pr.all = TRUE;
|
||||
pr.initial_solutions = TRUE;
|
||||
pr.initial_exchangers = TRUE;
|
||||
pr.reactions = TRUE;
|
||||
pr.gas_phase = TRUE;
|
||||
pr.ss_assemblage = TRUE;
|
||||
pr.pp_assemblage = TRUE;
|
||||
pr.surface = TRUE;
|
||||
pr.exchange = TRUE;
|
||||
pr.kinetics = TRUE;
|
||||
pr.totals = TRUE;
|
||||
pr.eh = TRUE;
|
||||
pr.species = TRUE;
|
||||
pr.saturation_indices = TRUE;
|
||||
pr.irrev = TRUE;
|
||||
pr.mix = TRUE;
|
||||
pr.reaction = TRUE;
|
||||
pr.use = TRUE;
|
||||
pr.logfile = FALSE;
|
||||
pr.punch = TRUE;
|
||||
if (phast == TRUE)
|
||||
{
|
||||
pr.status = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
pr.status = TRUE;
|
||||
}
|
||||
pr.inverse = TRUE;
|
||||
pr.dump = TRUE;
|
||||
pr.user_print = TRUE;
|
||||
pr.headings = TRUE;
|
||||
pr.user_graph = TRUE;
|
||||
pr.echo_input = TRUE;
|
||||
count_warnings = 0;
|
||||
pr.warnings = 100;
|
||||
pr.initial_isotopes = TRUE;
|
||||
pr.isotope_ratios = TRUE;
|
||||
pr.isotope_alphas = TRUE;
|
||||
pr.hdf = FALSE;
|
||||
pr.alkalinity = FALSE;
|
||||
species_list = NULL;
|
||||
|
||||
user_database = NULL;
|
||||
first_read_input = TRUE;
|
||||
have_punch_name = FALSE;
|
||||
selected_output_file_name = NULL;
|
||||
dump_file_name = NULL;
|
||||
|
||||
#ifdef PHREEQCI_GUI
|
||||
g_spread_sheet.heading = NULL;
|
||||
g_spread_sheet.units = NULL;
|
||||
g_spread_sheet.count_rows = 0;
|
||||
g_spread_sheet.rows = NULL;
|
||||
g_spread_sheet.defaults.units = NULL;
|
||||
g_spread_sheet.defaults.count_iso = 0;
|
||||
g_spread_sheet.defaults.iso = NULL;
|
||||
g_spread_sheet.defaults.redox = NULL;
|
||||
#endif
|
||||
|
||||
/* calculate_value */
|
||||
max_calculate_value = MAX_ELTS;
|
||||
count_calculate_value = 0;
|
||||
space((void **) ((void *) &calculate_value), INIT, &max_calculate_value,
|
||||
sizeof(struct calculate_value *));
|
||||
hcreate_multi((unsigned) max_calculate_value,
|
||||
&calculate_value_hash_table);
|
||||
|
||||
/* isotope_ratio */
|
||||
max_isotope_ratio = MAX_ELTS;
|
||||
count_isotope_ratio = 0;
|
||||
space((void **) ((void *) &isotope_ratio), INIT, &max_isotope_ratio,
|
||||
sizeof(struct isotope_ratio *));
|
||||
hcreate_multi((unsigned) max_isotope_ratio, &isotope_ratio_hash_table);
|
||||
|
||||
/* isotope_value */
|
||||
max_isotope_alpha = MAX_ELTS;
|
||||
count_isotope_alpha = 0;
|
||||
space((void **) ((void *) &isotope_alpha), INIT, &max_isotope_alpha,
|
||||
sizeof(struct isotope_alpha *));
|
||||
hcreate_multi((unsigned) max_isotope_alpha, &isotope_alpha_hash_table);
|
||||
|
||||
/*
|
||||
* define constant named log_k
|
||||
*/
|
||||
strcpy(token, "XconstantX");
|
||||
logk_ptr = logk_store(token, TRUE);
|
||||
strcpy(token, "1.0");
|
||||
read_log_k_only(token, &logk_ptr->log_k[0]);
|
||||
|
||||
phreeqc_mpi_myself = 0;
|
||||
|
||||
copier_init(©_solution);
|
||||
copier_init(©_pp_assemblage);
|
||||
copier_init(©_exchange);
|
||||
copier_init(©_surface);
|
||||
copier_init(©_ss_assemblage);
|
||||
copier_init(©_gas_phase);
|
||||
copier_init(©_kinetics);
|
||||
copier_init(©_mix);
|
||||
copier_init(©_reaction);
|
||||
copier_init(©_temperature);
|
||||
copier_init(©_pressure);
|
||||
|
||||
set_forward_output_to_log(FALSE);
|
||||
simulation = 0;
|
||||
/*
|
||||
* cvode
|
||||
*/
|
||||
|
||||
cvode_init();
|
||||
/*
|
||||
* Pitzer
|
||||
*/
|
||||
pitzer_init();
|
||||
/*
|
||||
* SIT
|
||||
*/
|
||||
sit_init();
|
||||
/*
|
||||
* to facilitate debuging
|
||||
*/
|
||||
dbg_master = master;
|
||||
calculating_deriv = FALSE;
|
||||
numerical_deriv = FALSE;
|
||||
|
||||
zeros = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
|
||||
if (zeros == NULL)
|
||||
malloc_error();
|
||||
zeros[0] = 0.0;
|
||||
zeros_max = 1;
|
||||
|
||||
cell_pore_volume = 0;
|
||||
cell_volume = 0;
|
||||
cell_porosity = 0;
|
||||
cell_saturation = 0;
|
||||
|
||||
print_density = 0;
|
||||
|
||||
same_model = FALSE;
|
||||
current_tc = NAN;
|
||||
current_pa = NAN;
|
||||
current_mu = NAN;
|
||||
mu_terms_in_logk = true;
|
||||
|
||||
g_iterations = -1;
|
||||
G_TOL = 1e-8;
|
||||
save_init(-1);
|
||||
count_species_list = 0;
|
||||
max_species_list = 0;
|
||||
count_sum_jacob0 = 0;
|
||||
max_sum_jacob0 = 0;
|
||||
count_sum_mb1 = 0;
|
||||
max_sum_mb1 = 0;
|
||||
count_sum_jacob1 = 0;
|
||||
max_sum_jacob1 = 0;
|
||||
count_sum_mb2 = 0;
|
||||
max_sum_mb2 = 0;
|
||||
count_sum_jacob2 = 0;
|
||||
max_sum_jacob2 = 0;
|
||||
count_sum_delta = 0;
|
||||
max_sum_delta = 0;
|
||||
new_x = FALSE;
|
||||
tc_x = 0;
|
||||
tk_x = 0;
|
||||
ph_x = 0;
|
||||
solution_pe_x = 0;
|
||||
mu_x = 0;
|
||||
density_x = 0;
|
||||
total_h_x = 0;
|
||||
total_o_x = 0;
|
||||
cb_x = 0;
|
||||
total_ions_x = 0;
|
||||
mass_water_aq_x = 0;
|
||||
mass_water_surfaces_x = 0;
|
||||
mass_water_bulk_x = 0;
|
||||
dl_type_x = cxxSurface::NO_DL;
|
||||
total_carbon = 0;
|
||||
total_co2 = 0;
|
||||
total_alkalinity = 0;
|
||||
gfw_water = 0;
|
||||
step_x = 0;
|
||||
kin_time_x = 0;
|
||||
correct_disp = FALSE;
|
||||
cell = 0;
|
||||
multi_Dflag = FALSE;
|
||||
interlayer_Dflag = FALSE;
|
||||
default_Dw = 0;
|
||||
multi_Dpor = 0;
|
||||
interlayer_Dpor = 0.1;
|
||||
multi_Dpor_lim = 0;
|
||||
interlayer_Dpor_lim = 0;
|
||||
multi_Dn = 0;
|
||||
interlayer_tortf = 100;
|
||||
cell_no = 0;
|
||||
new_model = TRUE;
|
||||
new_exchange = FALSE;
|
||||
new_pp_assemblage = FALSE;
|
||||
new_surface = FALSE;
|
||||
new_reaction = FALSE;
|
||||
new_temperature = FALSE;
|
||||
new_mix = FALSE;
|
||||
new_solution = FALSE;
|
||||
new_gas_phase = FALSE;
|
||||
new_inverse = FALSE;
|
||||
new_punch = FALSE;
|
||||
new_ss_assemblage = FALSE;
|
||||
new_kinetics = FALSE;
|
||||
new_copy = FALSE;
|
||||
new_pitzer = FALSE;
|
||||
element_h_one = NULL;
|
||||
count_elts = 0;
|
||||
count_s_x = 0;
|
||||
max_s_x = 0;
|
||||
count_unknowns = 0;
|
||||
ah2o_unknown = NULL;
|
||||
alkalinity_unknown = NULL;
|
||||
carbon_unknown = NULL;
|
||||
charge_balance_unknown = NULL;
|
||||
exchange_unknown = NULL;
|
||||
mass_hydrogen_unknown = NULL;
|
||||
mass_oxygen_unknown = NULL;
|
||||
mb_unknown = NULL;
|
||||
mu_unknown = NULL;
|
||||
pe_unknown = NULL;
|
||||
ph_unknown = NULL;
|
||||
pure_phase_unknown = NULL;
|
||||
solution_phase_boundary_unknown = NULL;
|
||||
surface_unknown = NULL;
|
||||
gas_unknown = NULL;
|
||||
ss_unknown = NULL;
|
||||
for (i = 0; i < MAX_LOG_K_INDICES; i++)
|
||||
{
|
||||
trxn.logk[i] = 0;
|
||||
}
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
trxn.dz[i] = 0;
|
||||
}
|
||||
count_trxn = 0;
|
||||
count_mb_unknowns = 0;
|
||||
status_on = true;
|
||||
status_timer = clock();
|
||||
status_interval = 0;
|
||||
count_rate_p = 0;
|
||||
reaction_step = 0;
|
||||
transport_step = 0;
|
||||
transport_start = 0;
|
||||
advection_step = 0;
|
||||
stop_program = FALSE;
|
||||
count_strings = 0;
|
||||
input_error = 0;
|
||||
parse_error = 0;
|
||||
paren_count = 0;
|
||||
iterations = 0;
|
||||
gamma_iterations = 0;
|
||||
run_reactions_iterations = 0;
|
||||
step_size_now = step_size;
|
||||
dampen_ah2o = false;
|
||||
slack = false;
|
||||
numerical_fixed_volume = false;
|
||||
force_numerical_fixed_volume = false;
|
||||
switch_numerical = false;
|
||||
pe_step_size_now = pe_step_size;
|
||||
count_total_steps = 0;
|
||||
remove_unstable_phases = FALSE;
|
||||
//for (i = 0; i < 50; i++)
|
||||
//{
|
||||
// match_tokens[i].name = NULL;
|
||||
// match_tokens[i].coef = 0;
|
||||
//}
|
||||
//count_match_tokens = 0;
|
||||
initial_solution_isotopes = FALSE;
|
||||
full_pitzer = FALSE;
|
||||
always_full_pitzer = FALSE;
|
||||
IC = -1;
|
||||
COSMOT = 0;
|
||||
AW = 0;
|
||||
sys = NULL;
|
||||
count_sys = 0;
|
||||
max_sys = 0;
|
||||
sys_tot = 0;
|
||||
#ifdef PHREEQC2
|
||||
AA_basic = 0;
|
||||
BB_basic = 0;
|
||||
CC = 0;
|
||||
I_m = 0;
|
||||
eps_r = EPSILON;
|
||||
#endif
|
||||
rho_0 = 0;
|
||||
need_temp_msg = 0;
|
||||
solution_mass = 0;
|
||||
solution_volume = 0;
|
||||
|
||||
patm_x = 1; /* Initialize pressure of component x to 1 atm */
|
||||
ah2o_x = 1.0;
|
||||
|
||||
/* model_min_value = 0; */
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void Phreeqc::
|
||||
initialize(void)
|
||||
|
||||
88
model.cpp
88
model.cpp
@ -576,40 +576,11 @@ gammas(LDBLE mu)
|
||||
/*
|
||||
* compute temperature dependence of a and b for debye-huckel
|
||||
*/
|
||||
#ifdef PHREEQC2
|
||||
LDBLE s1, s2, s3;
|
||||
s1 = 374.11 - tc_x;
|
||||
s2 = pow(s1, (LDBLE) 1.0 / (LDBLE) 3.0);
|
||||
s3 = 1.0 + 0.1342489 * s2 - 3.946263e-03 * s1;
|
||||
s3 = s3 / (3.1975 - 0.3151548 * s2 - 1.203374e-03 * s1 +
|
||||
7.48908e-13 * (s1 * s1 * s1 * s1));
|
||||
s3 = sqrt(s3);
|
||||
if (tk_x >= 373.15)
|
||||
{
|
||||
c1 = 5321.0 / tk_x + 233.76 -
|
||||
tk_x * (tk_x * (8.292e-07 * tk_x - 1.417e-03) + 0.9297);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* replaced by wateq4f expression
|
||||
c1=87.74-tc_x*(tc_x*(1.41e-06*tc_x-9.398e-04)+0.4008);
|
||||
*/
|
||||
c1 = 2727.586 + 0.6224107 * tk_x - 466.9151 * log(tk_x) -
|
||||
52000.87 / tk_x;
|
||||
}
|
||||
c1 = sqrt(c1 * tk_x);
|
||||
/* replaced by wateq4f expressions
|
||||
a=1824600.0*s3/(c1 * c1 * c1);
|
||||
b=50.29*s3/c1;
|
||||
*/
|
||||
a = 1824827.7 * s3 / (c1 * c1 * c1);
|
||||
b = 50.2905 * s3 / c1;
|
||||
#else
|
||||
// a and b are calc'd in calc_dielectrics(tc_x, patm_x);
|
||||
k_temp(tc_x, patm_x);
|
||||
a = DH_A;
|
||||
b = DH_B;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* LLNL temperature dependence
|
||||
*/
|
||||
@ -1008,37 +979,7 @@ ineq(int in_kode)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Slack unknown
|
||||
*/
|
||||
|
||||
if (slack && slack_unknown)
|
||||
{
|
||||
int n = slack_unknown->number;
|
||||
// slack row
|
||||
for (j = 0; j <= count_unknowns + 1; j++)
|
||||
{
|
||||
array[n * (count_unknowns + 1) + j] = 0.0;
|
||||
}
|
||||
// slack column
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
array[j * (count_unknowns + 1) + n] = 1.0;
|
||||
}
|
||||
}
|
||||
#ifdef SKIP
|
||||
if (slack && slack_unknown)
|
||||
{
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
if (x[j]->type == SLACK)
|
||||
{
|
||||
array[j * (count_unknowns + 1) + x[j]->number] = 1.0;
|
||||
array[x[j]->mb_number * (count_unknowns + 1) + x[j]->number] = 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Initialize space if necessary
|
||||
*/
|
||||
@ -1172,17 +1113,6 @@ ineq(int in_kode)
|
||||
{
|
||||
if (iterations < aqueous_only)
|
||||
continue;
|
||||
/*
|
||||
* slack
|
||||
*/
|
||||
if (slack && slack_unknown && x[i]->type == SLACK)
|
||||
{
|
||||
memcpy((void *) &(ineq_array[l_count_rows * max_column_count]),
|
||||
(void *) &(array[i * (count_unknowns + 1)]),
|
||||
(size_t) (count_unknowns + 1) * sizeof(LDBLE));
|
||||
back_eq[l_count_rows] = i;
|
||||
l_count_rows++;
|
||||
}
|
||||
/*
|
||||
* Pure phases
|
||||
*/
|
||||
@ -1309,7 +1239,6 @@ ineq(int in_kode)
|
||||
x[i]->type != ALK &&
|
||||
x[i]->type != GAS_MOLES && x[i]->type != SS_MOLES
|
||||
/* && x[i]->type != PP */
|
||||
&& x[i]->type != SLACK
|
||||
)
|
||||
{
|
||||
if (x[i]->type == PP && !comp_ptr->Get_force_equality())
|
||||
@ -4455,11 +4384,8 @@ set(int initial)
|
||||
|
||||
tc_x = solution_ptr->Get_tc();
|
||||
tk_x = tc_x + 273.15;
|
||||
#ifdef PHREEQC2
|
||||
|
||||
patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa)
|
||||
#else
|
||||
patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* H+, e-, H2O
|
||||
@ -4777,11 +4703,7 @@ sum_species(void)
|
||||
ph_x = -s_hplus->la;
|
||||
solution_pe_x = -s_eminus->la;
|
||||
ah2o_x = exp(s_h2o->la * LOG_10);
|
||||
#ifdef PHREEQC2
|
||||
ah2o_x = exp(s_h2o->la * LOG_10);
|
||||
#else
|
||||
//ah2o_x = exp(s_h2o->la * LOG_10);
|
||||
#endif
|
||||
|
||||
density_x = 1.0;
|
||||
if (s_o2 != NULL)
|
||||
s_o2->moles = under(s_o2->lm) * mass_water_aq_x;
|
||||
@ -5000,9 +4922,7 @@ surface_model(void)
|
||||
debug_model = TRUE;
|
||||
debug_diffuse_layer = TRUE;
|
||||
}
|
||||
#ifdef PHREEQC2
|
||||
k_temp(tc_x, patm_x);
|
||||
#endif
|
||||
|
||||
gammas(mu_x);
|
||||
molalities(TRUE);
|
||||
mb_sums();
|
||||
|
||||
@ -1384,11 +1384,9 @@ set_pz(int initial)
|
||||
|
||||
tc_x = solution_ptr->Get_tc();
|
||||
tk_x = tc_x + 273.15;
|
||||
#ifdef PHREEQC2
|
||||
|
||||
patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa)
|
||||
#else
|
||||
patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* H+, e-, H2O
|
||||
*/
|
||||
|
||||
402
prep.cpp
402
prep.cpp
@ -71,7 +71,6 @@ prep(void)
|
||||
setup_gas_phase();
|
||||
setup_ss_assemblage();
|
||||
setup_related_surface();
|
||||
setup_slack();
|
||||
tidy_redox();
|
||||
if (get_input_errors() > 0)
|
||||
{
|
||||
@ -2029,161 +2028,7 @@ convert_units(cxxSolution *solution_ptr)
|
||||
|
||||
return (OK);
|
||||
}
|
||||
#ifdef SKIP
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
convert_units(struct solution *solution_ptr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Converts solution concentrations to moles/kg water
|
||||
* Uses totals.input conc to calculate totals.moles.
|
||||
*/
|
||||
int i, l;
|
||||
LDBLE sum_solutes;
|
||||
char c;
|
||||
struct master *master_ptr;
|
||||
struct conc *tot_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
/*
|
||||
* Convert units
|
||||
*/
|
||||
sum_solutes = exp(-solution_ptr->ph * LOG_10);
|
||||
for (i = 0; solution_ptr->totals[i].description != NULL; i++)
|
||||
{
|
||||
master_ptr = master_bsearch(solution_ptr->totals[i].description);
|
||||
if (master_ptr != NULL)
|
||||
{
|
||||
if (master_ptr->minor_isotope == TRUE)
|
||||
continue;
|
||||
}
|
||||
tot_ptr = &(solution_ptr->totals[i]);
|
||||
tot_ptr->moles = 0.0;
|
||||
if (strcmp(tot_ptr->description, "H(1)") == 0 ||
|
||||
strcmp(tot_ptr->description, "E") == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (tot_ptr->input_conc <= 0)
|
||||
continue;
|
||||
/*
|
||||
* Get gfw
|
||||
*/
|
||||
/* use given gfw if gfw > 0.0 */
|
||||
/* use formula give with "as" */
|
||||
if (tot_ptr->gfw <= 0.0)
|
||||
{
|
||||
if (tot_ptr->as != NULL)
|
||||
{
|
||||
/* use given chemical formula to calculate gfw */
|
||||
if (compute_gfw(tot_ptr->as, &(tot_ptr->gfw)) == ERROR)
|
||||
{
|
||||
error_string = sformatf( "Could not compute gfw, %s.",
|
||||
tot_ptr->as);
|
||||
error_msg(error_string, CONTINUE);
|
||||
input_error++;
|
||||
}
|
||||
if (strcmp(tot_ptr->description, "Alkalinity") == 0 &&
|
||||
strcmp(tot_ptr->as, "CaCO3") == 0)
|
||||
{
|
||||
tot_ptr->gfw /= 2.;
|
||||
error_string = sformatf(
|
||||
"Equivalent wt for alkalinity should be Ca.5(CO3).5. Using %g g/eq.",
|
||||
(double) tot_ptr->gfw);
|
||||
warning_msg(error_string);
|
||||
}
|
||||
/* use gfw of master species */
|
||||
}
|
||||
else
|
||||
{
|
||||
char * temp_desc = string_duplicate(tot_ptr->description);
|
||||
char *ptr = temp_desc;
|
||||
copy_token(token, &ptr, &l);
|
||||
master_ptr = master_bsearch(token);
|
||||
free_check_null(temp_desc);
|
||||
if (master_ptr != NULL)
|
||||
{
|
||||
/* use gfw for element redox state */
|
||||
tot_ptr->gfw = master_ptr->gfw;
|
||||
}
|
||||
else
|
||||
{
|
||||
error_string = sformatf( "Could not find gfw, %s.",
|
||||
tot_ptr->description);
|
||||
error_msg(error_string, CONTINUE);
|
||||
input_error++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Convert liters to kg solution
|
||||
*/
|
||||
tot_ptr->moles = tot_ptr->input_conc;
|
||||
if (strstr(solution_ptr->units, "/l") != NULL)
|
||||
{
|
||||
tot_ptr->moles *= 1.0 / (solution_ptr->density);
|
||||
}
|
||||
/*
|
||||
* Convert milli or micro
|
||||
*/
|
||||
c = tot_ptr->units[0];
|
||||
if (c == 'm')
|
||||
{
|
||||
tot_ptr->moles *= 1e-3;
|
||||
}
|
||||
else if (c == 'u')
|
||||
{
|
||||
tot_ptr->moles *= 1e-6;
|
||||
}
|
||||
/*
|
||||
* Sum grams of solute, convert from moles necessary
|
||||
*/
|
||||
if (strstr(tot_ptr->units, "g/kgs") != NULL ||
|
||||
strstr(tot_ptr->units, "g/l") != NULL)
|
||||
{
|
||||
sum_solutes += tot_ptr->moles;
|
||||
}
|
||||
else if (strstr(tot_ptr->units, "Mol/kgs") != NULL ||
|
||||
strstr(tot_ptr->units, "Mol/l") != NULL ||
|
||||
strstr(tot_ptr->units, "eq/l") != NULL)
|
||||
{
|
||||
sum_solutes += (tot_ptr->moles) * (tot_ptr->gfw);
|
||||
}
|
||||
/*
|
||||
* Convert grams to moles, if necessary
|
||||
*/
|
||||
if (strstr(tot_ptr->units, "g/") != NULL && tot_ptr->gfw != 0.0)
|
||||
{
|
||||
tot_ptr->moles /= tot_ptr->gfw;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Convert /kgs to /kgw
|
||||
*/
|
||||
if (strstr(solution_ptr->units, "kgs") != NULL ||
|
||||
strstr(solution_ptr->units, "/l") != NULL)
|
||||
{
|
||||
mass_water_aq_x = 1.0 - 1e-3 * sum_solutes;
|
||||
for (i = 0; solution_ptr->totals[i].description != NULL; i++)
|
||||
{
|
||||
solution_ptr->totals[i].moles /= mass_water_aq_x;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Scale by mass of water in solution
|
||||
*/
|
||||
mass_water_aq_x = solution_ptr->mass_water;
|
||||
for (i = 0; solution_ptr->totals[i].description != NULL; i++)
|
||||
{
|
||||
solution_ptr->totals[i].moles *= mass_water_aq_x;
|
||||
}
|
||||
|
||||
solution_ptr->units = moles_per_kilogram_string;
|
||||
|
||||
return (OK);
|
||||
}
|
||||
#endif
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct master ** Phreeqc::
|
||||
get_list_master_ptrs(char *ptr, struct master *master_ptr)
|
||||
@ -3428,64 +3273,7 @@ setup_gas_phase(void)
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
setup_slack(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Fill in data for slack unknown
|
||||
*/
|
||||
slack_unknown = NULL;
|
||||
if (slack)
|
||||
{
|
||||
x[count_unknowns]->type = SLACK;
|
||||
x[count_unknowns]->description = string_hsave("slack");
|
||||
x[count_unknowns]->moles = 0.0;
|
||||
x[count_unknowns]->number = count_unknowns;
|
||||
slack_unknown = x[count_unknowns];
|
||||
count_unknowns++;
|
||||
}
|
||||
return (OK);
|
||||
}
|
||||
|
||||
#ifdef SKIP
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
setup_slack(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Fill in data for slack unknown
|
||||
*/
|
||||
|
||||
slack_unknown = NULL;
|
||||
if (slack)
|
||||
{
|
||||
int i = count_unknowns;
|
||||
int j;
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
if (x[j]->type == MB)
|
||||
{
|
||||
x[count_unknowns]->type = SLACK;
|
||||
x[count_unknowns]->description = string_hsave("slack");
|
||||
x[count_unknowns]->moles = 0.0;
|
||||
x[count_unknowns]->number = count_unknowns;
|
||||
x[count_unknowns]->mb_number = j;
|
||||
slack_unknown = x[count_unknowns];
|
||||
count_unknowns++;
|
||||
}
|
||||
}
|
||||
if (count_unknowns > i)
|
||||
{
|
||||
slack_unknown = x[i];
|
||||
}
|
||||
}
|
||||
|
||||
return (OK);
|
||||
}
|
||||
#endif
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
setup_ss_assemblage(void)
|
||||
@ -4889,10 +4677,6 @@ setup_unknowns(void)
|
||||
{
|
||||
max_unknowns += count_s;
|
||||
}
|
||||
/*
|
||||
* One for slack
|
||||
*/
|
||||
max_unknowns++;
|
||||
|
||||
/*
|
||||
* Allocate space for pointer array and structures
|
||||
@ -5586,154 +5370,6 @@ calc_delta_v(reaction *r_ptr, bool phase)
|
||||
return d_v;
|
||||
#endif
|
||||
}
|
||||
#ifdef PHREEQC2
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* calculate log_k for a single phase, correct for pressure
|
||||
*/
|
||||
|
||||
reaction *r_ptr = (p_ptr->rxn_x ? p_ptr->rxn_x :\
|
||||
(p_ptr->rxn_s ? p_ptr->rxn_s : NULL));
|
||||
if (!r_ptr)
|
||||
return 0.0;
|
||||
if (!r_ptr->logk[vm0])
|
||||
return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM);
|
||||
|
||||
LDBLE tc = TK - 273.15;
|
||||
LDBLE kp_t, d_v = 0.0;
|
||||
|
||||
for (size_t i = 0; r_ptr->token[i].name; i++)
|
||||
{
|
||||
if (!r_ptr->token[i].s)
|
||||
continue;
|
||||
if (!strcmp(r_ptr->token[i].s->name, "H+"))
|
||||
continue;
|
||||
if (!strcmp(r_ptr->token[i].s->name, "e-"))
|
||||
continue;
|
||||
if (!strcmp(r_ptr->token[i].s->name, "H2O"))
|
||||
{
|
||||
d_v += r_ptr->token[i].coef * 18.016 / calc_rho_0(tc, pa);
|
||||
}
|
||||
else if (r_ptr->token[i].s->logk[vm0])
|
||||
{
|
||||
d_v += r_ptr->token[i].coef * (r_ptr->token[i].s->logk[vm0] +\
|
||||
(r_ptr->token[i].s->logk[vm1] + r_ptr->token[i].s->logk[vm2] * tc) * tc);
|
||||
if (r_ptr->token[i].s->logk[kappa])
|
||||
{
|
||||
kp_t = r_ptr->token[i].s->logk[kappa];
|
||||
d_v += kp_t * pa;
|
||||
}
|
||||
}
|
||||
}
|
||||
d_v -= p_ptr->logk[vm0] + (p_ptr->logk[vm1] * tc + p_ptr->logk[vm2] * tc) * tc;
|
||||
r_ptr->logk[delta_v] = d_v;
|
||||
|
||||
if (!strcmp(r_ptr->token[0].name, "H2O(g)"))
|
||||
r_ptr->logk[delta_v] = 0.0;
|
||||
|
||||
return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM);
|
||||
}
|
||||
#ifdef SKIP_THIS_VM
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
calc_vm(LDBLE tc, LDBLE pa)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Calculate molar volumes for aqueous species, using the millero parm's.
|
||||
* Read.cpp copies millero[0..3] into logk[vm0 + 0..3], or reads them directly with -Vm.
|
||||
*/
|
||||
LDBLE kp_t;
|
||||
|
||||
/* S_v * Iv^0.5 is from Redlich and Meyer, Chem. Rev. 64, 221,
|
||||
Use mu_x for the volume averaged Iv, the difference is negligible....*/
|
||||
LDBLE Sv_I = 0.5 * (1.444 + (0.016799 + (-8.4055e-6 + 5.5153e-7 * tc) * tc) * tc) * sqrt(mu_x);
|
||||
// Sv_I = 0.0;
|
||||
for (int i = 0; i < count_s_x; i++)
|
||||
{
|
||||
if (!strcmp(s_x[i]->name, "H2O"))
|
||||
{
|
||||
s_x[i]->logk[vm_tc] = 18.016 / rho_0;
|
||||
continue;
|
||||
}
|
||||
if (!s_x[i]->logk[vm0])
|
||||
continue;
|
||||
/* the volume terms... */
|
||||
s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->logk[vm0] + (s_x[i]->logk[vm1] + s_x[i]->logk[vm2] * tc) * tc;
|
||||
if (s_x[i]->logk[kappa])
|
||||
{
|
||||
kp_t = s_x[i]->logk[kappa];
|
||||
//if (s_x[i]->z > 0)
|
||||
//{
|
||||
// /* correct kappa of cations for temperature, but kappa should be <= 0, Table 43.6 */
|
||||
// kp_t += 4e-5 * (tc - 25);
|
||||
// if (kp_t > 0)
|
||||
// kp_t = 0;
|
||||
//}
|
||||
s_x[i]->rxn_x->logk[vm_tc] += kp_t * pa;
|
||||
}
|
||||
|
||||
/* the ionic strength term * Iv^0.5... */
|
||||
s_x[i]->rxn_x->logk[vm_tc] += 0.5 * s_x[i]->z * s_x[i]->z * Sv_I;
|
||||
/* plus the volume terms * Iv, take mu_x for Iv... */
|
||||
//s_x[i]->rxn_x->logk[vm_tc] += (s_x[i]->millero[3] + (s_x[i]->millero[4] + s_x[i]->millero[5] * tc) * tc) * mu_x;
|
||||
|
||||
/* for calculating delta_v of the reaction... */
|
||||
s_search(s_x[i]->name)->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc];
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
calc_vm(LDBLE tc, LDBLE pa)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Calculate molar volumes for aqueous species, using the millero parm's.
|
||||
* Read.cpp copies millero[0..3] into logk[vm0 + 0..3], or reads them directly with -Vm.
|
||||
*/
|
||||
LDBLE I_v;
|
||||
|
||||
/* S_v * I_v^0.5 is from Redlich and Meyer, Chem. Rev. 64, 221,
|
||||
Use mu_x for the volume averaged Iv, the difference is negligible for mu < 10....*/
|
||||
//if (mu_x > 0.7)
|
||||
//{
|
||||
// calc_dens();
|
||||
// I_v = I_m / solution_volume;
|
||||
//}
|
||||
//else
|
||||
I_v = mu_x;
|
||||
|
||||
LDBLE Sv_I = 0.5 * (1.444 + (0.016799 + (-8.4055e-6 + 5.5153e-7 * tc) * tc) * tc) * sqrt(I_v);
|
||||
for (int i = 0; i < count_s_x; i++)
|
||||
{
|
||||
if (!strcmp(s_x[i]->name, "H2O"))
|
||||
{
|
||||
s_x[i]->logk[vm_tc] = 18.016 / rho_0;
|
||||
continue;
|
||||
}
|
||||
if (!s_x[i]->logk[vm0])
|
||||
continue;
|
||||
/* the volume terms... */
|
||||
s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->logk[vm0] + (s_x[i]->logk[vm1] + s_x[i]->logk[vm2] * tc) * tc;
|
||||
s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->logk[kappa] * pa;
|
||||
|
||||
/* the ionic strength term * Iv^0.5... */
|
||||
s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * Sv_I;
|
||||
/* plus the volume terms * Iv, take mu_x for Iv... */
|
||||
//s_x[i]->rxn_x->logk[vm_tc] += (s_x[i]->millero[3] + (s_x[i]->millero[4] + s_x[i]->millero[5] * tc) * tc) * mu_x;
|
||||
|
||||
/* for calculating delta_v of the reaction... */
|
||||
s_search(s_x[i]->name)->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc];
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
#else
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa)
|
||||
@ -5912,7 +5548,7 @@ calc_vm(LDBLE tc, LDBLE pa)
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */
|
||||
@ -5921,13 +5557,10 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */
|
||||
/*
|
||||
* Calculates log k's for all species and pure_phases
|
||||
*/
|
||||
#ifndef PHREEQC2
|
||||
|
||||
if (tc == current_tc && pa == current_pa && ((fabs(mu_x - current_mu) < 1e-3 * mu_x) || !mu_terms_in_logk))
|
||||
return OK;
|
||||
#else
|
||||
if (tc == current_tc && pa == current_pa)
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
int i;
|
||||
LDBLE tempk = tc + 273.15;
|
||||
/*
|
||||
@ -5935,11 +5568,10 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */
|
||||
*/
|
||||
/* calculate relative molar volumes for tc... */
|
||||
rho_0 = calc_rho_0(tc, pa);
|
||||
#ifndef PHREEQC2
|
||||
|
||||
pa = patm_x;
|
||||
//calc_dielectrics(tc_x, pa);
|
||||
calc_dielectrics(tc, pa);
|
||||
#endif
|
||||
|
||||
calc_vm(tc, pa);
|
||||
|
||||
mu_terms_in_logk = false;
|
||||
@ -5960,17 +5592,13 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */
|
||||
{
|
||||
if (phases[i]->in == TRUE)
|
||||
{
|
||||
#ifdef PHREEQC2
|
||||
phases[i]->rxn_x->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) -
|
||||
(phases[i]->logk[vm0] + phases[i]->logk[vm1] * tc + phases[i]->logk[vm2] * tc * tc);
|
||||
phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM);
|
||||
#else
|
||||
|
||||
phases[i]->rxn_x->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) -
|
||||
phases[i]->logk[vm0];
|
||||
if (phases[i]->rxn_x->logk[delta_v])
|
||||
mu_terms_in_logk = true;
|
||||
phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -6610,21 +6238,7 @@ build_min_surface(void)
|
||||
-comp_ptr->Get_formula_z() * comp_ptr->Get_phase_proportion());
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
#ifdef SKIP
|
||||
if (surface_ptr->Get_type() == cxxSurface::CD_MUSIC)
|
||||
{
|
||||
/* Add formula for CD_MUSIC */
|
||||
char * formula = string_duplicate(comp_ptr->Get_formula().c_str());
|
||||
char *ptr1 = formula;
|
||||
get_elts_in_species(&ptr1, 1.0);
|
||||
free_check_null(formula);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add master species for non CD_MUSIC */
|
||||
add_elt_list(x[j]->master[0]->s->next_elt, 1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
{
|
||||
/* Add specified formula for all types of surfaces */
|
||||
|
||||
6
sit.cpp
6
sit.cpp
@ -501,11 +501,9 @@ set_sit(int initial)
|
||||
*/
|
||||
tc_x = solution_ptr->Get_tc();
|
||||
tk_x = tc_x + 273.15;
|
||||
#ifdef PHREEQC2
|
||||
patm_x = solution_ptr->Get_patm();
|
||||
#else
|
||||
|
||||
patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* H+, e-, H2O
|
||||
*/
|
||||
|
||||
108
utilities.cpp
108
utilities.cpp
@ -81,37 +81,12 @@ calc_alk(struct reaction * rxn_ptr)
|
||||
}
|
||||
return (return_value);
|
||||
}
|
||||
#ifdef PHREEQC2
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
calc_rho_0(LDBLE tc, LDBLE pa)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/* Density of pure water
|
||||
Millero, 2009, Aq. Geochem. 15, 7-41, 1 - 200 oC, 1 - 1000 atm... */
|
||||
|
||||
LDBLE rho_0 = (999.83952 + (16.952577 + (-7.9905127e-3 + (-4.6241757e-5 + (1.0584601e-7 -\
|
||||
2.8103006e-10 * tc) * tc) * tc) * tc) * tc) / (1 + 0.016887236 * tc);
|
||||
/* pressure... */
|
||||
/*
|
||||
//LDBLE A = 5.08531e-2 + (-3.338927e-4 + (5.112457e-6 + (-3.226571e-8 + (1.186388e-10 -\
|
||||
// 1.437927e-13 * tc) * tc) * tc) * tc);
|
||||
//LDBLE B = -5.6999022e-6 + (6.370734e-8 + (-1.047053e-9 + (5.836798e-12 + (-1.658343e-14 +\
|
||||
// 3.977591e-22 * tc) * tc) * tc) * tc);
|
||||
//rho_0 += (A + B * patm_x) * patm_x;
|
||||
*/
|
||||
/* But, A and B are near-constants, the pressure term is equal to... */
|
||||
rho_0 += 0.046 * pa;
|
||||
|
||||
return (1e-3 * rho_0);
|
||||
}
|
||||
#else
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
calc_rho_0(LDBLE tc, LDBLE pa)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
//#ifdef SKIP
|
||||
/* Density of pure water
|
||||
Wagner and Pruss, 2002, JPCRD 31, 387, eqn. 2.6, along the saturation pressure line +
|
||||
interpolation 0 - 300 oC, 0.006 - 1000 atm...
|
||||
@ -161,85 +136,6 @@ calc_rho_0(LDBLE tc, LDBLE pa)
|
||||
kappa_0 = (p0 + pa * (2 * p1 + pa * (3 * p2 + sqrt(pa) * 3.5 * p3))) / rho_0;
|
||||
|
||||
return (rho_0 / 1e3);
|
||||
//#endif
|
||||
#ifdef SKIP
|
||||
/* Calculate the density and compressibility of pure water,
|
||||
IAPWS, IF97, region 1, 273 < Tk < 623, p_sat < p < 1e8 Pascal.
|
||||
Seems to give somewhat better rho's and kappa's for p < 2e3 than above,
|
||||
but may give densities < 0 outside the limits, e.g. tc = 250, p = 2.5e3... */
|
||||
|
||||
/* The minimal pressure equals the saturation pressure... */
|
||||
LDBLE tk = tc + 273.15;
|
||||
p_sat = exp(11.6702 - 3816.44 / (tk - 46.13));
|
||||
if (ah2o_x <= 1.0)
|
||||
p_sat *= ah2o_x;
|
||||
//ah2o_x0 = ah2o_x; // for updating rho in model(): compare with new ah2o_x
|
||||
if (pa < p_sat || (use.Get_solution_ptr() && use.Get_solution_ptr()->Get_patm() < p_sat))
|
||||
{
|
||||
pa = p_sat;
|
||||
}
|
||||
if (!use.Get_gas_phase_in())
|
||||
patm_x = pa;
|
||||
LDBLE pasc = pa * 1.01325e5;
|
||||
LDBLE Rg = 0.461526e3; //J / kg / K
|
||||
LDBLE Tref = 1386.0, Pref = 16.53e6; // K, Pa
|
||||
LDBLE t_t = Tref / tk, p_p = pasc / Pref;
|
||||
LDBLE ni[34] = {0.14632971213167, -0.84548187169114, -0.37563603672040e1, 0.33855169168385e1,
|
||||
-0.95791963387872, 0.15772038513228, -0.16616417199501e-1, 0.81214629983568e-3,
|
||||
0.28319080123804e-3, -0.60706301565874e-3, -0.18990068218419e-1, -0.32529748770505e-1,
|
||||
-0.21841717175414e-1, -0.52838357969930e-4, -0.47184321073267e-3, -0.30001780793026e-3,
|
||||
0.47661393906987e-4, -0.44141845330846e-5, -0.72694996297594e-15, -0.31679644845054e-4,
|
||||
-0.28270797985312e-5, -0.85205128120103e-9, -0.22425281908000e-5, -0.65171222895601e-6,
|
||||
-0.14341729937924e-12, -0.40516996860117e-6, -0.12734301741641e-8, -0.17424871230634e-9,
|
||||
-0.68762131295531e-18, 0.14478307828521e-19, 0.26335781662795e-22, -0.11947622640071e-22,
|
||||
0.18228094581404e-23, -0.93537087292458e-25};
|
||||
int ii[34] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2,
|
||||
2, 2, 3, 3, 3, 4, 4, 4, 5, 8, 8, 21, 23, 29, 30, 31, 32};
|
||||
int jj[34] = {-2, -1, 0, 1, 2, 3, 4, 5, -9, -7, -1, 0, 1, 3, -3, 0, 1,
|
||||
3, 17, -4, 0, 6, -5, -2, 10, -8, -11, -6, -29, -31, -38, -39, -40, -41};
|
||||
/* v (m3/kg) = dG/dp =
|
||||
(p_p * Rg * tk / pasc) * Sum_i (-ni[i] * ii[i] * (7.1 - p_p)^(ii[i] - 1) * (t_t - 1.222)^jj[i])
|
||||
kappa_0 (1 / Pa) = -1/v * dv/dp = -1/v * d2G/dp2 =
|
||||
-1 / (v * Pref) * Sum_i (ni[i] * ii[i] * (ii[i] - 1) * (7.1 - p_p)^(ii[i] - 2) * (t_t - 1.222)^jj[i]) */
|
||||
|
||||
double v = -ni[11] - (7.1 - p_p) * (ni[15] * ii[15] + ni[20] * ii[20] * (7.1 - p_p));
|
||||
double dvdp = ni[15] * ii[15] + ni[20] * ii[20] * (ii[20] - 1) * (7.1 - p_p);
|
||||
for (int i = 8; i < 34; i++)
|
||||
{
|
||||
if (i == 11 || i == 15 || i == 20)
|
||||
continue;
|
||||
if (ii[i] == 1)
|
||||
{
|
||||
if (jj[i] == 1)
|
||||
v -= ni[i] * (t_t - 1.222);
|
||||
else
|
||||
v -= ni[i] * pow(t_t - 1.222, jj[i]);
|
||||
}
|
||||
else if (ii[i] == 2)
|
||||
{
|
||||
if (jj[i] == 1)
|
||||
{
|
||||
v -= ni[i] * ii[i] * (7.1 - p_p) * (t_t - 1.222);
|
||||
dvdp += ni[i] * ii[i] * (ii[i] - 1) * (t_t - 1.222);
|
||||
}
|
||||
else
|
||||
{
|
||||
v -= ni[i] * ii[i] * (7.1 - p_p) * pow(t_t - 1.222, jj[i]);
|
||||
dvdp += ni[i] * ii[i] * (ii[i] - 1) * pow(t_t - 1.222, jj[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
v -= ni[i] * ii[i] * pow(7.1 - p_p, ii[i] - 1) * pow(t_t - 1.222, jj[i]);
|
||||
dvdp += ni[i] * ii[i] * (ii[i] - 1) * pow(7.1 - p_p, ii[i] - 2) * pow(t_t - 1.222, jj[i]);
|
||||
}
|
||||
}
|
||||
if (v < 0)
|
||||
error_msg("Calculating negative densities:\n Pressure and/or Temperature are outside the model's domain.\n", TRUE);
|
||||
kappa_0 = -dvdp / v / Pref * 1.01325e5; // compressibility, 1/atm
|
||||
rho_0 = 1e-3 / (v * (p_p * Rg * tk / pasc)); // density, kg/L
|
||||
return rho_0;
|
||||
#endif
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
LDBLE Phreeqc::
|
||||
@ -302,7 +198,7 @@ calc_dielectrics(LDBLE tc, LDBLE pa)
|
||||
|
||||
return (OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user