Skip to content

Commit

Permalink
invoke register_src_time in several places, add id = t.id in src_time…
Browse files Browse the repository at this point in the history
…(const src_time &t) in meep.hpp, add a ifdef-endif sentence in fix_boundary_sources.cpp, add needs_boundary_fix in IndexedSource
  • Loading branch information
mawc2019 committed Feb 21, 2022
1 parent ca688c6 commit 997a1a7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
8 changes: 5 additions & 3 deletions python/adjoint/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ def _create_time_profile(self, fwidth_frac=0.1):
The user may specify a scalar valued objective function across multiple frequencies (e.g. MSE) in
which case we should check that all the frequencies fit in the specified bandwidth.
"""
return mp.GaussianSource(
srct = mp.GaussianSource(
np.mean(self._frequencies),
fwidth=fwidth_frac * np.mean(self._frequencies),
)
self.sim.fields.register_src_time(srct.swigobj)
return srct


class EigenmodeCoefficient(ObjectiveQuantity):
Expand Down Expand Up @@ -273,12 +275,12 @@ def place_adjoint_source(self, dJ):
scale = amp_arr * self._adj_src_scale(include_resolution=False)

if self.num_freq == 1:
sources += [mp.IndexedSource(time_src, fourier_data, scale[:,0])]
sources += [mp.IndexedSource(time_src, fourier_data, scale[:,0], not self.yee_grid)]
else:
src = FilteredSource(time_src.frequency,self._frequencies,scale,self.sim.fields.dt)
(num_basis, num_pts) = src.nodes.shape
for basis_i in range(num_basis):
sources += [mp.IndexedSource(src.time_src_bf[basis_i], fourier_data, src.nodes[basis_i])]
sources += [mp.IndexedSource(src.time_src_bf[basis_i], fourier_data, src.nodes[basis_i], not self.yee_grid)]
return sources

def __call__(self):
Expand Down
3 changes: 2 additions & 1 deletion python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,8 @@ def add_source(self, src):
self.init_sim()

if isinstance(src, IndexedSource):
self.fields.add_srcdata(src.srcdata, src.src.swigobj, src.num_pts, src.amp_arr)
self.fields.register_src_time(src.src.swigobj)
self.fields.add_srcdata(src.srcdata, src.src.swigobj, src.num_pts, src.amp_arr, src.needs_boundary_fix)
return

where = Volume(src.center, src.size, dims=self.dimensions,
Expand Down
3 changes: 2 additions & 1 deletion python/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,9 @@ class IndexedSource(Source):
"""
created a source object using (SWIG-wrapped mp::srcdata*) srcdata.
"""
def __init__(self, src, srcdata, amp_arr):
def __init__(self, src, srcdata, amp_arr, needs_boundary_fix=False):
self.src = src
self.num_pts = len(amp_arr)
self.srcdata = srcdata
self.amp_arr = amp_arr
self.needs_boundary_fix = needs_boundary_fix
7 changes: 6 additions & 1 deletion src/fix_boundary_sources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
#undef SEEK_CUR
#endif
#include <mpi.h>
#include <algorithm>
#endif

namespace meep {

#ifdef HAVE_MPI
static MPI_Comm mycomm = MPI_COMM_WORLD;
#endif

// data structure for sending source information from one chunk to another
struct srcpt_info {
std::complex<double> A; // amplitude
Expand Down Expand Up @@ -168,4 +173,4 @@ for (int psrc = 0; psrc < P; ++psrc)
finished_working();
}

} // namespace meep
} // namespace meep
3 changes: 2 additions & 1 deletion src/meep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ class src_time {
current_time = t.current_time;
current_current = t.current_current;
current_dipole = t.current_dipole;
id = t.id;
if (t.next)
next = t.next->clone();
else
Expand Down Expand Up @@ -1897,7 +1898,7 @@ class fields {
void require_source_components();
void _require_component(component c, bool aniso2d);
void require_component(component c) { _require_component(c, is_aniso2d()); sync_chunk_connections(); }
void add_srcdata(struct sourcedata cur_data, src_time *src, size_t n, std::complex<double>* amp_arr, bool needs_boundary_fix=false);
void add_srcdata(struct sourcedata cur_data, src_time *src, size_t n, std::complex<double>* amp_arr, bool needs_boundary_fix);
void register_src_time(src_time *src);
src_time *lookup_src_time(size_t id);

Expand Down

0 comments on commit 997a1a7

Please sign in to comment.