6 #include "GmshConfig.h"
12 #if !defined(WIN32) || defined(__CYGWIN__)
33 #if defined(HAVE_ONELAB)
40 #if defined(HAVE_PETSC)
44 #if defined(HAVE_SLEPC)
48 #if defined(HAVE_FLTK)
49 #include <FL/fl_ask.H>
51 #include "extraDialogs.h"
81 #if defined(HAVE_ONELAB)
88 #if defined(_MSC_VER) && (_MSC_VER >= 1310) //NET 2003
89 #define vsnprintf _vsnprintf
91 #if defined(HAVE_NO_VSNPRINTF)
92 static int vsnprintf(
char *str,
size_t size,
const char *fmt, va_list ap)
94 if (strlen(fmt) > size - 1) {
95 strncpy(str, fmt, size - 1);
99 return vsprintf(str, fmt, ap);
109 if(tmp.find(gmshPath) != std::string::npos)
return;
116 path = tmp +
";" + gmshPath;
118 path = tmp +
":" + gmshPath;
128 #if defined(HAVE_MPI)
130 MPI_Initialized(&flag);
131 if(!flag) MPI_Init(&argc, &argv);
132 MPI_Comm_rank(MPI_COMM_WORLD, &
_commRank);
133 MPI_Comm_size(MPI_COMM_WORLD, &
_commSize);
134 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
136 #if defined(HAVE_PETSC)
138 char **sargv =
new char*[argc + 1];
140 for(
int i = 0; i < argc; i++){
141 std::string val(argv[i]);
142 if(val !=
"-info" && val !=
"-help" && val !=
"-version" && val !=
"-v")
143 sargv[sargc++] = argv[i];
145 sargv[sargc] =
nullptr;
146 PetscInitialize(&sargc, &sargv, PETSC_NULL, PETSC_NULL);
147 PetscPopSignalHandler();
148 #if defined(HAVE_SLEPC)
149 SlepcInitialize(&sargc, &sargv, PETSC_NULL, PETSC_NULL);
158 bool _env =
true, _locale =
true;
160 for(
int i = 0; i < argc; i++) {
183 std::setlocale(LC_ALL,
"C.UTF-8");
184 std::setlocale(LC_NUMERIC,
"C");
203 #if defined(HAVE_SLEPC)
206 #if defined(HAVE_PETSC)
210 #if defined(HAVE_MPI)
212 MPI_Finalized(&finalized);
266 Msg::Error(
"Could not open file '%s'", name.c_str());
322 #if defined(HAVE_FLTK)
323 if(FlGui::available()){
324 FlGui::instance()->setProgress(
"", 0, 0, 1);
377 #if defined(HAVE_ONELAB)
380 return _onelabClient;
387 #if defined(HAVE_MPI)
388 if(level) MPI_Abort(MPI_COMM_WORLD, level);
396 struct stat stream_stat;
397 if(fstat(fileno(stream), &stream_stat) == 0){
398 if(stream_stat.st_mode & S_IFREG)
return 1;
406 #if !defined(WIN32) || defined(__CYGWIN__)
407 return isatty(fileno(stream));
413 const char* emacs = getenv(
"EMACS");
414 if(emacs && *emacs ==
't')
return 0;
417 static const char* names[] =
418 {
"Eterm",
"ansi",
"color-xterm",
"con132x25",
"con132x30",
"con132x43",
419 "con132x60",
"con80x25",
"con80x28",
"con80x30",
"con80x43",
"con80x50",
420 "con80x60",
"cons25",
"console",
"cygwin",
"dtterm",
"eterm-color",
"gnome",
421 "gnome-256color",
"konsole",
"konsole-256color",
"kterm",
"linux",
"msys",
422 "linux-c",
"mach-color",
"mlterm",
"putty",
"rxvt",
"rxvt-256color",
423 "rxvt-cygwin",
"rxvt-cygwin-native",
"rxvt-unicode",
"rxvt-unicode-256color",
424 "screen",
"screen-256color",
"screen-256color-bce",
"screen-bce",
"screen-w",
425 "screen.linux",
"vt100",
"xterm",
"xterm-16color",
"xterm-256color",
426 "xterm-88color",
"xterm-color",
"xterm-debian",
nullptr};
427 const char** t =
nullptr;
428 const char* term = getenv(
"TERM");
430 for(t = names; *t && strcmp(term, *t) != 0; ++t) {}
432 if(!(t && *t))
return 0;
437 bool printCpu,
bool printMem)
441 std::string pdate =
"";
446 pdate.resize(pdate.size() - 1);
447 if(printWallTime || printCpu || (printMem && mem))
451 std::string pwall =
"";
456 if(printCpu || (printMem && mem))
460 std::string pcpu =
"";
463 sprintf(tmp,
"CPU %gs",
Cpu());
469 std::string pmem =
"";
472 sprintf(tmp,
"Mem %gMb", (
double)mem / 1024. / 1024.);
477 if(pdate.size() || pwall.size() || pcpu.size() || pmem.size())
478 str +=
" (From start: " + pdate + pwall + pcpu + pmem +
")";
484 #pragma omp critical(MsgError)
492 vsnprintf(str,
sizeof(str), fmt, args);
494 int l = strlen(str);
if(str[l - 1] ==
'\n') str[l - 1] =
'\0';
496 #pragma omp critical(MsgError)
504 if(
_callback) (*_callback)(
"Error", str);
506 #if defined(HAVE_FLTK)
507 if(FlGui::available()){
508 std::string tmp = std::string(
CTX::instance()->guiColorScheme ?
"@B72@." :
"@C1@.")
510 FlGui::instance()->addMessage(tmp.c_str());
511 FlGui::instance()->setLastStatus
517 const char *c0 =
"", *
c1 =
"";
519 c0 =
"\33[1m\33[31m";
c1 =
"\33[0m";
522 fprintf(stderr,
"%sError : [rank %3d] %s%s\n", c0,
GetCommRank(), str,
c1);
524 fprintf(stderr,
"%sError : %s%s\n", c0, str,
c1);
530 #if defined(HAVE_FLTK)
531 if(FlGui::available())
return;
545 #pragma omp critical(MsgWarning)
555 vsnprintf(str,
sizeof(str), fmt, args);
557 int l = strlen(str);
if(str[l - 1] ==
'\n') str[l - 1] =
'\0';
560 if(
_callback) (*_callback)(
"Warning", str);
563 #if defined(HAVE_FLTK)
564 if(FlGui::available()){
565 std::string tmp = std::string(
CTX::instance()->guiColorScheme ?
"@B152@." :
"@C5@.")
566 +
"Warning : " + str;
567 FlGui::instance()->addMessage(tmp.c_str());
569 FlGui::instance()->setLastStatus();
575 const char *c0 =
"", *
c1 =
"";
577 c0 =
"\33[35m";
c1 =
"\33[0m";
580 fprintf(stderr,
"%sWarning : [rank %3d] %s%s\n", c0,
GetCommRank(), str,
c1);
582 fprintf(stderr,
"%sWarning : %s%s\n", c0, str,
c1);
594 vsnprintf(str,
sizeof(str), fmt, args);
596 int l = strlen(str);
if(str[l - 1] ==
'\n') str[l - 1] =
'\0';
600 strcat(str, res.c_str());
607 #if defined(HAVE_FLTK)
608 if(FlGui::available()){
609 std::string tmp = std::string(
"Info : ") + str;
610 FlGui::instance()->addMessage(tmp.c_str());
619 fprintf(stdout,
"Info : [%3d%%] %s\n", p, str);
622 fprintf(stdout,
"Info : [rank %3d] %s\n",
GetCommRank(), str);
624 fprintf(stdout,
"Info : %s\n", str);
631 if(
_callback) (*_callback)(
"RequestRender",
"");
641 vsnprintf(str,
sizeof(str), fmt, args);
643 int l = strlen(str);
if(str[l - 1] ==
'\n') str[l - 1] =
'\0';
646 if(
_callback) (*_callback)(
"Direct", str);
649 #if defined(HAVE_FLTK)
650 if(FlGui::available()){
651 std::string tmp = std::string(
CTX::instance()->guiColorScheme ?
"@B136@." :
"@C4@.")
653 FlGui::instance()->addMessage(tmp.c_str());
659 const char *c0 =
"", *
c1 =
"";
661 c0 =
"\33[34m";
c1 =
"\33[0m";
664 fprintf(stdout,
"%s[rank %3d] %s%s\n", c0,
GetCommRank(), str,
c1);
666 fprintf(stdout,
"%s%s%s\n", c0, str,
c1);
676 vsnprintf(str,
sizeof(str), fmt, args);
678 if(strstr(str,
"Error") || strstr(str,
"error") || strstr(str,
"ERROR"))
680 else if(strstr(str,
"Warning") || strstr(str,
"warning") || strstr(str,
"WARNING"))
693 vsnprintf(str,
sizeof(str), fmt, args);
695 int l = strlen(str);
if(str[l - 1] ==
'\n') str[l - 1] =
'\0';
699 strcat(str, res.c_str());
703 if(
_callback && log) (*_callback)(
"Info", str);
706 #if defined(HAVE_FLTK)
707 if(FlGui::available()){
709 FlGui::instance()->setStatus(str);
711 std::string tmp = std::string(
"Info : ") + str;
712 FlGui::instance()->addMessage(tmp.c_str());
720 fprintf(stdout,
"Info : [rank %3d] %s\n",
GetCommRank(), str);
722 fprintf(stdout,
"Info : %s\n", str);
729 #if defined(HAVE_FLTK)
734 vsnprintf(str,
sizeof(str), fmt, args);
736 int l = strlen(str);
if(str[l - 1] ==
'\n') str[l - 1] =
'\0';
738 if(FlGui::available())
739 FlGui::instance()->setStatus(str,
true);
745 #if defined(HAVE_FLTK)
746 if(FlGui::available()){
747 FlGui::instance()->setGraphicTitle(title);
759 vsnprintf(str,
sizeof(str), fmt, args);
761 int l = strlen(str);
if(str[l - 1] ==
'\n') str[l - 1] =
'\0';
764 if(
_callback) (*_callback)(
"Debug", str);
767 #if defined(HAVE_FLTK)
768 if(FlGui::available()){
769 std::string tmp = std::string(
"Debug : ") + str;
770 FlGui::instance()->addMessage(tmp.c_str());
776 fprintf(stdout,
"Debug : [rank %3d] %s\n",
GetCommRank(), str);
778 fprintf(stdout,
"Debug : %s\n", str);
786 if(_progressMeterStep <= 0 || _progressMeterStep >= 100)
return;
790 double percent = 100. * (double)n / (
double)N;
795 if(p >= 100) p = 100;
802 char str[5000], str2[5100];
805 vsnprintf(str,
sizeof(str), fmt, args);
807 int l = strlen(str);
if(str[l - 1] ==
'\n') str[l - 1] =
'\0';
808 sprintf(str2,
"Info : [%3d%%] %s", p, str);
812 #if defined(HAVE_FLTK)
814 FlGui::instance()->setProgress(str, (n > N - 1) ? 0 : n, 0, N);
819 if(
_callback) (*_callback)(
"Progress", str);
821 fprintf(stdout,
"%s \r",
822 (n > N - 1) ?
"" : str2);
834 if(it !=
_timers.begin()) str +=
", ";
836 sprintf(tmp,
"%s = %gs ", it->first.c_str(), it->second);
837 str += std::string(tmp);
839 if(!str.size())
return;
843 fprintf(stdout,
"Timers : [rank %3d] %s\n",
GetCommRank(), str.c_str());
845 fprintf(stdout,
"Timers : %s\n", str.c_str());
854 #if defined(HAVE_FLTK)
855 if(FlGui::available()) FlGui::instance()->setLastStatus();
864 std::string prefix =
GetErrorCount() ?
"Error : " :
"Warning : ";
865 std::string help(
"Check the full log for details");
866 std::string
line(std::max(strlen(title), help.size()),
'-');
867 char warn[128], err[128];
871 #if defined(HAVE_FLTK)
872 if(FlGui::available()){
874 std::string(
CTX::instance()->guiColorScheme ?
"@B72@." :
"@C1@.") :
875 std::string(
CTX::instance()->guiColorScheme ?
"@B152@." :
"@C5@.");
876 FlGui::instance()->addMessage((col + prefix +
line).c_str());
877 FlGui::instance()->addMessage((col + prefix + title).c_str());
878 FlGui::instance()->addMessage((col + prefix + warn).c_str());
879 FlGui::instance()->addMessage((col + prefix + err).c_str());
880 FlGui::instance()->addMessage((col + prefix + help).c_str());
881 FlGui::instance()->addMessage((col + prefix +
line).c_str());
887 const char *c0 =
"", *
c1 =
"";
892 fprintf(stderr,
"%s%s\n%s\n%s\n%s\n%s\n%s%s\n", c0, (prefix +
line).c_str(),
893 (prefix + title).c_str(), (prefix + warn).c_str(),
894 (prefix + err).c_str(), (prefix + help).c_str(),
895 (prefix +
line).c_str(),
c1);
906 #if defined(HAVE_FLTK)
907 if(FlGui::available()){
908 char defaultstr[256];
909 sprintf(defaultstr,
"%.16g", defaultval);
910 const char *ret = fl_input(text, defaultstr,
"");
918 printf(
"%s (default=%.16g): ", text, defaultval);
920 char *ret = fgets(str,
sizeof(str), stdin);
921 if(!ret || !strlen(str) || !strcmp(str,
"\n"))
933 #if defined(HAVE_FLTK)
934 if(FlGui::available()){
935 const char *ret = fl_input(text, defaultval.c_str(),
"");
939 return std::string(ret);
943 printf(
"%s (default=%s): ", text, defaultval.c_str());
945 char *ret = fgets(str,
sizeof(str), stdin);
946 if(!ret || !strlen(str) || !strcmp(str,
"\n"))
949 return std::string(str);
953 const char *one,
const char *two)
959 #if defined(HAVE_FLTK)
960 if(FlGui::available())
961 return fl_choice(question, zero, one, two,
"");
965 printf(
"%s\n\n0=[%s] 1=[%s] 2=[%s] (default=%d): ", question,
966 zero, one, two, defaultval);
968 printf(
"%s\n\n0=[%s] 1=[%s] (default=%d): ", question,
969 zero, one, defaultval);
971 char *ret = fgets(str,
sizeof(str), stdin);
972 if(!ret || !strlen(str) || !strcmp(str,
"\n"))
980 #if defined(HAVE_ONELAB)
981 return _onelabClient ? true :
false;
988 bool persistent,
bool readOnly,
int changedValue)
990 #if defined(HAVE_ONELAB)
993 std::vector<onelab::number> numbers;
994 _onelabClient->get(numbers, name);
997 numbers[0].setName(name);
999 numbers[0].setValue(val);
1000 if(!visible) numbers[0].setVisible(
false);
1001 if(persistent) numbers[0].setAttribute(
"Persistent",
"1");
1002 numbers[0].setReadOnly(readOnly);
1003 numbers[0].setChangedValue(changedValue);
1004 _onelabClient->set(numbers[0]);
1012 #if defined(HAVE_ONELAB)
1016 _onelabClient->set(n);
1022 bool visible,
bool persistent,
bool readOnly,
1023 int changedValue,
const std::string &kind)
1025 #if defined(HAVE_ONELAB)
1028 std::vector<onelab::string> strings;
1029 _onelabClient->get(strings, name);
1030 if(strings.empty()){
1032 strings[0].setName(name);
1034 strings[0].setValue(val);
1035 if(!visible) strings[0].setVisible(
false);
1036 if(persistent) strings[0].setAttribute(
"Persistent",
"1");
1037 strings[0].setReadOnly(readOnly);
1038 strings[0].setChangedValue(changedValue);
1039 if(kind.size()) strings[0].setKind(kind);
1040 _onelabClient->set(strings[0]);
1046 const std::string &kind,
1047 const std::string &value,
bool updateValue,
1048 bool readOnly,
bool visible)
1050 #if defined(HAVE_ONELAB)
1052 std::vector<std::string> choices;
1053 std::vector<onelab::string> ps;
1054 _onelabClient->get(ps, name);
1056 choices = ps[0].getChoices();
1057 if(std::find(choices.begin(), choices.end(), value) == choices.end())
1058 choices.push_back(value);
1060 ps[0].setValue(value);
1064 ps[0].setName(name);
1065 ps[0].setKind(kind);
1066 ps[0].setValue(value);
1067 choices.push_back(value);
1069 ps[0].setChoices(choices);
1071 ps[0].setReadOnly(
true);
1072 ps[0].setAttribute(
"AutoCheck",
"0");
1075 ps[0].setReadOnly(
false);
1076 ps[0].setAttribute(
"AutoCheck",
"1");
1078 ps[0].setVisible(visible);
1079 _onelabClient->set(ps[0]);
1085 bool errorIfMissing)
1087 #if defined(HAVE_ONELAB)
1089 std::vector<onelab::number> numbers;
1090 _onelabClient->get(numbers, name);
1091 if(numbers.empty()){
1093 Msg::Error(
"Unknown ONELAB number parameter '%s'", name.c_str());
1094 return defaultValue;
1097 return numbers[0].getValue();
1101 Msg::Error(
"GetNumber requires a ONELAB client");
1102 return defaultValue;
1106 const std::string &defaultValue,
1107 bool errorIfMissing)
1109 #if defined(HAVE_ONELAB)
1111 std::vector<onelab::string> strings;
1112 _onelabClient->get(strings, name);
1113 if(strings.empty()){
1115 Msg::Error(
"Unknown ONELAB string parameter '%s'", name.c_str());
1116 return defaultValue;
1119 return strings[0].getValue();
1123 Msg::Error(
"GetString requires a ONELAB client");
1124 return defaultValue;
1127 #if defined(HAVE_ONELAB)
1130 localGmsh() :
onelab::localClient(
"Gmsh") {}
1134 if(name.find(
".geo") != std::string::npos){
1139 else if((name.find(
".opt") != std::string::npos)){
1142 else if((name.find(
".macro") != std::string::npos)){
1157 #if defined(HAVE_ONELAB)
1158 if(_onelabClient)
delete _onelabClient;
1159 if(sockname.empty()){
1160 _onelabClient =
new localGmsh();
1162 FILE *fp =
Fopen(name.c_str(),
"rb");
1164 Msg::Info(
"Reading ONELAB database '%s'", name.c_str());
1165 _onelabClient->fromFile(fp);
1169 Error(
"Error loading onelab database '%s'", name.c_str());
1182 std::vector<onelab::string> ps;
1183 _onelabClient->get(ps, name +
"/Action");
1187 if(ps[0].getValue() ==
"initialize")
Exit(0);
1198 #if defined(HAVE_ONELAB)
1206 delete _onelabClient;
1207 _onelabClient =
nullptr;
1215 #if defined(HAVE_ONELAB)
1220 _onelabClient->set(o);
1227 #if defined(HAVE_ONELAB)
1229 std::vector<onelab::string> ps;
1230 _onelabClient->get(ps, _onelabClient->getName() +
"/Action");
1231 if(ps.size())
return ps[0].getValue();
1239 #if defined(HAVE_ONELAB)
1243 std::string action, cmd;
1244 std::vector<onelab::string> ps;
1245 client->
get(ps, clientName +
"/Action");
1246 if(ps.size() && ps[0].getValue().size())
1247 action.assign(ps[0].getValue());
1249 if(!action.compare(
"compute")){
1250 std::vector<onelab::string> ps;
1251 client->
get(ps,clientName+
"/FullCmdLine");
1252 if(ps.size() && ps[0].getValue().size())
1253 cmd.assign(ps[0].getValue());
1256 Msg::Info(
"Loader calls <%s>", cmd.c_str());
1258 std::cout <<
"Loader calls " << cmd << std::endl;
1262 Msg::Info(
"No full command line found for <%s>",
1263 clientName.c_str());
1265 Msg::Info(
"Stopping client <%s>", clientName.c_str());
1279 #if defined(HAVE_ONELAB)
1285 #if defined(HAVE_ONELAB)
1287 std::map<std::string, std::vector<double> > &fopt,
1288 std::map<std::string, std::vector<std::string> > &copt)
1291 if(copt.count(
"Label")) p->
setLabel(copt[
"Label"][0]);
1292 if(copt.count(
"ShortHelp"))
1294 if(copt.count(
"Help")) p->
setHelp(copt[
"Help"][0]);
1295 if(copt.count(
"Highlight")) p->
setAttribute(
"Highlight", copt[
"Highlight"][0]);
1296 if(copt.count(
"Macro")) p->
setAttribute(
"Macro", copt[
"Macro"][0]);
1297 if(copt.count(
"GmshOption")) p->
setAttribute(
"GmshOption", copt[
"GmshOption"][0]);
1298 if(copt.count(
"ServerAction")) p->
setAttribute(
"ServerAction", copt[
"ServerAction"][0]);
1299 if(copt.count(
"Units")) p->
setAttribute(
"Units", copt[
"Units"][0]);
1300 if(copt.count(
"AutoCheck"))
1304 if(fopt.count(
"Visible")) p->
setVisible(fopt[
"Visible"][0] ?
true :
false);
1305 if(fopt.count(
"ReadOnly")) p->
setReadOnly(fopt[
"ReadOnly"][0] ?
true :
false);
1306 if(fopt.count(
"NeverChanged")) p->
setNeverChanged(fopt[
"NeverChanged"][0] ?
true :
false);
1307 if(fopt.count(
"ChangedValue")) p->
setChangedValue(fopt[
"ChangedValue"][0]);
1308 if(fopt.count(
"ReadOnlyRange"))
1309 p->
setAttribute(
"ReadOnlyRange", fopt[
"ReadOnlyRange"][0] ?
"1" :
"0");
1310 if(fopt.count(
"AutoCheck"))
1311 p->
setAttribute(
"AutoCheck", fopt[
"AutoCheck"][0] ?
"1" :
"0");
1315 std::map<std::string, std::vector<std::string> > &copt)
1317 for(
auto it = copt.begin(); it != copt.end(); it++)
1319 it->first.compare(
"Name") &&
1320 it->first.compare(
"Label") &&
1321 it->first.compare(
"ShortHelp") &&
1322 it->first.compare(
"Help") &&
1323 it->first.compare(
"Visible") &&
1324 it->first.compare(
"ReadOnly") &&
1325 it->first.compare(
"NeverChanged") &&
1326 it->first.compare(
"ChangedValue"))
1330 static std::string _getParameterName(
const std::string &key,
1331 std::map<std::string, std::vector<std::string> > &copt)
1333 std::string name(key);
1334 if(copt.count(
"Path")){
1335 std::string path = copt[
"Path"][0];
1337 if(path.size() && path[path.size() - 1] >=
'0' && path[path.size() - 1] <=
'9')
1339 else if(path.size() && path[path.size() - 1] ==
'/')
1342 name = path +
"/" + name;
1349 std::vector<double> &val,
1350 std::map<std::string, std::vector<double> > &fopt,
1351 std::map<std::string, std::vector<std::string> > &copt)
1353 #if defined(HAVE_ONELAB)
1354 if(!_onelabClient)
return;
1357 if(copt.count(
"Name"))
1358 name = copt[
"Name"][0];
1361 if(copt.size() || fopt.size())
1362 Msg::Error(
"From now on you need to use the `Name' attribute to create a "
1363 "ONELAB parameter: `Name \"%s\"'",
1364 _getParameterName(key, copt).c_str());
1368 std::vector<onelab::number> ps;
1369 _onelabClient->get(ps, name);
1370 bool noRange =
true, noChoices =
true, noLoop =
true;
1371 bool noGraph =
true, noClosed =
true;
1373 bool useLocalValue = ps[0].getReadOnly();
1374 if(fopt.count(
"ReadOnly")) useLocalValue = fopt[
"ReadOnly"][0];
1376 ps[0].setValues(val);
1378 val = ps[0].getValues();
1382 if(ps[0].getVisible()){
1383 if(!(fopt.count(
"ReadOnlyRange") && fopt[
"ReadOnlyRange"][0])){
1386 ps[0].getStep() != 0.) noRange =
false;
1387 if(ps[0].getChoices().size()) noChoices =
false;
1389 if(ps[0].getAttribute(
"Loop").size()) noLoop =
false;
1390 if(ps[0].getAttribute(
"Graph").size()) noGraph =
false;
1391 if(ps[0].getAttribute(
"Closed").size()) noClosed =
false;
1396 ps[0].setName(name);
1397 ps[0].setValues(val);
1400 if(noRange && fopt.count(
"Range") && fopt[
"Range"].size() == 2){
1401 ps[0].setMin(fopt[
"Range"][0]); ps[0].setMax(fopt[
"Range"][1]);
1403 else if(noRange && fopt.count(
"Min") && fopt.count(
"Max")){
1404 ps[0].setMin(fopt[
"Min"][0]); ps[0].setMax(fopt[
"Max"][0]);
1406 else if(noRange && fopt.count(
"Min")){
1409 else if(noRange && fopt.count(
"Max")){
1412 if(noRange && fopt.count(
"Step")) ps[0].setStep(fopt[
"Step"][0]);
1415 if(val.size() && noRange && !fopt.count(
"Range") && !fopt.count(
"Step") &&
1416 !fopt.count(
"Min") && !fopt.count(
"Max")){
1417 bool isInteger = (floor(val[0]) == val[0]);
1418 double fact = isInteger ? 5. : 20.;
1420 ps[0].setMin(val[0] / fact);
1421 ps[0].setMax(val[0] * fact);
1422 ps[0].setStep((ps[0].getMax() - ps[0].getMin()) / 100.);
1424 else if(val[0] < 0){
1425 ps[0].setMin(val[0] * fact);
1426 ps[0].setMax(val[0] / fact);
1427 ps[0].setStep((ps[0].getMax() - ps[0].getMin()) / 100.);
1429 if(val[0] && isInteger){
1430 ps[0].setMin((
int)ps[0].getMin());
1431 ps[0].setMax((
int)ps[0].getMax());
1432 ps[0].setStep((
int)ps[0].getStep());
1435 if(noChoices && fopt.count(
"Choices")){
1436 ps[0].setChoices(fopt[
"Choices"]);
1437 if(copt.count(
"Choices")) ps[0].setChoiceLabels(copt[
"Choices"]);
1439 if(noLoop && copt.count(
"Loop"))
1440 ps[0].setAttribute(
"Loop", copt[
"Loop"][0]);
1441 if(noLoop && fopt.count(
"Loop"))
1442 ps[0].setAttribute(
"Loop", (fopt[
"Loop"][0] == 3.) ?
"3" :
1443 (fopt[
"Loop"][0] == 2.) ?
"2" :
1444 (fopt[
"Loop"][0] == 1.) ?
"1" :
"");
1445 if(noGraph && copt.count(
"Graph")) ps[0].setAttribute(
"Graph", copt[
"Graph"][0]);
1446 if(noClosed && copt.count(
"Closed"))
1447 ps[0].setAttribute(
"Closed", copt[
"Closed"][0]);
1448 if(noClosed && fopt.count(
"Closed"))
1449 ps[0].setAttribute(
"Closed", fopt[
"Closed"][0] ?
"1" :
"0");
1450 if(copt.count(
"NumberFormat"))
1451 ps[0].setAttribute(
"NumberFormat", copt[
"NumberFormat"][0]);
1452 _setStandardOptions(&ps[0], fopt, copt);
1453 _setOtherAttributes(&ps[0], copt);
1454 _onelabClient->set(ps[0]);
1460 std::map<std::string, std::vector<double> > &fopt,
1461 std::map<std::string, std::vector<std::string> > &copt)
1463 #if defined(HAVE_ONELAB)
1464 if(!_onelabClient)
return;
1467 if(copt.count(
"Name"))
1468 name = copt[
"Name"][0];
1471 if(copt.size() || fopt.size())
1472 Msg::Error(
"From now on you need to use the `Name' attribute to create a "
1473 "ONELAB parameter: `Name \"%s\"'",
1474 _getParameterName(key, copt).c_str());
1478 std::vector<onelab::string> ps;
1479 _onelabClient->get(ps, name);
1480 bool noChoices =
true, noClosed =
true, noMultipleSelection =
true;
1482 bool useLocalValue = ps[0].getReadOnly();
1483 if(fopt.count(
"ReadOnly")) useLocalValue = fopt[
"ReadOnly"][0];
1485 ps[0].setValue(val);
1487 val = ps[0].getValue();
1490 if(ps[0].getVisible()){
1491 if(ps[0].getChoices().size()) noChoices =
false;
1492 if(ps[0].getAttribute(
"Closed").size()) noClosed =
false;
1493 if(ps[0].getAttribute(
"MultipleSelection").size()) noMultipleSelection =
false;
1498 ps[0].setName(name);
1499 ps[0].setValue(val);
1501 if(copt.count(
"Kind")) ps[0].setKind(copt[
"Kind"][0]);
1502 if(noChoices && copt.count(
"Choices")) ps[0].setChoices(copt[
"Choices"]);
1503 if(noClosed && copt.count(
"Closed"))
1504 ps[0].setAttribute(
"Closed", copt[
"Closed"][0]);
1505 if(noClosed && fopt.count(
"Closed"))
1506 ps[0].setAttribute(
"Closed", fopt[
"Closed"][0] ?
"1" :
"0");
1507 if(noMultipleSelection && copt.count(
"MultipleSelection"))
1508 ps[0].setAttribute(
"MultipleSelection", copt[
"MultipleSelection"][0]);
1509 _setStandardOptions(&ps[0], fopt, copt);
1510 _setOtherAttributes(&ps[0], copt);
1511 _onelabClient->set(ps[0]);
1517 #if defined(HAVE_ONELAB)
1518 if(!_onelabClient)
return;
1519 _onelabClient->clear(name);
1525 #if defined(HAVE_ONELAB)
1527 std::vector<onelab::number> oldn;
1528 _onelabClient->get(oldn,
"Gmsh/Number of physical groups");
1530 if(oldn.size()) oldsize = (int)oldn[0].getValue();
1532 std::map<int, std::vector<GEntity*> > groups[4];
1535 for(
int dim = 0; dim <= 3; dim++)
1536 size += groups[dim].size();
1542 _onelabClient->set(n);
1549 _onelabClient->set(nd);
1552 for(
int dim = 0; dim <= 3; dim++){
1553 for(
auto it = groups[dim].begin();
1554 it != groups[dim].end(); it++){
1555 int num = it->first;
1559 sprintf(tmp,
"Physical %s %d", (dim == 3) ?
"Volume" : (dim == 2) ?
"Surface" :
1560 (dim == 1) ?
"Curve" :
"Point", num);
1563 sprintf(tmp,
"Gmsh/Physical group %d/", index);
1564 std::string str = tmp;
1569 _onelabClient->set(n1);
1574 _onelabClient->set(n2);
1579 _onelabClient->set(s);
1585 for(
int index = size + 1; index < oldsize + 1; index++){
1587 sprintf(tmp,
"Gmsh/Physical group %d/Dimension", index);
1588 _onelabClient->clear(tmp);
1589 sprintf(tmp,
"Gmsh/Physical group %d/Number", index);
1590 _onelabClient->clear(tmp);
1591 sprintf(tmp,
"Gmsh/Physical group %d/Name", index);
1592 _onelabClient->clear(tmp);
1595 #if defined(HAVE_FLTK)
1596 if(FlGui::available()){
1597 FlGui::instance()->resetVisibility();
1598 FlGui::instance()->rebuildTree(
false);
1607 #if defined(HAVE_ONELAB)
1614 #if defined(HAVE_ONELAB)
1621 #if defined(HAVE_MPI)
1622 MPI_Barrier(MPI_COMM_WORLD);
1626 #if defined(_OPENMP)
1643 : _totalElementToTreat(num), _currentI(0), _nextIToCheck(0),
1644 _initialTime(
Cpu()), _lastTime(_initialTime), _lastPercentage(0),
1645 _progressMeterStep(
Msg::GetProgressMeterStep())
1669 double currentTime =
Cpu();
1670 if ((currentPercentage < 5 && currentTime - _lastTime > 15.) ||
1676 if (remaining < 60*2)
1678 "%d%% (remaining time ~%g seconds)",
1679 currentPercentage, remaining);
1680 else if (remaining < 60*60*2)
1682 "%d%% (remaining time ~%g minutes)",
1683 currentPercentage, remaining / 60);
1686 "%d%% (remaining time ~%g hours)",
1687 currentPercentage, remaining / 3600);