[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Five external solvers can be interfaced simultaneously with Gmsh.
If you just want to start a solver from the solver module, with no further
interactions between the solver and Gmsh, just edit the options relative to
one of the five available solvers (e.g. Solver.Name0
,
Solver.Executable0
, ...; see 5.1 Solver options), and set the
corresponding "client-server" option to zero
(e.g. Solver.ClientServer0 = 0
). This doesn't require any
modification to be made to the solver.
If you want the solver to interact with Gmsh (for error messages, option
definitions, post-processing, etc.), you need to link your solver with the
`GmshClient.c' file and add the appropriate function calls inside your
program. You can then proceed as in the previous case, but this time you
should set the client-server option to 1 (e.g. Solver.ClientServer0
= 1
), so that Gmsh and the solver can communicate through a Unix
socket. See 5.2 Solver example, for an example of how to interface a C
solver. Bindings for solvers written in other languages (e.g. Perl) are
available on http://www.geuz.org/gmsh/.
5.1 Solver options 5.2 Solver example
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Solver.Name0
"GetDP"
General.OptionsFileName
Solver.Help0
"A General environment for the treatment of
Discrete Problems.
Copyright (C) 1997-2004
Patrick Dular and Christophe Geuzaine.
Visit http://www.geuz.org/getdp/ for more info"
General.OptionsFileName
Solver.Executable0
"getdp"
General.OptionsFileName
Solver.Extension0
".pro"
General.OptionsFileName
Solver.MeshName0
""
General.OptionsFileName
Solver.MeshCommand0
"-msh %s"
General.OptionsFileName
Solver.OptionCommand0
""
General.OptionsFileName
Solver.FirstOption0
"Resolution"
General.OptionsFileName
Solver.SecondOption0
"PostOperation"
General.OptionsFileName
Solver.ThirdOption0
""
General.OptionsFileName
Solver.FourthOption0
""
General.OptionsFileName
Solver.FifthOption0
""
General.OptionsFileName
Solver.FirstButton0
"Pre"
General.OptionsFileName
Solver.FirstButtonCommand0
"-pre %s"
General.OptionsFileName
Solver.SecondButton0
"Cal"
General.OptionsFileName
Solver.SecondButtonCommand0
"-cal"
General.OptionsFileName
Solver.ThirdButton0
"Pos"
General.OptionsFileName
Solver.ThirdButtonCommand0
"-bin -pos %s"
General.OptionsFileName
Solver.FourthButton0
""
General.OptionsFileName
Solver.FourthButtonCommand0
""
General.OptionsFileName
Solver.FifthButton0
""
General.OptionsFileName
Solver.FifthButtonCommand0
""
General.OptionsFileName
Solver.Name1
""
General.OptionsFileName
Solver.Help1
""
General.OptionsFileName
Solver.Executable1
""
General.OptionsFileName
Solver.Extension1
""
General.OptionsFileName
Solver.MeshName1
""
General.OptionsFileName
Solver.MeshCommand1
""
General.OptionsFileName
Solver.OptionCommand1
""
General.OptionsFileName
Solver.FirstOption1
""
General.OptionsFileName
Solver.SecondOption1
""
General.OptionsFileName
Solver.ThirdOption1
""
General.OptionsFileName
Solver.FourthOption1
""
General.OptionsFileName
Solver.FifthOption1
""
General.OptionsFileName
Solver.FirstButton1
""
General.OptionsFileName
Solver.FirstButtonCommand1
""
General.OptionsFileName
Solver.SecondButton1
""
General.OptionsFileName
Solver.SecondButtonCommand1
""
General.OptionsFileName
Solver.ThirdButton1
""
General.OptionsFileName
Solver.ThirdButtonCommand1
""
General.OptionsFileName
Solver.FourthButton1
""
General.OptionsFileName
Solver.FourthButtonCommand1
""
General.OptionsFileName
Solver.FifthButton1
""
General.OptionsFileName
Solver.FifthButtonCommand1
""
General.OptionsFileName
Solver.Name2
""
General.OptionsFileName
Solver.Help2
""
General.OptionsFileName
Solver.Executable2
""
General.OptionsFileName
Solver.Extension2
""
General.OptionsFileName
Solver.MeshName2
""
General.OptionsFileName
Solver.MeshCommand2
""
General.OptionsFileName
Solver.OptionCommand2
""
General.OptionsFileName
Solver.FirstOption2
""
General.OptionsFileName
Solver.SecondOption2
""
General.OptionsFileName
Solver.ThirdOption2
""
General.OptionsFileName
Solver.FourthOption2
""
General.OptionsFileName
Solver.FifthOption2
""
General.OptionsFileName
Solver.FirstButton2
""
General.OptionsFileName
Solver.FirstButtonCommand2
""
General.OptionsFileName
Solver.SecondButton2
""
General.OptionsFileName
Solver.SecondButtonCommand2
""
General.OptionsFileName
Solver.ThirdButton2
""
General.OptionsFileName
Solver.ThirdButtonCommand2
""
General.OptionsFileName
Solver.FourthButton2
""
General.OptionsFileName
Solver.FourthButtonCommand2
""
General.OptionsFileName
Solver.FifthButton2
""
General.OptionsFileName
Solver.FifthButtonCommand2
""
General.OptionsFileName
Solver.Name3
""
General.OptionsFileName
Solver.Help3
""
General.OptionsFileName
Solver.Executable3
""
General.OptionsFileName
Solver.Extension3
""
General.OptionsFileName
Solver.MeshName3
""
General.OptionsFileName
Solver.MeshCommand3
""
General.OptionsFileName
Solver.OptionCommand3
""
General.OptionsFileName
Solver.FirstOption3
""
General.OptionsFileName
Solver.SecondOption3
""
General.OptionsFileName
Solver.ThirdOption3
""
General.OptionsFileName
Solver.FourthOption3
""
General.OptionsFileName
Solver.FifthOption3
""
General.OptionsFileName
Solver.FirstButton3
""
General.OptionsFileName
Solver.FirstButtonCommand3
""
General.OptionsFileName
Solver.SecondButton3
""
General.OptionsFileName
Solver.SecondButtonCommand3
""
General.OptionsFileName
Solver.ThirdButton3
""
General.OptionsFileName
Solver.ThirdButtonCommand3
""
General.OptionsFileName
Solver.FourthButton3
""
General.OptionsFileName
Solver.FourthButtonCommand3
""
General.OptionsFileName
Solver.FifthButton3
""
General.OptionsFileName
Solver.FifthButtonCommand3
""
General.OptionsFileName
Solver.Name4
""
General.OptionsFileName
Solver.Help4
""
General.OptionsFileName
Solver.Executable4
""
General.OptionsFileName
Solver.Extension4
""
General.OptionsFileName
Solver.MeshName4
""
General.OptionsFileName
Solver.MeshCommand4
""
General.OptionsFileName
Solver.OptionCommand4
""
General.OptionsFileName
Solver.FirstOption4
""
General.OptionsFileName
Solver.SecondOption4
""
General.OptionsFileName
Solver.ThirdOption4
""
General.OptionsFileName
Solver.FourthOption4
""
General.OptionsFileName
Solver.FifthOption4
""
General.OptionsFileName
Solver.FirstButton4
""
General.OptionsFileName
Solver.FirstButtonCommand4
""
General.OptionsFileName
Solver.SecondButton4
""
General.OptionsFileName
Solver.SecondButtonCommand4
""
General.OptionsFileName
Solver.ThirdButton4
""
General.OptionsFileName
Solver.ThirdButtonCommand4
""
General.OptionsFileName
Solver.FourthButton4
""
General.OptionsFileName
Solver.FourthButtonCommand4
""
General.OptionsFileName
Solver.FifthButton4
""
General.OptionsFileName
Solver.FifthButtonCommand4
""
General.OptionsFileName
Solver.ClientServer0
1
General.OptionsFileName
Solver.MergeViews0
1
General.OptionsFileName
Solver.PopupMessages0
1
General.OptionsFileName
Solver.ClientServer1
0
General.OptionsFileName
Solver.MergeViews1
1
General.OptionsFileName
Solver.PopupMessages1
1
General.OptionsFileName
Solver.ClientServer2
0
General.OptionsFileName
Solver.MergeViews2
1
General.OptionsFileName
Solver.PopupMessages2
1
General.OptionsFileName
Solver.ClientServer3
0
General.OptionsFileName
Solver.MergeViews3
1
General.OptionsFileName
Solver.PopupMessages3
1
General.OptionsFileName
Solver.ClientServer4
0
General.OptionsFileName
Solver.MergeViews4
1
General.OptionsFileName
Solver.PopupMessages4
1
General.OptionsFileName
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here is a small example of how to interface a C solver with Gmsh. The following listing reproduces the `utils/solvers/mysolver.c' file from the Gmsh source distribution.
/* $Id: mysolver.c,v 1.3 2004/02/07 01:40:35 geuzaine Exp $ */ /* * Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, and/or sell copies of the * Software, and to permit persons to whom the Software is furnished * to do so, provided that the above copyright notice(s) and this * permission notice appear in all copies of the Software and that * both the above copyright notice(s) and this permission notice * appear in supporting documentation. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR * ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * * Please report all bugs and problems to <gmsh@geuz.org>. */ /* This file contains a dummy client solver for Gmsh. It does not solve anything, but shows how to program your own solver to interact with the Gmsh solver module. To compile this solver, type something like: gcc -o mysolver.exe mysolver.c GmshClient.c To test this solver, copy the mysolver.opt file into your default Gmsh option file, or lauch Gmsh with the command: gmsh -option mysolver.opt */ /* We start by including some standard headers. Under Windows, you will need to install the cygwin tools (http://www.cygwin.com) to compile this example (as well as your own solver), since the Gmsh solver interface uses Unix sockets. */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/time.h> #include <unistd.h> /* Now we include the Gmsh client interface definitions. At the time of this writing, the client interface contains only three functions: Gmsh_Connect, Gmsh_SendString and Gmsh_Disconnect. This example shows how to use these functions in order to program some simple interactions between a solver and Gmsh. */ #include "GmshClient.h" /* The following typedef defines the two actions of our dummy solver: either output some valid option strings, or run a dummy computation and output a post-processing map. */ typedef enum { options, run } action; /* Let's now define some fake CPU intensive functions: */ long worktime() { struct timeval tp; gettimeofday(&tp, (struct timezone *)0); return (long)tp.tv_sec * 1000000 + (long)tp.tv_usec; } void work() { long t1 = worktime(); while(1) { if(worktime() - t1 > 1.e5) break; } } /* And here we go with the main routine of the solver: */ int main(int argc, char *argv[]) { action what = run; int i = 0, s; char *name = NULL, *option = NULL, *socket = NULL, tmp[256]; FILE *file; /* 1. Loop through the command line arguments, remember the action the solver has to perform (what) and store the socket name, the option name and the problem name. */ while(i < argc) { if(argv[i][0] == '-') { if(!strcmp(argv[i] + 1, "socket")) { i++; if(argv[i]) socket = argv[i++]; } else if(!strcmp(argv[i] + 1, "options")) { i++; what = options; } else if(!strcmp(argv[i] + 1, "run")) { i++; what = run; if(argv[i]) option = argv[i++]; } } else name = argv[i++]; } /* 2. If the '-socket' option was not given, we cannot connect to Gmsh... */ if(!socket) { printf("No socket specified: running non-interactively...\n"); exit(1); } /* 3. Try to connect to the socket given by the '-socket' command line option: */ s = Gmsh_Connect(socket); switch (s) { /* 3.1. If the socket is <0, issue an error... */ case -1: printf("Couldn't create socket %s\n", socket); break; case -2: printf("Couldn't connect to socket %s\n", socket); break; default: /* 3.2. ...otherwise, send the GMSH_CLIENT_START command (together with the process ID of the solver), check if a problem name was specified, and decide what to do according to the 'what' variable: */ sprintf(tmp, "%d", getpid()); Gmsh_SendString(s, GMSH_CLIENT_START, tmp); if(!name) { Gmsh_SendString(s, GMSH_CLIENT_ERROR, "Missing file name"); Gmsh_Disconnect(s); exit(1); } switch (what) { /* 3.2.1. If what==options, the solver sends the valid options (here for the first option): */ case options: Gmsh_SendString(s, GMSH_CLIENT_OPTION_1, "Val1"); Gmsh_SendString(s, GMSH_CLIENT_OPTION_1, "Val2"); Gmsh_SendString(s, GMSH_CLIENT_OPTION_1, "Val3"); break; /* 3.2.2. If what==run, the solver runs the chosen option, updates the progress message, issues some information data, produces a post-processing map and asks Gmsh to merge it: */ case run: sprintf(tmp, "Running %s with option %s...", name, option); Gmsh_SendString(s, GMSH_CLIENT_INFO, tmp); for(i = 0; i < 10; i++) { sprintf(tmp, "%d %% complete", 10*i); Gmsh_SendString(s, GMSH_CLIENT_PROGRESS, tmp); work(); } sprintf(tmp, "Done with %s!", name); Gmsh_SendString(s, GMSH_CLIENT_INFO, tmp); file = fopen("mysolver.pos", "wb"); if(!file) { Gmsh_SendString(s, GMSH_CLIENT_ERROR, "Unable to open output file"); } else { fprintf(file, "View \"%s\"{\n", option); fprintf(file, "ST(0,0,0,1,0,0,0,1,0){0,1,2};\n"); fprintf(file, "};\n"); fclose(file); Gmsh_SendString(s, GMSH_CLIENT_VIEW, "mysolver.pos"); } break; } /* 3.3. We can now disconnect the solver from Gmsh: */ Gmsh_SendString(s, GMSH_CLIENT_STOP, "Goodbye!"); Gmsh_Disconnect(s); break; } /* 4. That's it! */ }
To define the above solver as the second external solver in Gmsh, you should
define the following solver options (either merge them in your Gmsh option
file, or use the -option
command-line option--see 8.2 Command-line options):
// These options define 'mysolver.exe' as the second solver in Gmsh's // solver module, under the name 'My C Solver'. Solver.Name1 = "My C solver"; Solver.Help1 = "A simple example of the client/server solver implementation in Gmsh..."; Solver.Executable1 = "./mysolver.exe"; Solver.Extension1 = ""; Solver.MeshName1 = ""; Solver.MeshCommand1 = ""; Solver.OptionCommand1 = "-options"; Solver.FirstOption1 = "Option"; Solver.SecondOption1 = ""; Solver.ThirdOption1 = ""; Solver.FourthOption1 = ""; Solver.FifthOption1 = ""; Solver.FirstButton1 = "Run"; Solver.FirstButtonCommand1 = "-run %s"; Solver.SecondButton1 = ""; Solver.SecondButtonCommand1 = ""; Solver.ThirdButton1 = ""; Solver.ThirdButtonCommand1 = ""; Solver.FourthButton1 = ""; Solver.FourthButtonCommand1 = ""; Solver.FifthButton1 = ""; Solver.FifthButtonCommand1 = ""; Solver.ClientServer1 = 1; Solver.MergeViews1 = 1; Solver.PopupMessages1 = 1;
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |