Optimized sum_species.

Keeps lists of species in a map <std::string, std::vector<std::string> > sum_species_map.

resets map whenever s_x changes (tidy and prep)

git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7470 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
David L Parkhurst 2013-02-15 18:06:29 +00:00
parent c6261d5f9e
commit 27e3f75c4e
4 changed files with 62 additions and 0 deletions

View File

@ -1888,6 +1888,9 @@ protected:
/* utilities.cpp ------------------------------- */
int spinner;
/* new after release of Version 3 */
std::map<std::string, std::vector < std::string> > sum_species_map;
friend class PBasic;
friend class ChartObject;
friend class IPhreeqc;

View File

@ -1465,6 +1465,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)
@ -1501,6 +1502,58 @@ 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())
{
std::vector<std::string> species_list;
for (i = 0; i < count_s_x; i++)
{
struct species *s_ptr = s_x[i];
if (match_elts_in_species(s_ptr->name, mytemplate) == TRUE)
{
species_list.push_back(s_ptr->name);
}
}
sum_species_map[mytemplate] = species_list;
}
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
/* ---------------------------------------------------------------------- */
LDBLE Phreeqc::
sum_match_ss(const char *mytemplate, const char *name)

View File

@ -1129,6 +1129,10 @@ build_model(void)
*/
max_s_x = MAX_S;
// clear sum_species_map, which is built from s_x
sum_species_map.clear();
space((void **) ((void *) &s_x), INIT, &max_s_x,
sizeof(struct species *));

View File

@ -180,6 +180,8 @@ tidy_model(void)
*/
if (new_model)
{
sum_species_map.clear();
tidy_species();
tidy_phases();