homebrew-core/Formula/petsc.rb

67 lines
2.6 KiB
Ruby

class Petsc < Formula
desc "Portable, Extensible Toolkit for Scientific Computation (real)"
homepage "https://www.mcs.anl.gov/petsc/"
url "https://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-lite-3.16.2.tar.gz"
sha256 "7ab257ae150d4837ac8d3872a1d206997962578785ec2427639ceac46d131bbc"
license "BSD-2-Clause"
livecheck do
url "https://ftp.mcs.anl.gov/pub/petsc/release-snapshots/"
regex(/href=.*?petsc-lite[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
bottle do
sha256 arm64_monterey: "ce005c68a53cf6bc5f20660f099d978f0f83f544a62ecfa7bf81ee8becf7fce9"
sha256 arm64_big_sur: "8badf45e7b98ad8ddb924fd0e33e34299584862d2171dd47834050e92c45cdc3"
sha256 monterey: "e2c76b2361ce0942c67b82fa637b9a460ebe1f02efa597f1e73430c15667f1d7"
sha256 big_sur: "ecd018fcf1607a2511b4bfaeb775a5b23401d2f458d9676bac6226d5cf179a1c"
sha256 catalina: "6deba00ca40bf661dfcc786ea23a01024c8713dd8bb80a50d1d67476554d3b0f"
end
depends_on "hdf5"
depends_on "hwloc"
depends_on "metis"
depends_on "netcdf"
depends_on "open-mpi"
depends_on "openblas"
depends_on "scalapack"
depends_on "suite-sparse"
conflicts_with "petsc-complex", because: "petsc must be installed with either real or complex support, not both"
def install
system "./configure", "--prefix=#{prefix}",
"--with-debugging=0",
"--with-scalar-type=real",
"--with-x=0",
"--CC=mpicc",
"--CXX=mpicxx",
"--F77=mpif77",
"--FC=mpif90",
"MAKEFLAGS=$MAKEFLAGS"
system "make", "all"
system "make", "install"
# Avoid references to Homebrew shims
rm_f lib/"petsc/conf/configure-hash"
if OS.mac?
inreplace lib/"petsc/conf/petscvariables", Superenv.shims_path, ""
elsif File.readlines("#{lib}/petsc/conf/petscvariables").grep(Superenv.shims_path.to_s).any?
inreplace lib/"petsc/conf/petscvariables", Superenv.shims_path, ""
end
end
test do
test_case = "#{pkgshare}/examples/src/ksp/ksp/tutorials/ex1.c"
system "mpicc", test_case, "-I#{include}", "-L#{lib}", "-lpetsc", "-o", "test"
output = shell_output("./test")
# This PETSc example prints several lines of output. The last line contains
# an error norm, expected to be small.
line = output.lines.last
assert_match(/^Norm of error .+, Iterations/, line, "Unexpected output format")
error = line.split[3].to_f
assert (error >= 0.0 && error < 1.0e-13), "Error norm too large"
end
end