[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Getfem-commits] r5309 - in /trunk/getfem/src: getfem/getfem_generic_ass
From: |
Yves . Renard |
Subject: |
[Getfem-commits] r5309 - in /trunk/getfem/src: getfem/getfem_generic_assembly.h getfem_generic_assembly.cc getfem_plasticity.cc |
Date: |
Wed, 27 Apr 2016 07:44:38 -0000 |
Author: renard
Date: Wed Apr 27 09:44:38 2016
New Revision: 5309
URL: http://svn.gna.org/viewcvs/getfem?rev=5309&view=rev
Log:
More efficient ga_substitute with a std::map
Modified:
trunk/getfem/src/getfem/getfem_generic_assembly.h
trunk/getfem/src/getfem_generic_assembly.cc
trunk/getfem/src/getfem_plasticity.cc
Modified: trunk/getfem/src/getfem/getfem_generic_assembly.h
URL:
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem/getfem_generic_assembly.h?rev=5309&r1=5308&r2=5309&view=diff
==============================================================================
--- trunk/getfem/src/getfem/getfem_generic_assembly.h (original)
+++ trunk/getfem/src/getfem/getfem_generic_assembly.h Wed Apr 27 09:44:38 2016
@@ -384,31 +384,30 @@
// Small tool to make basic substitutions into an assembly string
std::string ga_substitute(const std::string &expr,
- const std::vector<std::string> &org,
- const std::vector<std::string> &subst);
+ const std::map<std::string, std::string> &dict);
inline std::string ga_subsitute(const std::string &expr,
const std::string &o1,const std::string &s1) {
- std::vector<std::string> org = { o1 };
- std::vector<std::string> subst = { s1 };
- return ga_substitute(expr, org, subst);
+ std::map<std::string, std::string> dict;
+ dict[o1] = s1;
+ return ga_substitute(expr, dict);
}
inline std::string ga_subsitute(const std::string &expr,
const std::string &o1,const std::string &s1,
const std::string &o2,const std::string &s2) {
- std::vector<std::string> org = { o1, o2 };
- std::vector<std::string> subst = { s1, s2 };
- return ga_substitute(expr, org, subst);
+ std::map<std::string, std::string> dict;
+ dict[o1] = s1; dict[o2] = s2;
+ return ga_substitute(expr, dict);
}
inline std::string ga_subsitute(const std::string &expr,
const std::string &o1,const std::string &s1,
const std::string &o2,const std::string &s2,
const std::string &o3,const std::string &s3) {
- std::vector<std::string> org = { o1, o2, o3 };
- std::vector<std::string> subst = { s1, s2, s3 };
- return ga_substitute(expr, org, subst);
+ std::map<std::string, std::string> dict;
+ dict[o1] = s1; dict[o2] = s2; dict[o3] = s3;
+ return ga_substitute(expr, dict);
}
inline std::string ga_subsitute(const std::string &expr,
@@ -416,9 +415,9 @@
const std::string &o2,const std::string &s2,
const std::string &o3,const std::string &s3,
const std::string &o4,const std::string &s4) {
- std::vector<std::string> org = { o1, o2, o3, o4 };
- std::vector<std::string> subst = { s1, s2, s3, s4 };
- return ga_substitute(expr, org, subst);
+ std::map<std::string, std::string> dict;
+ dict[o1] = s1; dict[o2] = s2; dict[o3] = s3; dict[o4] = s4;
+ return ga_substitute(expr, dict);
}
Modified: trunk/getfem/src/getfem_generic_assembly.cc
URL:
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem_generic_assembly.cc?rev=5309&r1=5308&r2=5309&view=diff
==============================================================================
--- trunk/getfem/src/getfem_generic_assembly.cc (original)
+++ trunk/getfem/src/getfem_generic_assembly.cc Wed Apr 27 09:44:38 2016
@@ -1840,37 +1840,24 @@
// Small tool to make basic substitutions into an assembly string
std::string ga_substitute(const std::string &expr,
- const std::vector<std::string> &org,
- const std::vector<std::string> &subst) {
- GMM_ASSERT1(org.size() == subst.size(), "Invalid size of arguments");
-
- if (org.size()) {
+ const std::map<std::string, std::string> &dict) {
+ if (dict.size()) {
size_type pos = 0, token_pos, token_length;
std::stringstream exprs;
- GA_TOKEN_TYPE t_type = ga_get_token(expr, pos, token_pos, token_length);
- if (t_type == GA_END) return expr;
- pos = 0;
for (;;) {
- bool found = false;
- t_type = ga_get_token(expr, pos, token_pos, token_length);
+ GA_TOKEN_TYPE t_type = ga_get_token(expr, pos, token_pos, token_length);
+ if (t_type == GA_END) return exprs.str();
std::string name(&(expr[token_pos]), token_length);
-
- switch (t_type) {
- case GA_END : return exprs.str();
- case GA_NAME :
- for (size_type i = 0; i < org.size(); ++i)
- if (name.compare(org[i]) == 0)
- { exprs << subst[i]; found = true; break; }
- default : if (!found) exprs << name; break;
- }
- }
- return exprs.str();
+ if (t_type == GA_NAME) {
+ auto it = dict.find(name);
+ if (it != dict.end()) exprs << it->second; else exprs << name;
+ } else
+ exprs << name;
+ }
}
return expr;
}
-
-
//=========================================================================
// Structure to gather instructions
Modified: trunk/getfem/src/getfem_plasticity.cc
URL:
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem_plasticity.cc?rev=5309&r1=5308&r2=5309&view=diff
==============================================================================
--- trunk/getfem/src/getfem_plasticity.cc (original)
+++ trunk/getfem/src/getfem_plasticity.cc Wed Apr 27 09:44:38 2016
@@ -552,28 +552,29 @@
"Wrong size of " << Previous_Ep);
- std::vector<std::string> // Dictionnary for substitution
- o = { "Grad_u", "Grad_Previous_u", "theta", "Previous_Ep",
- "lambda", "mu", "sigma_y" },
- s = { "Grad_"+dispname, "Grad_Previous_"+dispname, theta, Previous_Ep,
- lambda, mu, sigma_y };
+ std::map<std::string, std::string> dict;
+ dict["Grad_u"] = "Grad_"+dispname;
+ dict["Grad_Previous_u"] = "Grad_Previous_"+dispname;
+ dict["theta"] = theta; dict["Previous_Ep"] = Previous_Ep;
+ dict["lambda"] = lambda; dict["mu"] = mu; dict["sigma_y"] = sigma_y;
std::string Etheta =
- ga_substitute("Sym((theta)*Grad_u+(1-(theta))*Grad_Previous_u)",o,s);
- o.push_back("Etheta"); s.push_back(Etheta);
- std::string Enp1 = ga_substitute("Sym(Grad_u)",o,s);
- o.push_back("Enp1"); s.push_back(Enp1);
- std::string Btheta = ga_substitute("Deviator(Etheta)-Epn",o,s);
- o.push_back("Btheta"); s.push_back(Btheta);
- Eptheta =
ga_substitute("(Previous_Ep)+pos_part(1-sqrt(2/3)*(sigma_y)/(2*(mu)*Norm(Btheta)+1e-25))*(Btheta)",o,s);
- o.push_back("Eptheta"); s.push_back(Eptheta);
- Epnp1 = ga_substitute("(Eptheta - (1-(theta))*Epn)/(theta)",o,s);
- o.push_back("Epnp1"); s.push_back(Epnp1);
+ ga_substitute("Sym((theta)*Grad_u+(1-(theta))*Grad_Previous_u)", dict);
+ dict["Etheta"] = Etheta;
+ std::string Enp1 = ga_substitute("Sym(Grad_u)", dict);
+ dict["Enp1"] = Enp1;
+ std::string Btheta = ga_substitute("Deviator(Etheta)-Epn", dict);
+ dict["Btheta"] = Btheta;
+ Eptheta =
ga_substitute("(Previous_Ep)+pos_part(1-sqrt(2/3)*(sigma_y)/(2*(mu)*Norm(Btheta)+1e-25))*(Btheta)",
dict);
+ dict["Eptheta"] = Eptheta;
+ Epnp1 = ga_substitute("(Eptheta - (1-(theta))*Epn)/(theta)", dict);
+ dict["Epnp1"] = Epnp1;
sigma_np1 = ga_substitute("(lambda)*Trace((Enp1)-(Epnp1))*Id(meshdim)"
- " + 2*(mu)*((Enp1)-(Epnp1))",o,s);
+ " + 2*(mu)*((Enp1)-(Epnp1))", dict);
sigma_theta =
ga_substitute("(lambda)*Trace((Etheta)-(Eptheta))*Id(meshdim)"
- "+ 2*(mu)*((Etheta)-(Eptheta))",o,s);
- sigma_after =
ga_substitute("(lambda)*Trace((Enp1)-(Previous_Ep))*Id(meshdim) +
2*(mu)*((Enp1)-(Previous_Ep))",o,s);
+ "+ 2*(mu)*((Etheta)-(Eptheta))", dict);
+ sigma_after =
ga_substitute("(lambda)*Trace((Enp1)-(Previous_Ep))*Id(meshdim) +
2*(mu)*((Enp1)-(Previous_Ep))", dict);
+ cout << "Eptheta = " << Eptheta << endl;
}
static void filter_lawname(std::string &lawname) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Getfem-commits] r5309 - in /trunk/getfem/src: getfem/getfem_generic_assembly.h getfem_generic_assembly.cc getfem_plasticity.cc,
Yves . Renard <=