Package: guix-patches;
Reported by: reza <reza <at> housseini.me>
Date: Fri, 29 Sep 2023 09:02:02 UTC
Severity: normal
Tags: patch
Done: reza <reza <at> housseini.me>
Bug is archived. No further changes may be made.
Message #41 received at 66262 <at> debbugs.gnu.org (full text, mbox):
From: reza <reza <at> housseini.me> To: 66262 <at> debbugs.gnu.org <66262 <at> debbugs.gnu.org> Cc: reza <reza <at> housseini.me> Subject: [PATCH v3 1/3] gnu: Add openfoam-package. Date: Tue, 10 Oct 2023 06:25:28 +0000
* gnu/packages/simulation.scm (openfoam-package): Add factory function to generate openfoam packages. Improve build tree clean up to fix reproducibility bug. Fix install path to follow openfoam naming convention. --- gnu/packages/simulation.scm | 285 ++++++++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) diff --git a/gnu/packages/simulation.scm b/gnu/packages/simulation.scm index b2fb123815..4b95688e33 100644 --- a/gnu/packages/simulation.scm +++ b/gnu/packages/simulation.scm @@ -88,6 +88,291 @@ (define-module (gnu packages simulation) #:use-module (ice-9 regex) #:use-module (srfi srfi-1)) +(define* (openfoam-package source version name home-page synopsis) + (let* ((install-path (string-append "share/OpenFOAM-" version))) + (package + (name name) + (version version) + (source source) + (build-system gnu-build-system) + (native-search-paths + (list (search-path-specification + (variable "WM_PROJECT_DIR") + (files `(,install-path))))) + (inputs (list boost + cgal + git + gmp + libxt + metis + mpfr + ncurses + openmpi + openssh + paraview + pt-scotch32 + readline + scotch + zlib)) + (native-inputs (list bison + flex + ;; paraview plugin dependencies + cli11 + cmake-minimal + cgns + curl + double-conversion + eigen + expat + ffmpeg + fmt + freetype + gdal + gl2ps + glew + gmsh + hdf5 + jsoncpp + libjpeg-turbo + libogg + libpng + libharu + libtheora + libtiff + libx11 + libxml2 + lz4 + netcdf + nlohmann-json + proj + protobuf + pugixml + python + python-mpi4py + qtbase-5 + qtsvg-5 + qttools-5 + qtwebengine-5 + qtxmlpatterns + utfcpp + vtk + xz)) + (propagated-inputs (list gnuplot)) + (outputs '("debug" ;~60MB + "out")) + (arguments + (list + ;; Executable files and shared libraries are located in the 'platforms' + ;; subdirectory. + #:strip-directories + #~(list (string-append "OpenFOAM-" #$version "/platforms/linux64GccDPInt32Opt/bin") + (string-append "OpenFOAM-" #$version "/platforms/linux64GccDPInt32Opt/lib")) + + #:modules + '((ice-9 ftw) + (ice-9 regex) + (ice-9 string-fun) + (srfi srfi-1) + (guix build gnu-build-system) + (guix build utils)) + + #:phases + #~(modify-phases %standard-phases + (add-before 'build 'patch-HOME-path + (lambda _ + (setenv "HOME" "/tmp") #t)) + (add-before 'build 'patch-scotch + (lambda _ + (substitute* "etc/config.sh/scotch" + (("^export SCOTCH_VERSION=scotch_.*$") + (string-append "export SCOTCH_VERSION=scotch_" + #$(package-version pt-scotch32) "\n")) + (("^export SCOTCH_ARCH_PATH=.*$") + (string-append "export SCOTCH_ARCH_PATH=" #$pt-scotch32 "\n"))) + #t)) + (add-before 'build 'patch-mpi + (lambda _ + (let* ((mpi-version #$(package-version openmpi))) + ;; specify openmpi type + (substitute* "etc/bashrc" + (("WM_MPLIB=SYSTEMOPENMPI") + "WM_MPLIB=OPENMPI")) + (substitute* "etc/config.sh/mpi" + (("export FOAM_MPI=openmpi-.*$") + (string-append "export FOAM_MPI=openmpi-" + mpi-version "\n")) + (("export MPI_ARCH_PATH=.*\\$FOAM_MPI.*$") + (string-append "export MPI_ARCH_PATH=" #$openmpi "\n")))) + #t)) + (add-before 'build 'patch-paraview + (lambda _ + (substitute* "etc/config.sh/paraview" + (("^export ParaView_VERSION=.*$") + (string-append "export ParaView_VERSION=" + #$(package-version paraview) "\n")) + (("^export ParaView_DIR=.*$") + (string-append "export ParaView_DIR=" #$paraview "\n")) + (("export ParaView_GL=mesa") "export ParaView_GL=system")) + #t)) + (add-before 'build 'add-rpaths + (lambda _ + (letrec* ((libraries '("boost" + "cgal" + "gmp" + "metis" + "mpfr" + "scotch" + "pt-scotch32" + "openmpi" + "zlib" + "paraview")) + (rpaths + (fold-right (lambda (lib rpaths) + (string-append rpaths + "-rpath=" + (assoc-ref %build-inputs lib) + "/lib,")) "" libraries)) + (openfoam-lib + (string-append #$output + "/share/OpenFOAM-" #$version + "/platforms/linux64GccDPInt32Opt/lib")) + (ldflags + (string-append "-Wl," + rpaths + "-rpath=" + openfoam-lib + "," + "-rpath=" + openfoam-lib + "/dummy," + "-rpath=" + openfoam-lib + "/paraview-" + #$(version-major+minor (package-version + paraview))))) + (substitute* "wmake/rules/linux64Gcc/c++" + (("\\$\\(LIB_HEADER_DIRS\\) -fPIC" all) + (string-append all " " ldflags)))) #t)) + (add-before 'build 'add-vtk-include-path + (lambda _ + (let* ((vtk-version #$(version-major+minor + (package-version vtk))) + (vtk-inc (string-append #$vtk "/include/vtk-" vtk-version)) + (vtk-inc-flag (string-append "-I" vtk-inc))) + (substitute* "wmake/rules/linux64Gcc/c++" + (("\\$\\(LIB_HEADER_DIRS\\)" all) + (string-append all " " vtk-inc-flag " ")))) + #t)) + (delete 'configure) ;no configure phase + (replace 'build + (lambda _ + ;; compile OpenFOAM libraries and applications + (invoke "bash" "-c" + (format #f + "source ./etc/bashrc && ./Allwmake -j~a" + (parallel-job-count))))) + (add-after 'build 'cleanup + ;; Avoid unnecessary, voluminous object and dep files. + (lambda _ + (when (file-exists? "platforms/linux64GccDPInt32Opt/src") + (delete-file-recursively + "platforms/linux64GccDPInt32Opt/src")) + (when (file-exists? + "platforms/linux64GccDPInt32OptOPENMPI") + (delete-file-recursively + "platforms/linux64GccDPInt32OptOPENMPI")) + (for-each delete-file + (find-files "." "\\.o$")) + ;; Remove spurious files in src tree + (invoke "bash" "-c" "source ./etc/bashrc && wclean all") + #t)) + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (when tests? + (when (file-exists? "test") + (with-directory-excursion "test" + (invoke "bash" "-c" + (format #f + "source ../etc/bashrc && ./Allrun -j~a" + (parallel-job-count))) + ;; cleanup + (invoke "bash" "-c" + "source ../etc/bashrc && ./Allclean"))) + ;; too many tutorials are failing + ;; (with-directory-excursion "tutorials" + ;; (invoke "bash" "-c" "source ../etc/bashrc && ./Alltest")) + ) #t)) + (add-before 'install 'set-paths + (lambda _ + (let ((install-path (string-append #$output + "/share/OpenFOAM-" #$version))) + (substitute* "etc/bashrc" + (("^\\[ \"\\$BASH\".*$") "") + (("^export FOAM_INST_DIR=\\$\\(cd.*$") + (string-append "export FOAM_INST_DIR=" install-path "\n")) + (("^export FOAM_INST_DIR=\\$HOME.*$") ""))) + #t)) + (replace 'install + (lambda* (#:key outputs inputs #:allow-other-keys) + (let ((install-path (string-append #$output + "/share/OpenFOAM-" #$version))) + (mkdir-p install-path) ;create install directory + ;; move contents of build directory to install directory + (copy-recursively "." install-path)))) + (add-after 'install 'add-symbolic-link + (lambda _ + (let* ((bin (string-append #$output "/bin")) + (lib (string-append #$output "/lib")) + (openfoam (string-append #$output + "/share/OpenFOAM-" #$version)) + (build-bin (string-append openfoam + "/platforms/linux64GccDPInt32Opt/bin")) + (build-lib (string-append openfoam + "/platforms/linux64GccDPInt32Opt/lib")) + (foam-bin (string-append openfoam "/bin"))) + ;; add symbolic links in standard 'bin' directory + (mkdir-p bin) + (for-each (lambda (file) + (unless (member file + '("." "..")) + (symlink (string-append build-bin "/" + file) + (string-append bin "/" file)))) + (scandir build-bin)) + (for-each (lambda (file) + (unless (member file + '("." "..")) + (symlink (string-append foam-bin "/" + file) + (string-append bin "/" file)))) + (scandir foam-bin)) + ;; add symbolic link for standard 'lib' directory + (symlink build-lib lib)) #t))))) + ;; Note: + ;; Tutorial files are installed read-only in /gnu/store. + ;; To allow write permissions on files copied from the store a + ;; 'chmod' step is needed before running the applications. For + ;; example, from a user's login: + ;; $ source $WM_PROJECT_DIR/etc/bashrc + ;; $ mkdir -p $FOAM_RUN + ;; $ cd $FOAM_RUN + ;; $ cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily . + ;; $ cd pitzDaily + ;; $ chmod -R u+w . + ;; $ blockMesh + (synopsis synopsis) + (description + "OpenFOAM provides a set of solvers and methods for tackling +problems in the field of Computational Fluid Dynamics (CFD). It is written in +C++. Governing equations such as the Navier-Stokes equations can be solved in +integral form. Physical processes such as phase change, droplet transport and +chemical reaction can be modelled. Numerical methods are included to deal with +sharp gradients, such as those encountered in flows with shock waves and flows +with gas/liquid interfaces. Large problems may be split into smaller, connected +problems for efficient solution on parallel systems.") + (license license:gpl3+) + (home-page home-page)))) + (define-public openfoam-org (package (name "openfoam-org") -- 2.41.0
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.