Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

# -*- coding: utf-8 -*- 

 

""" 

chemreac.util.testing 

--------------------- 

Utility module for unit testing of chemreac library. 

""" 

 

from __future__ import (absolute_import, division, 

                        print_function, unicode_literals) 

import numpy as np 

import pytest 

 

from chemreac.util.analysis import solver_linear_error 

 

 

slow = pytest.mark.slow  # call time >~ 100 ms 

veryslow = pytest.mark.veryslow  # call time > a few seconds 

 

 

def check_rd_integration_run(cb, forgiveness=10, **kwargs): 

    """ 

    Tests whether numerical solution is within error-bounds 

    of reference solution. User provided callback "cb" needs 

    to return a tuple of (yout, linCref, rd, info). 

    """ 

    yout, linCref, rd, info = cb(**kwargs) 

    assert info['success'] 

    for i in range(rd.n): 

        try: 

            atol = info['atol'][i] 

        except: 

            atol = info['atol'] 

 

        try: 

            rtol = info['rtol'][i] 

        except: 

            rtol = info['rtol'] 

        lb, ub = solver_linear_error(yout[..., i], rtol, atol, rd.logy, 

                                     scale_err=forgiveness) 

        assert np.all(lb < linCref[..., i]) 

        assert np.all(ub > linCref[..., i]) 

 

 

def spat_ave_rmsd_vs_time(Cout, Cref): 

    """ Spatially averaged root mean square deviation versus time""" 

    if not Cout.shape == Cref.shape: 

        raise ValueError("Incompatible shapes: {}, {}".format( 

            Cout.shape, Cref.shape)) 

    N = Cout.shape[1] 

    err = Cout - Cref 

    return np.sqrt(np.sum(err**2 / N, axis=1))