Skip to content

Commit

Permalink
Fix ENV
Browse files Browse the repository at this point in the history
Signed-off-by: Umberto Zerbinati <zerbinati@maths.ox.ac.uk>
  • Loading branch information
Umberto Zerbinati committed Oct 28, 2023
1 parent e2273d8 commit 4cffdd7
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 38 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/FEniCSx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# .github/workflows/app.yaml
name: ngsPETSc FEniCSx tests
on:
push:
branches-ignore:
- 'no-ci/*'

schedule:
- cron: '30 10 7,14,21,28 * *'

jobs:
ngsolve_tests:
runs-on: ubuntu-latest
container: dolfinx/dolfinx:latest
timeout-minutes: 20

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

- name: Install Netgen and ngsPETSc
run: |
pip3 install netgen-mesher \
&& pip3 install pylint \
&& export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.10/site-packages \
&& NGSPETSC_NO_INSTALL_REQUIRED=ON pip install .
- name: Check formatting
run: |
make lint
make lint_test
- name: Run test suite in serial
run: |
pytest -v tests/test_fenicsx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# .github/workflows/app.yaml
name: ngsPETSc
name: ngsPETSc NGsolve tests
on:
push:
branches-ignore:
Expand Down
8 changes: 5 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,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,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,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
lint_test:
pylint --disable=C0412,C0103,C0415,C0321,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,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 All @@ -13,6 +13,7 @@ test:
pytest tests/test_pc.py
pytest tests/test_eps.py
pytest tests/test_snes.py
pytest tests/test_fenicsx.py
test_mpi:
$(MPI_EXEC) --allow-run-as-root -n 2 pytest --with-mpi tests/test_env.py
$(MPI_EXEC) --allow-run-as-root -n 2 pytest --with-mpi tests/test_vec.py
Expand All @@ -22,6 +23,7 @@ test_mpi:
$(MPI_EXEC) --allow-run-as-root -n 2 pytest --with-mpi tests/test_pc.py
$(MPI_EXEC) --allow-run-as-root -n 2 pytest --with-mpi tests/test_eps.py
$(MPI_EXEC) --allow-run-as-root -n 2 pytest --with-mpi tests/test_snes.py
$(MPI_EXEC) --allow-run-as-root -n 2 pytest --with-mpi tests/test_fenicsx.py
doc:
rm docs/src/notebooks/*.rst
jupyter nbconvert --to rst docs/src/notebooks/*.ipynb
Expand Down
26 changes: 23 additions & 3 deletions ngsPETSc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,34 @@
ngsPETSc is a NGSolve/Netgen interface to PETSc
'''
import warnings

from ngsPETSc.plex import *
from ngsPETSc.utils.firedrake import *
from ngsPETSc.utils.fenicsx import *

#Firedrake
try:
import firedrake
except ImportError:
firedrake = None

if firedrake:
from ngsPETSc.utils.firedrake import *

#FEniCSx
try:
import dolfinx
except ImportError:
dolfinx = None

if dolfinx:
from ngsPETSc.utils.fenicsx import *

#Netgen
try:
import ngsolve
except ImportError:
warnings.warn("No NGSolve installed, only working with Netgen.")
ngsolve = None

if ngsolve:
from ngsPETSc.mat import *
from ngsPETSc.vec import *
Expand All @@ -18,6 +38,6 @@
from ngsPETSc.eps import *
from ngsPETSc.snes import *

VERSION = "0.0.3"
VERSION = "0.0.4"

__all__ = ["Matrix","VectorMapping","MeshMapping","KrylovSolver","EigenSolver","FiredrakeMesh"]
40 changes: 15 additions & 25 deletions ngsPETSc/utils/fenicsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@
We adopt the same docstring conventiona as the FEniCSx project, since this part of
the package will only be used in combination with FEniCSx.
'''
try:
import dolfinx
import basix
import ufl
except ImportError:
dolfinx = None
basix = None
ufl = None

import typing
import typing
import dolfinx
import numpy as np

import netgen as ng
import netgen.meshing as ngm

from mpi4py import MPI as _MPI

from ngsPETSc import MeshMapping
Expand All @@ -33,15 +22,16 @@ class GeometricModel:
comm: The MPI communicator to use for mesh creation
"""
def __init__(self,geo, comm: _MPI.Comm):
self.geo = geo
self.comm = comm
self.geo = geo
self.comm = comm

def model_to_mesh(self, hmax: float, gdim: int = 2,
partitioner: typing.Callable[
[_MPI.Comm, int, int, dolfinx.cpp.graph.AdjacencyList_int32], dolfinx.cpp.graph.AdjacencyList_int32] =
dolfinx.mesh.create_cell_partitioner(dolfinx.mesh.GhostMode.none), transform: typing.Any = None,
routine: typing.Any = None) -> typing.Tuple[dolfinx.mesh.Mesh, dolfinx.cpp.mesh.MeshTags_int32,
dolfinx.cpp.mesh.MeshTags_int32]:
partitioner: typing.Callable[
[_MPI.Comm, int, int, dolfinx.cpp.graph.AdjacencyList_int32],
dolfinx.cpp.graph.AdjacencyList_int32] =
dolfinx.mesh.create_cell_partitioner(dolfinx.mesh.GhostMode.none),
transform: typing.Any = None, routine: typing.Any = None) -> typing.Tuple[dolfinx.mesh.Mesh,
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.
Expand All @@ -65,10 +55,10 @@ def model_to_mesh(self, hmax: float, gdim: int = 2,
ngmesh = self.geo.GenerateMesh(maxh=hmax)
# Apply any ngs routine post meshing
if routine is not None:
ngmesh, geo = routine(ngmesh, geo)
ngmesh, self.geo = routine(ngmesh, self.geo)
# Applying any PETSc Transform
if transform is not None:
meshMap = MeshMapping(ngmesh)
meshMap = MeshMapping(ngmesh)
transform.setDM(meshMap.plex)
transform.setUp()
newplex = transform.apply(meshMap.plex)
Expand All @@ -84,8 +74,8 @@ def model_to_mesh(self, hmax: float, gdim: int = 2,
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)
cell_perm = dolfinx.cpp.io.perm_gmsh(dolfinx.cpp.mesh.to_type(str(ufl_domain.ufl_cell())), T.shape[1])
cell_perm = dolfinx.cpp.io.perm_gmsh(dolfinx.cpp.mesh.to_type(str(ufl_domain.ufl_cell())),
T.shape[1])
T = T[:, cell_perm]
mesh = dolfinx.mesh.create_mesh(self.comm, T, V, ufl_domain, partitioner)
return mesh

2 changes: 1 addition & 1 deletion tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def test_ngsPETSc():
'''
Testing that ngsPETSc can be imported correctly
'''
assert ngsPETSc.VERSION == "0.0.3"
assert ngsPETSc.VERSION == "0.0.4"
16 changes: 11 additions & 5 deletions tests/test_fenicsx.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
'''
This module test the utils.fenicsx class
'''
import pytest

def test_square_netgen():
'''
Testing FEniCSx interface with Netgen generating a square mesh
'''
from mpi4py import MPI
import ngsPETSc.utils.fenicsx as fx
from dolfinx.io import XDMFFile
try:
from mpi4py import MPI
import ngsPETSc.utils.fenicsx as fx
from dolfinx.io import XDMFFile
pass
except ImportError:
pytest.skip(msg="DOLFINx unavailable, skipping FENICSx test")
import numpy as np

from netgen.geom2d import SplineGeometry
geo = SplineGeometry()
Expand All @@ -18,4 +24,4 @@ def test_square_netgen():
xdmf.write_mesh(domain)

if __name__ == "__main__":
test_square_netgen()
test_square_netgen()

0 comments on commit 4cffdd7

Please sign in to comment.