示例#1
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
示例#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.02, 0.03, 0.08, 0.0, 0.0, 0.02, 0.0],
                [0.003, 0.002, 0.007, 0.01, 0.007, 0.0, 0.005, 0.007],
                [0.003, 0.002, 0.03, 0.04, 0.008, 0.0, 0.002, 0.005]]
    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/sr_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]]
            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
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
示例#4
0
def analyze():
  ksqr = (2.0*np.pi)**2
  # decay rate = (19\nu/4+3\eta+3(\gamma-1)^2*kappa/gamma/4)*(2/15)*k^2
  rate = 2.0*0.04/15.0*ksqr #(4nu/3+(gamma-1)^2/gamma*kappa)*k^2/2 decay rate of sound wave with thermal conduction

  basename='bin/DecayLinWave.block0.out2.'
  nframe = 101
  dumprate = 0.03
  max_vy = np.zeros(nframe)
  tt     = np.zeros(nframe)
  for i in range(nframe):
    x1f,x2f,x3f,data = athena_read.vtk(basename+str(i).zfill(5)+'.vtk')
    max_vy[i] = np.max(data['vel'][...,1])
    tt[i]     = i*dumprate

  # estimate the decay rate from simulation
  new_rate,coeff = np.polyfit(tt,np.log(np.abs(max_vy)),1,w=np.sqrt(np.abs(max_vy)))
  new_rate = -new_rate
  print('[Decaying Linear Wave-3D]: Ref(decay_rate) = {}'.format(rate))
  print('[Decaying Linear Wave-3D]: New(decay_rate) = {}'.format(new_rate))

  flag = True
  error_rel = np.fabs(rate/new_rate-1.0)
  if error_rel > 0.1:
    print('[Decaying Linear Wave-3D]: decay rate is off by 10 percent')
    flag = False
  else:
    print('[Decaying Linear Wave-3D]: decay rate is within 10 percent precision')

  return flag
示例#5
0
def loadData(fname='Unstra.out2.00008.vtk'):
    """load 3d bfield and calc the current density"""
    #data=ath.athdf(fname,quantities=['B1','B2','B3'])
    time, x, y, z, data = ath.vtk(fname)
    bx = data['Bcc'][..., 0]
    by = data['Bcc'][..., 1]
    bz = data['Bcc'][..., 2]

    # ---
    def curl(vx, vy, vz, dx, dy, dz):
        [dzvx, dyvx, dxvx] = np.gradient(vx)
        [dzvy, dyvy, dxvy] = np.gradient(vy)
        [dzvz, dyvz, dxvz] = np.gradient(vz)
        cx = dyvz / dy - dzvy / dz
        cy = dzvx / dz - dxvz / dx
        cz = dxvy / dx - dyvx / dy
        # No need to del the reference by one manually
        # allow python to perform its own garbage collection
        # after the function return cxyz
        #del dzvx
        #del dzvy
        #del dzvz
        return cx, cy, cz

    # ---
    dx = dz = x[1] - x[0]
    dy = y[1] - y[0]
    jx, jy, jz = curl(bx, by, bz, dx, dy, dz)
    j2 = jx**2 + jy**2 + jz**2
    return bx, by, bz, j2
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
示例#7
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
示例#8
0
def aread(filename):
    suffix = filename.split('.')[-1]
    if suffix == 'vtk':
        return ar.vtk(filename)
    if suffix == 'tab':
        return ar.tab(filename)
    if suffix == 'athdf':
        return ar.athdf(filename, subsample=True)
    else:
        print('Error: filetype not supported')
        return
示例#9
0
def analyze():
    analyze_status = True
    # check density max and Vz and Bz components in tab slice
    slice_data = athena_read.tab(
        filename='bin/TestOutputs.block0.out2.00010.tab',
        raw=True,
        dimensions=1)
    if max(slice_data[1, :]) < 0.25:
        analyze_status = False
    if max(slice_data[5, :]) != 0.0:
        analyze_status = False
    if max(slice_data[8, :]) != 0.0:
        analyze_status = False

    # check density max and Vz and Bz components in tab sum
    sum_data = athena_read.tab(
        filename='bin/TestOutputs.block0.out3.00010.tab',
        raw=True,
        dimensions=1)
    if max(sum_data[1, :]) < 15.0 and max(sum_data[:, 1]) > 20.0:
        analyze_status = False
    if max(sum_data[5, :]) != 0.0:
        analyze_status = False
    if max(sum_data[8, :]) != 0.0:
        analyze_status = False

    # assuming domain is 64x64 w/o ghost zones output, slice near central interface x2=0.0
    # check density max and Vz and Bz components in VTK dump
    xf, yf, _, vtk_data = athena_read.vtk(
        filename='bin/TestOutputs.block0.out4.00010.vtk')
    if max(vtk_data['rho'][0, 32, :]) < 0.25:
        analyze_status = False
    if max(vtk_data['vel'][0, 32, :, 2]) != 0.0:
        analyze_status = False
    if max(vtk_data['Bcc'][0, 32, :, 2]) != 0.0:
        analyze_status = False
    # if max(xf) != 0.5 and min(xf) != -0.5:
    #   analyze_status = False
    # if max(yf) != 0.5 and min(yf) != -0.5:
    #  analyze_status = False
    # logger.debug(str(vtk_data['rho'].shape))

    hdf5_data = athena_read.athdf('bin/TestOutputs.out5.00010.athdf',
                                  dtype=np.float32)
    if max(hdf5_data['rho'][0, 32, :]) < 0.25:
        analyze_status = False
    if max(hdf5_data['vel3'][0, 32, :]) != 0.0:
        analyze_status = False
    if max(hdf5_data['Bcc3'][0, 32, :]) != 0.0:
        analyze_status = False

    return analyze_status
示例#10
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
示例#11
0
def vx_amp(targ, ts, te):
    """ read filename.vtk from frame=ts to frame=te """
    """ and plot the vx amplitude over time         """
    nt = te - ts + 1
    time = np.empty([nt])
    vx = np.empty([nt])
    for i in range(te - ts + 1):
        filename = targ + '/sst.block0.out2.' + cn5(ts + i) + '.vtk'
        trunk = ath.vtk(filename)
        time[i] = trunk[0]
        absvx = trunk[4]['vel'][:, :, :, 0]
        vx[i] = np.amax(np.sqrt(np.square(absvx) * trunk[4]['rho']))
    torb = 2.0 * np.pi / 1e-3
    vx = vx * 1e3
    time = time / torb
    print type(vx)
    ascii.write(Table([time, vx], names=['#time(orbits)', '|v_x|(c_s)']),
                targ + '/absvx.tab')
    return
示例#12
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
示例#13
0
def read_all_vtk(fname):
  time,x,y,z,data=ath.vtk(fname)
  bx = data['Bcc'][0,...,0]
#time,data=ath.athdf(fname,quantities=['Bcc2'])
  by = data['Bcc'][0,...,1]
#time,data=ath.athdf(fname,quantities=['Bcc3'])
  bz = data['Bcc'][0,...,2]
#time,data=ath.athdf(fname,quantities=['vel1'])
  vx = data['vel'][0,...,0]
#time,data=ath.athdf(fname,quantities=['vel2'])
  vy = data['vel'][0,...,1]
#time,data=ath.athdf(fname,quantities=['vel3'])
  vz = data['vel'][0,...,2]
  rho = data['rho'][0]
  T = data['press'][0]/rho
  x = (x + 0.5*(x[1]-x[0]))[:-1]
  y = (y + 0.5*(y[1]-y[0]))[:-1]
  if len(z) > 1:
    z = (z + 0.5*(z[1]-z[0]))[:-1]
  else:
    z = z
  return time,x,y,z,rho,T,bx,by,bz,vx,vy,vz
示例#14
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
示例#15
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
示例#16
0
names = glob.glob('*.vtk')
nfiles = len(names)

name = str(names[0])
pos_dot = name.index('.')
name = name[:pos_dot]

data = athena_read.hst("%s.hst" % (name))
times = data['time']
np.savetxt('times', times)
os.system("rm %s.hst" % (name))

filename = "%s.%04i.vtk" % (name, 0)
maxes = {}
x_faces, y_faces, z_faces, data = athena_read.vtk(filename)
for key in data:
    maxes[key] = np.zeros(nfiles)

for n in range(nfiles):
    print("-------", n, "------")
    filename = "%s.%04i.vtk" % (name, n)
    x_faces, y_faces, z_faces, data = athena_read.vtk(filename)

    for key in data:
        array = data[key]
        maxes[key][n] = array[unravel_index(array.argmax(), array.shape)]
    os.system("rm %s" % filename)

    # press = data['Etot']
    # vel   = data['mom']