Skip to content
Snippets Groups Projects
Commit 876e2e1d authored by Francois Henrotte's avatar Francois Henrotte
Browse files

No commit message

No commit message
parent 90883816
No related branches found
No related tags found
No related merge requests found
......@@ -666,12 +666,11 @@ public:
localGmsh() : onelab::localClient("Gmsh") {}
void sendMergeFileRequest(const std::string &name)
{
MergePostProcessingFile(name, CTX::instance()->solver.autoShowLastStep,
CTX::instance()->solver.autoHideNewViews, true);
if(name.find(".geo")!= std::string::npos){
GModel::current()->setFileName(name);
}
else
MergePostProcessingFile(name, CTX::instance()->solver.autoShowLastStep,
CTX::instance()->solver.autoHideNewViews, true);
}
void sendInfo(const std::string &msg){ Msg::Info("%s", msg.c_str()); }
void sendWarning(const std::string &msg){ Msg::Warning("%s", msg.c_str()); }
......@@ -734,7 +733,7 @@ void Msg::ExchangeOnelabParameter(const std::string &key,
bool noRange = true, noChoices = true, noLoop = true;
bool noGraph = true, noClosed = true;
if(ps.size()){
if(!ps[0].getReadOnly())
//if(!ps[0].getReadOnly())
val[0] = ps[0].getValue(); // use value from server
// keep track of these attributes, which can be changed server-side
if(ps[0].getMin() != -onelab::parameter::maxNumber() ||
......
......@@ -544,10 +544,8 @@ void onelab_cb(Fl_Widget *w, void *data)
if(isMetamodel){
#if defined(HAVE_ONELAB_METAMODEL)
metamodel(action);
geometry_reload_cb(0, 0);
//std::cout << "FHFap:" << GModel::current()->getFileName() << std::endl;
//std::cout << "FHFap:" << GModel::current()->getName() << std::endl;
if(metamodel(action))
geometry_reload_cb(0, 0);
#endif
}
else{
......
......@@ -59,15 +59,9 @@ class onelabMetaModelServer : public GmshServer{
// return immediately, i.e., do polling)
int ret = Select(0, 0, socket);
if(ret == 0){ // nothing available
// if asked, refresh the onelab GUI
std::vector<onelab::string> ps;
onelab::server::instance()->get(ps, "Gmsh/Action");
if(ps.size() && ps[0].getValue() == "refresh"){
ps[0].setVisible(false);
ps[0].setValue("");
onelab::server::instance()->set(ps[0]);
//onelab_cb(0, (void*)"refresh");
}
//FlGui::instance()->wait(waitint);
void (*waitFct)(double) = OLMsg::GetGuiWaitFunction();
if(waitFct) waitFct(waitint);
}
else if(ret > 0){
return 0; // data is there!
......@@ -361,6 +355,18 @@ std::string localSolverClient::toChar(){
return sstream.str();
}
const std::string localSolverClient::getString(const std::string what){
std::string name=getName() + "/" + what;
std::vector<onelab::string> strings;
get(strings, name);
if(strings.size())
return strings[0].getValue();
else{
//OLMsg::Info("Undefined parameter <%s> in getString", name.c_str());
return "";
}
}
void localSolverClient::setAction(const std::string action){
std::string name=getName() + "/Action";
onelab::string s(name, action);
......@@ -369,15 +375,6 @@ void localSolverClient::setAction(const std::string action){
set(s);
}
const std::string localSolverClient::getString(const std::string what){
std::vector<onelab::string> strings;
get(strings, getName() + "/" + what);
if(strings.size())
return strings[0].getValue();
else
return "";
}
const bool localSolverClient::getList(const std::string type, std::vector<std::string> &choices){
std::vector<onelab::string> strings;
get(strings, getName() + "/" + type);
......@@ -391,9 +388,6 @@ const bool localSolverClient::getList(const std::string type, std::vector<std::s
bool localSolverClient::checkCommandLine(){
OLMsg::Info("Check command line for <%s>",getName().c_str());
// if(getCommandLine().empty()){
// // look if one has a commandLine on server
// std::string commandLine = getString("CommandLine");
if(getCommandLine().empty())
OLMsg::Fatal("No commandline for client <%s>", getName().c_str());
......@@ -620,17 +614,28 @@ bool MetaModel::checkCommandLines(){
return allDefined;
}
void MetaModel::initialize()
void MetaModel::construct()
{
OLMsg::Info("Initialize Metamodel by the loader");
OLMsg::SetOnelabString(clientName + "/9CheckCommand","-a",false);
OLMsg::SetOnelabNumber(clientName + "/UseCommandLine",1,false);
OLMsg::SetOnelabNumber(clientName + "/Initialized",1,false);
OLMsg::Info("Metamodel now CONSTRUCTING");
openOnelabBlock();
parse_onefile( genericNameFromArgs + onelabExtension + ".save",false);
parse_onefile( genericNameFromArgs + onelabExtension);
closeOnelabBlock();
}
// void MetaModel::initialize()
// {
// OLMsg::Info("Metamodel now INITIALIZING");
// OLMsg::Info("Initialize Metamodel by the loader");
// OLMsg::SetOnelabString(clientName + "/9CheckCommand","-a",false);
// OLMsg::SetOnelabNumber(clientName + "/UseCommandLine",1,false);
// OLMsg::SetOnelabNumber(clientName + "/Initialized",1,false);
// }
void MetaModel::analyze() {
OLMsg::Info("Metamodel now ANALYZING");
std::string fileName = genericNameFromArgs + onelabExtension;
OLMsg::Info("Metamodel now ANALYZING",fileName.c_str());
openOnelabBlock();
parse_onefile(fileName);
closeOnelabBlock();
......@@ -638,8 +643,8 @@ void MetaModel::analyze() {
void MetaModel::compute() {
OLMsg::Info("Metamodel now COMPUTING");
std::string fileName = genericNameFromArgs + onelabExtension;
OLMsg::Info("Metamodel now COMPUTING",fileName.c_str());
openOnelabBlock();
parse_onefile(fileName);
closeOnelabBlock();
......@@ -696,7 +701,7 @@ void InterfacedClient::analyze() {
std::vector<std::string> choices;
setAction("check");
OLMsg::Info("Analyses <%s> changed=%d", getName().c_str(),
OLMsg::Info("Analyze <%s> changed=%d", getName().c_str(),
onelab::server::instance()->getChanged(getName()));
getList("InputFiles", choices);
for(unsigned int i = 0; i < choices.size(); i++){
......@@ -775,7 +780,7 @@ void InterfacedClient::compute(){
void NativeClient::analyze() {
setAction("check");
OLMsg::Info("Analyses <%s> changed=%d", getName().c_str(),
OLMsg::Info("Analyze <%s> changed=%d", getName().c_str(),
onelab::server::instance()->getChanged(getName()));
run();
}
......@@ -819,7 +824,7 @@ void EncapsulatedClient::analyze() {
std::vector<std::string> choices;
setAction("check");
OLMsg::Info("Analyses <%s> changed=%d", getName().c_str(),
OLMsg::Info("Analyze <%s> changed=%d", getName().c_str(),
onelab::server::instance()->getChanged(getName()));
getList("InputFiles", choices);
for(unsigned int i = 0; i < choices.size(); i++){
......@@ -861,7 +866,7 @@ void EncapsulatedClient::compute(){
std::string cmd;
std::vector<std::string> choices;
setAction("compute");
//setAction("compute");
std::string name=getName();
OLMsg::Info("Computes <%s> changed=%d", name.c_str(),
onelab::server::instance()->getChanged(name));
......@@ -958,7 +963,7 @@ void RemoteNativeClient::analyze(){
std::vector<std::string> choices;
setAction("check");
OLMsg::Info("Analyses <%s> changed=%d", getName().c_str(),
OLMsg::Info("Analyze <%s> changed=%d", getName().c_str(),
onelab::server::instance()->getChanged(getName()));
if(getList("InputFiles",choices)){
......@@ -974,7 +979,7 @@ void RemoteNativeClient::compute(){
std::vector<std::string> choices;
setAction("compute");
OLMsg::Info("Analyses <%s> changed=%d", getName().c_str(),
OLMsg::Info("Analyze <%s> changed=%d", getName().c_str(),
onelab::server::instance()->getChanged(getName()));
if(getActive() && onelab::server::instance()->getChanged(getName())){
......
......@@ -227,11 +227,8 @@ class MetaModel : public localSolverClient {
clientName = cname;
genericNameFromArgs = fname.size() ? fname : cmdl;
setWorkingDir(wdir); // wdir from args
openOnelabBlock();
_todo=REGISTER;
parse_onefile( genericNameFromArgs + onelabExtension + ".save",false);
parse_onefile( genericNameFromArgs + onelabExtension);
closeOnelabBlock();
construct();
}
~MetaModel(){}
typedef std::vector<localSolverClient*>::iterator citer;
......@@ -252,12 +249,13 @@ class MetaModel : public localSolverClient {
if(_clients[i]->getName() == name) return _clients[i];
return 0;
}
std::string genericNameFromArgs, clientName;
void client_sentence(const std::string &name, const std::string &action,
const std::vector<std::string> &arguments);
std::string toChar(){}
void PostArray(std::vector<std::string> choices);
void initialize();
void construct();
void analyze();
void compute();
};
......
......@@ -31,6 +31,8 @@ GmshClient *OLMsg::_client = 0;
onelab::client *OLMsg::_onelabClient = 0;
bool OLMsg::hasGmsh=false;
std::set<std::string, fullNameLessThan> OLMsg::_fullNameDict;
void (*OLMsg::gui_wait_fct)(double time) = 0;
#if defined(HAVE_NO_VSNPRINTF)
static int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
......@@ -215,19 +217,6 @@ void OLMsg::StatusBar(int num, bool log, const char *fmt, ...)
}
}
// void OLMsg::InitializeOnelab(const std::string &name, const std::string &sockname)
// {
// if(_onelabClient) delete _onelabClient;
// if (sockname.empty())
// _onelabClient = new onelab::localClient(name);
// else{
// onelab::remoteNetworkClient *c =
// new onelab::remoteNetworkClient(name, sockname);
// _onelabClient = c;
// _client = c->getGmshClient();
// }
// }
void OLMsg::InitializeOnelab(const std::string &name)
{
if(_onelabClient) delete _onelabClient;
......@@ -235,6 +224,12 @@ void OLMsg::InitializeOnelab(const std::string &name)
OLMsg::hasGmsh = OLMsg::GetOnelabNumber("IsMetamodel");
}
void OLMsg::SetGuiWaitFunction(void (*fct)(double time)){
gui_wait_fct = fct;
}
void (*OLMsg::GetGuiWaitFunction())(double){
return gui_wait_fct;
}
double OLMsg::GetOnelabNumber(std::string name)
{
......@@ -391,13 +386,38 @@ std::string OLMsg::obtainFullName(const std::string &name){
}
void OLMsg::MergeFile(const std::string &name){
if(_onelabClient)
_onelabClient->sendMergeFileRequest(name);
//This routine allows sending input files (geo, pos, msh) to Gmsh
//The parameter Gmsh/MergedGeo ensures that only one geometry
//is sent to Gmsh. It is reloaded afted each metamodel execution
//
if(_onelabClient){
if(name.find(".geo") != std::string::npos){
if(GetOnelabString("Gmsh/MergedGeo").empty()){
SetOnelabString("Gmsh/MergedGeo",name,false);
Info("Merge a geometry <%s> to Gmsh", name.c_str());
_onelabClient->sendMergeFileRequest(name);
}
}
else{
Info("Merge a geometry <%s> to Gmsh", name.c_str());
_onelabClient->sendMergeFileRequest(name);
}
}
else
OLMsg::Info("Not connected to Gmsh");
}
void OLMsg::FinalizeOnelab(){
if(_onelabClient){
delete _onelabClient;
_onelabClient = 0;
_client = 0;
}
}
// void OLMsg::AddOnelabNumberChoice(std::string name, double val)
// {
// if(_onelabClient){
......@@ -417,186 +437,3 @@ void OLMsg::MergeFile(const std::string &name){
// _onelabClient->set(ps[0]);
// }
// }
void OLMsg::FinalizeOnelab(){
if(_onelabClient){
delete _onelabClient;
_onelabClient = 0;
_client = 0;
}
}
/*
void OLMsg::Debug(const char *fmt, ...)
{
if(_verbosity < 99) return;
char str[1024];
va_list args;
va_start(args, fmt);
vsnprintf(str, sizeof(str), fmt, args);
va_end(args);
if(_callback) (*_callback)("Debug", str);
if(_client) _client->Info(str);
if(ALWAYS_TRUE){
if(_commSize > 1)
fprintf(stdout, "Debug : [On processor %d] %s\n", _commRank, str);
else
fprintf(stdout, "Debug : %s\n", str);
fflush(stdout);
}
}
void OLMsg::ProgressMeter(int n, int N, const char *fmt, ...)
{
if(_commRank || _verbosity < 3) return;
double percent = 100. * (double)n/(double)N;
if(percent >= _progressMeterCurrent){
char str[1024];
va_list args;
va_start(args, fmt);
vsnprintf(str, sizeof(str), fmt, args);
va_end(args);
if(strlen(fmt)) strcat(str, " ");
char str2[1024];
sprintf(str2, "(%d %%)", _progressMeterCurrent);
strcat(str, str2);
if(_client) _client->Progress(str);
if(ALWAYS_TRUE){
fprintf(stdout, "%s \r", str);
fflush(stdout);
}
while(_progressMeterCurrent < percent)
_progressMeterCurrent += _progressMeterStep;
}
if(n > N - 1){
if(_client) _client->Progress("Done!");
if(ALWAYS_TRUE){
fprintf(stdout, "Done! \r");
fflush(stdout);
}
}
}
void OLMsg::PrintTimers()
{
// do a single stdio call!
std::string str;
for(std::map<std::string, double>::iterator it = _timers.begin();
it != _timers.end(); it++){
if(it != _timers.begin()) str += ", ";
char tmp[256];
sprintf(tmp, "%s = %gs ", it->first.c_str(), it->second);
str += std::string(tmp);
}
if(!str.size()) return;
if(ALWAYS_TRUE){
if(_commSize > 1)
fprintf(stdout, "Timers : [On processor %d] %s\n", _commRank, str.c_str());
else
fprintf(stdout, "Timers : %s\n", str.c_str());
fflush(stdout);
}
}
void OLMsg::PrintErrorCounter(const char *title)
{
if(_commRank || _verbosity < 1) return;
if(!_warningCount && !_errorCount) return;
std::string prefix = _errorCount ? "Error : " : "Warning : ";
std::string help("Check the full log for details");
std::string line(std::max(strlen(title), help.size()), '-');
char warn[128], err[128];
sprintf(warn, "%5d warning%s", _warningCount, _warningCount == 1 ? "" : "s");
sprintf(err, "%5d error%s", _errorCount, _errorCount == 1 ? "" : "s");
if(ALWAYS_TRUE){
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", (prefix + line).c_str(),
(prefix + title).c_str(), (prefix + warn).c_str(),
(prefix + err).c_str(), (prefix + help).c_str(),
(prefix + line).c_str());
fflush(stderr);
}
}
double OLMsg::GetValue(const char *text, double defaultval)
{
printf("%s (default=%.16g): ", text, defaultval);
char str[256];
char *ret = fgets(str, sizeof(str), stdin);
if(!ret || !strlen(str) || !strcmp(str, "\n"))
return defaultval;
else
return atof(str);
}
std::string OLMsg::GetString(const char *text, std::string defaultval)
{
printf("%s (default=%s): ", text, defaultval.c_str());
char str[256];
char *ret = fgets(str, sizeof(str), stdin);
if(!ret || !strlen(str) || !strcmp(str, "\n"))
return defaultval;
else
return std::string(str);
}
int OLMsg::GetAnswer(const char *question, int defaultval, const char *zero,
const char *one, const char *two)
{
if(two)
printf("%s\n\n0=[%s] 1=[%s] 2=[%s] (default=%d): ", question,
zero, one, two, defaultval);
else
printf("%s\n\n0=[%s] 1=[%s] (default=%d): ", question,
zero, one, defaultval);
char str[256];
char *ret = fgets(str, sizeof(str), stdin);
if(!ret || !strlen(str) || !strcmp(str, "\n"))
return defaultval;
else
return atoi(ret);
}
void OLMsg::InitClient(std::string sockname)
{
if(_client) delete _client;
_client = new GmshClient();
if(_client->Connect(sockname.c_str()) < 0){
OLMsg::Error("Unable to connect to server on %s", sockname.c_str());
delete _client;
_client = 0;
}
else
_client->Start();
}
void OLMsg::Barrier()
{
}
void OLMsg::FinalizeClient()
{
if(_client){
_client->Stop();
_client->Disconnect();
delete _client;
}
_client = 0;
}
*/
......@@ -54,6 +54,8 @@ class OLMsg {
static onelab::client *_onelabClient;
// dictionnary for parameter names
static std::set<std::string, fullNameLessThan> _fullNameDict;
// Gmsh wait function
static void (*gui_wait_fct)(double time);
public:
OLMsg() {}
static void Init(int argc, char **argv);
......@@ -92,8 +94,10 @@ class OLMsg {
static int GetAnswer(const char *question, int defaultval, const char *zero,
const char *one, const char *two=0);
//static void InitClient(std::string sockname);
static GmshClient *GetClient(){ return _client; }
//static void FinalizeClient();
static GmshClient *GetClient(){ return _client; }
static void SetGuiWaitFunction(void (*fct)(double time));
static void (*GetGuiWaitFunction())(double);
static void InitializeOnelab(const std::string &name);
static void FinalizeOnelab();
......
......@@ -797,12 +797,8 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
if(enclosed(line.substr(cursor),arguments,pos)<1)
OLMsg::Fatal("Misformed <%s> statement: (%s)",
olkey::showGmsh.c_str(),line.c_str());
if (OLMsg::GetOnelabString(getName()+"/MergedGeo").empty()){
std::string fileName=resolveGetVal(arguments[0]);
OLMsg::MergeFile(fileName);
OLMsg::SetOnelabString(getName()+"/MergedGeo",fileName);
OLMsg::Info("Merge a geometry <%s> to Gmsh", fileName.c_str());
}
std::string fileName=resolveGetVal(arguments[0]);
OLMsg::MergeFile(fileName);
}
else if ( (pos=line.find(olkey::dump)) != std::string::npos) {
// onelab.dump
......@@ -1302,24 +1298,6 @@ void MetaModel::client_sentence(const std::string &name,
}
}
}
else if(!action.compare("check")){
localSolverClient *c;
if(c=findClientByName(name)){
c->checkCommandLine();
c->analyze();
}
else
OLMsg::Fatal("Unknown client <%s>", name.c_str());
}
else if(!action.compare("compute")){
localSolverClient *c;
if(c=findClientByName(name)){
c->checkCommandLine();
c->compute();
}
else
OLMsg::Fatal("Unknown client <%s>", name.c_str());
}
else if(!action.compare("up")){
if(arguments.size()%4==0){
if(isTodo(REGISTER)){
......@@ -1354,6 +1332,29 @@ void MetaModel::client_sentence(const std::string &name,
OLMsg::Fatal("Wrong number of arguments <%d> for <%s>",
arguments.size(), action.c_str());
}
else if(!action.compare("check")){
localSolverClient *c;
if(c=findClientByName(name)){
c->checkCommandLine();
c->analyze();
}
else
OLMsg::Fatal("Unknown client <%s>", name.c_str());
}
else if(!action.compare("compute")){
localSolverClient *c;
if(c=findClientByName(name)){
c->checkCommandLine();
if(isTodo(REGISTER))
c->analyze(); // computes nothing at registration
else{
c->compute();
onelab::server::instance()->setChanged(false, c->getName());
}
}
else
OLMsg::Fatal("Unknown client <%s>", name.c_str());
}
else if(!action.compare("merge")){
if(isTodo(COMPUTE)){
std::vector<std::string> choices;
......@@ -1361,7 +1362,30 @@ void MetaModel::client_sentence(const std::string &name,
choices.push_back(resolveGetVal(arguments[i]));
}
localSolverClient *c;
if(c=findClientByName(name)) c->GmshMerge(choices);
if(c=findClientByName(name)) {
OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",1,false);
c->GmshMerge(choices);
}
}
}
else if(!action.compare("computeMerge")){
std::vector<std::string> choices;
for(unsigned int i = 0; i < arguments.size(); i++){
choices.push_back(resolveGetVal(arguments[i]));
}
localSolverClient *c;
if(c=findClientByName(name)) {
c->checkCommandLine();
if(isTodo(REGISTER))
c->analyze(); // computes nothing at registration
else{
if(onelab::server::instance()->getChanged(c->getName())){
c->compute();
c->GmshMerge(choices);
OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",1,false);
onelab::server::instance()->setChanged(false, c->getName());
}
}
}
}
else
......
#include "OnelabClients.h"
#include "metamodel.h"
void (*my_gui_wait_fct)(double time) = 0;
void initializeMetamodel(onelab::client *client, void (*gui_wait_fct)(double time))
{
......@@ -9,8 +8,10 @@ void initializeMetamodel(onelab::client *client, void (*gui_wait_fct)(double tim
//copies the Msg::_onelabClient to OLMsg::_onelabClient
//This pointer refers to an object of class localGmsh() (cf GmshMessage.cpp)
//which is a onelab::client with sone Gmsh features (merge and messages).
//Initilizes also the wait function the Gmsh Gui
//so that Gmsh windows may remain active during client computations.
OLMsg::SetOnelabClient(client);
my_gui_wait_fct = gui_wait_fct;
OLMsg::SetGuiWaitFunction(gui_wait_fct);
}
int metamodel(const std::string &action){
......@@ -51,9 +52,6 @@ int metamodel(const std::string &action){
if( myModel->isTodo(EXIT)){
// exit metamodel
}
else if( myModel->isTodo(INITIALIZE)){
myModel->initialize();
}
else if( myModel->isTodo(ANALYZE)){
myModel->analyze();
}
......@@ -62,8 +60,13 @@ int metamodel(const std::string &action){
}
else
OLMsg::Fatal("Main: Unknown Action <%d>", todo);
delete myModel;
OLMsg::Info("Leave metamodel");
int reload=OLMsg::GetOnelabNumber("Gmsh/NeedReloadGeom");
OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",0,false);
OLMsg::Info("Leave metamodel - need reload=%d",reload);
OLMsg::Info("==============================================");
return reload;
}
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