Skip to content

Commit 9e012a3

Browse files
committed
can specify mesh size on grain boundaries when using gmsh
1 parent 42046a9 commit 9e012a3

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

CHANGELOG.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ All notable changes to this project will be documented in this file.
66
The format is based on `Keep a Changelog`_,
77
and this project adheres to `Semantic Versioning`_.
88

9+
`1.4.5`_ - 2020-12-24
10+
--------------------------
11+
Added
12+
'''''''
13+
- Meshing with gmsh can now use different mesh sizes in the interior and on the
14+
boundary of grains. The ``<mesh_max_edge_length>`` tag specifies edge lengths
15+
on the boundary and ``<mesh_size>`` on the interior.
16+
If ``<mesh_max_edge_length>`` is not used, ``<mesh_size>`` is used
17+
throughout.
18+
919
`1.4.4`_ - 2020-12-22
1020
--------------------------
1121
Fixed
@@ -190,7 +200,8 @@ Added
190200

191201
.. LINKS
192202
193-
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.4...HEAD
203+
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.5...HEAD
204+
.. _`1.4.5`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.5...v1.4.5
194205
.. _`1.4.4`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.3...v1.4.4
195206
.. _`1.4.3`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.2...v1.4.3
196207
.. _`1.4.2`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.1...v1.4.2

src/microstructpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
import microstructpy.seeding
55
import microstructpy.verification
66

7-
__version__ = '1.4.4'
7+
__version__ = '1.4.5'

src/microstructpy/meshing/trimesh.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def from_polymesh(cls, polymesh, phases=None, mesher='Triangle/Tetgen',
201201
tri_args = _call_meshpy(polymesh, phases, min_angle, max_volume,
202202
max_edge_length)
203203
elif key == 'gmsh':
204-
tri_args = _call_gmsh(polymesh, phases, mesh_size)
204+
tri_args = _call_gmsh(polymesh, phases, mesh_size, max_edge_length)
205205

206206
return cls(*tri_args)
207207

@@ -845,9 +845,12 @@ def _call_meshpy(polymesh, phases=None, min_angle=0, max_volume=float('inf'),
845845
return tri_args
846846

847847

848-
def _call_gmsh(pmesh, phases, res):
848+
def _call_gmsh(pmesh, phases, res, edge_res):
849849
if res == float('inf'):
850850
res = None
851+
# If edge length not specified, default to mesh size input
852+
if edge_res == float('inf'):
853+
edge_res = res
851854

852855
amorph_seeds = _amorphous_seed_numbers(pmesh, phases)
853856

@@ -913,7 +916,8 @@ def _call_gmsh(pmesh, phases, res):
913916
# ----------------------------------------------------------------------
914917
with pg.geo.Geometry() as geom:
915918
# Add points
916-
pts = [geom.add_point(_pt3d(pt), res) for pt in pmesh.points]
919+
pt_arr = np.array(pmesh.points)
920+
pts = [geom.add_point(_pt3d(pt), edge_res) for pt in pmesh.points]
917921
n_dim = len(pmesh.points[0])
918922

919923
# Add edges to geometry
@@ -958,12 +962,19 @@ def _call_gmsh(pmesh, phases, res):
958962
mat_type = phases[p_num].get('material_type', 'solid')
959963
if mat_type not in _misc.kw_void:
960964
geom.add_physical(surfs[-1], 'seed-' + str(i))
965+
# Add mesh size control points to 'centers' of regions
966+
if res is not None:
967+
kps = list({kp for p in sorted_pairs for kp in p})
968+
cen = pt_arr[kps].mean(axis=0) # estimate of center
969+
pt = geom.add_point(_pt3d(cen), res)
970+
geom.in_surface(pt, surfs[-1])
961971

962972
elif n_dim == 3:
963973
# Add surfaces to geometry
964974
loops = []
965975
surfs = []
966976
seed_surfs = {}
977+
surf_kps = {}
967978
seed_phases = dict(zip(pmesh.seed_numbers, pmesh.phase_numbers))
968979
for i in facets_info:
969980
info = facets_info[i]
@@ -982,6 +993,7 @@ def _call_gmsh(pmesh, phases, res):
982993
loop.append(-line)
983994
loops.append(geom.add_curve_loop(loop))
984995
surfs.append(geom.add_plane_surface(loops[-1]))
996+
surf_kps[surfs[-1]] = set(info['facet'])
985997
if facet_check(info['neighbors'], pmesh, phases):
986998
geom.add_physical(surfs[-1], 'facet-' + str(i))
987999
for seed_num in facet_seeds:
@@ -1001,6 +1013,12 @@ def _call_gmsh(pmesh, phases, res):
10011013
mat_type = phases[p_num].get('material_type', 'solid')
10021014
if mat_type not in _misc.kw_void:
10031015
geom.add_physical(volumes[-1], 'seed-' + str(seed_num))
1016+
# Add mesh size control points to 'centers' of regions
1017+
if res is not None:
1018+
kps = set().union(*[surf_kps[s] for s in surf_loop])
1019+
cen = pt_arr[list(kps)].mean(axis=0) # estimate center
1020+
pt = geom.add_point(_pt3d(cen), res)
1021+
geom.in_surface(pt, surfs[-1])
10041022
else:
10051023
raise ValueError('Points cannot have dimension ' + str(n_dim) + '.')
10061024

0 commit comments

Comments
 (0)