コード例 #1
0
def viz(
    I, V, f, c, L, dt, C, T,  # PDE paramteres
    umin, umax,               # Interval for u in plots
    animate=True,             # Simulation with animation?
    tool='matplotlib',        # 'matplotlib' or 'scitools'
    solver_function=solver,   # Function with numerical algorithm
    version='vectorized',     # 'scalar' or 'vectorized'
    ):
    import wave1D_u0
    if version == 'vectorized':
        # Reuse viz from wave1D_u0, but with the present
        # modules' new vectorized solver (which has
        # version='vectorized' as default argument;
        # wave1D_u0.viz does not feature this argument)
        cpu = wave1D_u0.viz(
            I, V, f, c, L, dt, C, T, umin, umax,
            animate, tool, solver_function=solver)
    elif version == 'scalar':
        # Call wave1D_u0.viz with a solver with
        # scalar code and use wave1D_u0.solver.
        cpu = wave1D_u0.viz(
            I, V, f, c, L, dt, C, T, umin, umax,
            animate, tool,
            solver_function=wave1D_u0.solver)
        # Method 2: wrap this module's solver with an extra
        # argument version='scalar'
        #import functools
        #scalar_solver = functools.partial(scalar, version='scalar')
    return cpu
コード例 #2
0
def viz(
        I,
        V,
        f,
        c,
        L,
        dt,
        C,
        T,  # PDE paramteres
        umin,
        umax,  # Interval for u in plots
        animate=True,  # Simulation with animation?
        tool='matplotlib',  # 'matplotlib' or 'scitools'
        solver_function=solver,  # Function with numerical algorithm
        version='vectorized',  # 'scalar' or 'vectorized'
):
    import wave1D_u0
    if version == 'vectorized':
        # Reuse viz from wave1D_u0, but with the present
        # modules' new vectorized solver (which has
        # version='vectorized' as default argument;
        # wave1D_u0.viz does not feature this argument)
        cpu = wave1D_u0.viz(I,
                            V,
                            f,
                            c,
                            L,
                            dt,
                            C,
                            T,
                            umin,
                            umax,
                            animate,
                            tool,
                            solver_function=solver)
    elif version == 'scalar':
        # Call wave1D_u0.viz with a solver with
        # scalar code and use wave1D_u0.solver.
        cpu = wave1D_u0.viz(I,
                            V,
                            f,
                            c,
                            L,
                            dt,
                            C,
                            T,
                            umin,
                            umax,
                            animate,
                            tool,
                            solver_function=wave1D_u0.solver)
        # Method 2: wrap this module's solver with an extra
        # argument version='scalar'
        #import functools
        #scalar_solver = functools.partial(scalar, version='scalar')
    return cpu
コード例 #3
0
ファイル: wave1D_n0.py プロジェクト: htphuc/fdm-book
def plug(C=1, Nx=50, animate=True, T=2):
    """Plug profile as initial condition."""
    def I(x):
        if abs(x-L/2.0) > 0.1:
            return 0
        else:
            return 1

    L = 1.
    c = 1
    dt = (L/Nx)/c  # choose the stability limit with given Nx
    cpu = viz(I, None, None, c, L, dt, C, T,
              umin=-1.1, umax=1.1, animate=animate)
コード例 #4
0
def plug(C=1, Nx=50, animate=True, T=2):
    """Plug profile as initial condition."""
    def I(x):
        if abs(x-L/2.0) > 0.1:
            return 0
        else:
            return 1

    L = 1.
    c = 1
    dt = (L/Nx)/c  # choose the stability limit with given Nx
    cpu = viz(I, None, None, c, L, dt, C, T,
              umin=-1.1, umax=1.1, animate=animate)