1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
use {
    crate::{
        constants::*,
        nhswps::{diagnose, psolve, source, Output, State},
        utils::{arr2zero, arr3zero},
    },
    anyhow::Result,
    ndarray::{Axis, Zip},
};

/// Advances fields from time t to t+dt using an iterative implicit
/// method of the form
pub fn advance(state: &mut State, output: &mut Output) -> Result<()> {
    // (F^{n+1}-F^n)/dt = L[(F^{n+1}-F^n)/2] + N[(F^{n+1}-F^n)/2]
    //
    // for a field F, where n refers to the time level, L refers to
    // the linear source terms, and N refers to the nonlinear source
    // terms.  We start with a guess for F^{n+1} in N and iterate
    // niter times (see parameter statement below).

    let ng = state.spectral.ng;
    let nz = state.spectral.nz;
    let dt = 1.0 / (ng as f64);
    let dt4 = dt / 4.0;
    let dt4i = 1.0 / dt4;

    // Local variables
    let niter = 2;

    // Spectral fields needed in time stepping
    let mut qsi = arr3zero(ng, nz);
    let mut qsm = arr3zero(ng, nz);
    let mut sqs = arr3zero(ng, nz);
    let mut sds = arr3zero(ng, nz);
    let mut nds = arr3zero(ng, nz);
    let mut sgs = arr3zero(ng, nz);
    let mut ngs = arr3zero(ng, nz);

    let mut wka = arr2zero(ng);
    let mut wkb = arr2zero(ng);

    // Invert PV and compute velocity at current time level, say t=t^n:
    if state.ggen {
        state.spectral.main_invert(
            state.qs.view(),
            state.ds.view(),
            state.gs.view(),
            state.r.view_mut(),
            state.u.view_mut(),
            state.v.view_mut(),
            state.zeta.view_mut(),
        );
        psolve(state);
    }

    // If ggen is false, main_invert and psolve were called previously
    // at this time level.

    // Save various diagnostics each time step:
    diagnose(state, output)?;

    //Start with a guess for F^{n+1} for all fields:

    //Calculate the source terms (sqs,sds,sgs) for linearised PV (qs),
    //divergence (ds) and acceleration divergence (gs):
    source(state, sqs.view_mut(), sds.view_mut(), sgs.view_mut());

    //Update PV field:
    qsi.assign(&state.qs);

    Zip::from(&mut qsm)
        .and(&state.qs)
        .and(&sqs)
        .apply(|qsm, qs, sqs| *qsm = qs + dt4 * sqs);

    {
        let mut diss_broadcast = state.spectral.diss.broadcast((nz + 1, ng, ng)).unwrap();
        diss_broadcast.swap_axes(0, 2);
        diss_broadcast.swap_axes(0, 1);

        Zip::from(&mut state.qs)
            .and(diss_broadcast)
            .and(&qsm)
            .and(&sqs)
            .and(&qsi)
            .apply(|qs, diss, qsm, sqs, qsi| *qs = diss * (qsm + dt4 * sqs) - qsi);
    }

    // Update divergence and acceleration divergence:
    let dsi = state.ds.clone();
    let gsi = state.gs.clone();

    Zip::from(&mut nds)
        .and(&sds)
        .and(&dsi)
        .apply(|nds, sds, dsi| *nds = sds + dt4i * dsi);
    Zip::from(&mut ngs)
        .and(&sgs)
        .and(&gsi)
        .apply(|ngs, sgs, gsi| *ngs = sgs + dt4i * gsi);

    // 2*N_tilde_delta
    sds += &nds;
    // 2*N_tilde_gamma
    sgs += &ngs;

    wka.fill(0.0);
    wkb.fill(0.0);
    {
        let mut rdis_broadcast = state.spectral.rdis.broadcast((nz + 1, ng, ng)).unwrap();
        rdis_broadcast.swap_axes(0, 2);
        rdis_broadcast.swap_axes(0, 1);

        Zip::from(&mut state.ds)
            .and(&sgs)
            .and(&rdis_broadcast)
            .and(&sds)
            .apply(|ds, sgs, rdis, sds| *ds = sgs + rdis * sds);

        for iz in 0..=nz {
            Zip::from(&mut wka)
                .and(state.ds.index_axis(Axis(2), iz))
                .apply(|wka, ds| *wka += state.spectral.weight[iz] * ds);

            Zip::from(&mut wkb)
                .and(sds.index_axis(Axis(2), iz))
                .apply(|wkb, sds| *wkb += state.spectral.weight[iz] * sds);
        }
    }

    // fope = F operator
    wka *= &state.spectral.fope;
    // c2g2 = c^2*Lap operator
    wkb *= &state.spectral.c2g2;

    for iz in 0..=nz {
        // simp = (R^2 + f^2)^{-1}
        Zip::from(state.ds.index_axis_mut(Axis(2), iz))
            .and(&state.spectral.simp)
            .and(&wka)
            .and(dsi.index_axis(Axis(2), iz))
            .apply(|ds, simp, wka, dsi| *ds = simp * (*ds - wka) - dsi);

        // 2*T_tilde_gamma
        Zip::from(state.gs.index_axis_mut(Axis(2), iz))
            .and(&wkb)
            .and(sds.index_axis(Axis(2), iz))
            .and(&state.spectral.rdis)
            .and(sgs.index_axis(Axis(2), iz))
            .apply(|gs, wkb, sds, rdis, sgs| *gs = wkb - FSQ * sds + rdis * sgs);
    }

    wka.fill(0.0);
    for iz in 0..=nz {
        Zip::from(&mut wka)
            .and(state.gs.index_axis(Axis(2), iz))
            .apply(|wka, gs| *wka += state.spectral.weight[iz] * gs);
    }

    // fope = F operator in paper
    wka *= &state.spectral.fope;

    for iz in 0..=nz {
        // simp = (R^2 + f^2)^{-1}
        Zip::from(state.gs.index_axis_mut(Axis(2), iz))
            .and(&state.spectral.simp)
            .and(&wka)
            .and(gsi.index_axis(Axis(2), iz))
            .apply(|gs, simp, wka, gsi| *gs = simp * (*gs - wka) - gsi);
    }

    // Iterate to improve estimates of F^{n+1}:
    for _ in 0..niter {
        // Perform inversion at t^{n+1} from estimated quantities:
        state.spectral.main_invert(
            state.qs.view(),
            state.ds.view(),
            state.gs.view(),
            state.r.view_mut(),
            state.u.view_mut(),
            state.v.view_mut(),
            state.zeta.view_mut(),
        );

        // Compute pressure, etc:
        psolve(state);

        // Calculate the source terms (sqs,sds,sgs) for linearised PV (qs),
        // divergence (ds) and acceleration divergence (gs):
        source(state, sqs.view_mut(), sds.view_mut(), sgs.view_mut());

        // Update PV field:
        let mut diss_broadcast = state.spectral.diss.broadcast((nz + 1, ng, ng)).unwrap();
        diss_broadcast.swap_axes(0, 2);
        diss_broadcast.swap_axes(0, 1);
        Zip::from(&mut state.qs)
            .and(&diss_broadcast)
            .and(&qsm)
            .and(&sqs)
            .and(&qsi)
            .apply(|qs, diss, qsm, sqs, qsi| *qs = diss * (qsm + dt4 * sqs) - qsi);

        // Update divergence and acceleration divergence:
        // 2*N_tilde_delta
        sds += &nds;
        // 2*N_tilde_gamma
        sgs += &ngs;

        wka.fill(0.0);
        wkb.fill(0.0);

        // 2*T_tilde_delta
        let mut rdis_broadcast = state.spectral.rdis.broadcast((nz + 1, ng, ng)).unwrap();
        rdis_broadcast.swap_axes(0, 2);
        rdis_broadcast.swap_axes(0, 1);
        Zip::from(&mut state.ds)
            .and(&sgs)
            .and(&rdis_broadcast)
            .and(&sds)
            .apply(|ds, sgs, rdis, sds| *ds = sgs + rdis * sds);

        for iz in 0..=nz {
            Zip::from(&mut wka)
                .and(&state.ds.index_axis(Axis(2), iz))
                .apply(|wka, ds| *wka += state.spectral.weight[iz] * ds);
            Zip::from(&mut wkb)
                .and(&sds.index_axis(Axis(2), iz))
                .apply(|wkb, sds| *wkb += state.spectral.weight[iz] * sds);
        }

        // fope = F operator
        wka *= &state.spectral.fope;
        // c2g2 = c^2*Lap operator
        wkb *= &state.spectral.c2g2;

        for iz in 0..=nz {
            // simp = (R^2 + f^2)^{-1}
            Zip::from(&mut state.ds.index_axis_mut(Axis(2), iz))
                .and(&state.spectral.simp)
                .and(&wka)
                .and(&dsi.index_axis(Axis(2), iz))
                .apply(|ds, simp, wka, dsi| *ds = simp * (*ds - wka) - dsi);

            // 2*T_tilde_gamma
            Zip::from(&mut state.gs.index_axis_mut(Axis(2), iz))
                .and(&wkb)
                .and(&sds.index_axis(Axis(2), iz))
                .and(&state.spectral.rdis)
                .and(&sgs.index_axis(Axis(2), iz))
                .apply(|gs, wkb, sds, rdis, sgs| *gs = wkb - FSQ * sds + rdis * sgs);
        }
        wka.fill(0.0);
        for iz in 0..=nz {
            Zip::from(&mut wka)
                .and(&state.gs.index_axis(Axis(2), iz))
                .apply(|wka, gs| *wka += state.spectral.weight[iz] * gs);
        }
        // fope = F operator
        wka *= &state.spectral.fope;

        let mut simp_broadcast = state.spectral.simp.broadcast((nz + 1, ng, ng)).unwrap();
        simp_broadcast.swap_axes(0, 2);
        simp_broadcast.swap_axes(0, 1);
        let mut wka_broadcast = wka.broadcast((nz + 1, ng, ng)).unwrap();
        wka_broadcast.swap_axes(0, 2);
        wka_broadcast.swap_axes(0, 1);

        Zip::from(&mut state.gs)
            .and(simp_broadcast)
            .and(wka_broadcast)
            .and(&gsi)
            .apply(|gs, simp, wka, gsi| *gs = simp * (*gs - wka) - gsi);
    }

    // Advance time:
    state.t += dt;

    Ok(())
}

#[cfg(test)]
mod test {
    use {
        super::*,
        crate::{
            array3_from_file,
            nhswps::{Output, Spectral},
        },
        approx::assert_abs_diff_eq,
        byteorder::ByteOrder,
        lazy_static::lazy_static,
        ndarray::{Array3, ShapeBuilder},
        tempdir::TempDir,
    };

    mod _18_6 {
        use super::*;

        lazy_static! {
            static ref STATE: State = {
                let ng = 18;
                let nz = 6;

                let ri = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/ri.bin");
                let r = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/r.bin");
                let u = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/u.bin");
                let v = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/v.bin");
                let w = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/w.bin");
                let z = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/z.bin");
                let zeta = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/zeta.bin");
                let zx = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/zx.bin");
                let zy = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/zy.bin");
                let ps = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/ps.bin");
                let pn = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/pn.bin");
                let dpn = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/dpn.bin");
                let aa = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/aa.bin");
                let qs = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/qs.bin");
                let ds = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/ds.bin");
                let gs = array3_from_file!(ng, ng, nz + 1, "testdata/advance/18_6/gs.bin");

                let mut state = State {
                    spectral: Spectral::new(ng, nz),
                    u,
                    v,
                    w,
                    z,
                    zx,
                    zy,
                    r,
                    ri,
                    aa,
                    zeta,
                    pn,
                    dpn,
                    ps,
                    qs,
                    ds,
                    gs,
                    t: 5.555_555_555_555_555E-2,
                    ngsave: 5,
                    itime: 1,
                    jtime: 0,
                    ggen: true,
                };
                let td = TempDir::new("advance").unwrap();
                advance(&mut state, &mut Output::from_path(td.path()).unwrap()).unwrap();
                state
            };
        }
        #[test]
        fn r() {
            let r2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/r2.bin");
            assert_abs_diff_eq!(&r2, &STATE.r, epsilon = 1.0E-10);
        }

        #[test]
        fn ri() {
            let ri2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/ri2.bin");
            assert_abs_diff_eq!(&ri2, &STATE.ri, epsilon = 1.0E-10);
        }

        #[test]
        fn u() {
            let u2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/u2.bin");
            assert_abs_diff_eq!(&u2, &STATE.u, epsilon = 1.0E-10);
        }

        #[test]
        fn v() {
            let v2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/v2.bin");
            assert_abs_diff_eq!(&v2, &STATE.v, epsilon = 1.0E-10);
        }

        #[test]
        fn w() {
            let w2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/w2.bin");
            assert_abs_diff_eq!(&w2, &STATE.w, epsilon = 1.0E-10);
        }
        #[test]
        fn z() {
            let z2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/z2.bin");
            assert_abs_diff_eq!(&z2, &STATE.z, epsilon = 1.0E-10);
        }

        #[test]
        fn zeta() {
            let zeta2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/zeta2.bin");
            assert_abs_diff_eq!(&zeta2, &STATE.zeta, epsilon = 1.0E-10);
        }

        #[test]
        fn zx() {
            let zx2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/zx2.bin");
            assert_abs_diff_eq!(&zx2, &STATE.zx, epsilon = 1.0E-10);
        }

        #[test]
        fn zy() {
            let zy2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/zy2.bin");
            assert_abs_diff_eq!(&zy2, &STATE.zy, epsilon = 1.0E-10);
        }

        #[test]
        fn ps() {
            let ps2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/ps2.bin");
            assert_abs_diff_eq!(&ps2, &STATE.ps, epsilon = 1.0E-10);
        }

        #[test]
        fn pn() {
            let pn2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/pn2.bin");
            assert_abs_diff_eq!(&pn2, &STATE.pn, epsilon = 1.0E-10);
        }

        #[test]
        fn dpn() {
            let dpn2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/dpn2.bin");
            assert_abs_diff_eq!(&dpn2, &STATE.dpn, epsilon = 1.0E-10);
        }

        #[test]
        fn aa() {
            let aa2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/aa2.bin");
            assert_abs_diff_eq!(&aa2, &STATE.aa, epsilon = 1.0E-10);
        }

        #[test]
        fn qs() {
            let qs2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/qs2.bin");
            assert_abs_diff_eq!(&qs2, &STATE.qs, epsilon = 1.0E-10);
        }

        #[test]
        fn ds() {
            let ds2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/ds2.bin");
            assert_abs_diff_eq!(&ds2, &STATE.ds, epsilon = 1.0E-10);
        }

        #[test]
        fn gs() {
            let gs2 = array3_from_file!(18, 18, 7, "testdata/advance/18_6/gs2.bin");
            assert_abs_diff_eq!(&gs2, &STATE.gs, epsilon = 1.0E-10);
        }

        #[test]
        fn t() {
            assert_abs_diff_eq!(0.111_111_111_111_111_1, STATE.t, epsilon = 1.0E-10);
        }
    }

    mod _24_4 {
        use super::*;

        lazy_static! {
            static ref STATE: State = {
                let ng = 24;
                let nz = 4;

                let ri = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/ri.bin");
                let r = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/r.bin");
                let u = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/u.bin");
                let v = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/v.bin");
                let w = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/w.bin");
                let z = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/z.bin");
                let zeta = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/zeta.bin");
                let zx = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/zx.bin");
                let zy = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/zy.bin");
                let ps = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/ps.bin");
                let pn = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/pn.bin");
                let dpn = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/dpn.bin");
                let aa = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/aa.bin");
                let qs = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/qs.bin");
                let ds = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/ds.bin");
                let gs = array3_from_file!(ng, ng, nz + 1, "testdata/advance/24_4/gs.bin");

                let mut state = State {
                    spectral: Spectral::new(ng, nz),
                    u,
                    v,
                    w,
                    z,
                    zx,
                    zy,
                    r,
                    ri,
                    aa,
                    zeta,
                    pn,
                    dpn,
                    ps,
                    qs,
                    ds,
                    gs,
                    t: 0.624_999_999_999_999_9,
                    ngsave: 6,
                    itime: 15,
                    jtime: 2,
                    ggen: true,
                };
                let td = TempDir::new("advance").unwrap();
                advance(&mut state, &mut Output::from_path(td.path()).unwrap()).unwrap();
                state
            };
        }

        #[test]
        fn r() {
            let r2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/r2.bin");
            assert_abs_diff_eq!(&r2, &STATE.r, epsilon = 1.0E-10);
        }

        #[test]
        fn ri() {
            let ri2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/ri2.bin");
            assert_abs_diff_eq!(&ri2, &STATE.ri, epsilon = 1.0E-10);
        }

        #[test]
        fn u() {
            let u2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/u2.bin");
            assert_abs_diff_eq!(&u2, &STATE.u, epsilon = 1.0E-10);
        }

        #[test]
        fn v() {
            let v2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/v2.bin");
            assert_abs_diff_eq!(&v2, &STATE.v, epsilon = 1.0E-10);
        }

        #[test]
        fn w() {
            let w2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/w2.bin");
            assert_abs_diff_eq!(&w2, &STATE.w, epsilon = 1.0E-10);
        }
        #[test]
        fn z() {
            let z2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/z2.bin");
            assert_abs_diff_eq!(&z2, &STATE.z, epsilon = 1.0E-10);
        }

        #[test]
        fn zeta() {
            let zeta2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/zeta2.bin");
            assert_abs_diff_eq!(&zeta2, &STATE.zeta, epsilon = 1.0E-10);
        }

        #[test]
        fn zx() {
            let zx2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/zx2.bin");
            assert_abs_diff_eq!(&zx2, &STATE.zx, epsilon = 1.0E-10);
        }

        #[test]
        fn zy() {
            let zy2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/zy2.bin");
            assert_abs_diff_eq!(&zy2, &STATE.zy, epsilon = 1.0E-10);
        }

        #[test]
        fn ps() {
            let ps2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/ps2.bin");
            assert_abs_diff_eq!(&ps2, &STATE.ps, epsilon = 1.0E-10);
        }

        #[test]
        fn pn() {
            let pn2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/pn2.bin");
            assert_abs_diff_eq!(&pn2, &STATE.pn, epsilon = 1.0E-10);
        }

        #[test]
        fn dpn() {
            let dpn2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/dpn2.bin");
            assert_abs_diff_eq!(&dpn2, &STATE.dpn, epsilon = 1.0E-10);
        }

        #[test]
        fn aa() {
            let aa2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/aa2.bin");
            assert_abs_diff_eq!(&aa2, &STATE.aa, epsilon = 1.0E-10);
        }

        #[test]
        fn qs() {
            let qs2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/qs2.bin");
            assert_abs_diff_eq!(&qs2, &STATE.qs, epsilon = 1.0E-10);
        }

        #[test]
        fn ds() {
            let ds2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/ds2.bin");
            assert_abs_diff_eq!(&ds2, &STATE.ds, epsilon = 1.0E-10);
        }

        #[test]
        fn gs() {
            let gs2 = array3_from_file!(24, 24, 5, "testdata/advance/24_4/gs2.bin");
            assert_abs_diff_eq!(&gs2, &STATE.gs, epsilon = 1.0E-10);
        }
    }
}