1{ stdenv
2, lib
3, buildPythonPackage
4, fetchFromGitHub
5, autoreconfHook
6, pkg-config
7, gfortran
8, mpi
9, blas
10, lapack
11, fftw
12, hdf5-mpi
13, swig
14, gsl
15, harminv
16, libctl
17, libGDSII
18, openssh
19, guile
20, python
21, numpy
22, scipy
23, matplotlib
24, h5py-mpi
25, cython
26, autograd
27, mpi4py
28}:
29
30assert !blas.isILP64;
31assert !lapack.isILP64;
32
33buildPythonPackage rec {
34 pname = "meep";
35 version = "1.25.0";
36
37 src = fetchFromGitHub {
38 owner = "NanoComp";
39 repo = pname;
40 rev = "v${version}";
41 hash = "sha256-4rIz2RXLSWzZbRuv8d4nidOa0ULYc4QHIdaYrGu1WkI=";
42 };
43
44 format = "other";
45
46 # MPI is needed in nativeBuildInputs too, otherwise MPI libs will be missing
47 # at runtime
48 nativeBuildInputs = [
49 autoreconfHook
50 gfortran
51 pkg-config
52 swig
53 mpi
54 ];
55
56 buildInputs = [
57 gsl
58 blas
59 lapack
60 fftw
61 hdf5-mpi
62 harminv
63 libctl
64 libGDSII
65 guile
66 gsl
67 ];
68
69 propagatedBuildInputs = [
70 mpi
71 numpy
72 scipy
73 matplotlib
74 h5py-mpi
75 cython
76 autograd
77 mpi4py
78 ];
79
80 propagatedUserEnvPkgs = [ mpi ];
81
82 dontUseSetuptoolsBuild = true;
83 dontUsePipInstall = true;
84 dontUseSetuptoolsCheck = true;
85
86 enableParallelBuilding = true;
87
88 preConfigure = ''
89 export HDF5_MPI=ON
90 export PYTHON=${python}/bin/${python.executable};
91 '';
92
93 configureFlags = [
94 "--without-libctl"
95 "--enable-shared"
96 "--with-mpi"
97 "--with-openmp"
98 "--enable-maintainer-mode"
99 ];
100
101 passthru = { inherit mpi; };
102
103 /*
104 This test is taken from the MEEP tutorial "Fields in a Waveguide" at
105 <https://meep.readthedocs.io/en/latest/Python_Tutorials/Basics/>.
106 It is important, that the test actually performs a calculation
107 (calls `sim.run()`), as only then MPI will be initialised and MPI linking
108 errors can be caught.
109 */
110 doCheck = true;
111 checkPhase = ''
112 export PATH=$PATH:${openssh}/bin
113 export PYTHONPATH="$out/lib/${python.libPrefix}/site-packages:$PYTHONPATH"
114
115 export OMP_NUM_THREADS=1
116
117 # Fix to make mpich run in a sandbox
118 export HYDRA_IFACE=lo
119 export OMPI_MCA_rmaps_base_oversubscribe=1
120
121 # Generate a python test script
122 cat > test.py << EOF
123 import meep as mp
124 cell = mp.Vector3(16,8,0)
125 geometry = [mp.Block(mp.Vector3(mp.inf,1,mp.inf),
126 center=mp.Vector3(),
127 material=mp.Medium(epsilon=12))]
128 sources = [mp.Source(mp.ContinuousSource(frequency=0.15),
129 component=mp.Ez,
130 center=mp.Vector3(-7,0))]
131 pml_layers = [mp.PML(1.0)]
132 resolution = 10
133 sim = mp.Simulation(cell_size=cell,
134 boundary_layers=pml_layers,
135 geometry=geometry,
136 sources=sources,
137 resolution=resolution)
138 sim.run(until=200)
139 EOF
140
141 ${mpi}/bin/mpiexec -np 2 python3 test.py
142 '';
143
144 meta = with lib; {
145 description = "Free finite-difference time-domain (FDTD) software for electromagnetic simulations";
146 homepage = "https://meep.readthedocs.io/en/latest/";
147 license = licenses.gpl2Only;
148 platforms = platforms.linux;
149 maintainers = with maintainers; [ sheepforce markuskowa ];
150 };
151}