Working on efficiency of updating Solution.cxx

Need to revise solution_modify.

git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6856 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
David L Parkhurst 2012-08-05 19:12:28 +00:00
parent 31c1ae8664
commit 8b0481a1ee
2 changed files with 52 additions and 23 deletions

View File

@ -642,41 +642,62 @@ cxxSolution::read_raw(CParser & parser, bool check)
return;
}
void
cxxSolution::Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble &const_nd)
{
// H, O, charge, totals, and activities of solution are updated
this->total_h = h_tot;
this->total_o = o_tot;
this->cb = charge;
this->Update(const_nd);
}
void
cxxSolution::Update(const cxxNameDouble &const_nd)
{
if (this->master_activity.size() > 0)
{
cxxNameDouble simple_original = this->totals.Simplify_redox();
cxxNameDouble simple_new = const_nd.Simplify_redox();
// Totals and activities of solution are updated
// nd does not have H, O, charge
cxxNameDouble simple_original = this->totals.Simplify_redox();
cxxNameDouble simple_new = const_nd.Simplify_redox();
// make factors
// make factors
cxxNameDouble factors;
{
cxxNameDouble::iterator it = simple_new.begin();
cxxNameDouble::iterator jit = simple_original.begin();
while (it != simple_new.end() && jit != simple_original.end())
{
cxxNameDouble::iterator it = simple_new.begin();
for ( ; it != simple_new.end(); it++)
int j = strcmp(it->first.c_str(), jit->first.c_str());
if (j < 0)
{
cxxNameDouble::iterator jit = simple_original.find(it->first);
if (jit != simple_original.end())
it++;
}
else if (j == 0)
{
if (jit->second != it->second)
{
if (it->second != 0 && jit->second > 0)
if (it->second > 0 && jit->second > 0)
{
it->second = log10(jit->second / it->second);
factors[it->first] = log10(jit->second / it->second);
}
}
else
{
it->second = 0;
}
it++;
jit++;
}
else
{
jit++;
}
}
// simple_new now has factors for master activities
// Now add factors to activities
{
cxxNameDouble::iterator activity_it = this->master_activity.begin();
cxxNameDouble::iterator total_it = simple_new.begin();
cxxNameDouble::iterator factors_it = factors.begin();
std::string activity_ename;
std::basic_string < char >::size_type indexCh;
while (activity_it != master_activity.end() && total_it != simple_new.end())
while (activity_it != master_activity.end() && factors_it != factors.end())
{
activity_ename = activity_it->first;
if (activity_ename.size() > 3)
@ -687,17 +708,14 @@ cxxSolution::Update(const cxxNameDouble &const_nd)
activity_ename = activity_ename.substr(0, indexCh);
}
}
int j = strcmp(total_it->first.c_str(), activity_ename.c_str());
int j = strcmp(factors_it->first.c_str(), activity_ename.c_str());
if (j < 0)
{
total_it++;
factors_it++;
}
else if (j == 0)
{
if (total_it->second > 0)
{
activity_it->second += total_it->second;
}
activity_it->second += factors_it->second;
activity_it++;
}
else
@ -707,6 +725,15 @@ cxxSolution::Update(const cxxNameDouble &const_nd)
}
}
}
// update other totals
{
cxxNameDouble::iterator it;
for (it = simple_new.begin(); it != simple_new.end(); it++)
{
simple_original[it->first] = it->second;
}
}
}
#ifdef SKIP
void

View File

@ -103,6 +103,8 @@ class cxxSolution:public cxxNumKeyword
//void modify_activities(const cxxSolution & original);
//void Simplify_totals();
void Update(const cxxNameDouble &nd);
void Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble &nd);
void Update_activities(const cxxNameDouble &old_tot, const cxxNameDouble &new_tot);
#ifdef USE_MPI
void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles);