simulation.scm 41 KB

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