Skip to content

Commit

Permalink
Merge branch 'main' into uzerbinati/paper
Browse files Browse the repository at this point in the history
  • Loading branch information
Umberto Zerbinati committed Mar 1, 2024
2 parents 0039bdb + e0f9628 commit df50ad6
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 71 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/Docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
schedule:
- cron: '30 10 7,14,21,28 * *'

workflow_dispatch:

push:
paths:
- Dockerfile
Expand All @@ -14,8 +16,9 @@ jobs:
timeout-minutes: 360
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Login to Docker Hub
if: github.repository == 'NGSolve/ngsPETSc'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
Expand All @@ -24,6 +27,7 @@ jobs:
run: |
docker build -t ngspetsc:latest .
- name: Push Docker image
if: github.repository == 'NGSolve/ngsPETSc'
run: |
docker tag ngspetsc:latest urzerbinati/ngspetsc:latest
docker push urzerbinati/ngspetsc:latest
24 changes: 12 additions & 12 deletions .github/workflows/ngsPETSc.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# .github/workflows/app.yaml
name: ngsPETSc tests
on:
on:
push:
branches-ignore:
branches-ignore:
- 'no-ci/*'

schedule:
Expand All @@ -16,7 +16,7 @@ jobs:

steps:
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install ngsPETSc
run: |
Expand Down Expand Up @@ -51,20 +51,20 @@ jobs:
fenicsx:
runs-on: ubuntu-latest
container: dolfinx/dolfinx:latest
timeout-minutes: 30
container: dolfinx/dolfinx:nightly
timeout-minutes: 50

steps:
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install Netgen and ngsPETSc
run: |
pip3 install netgen-mesher \
&& pip3 install pylint \
&& export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.10/site-packages \
&& echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV \
&& NGSPETSC_NO_INSTALL_REQUIRED=ON pip install .
pip install netgen-mesher
pip install pylint
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.10/site-packages
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV
NGSPETSC_NO_INSTALL_REQUIRED=ON pip install .
- name: Check formatting
run: |
Expand All @@ -73,4 +73,4 @@ jobs:
- name: Run test suite in serial
run: |
pytest -v tests/test_fenicsx.py
pytest -v tests/test_fenicsx.py
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
MPI_EXEC = ${PETSC_DIR}/${PETSC_ARCH}/bin/mpiexec
lint:
pylint --disable=C0412,C0103,C0415,C0321,E0401,E1101,E0611,R1736,R0401,R0801,R0902,R1702,R0913,R0914,R0903,R0205,R0912,R0915,I1101,W0201,C0209 --variable-naming-style=camelCase --class-naming-style=PascalCase --argument-naming-style=camelCase --attr-naming-style=camelCase ngsPETSc
pylint --disable=C0412,C0103,C0415,C0321,C3001,E0401,E1101,E0611,R1736,R0401,R0801,R0902,R1702,R0913,R0914,R0903,R0205,R0912,R0915,I1101,W0201,W0406,W0212,C0209 --variable-naming-style=camelCase --class-naming-style=PascalCase --argument-naming-style=camelCase --attr-naming-style=camelCase ngsPETSc/utils
pylint --disable=C0412,C0103,C0415,C0321,E0401,E1101,E0611,R1728,R1736,R0401,R0801,R0902,R1702,R0913,R0914,R0903,R0205,R0912,R0915,I1101,W0201,C0209 --variable-naming-style=camelCase --class-naming-style=PascalCase --argument-naming-style=camelCase --attr-naming-style=camelCase ngsPETSc
pylint --disable=C0412,C0103,C0415,C0321,C3001,E0401,E1101,E0611,R1728,R1736,R0401,R0801,R0902,R1702,R0913,R0914,R0903,R0205,R0912,R0915,I1101,W0201,W0406,W0212,C0209 --variable-naming-style=camelCase --class-naming-style=PascalCase --argument-naming-style=camelCase --attr-naming-style=camelCase ngsPETSc/utils
lint_test:
pylint --disable=C0412,C0103,C0415,C0321,E0401,E1101,E0611,R1736,R0401,R0914,R0801,R0902,R1702,R0913,R0903,R0205,R0912,R0915,I1101,W0201,C0209 --variable-naming-style=camelCase --class-naming-style=PascalCase --argument-naming-style=camelCase --attr-naming-style=camelCase tests
pylint --disable=C0412,C0103,C0415,C0321,E0401,E1101,E0611,R1728,R1736,R0401,R0914,R0801,R0902,R1702,R0913,R0903,R0205,R0912,R0915,I1101,W0201,C0209 --variable-naming-style=camelCase --class-naming-style=PascalCase --argument-naming-style=camelCase --attr-naming-style=camelCase tests
test:
pytest tests/test_env.py
pytest tests/test_vec.py
Expand Down
1 change: 1 addition & 0 deletions docs/src/Tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ How to use ngsPETSc
notebooks/Meshes
notebooks/Krylov Solver and Preconditioners
notebooks/Eigenvalue Problems
Firedrake-Netgen interface via ngsPETSc <https://www.firedrakeproject.org/demos/netgen_mesh.py.html>
15 changes: 9 additions & 6 deletions ngsPETSc/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class MeshMapping:
'''

def __init__(self, mesh=None, name="Default"):
def __init__(self, mesh=None, comm=MPI.COMM_WORLD, name="Default"):
self.name = name
self.comm = comm
if isinstance(mesh,(ngs.comp.Mesh,ngm.Mesh)):
self.createPETScDMPlex(mesh)
elif isinstance(mesh,PETSc.DMPlex):
Expand Down Expand Up @@ -157,7 +158,7 @@ def createPETScDMPlex(self, mesh):
self.ngMesh = mesh.ngmesh
else:
self.ngMesh = mesh
comm = MPI.COMM_WORLD
comm = self.comm
if self.ngMesh.dim == 3:
if comm.rank == 0:
V = self.ngMesh.Coordinates()
Expand All @@ -168,7 +169,7 @@ def createPETScDMPlex(self, mesh):
surfMesh, dim = True, 2
T = self.ngMesh.Elements2D().NumPy()["nodes"]
T = np.array([list(np.trim_zeros(a, 'b')) for a in list(T)])-1
plex = PETSc.DMPlex().createFromCellList(dim, T, V)
plex = PETSc.DMPlex().createFromCellList(dim, T, V, comm=comm)
plex.setName(self.name)
vStart, _ = plex.getDepthStratum(0)
if surfMesh:
Expand All @@ -186,14 +187,15 @@ def createPETScDMPlex(self, mesh):
else:
plex = PETSc.DMPlex().createFromCellList(3,
np.zeros((0, 4), dtype=np.int32),
np.zeros((0, 3), dtype=np.double))
np.zeros((0, 3), dtype=np.double),
comm=comm)
self.petscPlex = plex
elif self.ngMesh.dim == 2:
if comm.rank == 0:
V = self.ngMesh.Coordinates()
T = self.ngMesh.Elements2D().NumPy()["nodes"]
T = np.array([list(np.trim_zeros(a, 'b')) for a in list(T)])-1
plex = PETSc.DMPlex().createFromCellList(2, T, V)
plex = PETSc.DMPlex().createFromCellList(2, T, V, comm=comm)
plex.setName(self.name)
vStart, _ = plex.getDepthStratum(0) # vertices
for e in self.ngMesh.Elements1D():
Expand All @@ -208,5 +210,6 @@ def createPETScDMPlex(self, mesh):
else:
plex = PETSc.DMPlex().createFromCellList(2,
np.zeros((0, 3), dtype=np.int32),
np.zeros((0, 2), dtype=np.double))
np.zeros((0, 2), dtype=np.double),
comm=comm)
self.petscPlex = plex
7 changes: 4 additions & 3 deletions ngsPETSc/utils/fenicsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def model_to_mesh(self, hmax: float, gdim: int = 2,
dolfinx.cpp.mesh.MeshTags_int32,dolfinx.cpp.mesh.MeshTags_int32]:
"""Given a NetGen model, take all physical entities of the highest
topological dimension and create the corresponding DOLFINx mesh.
This function only works in serial, at the moment.
Args:
Expand Down Expand Up @@ -73,9 +73,10 @@ def model_to_mesh(self, hmax: float, gdim: int = 2,
V = ngmesh.Coordinates()
T = ngmesh.Elements3D().NumPy()["nodes"]
T = np.array([list(np.trim_zeros(a, 'b')) for a in list(T)])-1
ufl_domain = dolfinx.io.gmshio.ufl_mesh(_ngs_to_cells[(gdim,T.shape[1])],gdim)
ufl_domain = dolfinx.io.gmshio.ufl_mesh(
_ngs_to_cells[(gdim,T.shape[1])], gdim, dolfinx.default_real_type)
cell_perm = dolfinx.cpp.io.perm_gmsh(dolfinx.cpp.mesh.to_type(str(ufl_domain.ufl_cell())),
T.shape[1])
T = T[:, cell_perm]
T = np.ascontiguousarray(T[:, cell_perm])
mesh = dolfinx.mesh.create_mesh(self.comm, T, V, ufl_domain, partitioner)
return mesh
Loading

0 comments on commit df50ad6

Please sign in to comment.