simulation.scm 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017, 2018, 2019, 2020, 2021 Paul Garlick <pgarlick@tourbillion-technology.com>
  3. ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  4. ;;; Copyright © 2022 Eric Bavier <bavier@posteo.net>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (gnu packages simulation)
  21. #:use-module (gnu packages)
  22. #:use-module (gnu packages algebra)
  23. #:use-module (gnu packages admin)
  24. #:use-module (gnu packages base)
  25. #:use-module (gnu packages bash)
  26. #:use-module (gnu packages bison)
  27. #:use-module (gnu packages boost)
  28. #:use-module (gnu packages check)
  29. #:use-module (gnu packages cmake)
  30. #:use-module (gnu packages compression)
  31. #:use-module (gnu packages flex)
  32. #:use-module (gnu packages gettext)
  33. #:use-module (gnu packages gcc)
  34. #:use-module (gnu packages gl)
  35. #:use-module (gnu packages graphics)
  36. #:use-module (gnu packages gtk)
  37. #:use-module (gnu packages linux)
  38. #:use-module (gnu packages m4)
  39. #:use-module (gnu packages maths)
  40. #:use-module (gnu packages mpi)
  41. #:use-module (gnu packages multiprecision)
  42. #:use-module (gnu packages ncurses)
  43. #:use-module (gnu packages pkg-config)
  44. #:use-module (gnu packages python)
  45. #:use-module (gnu packages python-build)
  46. #:use-module (gnu packages python-science)
  47. #:use-module (gnu packages python-xyz)
  48. #:use-module (gnu packages readline)
  49. #:use-module (gnu packages tls)
  50. #:use-module (gnu packages version-control)
  51. #:use-module (gnu packages xml)
  52. #:use-module (gnu packages xorg)
  53. #:use-module (guix download)
  54. #:use-module (guix git-download)
  55. #:use-module (guix svn-download)
  56. #:use-module (guix build-system cmake)
  57. #:use-module (guix build-system gnu)
  58. #:use-module (guix build-system python)
  59. #:use-module ((guix licenses) #:prefix license:)
  60. #:use-module (guix packages)
  61. #:use-module (guix utils)
  62. #:use-module (ice-9 ftw)
  63. #:use-module (ice-9 regex)
  64. #:use-module (srfi srfi-1))
  65. (define-public openfoam
  66. (package
  67. (name "openfoam")
  68. (version "4.1")
  69. (source
  70. (origin
  71. (method url-fetch)
  72. (uri (string-append
  73. "http://dl.openfoam.org/source/"
  74. (string-map (lambda (x) (if (eq? x #\.) #\- x)) version)))
  75. (file-name (string-append name "-" version ".tar.gz"))
  76. (sha256
  77. (base32 "0cgxh4h2hf50qbvvdg5miwc2nympb0nrv3md96vb3gbs9vk8vq9d"))
  78. (patches (search-patches "openfoam-4.1-cleanup.patch"))
  79. (modules '((guix build utils)))
  80. (snippet
  81. '(begin
  82. ;; Include <sys/sysmacros.h>, which is where glibc >= 2.28 provides
  83. ;; 'major' and 'minor'.
  84. (substitute* "src/OSspecific/POSIX/fileStat.C"
  85. (("#include <unistd\\.h>")
  86. "#include <unistd.h>\n#include <sys/sysmacros.h>\n"))
  87. #t))))
  88. (build-system gnu-build-system)
  89. (inputs
  90. `(("boost" ,boost)
  91. ("cgal" ,cgal)
  92. ("flex" ,flex)
  93. ("git" ,git)
  94. ("gmp" ,gmp)
  95. ("libxt" ,libxt)
  96. ("metis" ,metis)
  97. ("mpfr" ,mpfr)
  98. ("ncurses" ,ncurses)
  99. ("readline" ,readline)
  100. ("scotch" ,pt-scotch32)
  101. ("zlib" ,zlib)))
  102. (native-inputs
  103. (list bison))
  104. (propagated-inputs
  105. (list gzip gnuplot openmpi))
  106. (outputs '("debug" ;~60MB
  107. "out"))
  108. (arguments
  109. `( ;; Executable files and shared libraries are located in the 'platforms'
  110. ;; subdirectory.
  111. #:strip-directories (list (string-append
  112. "lib/OpenFOAM-" ,version
  113. "/platforms/linux64GccDPInt32Opt/bin")
  114. (string-append
  115. "lib/OpenFOAM-" ,version
  116. "/platforms/linux64GccDPInt32Opt/lib"))
  117. #:tests? #f ; no tests to run
  118. #:modules ((ice-9 ftw)
  119. (ice-9 regex)
  120. (guix build gnu-build-system)
  121. (guix build utils))
  122. #:phases (modify-phases %standard-phases
  123. (add-after 'unpack 'rename-build-directory
  124. (lambda _
  125. (chdir "..")
  126. ;; Use 'OpenFOAM-version' convention to match the file
  127. ;; name expectations in the build phase.
  128. (let ((unpack-dir (string-append
  129. (getcwd) "/"
  130. (list-ref (scandir (getcwd) (lambda (name)
  131. (string-match "^OpenFOAM" name))) 0)))
  132. (build-dir (string-append
  133. (getcwd) "/OpenFOAM-" ,version)))
  134. (rename-file unpack-dir build-dir) ; rename build directory
  135. (chdir (basename build-dir))) ; move to build directory
  136. #t))
  137. (delete 'configure) ; no configure phase
  138. (replace 'build
  139. (lambda _
  140. (let ((libraries '("boost" "cgal" "gmp" "metis" "mpfr" "scotch")))
  141. ;; set variables to define store paths
  142. (for-each (lambda (library)
  143. (setenv (string-append
  144. (string-upcase library) "_ROOT")
  145. (assoc-ref %build-inputs library))) libraries))
  146. ;; set variables to define package versions
  147. (setenv "SCOTCHVERSION" ,(package-version scotch))
  148. (setenv "METISVERSION" ,(package-version metis))
  149. ;; set variable to pass extra 'rpath' arguments to linker
  150. (setenv "LDFLAGS"
  151. (string-append
  152. "-Wl,"
  153. "-rpath=" %output "/lib/OpenFOAM-" ,version
  154. "/platforms/linux64GccDPInt32Opt/lib,"
  155. "-rpath=" %output "/lib/OpenFOAM-" ,version
  156. "/platforms/linux64GccDPInt32Opt/lib/dummy"))
  157. ;; compile OpenFOAM libraries and applications
  158. (zero? (system (format #f
  159. "source ./etc/bashrc && ./Allwmake -j~a"
  160. (parallel-job-count))))))
  161. (add-after 'build 'update-configuration-files
  162. (lambda _
  163. ;; record store paths and package versions in
  164. ;; configuration files
  165. (substitute* "etc/config.sh/CGAL"
  166. (("$BOOST_ROOT") (getenv "BOOST_ROOT")))
  167. (substitute* "etc/config.sh/CGAL"
  168. (("$CGAL_ROOT") (getenv "CGAL_ROOT")))
  169. (substitute* "etc/config.sh/metis"
  170. (("$METIS_ROOT") (getenv "METIS_ROOT")))
  171. (substitute* "etc/config.sh/metis"
  172. (("$METISVERSION") (getenv "METISVERSION")))
  173. (substitute* "etc/config.sh/scotch"
  174. (("$SCOTCH_ROOT") (getenv "SCOTCH_ROOT")))
  175. (substitute* "etc/config.sh/scotch"
  176. (("$SCOTCHVERSION") (getenv "SCOTCHVERSION")))
  177. (substitute* "etc/config.sh/settings"
  178. (("$GMP_ROOT") (getenv "GMP_ROOT")))
  179. (substitute* "etc/config.sh/settings"
  180. (("$MPFR_ROOT") (getenv "MPFR_ROOT")))
  181. ;; reset lockDir variable to refer to write-enabled
  182. ;; directory
  183. (substitute* "wmake/wmake"
  184. ((" lockDir=.*$")
  185. " lockDir=$HOME/.$WM_PROJECT/.wmake\n"))
  186. (substitute* "wmake/wmakeScheduler"
  187. (("lockDir=.*$")
  188. "lockDir=$HOME/.$WM_PROJECT/.wmake\n"))
  189. (substitute* "wmake/wmakeSchedulerUptime"
  190. (("lockDir=.*$")
  191. "lockDir=$HOME/.$WM_PROJECT/.wmake\n"))
  192. #t))
  193. (add-after 'build 'cleanup
  194. ;; Avoid unncessary, voluminous object and dep files.
  195. (lambda _
  196. (delete-file-recursively
  197. "platforms/linux64GccDPInt32Opt/src")
  198. (delete-file-recursively
  199. "platforms/linux64GccDPInt32OptSYSTEMOPENMPI")
  200. (for-each delete-file (find-files "." "\\.o$"))
  201. #t))
  202. (replace 'install
  203. (lambda _
  204. ;; use 'OpenFOAM-version' convention
  205. (let ((install-dir (string-append
  206. %output "/lib/OpenFOAM-" ,version)))
  207. (mkdir-p install-dir) ; create install directory
  208. ;; move contents of build directory to install directory
  209. (copy-recursively "." install-dir))))
  210. (add-after 'install 'add-symbolic-link
  211. (lambda _
  212. ;; add symbolic link for standard 'bin' directory
  213. (symlink
  214. (string-append "./lib/OpenFOAM-" ,version
  215. "/platforms/linux64GccDPInt32Opt/bin")
  216. (string-append %output "/bin"))
  217. #t)))))
  218. ;; Note:
  219. ;; Tutorial files are installed read-only in /gnu/store.
  220. ;; To allow write permissions on files copied from the store a
  221. ;; 'chmod' step is needed before running the applications. For
  222. ;; example, from a user's login:
  223. ;; $ source $GUIX_PROFILE/lib/OpenFOAM-4.1/etc/bashrc
  224. ;; $ mkdir -p $FOAM_RUN
  225. ;; $ cd $FOAM_RUN
  226. ;; $ cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily .
  227. ;; $ cd pitzDaily
  228. ;; $ chmod -R u+w .
  229. ;; $ blockMesh
  230. (synopsis "Framework for numerical simulation of fluid flow")
  231. (description "OpenFOAM provides a set of solvers and methods for tackling
  232. problems in the field of Computational Fluid Dynamics (CFD). It is written in
  233. C++. Governing equations such as the Navier-Stokes equations can be solved in
  234. integral form. Physical processes such as phase change, droplet transport and
  235. chemical reaction can be modelled. Numerical methods are included to deal with
  236. sharp gradients, such as those encountered in flows with shock waves and flows
  237. with gas/liquid interfaces. Large problems may be split into smaller, connected
  238. problems for efficient solution on parallel systems.")
  239. (license license:gpl3+)
  240. (home-page "https://openfoam.org")))
  241. (define-public python-fenics-dijitso
  242. (package
  243. (name "python-fenics-dijitso")
  244. (version "2019.1.0")
  245. (source
  246. (origin
  247. (method url-fetch)
  248. (uri (pypi-uri "fenics-dijitso" version))
  249. (sha256
  250. (base32
  251. "0lhqsq8ypdak0ahr2jnyvg07yrqp6wicjxi6k56zx24wp3qg60sc"))))
  252. (build-system python-build-system)
  253. (inputs
  254. (list openmpi python-numpy))
  255. (native-inputs
  256. (list python-pytest-cov))
  257. (propagated-inputs
  258. (list python-mpi4py))
  259. (arguments
  260. `(#:phases
  261. (modify-phases %standard-phases
  262. (add-after 'build 'mpi-setup
  263. ,%openmpi-setup)
  264. (replace 'check
  265. (lambda _
  266. (setenv "HOME" "/tmp")
  267. (with-directory-excursion "test"
  268. ;; Disable parallel tests to avoid race condition. See
  269. ;; https://github.com/pytest-dev/pytest-cov/issues/237.
  270. (substitute* "runtests.sh"
  271. (("for p in 1 4 8 16; do")
  272. "for p in 1; do"))
  273. (invoke "./runtests.sh")))))))
  274. (home-page "https://bitbucket.org/fenics-project/dijitso/")
  275. (synopsis "Distributed just-in-time building of shared libraries")
  276. (description
  277. "Dijitso provides a core component of the @code{FEniCS} framework,
  278. namely the just-in-time compilation of C++ code that is generated from
  279. Python modules. It is called from within a C++ library, using ctypes
  280. to import the dynamic shared library directly.
  281. As long as the compiled code can provide a simple factory function to
  282. a class implementing a predefined C++ interface, there is no limit to
  283. the complexity of that interface. Parallel support depends on the
  284. @code{mpi4py} interface.")
  285. (license license:lgpl3+)))
  286. (define-public python-fenics-ufl
  287. (package
  288. (name "python-fenics-ufl")
  289. (version "2019.1.0")
  290. (source
  291. (origin
  292. (method url-fetch)
  293. (uri (pypi-uri "fenics-ufl" version))
  294. (sha256
  295. (base32
  296. "10dz8x3lm68x2w3kkqcjask38h0zkhhak26jdbkppr8g9y8wny7p"))))
  297. (build-system python-build-system)
  298. (inputs
  299. (list python-numpy))
  300. (native-inputs
  301. (list python-pytest))
  302. (arguments
  303. '(#:phases
  304. (modify-phases %standard-phases
  305. (replace 'check
  306. (lambda _
  307. (invoke "py.test" "test"))))))
  308. (home-page "https://bitbucket.org/fenics-project/ufl/")
  309. (synopsis "Unified language for form-compilers")
  310. (description "The Unified Form Language (UFL) is a domain specific
  311. language for declaration of finite element discretizations of
  312. variational forms. More precisely, it defines a flexible interface
  313. for choosing finite element spaces and defining expressions for weak
  314. forms in a notation close to mathematical notation.
  315. UFL is part of the FEniCS Project.")
  316. (license license:lgpl3+)))
  317. (define-public python-fenics-fiat
  318. (package
  319. (name "python-fenics-fiat")
  320. (version "2019.1.0")
  321. (source
  322. (origin
  323. (method url-fetch)
  324. (uri (pypi-uri "fenics-fiat" version))
  325. (sha256
  326. (base32
  327. "13sc7lma3d2mh43an7i4kkdbbk4cmvxjk45wi43xnjd7qc38zg4b"))))
  328. (build-system python-build-system)
  329. (native-inputs
  330. (list python-pytest))
  331. (propagated-inputs
  332. (list python-numpy python-sympy))
  333. (arguments
  334. '(#:phases
  335. (modify-phases %standard-phases
  336. (replace 'check
  337. (lambda _
  338. (with-directory-excursion "test"
  339. ;; FIXME: three FIAT test modules are known to fail
  340. ;; with recent versions of pytest (>= 4). These are
  341. ;; skipped for FIAT version 2019.1.0 pending an
  342. ;; upstream pull request. For details see request #59
  343. ;; at https://bitbucket.org/fenics-project/fiat/.
  344. (invoke "py.test" "unit/"
  345. "--ignore=unit/test_fiat.py"
  346. "--ignore=unit/test_quadrature.py"
  347. "--ignore=unit/test_reference_element.py")))))))
  348. (home-page "https://bitbucket.org/fenics-project/fiat/")
  349. (synopsis "Tabulation of finite element function spaces")
  350. (description
  351. "The FInite element Automatic Tabulator (FIAT) supports
  352. generation of arbitrary order instances of the Lagrange elements on
  353. lines, triangles, and tetrahedra. It is also capable of generating
  354. arbitrary order instances of Jacobi-type quadrature rules on the same
  355. element shapes. Further, H(div) and H(curl) conforming finite element
  356. spaces such as the families of Raviart-Thomas, Brezzi-Douglas-Marini
  357. and Nedelec are supported on triangles and tetrahedra. Upcoming
  358. versions will also support Hermite and nonconforming elements.
  359. FIAT is part of the FEniCS Project.")
  360. (license license:lgpl3+)))
  361. (define-public python-fenics-ffc
  362. (package
  363. (name "python-fenics-ffc")
  364. (version "2019.1.0.post0")
  365. (source
  366. (origin
  367. (method url-fetch)
  368. (uri (pypi-uri "fenics-ffc" version))
  369. (sha256
  370. (base32
  371. "1f2a44ha65fg3a1prrbrsz4dgvibsv0j5c3pi2m52zi93bhwwgg9"))))
  372. (build-system python-build-system)
  373. (native-inputs
  374. (list python-pytest))
  375. (propagated-inputs
  376. (list python-fenics-dijitso python-fenics-fiat python-fenics-ufl))
  377. (arguments
  378. '(#:phases
  379. (modify-phases %standard-phases
  380. (replace 'check
  381. (lambda _
  382. (setenv "HOME" (getcwd))
  383. (with-directory-excursion "test"
  384. ;; FIXME: the tests in subdirectory
  385. ;; 'unit/ufc/finite_element' require the ffc_factory
  386. ;; extension module. This module, located in the 'libs'
  387. ;; subdirectory, needs to be built and made accessible
  388. ;; prior to running the tests.
  389. (invoke "py.test" "unit/" "--ignore=unit/ufc/")
  390. (with-directory-excursion "uflacs"
  391. (invoke "py.test" "unit/")))
  392. #t)))))
  393. (home-page "https://bitbucket.org/fenics-project/ffc/")
  394. (synopsis "Compiler for finite element variational forms")
  395. (description "The FEniCS Form Compiler (FFC) is a compiler for
  396. finite element variational forms. From a high-level description of
  397. the form, it generates efficient low-level C++ code that can be used
  398. to assemble the corresponding discrete operator (tensor). In
  399. particular, a bilinear form may be assembled into a matrix and a
  400. linear form may be assembled into a vector. FFC may be used either
  401. from the command line (by invoking the @code{ffc} command) or as a
  402. Python module (@code{import ffc}).
  403. FFC is part of the FEniCS Project.")
  404. ;; There are two files released with a public domain licence;
  405. ;; ufc.h and ufc_geometry.h, in subdirectory 'ffc/backends/ufc'.
  406. (license (list license:public-domain license:lgpl3+))))
  407. (define-public fenics-dolfin
  408. (package
  409. (name "fenics-dolfin")
  410. (version "2019.1.0.post0")
  411. (source
  412. (origin
  413. (method url-fetch)
  414. (uri (string-append
  415. "https://bitbucket.org/fenics-project/dolfin/get/"
  416. version ".tar.gz"))
  417. (file-name (string-append name "-" version ".tar.gz"))
  418. (sha256
  419. (base32
  420. "1m91hwcq5gfj4qqswp8l8kj58nia48f0n4kq13w0xqj4biq7rla0"))
  421. (patches (search-patches "fenics-dolfin-algorithm.patch"
  422. "fenics-dolfin-demo-init.patch"
  423. "fenics-dolfin-boost.patch"
  424. "fenics-dolfin-config-slepc.patch"))
  425. (modules '((guix build utils)))
  426. (snippet
  427. '(begin
  428. ;; Make sure we don't use the bundled test framework.
  429. (delete-file-recursively "test/unit/cpp/catch")
  430. (substitute* "test/unit/cpp/main.cpp"
  431. ;; Use standard search paths for 'catch' header file.
  432. (("#include.*")
  433. "#include <catch.hpp>\n"))
  434. (substitute* "test/unit/cpp/CMakeLists.txt"
  435. ;; Specify directory to find the header file.
  436. (("(^set\\(CATCH_INCLUDE_DIR ).*(/catch\\))" _ front back)
  437. (string-append front
  438. "$ENV{CATCH_DIR}/include" back "\n")))
  439. #t))))
  440. (build-system cmake-build-system)
  441. (inputs
  442. `(("blas" ,openblas)
  443. ("boost" ,boost)
  444. ("eigen" ,eigen)
  445. ("hdf5" ,hdf5-parallel-openmpi)
  446. ("lapack" ,lapack)
  447. ("libxml2" ,libxml2)
  448. ("openmpi" ,openmpi)
  449. ("python" ,python-3)
  450. ("scotch" ,pt-scotch32)
  451. ("suitesparse" ,suitesparse)
  452. ("sundials" ,sundials-openmpi)
  453. ("zlib" ,zlib)))
  454. (native-inputs
  455. `(("catch" ,catch-framework2-1)
  456. ("pkg-config" ,pkg-config)))
  457. (propagated-inputs
  458. `(("ffc" ,python-fenics-ffc)
  459. ("petsc" ,petsc-openmpi)
  460. ("slepc" ,slepc-openmpi)))
  461. (arguments
  462. `(#:configure-flags
  463. `("-DDOLFIN_ENABLE_DOCS:BOOL=OFF"
  464. "-DDOLFIN_ENABLE_HDF5:BOOL=ON"
  465. "-DDOLFIN_ENABLE_MPI:BOOL=ON"
  466. "-DDOLFIN_ENABLE_PARMETIS:BOOL=OFF"
  467. "-DDOLFIN_ENABLE_SCOTCH:BOOL=ON"
  468. "-DDOLFIN_ENABLE_SUNDIALS:BOOL=ON"
  469. "-DDOLFIN_ENABLE_TRILINOS:BOOL=OFF")
  470. #:phases
  471. (modify-phases %standard-phases
  472. (add-after 'patch-usr-bin-file 'mpi-setup
  473. ,%openmpi-setup)
  474. (add-after 'patch-source-shebangs 'set-paths
  475. (lambda _
  476. ;; Define paths to store locations.
  477. (setenv "BLAS_DIR" (assoc-ref %build-inputs "blas"))
  478. (setenv "CATCH_DIR" (assoc-ref %build-inputs "catch"))
  479. (setenv "LAPACK_DIR" (assoc-ref %build-inputs "lapack"))
  480. (setenv "PETSC_DIR" (assoc-ref %build-inputs "petsc"))
  481. (setenv "SLEPC_DIR" (assoc-ref %build-inputs "slepc"))
  482. (setenv "SCOTCH_DIR" (assoc-ref %build-inputs "scotch"))
  483. (setenv "SUNDIALS_DIR" (assoc-ref %build-inputs "sundials"))
  484. (setenv "UMFPACK_DIR" (assoc-ref %build-inputs "suitesparse"))
  485. #t))
  486. (add-before 'check 'pre-check
  487. (lambda _
  488. ;; The Dolfin repository uses git-lfs, whereby web links are
  489. ;; substituted for large files. Guix does not currently support
  490. ;; git-lfs, so only the links are downloaded. The tests that
  491. ;; require the absent meshes cannot run and are skipped.
  492. ;;
  493. ;; One serial test fails and is skipped.
  494. ;; i) demo_multimesh-stokes_serial:
  495. ;; Warning: Found no facets matching domain for boundary
  496. ;; condition.
  497. ;;
  498. ;; One mpi test fails and is skipped.
  499. ;; i) demo_stokes-iterative_mpi:
  500. ;; The MPI_Comm_rank() function was called before MPI_INIT was
  501. ;; invoked
  502. (call-with-output-file "CTestCustom.cmake"
  503. (lambda (port)
  504. (display
  505. (string-append
  506. "set(CTEST_CUSTOM_TESTS_IGNORE "
  507. "demo_bcs_serial "
  508. "demo_bcs_mpi "
  509. "demo_eigenvalue_serial "
  510. "demo_eigenvalue_mpi "
  511. "demo_navier-stokes_serial "
  512. "demo_navier-stokes_mpi "
  513. "demo_stokes-taylor-hood_serial "
  514. "demo_stokes-taylor-hood_mpi "
  515. "demo_subdomains_serial "
  516. "demo_advection-diffusion_serial "
  517. "demo_advection-diffusion_mpi "
  518. "demo_auto-adaptive-navier-stokes_serial "
  519. "demo_contact-vi-snes_serial "
  520. "demo_contact-vi-snes_mpi "
  521. "demo_contact-vi-tao_serial "
  522. "demo_contact-vi-tao_mpi "
  523. "demo_curl-curl_serial "
  524. "demo_curl-curl_mpi "
  525. "demo_dg-advection-diffusion_serial "
  526. "demo_dg-advection-diffusion_mpi "
  527. "demo_elasticity_serial "
  528. "demo_elasticity_mpi "
  529. "demo_elastodynamics_serial "
  530. "demo_elastodynamics_mpi "
  531. "demo_lift-drag_serial "
  532. "demo_lift-drag_mpi "
  533. "demo_mesh-quality_serial "
  534. "demo_mesh-quality_mpi "
  535. "demo_multimesh-stokes_serial "
  536. ")\n") port)))
  537. #t))
  538. (replace 'check
  539. (lambda _
  540. (and (invoke "make" "unittests")
  541. (invoke "make" "demos")
  542. (invoke "ctest" "-R" "unittests")
  543. (invoke "ctest" "-R" "demo" "-R" "serial")
  544. (invoke "ctest" "-R" "demo" "-R" "mpi")))))))
  545. (home-page "https://bitbucket.org/fenics-project/dolfin/")
  546. (synopsis "Problem solving environment for differential equations")
  547. (description
  548. "DOLFIN is a computational framework for finding numerical
  549. solutions to problems described by differential equations. Numerical
  550. models in DOLFIN are constructed using general families of finite
  551. elements. Data structures are provided for discretizing the governing
  552. system on a computational mesh. A compact syntax, similar to
  553. mathematical notation, is made available for defining function spaces
  554. and expressing variational forms. Interfaces to specialized matrix
  555. solvers are provided for solving the resultant linear systems.
  556. @code{fenics-dolfin} is part of the FEniCS project. It is the C++
  557. user interface to the FEniCS core components and external libraries.")
  558. ;; The source code for the DOLFIN C++ library is licensed under the
  559. ;; GNU Lesser General Public License, version 3 or later, with the
  560. ;; following exceptions:
  561. ;;
  562. ;; public-domain: dolfin/geometry/predicates.cpp
  563. ;; dolfin/geometry/predicates.h
  564. ;;
  565. ;; zlib: dolfin/io/base64.cpp
  566. ;; dolfin/io/base64.h
  567. ;;
  568. ;; expat: dolfin/io/pugiconfig.hpp
  569. ;; dolfin/io/pugixml.cpp
  570. ;; dolfin/io/pugixml.hpp
  571. (license (list license:public-domain
  572. license:zlib
  573. license:expat
  574. license:lgpl3+))))
  575. (define-public fenics
  576. (package/inherit fenics-dolfin
  577. (name "fenics")
  578. (build-system python-build-system)
  579. (inputs
  580. `(("pybind11" ,pybind11)
  581. ("python-matplotlib" ,python-matplotlib)
  582. ,@(alist-delete "python" (package-inputs fenics-dolfin))))
  583. (native-inputs
  584. `(("cmake" ,cmake-minimal)
  585. ("ply" ,python-ply)
  586. ("pytest" ,python-pytest)
  587. ("python-decorator" ,python-decorator)
  588. ("python-pkgconfig" ,python-pkgconfig)
  589. ,@(package-native-inputs fenics-dolfin)))
  590. (propagated-inputs
  591. `(("dolfin" ,fenics-dolfin)
  592. ("petsc4py" ,python-petsc4py)
  593. ("slepc4py" ,python-slepc4py)))
  594. (arguments
  595. `(#:phases
  596. (modify-phases %standard-phases
  597. (add-after 'patch-source-shebangs 'set-paths
  598. (lambda _
  599. ;; Define paths to store locations.
  600. (setenv "PYBIND11_DIR" (assoc-ref %build-inputs "pybind11"))
  601. ;; Move to python sub-directory.
  602. (chdir "python")))
  603. (add-after 'build 'mpi-setup
  604. ,%openmpi-setup)
  605. (add-before 'check 'pre-check
  606. (lambda _
  607. ;; Exclude three tests that generate
  608. ;; 'NotImplementedError' in matplotlib version 3.1.2.
  609. ;; See
  610. ;; <https://github.com/matplotlib/matplotlib/issues/15382>.
  611. ;; Also exclude tests that require meshes supplied by
  612. ;; git-lfs.
  613. (substitute* "demo/test.py"
  614. (("(.*stem !.*)" line)
  615. (string-append
  616. line "\n"
  617. "excludeList = [\n"
  618. "'built-in-meshes', \n"
  619. "'hyperelasticity', \n"
  620. "'elasticity', \n"
  621. "'multimesh-quadrature', \n"
  622. "'multimesh-marking', \n"
  623. "'mixed-poisson-sphere', \n"
  624. "'mesh-quality', \n"
  625. "'lift-drag', \n"
  626. "'elastodynamics', \n"
  627. "'dg-advection-diffusion', \n"
  628. "'curl-curl', \n"
  629. "'contact-vi-tao', \n"
  630. "'contact-vi-snes', \n"
  631. "'collision-detection', \n"
  632. "'buckling-tao', \n"
  633. "'auto-adaptive-navier-stokes', \n"
  634. "'advection-diffusion', \n"
  635. "'subdomains', \n"
  636. "'stokes-taylor-hood', \n"
  637. "'stokes-mini', \n"
  638. "'navier-stokes', \n"
  639. "'eigenvalue']\n"
  640. "demos = ["
  641. "d for d in demos if d[0].stem not in "
  642. "excludeList]\n")))
  643. (setenv "HOME" (getcwd))
  644. ;; Restrict OpenBLAS to MPI-only in preference to MPI+OpenMP.
  645. (setenv "OPENBLAS_NUM_THREADS" "1")))
  646. (replace 'check
  647. (lambda _
  648. (with-directory-excursion "test"
  649. ;; Note: The test test_snes_set_from_options() in the file
  650. ;; unit/nls/test_PETScSNES_solver.py fails and is ignored.
  651. ;; Limit the number of jobs to 3 as 500 MiB of memory is used
  652. ;; per process.
  653. (invoke "mpirun" "-np" (number->string
  654. (min 3 (parallel-job-count)))
  655. "python" "-B" "-m"
  656. "pytest" "unit" "--ignore"
  657. "unit/nls/test_PETScSNES_solver.py"))))
  658. (add-after 'install 'install-demo-files
  659. (lambda* (#:key outputs #:allow-other-keys)
  660. (let* ((demos (string-append
  661. (assoc-ref outputs "out")
  662. "/share/python-dolfin/demo")))
  663. (mkdir-p demos)
  664. (with-directory-excursion "demo"
  665. (for-each (lambda (file)
  666. (let* ((dir (dirname file))
  667. (tgt-dir (string-append demos "/" dir)))
  668. (unless (equal? "." dir)
  669. (mkdir-p tgt-dir)
  670. (install-file file tgt-dir))))
  671. (find-files "." ".*\\.(py|gz|xdmf)$")))))))))
  672. (home-page "https://fenicsproject.org/")
  673. (synopsis "High-level environment for solving differential equations")
  674. (description
  675. "@code{fenics} is a computing platform for solving general classes of
  676. problems that involve differential equations. @code{fenics} facilitates
  677. access to efficient methods for dealing with ordinary differential
  678. equations (ODEs) and partial differential equations (PDEs). Systems of
  679. equations such as these are commonly encountered in areas of engineering,
  680. mathematics and the physical sciences. It is particularly well-suited to
  681. problems that can be solved using the Finite Element Method (FEM).
  682. @code{fenics} is the top level of the set of packages that are developed
  683. within the FEniCS project. It provides the python user interface to the
  684. FEniCS core components and external libraries.")
  685. (license license:lgpl3+)))
  686. (define-public fullswof-2d
  687. (let ((revision 505)
  688. (release "1.09.01"))
  689. (package
  690. (name "fullswof-2d")
  691. (version release)
  692. (source (origin
  693. (method svn-fetch)
  694. (uri (svn-reference
  695. (url (string-append "https://subversion.renater.fr/"
  696. "anonscm/svn/fullswof-2d/tags/"
  697. "release-" version))
  698. (revision revision)))
  699. (file-name (string-append "fullswof-2d-" version "-checkout"))
  700. (sha256
  701. (base32
  702. "16v08dx7h7n4wyddzbwimazwyj74ynis12mpjfkay4243npy44b8"))))
  703. (build-system gnu-build-system)
  704. (native-inputs
  705. (list inetutils)) ; for 'hostname', used in the check phase
  706. (arguments
  707. `(#:phases
  708. (modify-phases %standard-phases
  709. (delete 'configure) ; no configure script
  710. (add-after 'build 'build-tools
  711. (lambda _
  712. (with-directory-excursion "Tools/ConvertFormat"
  713. (invoke "make" "../../bin/asc2xyz")
  714. (invoke "make" "../../bin/xyz2asc"))
  715. (with-directory-excursion "Tools/ExtractWindow"
  716. (invoke "make" "../../bin/cropxyz"))
  717. #t))
  718. (replace 'check ; no check target
  719. (lambda _
  720. (invoke "make" "benchref")))
  721. (replace 'install ; no install target
  722. (lambda* (#:key outputs #:allow-other-keys)
  723. (let* ((out (assoc-ref outputs "out"))
  724. (bin (string-append out "/bin"))
  725. (doc (string-append
  726. out "/share/doc/" ,name "-" ,version))
  727. (examples (string-append doc "/Examples")))
  728. (with-directory-excursion "bin"
  729. (for-each (lambda (binary) (install-file binary bin))
  730. (list "asc2xyz" "xyz2asc" "cropxyz"
  731. "FullSWOF_2D")))
  732. (with-directory-excursion "doc"
  733. (for-each (lambda (pdf) (install-file pdf doc))
  734. (list "Documentation.pdf" "refman.pdf")))
  735. (with-directory-excursion "Tools"
  736. (for-each (lambda (dir)
  737. (copy-file
  738. (string-append dir "/README.txt")
  739. (string-append doc "/README_" dir ".txt")))
  740. (list "ConvertFormat" "ExtractWindow")))
  741. (copy-recursively "Examples" examples)
  742. #t))))))
  743. (home-page "https://www.idpoisson.fr/fullswof/")
  744. (synopsis "Two dimensional flow solver for flood modelling")
  745. (description "@code{FullSWOF_2d} is a numerical tool for solving
  746. the shallow water equations on structured grids. The name FullSWOF
  747. refers to the Full form of the Shallow Water equations for Overland
  748. Flow. The discretized system of equations is solved using the finite
  749. volume method. A choice of shock-capturing methods is available to
  750. locate the transition boundaries between the wet areas and the dry
  751. areas in the model. A semi-implicit method is used to advance the
  752. solution in time. The tool is typically applied to the modelling of
  753. river flooding.")
  754. (license license:cecill))))
  755. (define-public python-meshio
  756. (package
  757. (name "python-meshio")
  758. (version "4.4.6")
  759. (source
  760. (origin
  761. (method url-fetch)
  762. (uri (pypi-uri "meshio" version))
  763. (sha256
  764. (base32
  765. "0kv832s2vyff30zz8yqypw5jifwdanvh5x56d2bzkvy94h4jlddy"))
  766. (snippet
  767. '(begin
  768. (let ((file (open-file "setup.py" "a")))
  769. (display "from setuptools import setup\nsetup()" file)
  770. (close-port file))
  771. #t))))
  772. (build-system python-build-system)
  773. (inputs
  774. `(("h5py" ,python-h5py)
  775. ("netcdf4" ,python-netcdf4)))
  776. (native-inputs
  777. `(("pytest" ,python-pytest)))
  778. (propagated-inputs
  779. `(("importlib-metadata" ,python-importlib-metadata)
  780. ("numpy" ,python-numpy)))
  781. (arguments
  782. `(#:phases
  783. (modify-phases %standard-phases
  784. (replace 'check
  785. (lambda* (#:key outputs inputs #:allow-other-keys)
  786. (add-installed-pythonpath inputs outputs)
  787. (invoke "python" "-m" "pytest" "-v" "tests")
  788. #t)))))
  789. (home-page "https://github.com/nschloe/meshio")
  790. (synopsis "I/O for mesh files")
  791. (description "There are various file formats available for
  792. representing unstructured meshes and mesh data. The @code{meshio}
  793. package is able to read and write mesh files in many formats and to
  794. convert files from one format to another. Formats such as cgns, h5m,
  795. gmsh, xdmf and vtk are supported. The package provides command-line
  796. tools and a collection of Python modules for programmatic use.")
  797. (license license:expat)))
  798. (define-public python-pygmsh
  799. (package
  800. (name "python-pygmsh")
  801. (version "7.1.11")
  802. (source
  803. (origin
  804. (method git-fetch)
  805. (uri (git-reference
  806. (url "https://github.com/nschloe/pygmsh")
  807. (commit version)))
  808. (file-name (git-file-name name version))
  809. (sha256
  810. (base32
  811. "0g4yllmxks7yb50vild5xi1cma0yl16vsq6rfvdwmqaj4hwxcabk"))
  812. (modules '((guix build utils)))
  813. (snippet
  814. '(begin
  815. (let ((file (open-file "setup.py" "a")))
  816. (display "from setuptools import setup\nsetup()" file)
  817. (close-port file))
  818. ;; A reference to setuptools in the configuration file
  819. ;; triggers an attempt to download the package from pypi.
  820. ;; The reference is not needed since the package is
  821. ;; provided by the build system.
  822. (substitute* "setup.cfg"
  823. (("^[[:blank:]]+setuptools>=42\n") ""))
  824. #t))))
  825. (build-system python-build-system)
  826. (native-inputs
  827. `(("pytest" ,python-pytest)
  828. ("wheel" ,python-wheel)))
  829. (propagated-inputs
  830. `(("importlib-metadata" ,python-importlib-metadata)
  831. ("gmsh" ,gmsh)
  832. ("meshio" ,python-meshio)
  833. ("numpy" ,python-numpy)))
  834. (arguments
  835. `(#:phases
  836. (modify-phases %standard-phases
  837. (replace 'check
  838. (lambda* (#:key inputs outputs tests? #:allow-other-keys)
  839. (when tests?
  840. (add-installed-pythonpath inputs outputs)
  841. (invoke "python" "-m" "pytest" "-v" "tests"))
  842. #t)))))
  843. (home-page "https://github.com/nschloe/pygmsh")
  844. (synopsis "Python frontend for Gmsh")
  845. (description "The goal of @code{pygmsh} is to combine the power of
  846. Gmsh with the versatility of Python. The package generalises many of
  847. the methods and functions that comprise the Gmsh Python API. In this
  848. way the meshing of complex geometries using high-level abstractions is
  849. made possible. The package provides a Python library together with a
  850. command-line utility for mesh optimisation.")
  851. (license license:lgpl3)))
  852. (define-public python-dolfin-adjoint
  853. (package
  854. (name "python-dolfin-adjoint")
  855. (version "2019.1.0")
  856. (source
  857. (origin
  858. (method git-fetch)
  859. (uri (git-reference
  860. (url "https://github.com/dolfin-adjoint/pyadjoint")
  861. (commit version)))
  862. (file-name (git-file-name name version))
  863. (sha256
  864. (base32
  865. "0xhy76a5f33hz94wc9g2mc5qmwkxfccbbc6yxl7psm130afp8lhn"))
  866. (modules '((guix build utils)))
  867. (snippet
  868. '(begin
  869. ;; One of the migration tests attempts to call openmpi
  870. ;; recursively and fails. See
  871. ;; https://bitbucket.org/mpi4py/mpi4py/issues/95. Run the
  872. ;; test sequentially instead.
  873. (with-directory-excursion "tests/migration/optimal_control_mms"
  874. (substitute* "test_optimal_control_mms.py"
  875. (("\\\"mpirun\\\", \\\"-n\\\", \\\"2\\\", ") "")))
  876. ;; Result files are regenerated in the check phase.
  877. (delete-file-recursively
  878. "tests/migration/viscoelasticity/test-results")
  879. #t))))
  880. (build-system python-build-system)
  881. (inputs
  882. (list fenics openmpi pybind11))
  883. (native-inputs
  884. (list pkg-config
  885. python-coverage
  886. python-decorator
  887. python-flake8
  888. python-pkgconfig
  889. python-pytest))
  890. (propagated-inputs
  891. `(("scipy" ,python-scipy)))
  892. (arguments
  893. `(#:phases
  894. (modify-phases %standard-phases
  895. (add-after 'build 'mpi-setup
  896. ,%openmpi-setup)
  897. (add-after 'install 'install-doc
  898. (lambda* (#:key outputs #:allow-other-keys)
  899. (let* ((doc (string-append (assoc-ref outputs "out")
  900. "/share/doc/" ,name "-"
  901. ,version))
  902. (examples (string-append doc "/examples")))
  903. (mkdir-p examples)
  904. (copy-recursively "examples" examples))
  905. #t))
  906. (replace 'check
  907. (lambda* (#:key inputs outputs tests? #:allow-other-keys)
  908. (when tests?
  909. (add-installed-pythonpath inputs outputs)
  910. (setenv "HOME" (getcwd))
  911. (and (invoke "py.test" "-v" "tests/fenics_adjoint")
  912. (invoke "py.test" "-v" "tests/migration")
  913. (invoke "py.test" "-v" "tests/pyadjoint")))
  914. #t)))))
  915. (home-page "http://www.dolfin-adjoint.org")
  916. (synopsis "Automatic differentiation library")
  917. (description "@code{python-dolfin-adjoint} is a solver of
  918. differential equations associated with a governing system and a
  919. functional of interest. Working from the forward model the solver
  920. automatically derives the discrete adjoint and tangent linear models.
  921. These additional models are key ingredients in many algorithms such as
  922. data assimilation, optimal control, sensitivity analysis, design
  923. optimisation and error estimation. The dolfin-adjoint project
  924. provides the necessary tools and data structures for cases where the
  925. forward model is implemented in @code{fenics} or
  926. @url{https://firedrakeproject.org,firedrake}.")
  927. (license license:lgpl3)))