Revised tidy_gases. Structure was wrong and j was used in two loops.

git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7920 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
David L Parkhurst 2013-08-13 15:15:47 +00:00
parent 59b456bdd5
commit 2abb2f2283

160
tidy.cpp
View File

@ -858,6 +858,165 @@ rewrite_eqn_to_primary(void)
int Phreeqc::
tidy_gas_phase(void)
/* ---------------------------------------------------------------------- */
{
int n_user, last;
LDBLE P, V_m;
bool PR;
/*
* Find all gases for each gas_phase in phase list
*/
for (std::set<int>::const_iterator nit = Rxn_new_gas_phase.begin(); nit != Rxn_new_gas_phase.end(); nit++)
{
std::map<int, cxxGasPhase>::iterator it = Rxn_gas_phase_map.find(*nit);
if (it == Rxn_gas_phase_map.end())
{
assert(false);
}
cxxGasPhase *gas_phase_ptr = &(it->second);
PR = false;
P = 0.0;
if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE)
{
if (gas_phase_ptr->Get_solution_equilibria())
{
input_error++;
error_string = sformatf(
"Gas phase %d: cannot use '-equilibrium' option with fixed pressure gas phase.",
gas_phase_ptr->Get_n_user());
error_msg(error_string, CONTINUE);
}
}
std::vector<cxxGasComp> gc = gas_phase_ptr->Get_gas_comps();
for (size_t j = 0; j < gc.size(); j++)
{
int k;
struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE);
if (phase_ptr == NULL)
{
input_error++;
error_string = sformatf(
"Gas not found in PHASES database, %s.",
gc[j].Get_phase_name().c_str());
error_msg(error_string, CONTINUE);
continue;
}
else
{
if (phase_ptr->t_c > 0 && phase_ptr->p_c > 0)
PR = true;
}
gas_phase_ptr->Set_pr_in(PR);
/*
* Fixed pressure
*/
if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE)
{
/* calculate moles */
if (gc[j].Get_p_read() != NAN)
{
P += gc[j].Get_p_read();
gc[j].Set_moles(
gc[j].Get_p_read() * gas_phase_ptr->Get_volume() /
R_LITER_ATM / gas_phase_ptr->Get_temperature());
}
else
{
input_error++;
error_string = sformatf(
"Gas phase %d: partial pressure of gas component %s not defined.",
gas_phase_ptr->Get_n_user(), gc[j].Get_phase_name().c_str());
error_msg(error_string, CONTINUE);
}
}
else
{
/*
* Fixed volume
*/
if (!gas_phase_ptr->Get_solution_equilibria())
{
if (gc[j].Get_p_read() != NAN)
{
P += gc[j].Get_p_read();
gc[j].Set_moles (
gc[j].Get_p_read() *
gas_phase_ptr->Get_volume() / R_LITER_ATM /
gas_phase_ptr->Get_temperature());
}
else
{
input_error++;
error_string = sformatf(
"Gas phase %d: moles of gas component %s not defined.",
gas_phase_ptr->Get_n_user(),
gc[j].Get_phase_name().c_str());
error_msg(error_string, CONTINUE);
}
}
}
}
gas_phase_ptr->Set_gas_comps(gc);
if (PR && P > 0)
{
std::vector<struct phase *> phase_ptrs;
for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++)
{
int k;
struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &k, FALSE);
if (gc[j].Get_p_read() == 0)
continue;
phase_ptr->moles_x = gc[j].Get_p_read() / P;
phase_ptrs.push_back(phase_ptr);
}
V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0);
gas_phase_ptr->Set_v_m(V_m);
if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME)
{
gas_phase_ptr->Set_total_p(P);
}
std::vector<cxxGasComp> gc = gas_phase_ptr->Get_gas_comps();
for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++)
{
int k;
struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE);
if (gc[j].Get_p_read() == 0)
{
gc[j].Set_moles(0.0);
} else
{
gc[j].Set_moles(phase_ptr->moles_x * gas_phase_ptr->Get_volume() / V_m);
gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j].Get_moles());
}
}
gas_phase_ptr->Set_gas_comps(gc);
}
/*
* Duplicate gas phase, only if not solution equilibria
*/
if (!gas_phase_ptr->Get_solution_equilibria())
{
n_user = gas_phase_ptr->Get_n_user();
last = gas_phase_ptr->Get_n_user_end();
gas_phase_ptr->Set_n_user_end(n_user);
for (int j = n_user + 1; j <= last; j++)
{
Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j);
}
}
else
{
gas_phase_ptr->Set_new_def(true);
}
}
return (OK);
}
#ifdef SKIP
/* ---------------------------------------------------------------------- */
int Phreeqc::
tidy_gas_phase(void)
/* ---------------------------------------------------------------------- */
{
int n_user, last;
LDBLE P, V_m;
@ -1023,6 +1182,7 @@ tidy_gas_phase(void)
}
return (OK);
}
#endif
/* ---------------------------------------------------------------------- */
int Phreeqc::
tidy_inverse(void)