コード例 #1
0
ファイル: sandbox.py プロジェクト: julien-blanchon/coilgun
def advanced_linear_test(loc, plot=False, plot3d=False):
    """ almost entire pipeline """
    coil = datastore.coils.iloc[loc]
    coil = l_construct(
        {
            'Lp': coil.Lp,
            'Rp': coil.Rp,
            'Lb': coil.Lb,
            'Rbi': coil.Rbi,
            'Rbo': coil.Rbo,
            'mu': 100
        },
        space=5)
    convex = convexApprox.Convex_approx(coil.dLz_z, coil.dLz, order=2)
    lz = splinify.splinify(convex.dLz_z, coil.L0, d2L=convex.run_approx())
    if plot:
        plot_l(coil)
    test = solver.gaussSolver(lz,
                              C=0.0047,
                              R=0.1 + coil.resistance,
                              E=450,
                              m=0.031)
    res = test._linear_opt(-(5 * coil.Lb) / 2000,
                           plot=plot,
                           plot3d=plot3d,
                           epsilon=0.00005)
    # print(res)
    if plot:
        test.plot_single(res[1])
    print(test.computeMaxEc(res[1]),
          str(int(test.computeTau(res[1]) * 100)) + "%")
    return (test.computeMaxEc(res[1]),
            str(int(test.computeTau(res[1]) * 100)) + "%")
コード例 #2
0
ファイル: sandbox.py プロジェクト: julien-blanchon/coilgun
def solver_test(loc, nb=1):
    """ Compute the dynamic of a solution for a simple case, nb it the number of initial position to try """
    coil = datastore.coils.iloc[loc]
    convex = convexApprox.Convex_approx(coil.dLz_z, coil.dLz, order=2)
    lz = splinify.splinify(convex.dLz_z, coil.L0, d2L=convex.run_approx())

    test = solver.gaussSolver(lz, C=0.0047, R=0.1, E=450, m=0.0078)
    res = []
    for i in range(nb):
        res.append(test.solve(-(2.4 * coil.Lb - i) / 2000, 0))
        print("ec" + str(i), test.computeMaxEc(res[i]))
        print("etotal" + str(i), test.computeMaxE(res[i]))
        print("tau" + str(i), test.computeTau(res[i]) * 100)
    test.plot_multiple(res)
コード例 #3
0
def find_optimal_launch(loc, C, R, E, v0=0, plot=False, plot3d=False):
    """Compute the optimal launch position

    Given a coil number and an electrical setup,
    computes the optimal launch position of the projectile
    and the key statistics linked (kinetic energy and efficiency).

    Use plot to:
    - plot the coil parameters
    - plot the projection of all launch positions tested
    - plot the dynamic of the best solution

    Use plot3d to:
    - plot the 3d representation of all solutions tested

    Arguments:
        loc {number} -- coil id
        C {number} -- capacity in Farad
        R {number} -- circuit resistance without coil in Ohm
        E {number} -- capacitor tension in Volts

    Keyword Arguments:
        v0 {number} -- starting speed for chained coils (default: {0})
        plot {bool} -- plot 2d informations (default: {False})
        plot3d {bool} -- plot 3d solutions (default: {False})

    Returns:
        tuple - starting position, system's dynamic, output kinetic energy, power efficiency
    """
    coil = datastore.coils.iloc[loc]
    m = numpy.pi * coil.Rp**2 * coil.Lp * 7860 * 10**(-9)
    convex = convexApprox.Convex_approx(coil.dLz_z,
                                        coil.dLz,
                                        est_freq=utils.estFreq(coil))
    lz = splinify.splinify(coil.dLz_z, coil.L0, d2L=convex.run_approx())
    if plot:
        plot_l_b(coil, lz)
    test = solver.gaussSolver(lz,
                              C=C,
                              R=(R + coil.resistance),
                              E=E,
                              m=m,
                              v0=v0)
    res = test.computeOptimal(-(1.5 * coil.Lb) / 1000, plot=plot, plot3d=plot)
    if plot:
        test.plot_single(res[1])
    print("Coil " + str(coil.name) + " opt launch", test.computeMaxEc(res[1]),
          str(int(test.computeTau(res[1]) * 100)) + "%")
    return (res[0], res[1], test.computeMaxEc(res[1]), test.computeTau(res[1]))
コード例 #4
0
ファイル: sandbox.py プロジェクト: julien-blanchon/coilgun
def linear_test(loc, plot=False, plot3d=False):
    """ Compute the optimal launch for a given problem, be careful plot3d takes some time """
    coil = datastore.coils.iloc[loc]
    convex = convexApprox.Convex_approx(coil.dLz_z, coil.dLz, order=2)
    lz = splinify.splinify(convex.dLz_z, coil.L0, d2L=convex.run_approx())
    if plot:
        plot_l(coil)
    test = solver.gaussSolver(lz,
                              C=0.0047,
                              R=0.1 + coil.resistance,
                              E=450,
                              m=0.031)
    res = test._linear_opt(-(5 * coil.Lb) / 2000, plot=plot, plot3d=plot3d)
    # print(res)
    if plot:
        test.plot_single(res[1])
    print(test.computeMaxEc(res[1]),
          str(int(test.computeTau(res[1]) * 100)) + "%")
    return (test.computeMaxEc(res[1]),
            str(int(test.computeTau(res[1]) * 100)) + "%")
コード例 #5
0
ファイル: sandbox.py プロジェクト: julien-blanchon/coilgun
def vs_old_maple():
    """ test vs. some legacy code (not provided) """
    coil = l_construct({
        'Lp': 22,
        'Rp': 4.5,
        'Lb': 31,
        'Rbi': 6,
        'Rbo': 7,
        'mu': 3.5,
    })
    convex = convexApprox.Convex_approx(coil.dLz_z, coil.dLz, order=2)
    lz = splinify.splinify(convex.dLz_z, coil.L0, d2L=convex.run_approx())
    plot_l(coil)
    print("rb", coil.resistance)
    test = solver.gaussSolver(lz, C=0.0050, R=0.016 + 0.075, E=170, m=0.0109)
    res = test._linear_opt(-0.08, plot=True, plot3d=True, epsilon=0.001)
    test.plot_single(res[1])
    print(test.computeMaxEc(res[1]),
          str(int(test.computeTau(res[1]) * 10000) / 100) + "%")
    return (test.computeMaxEc(res[1]),
            str(int(test.computeTau(res[1]) * 100)) + "%")
コード例 #6
0
ファイル: sandbox.py プロジェクト: julien-blanchon/coilgun
def plot_l(test):
    """ Plot the inductance (raw vs. convex approx and splines) """
    convex = convexApprox.Convex_approx(test.dLz_z, test.dLz)
    lz = splinify.splinify(test.dLz_z, test.L0, dL=convex.run_approx())

    z = numpy.linspace(lz.z[0], lz.z[-1], 5000)

    ax1 = plt.subplot(311)
    plt.plot(z, lz.Lz()(z), color=(0, 0, 1))
    plt.setp(ax1.get_xticklabels())

    ax2 = plt.subplot(312, sharex=ax1)
    plt.plot(lz.z, test.dLz, color=(1, 0, 0))
    plt.plot(z, lz.dLz()(z), color=(0, 0, 1))
    plt.setp(ax2.get_xticklabels(), visible=False)

    plt.subplot(313, sharex=ax1)
    plt.plot(lz.z, discrete_fprime(test.dLz, test.dLz_z), color=(1, 0, 0))
    plt.plot(lz.z, convex.run_approx(), color=(0, 1, 0))
    plt.plot(z, lz.d2Lz()(z), color=(0, 0, 1))
    plt.show()
コード例 #7
0
ファイル: sandbox.py プロジェクト: julien-blanchon/coilgun
def Mu_impact(cas):
    """Shows the impact of Mu

    Given a project setup, computes the inductance
    and its 2 derivatives for several Mu values and
    plots them nicely.

    The output is not raw but the splinified convex
    approx.

    Arguments:
        cas {dict} -- a setup
    """
    Lp = cas["Lp"]
    Rp = cas["Rp"]
    Lb = cas["Lb"]
    Rbi = cas["Rbi"]
    Rbo = cas["Rbo"]
    mu = [5, 10, 50, 100, 500, 1000, 5000]  # [5, 10, 50, 100, 500, 1000, 5000]
    n = len(mu)
    res = []
    for k in range(n):
        test = coilCalculator(True, 5)
        test.defineCoil(Lb, Rbi, Rbo)
        test.drawCoil()
        test.defineProjectile(Lp, Rp, mu=mu[k])
        test.drawProjectile()
        test.setSpace()
        test.computeL0()
        test.computedLz()
        res += [max(test.dLz)]
        convex = convexApprox.Convex_approx(test.dLz_z, test.dLz, order=2)
        lz = splinify.splinify(convex.dLz_z, test.L0, d2L=convex.run_approx())
        z = numpy.linspace(2 * lz.z[0], 2 * lz.z[-1], 10000)

        ax1 = plt.subplot(321)
        plt.plot(z, lz.Lz()(z), color=(k / n, 0, 1 - k / n), label=k)
        plt.setp(ax1.get_xticklabels(), visible=False)

        ax1 = plt.subplot(322, sharex=ax1)
        plt.plot(z, (lz.Lz()(z) - test.L0) / res[-1] + test.L0,
                 color=(k / n, 0, 1 - k / n),
                 label=k)
        plt.setp(ax1.get_xticklabels(), visible=False)

        ax2 = plt.subplot(323, sharex=ax1)
        plt.plot(z, lz.dLz()(z), color=(k / n, 0, 1 - k / n), label=k)
        plt.setp(ax2.get_xticklabels(), visible=False)

        ax2 = plt.subplot(324, sharex=ax1)
        plt.plot(z,
                 lz.dLz()(z) / res[-1],
                 color=(k / n, 0, 1 - k / n),
                 label=k)
        plt.setp(ax2.get_xticklabels(), visible=False)

        plt.subplot(325, sharex=ax1)
        plt.plot(z, lz.d2Lz()(z), color=(k / n, 0, 1 - k / n), label=k)

        plt.subplot(326, sharex=ax1)
        plt.plot(z,
                 lz.d2Lz()(z) / res[-1],
                 color=(k / n, 0, 1 - k / n),
                 label=k)
        plt.setp(ax1.get_xticklabels(), visible=False)
    plt.show()