示例#1
0
def test_latitude():
    tol = 1e-5
    lt = np.linspace(start=0, stop=24, num=2, endpoint=False)
    ds1 = ds.driftShell(local_times=lt,
                        start_line=[6.6, 0.0, 0.0],
                        K=0,
                        mode='analytic_K',
                        error_tol=tol)

    phi = ds1.get_phi_locations()
    RE = []
    for key in phi:
        RE = ih.mag(phi[key])
        lat = ih.rad_to_deg(ih.get_lat(phi[key]))
        print "RE: {}".format(RE)
        print "lat: {}".format(lat)
示例#2
0
def test_lt_boundary(count=3):
    tol = 1e-5
    x0 = [6.6, 0.0, 0.0]
    k = 0.0
    divs = 600

    data = {}
    local_times = []
    for rounds in range(count):
        lts = np.linspace(start=0, stop=24, num=(4 + rounds), endpoint=False)
        local_times.append(lts)

    for lt in local_times:
        ds1 = ds.driftShell(local_times=lt,
                            start_line=x0,
                            K=k,
                            mode='analytic_K',
                            error_tol=tol)
        data[len(lt)] = ds1.calculate_L_star(lat_divs=divs, lon_divs=divs)

    X, Y = ih.dict_to_x_y(data)
    Y2 = (np.array(Y) - 6.6) / 6.6 * 100

    fig1 = plt.figure(1)
    ax1 = fig1.add_subplot(111)
    ax2 = fig1.add_subplot(111, sharex=ax1, frameon=False)
    ax1.set_title("Number of Field Lines vs. % Error")

    ax1.set_ylabel("$L^*$")
    ax1.set_xlabel("Number of Field Lines to Define Polar Cap")
    line1, = ax1.plot(X, Y, 'ko-', label="$L^*$")

    ax2.set_ylabel("% Error")
    ax2.yaxis.tick_right()
    ax2.yaxis.set_label_position("right")
    ax2.set_ylabel("% Error")
    line2, = ax2.plot(X, Y2, 'rx-', label="% Error")

    plt.legend(handles=[line1, line2], loc=3)
    plt.tight_layout()
    plt.savefig("out/error_analysis/error_local_time_base_4_lines.pdf")
示例#3
0
def test_error_tol(count=3):
    divs = 600
    x0 = [6.6, 0.0, 0.0]
    k = 0.0
    lt = [0, 6, 12, 18]
    tols = np.logspace(start=-7.0, stop=0.0, num=count)
    tols = tols[::-1]
    data = {}
    for tol in tols:
        print "Processing Tolerance: {}".format(tol)
        ds1 = ds.driftShell(local_times=lt,
                            start_line=x0,
                            K=k,
                            mode='analytic_K',
                            error_tol=tol)
        l = ds1.calculate_L_star(RE=1.0, lat_divs=divs, lon_divs=divs)
        data[tol] = l

    X, Y = ih.dict_to_x_y(data)
    Y2 = (np.array(Y) - 6.6) / 6.6 * 100

    fig1 = plt.figure(1)
    ax1 = fig1.add_subplot(111)
    ax2 = fig1.add_subplot(111, sharex=ax1, frameon=False)
    ax1.set_title("Error Tolerance vs. L* and % Error")

    ax1.set_ylabel("$L^*$")
    ax1.set_xlabel("Error Tolerance")
    line1, = ax1.semilogx(X, Y, 'ko-', label="$L^*$")

    ax2.set_ylabel("% Error")
    ax2.yaxis.tick_right()
    ax2.yaxis.set_label_position("right")
    ax2.set_ylabel("% Error")
    line2, = ax2.semilogx(X, Y2, 'rx-', label="% Error")

    plt.legend(handles=[line1, line2], loc=1)
    plt.tight_layout()
    plt.savefig("out/error_analysis/error_tol_6.6RE_4_lines.pdf")
示例#4
0
def test_flux_grid(count=3):
    divlist = np.linspace(start=10, stop=800, num=count, dtype=np.int)
    k = 0.0
    lt = [0, 6, 12, 18]
    tol = 1e-5
    x0 = [6.6, 0.0, 0.0]
    ds1 = ds.driftShell(local_times=lt,
                        start_line=x0,
                        K=k,
                        mode='analytic_K',
                        error_tol=tol)
    data = {}
    for divs in divlist:
        l = ds1.calculate_L_star(RE=1.0, lat_divs=divs, lon_divs=divs)
        data[divs] = l
        print "L*({}): {}".format(divs, l)

    X, Y = ih.dict_to_x_y(data)
    Y2 = np.abs((np.array(Y) - 6.6)) / 6.6 * 100

    fig1 = plt.figure(1)
    ax1 = fig1.add_subplot(111)
    ax2 = fig1.add_subplot(111, sharex=ax1, frameon=False)
    ax1.set_title("Flux Integration Grid vs. % Error\nfor 6.6 $R_E$")

    ax1.set_ylabel("$L^*$")
    ax1.set_xlabel("Flux Grid Size (n x n)")
    line1, = ax1.plot(X, Y, 'ko-', label="$L^*$")

    ax2.set_ylabel("% Error")
    ax2.yaxis.tick_right()
    ax2.yaxis.set_label_position("right")
    ax2.set_ylabel("% Error")
    line2, = ax2.semilogy(X, Y2, 'rx-', label="% Error")

    plt.legend(handles=[line1, line2], loc=4)
    plt.tight_layout()
    plt.savefig("out/error_analysis/error_Flux_grid_base_4_lines.pdf")
示例#5
0
def test_RE_based(count=3):
    dist = np.linspace(start=2, stop=8, num=count)
    divs = 600
    k = 0.0
    lt = [0, 6, 12, 18]
    tol = 1e-5

    data = {}
    for x0 in dist:
        ds1 = ds.driftShell(local_times=lt,
                            start_line=[x0, 0.0, 0.0],
                            K=k,
                            mode='analytic_K',
                            error_tol=tol)
        data[x0] = ds1.calculate_L_star(lat_divs=divs, lon_divs=divs)

    X, Y = ih.dict_to_x_y(data)
    Y2 = (np.array(Y) - np.array(X)) / np.array(X) * 100

    fig1 = plt.figure(1)
    ax1 = fig1.add_subplot(111)
    ax2 = fig1.add_subplot(111, sharex=ax1, frameon=False)
    ax1.set_title("Starting Distance vs. % Error")

    ax1.set_ylabel("$L^*$")
    ax1.set_xlabel("Starting Distance ($R_E$)")
    line1, = ax1.plot(X, Y, 'ko-', label="$L^*$")

    ax2.set_ylabel("% Error")
    ax2.yaxis.tick_right()
    ax2.yaxis.set_label_position("right")
    ax2.set_ylabel("% Error")
    line2, = ax2.plot(X, Y2, 'rx-', label="% Error")

    plt.legend(handles=[line1, line2], loc=2)
    plt.tight_layout()
    plt.savefig("out/error_analysis/error_RE_base_4_lines.pdf")
示例#6
0
x_f = [a[0] for a in fl1.fieldLinePoints_f]
y_f = [a[1] for a in fl1.fieldLinePoints_f]
z_f = [a[2] for a in fl1.fieldLinePoints_f]

x_b = [a[0] for a in fl1.fieldLinePoints_b]
y_b = [a[1] for a in fl1.fieldLinePoints_b]
z_b = [a[2] for a in fl1.fieldLinePoints_b]

print "B(K=0): {} nT".format(fl1.get_B_mirror_for_K(K=0))

divs = 1000
calcTimes = np.linspace(0, 24, num=4, endpoint=False)

ds1 = ds.driftShell(local_times=calcTimes,
                    start_line=[2.5, 0.0, 0.0],
                    K=0,
                    mode='analytic_K')
ideal_RE = ih.mag(ds1.field_lines[0].fieldLinePoints_f[0])
print "Ideal L*: {}".format(ideal_RE)

test_grids = np.arange(start=100, stop=100, step=50, dtype=np.int)
L_star = ds1.calculate_L_star(RE=1.0, lat_divs=divs, lon_divs=divs)
diff = ideal_RE - L_star
error = np.abs(diff / ideal_RE * 100)

print "L*: {}".format(L_star)
print "diff: {}".format(diff)
print "% Error: {}".format(error)

# mlab.plot3d(x_f, y_f, z_f)
# mlab.plot3d(x_b, y_b, z_b)
示例#7
0
# Test drift shells routines

import paraview.simple as pv

from prototype import driftShell as ds

pv._DisableFirstRenderCameraReset()

# Load Test Data
t96 = pv.OpenDataFile("../out/fields/t96_128_dst50_5.vts")
dipole = pv.OpenDataFile("../out/fields/dipole_5.vts")

t96_K0_ds = ds.driftShell(PV_dataObject=t96,
                          local_times=[12, 0],
                          b_mirror=115.0,
                          K=0,
                          mode='K')

b_k1000 = t96_K0_ds.field_lines[12].get_B_mirror_for_K(K=1000)
t96_K1000_ds = ds.driftShell(PV_dataObject=t96,
                             local_times=[12, 0],
                             b_mirror=b_k1000,
                             K=1000,
                             mode='K')

dipole_K0_ds = ds.driftShell(PV_dataObject=dipole,
                             local_times=[12, 0],
                             b_mirror=115.0,
                             K=0,
                             mode='K')
示例#8
0
import numpy as np
import paraview.simple as pv

from prototype import driftShell as ds

pv._DisableFirstRenderCameraReset()

checkTimes = np.linspace(0, 24, num=64, endpoint=False)
#calcTimes = [0.0, 6.0, 12.0,  18.0]
calcTimes = np.linspace(0,24, num=4, endpoint=False)

#t96 = pv.OpenDataFile("../out/fields/t96_dp0_dst50_5.vts")
#t96 = pv.OpenDataFile("../out/fields/dipole_dp0.vts")
t96 = pv.OpenDataFile("../out/fields/t96_dp20_dst50_small_grid.vts")

t96_K0_ds2 = ds.driftShell(PV_dataObject=t96, local_times=checkTimes, b_mirror=150.00, K=100, mode='K')
t96_K0_ds = ds.driftShell(PV_dataObject=t96, local_times=calcTimes, b_mirror=150.00, K=100, mode='K')

RE_el = 1.0

phi_location = {}
phi_location2 = {}
print "Locations: ", phi_location

interp_points = np.linspace(0,24,64, endpoint=False)

for x in interp_points:
        phi_location[x] = t96_K0_ds.get_new_phi_for_localtime(x, RE=RE_el)
        phi_location2[x] = t96_K0_ds2.get_new_phi_for_localtime(x, RE=RE_el)

# now to figure out how to make the actual grid.
示例#9
0
def test_lstar_dipole_analytic():
    tol = 1e-5
    divs = 1200
    k = 0
    num_tests = 10
    lt = np.linspace(start=0, stop=24, num=4, endpoint=False)
    Lstars = np.linspace(start=2, stop=10, num=num_tests, endpoint=True)
    data1 = col.OrderedDict()
    error1 = col.OrderedDict()
    relerror1 = col.OrderedDict()
    intersectL = col.OrderedDict()
    intersectCalcL = col.OrderedDict()
    intError = col.OrderedDict()
    intRelError = col.OrderedDict()

    for L in Lstars:
        ds1 = ds.driftShell(local_times=lt,
                            start_line=[L, 0.0, 0.0],
                            K=k,
                            mode='analytic_K',
                            error_tol=tol)
        data1[L] = ds1.calculate_L_star(RE=1.0, lat_divs=divs, lon_divs=divs)
        error1[L] = np.abs(L - data1[L])
        relerror1[L] = np.abs(L - data1[L]) / L
        intersectL[L] = ih.analytic_dipole_line_lat_crossing(L=L, r=1)
        intersectCalcL[L] = ih.get_lat(ds1.get_new_phi_for_localtime(11.34))
        intError[L] = np.abs(intersectL[L] - intersectCalcL[L])
        intRelError[L] = np.abs(intersectL[L] -
                                intersectCalcL[L]) / intersectL[L]

    # get data
    X1, Y1 = ih.dict_to_x_y(data1)
    X2, Y2 = ih.dict_to_x_y(error1)
    X3, Y3 = ih.dict_to_x_y(relerror1)
    X4, Y4 = ih.dict_to_x_y(intersectL)
    X5, Y5 = ih.dict_to_x_y(intersectCalcL)
    X6, Y6 = ih.dict_to_x_y(intError)
    X7, Y7 = ih.dict_to_x_y(intRelError)

    # plot the results
    fig1 = plt.figure()
    fig2 = plt.figure()

    axF1_1 = fig1.add_subplot(111)
    axF1_2 = fig1.add_subplot(111, sharex=axF1_1, frameon=False)

    line1, = axF1_1.plot(X1, Y1, "k*-", label="Calculated $L^{*}$")
    line2, = axF1_2.semilogy(X2, Y2, "r.-", label="Absolute Error")
    line3, = axF1_2.semilogy(X3, Y3, "bo-", label="Relative Error")
    axF1_2.yaxis.tick_right()
    axF1_2.yaxis.set_label_position("right")

    axF1_1.set_xlabel("Analytic $L^{*}$")
    axF1_1.set_ylabel("Calculated $L^{*}$")
    axF1_2.set_ylabel("Error")
    axF1_1.set_title("$L^{*}$ Error -- Analytic vs. Calculated \n on a Dipole")

    axF2_1 = fig2.add_subplot(111)
    axF2_2 = fig2.add_subplot(111, sharex=axF2_1, frameon=False)

    line4, = axF2_1.plot(X4,
                         Y4,
                         "k*-",
                         label="Analytic $\lambda$ intersection")
    line5, = axF2_1.plot(X5,
                         Y5,
                         "r.-",
                         label="Calculated $\lambda$ intersection")
    line6, = axF2_2.semilogy(X6, Y6, "bo-", label="Absolute Error")
    line7, = axF2_2.semilogy(X7, Y7, "k-.", label="Relative Error")

    axF2_1.set_xlabel("Analytic $L^{*}$")
    axF2_1.set_ylabel("$\lambda$ intersection ($^{\circ}$)")
    axF2_2.set_ylabel("Error")
    axF2_1.set_title(
        "$\lambda$ Intersection Error -- Analytic vs. Calculated \n on a Dipole"
    )
    axF2_2.yaxis.tick_right()
    axF2_2.yaxis.set_label_position("right")

    axF1_1.legend(handles=[line1, line2, line3], loc=2, prop={'size': 8})
    fig1.tight_layout()
    fig1.savefig("out/error_analysis/Calculated_L_Error.pdf")

    axF2_1.legend(handles=[line4, line5, line6, line7],
                  loc=2,
                  prop={'size': 8})
    fig2.tight_layout()
    fig2.savefig("out/error_analysis/Lambda_intersection_error.pdf")
示例#10
0
    start_location = np.linspace(6.8, 3.0, num=size, endpoint=True)
    grid_files = ["dipole_dp0_3_small_grid.vts"
                  ]  #, "dipole_dp0_10_large_grid.vts"]

    plot_data = col.OrderedDict()

    for grid_file in grid_files:
        data = pv.OpenDataFile("../out/fields/{}".format(grid_file))
        jobs = len(start_location)

        print "Looking for Drift Shell at: {} RE".format(start_location[rank])

        # drift_shell = ds.driftShell(PV_dataObject=data, local_times=calcTimes, start_line=(start_location[rank],0,0), K=0, mode='location_k')
        drift_shell = ds.driftShell(local_times=calcTimes,
                                    start_line=(start_location[rank], 0, 0),
                                    K=0,
                                    mode='analytic_K')

        ideal_RE = ih.mag(drift_shell.field_lines[0].fieldLinePoints_f[0])
        print "[{}] Ideal L*: {}".format(rank, ideal_RE)

        RE_el = 1.0

        test_grids = np.arange(start=50, stop=600, step=50, dtype=np.int)

        # Output to file
        # fileName = "out/error_analysis/{}_lines/l_star_error_analysis_{}_RE_{}_tab.txt".format(lines, grid_file, start_location[rank])
        fileName = "out/error_analysis/{}_lines/l_star_error_analysis_{}_RE_{}_analytic_tab.txt".format(
            lines, grid_file, start_location[rank])

        f = open(fileName, 'w')
示例#11
0
import numpy as np
import paraview.simple as pv
from prototype import driftShell as ds

from ghostpy.prototype import inv_common as ih

#pv._DisableFirstRenderCameraReset()

checkTimes = np.linspace(0, 24, num=64, endpoint=False)
calcTimes = np.linspace(0, 24, num=4, endpoint=False)

t96 = pv.OpenDataFile("../out/fields/dipole_dp0_3_small_grid.vts")

t96_K0_ds = ds.driftShell(PV_dataObject=t96,
                          local_times=calcTimes,
                          b_mirror=115.00,
                          K=0,
                          mode='K')

RE_el = 1.0

L_10 = t96_K0_ds.calculate_L_star(RE=RE_el, lat_divs=10, lon_divs=10)
print "L* (10): ", L_10
raw_input("Press Enter to Continue...")

L_25 = t96_K0_ds.calculate_L_star(RE=RE_el, lat_divs=25, lon_divs=25)
print "L* (25): ", L_25
print "L* (10) - L* (25):", L_10 - L_25
raw_input("Press Enter to Continue...")

L_50 = t96_K0_ds.calculate_L_star(RE=RE_el, lat_divs=50, lon_divs=50)