コード例 #1
0
def analyze():
    analyze_status = True
    for i, g in enumerate(_gammas):
        for t in [10, 25]:
            x_ref, _, _, data_ref = athena_read.vtk(
                'bin/Sod_ideal_{0:}.block0.out1.{1:05d}.vtk'.format(i, t))
            x_new, _, _, data_new = athena_read.vtk(
                'bin/Sod_eos_hllc_{0:}.block0.out1.{1:05d}.vtk'.format(i, t))
            x_ascii, _, _, data_ascii = athena_read.vtk(
                'bin/Sod_eos_hllc_ascii_{0:}.block0.out1.{1:05d}.vtk'.format(
                    i, t))
            loc = tuple([0, 0, slice(None)])
            for var in ['rho', 'press']:
                norm = comparison.l1_norm(x_ref, data_ref[var][loc])
                diff = comparison.l1_diff(x_ref, data_ref[var][loc], x_new,
                                          data_new[var][loc]) / norm
                if diff > 0.0 or np.isnan(diff):
                    line = [
                        'Eos ideal table test fail (binary). var, err, gamma =',
                        var, diff, g
                    ]
                    print(' '.join(map(str, line)))
                    analyze_status = False
                diff = comparison.l1_diff(x_ref, data_ref[var][loc], x_ascii,
                                          data_ascii[var][loc]) / norm
                if diff > 1e-6 or np.isnan(diff):
                    line = [
                        'Eos ideal table test fail (ascii). var, err, gamma =',
                        var, diff, g
                    ]
                    print(' '.join(map(str, line)))
                    analyze_status = False
    tol = .004
    for t in [10, 25]:
        x_ref, _, _, data_ref = athena_read.vtk(
            'bin/Sod_eos_H.block0.out1.{1:05d}.vtk'.format(i, t))
        x_new, _, _, data_new = athena_read.vtk(
            'bin/Sod_eos_H_binary.block0.out1.{1:05d}.vtk'.format(i, t))
        x_ascii, _, _, data_ascii = athena_read.vtk(
            'bin/Sod_eos_H_ascii.block0.out1.{1:05d}.vtk'.format(i, t))
        loc = tuple([0, 0, slice(None)])
        for var in ['rho', 'press']:
            norm = comparison.l1_norm(x_ref, data_ref[var][loc])
            diff = comparison.l1_diff(x_ref, data_ref[var][loc], x_new,
                                      data_new[var][loc]) / norm
            if diff > tol or np.isnan(diff):
                line = [
                    'Eos H table test fail (binary). var, err =', var, diff
                ]
                print(' '.join(map(str, line)))
                analyze_status = False
            diff = comparison.l1_diff(x_ref, data_ref[var][loc], x_ascii,
                                      data_ascii[var][loc]) / norm
            if diff > tol or np.isnan(diff):
                line = ['Eos H table test fail (ascii). var, err =', var, diff]
                print(' '.join(map(str, line)))
                analyze_status = False

    return analyze_status
コード例 #2
0
def analyze():
    analyze_status = True
    headers_ref = [('dens',), ('Etot',), ('mom', 0), ('mom', 1), ('mom', 2), ('cc-B', 0),
                   ('cc-B', 1), ('cc-B', 2)]
    headers_new = [('dens',), ('Etot',), ('mom', 0), ('mom', 1), ('mom', 2), ('Bcc', 0),
                   ('Bcc', 1), ('Bcc', 2)]
    tol_sets = [[0.02,  0.01,  0.02,  0.04, 0.0,   0.0, 0.01,  0.0],
                [0.003, 0.002, 0.007, 0.01, 0.005, 0.0, 0.004, 0.007],
                [0.002, 0.001, 0.02,  0.03, 0.004, 0.0, 0.001, 0.003]]
    for i, tols in zip([1, 2, 4], tol_sets):
        x_ref, _, _, data_ref = athena_read.vtk('data/sr_mhd_shock{0}_hlld.vtk'.format(i))
        x_new, _, _, data_new = \
            athena_read.vtk('bin/gr_mhd_shock{0}.block0.out1.00001.vtk'.format(i))
        for header_ref, header_new, tol in zip(headers_ref, headers_new, tols):
            array_ref = data_ref[header_ref[0]]
            if len(header_ref) == 1:
                array_ref = array_ref[0, 0, :]
            else:
                array_ref = array_ref[0, 0, :, header_ref[1]]
            array_new = data_new[header_new[0]]
            if len(header_new) == 1:
                array_new = array_new[0, 0, :]
            else:
                array_new = array_new[0, 0, :, header_new[1]]
            if header_new[0] == 'Etot':
                array_new = -array_new   # sign difference between SR and GR
            eps = comparison.l1_diff(x_ref, array_ref, x_new, array_new)
            if tol == 0.0:
                if eps > 0.0:
                    analyze_status = False
            else:
                eps /= comparison.l1_norm(x_ref, array_ref)
                if eps > tol or np.isnan(eps):
                    analyze_status = False
    return analyze_status
コード例 #3
0
def analyze():
    analyze_status = True
    headers = [('dens', ), ('Etot', ), ('mom', 0)]
    tols = [[0.02, 0.01, 0.01], [0.01, 0.01, 0.02], [0.01, 0.01, 0.02],
            [0.5, 0.01, 0.02]]
    for i in range(1, 5):
        x_ref, _, _, data_ref = athena_read.vtk(
            'data/sr_hydro_shock{0}_hllc.vtk'.format(i))
        x_new, _, _, data_new = \
            athena_read.vtk('bin/gr_hydro_shock{0}.block0.out1.00001.vtk'.format(i))
        tols_particular = tols[i - 1]
        for header, tol in zip(headers, tols_particular):
            array_ref = data_ref[header[0]]
            array_ref = array_ref[0, 0, :] if len(header) == 1 else array_ref[
                0, 0, :, header[1]]
            array_new = data_new[header[0]]
            array_new = array_new[0, 0, :] if len(header) == 1 else array_new[
                0, 0, :, header[1]]
            if header[0] == 'Etot':
                array_new = -array_new  # sign difference between SR and GR
            eps = comparison.l1_diff(x_ref, array_ref, x_new, array_new)
            eps /= comparison.l1_norm(x_ref, array_ref)
            if eps > tol or np.isnan(eps):
                analyze_status = False
    return analyze_status
コード例 #4
0
def analyze():
    analyze_status = True
    for flux in _fluxes:
        for n, state in enumerate(_states):
            # the double shock tests are too hard for hlle
            t = 1
            fn = 'bin/eos_riemann_{0:}_{1:02d}.block0.out1.{2:05d}.vtk'
            x_ref, _, _, data_ref = athena_read.vtk(fn.format(flux, n, t))
            xi = (.5 * x_ref[:-1] + .5 * x_ref[1:]) / _tests[n]['time/tlim']
            exact = riemann_problem(state, 'H').data_array(xi)
            for var in ['rho', 'press', 'vel']:
                data = data_ref[var][0, 0, :]
                if var == 'vel':
                    data = data_ref[var][0, 0, :, 0]
                diff = comparison.l1_norm(x_ref, data - exact[var])
                msg = 'Test#, var, diff, thresh = ' + '{:d}, {:>5}' + ', {:.03e}' * 2
                msg = msg.format(n + 1, var, diff, _thresh[n][var])
                msg = ['EOS Riemann ({0:})'.format(flux), 'FAIL:', msg]
                if diff > _thresh[n][var]:
                    logger.warning(' '.join(msg))
                    analyze_status = False
                else:
                    msg[1] = 'pass:'******' '.join(msg))
    return analyze_status
コード例 #5
0
def analyze():
    analyze_status = True
    for n, state in enumerate(_mhd_states):
        t = 1
        x_ref, _, _, data_ref = athena_read.vtk(
            'bin/eos_mhd_{0:02d}.block0.out1.{1:05d}.vtk'.format(n, t))
        xi = (.5 * x_ref[:-1] + .5 * x_ref[1:]) / _mhd_tests[n]['time/tlim']
        exact = riemann_problem(state, 'H').data_array(xi)
        for var in ['rho', 'press', 'vel']:
            data = data_ref[var][0, 0, :]
            if var == 'vel':
                data = data_ref[var][0, 0, :, 0]
            diff = comparison.l1_norm(x_ref, data - exact[var])
            msg = ['EOS MHD Riemann', 'fail:', 'Test#, var, diff, thresh =', n, var, diff,
                   _mhd_thresh[n][var]]
            if diff > _mhd_thresh[n][var]:
                logger.warning(' '.join(map(str, msg)))
                analyze_status = False
            else:
                msg[1] = 'pass:'******' '.join(map(str, msg)))
    # test hydrogen version of RJ2a
    x_ref, _, _, data = athena_read.vtk('bin/RJ2a.block0.out1.00040.vtk')
    xc = (x_ref[1:] + x_ref[:-1]) * .5
    j = 0
    t = 0.2
    # construct H-RJ2a solution array
    data_ref = np.empty((7, xc.size))
    for i, x in enumerate(xc):
        try:
            while x / t > wave_speeds[j]:
                j += 1
        except IndexError:
            pass
        data_ref[:, i] = eos_rj2a[j]
    # compute errors
    errors = [comparison.l1_norm(x_ref, data['rho'][0, 0] - data_ref[0]),
              comparison.l1_norm(x_ref, data['vel'][0, 0, :, 0] - data_ref[1]),
              comparison.l1_norm(x_ref, data['vel'][0, 0, :, 1] - data_ref[2]),
              comparison.l1_norm(x_ref, data['vel'][0, 0, :, 2] - data_ref[3]),
              comparison.l1_norm(x_ref, data['Bcc'][0, 0, :, 1] - data_ref[4]),
              comparison.l1_norm(x_ref, data['Bcc'][0, 0, :, 2] - data_ref[5]),
              comparison.l1_norm(x_ref, data['press'][0, 0] - data_ref[6])]
    names = ["rho", "vx", "vy", "vz", "By", "Bz", "p"]
    threshes = [7e-3] + [5e-3] * 3 + [7e-3] * 3
    # check errors
    for err, name, thresh in zip(errors, names, threshes):
        msg = ['EOS RJ2a', 'fail:', 'var, diff, thresh =', name, err, thresh]
        if err > thresh:
            logger.warning(' '.join(map(str, msg)))
            analyze_status = False
        else:
            msg[1] = 'pass:'******' '.join(map(str, msg)))
    return analyze_status
コード例 #6
0
def analyze():
    analyze_status = True
    for i, g in enumerate(_gammas):
        for t in [10, 25]:
            x_ref, _, _, data_ref = athena_read.vtk(
                'bin/Sod_ideal_{0:}.block0.out1.{1:05d}.vtk'.format(i, t))
            x_new, _, _, data_new = athena_read.vtk(
                'bin/Sod_eos_hllc_hdf5_{0:}.block0.out1.{1:05d}.vtk'.format(
                    i, t))
            loc = tuple([0, 0, slice(None)])
            for var in ['rho', 'press']:
                diff = comparison.l1_diff(x_ref, data_ref[var][loc], x_new,
                                          data_new[var][loc])
                diff /= comparison.l1_norm(x_ref, data_ref[var][loc])
                msg = [
                    'Eos hdf5 table', 'failed.', 'var, diff, gamma =', var,
                    diff, g
                ]
                if diff > 1e-8 or np.isnan(diff):
                    logger.warning(' '.join(map(str, msg)))
                    analyze_status = False
                else:
                    msg[1] = 'passed.'
                    logger.debug(' '.join(map(str, msg)))

    tol = [3e-3, 7e-4]
    for i, t in enumerate([10, 25]):
        x_ref, _, _, data_ref = athena_read.vtk(
            'bin/Sod_eos_H.block0.out1.{:05d}.vtk'.format(t))
        x_new, _, _, data_new = athena_read.vtk(
            'bin/Sod_eos_H_hdf5.block0.out1.{:05d}.vtk'.format(t))
        loc = tuple([0, 0, slice(None)])
        for var in ['rho', 'press']:
            norm = comparison.l1_norm(x_ref, data_ref[var][loc])
            diff = comparison.l1_diff(x_ref, data_ref[var][loc], x_new,
                                      data_new[var][loc]) / norm
            msg = ['Eos H table test', 'failed.', 'var, err =', var, diff]
            if diff > tol[i] or np.isnan(diff):
                logger.warning(' '.join(map(str, msg)))
                analyze_status = False
            else:
                msg[1] = 'passed.'
                logger.debug(' '.join(map(str, msg)))

    return analyze_status
コード例 #7
0
def analyze():
    analyze_status = True
    for n, state in enumerate(_states):
        t = 1
        x_ref, _, _, data_ref = athena_read.vtk(
            'bin/eos_riemann_{0:02d}.block0.out1.{1:05d}.vtk'.format(n, t))
        xi = (.5 * x_ref[:-1] + .5 * x_ref[1:]) / _tests[n]['time/tlim']
        exact = riemann_problem(state, 'H').data_array(xi)
        for var in ['rho', 'press', 'vel']:
            data = data_ref[var][0, 0, :]
            if var == 'vel':
                data = data_ref[var][0, 0, :, 0]
            diff = comparison.l1_norm(x_ref, data - exact[var])
            msg = ['EOS Riemann', 'fail:', 'Test#, var, diff, thresh =', n, var, diff,
                   _thresh[n][var]]
            if diff > _thresh[n][var]:
                logger.warning(' '.join(map(str, msg)))
                analyze_status = False
            else:
                msg[1] = 'pass:'******' '.join(map(str, msg)))
    return analyze_status
コード例 #8
0
def analyze():
    """
  Analyze the output and determine if the test passes.

  This function is called third; nothing from this file is called after it. It is
  responsible for reading whatever data it needs and making a judgment about whether or
  not the test passes. It takes no inputs. Output should be True (test passes) or False
  (test fails).
  """

    # Read in reference data. The tst/regression/data/ directory has reference runs for
    # comparing future output of the code. We only need to specify file names starting
    # with "data/". Now athena_read.vtk() returns four objects: the x-interface locations,
    # the y-interface locations, the z-interface locations, and the values of the
    # variables themselves. In a 1D problem we ignore the second and third returned
    # values, assigning them to the _ variable as is typical Python style.
    x_ref, _, _, data_ref = athena_read.vtk('data/sr_hydro_shock1_hlle.vtk')

    # Read in the data produced during this test. This will usually be stored in the
    # tst/regression/bin/ directory, but again we omit the first part of the path. Note
    # the file name is what we expect based on the job/problem_id field supplied in run().
    x_new, _, _, data_new = athena_read.vtk(
        'bin/gr_shock_tube.block0.out1.00001.vtk')

    # Extract the quantities of interest. Suppose we want to check that the total energy
    # and the x-momentum are the same as those given in the reference dataset. The fourth
    # object returned by athena_read.vtk() is a dictionary of 3D (scalars) or 4D (vectors)
    # NumPy arrays, whose keys ('Etot' and 'mom' in this case) are exactly the names of
    # the arrays as stored in the vtk file. Here we extract the reference values, where
    # the fourth index specifies which component of the vector quantity to extract. The
    # choice of slicing will give us 1D arrays without any singleton dimensions.
    e_ref = data_ref['Etot'][0, 0, :]
    mx_ref = data_ref['mom'][0, 0, :, 0]

    # Similarly, we extract the newly created values.
    e_new = -data_new['Etot'][0,
                              0, :]  # sign flip between SR and GR definitions
    mx_new = data_new['mom'][0, 0, :, 0]

    # Next we compute the differences between the reference arrays and the newly created
    # ones in the L^1 sense. That is, given functions f and g, we want
    #     \int |f(x)-g(x)| dx.
    # The utility script comparison.l1_diff() does this exactly, conveniently taking N+1
    # interface locations and N volume-averaged quantities. The two datasets can have
    # different values of N.
    error_abs_e = comparison.l1_diff(x_ref, e_ref, x_new, e_new)
    error_abs_mx = comparison.l1_diff(x_ref, mx_ref, x_new, mx_new)

    # The errors are more meaningful if we account for the length of the domain and the
    # typical magnitude of the function itself. Fortunately, comparison.l1_norm() computes
    #     \int |f(x)| dx.
    # (Note neither comparison.l1_diff() nor comparison.l1_norm() divides by the length of
    # the domain.)
    error_rel_e = error_abs_e / comparison.l1_norm(x_ref, e_ref)
    error_rel_mx = error_abs_mx / comparison.l1_norm(x_ref, mx_ref)

    # Finally, we test that the relative errors in the two quantities are no more than 1%.
    # If they are, we return False; otherwise we return True. NumPy provides a way of
    # checking if the error is NaN, which also indicates something went wrong. The main
    # test script will record the result and delete tst/regression/bin/ before proceeding
    # on to the next test.
    if error_rel_e > 0.01 or np.isnan(error_rel_e):
        return False
    if error_rel_mx > 0.01 or np.isnan(error_rel_mx):
        return False
    return True
コード例 #9
0
def analyze():
    analyze_status = True
    lbls = ['ideal', 'binary', 'ascii']
    ids = ['ideal', 'eos_hllc', 'eos_hllc_ascii']
    id = 'bin/Sod_{0:}_{1:}.block0.out1.{2:05d}.vtk'
    tolerances = [0.0, 0.0, 1e-6]
    for i, g in enumerate(_gammas):
        for t in [10, 25]:
            x_ref, _, _, data_ref = athena_read.vtk(
                id.format('adiabatic', i, t))
            loc = tuple([0, 0, slice(None)])
            for var in ['rho', 'press']:
                for j in range(len(lbls)):
                    x_new, _, _, data_new = athena_read.vtk(
                        id.format(ids[j], i, t))
                    norm = comparison.l1_norm(x_ref, data_ref[var][loc])
                    diff = comparison.l1_diff(x_ref, data_ref[var][loc], x_new,
                                              data_new[var][loc]) / norm
                    msg = '({0:}). var, err, gamma ='.format(lbls[j])
                    if diff > tolerances[j] or np.isnan(diff):
                        line = 'Eos ideal table test fail '
                        logger.warning(' '.join(
                            map(str, [line, msg, var, diff, g])))
                        analyze_status = False
                    else:
                        line = 'Eos ideal table test pass '
                        logger.debug(' '.join(
                            map(str, [line, msg, var, diff, g])))

    tol = .004
    for t in [10, 25]:
        x_ref, _, _, data_ref = athena_read.vtk(
            'bin/Sod_eos_H.block0.out1.{:05d}.vtk'.format(t))
        x_new, _, _, data_new = athena_read.vtk(
            'bin/Sod_eos_H_binary.block0.out1.{:05d}.vtk'.format(t))
        x_ascii, _, _, data_ascii = athena_read.vtk(
            'bin/Sod_eos_H_ascii.block0.out1.{:05d}.vtk'.format(t))
        loc = tuple([0, 0, slice(None)])
        for var in ['rho', 'press']:
            norm = comparison.l1_norm(x_ref, data_ref[var][loc])
            diff = comparison.l1_diff(x_ref, data_ref[var][loc], x_new,
                                      data_new[var][loc]) / norm
            msg = [
                'Eos H table test', 'fail', '(binary). var, err =', var, diff
            ]
            if diff > tol or np.isnan(diff):
                logger.warning(' '.join(map(str, msg)))
                analyze_status = False
            else:
                msg[1] = 'pass'
                logger.debug(' '.join(map(str, msg)))

            diff = comparison.l1_diff(x_ref, data_ref[var][loc], x_ascii,
                                      data_ascii[var][loc]) / norm
            msg = [
                'Eos H table test', 'fail', '(ascii). var, err =', var, diff
            ]
            if diff > tol or np.isnan(diff):
                logger.warning(' '.join(map(str, msg)))
                analyze_status = False
            else:
                msg[1] = 'pass'
                logger.debug(' '.join(map(str, msg)))

    return analyze_status