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

Lower tolerance of CW and eigenfrequency solver tests for single precision #1714

Merged
merged 2 commits into from
Jul 29, 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
5 changes: 3 additions & 2 deletions python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3061,13 +3061,14 @@ def modal_volume_in_box(self, box=None, center=None, size=None):

return self.fields.modal_volume_in_box(box)

def solve_cw(self, tol=1e-8, maxiters=10000, L=2):
def solve_cw(self, tol=1e-5 if mp.is_single_precision() else 1e-8, maxiters=10000, L=2):
if self.fields is None:
raise RuntimeError('Fields must be initialized before using solve_cw')
self._evaluate_dft_objects()
return self.fields.solve_cw(tol, maxiters, L)

def solve_eigfreq(self, tol=1e-7, maxiters=100, guessfreq=None, cwtol=None, cwmaxiters=10000, L=10):
def solve_eigfreq(self, tol=1e-5 if mp.is_single_precision() else 1e-7, maxiters=100,
guessfreq=None, cwtol=None, cwmaxiters=10000, L=10):
if self.fields is None:
raise RuntimeError('Fields must be initialized before using solve_cw')
if cwtol is None:
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_array_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_array_metadata(self):
boundary_layers=pml_layers)

sim.init_sim()
sim.solve_cw(1e-6, 1000, 10)
sim.solve_cw(1e-5 if mp.is_single_precision() else 1e-6, 1000, 10)

def electric_energy(r, ez, eps):
return np.real(eps * np.conj(ez)*ez)
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_physical.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_physical(self):
sources=sources,
force_complex_fields=True)
sim.init_sim()
sim.solve_cw(tol=1e-6)
sim.solve_cw(tol=1e-5 if mp.is_single_precision() else 1e-6)

p1 = mp.Vector3()
p2 = mp.Vector3(dx)
Expand Down
5 changes: 3 additions & 2 deletions src/meep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1824,8 +1824,9 @@ class fields {
// cw_fields.cpp:
bool solve_cw(double tol, int maxiters, std::complex<double> frequency, int L = 2,
std::complex<double> *eigfreq = NULL, double eigtol = 1e-8, int eigiters = 20);
bool solve_cw(double tol = 1e-8, int maxiters = 10000, int L = 2,
std::complex<double> *eigfreq = NULL, double eigtol = 1e-8, int eigiters = 20);
bool solve_cw(double tol = sizeof(realnum) == sizeof(float) ? 1e-5 : 1e-8, int maxiters = 10000,
int L = 2, std::complex<double> *eigfreq = NULL, double eigtol = 1e-8,
int eigiters = 20);

// sources.cpp:
double last_source_time();
Expand Down
2 changes: 1 addition & 1 deletion tests/dft-fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void Run(bool Pulse, double resolution, cdouble **field_array = 0, int *array_ra
}
else {
f.add_point_source(Ez, continuous_src_time(fcen, df), x0);
f.solve_cw(1e-8, 10000, 10);
f.solve_cw(sizeof(realnum) == sizeof(float) ? 1e-5 : 1e-8, 10000, 10);
h5file *file = f.open_h5file("cw-fields", h5file::WRITE, 0, false);
f.output_hdf5(Ez, f.v, file);
f.output_hdf5(Hx, f.v, file);
Expand Down
4 changes: 2 additions & 2 deletions tests/near2far.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int check_cyl(double sr, double sz, double a) {
continuous_src_time src(w);
vec x0 = veccyl(0.5 * sr, 0);
f.add_point_source(c0, src, x0);
f.solve_cw(1e-6);
f.solve_cw(sizeof(realnum) == sizeof(float) ? 1e-5 : 1e-6);

component c = Ep;
const int N = 20;
Expand Down Expand Up @@ -137,7 +137,7 @@ int check_2d_3d(ndim dim, const double xmax, double a, component c0, component c
continuous_src_time src(w);
f.add_point_source(c0, src, zero_vec(dim));
if (c1 != NO_COMPONENT) f.add_point_source(c1, src, zero_vec(dim), 0.7654321);
f.solve_cw(1e-6);
f.solve_cw(sizeof(realnum) == sizeof(float) ? 1e-5 : 1e-6);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not necessary to change this, but it's fine as long as the test still passes.


FOR_E_AND_H(c) {
if (gv.has_field(c)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/physical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int radiating_2D(const double xmax) {

// let the source reach steady state
#if 1
f.solve_cw(1e-6);
f.solve_cw(sizeof(realnum) == sizeof(float) ? 1e-5 : 1e-6);
#else
while (f.time() < 400)
f.step();
Expand Down