Skip to content
Snippets Groups Projects
Commit 908ef8c9 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

use C++ example in doc instead of C
parent f3eb1685
No related branches found
No related tags found
No related merge requests found
\input texinfo.tex @c -*-texinfo-*- \input texinfo.tex @c -*-texinfo-*-
@c $Id: gmsh.texi,v 1.166 2005-01-13 05:45:46 geuzaine Exp $ @c $Id: gmsh.texi,v 1.167 2005-01-14 17:54:01 geuzaine Exp $
@c @c
@c Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle @c Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
@c @c
...@@ -2210,24 +2210,24 @@ available on @value{GMSH-WEB}. ...@@ -2210,24 +2210,24 @@ available on @value{GMSH-WEB}.
@cindex Solver example @cindex Solver example
@cindex Example, solver @cindex Example, solver
Here is a small example of how to interface a C solver with Gmsh. The Here is a small example of how to interface a C++ solver with Gmsh. The
following listing reproduces the @file{utils/solvers/mysolver.c} file from following listing reproduces the @file{utils/solvers/c++/solver.cpp} file
the Gmsh source distribution. from the Gmsh source distribution (C and Perl examples are also available).
@sp 1 @sp 1
@verbatiminclude ../../utils/solvers/mysolver.c @verbatiminclude ../../utils/solvers/c++/solver.cpp
@sp 1 @sp 1
To define the above solver as the second external solver in Gmsh, you should To define the above solver as the second external solver in Gmsh, you then
define the following solver options (either merge them in your Gmsh option need to define the following options (either merge them in your Gmsh option
file, or use the @code{-option} command-line option---see @ref{Command-line file, or use the @code{-option} command-line option---see @ref{Command-line
options}): options}):
@sp 1 @sp 1
@verbatiminclude ../../utils/solvers/mysolver.opt @verbatiminclude ../../utils/solvers/c++/solver.opt
@c ========================================================================= @c =========================================================================
@c Post-processing module @c Post-processing module
...@@ -2322,6 +2322,10 @@ different display options), but you cannot afford to store all copies in ...@@ -2322,6 +2322,10 @@ different display options), but you cannot afford to store all copies in
memory. If what you really want is multiple physical copies of the data, memory. If what you really want is multiple physical copies of the data,
just merge the file containing the post-processing view multiple times. just merge the file containing the post-processing view multiple times.
@item AliasWithOptions View[@var{expression}];
Creates an alias of the @var{expression}-th post-processing view and copies
all the options of the @var{expression}-th view to the new aliased view.
@item Combine TimeSteps; @item Combine TimeSteps;
Combines the data from all the post-processing views having the same name Combines the data from all the post-processing views having the same name
into new multi-time-step views. into new multi-time-step views.
......
# $Id: Makefile,v 1.2 2005-01-14 02:27:01 geuzaine Exp $ # $Id: Makefile,v 1.3 2005-01-14 17:54:01 geuzaine Exp $
# #
# Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle # Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
# #
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
include ../../../variables include ../../../variables
andre: andre.cpp solver: solver.cpp
${CXX} ${FLAGS} ${OPTIM} -o andre.exe andre.cpp ${CXX} ${FLAGS} ${OPTIM} -o solver.exe solver.cpp
clean: clean:
rm -f *.o *.exe *.pos rm -f *.o *.exe *.pos
......
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <math.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <math.h>
#include "GmshClient.h" #include "GmshClient.h"
typedef enum { send_options, run_code } action; typedef enum { send_options, run_code } action;
...@@ -47,24 +45,25 @@ int main(int argc, char *argv[]) ...@@ -47,24 +45,25 @@ int main(int argc, char *argv[])
GmshClient client; GmshClient client;
if(client.Connect(socket) < 0){ if(client.Connect(socket) < 0){
printf("Unable to connect to server\n"); printf("Unable to connect to Gmsh\n");
exit(1); exit(1);
} }
else{
client.Start(getpid()); client.Start(getpid());
if(what_to_do == send_options) { if(what_to_do == send_options) {
// send the available options for this computation // send the available options for this computation
client.Option(1, "FormulationH"); client.Option(1, "FormulationH");
client.Option(1, "\"Convergence Test\""); client.Option(1, "ConvTest");
client.Option(1, "\"Blabla blblablabli\""); client.Option(1, "Blablabli");
} }
else if(what_to_do == run_code){ else if(what_to_do == run_code){
// do the computation and merge some views // do the computation and merge some views
for(int i = 0; i < 10; i++){ for(int i = 0; i < 10; i++){
client.Info("Computing curve..."); client.Info("Computing curve...");
sleep(1); sleep(1); // fake computation...
client.Info("Done computing curve"); client.Info("Done computing curve");
FILE *file = fopen("andre.pos", "w"); FILE *file = fopen("solver.pos", "w");
if(!file) if(!file)
client.Error("Unable to open output file"); client.Error("Unable to open output file");
else { else {
...@@ -78,12 +77,12 @@ int main(int argc, char *argv[]) ...@@ -78,12 +77,12 @@ int main(int argc, char *argv[])
fprintf(file, "View.Width = 350;\n"); fprintf(file, "View.Width = 350;\n");
fprintf(file, "View.Height = 350;\n"); fprintf(file, "View.Height = 350;\n");
fprintf(file, "Delete View[0];\n"); fprintf(file, "Delete View[0];\n");
fprintf(file, "View \"test\"{\n"); fprintf(file, "View \"%s\"{\n", option);
for(int j = 0; j < 100; j++) for(int j = 0; j < 100; j++)
fprintf(file, "SP(%d,0,0){%g};\n", j,sin(j*i*M_PI/10.)); fprintf(file, "SP(%d,0,0){%g};\n", j,sin(j*i*M_PI/10.));
fprintf(file, "};\n"); fprintf(file, "};\n");
fclose(file); fclose(file);
client.View("andre.pos"); client.View("solver.pos");
} }
} }
client.Info("Done!"); client.Info("Done!");
...@@ -92,4 +91,3 @@ int main(int argc, char *argv[]) ...@@ -92,4 +91,3 @@ int main(int argc, char *argv[])
client.Stop(); client.Stop();
client.Disconnect(); client.Disconnect();
} }
}
Solver.Name1 = "Solveur Andre"; Solver.Name1 = "My C++ Solver";
Solver.Help1 = "Mon petit solveur"; Solver.Executable1 = "./solver.exe";
Solver.Executable1 = "./andre.exe";
Solver.OptionCommand1 = "-options"; Solver.OptionCommand1 = "-options";
Solver.FirstOption1 = "Mes options"; Solver.FirstOption1 = "My options";
Solver.FirstButton1 = "Run !"; Solver.FirstButton1 = "Run !";
Solver.FirstButtonCommand1 = "-run %s"; Solver.FirstButtonCommand1 = "-run %s";
Solver.ClientServer1 = 1; Solver.ClientServer1 = 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment