示例#1
0
def solver_r(I,
             f,
             c,
             U_L,
             L,
             n,
             dt,
             tstop,
             graphics=None,
             user_action=None,
             version='scalar'):
    """
    1D wave equation as in wave1D_func1.solver, but the present
    function models spherical waves. The physical solution is v=u/r.
    The boundary condition at r=0 is u=0 because of symmetry
    so u(L)=U_L is the only free boundary condition.

    This version is implemented as a wrapper of the solver
    in wave1D_func1.
    We compute v and display it through solver's user_action
    function before calling the supplied user's user_action
    function.
    """

    v = None  # bring v=u/r into play

    def U_0(t):
        return 0

    solutions = []  # store all u fields at all time levels

    def action_with_plot(u, x, t):

        v = u.copy()  # get right length and type
        r = x  # radial coordinates
        v[1:] = u[1:] / r[1:]  # in-place modification
        v[0] = v[1]  # from the b.c. dv/dr=0 at r=0
        solutions.append(v.copy())
        if graphics is not None:
            graphics.configure(coor=x)
            graphics.plotcurve(v, legend='v(x,t=%9.4E)' % t, ps=0)
        if user_action is not None:
            user_action(v, x, t)  # call user's function with v

    dt, r, cpu = solver(I, f, c, U_0, U_L, L, n, dt, tstop, action_with_plot,
                        version)
    return dt, r, solutions, cpu
示例#2
0
def solver_r(I, f, c, U_L, L, n, dt, tstop,
             graphics=None, user_action=None, version='scalar'):
    """
    1D wave equation as in wave1D_func1.solver, but the present
    function models spherical waves. The physical solution is v=u/r.
    The boundary condition at r=0 is u=0 because of symmetry
    so u(L)=U_L is the only free boundary condition.

    This version is implemented as a wrapper of the solver
    in wave1D_func1.
    We compute v and display it through solver's user_action
    function before calling the supplied user's user_action
    function.
    """

    v = None  # bring v=u/r into play

    def U_0(t):
        return 0
    
    solutions = []  # store all u fields at all time levels
    
    def action_with_plot(u, x, t):

        v  = u.copy()        # get right length and type
        r = x                # radial coordinates
        v[1:] = u[1:]/r[1:]  # in-place modification
        v[0] = v[1]          # from the b.c. dv/dr=0 at r=0
        solutions.append(v.copy())
        if graphics is not None:
            graphics.configure(coor=x)
            graphics.plotcurve(v, legend='v(x,t=%9.4E)' % t, ps=0)
        if user_action is not None:
            user_action(v, x, t)  # call user's function with v

    dt, r, cpu = solver(I, f, c, U_0, U_L, L, n, dt, tstop,
                        action_with_plot, version)
    return dt, r, solutions, cpu
示例#3
0

solutions = []
time_level_counter = 0
version = 'scalar'
N = int(sys.argv[1])


def action(u, x, t):
    global time_level_counter
    if time_level_counter % N == 0:
        solutions.append(u.copy())
    time_level_counter += 1


n = 100
tstop = 6
L = 10
dt, x, cpu = solver(I,
                    f,
                    1.0,
                    lambda t: 0,
                    lambda t: 0,
                    L,
                    n,
                    0,
                    tstop,
                    user_action=action,
                    version=version)
print 'CPU time:', cpu
示例#4
0
from wave1D_func1 import solver
from numpy import sin, pi

def I(x):  return sin(2*x*pi/L)
def f(x,t): return 0

solutions = []
time_level_counter = 0
version = 'scalar'
N = int(sys.argv[1])

def action(u, x, t):
    global time_level_counter
    if time_level_counter % N == 0:
        solutions.append(u.copy())
    time_level_counter += 1

n = 100; tstop = 6; L = 10
dt, x, cpu = solver(I, f, 1.0, lambda t: 0, lambda t: 0,
                    L, n, 0, tstop,
                    user_action=action, version=version)
print 'CPU time:', cpu