class PetscComplex < Formula desc "Portable, Extensible Toolkit for Scientific Computation (complex)" homepage "https://www.mcs.anl.gov/petsc/" url "http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-lite-3.12.2.tar.gz" sha256 "c30bf8a005e850d1db137b7807a1b780286f70e650e5eba251061133ebd27f63" bottle do sha256 "f9b4dccbeb53f1e8b506b6a7240c349cfa031125649fdbae87f7af2432fae7ed" => :catalina sha256 "a0a3ec9c0de65a1c51f8e3c902019618da706ce8467c2ac279239e4dfc000036" => :mojave sha256 "532a56cee38730e75a93b88052b5ddc08d312e21dd1b2bd8c57f914e56b557eb" => :high_sierra end depends_on "hdf5" depends_on "hwloc" depends_on "metis" depends_on "netcdf" depends_on "open-mpi" 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 ENV["CC"] = "mpicc" ENV["CXX"] = "mpicxx" ENV["F77"] = "mpif77" ENV["FC"] = "mpif90" system "./configure", "--prefix=#{prefix}", "--with-debugging=0", "--with-scalar-type=complex", "--with-x=0" system "make", "all" system "make", "install" end test do test_case = "#{share}/petsc/examples/src/ksp/ksp/examples/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