6 #include "GmshConfig.h"
8 #if defined(HAVE_ONELAB)
21 #if defined(HAVE_POST)
27 #if defined(HAVE_FLTK)
29 #include "onelabGroup.h"
39 std::vector<std::string> args;
40 std::string name(
c->getName());
41 std::vector<onelab::number> n;
42 c->get(n, name +
"/Use command line");
43 if(n.size() && n[0].getValue()) {
44 std::vector<onelab::string> ps;
45 c->get(ps, name +
"/Action");
46 std::string action = (ps.empty() ?
"" : ps[0].getValue());
47 c->get(ps, name +
"/Model name");
48 std::string modelName = (ps.empty() ?
"" : ps[0].getValue());
49 c->get(ps, name +
"/9CheckCommand");
50 std::string checkCommand = (ps.empty() ?
"" : ps[0].getValue());
51 c->get(ps, name +
"/9ComputeCommand");
52 std::string computeCommand = (ps.empty() ?
"" : ps[0].getValue());
53 if(modelName.size()) args.push_back(
" \"" + modelName +
"\"");
55 args.push_back(
" " + checkCommand);
56 else if(action ==
"compute")
57 args.push_back(
" " + computeCommand);
60 std::ostringstream sstream;
61 sstream.precision(16);
62 std::map<std::string, std::vector<double> > cln(
66 it != cln.end(); it++) {
67 if(it->second.size() == 1) {
68 sstream <<
" -setnumber " << it->first <<
" " << it->second[0];
71 sstream <<
" -setlistofnumbers " << it->first;
72 for(std::size_t i = 0; i < it->second.size(); i++)
73 sstream <<
" " << it->second[i];
77 for(
auto it = cls.begin();
78 it != cls.end(); it++)
79 sstream <<
" -setstring " << it->first <<
" " << it->second;
80 args.push_back(sstream.str());
88 std::vector<onelab::string> ps;
89 c->get(ps,
"Gmsh/MshFileName");
91 name = ps[0].getValue();
103 o.setAttribute(
"Closed",
"1");
122 std::vector<onelab::number> n;
123 c->get(n,
c->getName() +
"/Guess model name");
124 if(n.size() && n[0].getValue()) {
125 std::vector<onelab::string> ps;
126 c->get(ps,
c->getName() +
"/Model name");
129 std::string ext =
"";
131 if(ps.size()) ext = ps[0].getValue();
132 std::string name(split[0] + split[1] + ext);
135 o.setAttribute(
"Persistent",
"1");
137 geo += std::string(
" - ") + name;
140 geo += std::string(
" - ") + ps[0].getValue();
148 bool changed =
false;
149 std::vector<onelab::number> numbers;
151 for(std::size_t i = 0; i < numbers.size(); i++) {
152 if(numbers[i].getAttribute(
"Loop") == level) {
153 if(numbers[i].getChoices().size() > 1) {
154 numbers[i].setIndex(0);
155 numbers[i].setValue(numbers[i].getChoices()[0]);
159 else if(numbers[i].getStep() > 0) {
161 numbers[i].setValue(numbers[i].getMin());
162 numbers[i].setIndex(0);
163 std::vector<double> choices;
164 numbers[0].setChoices(choices);
169 else if(numbers[i].getStep() < 0) {
171 numbers[i].setIndex(0);
172 std::vector<double> choices;
173 numbers[0].setChoices(choices);
174 numbers[i].setValue(numbers[i].getMax());
188 const double eps = 1.e-15;
190 bool recompute =
false, loop =
false;
191 std::vector<onelab::number> numbers;
193 for(std::size_t i = 0; i < numbers.size(); i++) {
194 if(numbers[i].getAttribute(
"Loop") == level) {
197 if(numbers[i].getChoices().size() > 1) {
198 int j = numbers[i].getIndex() + 1;
199 if((j >= 0) && (j < (
int)numbers[i].getChoices().size())) {
200 numbers[i].setValue(numbers[i].getChoices()[j]);
201 numbers[i].setIndex(j);
203 Msg::Info(
"Recomputing with %dth choice %s=%g", j,
204 numbers[i].getName().c_str(), numbers[i].getValue());
208 else if(numbers[i].getStep() > 0) {
209 int j = numbers[i].getIndex() + 1;
210 double val = numbers[i].getValue() + numbers[i].getStep();
212 val <= numbers[i].getMax() * (1 + eps)) {
213 numbers[i].setValue(val);
214 numbers[i].setIndex(j);
216 Msg::Info(
"Recomputing with new step %s=%g",
217 numbers[i].getName().c_str(), numbers[i].getValue());
221 numbers[i].setIndex(numbers[i].getMax());
223 else if(numbers[i].getStep() < 0) {
224 int j = numbers[i].getIndex() + 1;
225 double val = numbers[i].getValue() + numbers[i].getStep();
227 val >= numbers[i].getMin() * (1 - eps)) {
228 numbers[i].setValue(val);
229 numbers[i].setIndex(j);
231 Msg::Info(
"Recomputing with new step %s=%g",
232 numbers[i].getName().c_str(), numbers[i].getValue());
236 numbers[i].setIndex(numbers[i].getMin());
241 if(loop && !recompute)
249 const double eps = 1.e-15;
250 std::vector<double> v;
272 bool changed =
false;
273 #if defined(HAVE_POST)
274 PView *view =
nullptr;
276 for(std::size_t i = 0; i <
PView::list.size(); i++) {
277 if(
PView::list[i]->getData()->getFileName() ==
"ONELAB" + graphNum) {
283 int num = atoi(graphNum.c_str());
284 std::vector<double> x, y;
285 std::string xName, yName;
287 std::vector<onelab::number> numbers;
289 for(std::size_t i = 0; i < numbers.size(); i++) {
290 std::string v = numbers[i].getAttribute(
"Graph");
292 if(v[2 * num] !=
'0') {
294 xName = numbers[i].getShortName();
296 if(v[2 * num + 1] !=
'0') {
298 yName = numbers[i].getShortName();
299 char t = v[2 * num + 1];
301 (t ==
'1') ? 1 : (t ==
'2') ? 2 : (t ==
'3') ? 3 : (t ==
'4') ? 4 : 3;
306 for(std::size_t i = 0; i < y.size(); i++) x.push_back(i);
308 if(x.size() && y.size()) {
309 if(x.size() != y.size())
310 Msg::Info(
"X-Y data series have different length (%d != %d)",
311 (
int)x.size(), (int)y.size());
319 view =
new PView(xName, yName, x, y);
334 static bool _firstComputation =
true;
345 std::vector<onelab::number> pn;
347 if(pn.size() && pn[0].getValue())
return redraw;
349 if(pn.size() && pn[0].getValue())
return redraw;
366 if(changed) changed = 3;
371 if(action ==
"initialize") {
374 else if(action ==
"reset") {
378 else if(action ==
"check_always") {
383 else if(action ==
"check") {
390 else if(action ==
"compute") {
398 Msg::Info(
"Skipping mesh generation: assuming '%s' is up-to-date "
399 "(use Solver.AutoMesh=2 to force mesh generation)",
400 mshFileName.c_str());
403 if(changed > 1 ||
StatFile(mshFileName) ||
433 void runClient(
const std::string &name,
const std::string &command)
440 c->runSubClient(name, command);
443 gmshLocalNetworkClient client(name, command,
"",
true);
451 std::string name, exe, host;
465 Msg::Error(
"Solver executable name not provided");
470 Msg::Error(
"Unknown client to run in batch mode (%d)", num);
482 c =
new gmshLocalNetworkClient(name, exe, host);
484 o =
c->getName() +
"/Action";
498 std::vector<std::string> split =
500 std::string db = split[0] + split[1] +
".db";
528 std::vector<std::string> split =
530 std::string db = split[0] + split[1] +
".db";
541 const bool readOnlyRange)
543 bool noRange =
true, noChoices =
true, noLoop =
true;
544 bool noGraph =
true, noClosed =
true;
566 bool noRangeEither =
true;
569 noRangeEither =
false;
577 bool isInteger = (floor(val) == val);
578 double fact = isInteger ? 5. : 20.;
589 if(val && isInteger) {
611 if(
c->getName() !=
"Gmsh" &&
c->getName() !=
"Listen" &&
612 c->getName() !=
"GmshRemote" &&
613 c->getName().find(
"NoAutoRun") == std::string::npos)
623 bool noChoices =
true, noClosed =
true, noMultipleSelection =
true;
634 if(x.
getAttribute(
"MultipleSelection").size()) noMultipleSelection =
false;
639 if(noMultipleSelection)
651 #if defined(HAVE_FLTK)
653 FlGui::instance()->rebuildTree(
false);
672 #if defined(HAVE_FLTK)
674 FlGui::instance()->rebuildTree(
false);
682 for(
int i = 0; i < 18; i++) {
683 std::ostringstream tmp;
686 redraw = redraw || ret;
690 #if defined(HAVE_FLTK)
691 FlGui::instance()->updateViews(
true,
false);
701 tm *t = localtime(&now);
704 sprintf(stamp,
"_%04d-%02d-%02d_%02d-%02d-%02d", 1900 + t->tm_year,
705 1 + t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
706 return std::string(stamp);
709 void saveDb(
const std::string &fileName)
711 FILE *fp =
Fopen(fileName.c_str(),
"wb");
713 Msg::StatusBar(
true,
"Saving database '%s'...", fileName.c_str());
716 Msg::StatusBar(
true,
"Done saving database '%s'", fileName.c_str());
719 Msg::Error(
"Could not save database '%s'", fileName.c_str());
722 fp =
Fopen((fileName +
".json").c_str(),
"wb");
726 fwrite(json.c_str(),
sizeof(
char), json.size(), fp);
735 std::vector<onelab::string> ps;
737 if(ps.size() && ps[0].getValue().size())
738 stamp.assign(
timeStamp() +
"_" + ps[0].getValue());
743 std::vector<onelab::string> strings;
745 for(std::size_t i = 0; i < strings.size(); i++) {
746 if(strings[i].getName().find(
"9Output files") != std::string::npos) {
747 std::vector<std::string> names = strings[i].getChoices();
748 names.push_back(strings[i].getValue());
749 for(std::size_t j = 0; j < names.size(); j++) {
751 int n = split[1].size();
753 if(n < 18 || split[1][n - 3] !=
'-' || split[1][n - 6] !=
'-' ||
754 split[1][n - 9] !=
'_') {
755 std::string old = names[j];
757 names[j] = split[0] +
"archive/" + split[1] + stamp + split[2];
758 Msg::Info(
"Renaming '%s' into '%s'", old.c_str(), names[j].c_str());
759 rename(old.c_str(), names[j].c_str());
762 strings[i].setValue(names.back());
764 strings[i].setChoices(names);
773 saveDb(split[0] +
"archive/" + split[1] + stamp + split[2]);
776 #if defined(HAVE_FLTK)
777 FlGui::instance()->rebuildTree(
true);
785 std::string dir = split[0] +
"archive/";
786 std::string tag = split[1];
787 if(!tag.compare(0, 6,
"onelab"))
788 tag.assign(tag.substr(6));
791 std::vector<onelab::string> strings;
794 std::vector<std::string> names = strings[0].getChoices();
796 for(std::size_t j = 0; j < names.size(); j++) {
798 std::string old = names[j];
800 names[j] = dir + split[1] + tag + split[2];
801 Msg::Info(
"Renaming '%s' into '%s'", old.c_str(), names[j].c_str());
802 rename(old.c_str(), names[j].c_str());
804 strings[0].setValue(names[0]);
805 strings[0].setChoices(names);
807 #if defined(HAVE_FLTK)
808 FlGui::instance()->rebuildTree(
true);
814 void loadDb(
const std::string &name)
817 FILE *fp =
Fopen(name.c_str(),
"rb");
824 Msg::Error(
"Could not load database '%s'", name.c_str());
832 std::vector<onelab::number> allNumbers, persistentNumbers;
833 std::vector<onelab::string> allStrings, persistentStrings;
836 bool ismetamodel =
false;
837 for(std::size_t i = 0; i < allNumbers.size(); i++) {
838 if(allNumbers[i].getAttribute(
"Persistent") ==
"1")
839 persistentNumbers.push_back(allNumbers[i]);
841 if(allNumbers[i].getName() ==
"IsMetamodel" ||
842 allNumbers[i].getName() ==
"IsPyMetamodel"){
843 ismetamodel = allNumbers[i].getValue() ? true :
false;
844 persistentNumbers.push_back(allNumbers[i]);
847 for(std::size_t i = 0; i < allStrings.size(); i++) {
848 if(allStrings[i].getAttribute(
"Persistent") ==
"1")
849 persistentStrings.push_back(allStrings[i]);
862 for(std::size_t i = 0; i < persistentNumbers.size(); i++) {
863 Msg::Debug(
"Restoring persistent parameter %s",
864 persistentNumbers[i].getName().c_str());
867 for(std::size_t i = 0; i < persistentStrings.size(); i++) {
868 Msg::Debug(
"Restoring persistent parameter %s",
869 persistentStrings[i].getName().c_str());