Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tutorial to show how to use pyvista-gmsh which is inspired by gmsh tutorial #1

Merged
merged 46 commits into from
Dec 23, 2023
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7518f69
Add Gmsh Python tutorial 1
tkoyama010 Jul 25, 2022
f3639ae
Apply suggestions from code review
tkoyama010 Jul 27, 2022
bf51731
Apply suggestions from code review
tkoyama010 Jul 27, 2022
69e747f
Update test_gmsh.py
tkoyama010 Jul 27, 2022
78705f4
Update test_gmsh.py
tkoyama010 Jul 27, 2022
c310942
Update test_gmsh.py
tkoyama010 Jul 27, 2022
a4f3a43
Update test_gmsh.py
tkoyama010 Jul 27, 2022
7d6d207
Update test_gmsh.py
tkoyama010 Jul 27, 2022
191f40c
Create testing-and-deployment.yml
tkoyama010 Jul 28, 2022
fc3dc04
Update testing-and-deployment.yml
tkoyama010 Jul 28, 2022
f392c53
Update testing-and-deployment.yml
tkoyama010 Jul 28, 2022
3282555
Create requirements_test.txt
tkoyama010 Jul 28, 2022
dafe7d6
Update requirements_test.txt
tkoyama010 Jul 28, 2022
22d0322
Update testing-and-deployment.yml
tkoyama010 Jul 28, 2022
4fb7e69
Create __init__.py
tkoyama010 Jul 28, 2022
c98ae8e
Update test_gmsh.py
tkoyama010 Jul 28, 2022
f8e2d7d
Update test_gmsh.py
tkoyama010 Jul 28, 2022
36b4a09
Update testing-and-deployment.yml
tkoyama010 Jul 28, 2022
5b13c23
Update test_gmsh.py
tkoyama010 Jul 28, 2022
de2da97
Update test_gmsh.py
tkoyama010 Jul 28, 2022
7bd9c57
Update __init__.py
tkoyama010 Jul 29, 2022
1cfb1d9
Update __init__.py
tkoyama010 Jul 29, 2022
b49b7c2
Update __init__.py
tkoyama010 Jul 29, 2022
0b9f14b
Update __init__.py
tkoyama010 Jul 29, 2022
26fdc47
Update testing-and-deployment.yml
tkoyama010 Aug 1, 2022
6afc9d5
Update test_gmsh.py
tkoyama010 Aug 1, 2022
8180a0a
Update __init__.py
tkoyama010 Aug 1, 2022
08bee79
Update requirements_test.txt
tkoyama010 Aug 1, 2022
716f4a2
Create tutorial1.py
tkoyama010 Apr 23, 2023
ed00b6f
Create .pre-commit-config.yaml
tkoyama010 Apr 23, 2023
94f4e1f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 23, 2023
1ad238f
Update test_gmsh.py
tkoyama010 Apr 23, 2023
3f98c28
Update __init__.py
tkoyama010 Apr 24, 2023
94d81f4
Update testing-and-deployment.yml
tkoyama010 Dec 21, 2023
c48edfa
Update testing-and-deployment.yml
tkoyama010 Dec 22, 2023
68e3841
Update testing-and-deployment.yml
tkoyama010 Dec 22, 2023
c0b8ead
Update testing-and-deployment.yml
tkoyama010 Dec 22, 2023
f1b1838
Add pyproject.toml
tkoyama010 Dec 23, 2023
392f7d1
Update point operation
tkoyama010 Dec 23, 2023
ce753b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 23, 2023
44230ef
Update
tkoyama010 Dec 23, 2023
7cd9b63
Merge branch 'feat/tutorial-1' of https://github.com/pyvista/pyvista-…
tkoyama010 Dec 23, 2023
67bee58
Update
tkoyama010 Dec 23, 2023
e74649a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 23, 2023
f70f750
Update
tkoyama010 Dec 23, 2023
0c4f549
Update .pre-commit-config.yaml
tkoyama010 Dec 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/testing-and-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Unit Testing and Deployment

on:
pull_request:
workflow_dispatch:
schedule:
- cron: "0 4 * * *"
push:
tags:
- "*"
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
ALLOW_PLOTTING: true
SHELLOPTS: 'errexit:pipefail'

jobs:
Linux:
name: Linux Unit Testing
runs-on: ubuntu-latest
strategy:
fail-fast: false

# see discussion at https://github.com/pyvista/pyvista/issues/2867
matrix:
include:
- python-version: '3.11'
vtk-version: 'latest'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: Python-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.vtk-version }}-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements_test.txt') }}
restore-keys: |
Python-${{ runner.os }}-${{ matrix.python-version }}
- name: Set up vtk
if: ${{ matrix.vtk-version != 'latest' }}
run: pip install vtk==${{ matrix.vtk-version }}

- name: Install gmsh
run: |
sudo apt -y install libgl1-mesa-glx xvfb python-tk libglu1 libxcursor-dev libxft2 libxinerama1 libfltk1.3-dev libfreetype6-dev libgl1-mesa-dev libocct-foundation-dev libocct-data-exchange-dev
pip install gmsh
- name: Install Testing Requirements
run: pip install -r requirements_test.txt

- name: Unit Testing
run: |
export PYTHONPATH=. && xvfb-run pytest
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ci:
autofix_prs: true
autoupdate_schedule: weekly
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
22 changes: 22 additions & 0 deletions examples/tutorial1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pvgmsh
import pyvista
import numpy as np


# Gmsh Python tutorial 1
# https://gitlab.onelab.info/gmsh/gmsh/blob/gmsh_4_10_5/tutorials/python/t1.py

vertices = np.array([[0, 0, 0], [0.1, 0, 0], [0.1, 0.3, 0], [0, 0.3, 0]])
faces = np.hstack([[4, 0, 1, 2, 3]])
surf = pyvista.PolyData(vertices, faces)

# pvgmsh does not support PhysicalGroup; group configuration can be easily done with PyVista.

mesh = pvgmsh.generate_mesh(surf)

plotter = pyvista.Plotter(shape=(1, 2))
plotter.subplot(0, 0)
plotter.add_mesh(surf, color="tan", show_edges=True)
plotter.subplot(0, 1)
plotter.add_mesh(mesh, color="tan", show_edges=True)
plotter.show(cpos="xy")
32 changes: 32 additions & 0 deletions pvgmsh/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import gmsh
import pyvista as pv
import tempfile
from pvgmsh._version import __version__ # noqa: F401


def generate_mesh(surf, lc=1e-2, dimension=2):
meshes = []
for cell in surf.cell:
gmsh.initialize()
for i, point in enumerate(surf.points):
gmsh.model.geo.addPoint(point[0], point[1], point[2], lc, i + 1)
if cell.type == pv.CellType.QUAD:
gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(2, 3, 2)
gmsh.model.geo.addLine(3, 4, 3)
gmsh.model.geo.addLine(4, 1, 4)
gmsh.model.geo.addCurveLoop([1, 2, 3, 4], 1)
gmsh.model.geo.addPlaneSurface([1], 1)
gmsh.model.geo.synchronize()
gmsh.model.mesh.generate(dimension)
with tempfile.NamedTemporaryFile(
mode="w+", encoding="utf-8", newline="\n", suffix=".msh"
) as fp:
gmsh.write(fp.name)
mesh = pv.read(fp.name)
if surf.number_of_cells == 1:
return mesh
gmsh.clear()
gmsh.finalize()
meshes.append(mesh)
return meshes
14 changes: 14 additions & 0 deletions pvgmsh/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Version info for fe2pv.
On the ``main`` branch, use 'dev0' to denote a development version.
For example:
version_info = 0, 1, 'dev0'
---
When generating pre-release wheels, use '0rcN', for example:
version_info = 0, 2, '0rc1'
Denotes the first release candidate.
"""
# major, minor, patch
version_info = 0, 0, "dev0"

# Nice string for the version
__version__ = ".".join(map(str, version_info))
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[build-system]
requires = [
'gmsh',
'meshio',
'pyvista',
'setuptools',
]
build-backend = 'setuptools.build_meta'

[project]
name = "pyvista-gmsh"
dynamic = ['version']
dependencies = [
'gmsh',
'meshio',
'pyvista',
]

[tool.setuptools.dynamic]
version = {attr = 'pvgmsh.__version__'}
4 changes: 4 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pyvista==0.43.1
gmsh==4.10.5
pytest==7.1.2
meshio==5.3.4
7 changes: 7 additions & 0 deletions tests/test_gmsh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pvgmsh
import pyvista
import numpy as np


def test_generate_mesh():
pass