Commit 492b492c authored by Christophe Geuzaine's avatar Christophe Geuzaine

ivectorvector + doc

parent 0768498e
......@@ -123,6 +123,8 @@ def ivectorpair(name, value=None, python_value=None, julia_value=None):
a.python_pre = api_name + ", " + api_name_n + " = _ivectorpair(" + name + ")"
a.python_arg = api_name + ", " + api_name_n
a.julia_ctype = "Ptr{Cint}, Csize_t"
a.julia_arg = ("convert(Vector{Cint}, collect(Iterators.flatten(" + name + "))), " +
"2 * length(" + name + ")")
return a
def ivectorvectorint(name, value=None, python_value=None, julia_value=None):
......@@ -150,6 +152,10 @@ def ivectorvectorint(name, value=None, python_value=None, julia_value=None):
api_name_nn + " = _ivectorvectorint(" + name + ")")
a.python_arg = api_name + ", " + api_name_n + ", " + api_name_nn
a.julia_ctype = "Ptr{Ptr{Cint}}, Ptr{Csize_t}, Csize_t"
a.julia_pre = (api_name_n + " = [ length(" + name + "[i]) for i in 1:length(" +
name + ") ]")
a.julia_arg = ("convert(Vector{Vector{Cint}}," + name + "), " + api_name_n +
", length(" + name + ")")
return a
def ivectorvectordouble(name, value=None, python_value=None, julia_value=None):
......@@ -178,6 +184,10 @@ def ivectorvectordouble(name, value=None, python_value=None, julia_value=None):
" = _ivectorvectordouble(" + name + ")")
a.python_arg = api_name + ", " + api_name_n + ", " + api_name_nn
a.julia_ctype = "Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Csize_t"
a.julia_pre = (api_name_n + " = [ length(" + name + "[i]) for i in 1:length(" +
name + ") ]")
a.julia_arg = ("convert(Vector{Vector{Cdouble}}," + name + "), " + api_name_n +
", length(" + name + ")")
return a
# output types
......@@ -1023,12 +1033,13 @@ class API:
def write_julia(self):
def parg(a):
return a.name + ((" = " + a.julia_value) if a.julia_value else "")
def write_function(f, fun, modulepath):
def write_function(f, fun, c_mpath, jl_mpath):
(rtype, name, args, doc, rawc) = fun
iargs = list(a for a in args if not a.out)
oargs = list(a for a in args if a.out)
f.write('\n"""\n')
f.write("\n".join(textwrap.wrap(doc, 80)) + "\n")
f.write('\n"""\n\n ')
f.write(jl_mpath + name + "(" + ", ".join(parg(a) for a in args) + ")\n\n")
f.write("\n".join(textwrap.wrap(doc, 80)).replace("`", "'") + "\n")
if rtype or oargs:
f.write("\nReturn " + ", ".join(
(["an " + rtype.rtexi_type] if rtype else[])
......@@ -1042,9 +1053,9 @@ class API:
if a.julia_pre: f.write(" " + a.julia_pre + "\n")
f.write(" ierr = Vector{Cint}(1)\n ")
f.write("api__result__ = " if rtype is oint else "")
c_name = modulepath + name[0].upper() + name[1:]
c_name = c_mpath + name[0].upper() + name[1:]
f.write("ccall((:" + c_name + ", " +
("" if modulepath == "gmsh" else "gmsh.") + "clib), " +
("" if c_mpath == "gmsh" else "gmsh.") + "clib), " +
("Void" if rtype is None else rtype.rjulia_type) + ",\n" +
" " * 10 + "(" + ", ".join(
(tuple(a.julia_ctype for a in args) + ("Ptr{Cint}",))) +
......@@ -1061,8 +1072,9 @@ class API:
if len(r) != 0:
f.write(" return " + ", ".join(r) + "\n")
f.write("end\n")
def write_module(f, m, modulepath, level):
f.write('\n"""\n')
def write_module(f, m, c_mpath, jl_mpath, level):
f.write('\n"""\n\n ')
f.write("module " + jl_mpath + m.name + "\n\n")
f.write("\n".join(textwrap.wrap(m.doc, 80)) + "\n")
f.write('"""\n')
f.write("module " + m.name + "\n\n")
......@@ -1070,19 +1082,21 @@ class API:
f.write("const clib = \"libgmsh\"\n")
else:
f.write("import " + ("." * level) + "gmsh\n")
if modulepath:
modulepath += m.name[0].upper() + m.name[1:]
if c_mpath:
c_mpath += m.name[0].upper() + m.name[1:]
jl_mpath += m.name + "."
else:
modulepath = m.name
c_mpath = m.name
jl_mpath = m.name + "."
for fun in m.fs:
write_function(f, fun, modulepath)
write_function(f, fun, c_mpath, jl_mpath)
for module in m.submodules:
write_module(f, module, modulepath, level + 1)
write_module(f, module, c_mpath, jl_mpath, level + 1)
f.write("\nend # end of module " + m.name + "\n")
with open("gmsh.jl", "w") as f:
f.write(julia_header.format(self.api_version))
for module in self.modules:
write_module(f, module, "", 1)
write_module(f, module, "", "", 1)
def write_texi(self):
def write_module(module, parent):
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
import gmsh
gmsh.initialize(ARGS)
gmsh.option.setNumber("General.Terminal", 1)
gmsh.model.add("test");
# add discrete surface with tag 1
gmsh.model.addDiscreteEntity(2, 1)
# add 4 mesh nodes
gmsh.model.mesh.setNodes(2, 1,
[1, 2, 3, 4], # node tags: 1, 2, 3, and 4
[0., 0., 0., # coordinates of node 1
1., 0., 0., # coordinates of node 2
1., 1., 0., # ...
0., 1., 0.])
# add 2 triangles
gmsh.model.mesh.setElements(2, 1,
[2], # single type : 3-node triangle
[[1, 2]], # triangle tags: 1 and 2
[[1, 2, 3, # triangle 1: nodes 1, 2, 3
1, 3, 4]]) # triangle 2: nodes 1, 3, 4
# export the mesh ; use explore.py to read and examine the mesh
gmsh.write("test.msh")
gmsh.finalize()
......@@ -11,11 +11,11 @@ gmsh.model.addDiscreteEntity(2, 1)
# add 4 mesh nodes
gmsh.model.mesh.setNodes(2, 1,
[1, 2, 3, 4], # node tags: 1, 2, 3, and 4
[0., 0., 0., # coordinates of node 1
1., 0., 0., # coordinates of node 2
1., 1., 0., # ...
0., 1., 0.])
[1, 2, 3, 4], # node tags: 1, 2, 3, and 4
[0., 0., 0., # coordinates of node 1
1., 0., 0., # coordinates of node 2
1., 1., 0., # ...
0., 1., 0.])
# add 2 triangles
gmsh.model.mesh.setElements(2, 1,
......
/* This file reimplements gmsh/tutorial/t1.geo in C.
For all the elementary explanations about the general philosphy of entities
in Gmsh, see the comments in the .geo file. Comments here focus on the
specifics of the C API.
The Gmsh API is entirely defined in the <gmsh.h> header. Read this file: it
contains the documentation for all the functions in the API.
*/
#include <gmshc.h>
int main(int argc, char **argv)
{
int ierr;
double lc = 1e-2;
int cl1[] = {4, 1, -2, 3}, ps1[] = {1};
int pg1[] = {1, 2}, pg2[] = {1,2}, pg6[] = {1};
/* Before using any functions in the C API, Gmsh must be initialized. In the C
API the last argument of all functions return the error code, if any. */
gmshInitialize(argc, argv, 1, &ierr);
/* By default Gmsh will not print out any messages: in order to output
messages on the terminal, just set the standard Gmsh option
"General.Terminal" (same format and meaning as in .geo files) using
gmshOptionSetNumber() */
gmshOptionSetNumber("General.Terminal", 1, &ierr);
/* This adds a new model, named "t1". If gmshModelAdd() is not called, a
new default (unnamed) model will be created on the fly, if necessary. */
gmshModelAdd("t1", &ierr);
/* The C API provides direct access to the internal CAD kernels. The
built-in CAD kernel was used in t1.geo: the corresponding API functions
live in the "gmshModelGeo" namespace. To create geometrical points with
the built-in CAD kernel, one thus uses gmshModelGeoAddPoint():
- the first 3 arguments are the point coordinates (x, y, z)
- the next argument is the target mesh size close to the point
- the next argument is the point tag */
gmshModelGeoAddPoint(0, 0, 0, lc, 1, &ierr);
gmshModelGeoAddPoint(.1, 0, 0, lc, 2, &ierr);
gmshModelGeoAddPoint(.1, .3, 0, lc, 3, &ierr);
gmshModelGeoAddPoint(0, .3, 0, lc, 4, &ierr);
/* The API to create lines with the built-in kernel follows the same
conventions: the first 2 arguments are point tags, the last (optional one)
is the line tag. */
gmshModelGeoAddLine(1, 2, 1, &ierr);
gmshModelGeoAddLine(3, 2, 2, &ierr);
gmshModelGeoAddLine(3, 4, 3, &ierr);
gmshModelGeoAddLine(4, 1, 4, &ierr);
/* The philosophy to construct curve loops and surfaces is similar: the first
argument is now a vector of integers. */
gmshModelGeoAddCurveLoop(cl1, sizeof(cl1)/sizeof(cl1[0]), 1, &ierr);
gmshModelGeoAddPlaneSurface(ps1, sizeof(ps1)/sizeof(ps1[0]), 1, &ierr);
/* Physical groups are defined by providing the dimension of the group (0 for
physical points, 1 for physical curves, 2 for physical surfaces and 3 for
phsyical volumes) followed by a vector of entity tags. The last (optional)
argument is the tag of the new group to create. */
gmshModelAddPhysicalGroup(0, pg1, sizeof(pg1)/sizeof(pg1[0]), 1, &ierr);
gmshModelAddPhysicalGroup(1, pg2, sizeof(pg2)/sizeof(pg2[0]), 2, &ierr);
gmshModelAddPhysicalGroup(2, pg6, sizeof(pg6)/sizeof(pg6[0]), 6, &ierr);
/* Physical names are also defined by providing the dimension and tag of the
entity. */
gmshModelSetPhysicalName(2, 6, "My surface", &ierr);
/* Before it can be meshed, the internal CAD representation must be
synchronized with the Gmsh model, which will create the relevant Gmsh data
structures. This is achieved by the gmsh::model::geo::synchronize() API
call for the built-in CAD kernel. Synchronizations can be called at any
time, but they involve a non trivial amount of processing; so while you
could synchronize the internal CAD data after every CAD command, it is
usually better to minimize the number of synchronization points. */
gmshModelGeoSynchronize( &ierr);
/* We can then generate a 2D mesh... */
gmshModelMeshGenerate(2, &ierr);
/* ... and save it to disk */
gmshWrite("t1.msh", &ierr);
/* This should be called at the end: */
gmshFinalize(&ierr);
return 0;
}
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