Skip to content

Commit

Permalink
Fields dump/load fix (#1783)
Browse files Browse the repository at this point in the history
* call self._evaluate_dft_objects() before loading saved fields

* remove extraneous log statements

* Make _get_load_dump_dirname non-protected
  • Loading branch information
kkg4theweb authored Oct 13, 2021
1 parent d12e544 commit b9efcc6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 5 additions & 4 deletions python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,7 @@ def load_fields(self, fname, single_parallel_file=True):
"""
if self.fields is None:
raise ValueError("Fields must be initialized before loading fields from file '%s'" % fname)
self._evaluate_dft_objects()
self.fields.load(fname, single_parallel_file)
print("Loaded fields from file: %s (%s)" % (fname, str(single_parallel_file)))

Expand All @@ -1964,9 +1965,9 @@ def load_chunk_layout(self, br, source):
## source is either filename (string)
self.structure.load_chunk_layout(source, br)

def _get_load_dump_dirname(self, dirname, single_parallel_file):
def get_load_dump_dirname(self, dirname, single_parallel_file):
"""
Get the dirname to dump simulation state to.
Get the (possibly rank specific) dirname to dump simulation state to.
"""
if single_parallel_file:
dump_dirname = dirname
Expand All @@ -1980,7 +1981,7 @@ def dump(self, dirname, dump_structure=True, dump_fields=True, single_parallel_f
"""
Dumps simulation state.
"""
dump_dirname = self._get_load_dump_dirname(dirname, single_parallel_file)
dump_dirname = self.get_load_dump_dirname(dirname, single_parallel_file)
os.makedirs(dump_dirname, exist_ok=True)

if dump_structure:
Expand All @@ -1998,7 +1999,7 @@ def load(self, dirname, load_structure=True, load_fields=True, single_parallel_f
This should called right after the Simulation object has been created
but before 'init_sim' is called.
"""
dump_dirname = self._get_load_dump_dirname(dirname, single_parallel_file)
dump_dirname = self.get_load_dump_dirname(dirname, single_parallel_file)
self.load_single_parallel_file = single_parallel_file

if load_structure:
Expand Down
4 changes: 0 additions & 4 deletions src/fields_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ void fields::dump_fields_chunk_field(h5file *h5f, bool single_parallel_file,
void fields::dump(const char *filename, bool single_parallel_file) {
if (verbosity > 0) {
printf("creating fields output file \"%s\" (%d)...\n", filename, single_parallel_file);
log();
}

h5file file(filename, h5file::WRITE, single_parallel_file, !single_parallel_file);
Expand Down Expand Up @@ -278,9 +277,6 @@ void fields::load(const char *filename, bool single_parallel_file) {
load_dft_hdf5(chunks[i]->dft_chunks, dataname, &file, 0, single_parallel_file);
}
}

if (verbosity > 0)
log();
}

} // namespace meep

0 comments on commit b9efcc6

Please sign in to comment.