Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Romin Tomasetti
gmsh
Commits
c3571cfb
Commit
c3571cfb
authored
7 years ago
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
basic Python stuff works
parent
552e3e07
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Common/gmsh.cpp
+1
-1
1 addition, 1 deletion
Common/gmsh.cpp
Common/gmsh.h
+2
-4
2 additions, 4 deletions
Common/gmsh.h
Common/gmsh.i
+10
-5
10 additions, 5 deletions
Common/gmsh.i
demos/api/t1.py
+86
-0
86 additions, 0 deletions
demos/api/t1.py
demos/api/t2.py
+110
-0
110 additions, 0 deletions
demos/api/t2.py
with
209 additions
and
10 deletions
Common/gmsh.cpp
+
1
−
1
View file @
c3571cfb
...
@@ -1262,7 +1262,7 @@ int gmshModelOccSynchronize()
...
@@ -1262,7 +1262,7 @@ int gmshModelOccSynchronize()
// gmshModelField
// gmshModelField
int
gmshModelField
Add
(
const
int
tag
,
const
std
::
string
&
type
)
int
gmshModelField
Create
(
const
int
tag
,
const
std
::
string
&
type
)
{
{
if
(
!
isInitialized
())
return
-
1
;
if
(
!
isInitialized
())
return
-
1
;
#if defined(HAVE_MESH)
#if defined(HAVE_MESH)
...
...
This diff is collapsed.
Click to expand it.
Common/gmsh.h
+
2
−
4
View file @
c3571cfb
...
@@ -293,7 +293,7 @@ GMSH_API gmshModelOccSynchronize();
...
@@ -293,7 +293,7 @@ GMSH_API gmshModelOccSynchronize();
// gmshModelField
// gmshModelField
GMSH_API
gmshModelField
Add
(
const
int
tag
,
const
std
::
string
&
type
);
GMSH_API
gmshModelField
Create
(
const
int
tag
,
const
std
::
string
&
type
);
GMSH_API
gmshModelFieldSetNumber
(
const
int
tag
,
const
std
::
string
&
option
,
GMSH_API
gmshModelFieldSetNumber
(
const
int
tag
,
const
std
::
string
&
option
,
const
double
value
);
const
double
value
);
GMSH_API
gmshModelFieldSetString
(
const
int
tag
,
const
std
::
string
&
option
,
GMSH_API
gmshModelFieldSetString
(
const
int
tag
,
const
std
::
string
&
option
,
...
@@ -303,9 +303,7 @@ GMSH_API gmshModelFieldSetNumbers(const int tag, const std::string &option,
...
@@ -303,9 +303,7 @@ GMSH_API gmshModelFieldSetNumbers(const int tag, const std::string &option,
GMSH_API
gmshModelFieldSetAsBackground
(
const
int
tag
);
GMSH_API
gmshModelFieldSetAsBackground
(
const
int
tag
);
GMSH_API
gmshModelFieldDelete
(
const
int
tag
);
GMSH_API
gmshModelFieldDelete
(
const
int
tag
);
// gmshSolver
// gmshView
// gmshPost
// gmshPlugin
// gmshPlugin
...
...
This diff is collapsed.
Click to expand it.
Common/gmsh.i
+
10
−
5
View file @
c3571cfb
%
module
gmsh
%
module
gmsh
%
include
typemaps
.
i
// reference to int is appended to the returned values of the function
%
apply
int
&OUTPUT
{ int &outTag }
;
%
{
%
{
#include "gmsh.h"
#include "gmsh.h"
%}
%}
%
include
std_string
.
i
%
include
std_string
.
i
%
include
std_vector
.
i
%
include
std_vector
.
i
%
include
std_pair
.
i
namespace
std
{
%
template
()
std
::
pair
<
int
,
int
>
;
%template(DoubleVector) vector<double>;
%
template
(
IntVector
)
std
::
vector
<
int
>
;
%template(StringVector) vector<string>;
%
template
(
DoubleVector
)
std
::
vector
<
double
>
;
%template(PairVector) vector<std::pair<int, int> >;
%
template
(
StringVector
)
std
::
vector
<
std
::
string
>
;
}
%
template
(
PairVector
)
std
::
vector
<
std
::
pair
<
int
,
int
>
>
;
%
template
(
PairVectorVector
)
std
::
vector
<
std
::
vector
<
std
::
pair
<
int
,
int
>
>
>
;
%
include
"
gmsh.h
"
%
include
"
gmsh.h
"
This diff is collapsed.
Click to expand it.
demos/api/t1.py
0 → 100644
+
86
−
0
View file @
c3571cfb
#!/usr/bin/env python
# This file reimplements gmsh/tutorial/t1.geo in Python. For all the elementary
# explanations about the general philosphy of entities in Gmsh, see the
# comments in the .geo file. Comments here will focus on the specifics of the
# Python API.
# The Gmsh API is entirely defined in the gmsh module
from
gmsh
import
*
# Before using any functions in the Python API, Gmsh must be initialized. If
# argc/argv are passed, Gmsh will parse the commandline in the same way as the
# standalone Gmsh code.
gmshInitialize
();
# 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
);
# This creates a new model, named "t1". If gmshModelCreate() is not called, a
# new default (unnamed) model will be created on the fly, if necessary.
gmshModelCreate
(
"
t1
"
);
# 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 have the
# "gmshModeGeo" prefix. To create geometrical points with the built-in CAD
# kernel, one thus uses gmshModelGeoAddPoint():
#
# - the first argument is the point tag ; if positive, the point is created with
# this tag ; if negative, a new (unused) tag will be assigned and returned as
# the second value after the return code, i.e. gmshModelGeoAddPoint(3, .1, .3,
# 0, lc) will return [0 3]
#
# - the next 3 arguments are the point coordinates (x, y, z)
#
# - the last (optional) argument is the target mesh size close to the point
lc
=
1e-2
;
gmshModelGeoAddPoint
(
1
,
0
,
0
,
0
,
lc
);
gmshModelGeoAddPoint
(
2
,
.
1
,
0
,
0
,
lc
);
gmshModelGeoAddPoint
(
3
,
.
1
,
.
3
,
0
,
lc
);
gmshModelGeoAddPoint
(
4
,
0
,
.
3
,
0
,
lc
);
# The API to create lines with the built-in kernel follows the same conventions:
# the first argument is a tag (here positive to force it), followed by 2 point
# tags, followed by the actual (returned) tag.
gmshModelGeoAddLine
(
1
,
1
,
2
);
gmshModelGeoAddLine
(
2
,
3
,
2
);
gmshModelGeoAddLine
(
3
,
3
,
4
);
gmshModelGeoAddLine
(
4
,
4
,
1
);
# The philosophy to construct line loops and surfaces is similar: the second
# arguments are now vectors of integers.
gmshModelGeoAddLineLoop
(
1
,
[
4
,
1
,
-
2
,
3
]);
gmshModelGeoAddPlaneSurface
(
1
,
[
1
]);
# Physical groups are defined by providing the dimension of the group (0 for
# physical points, 1 for physical lines, 2 for physical surfaces and 3 for
# phsyical volumes) and its tag, followed by a vector of entity tags.
gmshModelAddPhysicalGroup
(
0
,
1
,
[
1
,
2
]);
gmshModelAddPhysicalGroup
(
1
,
2
,
[
1
,
2
]);
gmshModelAddPhysicalGroup
(
2
,
6
,
[
1
]);
# Physical names are also defined by providing the dimension and tag of the
# entity.
gmshModelSetPhysicalName
(
2
,
6
,
"
My surface
"
);
# 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 gmshModelGeoSynchronize() 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
();
# We can then generate a 2D mesh...
gmshModelMesh
(
2
);
# ... and save it to disk
gmshExport
(
"
t1.msh
"
);
# This should be called at the end:
gmshFinalize
();
This diff is collapsed.
Click to expand it.
demos/api/t2.py
0 → 100644
+
110
−
0
View file @
c3571cfb
#!/usr/bin/env python
# This file reimplements gmsh/tutorial/t2.geo in Python. Comments focus on the new
# API functions used, compared to the ones introduced in t1.py.
from
gmsh
import
*
gmshInitialize
();
gmshOptionSetNumber
(
"
General.Terminal
"
,
1
);
gmshModelCreate
(
"
t2
"
);
# Copied from t1.cpp...
lc
=
1e-2
;
gmshModelGeoAddPoint
(
1
,
0
,
0
,
0
,
lc
);
gmshModelGeoAddPoint
(
2
,
.
1
,
0
,
0
,
lc
);
gmshModelGeoAddPoint
(
3
,
.
1
,
.
3
,
0
,
lc
);
gmshModelGeoAddPoint
(
4
,
0
,
.
3
,
0
,
lc
);
gmshModelGeoAddLine
(
1
,
1
,
2
);
gmshModelGeoAddLine
(
2
,
3
,
2
);
gmshModelGeoAddLine
(
3
,
3
,
4
);
gmshModelGeoAddLine
(
4
,
4
,
1
);
gmshModelGeoAddLineLoop
(
1
,
[
4
,
1
,
-
2
,
3
]);
gmshModelGeoAddPlaneSurface
(
1
,
[
1
]);
gmshModelAddPhysicalGroup
(
0
,
1
,
[
1
,
2
]);
gmshModelAddPhysicalGroup
(
1
,
2
,
[
1
,
2
]);
gmshModelAddPhysicalGroup
(
2
,
6
,
[
1
]);
gmshModelSetPhysicalName
(
2
,
6
,
"
My surface
"
);
# ...end of copy
gmshModelGeoAddPoint
(
5
,
0
,
.
4
,
0
,
lc
);
gmshModelGeoAddLine
(
5
,
4
,
5
);
# Geometrical transformations take a vector of pairs of integers as first
# argument, which contains the list of entities, represented by (dimension, tag)
# pairs. Here we thus translate point 3 (dimension=0, tag=3), by dx=-0.05, dy=0,
# dz=0.
gmshModelGeoTranslate
([(
0
,
3
)],
-
0.05
,
0
,
0
);
# The "Duplicata" functionality in .geo files is handled by
# gmshModelGeoCopy(), which takes a vector of (dim, tag) pairs as input, and
# returns another vector of (dim, tag) pairs.
ov
=
PairVector
()
gmshModelGeoCopy
([(
0
,
3
)],
ov
);
gmshModelGeoTranslate
(
ov
,
0
,
0.1
,
0
);
gmshModelGeoAddLine
(
7
,
3
,
ov
[
0
][
1
]);
gmshModelGeoAddLine
(
8
,
ov
[
0
][
1
],
5
);
gmshModelGeoAddLineLoop
(
10
,
[
5
,
-
8
,
-
7
,
3
]);
gmshModelGeoAddPlaneSurface
(
11
,
[
10
]);
gmshModelGeoCopy
([(
2
,
1
),
(
2
,
11
)],
ov
);
gmshModelGeoTranslate
(
ov
,
0.12
,
0
,
0
);
print
"
New surfaces
'
%d
'
and
'
%d
'
\n
"
,
ov
[
0
][
1
],
ov
[
1
][
1
];
gmshModelGeoAddPoint
(
100
,
0.
,
0.3
,
0.13
,
lc
);
gmshModelGeoAddPoint
(
101
,
0.08
,
0.3
,
0.1
,
lc
);
gmshModelGeoAddPoint
(
102
,
0.08
,
0.4
,
0.1
,
lc
);
gmshModelGeoAddPoint
(
103
,
0.
,
0.4
,
0.13
,
lc
);
gmshModelGeoAddLine
(
110
,
4
,
100
);
gmshModelGeoAddLine
(
111
,
3
,
101
);
gmshModelGeoAddLine
(
112
,
6
,
102
);
gmshModelGeoAddLine
(
113
,
5
,
103
);
gmshModelGeoAddLine
(
114
,
103
,
100
);
gmshModelGeoAddLine
(
115
,
100
,
101
);
gmshModelGeoAddLine
(
116
,
101
,
102
);
gmshModelGeoAddLine
(
117
,
102
,
103
);
gmshModelGeoAddLineLoop
(
118
,
[
115
,
-
111
,
3
,
110
]);
gmshModelGeoAddPlaneSurface
(
119
,
[
118
]);
gmshModelGeoAddLineLoop
(
120
,
[
111
,
116
,
-
112
,
-
7
]);
gmshModelGeoAddPlaneSurface
(
121
,
[
120
]);
gmshModelGeoAddLineLoop
(
122
,
[
112
,
117
,
-
113
,
-
8
]);
gmshModelGeoAddPlaneSurface
(
123
,
[
122
]);
gmshModelGeoAddLineLoop
(
124
,
[
114
,
-
110
,
5
,
113
]);
gmshModelGeoAddPlaneSurface
(
125
,
[
124
]);
gmshModelGeoAddLineLoop
(
126
,
[
115
,
116
,
117
,
114
]);
gmshModelGeoAddPlaneSurface
(
127
,
[
126
]);
# The API to create surface loops ("shells") and volumes is similar to the
# one used to create line loops and surfaces.
gmshModelGeoAddSurfaceLoop
(
128
,
[
127
,
119
,
121
,
123
,
125
,
11
]);
gmshModelGeoAddVolume
(
129
,
[
128
]);
# Extrusion works as expected, by providing a vector of (dim, tag) pairs as
# input, the translation vector, and a vector of (dim, tag) pairs as output.
ov2
=
PairVector
()
gmshModelGeoExtrude
([
ov
[
1
]],
0
,
0
,
0.12
,
ov2
);
# Mesh sizes associated to geometrical points can be set by passing a vector of
# (dim, tag) pairs for the corresponding points.
gmshModelGeoSetMeshSize
([(
0
,
103
),
(
0
,
105
),
(
0
,
109
),
(
0
,
102
),
(
0
,
28
),
(
0
,
24
),
(
0
,
6
),
(
0
,
5
)],
lc
*
3
);
gmshModelAddPhysicalGroup
(
3
,
1
,
[
129
,
130
]);
gmshModelSetPhysicalName
(
3
,
1
,
"
The volume
"
);
gmshModelGeoSynchronize
();
gmshModelMesh
(
3
);
gmshExport
(
"
t2.msh
"
);
gmshFinalize
();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment