Skip to content

Commit 8323d50

Browse files
committed
Convergence failure tests
1 parent 0beb4a9 commit 8323d50

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

include/novas.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,9 @@ double novas_inv_refract(RefractionModel model, double jd_tt, const on_surface *
12671267
#define HOURANGLE (M_PI / 12.0)
12681268
#define MAS (1e-3 * ASEC2RAD)
12691269

1270-
#define INV_MAX_ITER 100
1270+
#ifndef INV_MAX_ITER
1271+
# define INV_MAX_ITER 100 ///< Maximum number of iterations for convergent inverse calculations
1272+
#endif
12711273

12721274
# ifndef THREAD_LOCAL
12731275
# if __STDC_VERSION__ >= 201112L

src/frames.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static int frame_aberration(const novas_frame *frame, int dir, double *pos) {
261261
}
262262
}
263263

264-
errno = ECANCELED;
264+
novas_set_errno(ECANCELED, "frame_aberration", "failed to converge");
265265
return -1;
266266
}
267267

src/novas.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -4458,8 +4458,7 @@ int grav_undo_planets(const double *pos_app, const double *pos_obs, enum novas_a
44584458
pos0[j] -= pos_def[j] - pos_app[j];
44594459
}
44604460

4461-
novas_set_errno(ECANCELED, fn, "failed to converge");
4462-
return -1;
4461+
return novas_error(-1, ECANCELED, fn, "failed to converge");
44634462
}
44644463

44654464
/**

test/Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ include ../config.mk
1313

1414
#OBJECTS := $(subst obj/,,$(OBJECTS))
1515
OBJECTS := novas.o nutation.o solsys3.o frames.o timescale.o refract.o
16+
SOURCES := $(subst .o,.c,$(OBJECTS))
1617

1718
.PHONY: run
1819
run: clean-cov clean-data test-compat test-cio_file test-super test-errors data ../cio_ra.bin bad-data
@@ -65,6 +66,10 @@ bad-cio-data:
6566
../cio_ra.bin:
6667
make -C .. cio_ra.bin
6768

69+
test-errors: CPPFLAGS += -DINV_MAX_ITER=0
70+
test-errors: test-errors.o $(SOURCES) | Makefile data
71+
$(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
72+
6873
test-%: test-%.o $(OBJECTS) | Makefile data
6974
$(CC) -o $@ $^ $(LDFLAGS)
7075

@@ -86,10 +91,13 @@ clean-cov:
8691
clean-data:
8792
rm -rf data cio_ra.bin bad-cio-data
8893

89-
.PHONY: clean
90-
clean: clean-test clean-cov clean-data
94+
.PHONY: clean-obj
95+
clean-obj:
9196
rm -f *.o
9297

98+
.PHONY: clean
99+
clean: clean-obj clean-test clean-cov clean-data
100+
93101

94102
.PHONY: help
95103
help:

test/src/test-errors.c

+38-3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,28 @@ static int test_refract() {
167167
return n;
168168
}
169169

170+
static int test_refract_astro() {
171+
on_surface surf = {};
172+
int n = 0;
173+
174+
if(check_nan("refract_astro:converge", refract_astro(&surf, NOVAS_STANDARD_ATMOSPHERE, 85.0))) {
175+
if(check("refract_astro:converge:errno", ECANCELED, errno)) n++;
176+
}
177+
178+
return n;
179+
}
180+
181+
static int test_inv_refract() {
182+
on_surface surf = {};
183+
int n = 0;
184+
185+
if(check_nan("inv_refract:converge", novas_inv_refract(novas_optical_refraction, NOVAS_JD_J2000, &surf, NOVAS_REFRACT_OBSERVED, 5.0))) {
186+
if(check("inv_refract:converge:errno", ECANCELED, errno)) n++;
187+
}
188+
189+
return n;
190+
}
191+
170192
static int test_limb_angle() {
171193
double pos[3] = { 0.01 }, pn[3] = { -0.01 }, pz[3] = {}, a, b;
172194
int n = 0;
@@ -335,12 +357,16 @@ static int test_radec_planet() {
335357
}
336358

337359
static int test_mean_star() {
338-
double x;
360+
double x, y;
339361
int n = 0;
340362

341-
if(check("mean_star:ira", -1, mean_star(0.0, 0.0, 0.0, NOVAS_FULL_ACCURACY, NULL, &x))) n++;
363+
if(check("mean_star:ira", -1, mean_star(0.0, 0.0, 0.0, NOVAS_FULL_ACCURACY, NULL, &y))) n++;
342364
if(check("mean_star:idec", -1, mean_star(0.0, 0.0, 0.0, NOVAS_FULL_ACCURACY, &x, NULL))) n++;
343365

366+
if(check("mean_star:converge", 1, mean_star(NOVAS_JD_J2000, 0.0, 0.0, NOVAS_REDUCED_ACCURACY, &x, &y))) {
367+
if(check("mean_star:converge:errno", ECANCELED, errno)) n++;
368+
}
369+
344370
return n;
345371
}
346372

@@ -903,6 +929,11 @@ static int test_grav_undo_planets() {
903929
if(check("grav_undo_planets:pl_pos=pl_vel", -1, grav_undo_planets(p, po, NOVAS_REDUCED_ACCURACY, pl_mask, pb, pb, out))) n++;
904930
if(check("grav_undo_planets:pos_src", -1, grav_undo_planets(p, po, NOVAS_REDUCED_ACCURACY, pl_mask, pb, vb, NULL))) n++;
905931

932+
pl_mask = 1 << NOVAS_SUN;
933+
if(check("grav_undo_planets:converge", -1, grav_undo_planets(p, po, NOVAS_REDUCED_ACCURACY, pl_mask, pb, vb, out))) {
934+
if(check("grav_undo_planets:converge:errno", ECANCELED, errno)) n++;
935+
}
936+
906937
return n;
907938
}
908939

@@ -1171,7 +1202,9 @@ static int test_app_to_geom() {
11711202
if(check("app_to_geom:frame:init", -1, novas_app_to_geom(&frame, NOVAS_ICRS, 1.0, 2.0, 10.0, pos))) n++;
11721203

11731204
novas_make_frame(NOVAS_REDUCED_ACCURACY, &obs, &ts, 0.0, 0.0, &frame);
1174-
if(check("app_to_geom:frame:ok", 0, novas_app_to_geom(&frame, NOVAS_ICRS, 1.0, 2.0, 10.0, pos))) n++;
1205+
if(check("app_to_geom:frame:converge", -1, novas_app_to_geom(&frame, NOVAS_ICRS, 1.0, 2.0, 10.0, pos))) {
1206+
if(check("app_to_geom:frame:converge:errno", ECANCELED, errno)) n++;
1207+
}
11751208

11761209
if(check("app_to_geom:pos", -1, novas_app_to_geom(&frame, NOVAS_ICRS, 1.0, 2.0, 10.0, NULL))) n++;
11771210
if(check("app_to_geom:sys:-1", -1, novas_app_to_geom(&frame, -1, 1.0, 2.0, 10.0, pos))) n++;
@@ -1336,6 +1369,8 @@ int main() {
13361369
if(test_transform_hip()) n++;
13371370

13381371
if(test_refract()) n++;
1372+
if(test_refract_astro()) n++;
1373+
if(test_inv_refract()) n++;
13391374
if(test_limb_angle()) n++;
13401375

13411376
if(test_ephemeris()) n++;

0 commit comments

Comments
 (0)