From 5c02ff27372c794752725548b01a599ccb71613f Mon Sep 17 00:00:00 2001 From: Ardavan Oskooi Date: Wed, 27 Oct 2021 12:51:46 -0700 Subject: [PATCH] use maximum rather than minimum decimation factor for DFT convergence criteria (#1796) * use maximum rather than minimum decimation factor for DFT convergence criteria * Update src/dft.cpp Co-authored-by: Steven G. Johnson Co-authored-by: Steven G. Johnson --- python/simulation.py | 2 +- src/dft.cpp | 18 +++++++++--------- src/meep.hpp | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/python/simulation.py b/python/simulation.py index 03db7ad28..407e053c8 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -4527,7 +4527,7 @@ def stop_when_dft_decayed(tol=1e-11, minimum_run_time=0, maximum_run_time=None): closure = {'previous_fields':0, 't0':0, 'dt':0, 'maxchange':0} def _stop(_sim): if _sim.fields.t == 0: - closure['dt'] = max(1/_sim.fields.dft_maxfreq()/_sim.fields.dt,_sim.fields.min_decimation()) + closure['dt'] = max(1/_sim.fields.dft_maxfreq()/_sim.fields.dt,_sim.fields.max_decimation()) if maximum_run_time and _sim.round_time() > maximum_run_time: return True elif _sim.fields.t <= closure['dt'] + closure['t0']: diff --git a/src/dft.cpp b/src/dft.cpp index 540a7bfbf..cb6cd13ad 100644 --- a/src/dft.cpp +++ b/src/dft.cpp @@ -316,21 +316,21 @@ double dft_chunk::norm2() const { return sum; } -// return the minimum decimation factor across +// return the maximum decimation factor across // all dft regions -int fields::min_decimation() const { - int mindec = std::numeric_limits::max(); +int fields::max_decimation() const { + int maxdec = 1; for (int i = 0; i < num_chunks; i++) if (chunks[i]->is_mine()) - mindec = std::min(mindec, chunks[i]->min_decimation()); - return min_to_all(mindec); + maxdec = std::max(maxdec, chunks[i]->max_decimation()); + return max_to_all(maxdec); } -int fields_chunk::min_decimation() const { - int mindec = std::numeric_limits::max(); +int fields_chunk::max_decimation() const { + int maxdec = std::numeric_limits::min(); for (dft_chunk *cur = dft_chunks; cur; cur = cur->next_in_chunk) - mindec = std::min(mindec, cur->get_decimation_factor()); - return mindec; + maxdec = std::max(maxdec, cur->get_decimation_factor()); + return maxdec; } // return the maximum abs(freq) over all DFT chunks diff --git a/src/meep.hpp b/src/meep.hpp index 45d45bb7c..ad77fb5e4 100644 --- a/src/meep.hpp +++ b/src/meep.hpp @@ -1572,7 +1572,7 @@ class fields_chunk { void update_dfts(double timeE, double timeH, int current_step); double dft_norm2() const; double dft_maxfreq() const; - int min_decimation() const; + int max_decimation() const; void changing_structure(); }; @@ -2000,7 +2000,7 @@ class fields { void update_dfts(); double dft_norm(); double dft_maxfreq() const; - int min_decimation() const; + int max_decimation() const; dft_flux add_dft_flux(const volume_list *where, const double *freq, size_t Nfreq, bool use_symmetry = true, bool centered_grid = true,