Commit 49924446 by Christophe Geuzaine

cleanup + c onelab example

parent 95423e3a
Pipeline #954 passed with stage
in 36 minutes 5 seconds
......@@ -52,6 +52,47 @@ typedef unsigned long intptr_t;
// interface. You'll need to reimplement this if you plan to build a different
// ONELAB server.
void solver_cb(Fl_Widget *w, void *data)
{
if(!FlGui::instance()->onelab) return;
int num = (intptr_t)data;
if(num >= 0){
std::string name = opt_solver_name(num, GMSH_GET, "");
std::string exe = opt_solver_executable(num, GMSH_GET, "");
std::string host = opt_solver_remote_login(num, GMSH_GET, "");
FlGui::instance()->onelab->addSolver(name, exe, host, num);
}
else{
FlGui::instance()->onelab->rebuildSolverList();
}
if(CTX::instance()->solver.autoLoadDatabase){
std::vector<std::string> split = SplitFileName(GModel::current()->getFileName());
std::string db = split[0] + split[1] + ".db";
if(!StatFile(db)){
onelabUtils::loadDb(db);
CTX::instance()->launchSolverAtStartup = -1;
}
}
if(FlGui::instance()->onelab->isBusy())
FlGui::instance()->onelab->show();
else{
if(CTX::instance()->launchSolverAtStartup >= 0){
onelab_cb(0, (void*)"reset");
onelabUtils::setFirstComputationFlag(true);
}
else if(num >= 0)
onelab_cb(0, (void*)"check");
else
onelab_cb(0, (void*)"refresh");
FlGui::instance()->onelab->updateGearMenu();
}
CTX::instance()->launchSolverAtStartup = -1;
}
void onelab_cb(Fl_Widget *w, void *data)
{
if(!data) return;
......@@ -1460,48 +1501,3 @@ void onelabGroup::addSolver(const std::string &name, const std::string &executab
onelab_cb(0, (void*)"initialize");
}
void solver_cb(Fl_Widget *w, void *data)
{
if(!FlGui::instance()->onelab) return;
int num = (intptr_t)data;
if(num >= 0){
std::string name = opt_solver_name(num, GMSH_GET, "");
std::string exe = opt_solver_executable(num, GMSH_GET, "");
std::string host = opt_solver_remote_login(num, GMSH_GET, "");
FlGui::instance()->onelab->addSolver(name, exe, host, num);
}
else{
FlGui::instance()->onelab->rebuildSolverList();
}
if(CTX::instance()->solver.autoLoadDatabase){
std::vector<std::string> split = SplitFileName(GModel::current()->getFileName());
std::string db = split[0] + split[1] + ".db";
if(!StatFile(db)){
onelabUtils::loadDb(db);
CTX::instance()->launchSolverAtStartup = -1;
}
}
if(FlGui::instance()->onelab->isBusy())
FlGui::instance()->onelab->show();
else{
if(CTX::instance()->launchSolverAtStartup >= 0){
onelab_cb(0, (void*)"reset");
onelabUtils::setFirstComputationFlag(true);
}
else if(num >= 0)
onelab_cb(0, (void*)"check");
else
onelab_cb(0, (void*)"refresh");
FlGui::instance()->onelab->updateGearMenu();
}
CTX::instance()->launchSolverAtStartup = -1;
}
void flgui_wait_cb(double time)
{
FlGui::instance()->wait(time);
}
......@@ -77,8 +77,7 @@ class onelabGroup : public Fl_Group{
void stop(bool val){ _stop = val; }
};
void onelab_cb(Fl_Widget *w, void *data);
void solver_cb(Fl_Widget *w, void *data);
int metamodel_cb(const std::string &name, const std::string &action="");
void onelab_cb(Fl_Widget *w, void *data);
#endif
#include <stdio.h>
#include <gmshc.h>
#define chk(ierr) \
if(ierr != 0){ \
fprintf(stderr, "Error on line %i in function '%s': " \
"gmsh function returned non-zero error code: %i\n", \
__LINE__, __FUNCTION__, ierr); \
gmshFinalize(NULL); \
exit(ierr); \
}
int main(int argc, char **argv)
{
int ierr;
char *json;
if(argc < 2){
printf("Usage: %s file [options]\n", argv[0]);
return 1;
}
gmshInitialize(0, 0, 1, &ierr); chk(ierr);
gmshOptionSetNumber("General.Terminal", 1, &ierr); chk(ierr);
gmshOpen(argv[1], &ierr); chk(ierr);
/* attempts to run a client selected when opening the file (e.g. a .pro
file) */
gmshOnelabRun("", "", &ierr); chk(ierr);
gmshOnelabGet(&json, "json", &ierr); chk(ierr);
printf("%s", json);
gmshFinalize(&ierr); chk(ierr);
return 0;
}
#include <stdio.h>
#include "gmshc.h"
#define chk(ierr) if (ierr != 0) {fprintf(stderr, "ERROR on line %i in function '%s': gmsh function return non-zero error code: %i\n",__LINE__, __FUNCTION__,ierr); gmshFinalize(NULL); exit(ierr);}
#define chk(ierr) \
if(ierr != 0){ \
fprintf(stderr, "Error on line %i in function '%s': " \
"gmsh function returned non-zero error code: %i\n", \
__LINE__, __FUNCTION__, ierr); \
gmshFinalize(NULL); \
exit(ierr); \
}
void genGeometry() {
int ierr;
......@@ -70,7 +77,7 @@ void genError() {
int main(int argc, char **argv) {
int ierr;
gmshInitialize(argc, argv, &ierr); chk(ierr);
gmshInitialize(argc, argv, 1, &ierr); chk(ierr);
genGeometry();
gmshModelMeshGenerate(2,&ierr); chk(ierr);
gmshWrite("square.msh",&ierr); chk(ierr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment