Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use maximum rather than minimum decimation factor for DFT convergence criteria #1796

Merged
merged 2 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = std::numeric_limits<int>::min();
oskooi marked this conversation as resolved.
Show resolved Hide resolved
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