Skip to content

Commit

Permalink
Use a pip-installed libsupermesh
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjward committed Dec 11, 2024
1 parent 6a20368 commit a240aec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 4 additions & 2 deletions firedrake/supermeshing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Code for projections and other fun stuff involving supermeshes.
import firedrake
import ctypes
import sys
import pathlib
import libsupermesh
from firedrake.cython.supermeshimpl import assemble_mixed_mass_matrix as ammm, intersection_finder
from firedrake.mg.utils import get_level
from firedrake.petsc import PETSc
Expand Down Expand Up @@ -428,7 +429,8 @@ def likely(cell_A):
"complex_mode": 1 if complex_mode else 0
}

dirs = get_petsc_dir() + (sys.prefix, )
libsupermesh_dir = pathlib.Path(libsupermesh.__path__._path[0]).absolute()
dirs = get_petsc_dir() + (libsupermesh_dir,)
includes = ["-I%s/include" % d for d in dirs]
libs = ["-L%s/lib" % d for d in dirs]
libs = libs + ["-Wl,-rpath,%s/lib" % d for d in dirs] + ["-lpetsc", "-lsupermesh"]
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies = [
"fenics-fiat @ git+https://github.com/firedrakeproject/fiat.git",
"pyadjoint-ad @ git+https://github.com/dolfin-adjoint/pyadjoint.git",
"loopy @ git+https://github.com/firedrakeproject/loopy.git@main",
"libsupermesh @ git+https://github.com/firedrakeproject/libsupermesh.git@connorjward/pip-install2",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down Expand Up @@ -98,6 +99,7 @@ requires = [
"mpi4py; python_version < '3.13'",
"petsc4py",
"rtree>=1.2",
"libsupermesh @ git+https://github.com/firedrakeproject/libsupermesh.git@connorjward/pip-install2",
]
build-backend = "setuptools.build_meta"

Expand Down
21 changes: 13 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pybind11
import petsc4py
import rtree
import libsupermesh
import pkgconfig
from dataclasses import dataclass, field
from setuptools import setup, find_packages, Extension
Expand Down Expand Up @@ -145,6 +146,9 @@ def __getitem__(self, key):
# In the next 2 linkages we are using `site.getsitepackages()[0]`, which isn't
# guaranteed to be the correct place we could also use "$ORIGIN/../../lib_dir",
# but that definitely doesn't work with editable installs.
# This is necessary because Python build isolation means that the compile-time
# library dirs (in the isolated build env) are different to the run-time
# library dirs (in the venv).

# libspatialindex
# example:
Expand All @@ -159,15 +163,16 @@ def __getitem__(self, key):

# libsupermesh
# example:
# gcc -I/supermesh/include
# gcc /supermesh/supermesh.cpython-311-x86_64-linux-gnu.so \
# gcc -Ipath/to/libsupermesh/include
# gcc path/to/libsupermesh/libsupermesh.cpython-311-x86_64-linux-gnu.so \
# -lsupermesh \
# -Wl,-rpath,$ORIGIN/../../supermesh
supermesh_ = ExternalDependency(
include_dirs=[f"{sys.prefix}/include"],
library_dirs=[f"{sys.prefix}/lib"],
# -Wl,-rpath,$ORIGIN/../../libsupermesh
libsupermesh_dir = Path(libsupermesh.__path__._path[0]).absolute()
libsupermesh_ = ExternalDependency(
include_dirs=[str(libsupermesh_dir.joinpath("include"))],
library_dirs=[str(libsupermesh_dir.joinpath("lib"))],
runtime_library_dirs=[os.path.join(site.getsitepackages()[0], "libsupermesh", "lib")],
libraries=["supermesh"],
runtime_library_dirs=[f"{sys.prefix}/lib"],
)

# The following extensions need to be linked accordingly:
Expand Down Expand Up @@ -221,7 +226,7 @@ def extensions():
name="firedrake.cython.supermeshimpl",
language="c",
sources=[os.path.join("firedrake", "cython", "supermeshimpl.pyx")],
**(petsc_ + numpy_ + supermesh_)
**(petsc_ + numpy_ + libsupermesh_)
))
# pyop2/sparsity.pyx: petsc, numpy,
cython_list.append(Extension(
Expand Down

0 comments on commit a240aec

Please sign in to comment.