Skip to content

Commit 4c73e03

Browse files
authored
Merge pull request #14 from GeoStat-Framework/remove_pygmesh
remove pygmsh support
2 parents 285e41d + 8250df3 commit 4c73e03

File tree

9 files changed

+203
-100
lines changed

9 files changed

+203
-100
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
All notable changes to **ogs5py** will be documented in this file.
44

55

6+
## [1.2.1] - 2020-05-15
7+
8+
### Enhancements
9+
* `MSH.import_mesh` can handle `meshio.Mesh` as input now [#13](https://github.com/GeoStat-Framework/ogs5py/pull/13)
10+
11+
### Changes
12+
* `pygmsh` support was removed. You can't use pygmsh Geometry objects to generate meshes anymore. Please generate beforehand and import the generated mesh. Other generators are using `gmsh` directly now. [#13](https://github.com/GeoStat-Framework/ogs5py/pull/13)
13+
14+
615
## [1.2.0] - 2020-05-15
716

817
### Enhancements
@@ -169,7 +178,8 @@ All notable changes to **ogs5py** will be documented in this file.
169178
First release of ogs5py.
170179

171180

172-
[Unreleased]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.2.0...HEAD
181+
[Unreleased]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.2.1...HEAD
182+
[1.2.1]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.2.0...v1.2.1
173183
[1.2.0]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.1.1...v1.2.0
174184
[1.1.1]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.1.0...v1.1.1
175185
[1.1.0]: https://github.com/GeoStat-Framework/ogs5py/compare/v1.0.5...v1.1.0

docs/source/tutorial_03_gmsh.rst

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,43 @@ Tutorial 2: Interaction with pygmsh
22
===================================
33

44
In this example we are generating different meshes with the aid of
5-
`pygmsh <https://github.com/nschloe/pygmsh>`_..
5+
`pygmsh <https://github.com/nschloe/pygmsh>`_ and `gmsh <https://gmsh.info>`_
66

77
.. code-block:: python
88
99
import numpy as np
10-
from ogs5py import OGS
1110
import pygmsh
1211
13-
geom = pygmsh.built_in.Geometry()
14-
poly = geom.add_polygon([
15-
[ 0.0, 0.5, 0.0],
16-
[-0.1, 0.1, 0.0],
17-
[-0.5, 0.0, 0.0],
18-
[-0.1, -0.1, 0.0],
19-
[ 0.0, -0.5, 0.0],
20-
[ 0.1, -0.1, 0.0],
21-
[ 0.5, 0.0, 0.0],
22-
[ 0.1, 0.1, 0.0]
23-
],
24-
lcar=0.05
25-
)
26-
axis = [0, 0, 1]
27-
geom.extrude(
28-
poly,
29-
translation_axis=axis,
30-
rotation_axis=axis,
31-
point_on_axis=[0, 0, 0],
32-
angle=2.0 / 6.0 * np.pi
33-
)
34-
model = OGS() # dummy model
12+
from ogs5py import OGS
13+
14+
with pygmsh.geo.Geometry() as geom:
15+
poly = geom.add_polygon(
16+
[
17+
[+0.0, +0.5],
18+
[-0.1, +0.1],
19+
[-0.5, +0.0],
20+
[-0.1, -0.1],
21+
[+0.0, -0.5],
22+
[+0.1, -0.1],
23+
[+0.5, +0.0],
24+
[+0.1, +0.1],
25+
],
26+
mesh_size=0.05,
27+
)
28+
29+
geom.twist(
30+
poly,
31+
translation_axis=[0, 0, 1],
32+
rotation_axis=[0, 0, 1],
33+
point_on_axis=[0, 0, 0],
34+
angle=np.pi / 3,
35+
)
36+
37+
mesh = geom.generate_mesh()
38+
39+
model = OGS()
3540
# generate example above
36-
model.msh.generate("gmsh", geo_object=geom)
41+
model.msh.import_mesh(mesh, import_dim=3)
3742
model.msh.show()
3843
# generate a predefined grid adapter in 2D
3944
model.msh.generate("grid_adapter2D", in_mat=1, out_mat=0, fill=True)

examples/03_pygmsh_generated.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,34 @@
44

55
from ogs5py import OGS
66

7-
geom = pygmsh.built_in.Geometry()
8-
poly = geom.add_polygon(
9-
[
10-
[0.0, 0.5, 0.0],
11-
[-0.1, 0.1, 0.0],
12-
[-0.5, 0.0, 0.0],
13-
[-0.1, -0.1, 0.0],
14-
[0.0, -0.5, 0.0],
15-
[0.1, -0.1, 0.0],
16-
[0.5, 0.0, 0.0],
17-
[0.1, 0.1, 0.0],
18-
],
19-
lcar=0.05,
20-
)
21-
axis = [0, 0, 1]
22-
geom.extrude(
23-
poly,
24-
translation_axis=axis,
25-
rotation_axis=axis,
26-
point_on_axis=[0, 0, 0],
27-
angle=2.0 / 6.0 * np.pi,
28-
)
7+
with pygmsh.geo.Geometry() as geom:
8+
poly = geom.add_polygon(
9+
[
10+
[+0.0, +0.5],
11+
[-0.1, +0.1],
12+
[-0.5, +0.0],
13+
[-0.1, -0.1],
14+
[+0.0, -0.5],
15+
[+0.1, -0.1],
16+
[+0.5, +0.0],
17+
[+0.1, +0.1],
18+
],
19+
mesh_size=0.05,
20+
)
21+
22+
geom.twist(
23+
poly,
24+
translation_axis=[0, 0, 1],
25+
rotation_axis=[0, 0, 1],
26+
point_on_axis=[0, 0, 0],
27+
angle=np.pi / 3,
28+
)
29+
30+
mesh = geom.generate_mesh()
31+
2932
model = OGS()
3033
# generate example above
31-
model.msh.generate("gmsh", geo_object=geom)
34+
model.msh.import_mesh(mesh, import_dim=3)
3235
model.msh.show()
3336
# generate a predefined grid adapter in 2D
3437
model.msh.generate("grid_adapter2D", in_mat=1, out_mat=0, fill=True)

ogs5py/fileclasses/msh/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,8 @@ def import_mesh(self, filepath, **kwargs):
773773
774774
Parameters
775775
----------
776-
filepath : string
777-
path to the mesh file to import
776+
filepath : string or meshio.Mesh instance
777+
mesh to import
778778
file_format : str, optional
779779
Here you can specify the fileformat. If 'None' it will be
780780
determined by file extension. Default: None

ogs5py/fileclasses/msh/generator.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
# -*- coding: utf-8 -*-
32
"""
43
Generators for the ogs MESH file.
54
@@ -585,13 +584,12 @@ def block_adapter3D(xy_dim=10.0, z_dim=5.0, in_res=1.0):
585584

586585
def gmsh(geo_object, import_dim=(1, 2, 3)):
587586
"""
588-
Generate mesh from pygmsh Geometry instance, gmsh code or gmsh .geo file.
587+
Generate mesh from gmsh code or gmsh .geo file.
589588
590589
Parameters
591590
----------
592-
geo_object : str or list of str or Geometry instance from pygmsh
593-
Either path to the gmsh .geo file, list of codelines for a .geo file
594-
or a pygmsh Geometry instance from pygmsh.
591+
geo_object : str or list of str
592+
Either path to the gmsh .geo file or list of codelines for a .geo file.
595593
import_dim : iterable of int or single int, optional
596594
State which elements should be imported by dimensionality.
597595
Default: (1, 2, 3)
@@ -621,11 +619,8 @@ def gmsh(geo_object, import_dim=(1, 2, 3)):
621619
element_id : dict
622620
contains element ids for each element sorted by element types
623621
"""
624-
import pygmsh as pg
622+
from ogs5py.fileclasses.msh.helpers import generate_mesh
625623

626-
if hasattr(geo_object, "get_code"):
627-
geo = geo_object
628-
else:
629-
geo = gmsh_code(geo_object)
630-
mesh = pg.generate_mesh(geo)
624+
geo = gmsh_code(geo_object)
625+
mesh = generate_mesh(geo)
631626
return convert_meshio(mesh, import_dim=import_dim)

ogs5py/fileclasses/msh/gmsh.py

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,20 @@
44

55
def gmsh_code(path_or_code):
66
"""Generate mesh with gmsh."""
7-
try:
8-
from pygmsh import Geometry
9-
except ImportError:
10-
from pygmsh.built_in import Geometry
11-
12-
geo = Geometry()
137
if isinstance(path_or_code, list):
14-
code = map(str, path_or_code)
8+
code = list(map(str, path_or_code))
159
else:
1610
try:
1711
with open(path_or_code, "r") as gmsh_f:
1812
code = gmsh_f.readlines()
1913
except (OSError, IOError):
2014
print("gmsh_code: could not read file...")
21-
return geo
22-
geo.add_raw_code(code)
23-
return geo
15+
code = []
16+
return code
2417

2518

2619
def gmsh_block_adapt3D(xy_dim=10.0, z_dim=5.0, in_res=1.0):
2720
"""Generate the mesh adapter."""
28-
try:
29-
from pygmsh import Geometry
30-
except ImportError:
31-
from pygmsh.built_in import Geometry
32-
33-
geo = Geometry()
3421
code = [
3522
f"xydim = {xy_dim};",
3623
f"zdim = {z_dim};",
@@ -49,8 +36,7 @@ def gmsh_block_adapt3D(xy_dim=10.0, z_dim=5.0, in_res=1.0):
4936
"Plane Surface(1) = {1};",
5037
"Extrude{0,0,zdim}{Surface{1};Layers{1};Recombine;};",
5138
]
52-
geo.add_raw_code(code)
53-
return geo
39+
return code
5440

5541

5642
def gmsh_grid_adapt3D(
@@ -64,12 +50,6 @@ def gmsh_grid_adapt3D(
6450
z_pos=0.0,
6551
):
6652
"""Generate the mesh adapter."""
67-
try:
68-
from pygmsh import Geometry
69-
except ImportError:
70-
from pygmsh.built_in import Geometry
71-
72-
geo = Geometry()
7353
code = [
7454
# "// layer thickness",
7555
f"dimz = {z_dim};",
@@ -199,8 +179,7 @@ def gmsh_grid_adapt3D(
199179
"Surface Loop(48) = {39, 28, 33, 35, 37, 31, 47, 41, 43, 45};",
200180
"Volume(49) = {48};",
201181
]
202-
geo.add_raw_code(code)
203-
return geo
182+
return code
204183

205184

206185
def gmsh_grid_adapt2D(
@@ -213,12 +192,6 @@ def gmsh_grid_adapt2D(
213192
z_pos=0.0,
214193
):
215194
"""Generate the 2D mesh adapter."""
216-
try:
217-
from pygmsh import Geometry
218-
except ImportError:
219-
from pygmsh.built_in import Geometry
220-
221-
geo = Geometry()
222195
code = [
223196
# "// size of the outer block",
224197
f"outx = {out_dim[0]};",
@@ -271,5 +244,4 @@ def gmsh_grid_adapt2D(
271244
"Transfinite Line{13, 15} = inx/grix + 1;",
272245
"Transfinite Line{14, 16} = iny/griy + 1;",
273246
]
274-
geo.add_raw_code(code)
275-
return geo
247+
return code

0 commit comments

Comments
 (0)