homebrew-core/Formula/petsc-complex.rb

66 lines
2.5 KiB
Ruby

class PetscComplex < Formula
desc "Portable, Extensible Toolkit for Scientific Computation (complex)"
homepage "https://www.mcs.anl.gov/petsc/"
url "https://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-lite-3.16.3.tar.gz"
sha256 "eff44c7e7f12991dc7d2b627c477807a215ce16c2ce8a1c78aa8237ddacf6ca5"
license "BSD-2-Clause"
livecheck do
formula "petsc"
end
bottle do
sha256 arm64_monterey: "9a35fda3229955fd76eece024ae46b0e3700d1e40748e21750570dd474165109"
sha256 arm64_big_sur: "2ca006232614720bfbbbe19f7d54d50926dcedcbbd8c7fb29d62afce102571e8"
sha256 monterey: "39e6bae966707379f42460826ecea25628238c9f2ad6fdd783bcd73391573960"
sha256 big_sur: "8007b5eb1cb4082b0094d82ca64b63a627da279d63ea82cec7500f585dbc65de"
sha256 catalina: "b121f72407ba40815b13f12960494920208efab169eaf7de70a24a994305fe40"
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", 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=complex",
"--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 = "#{share}/petsc/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