示例#1
0
def test_solve_c_lpm():
    try:
        assert (norm(
            ls.solve_c_lpm(
                [1, 2, 3, 4, 5], 1, 2, 3, 4, 5, 6, 7, extrap=[1, 2, 3, 4, 5]) -
            [0, -3.161, -7.465, -13.3231, -21.298]) < 0.001)
        print("solve_c_lpm             TEST OK")
    except (AssertionError):
        print("solve_c_lpm             TEST FAIL")
def plot_conc_benchmark(save):
    ''' Plots the benchmark of the concentration lpm against an analytical solution

        Parameters:
        ----------
		save : Bool
			If set to true, save figure generated to working directory

        Returns:
        --------
        None

        Notes:
        This will output a plot to the screen where a plot of the numerical and analytical solution is overlayed on top
        dotted broken line is numerical and solid blue line is analytical.

    '''
    #analytical solution obtained via wolfram, parameters are as follows:
    #a = 1, b = 3, P0 = 4, P1 = 5, P = 6, d = 7, Csrc = 1, C(0)=1, M0=3
    n = 100
    t = np.linspace(0, 5, num=n)
    analytical = 3.5 - 2.5 * np.exp(t)

    #obtain numerical solution for conc lpm
    numerical = ls.solve_c_lpm(t,
                               1,
                               3,
                               4,
                               5,
                               7,
                               3,
                               1,
                               testing=[True, t, [1],
                                        np.full(n, 6)])

    #plot
    f, ax = plt.subplots(1, 1)
    ax.plot(t, numerical, 'k-o', label='Numerical')
    ax.plot(t, analytical, 'b', label='Analytical')
    ax.legend(loc='lower left', prop={'size': 14})
    ax.set_title(
        'a = 1, b = 3, $P_0$ = 4, $P_1$ = 5, d = 7, $M_0$=3, $C_{src}$ = 1, C(0)=1, and $P$ = 6 [held constant]',
        size=10)
    f.suptitle(
        "Comparison of analytical and numerical solutions to concentration LPM"
    )

    save_figure = save
    if not save_figure:
        #Open a new window and display the plot
        plt.show()
    else:
        #Save that plot to a png file
        plt.savefig('conc_benchmark.png', dpi=300)
示例#3
0
def test_solve_c_lpm():
    try:
        assert (norm(
            ls.solve_c_lpm([0, 1, 2],
                           2,
                           3,
                           4,
                           5,
                           6,
                           7,
                           8,
                           testing=[True, [0, 1, 2], [6, 6, 6]]) -
            [6, -3.964, -16.293]) < 0.001)
        print("solve_c_lpm             TEST OK")
    except (AssertionError):
        print("solve_c_lpm             TEST FAIL")