diff --git a/doc/docs/Build_From_Source.md b/doc/docs/Build_From_Source.md index a643cb94d..54f9cb69e 100644 --- a/doc/docs/Build_From_Source.md +++ b/doc/docs/Build_From_Source.md @@ -256,8 +256,7 @@ This flag enables some experimental support for [OpenMP](https://en.wikipedia.or By default, the C++ arrays used in Meep to store the time-domain fields ($\mathbf{E}$, $\mathbf{D}$, $\mathbf{H}$, $\mathbf{B}$) and materials ($\varepsilon$, $\mu$) are defined using [double-precision floating point](https://en.wikipedia.org/wiki/Double-precision_floating-point_format). Updating the fields arrays generally dominates the computational cost of the simulation because it occurs at every voxel in the cell and at every timestep. Because [discretization errors](https://en.wikipedia.org/wiki/Discretization_error) which include the [discontinuous material interfaces](Subpixel_Smoothing.md) as well as the [numerical dispersion](https://en.wikipedia.org/wiki/Numerical_dispersion) of the Yee grid typically dominates the [floating-point roundoff error](https://en.wikipedia.org/wiki/Round-off_error), the fields and materials arrays can be defined using [single-precision floating point](https://en.wikipedia.org/wiki/Single-precision_floating-point_format) to provide a significant speedup by reducing the [memory bandwidth](https://en.wikipedia.org/wiki/Memory_bandwidth) often without any loss in simulation accuracy. -This feature requires one to pass the `--enable-single` flag to -the Meep `configure` script before compiling. +This feature requires one to pass the `--enable-single` flag to the Meep `configure` script before compiling. In Python, you can determine whether the Meep module has been compiled with single-precision floating point using the boolean function `meep.is_single_precision()`. As a demonstration of the potential improvement in runtime performance, for a benchmarking experiment based on [computing the light-extraction efficiency of an OLED](https://gist.github.com/oskooi/f745c467ae54e192d5c8340eace9a780) which includes PMLs, DFT flux monitors, and Lorentzian susceptibilities (for material dispersion), the timestepping rate (s/step) for the single-precision case using 20 MPI processes was *less than half* that of double precision. diff --git a/python/meep.i b/python/meep.i index c5fbc734a..c8ac91506 100644 --- a/python/meep.i +++ b/python/meep.i @@ -1869,6 +1869,10 @@ size_t get_realnum_size() { return sizeof(meep::realnum); } +bool is_single_precision() { + return sizeof(meep::realnum) == sizeof(float); +} + meep::structure *create_structure_and_set_materials(vector3 cell_size, std::vector dft_data_list_, std::vector pml_1d_vols_,