Skip to content

Commit

Permalink
Add raster mesh (#45)
Browse files Browse the repository at this point in the history
addresses (#44)
  • Loading branch information
kip-hart authored Sep 9, 2021
1 parent cb1a18c commit e2854df
Show file tree
Hide file tree
Showing 6 changed files with 701 additions and 16 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog`_,
and this project adheres to `Semantic Versioning`_.

`1.5.0`_ - 2021-09-08
--------------------------
Added
'''''
- RasterMesh class, to create pixel/voxel meshes. (addresses `#44`_)

`1.4.10`_ - 2021-06-08
--------------------------
Fixed
Expand Down Expand Up @@ -237,7 +243,8 @@ Added

.. LINKS
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.10...HEAD
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.5.0...HEAD
.. _`1.5.0`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.10...v1.5.0
.. _`1.4.10`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.9...v1.4.10
.. _`1.4.9`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.8...v1.4.9
.. _`1.4.8`: https://github.com/kip-hart/MicroStructPy/compare/v1.4.7...v1.4.8
Expand Down Expand Up @@ -270,3 +277,4 @@ Added

.. _`#14`: https://github.com/kip-hart/MicroStructPy/issues/14
.. _`#16`: https://github.com/kip-hart/MicroStructPy/issues/16
.. _`#44`: https://github.com/kip-hart/MicroStructPy/issues/44
14 changes: 13 additions & 1 deletion docs/source/cli/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ quality, among other things. The default settings are:
<edge_opt> False </edge_opt>
<edge_opt_n_iter> 100 </edge_opt_n_iter>
<mesher> Triangle/TetGen </mesher>
<mesher> Triangle/TetGen </mesher>
<mesh_size> inf </mesh_size> <!-- used with gmsh -->
<mesh_max_volume> inf </mesh_max_volume> <!-- used with Triangle and TetGen -->
Expand Down Expand Up @@ -286,6 +286,18 @@ The default is ``<edge_opt_n_iter> 100 </edge_opt_n_iter>``, which limits the
optimizer to 100 attempts per edge.
This field is ignored if ``edge_opt`` is set to ``False``.

mesher
------

This field specifies how to mesh the PolyMesh. If set to ``raster``, the output
mesh will contain pixels/voxels of the PolyMesh.
Other options include ``Triangle/Tetgen`` and ``gmsh``.

mesh_size
---------

This field specifies a target element size if using the ``gmsh`` mesher.

mesh_max_volume
---------------

Expand Down
2 changes: 1 addition & 1 deletion src/microstructpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
import microstructpy.seeding
import microstructpy.verification

__version__ = '1.4.10'
__version__ = '1.5.0'
42 changes: 32 additions & 10 deletions src/microstructpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from microstructpy import seeding
from microstructpy import verification
from microstructpy.meshing import PolyMesh
from microstructpy.meshing import RasterMesh
from microstructpy.meshing import TriMesh
from microstructpy.meshing.trimesh import facet_check

Expand Down Expand Up @@ -301,7 +302,8 @@ def run(phases, domain, verbose=False, restart=True, directory='.',
edge_opt_n_iter (int): *(optional)* Maximum number of iterations per
edge during optimization. Ignored if `edge_opt` set to False.
Defaults to 100.
mesher (str): {'Triangle/TetGen' | 'Triangle' | 'TetGen' | 'gmsh'}
mesher (str): {'raster' | 'Triangle/TetGen' | 'Triangle' | 'TetGen' |
'gmsh'}
specify the mesh generator. Default is 'Triangle/TetGen'.
mesh_max_volume (float): *(optional)* The maximum volume (area in 2D)
of a mesh cell in the triangular mesh. Default is infinity,
Expand Down Expand Up @@ -491,28 +493,41 @@ def run(phases, domain, verbose=False, restart=True, directory='.',
# ----------------------------------------------------------------------- #
# Create Triangular Mesh #
# ----------------------------------------------------------------------- #
tri_basename = 'trimesh.txt'
raster = mesher == 'raster'
if raster:
tri_basename = 'rastermesh.txt'
else:
tri_basename = 'trimesh.txt'
tri_filename = os.path.join(directory, tri_basename)
exts = {'abaqus': '.inp', 'txt': '.txt', 'str': '.txt', 'tet/tri': '',
'vtk': '.vtk'}

if restart and os.path.exists(tri_filename) and not poly_created:
# Read triangle mesh
if verbose:
print('Reading triangular mesh.')
print('Triangular mesh filename: ' + tri_filename)
if raster:
print('Reading raster mesh.')
else:
print('Reading triangular mesh.')
print('Mesh filename: ' + tri_filename)

tmesh = TriMesh.from_file(tri_filename)
tri_created = False
else:
tri_created = True
# Create triangular mesh
if verbose:
print('Creating triangular mesh.')
if raster:
print('Creating raster mesh.')
else:
print('Creating triangular mesh.')

tmesh = TriMesh.from_polymesh(pmesh, phases, mesher, mesh_min_angle,
mesh_max_volume, mesh_max_edge_length,
mesh_size)
if raster:
tmesh = RasterMesh.from_polymesh(pmesh, mesh_size, phases)
else:
tmesh = TriMesh.from_polymesh(pmesh, phases, mesher,
mesh_min_angle, mesh_max_volume,
mesh_max_edge_length, mesh_size)

# Write triangular mesh
tri_types = filetypes.get('tri', [])
Expand All @@ -535,12 +550,19 @@ def run(phases, domain, verbose=False, restart=True, directory='.',

plot_files = []
for ext in plot_types:
fname = os.path.join(directory, 'trimesh.' + str(ext))
if raster:
bname = 'rastermesh'
else:
bname = 'trimesh'
fname = os.path.join(directory, bname + '.' + str(ext))
if tri_created or not os.path.exists(fname):
plot_files.append(fname)

if plot_files and verbose:
print('Plotting triangular mesh.')
if raster:
print('Plotting raster mesh.')
else:
print('Plotting triangular mesh.')

if plot_files:
plot_tri(tmesh, phases, seeds, pmesh, plot_files, plot_axes, color_by,
Expand Down
3 changes: 2 additions & 1 deletion src/microstructpy/meshing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from microstructpy.meshing.polymesh import PolyMesh
from microstructpy.meshing.trimesh import RasterMesh
from microstructpy.meshing.trimesh import TriMesh

__all__ = ['PolyMesh', 'TriMesh']
__all__ = ['PolyMesh', 'RasterMesh', 'TriMesh']
Loading

0 comments on commit e2854df

Please sign in to comment.