Skip to content

Commit

Permalink
Mainly libsupermesh fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JDBetteridge committed Nov 2, 2024
1 parent a205aa8 commit 6f6e467
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 8 deletions.
Empty file added firedrake/scripts/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
24 changes: 23 additions & 1 deletion firedrake/supermeshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,26 @@
from pyop2.compilation import load
from pyop2.mpi import COMM_SELF
from pyop2.utils import get_petsc_dir
from pathlib import Path
from functools import cache


__all__ = ["assemble_mixed_mass_matrix", "intersection_finder"]


# JBTODO: This _really_ needs adding to the libsupermesh python package
@cache
def supermesh_location():
try:
import supermesh
supermesh_dir = Path(supermesh.__path__._path[-1]).absolute()
supermesh_so = [*supermesh_dir.glob("*.so")][0]
except ImportError:
supermesh_dir = ""
supermesh_so = ""
return supermesh_dir, supermesh_so


class BlockMatrix(object):
def __init__(self, mat, dimension):
self.mat = mat
Expand Down Expand Up @@ -431,7 +446,14 @@ def likely(cell_A):
dirs = get_petsc_dir() + (sys.prefix, )
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"]
libs += ["-Wl,-rpath,%s/lib" % d for d in dirs] + ["-lpetsc"]

supermesh_dir, supermesh_so = supermesh_location()
if supermesh_dir:
libs += [f"-L{supermesh_dir!s}", f"-l:{supermesh_so.name!s}", f"-Wl,-rpath,{supermesh_dir!s}"]
else:
libs += ["-lsupermesh"]

lib = load(
supermesh_kernel_str, "c", "supermesh_kernel",
cppargs=includes,
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "firedrake"
version = "0.14"
version = "0.14_dev"
description = "An automated system for the portable solution of partial differential equations using the finite element method"
readme = "README.rst"
license = {file = "LICENSE"}
Expand All @@ -14,6 +14,7 @@ maintainers = [
]
dependencies = [
"cachetools",
"decorator",
"mpi4py",
"h5py",
"petsc4py",
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ def get_petsc_dir():
include_dirs += petsc_include
petsc_library = [os.path.join(petsc_dirs[1], "lib")]
dirs = (sys.prefix, *petsc_dirs)
link_args = ["-L%s/lib" % d for d in dirs] + ["-Wl,-rpath,%s/lib" % d for d in dirs]
petsc_link_args = ["-L%s/lib" % d for d in dirs] + ["-Wl,-rpath,%s/lib" % d for d in dirs]

# numpy
numpy_include = [np.get_include()]
include_dirs += numpy_include

# libspatialindex
libspatialindex_so = Path(rtree.core.rt._name).absolute()
link_args += [str(libspatialindex_so)]
link_args += ["-Wl,-rpath,$ORIGIN/../Rtree.libs"]
link_args = petsc_link_args + [str(libspatialindex_so)]
link_args += ["-Wl,-rpath,$ORIGIN/../../Rtree.libs"]
include_dirs += [rtree.finder.get_include()]

# libsupermesh
supermesh_dir = Path(supermesh.__path__._path[0]).absolute()
supermesh_so = next(supermesh_dir.glob('*.so'))
link_args += [f"-L{supermesh_so!s} -l:{supermesh_so.name!s}"]
link_args += [f"-Wl,-rpath,$ORIGIN/../supermesh,--soname={supermesh_so.name!s}"]
link_args += [f"-L{supermesh_dir!s}", f"-l:{supermesh_so.name!s}"]
link_args += ["-Wl,-rpath,$ORIGIN/../../supermesh"]
include_dirs += [str(supermesh_dir.joinpath("include"))]

extensions = cythonize([Extension(
Expand All @@ -122,7 +122,7 @@ def get_petsc_dir():
language="c",
include_dirs=petsc_include + numpy_include,
libraries=["petsc"],
extra_link_args=link_args,
extra_link_args=petsc_link_args,
)]) + [
Pybind11Extension(
name="tinyasm._tinyasm",
Expand Down

0 comments on commit 6f6e467

Please sign in to comment.