mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 16:44:49 +01:00
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:
parent
c6261d5f9e
commit
27e3f75c4e
@ -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;
|
||||
|
||||
@ -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)
|
||||
|
||||
4
prep.cpp
4
prep.cpp
@ -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 *));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user