Skip to content

Commit

Permalink
get_ldos_freqs method for Python LDOS objects (#1156)
Browse files Browse the repository at this point in the history
  • Loading branch information
oskooi authored Mar 27, 2020
1 parent e7e02a6 commit 1614959
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions doc/docs/Python_User_Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -1417,9 +1417,9 @@ Meep can also calculate the LDOS (local density of states) spectrum, as describe
Create an LDOS object with frequency bandwidth `df` centered at `fcen`, at `nfreq` frequency points. This can be passed to the `dft_ldos` step function below, and has the properties `freq_min`, `nfreq` and `dfreq`.

**`freqs()`**
**`get_ldos_freqs(ldos)`**
Method of `Ldos` that returns a list of the frequencies that this `Ldos` instance is computing the spectrum for.
Given an LDOS object, returns a list of the frequencies that it is computing the spectrum for.

**`dft_ldos(fcen=None, df=None, nfreq=None, ldos=None)`**
Expand Down
1 change: 1 addition & 0 deletions python/meep.i
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,7 @@ PyObject *_get_array_slice_dimensions(meep::fields *f, const meep::volume &where
get_fluxes,
get_force_freqs,
get_forces,
get_ldos_freqs,
get_magnetic_energy,
get_near2far_freqs,
get_total_energy,
Expand Down
6 changes: 5 additions & 1 deletion python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2961,14 +2961,18 @@ def _ldos(sim, todo):
sim.ldos_data = mp._dft_ldos_ldos(ldos)
sim.ldos_Fdata = mp._dft_ldos_F(ldos)
sim.ldos_Jdata = mp._dft_ldos_J(ldos)
display_csv(sim, 'ldos', zip(ldos.freq, sim.ldos_data))
display_csv(sim, 'ldos', zip(mp.get_ldos_freqs(ldos), sim.ldos_data))
return _ldos


def scale_flux_fields(s, flux):
flux.scale_dfts(s)


def get_ldos_freqs(l):
return [l.freq[i] for i in range(l.freq.size())]


def get_flux_freqs(f):
return [f.freq[i] for i in range(f.freq.size())]

Expand Down
3 changes: 1 addition & 2 deletions python/tests/ldos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import math
import unittest

import meep as mp
Expand Down Expand Up @@ -43,7 +42,7 @@ def test_ldos_user_object(self):
)

self.assertAlmostEqual(self.sim.ldos_data[0], 1.011459560620368)
self.assertEqual(ldos.freq.size(), 1)
self.assertEqual(len(mp.get_ldos_freqs(ldos)), 1)

def test_invalid_dft_ldos(self):
with self.assertRaises(ValueError):
Expand Down

0 comments on commit 1614959

Please sign in to comment.