示例#1
0
def continuation_2D(nx=4, interactive=False):
    dim = 2
    dof = 3
    ny = nx
    nz = 1

    parameters = {'Reynolds Number': 0}
    interface = Interface(parameters, nx, ny, nz, dim, dof)

    continuation = Continuation(interface, parameters)

    x0 = numpy.zeros(dof * nx * ny * nz)
    x0 = continuation.newton(x0)

    target = 2000
    ds = 100
    maxit = 20
    x = continuation.continuation(x0, 'Reynolds Number', target, ds, maxit)

    assert numpy.linalg.norm(x) > 0

    if not interactive:
        return x

    print(x)

    x = plot_utils.create_state_mtx(x, nx, ny, nz, dof)
    plot_utils.plot_state(x[:, :, 0, 0], x[:, :, 0, 1], nx, ny)
示例#2
0
def test_continuation(nx=4, interactive=False):
    dim = 3
    dof = 4
    ny = nx
    nz = nx

    parameters = {}
    interface = Interface(parameters, nx, ny, nz, dim, dof)

    continuation = Continuation(interface, parameters)

    x0 = numpy.zeros(dof * nx * ny * nz)
    x0 = continuation.newton(x0)

    start = 0
    target = 100
    ds = 100
    x = continuation.continuation(x0, 'Reynolds Number', start, target, ds)[0]

    assert numpy.linalg.norm(x) > 0

    if not interactive:
        return

    print(x)

    x = plot_utils.create_state_mtx(x, nx, ny, nz, dof)
    plot_utils.plot_velocity_magnitude(x[:, ny // 2, :, 0], x[:, ny // 2, :,
                                                              2], nx, nz)
示例#3
0
def test_continuation_2D_stretched(nx=4, interactive=False):
    dim = 2
    dof = 3
    ny = nx
    nz = 1

    xpos = utils.create_stretched_coordinate_vector(0, 1, nx, 1.5)
    ypos = utils.create_stretched_coordinate_vector(0, 1, ny, 1.5)

    parameters = {}
    interface = Interface(parameters, nx, ny, nz, dim, dof, xpos, ypos)

    continuation = Continuation(interface, parameters)

    x0 = numpy.zeros(dof * nx * ny * nz)
    x0 = continuation.newton(x0)

    start = 0
    target = 2000
    ds = 100
    x = continuation.continuation(x0, 'Reynolds Number', start, target, ds)[0]

    assert numpy.linalg.norm(x) > 0

    if not interactive:
        return x

    print(x)

    x = plot_utils.create_state_mtx(x, nx, ny, nz, dof)
    plot_utils.plot_velocity_magnitude(x[:, :, 0, 0], x[:, :, 0, 1], interface)
示例#4
0
文件: ldc2.py 项目: ipelupessy/fvm
def main():
    ''' An example of performing a continuation for a 2D lid-driven cavity and detecting a bifurcation point'''
    dim = 2
    dof = 3
    nx = 32
    ny = nx
    nz = 1
    n = dof * nx * ny * nz

    # Define a point of interest
    poi = (nx // 2 - 1, ny // 4 - 1)

    # Define the problem
    parameters = {
        'Problem Type':
        'Lid-driven cavity',
        # Problem parameters
        'Reynolds Number':
        1,
        'Lid Velocity':
        0,
        # Use a stretched grid
        'Grid Stretching Factor':
        1.5,
        # Set a maximum step size ds
        'Maximum Step Size':
        500,
        # Give back extra output (this is also more expensive)
        'Verbose':
        True,
        # Value describes the value that is traced in the continuation
        # and time integration methods
        'Value':
        lambda x: utils.create_state_mtx(x, nx, ny, nz, dof)[poi[0], poi[1], 0,
                                                             0]
    }

    interface = Interface(parameters, nx, ny, nz, dim, dof)

    print('Looking at point ({}, {})'.format(
        interface.discretization.x[poi[0]],
        interface.discretization.y[poi[1]]))

    continuation = Continuation(interface, parameters)

    # Compute an initial guess
    x0 = numpy.zeros(n)
    x0 = continuation.continuation(x0, 'Lid Velocity', 0, 1, 0.1)[0]

    # Perform an initial continuation to Reynolds number 7000 without detecting bifurcation points
    ds = 100
    target = 7000
    x, mu, data1 = continuation.continuation(x0, 'Reynolds Number', 0, target,
                                             ds)

    parameters['Newton Tolerance'] = 1e-12
    parameters['Destination Tolerance'] = 1e-4
    parameters['Detect Bifurcation Points'] = True
    parameters['Maximum Step Size'] = 100

    # parameters['Eigenvalue Solver'] = {}
    # parameters['Eigenvalue Solver']['Target'] = 3j
    # parameters['Eigenvalue Solver']['Tolerance'] = 1e-9
    # parameters['Eigenvalue Solver']['Number of Eigenvalues'] = 20

    # Now detect the bifurcation point
    target = 10000
    x2, mu2, data2 = continuation.continuation(x, 'Reynolds Number', mu,
                                               target, ds)

    # Compute the unstable branch after the bifurcation
    parameters['Detect Bifurcation Points'] = False
    parameters['Maximum Step Size'] = 2000

    target = 10000
    parameters['Newton Tolerance'] = 1e-4
    x3, mu3, data3 = continuation.continuation(x2, 'Reynolds Number', mu2,
                                               target, ds)

    # Plot a bifurcation diagram
    plt.plot(data1.mu, data1.value)
    plt.plot(data2.mu, data2.value)
    plt.plot(data3.mu, data3.value)
    plt.show()

    # Add a perturbation based on the eigenvector
    interface.set_parameter('Reynolds Number', mu2)
    _, v = interface.eigs(x2, True)
    v = v[:, 0].real

    v = plot_utils.create_state_mtx(v, nx, ny, nz, dof)

    # Plot the velocity magnutide
    plot_utils.plot_velocity_magnitude(v[:, :, 0, 0], v[:, :, 0, 1], interface)

    # Plot the pressure
    plot_utils.plot_value(v[:, :, 0, 2], interface)