Skip to content
Snippets Groups Projects
Commit f8a91064 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

onelab 1.3 with ability to exchange parameters without incremental choices (to...

onelab 1.3 with ability to exchange parameters without incremental choices (to speed up e.g. long time simulations where choices are used as time history)
parent c3281835
No related branches found
No related tags found
No related merge requests found
...@@ -86,6 +86,8 @@ class GmshSocket{ ...@@ -86,6 +86,8 @@ class GmshSocket{
GMSH_PARAMETER_UPDATE = 32, GMSH_PARAMETER_UPDATE = 32,
GMSH_OPEN_PROJECT = 33, GMSH_OPEN_PROJECT = 33,
GMSH_CLIENT_CHANGED = 34, GMSH_CLIENT_CHANGED = 34,
GMSH_PARAMETER_WITHOUT_CHOICES = 35,
GMSH_PARAMETER_QUERY_WITHOUT_CHOICES = 36,
GMSH_OPTION_1 = 100, GMSH_OPTION_1 = 100,
GMSH_OPTION_2 = 101, GMSH_OPTION_2 = 101,
GMSH_OPTION_3 = 102, GMSH_OPTION_3 = 102,
......
...@@ -245,6 +245,7 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) ...@@ -245,6 +245,7 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
} }
break; break;
case GmshSocket::GMSH_PARAMETER: case GmshSocket::GMSH_PARAMETER:
case GmshSocket::GMSH_PARAMETER_WITHOUT_CHOICES:
case GmshSocket::GMSH_PARAMETER_UPDATE: case GmshSocket::GMSH_PARAMETER_UPDATE:
{ {
std::string version, ptype, name; std::string version, ptype, name;
...@@ -256,6 +257,14 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) ...@@ -256,6 +257,14 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
else if(ptype == "number"){ else if(ptype == "number"){
onelab::number p; p.fromChar(message); onelab::number p; p.fromChar(message);
if(!tryToSetGmshNumberOption(p)){ if(!tryToSetGmshNumberOption(p)){
if(type == GmshSocket::GMSH_PARAMETER_WITHOUT_CHOICES){
// append value to any choices already on the server
std::vector<onelab::number> par; get(par, name);
std::vector<double> c;
if(par.size()) c = par[0].getChoices();
c.push_back(p.getValue());
p.setChoices(c);
}
if(type == GmshSocket::GMSH_PARAMETER_UPDATE){ if(type == GmshSocket::GMSH_PARAMETER_UPDATE){
std::vector<onelab::number> par; get(par, name); std::vector<onelab::number> par; get(par, name);
if(par.size()) { if(par.size()) {
...@@ -275,7 +284,15 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) ...@@ -275,7 +284,15 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
else if(ptype == "string"){ else if(ptype == "string"){
onelab::string p; p.fromChar(message); onelab::string p; p.fromChar(message);
if(!tryToSetGmshStringOption(p)){ if(!tryToSetGmshStringOption(p)){
if(type == GmshSocket::GMSH_PARAMETER_UPDATE){ if(type == GmshSocket::GMSH_PARAMETER_WITHOUT_CHOICES){
// append value to any choices already on the server
std::vector<onelab::string> par; get(par, name);
std::vector<std::string> c;
if(par.size()) c = par[0].getChoices();
c.push_back(p.getValue());
p.setChoices(c);
}
else if(type == GmshSocket::GMSH_PARAMETER_UPDATE){
std::vector<onelab::string> par; get(par, name); std::vector<onelab::string> par; get(par, name);
if(par.size()){ if(par.size()){
onelab::string y = p; p = par[0]; onelabUtils::updateString(p,y); onelab::string y = p; p = par[0]; onelabUtils::updateString(p,y);
...@@ -289,6 +306,7 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) ...@@ -289,6 +306,7 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
} }
break; break;
case GmshSocket::GMSH_PARAMETER_QUERY: case GmshSocket::GMSH_PARAMETER_QUERY:
case GmshSocket::GMSH_PARAMETER_QUERY_WITHOUT_CHOICES:
{ {
std::string version, ptype, name, reply; std::string version, ptype, name, reply;
onelab::parameter::getInfoFromChar(message, version, ptype, name); onelab::parameter::getInfoFromChar(message, version, ptype, name);
...@@ -297,14 +315,22 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) ...@@ -297,14 +315,22 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
onelab::parameter::version().c_str(), version.c_str()); onelab::parameter::version().c_str(), version.c_str());
} }
else if(ptype == "number"){ else if(ptype == "number"){
std::vector<onelab::number> par; get(par, name); std::vector<onelab::number> par;
if(type == GmshSocket::GMSH_PARAMETER_QUERY_WITHOUT_CHOICES)
getWithoutChoices(par, name);
else
get(par, name);
if(par.empty()) if(par.empty())
reply = tryToGetGmshNumberOption(name); reply = tryToGetGmshNumberOption(name);
else else
reply = par[0].toChar(); reply = par[0].toChar();
} }
else if(ptype == "string"){ else if(ptype == "string"){
std::vector<onelab::string> par; get(par, name); std::vector<onelab::string> par;
if(type == GmshSocket::GMSH_PARAMETER_QUERY_WITHOUT_CHOICES)
getWithoutChoices(par, name);
else
get(par, name);
if(par.empty()) if(par.empty())
reply = tryToGetGmshStringOption(name); reply = tryToGetGmshStringOption(name);
else else
...@@ -470,6 +496,7 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) ...@@ -470,6 +496,7 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
break; break;
default: default:
Msg::Warning("Received unknown message type (%d)", type); Msg::Warning("Received unknown message type (%d)", type);
return false;
break; break;
} }
......
...@@ -198,7 +198,7 @@ namespace onelab{ ...@@ -198,7 +198,7 @@ namespace onelab{
const std::map<std::string, int> &getClients() const { return _clients; } const std::map<std::string, int> &getClients() const { return _clients; }
static char charSep() { return '\0'; } static char charSep() { return '\0'; }
static double maxNumber() { return 1e200; } static double maxNumber() { return 1e200; }
static std::string version() { return "1.2"; } static std::string version() { return "1.3"; }
static int defaultChangedValue() { return 31; } static int defaultChangedValue() { return 31; }
static std::string getNextToken(const std::string &msg, static std::string getNextToken(const std::string &msg,
std::string::size_type &first, std::string::size_type &first,
...@@ -742,7 +742,7 @@ namespace onelab{ ...@@ -742,7 +742,7 @@ namespace onelab{
{ {
return _get(ps, name, client, _numbers); return _get(ps, name, client, _numbers);
} }
bool get(std::vector<onelab::string> &ps, const std::string &name="", bool get(std::vector<string> &ps, const std::string &name="",
const std::string &client="") const std::string &client="")
{ {
return _get(ps, name, client, _strings); return _get(ps, name, client, _strings);
...@@ -831,10 +831,10 @@ namespace onelab{ ...@@ -831,10 +831,10 @@ namespace onelab{
onelab::parameter::getInfoFromChar(msg[i], version, type, name); onelab::parameter::getInfoFromChar(msg[i], version, type, name);
if(onelab::parameter::version() != version) return false; if(onelab::parameter::version() != version) return false;
if(type == "number"){ if(type == "number"){
onelab::number p; p.fromChar(msg[i]); set(p, client); number p; p.fromChar(msg[i]); set(p, client);
} }
else if(type == "string"){ else if(type == "string"){
onelab::string p; p.fromChar(msg[i]); set(p, client); string p; p.fromChar(msg[i]); set(p, client);
} }
else else
return false; return false;
...@@ -900,7 +900,11 @@ namespace onelab{ ...@@ -900,7 +900,11 @@ namespace onelab{
virtual bool set(const number &p) = 0; virtual bool set(const number &p) = 0;
virtual bool set(const string &p) = 0; virtual bool set(const string &p) = 0;
virtual bool get(std::vector<number> &ps, const std::string &name="") = 0; virtual bool get(std::vector<number> &ps, const std::string &name="") = 0;
virtual bool get(std::vector<onelab::string> &ps, const std::string &name="") = 0; virtual bool get(std::vector<string> &ps, const std::string &name="") = 0;
virtual bool setAndAppendChoices(const number &p) = 0;
virtual bool setAndAppendChoices(const string &p) = 0;
virtual bool getWithoutChoices(std::vector<number> &ps, const std::string &name="") = 0;
virtual bool getWithoutChoices(std::vector<string> &ps, const std::string &name="") = 0;
std::vector<std::string> toChar() std::vector<std::string> toChar()
{ {
std::vector<std::string> out; std::vector<std::string> out;
...@@ -917,10 +921,10 @@ namespace onelab{ ...@@ -917,10 +921,10 @@ namespace onelab{
onelab::parameter::getInfoFromChar(msg[i], version, type, name); onelab::parameter::getInfoFromChar(msg[i], version, type, name);
if(onelab::parameter::version() != version) return false; if(onelab::parameter::version() != version) return false;
if(type == "number"){ if(type == "number"){
onelab::number p; p.fromChar(msg[i]); set(p); number p; p.fromChar(msg[i]); set(p);
} }
else if(type == "string"){ else if(type == "string"){
onelab::string p; p.fromChar(msg[i]); set(p); string p; p.fromChar(msg[i]); set(p);
} }
else else
return false; return false;
...@@ -938,6 +942,7 @@ namespace onelab{ ...@@ -938,6 +942,7 @@ namespace onelab{
return false; return false;
} }
}; };
// The onelab server: a singleton that stores the parameter space and // The onelab server: a singleton that stores the parameter space and
// interacts with onelab clients. // interacts with onelab clients.
class server{ class server{
...@@ -1057,8 +1062,46 @@ namespace onelab{ ...@@ -1057,8 +1062,46 @@ namespace onelab{
virtual bool set(const string &p){ return _set(p); } virtual bool set(const string &p){ return _set(p); }
virtual bool get(std::vector<number> &ps, virtual bool get(std::vector<number> &ps,
const std::string &name=""){ return _get(ps, name); } const std::string &name=""){ return _get(ps, name); }
virtual bool get(std::vector<onelab::string> &ps, virtual bool get(std::vector<string> &ps,
const std::string &name=""){ return _get(ps, name); } const std::string &name=""){ return _get(ps, name); }
virtual bool setAndAppendChoices(const number &p)
{
std::vector<number> ps;
_get(ps, _name);
std::vector<double> choices;
if(ps.size()) choices = ps[0].getChoices();
choices.insert(choices.end(), p.getChoices().begin(), p.getChoices().end());
number p2(p);
p2.setChoices(choices);
return _set(p2);
}
virtual bool setAndAppendChoices(const string &p)
{
std::vector<string> ps;
_get(ps, _name);
std::vector<std::string> choices;
if(ps.size()) choices = ps[0].getChoices();
choices.insert(choices.end(), p.getChoices().begin(), p.getChoices().end());
string p2(p);
p2.setChoices(choices);
return _set(p2);
}
virtual bool getWithoutChoices(std::vector<number> &ps,
const std::string &name="")
{
bool ret = _get(ps, name);
for(unsigned int i = 0; i < ps.size(); i++)
ps[i].setChoices(std::vector<double>());
return ret;
}
virtual bool getWithoutChoices(std::vector<string> &ps,
const std::string &name="")
{
bool ret = _get(ps, name);
for(unsigned int i = 0; i < ps.size(); i++)
ps[i].setChoices(std::vector<std::string>());
return ret;
}
}; };
// The local part of a network client. // The local part of a network client.
...@@ -1115,21 +1158,26 @@ namespace onelab{ ...@@ -1115,21 +1158,26 @@ namespace onelab{
GmshClient *_gmshClient; GmshClient *_gmshClient;
// number of subclients // number of subclients
int _numSubClients; int _numSubClients;
template <class T> bool _set(const T &p) template <class T> bool _set(const T &p, bool withChoices=true)
{ {
if(!_gmshClient) return false; if(!_gmshClient) return false;
std::string msg = p.toChar(); std::string msg = p.toChar();
_gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER, msg.size(), &msg[0]); _gmshClient->SendMessage(withChoices ? GmshSocket::GMSH_PARAMETER :
GmshSocket::GMSH_PARAMETER_WITHOUT_CHOICES,
msg.size(), &msg[0]);
return true; return true;
} }
template <class T> bool _get(std::vector<T> &ps, const std::string &name="") template <class T> bool _get(std::vector<T> &ps, const std::string &name="",
bool withChoices=true)
{ {
ps.clear(); ps.clear();
if(!_gmshClient) return false; if(!_gmshClient) return false;
T p(name); T p(name);
std::string msg = p.toChar(); std::string msg = p.toChar();
if (name.size()) if(name.size())
_gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY, msg.size(), &msg[0]); _gmshClient->SendMessage(withChoices ? GmshSocket::GMSH_PARAMETER_QUERY :
GmshSocket::GMSH_PARAMETER_QUERY_WITHOUT_CHOICES,
msg.size(), &msg[0]);
else // get all parameters else // get all parameters
_gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY_ALL, msg.size(), &msg[0]); _gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY_ALL, msg.size(), &msg[0]);
...@@ -1251,10 +1299,20 @@ namespace onelab{ ...@@ -1251,10 +1299,20 @@ namespace onelab{
{ {
return _get(ps, name); return _get(ps, name);
} }
virtual bool get(std::vector<onelab::string> &ps, const std::string &name="") virtual bool get(std::vector<string> &ps, const std::string &name="")
{ {
return _get(ps, name); return _get(ps, name);
} }
virtual bool setAndAppendChoices(const number &p){ return _set(p, false); }
virtual bool setAndAppendChoices(const string &p){ return _set(p, false); }
virtual bool getWithoutChoices(std::vector<number> &ps, const std::string &name="")
{
return _get(ps, name, false);
}
virtual bool getWithoutChoices(std::vector<string> &ps, const std::string &name="")
{
return _get(ps, name, false);
}
void sendInfo(const std::string &msg) void sendInfo(const std::string &msg)
{ {
if(_gmshClient) _gmshClient->Info(msg.c_str()); if(_gmshClient) _gmshClient->Info(msg.c_str());
......
2.13.3: new Tochnog file format export; added ability to remove last command in 2.13.3: new Tochnog file format export; added ability to remove last command in
scripts generated interactively; small ONELAB usability improvements; faster scripts generated interactively; ONELAB 1.3 with usability and performance
"Coherence Mesh". improvements; faster "Coherence Mesh".
2.13.2 (August 18, 2016)): small improvements (scale labels, periodic and 2.13.2 (August 18, 2016)): small improvements (scale labels, periodic and
high-order meshes) and bug fixes. high-order meshes) and bug fixes.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment