Skip to content

Commit

Permalink
use maximum rather than minimum decimation factor for DFT convergence…
Browse files Browse the repository at this point in the history
… criteria (#1796)

* use maximum rather than minimum decimation factor for DFT convergence criteria

* Update src/dft.cpp

Co-authored-by: Steven G. Johnson <stevenj@mit.edu>

Co-authored-by: Steven G. Johnson <stevenj@mit.edu>
  • Loading branch information
oskooi and stevengj authored Oct 27, 2021
1 parent e8c2023 commit 5c02ff2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
18 changes: 9 additions & 9 deletions src/dft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>::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<int>::max();
int fields_chunk::max_decimation() const {
int maxdec = std::numeric_limits<int>::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
Expand Down
4 changes: 2 additions & 2 deletions src/meep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5c02ff2

Please sign in to comment.