Esempio n. 1
0
def _main():
    '''Main function.
    '''
    args = _parse_input_arguments()

    # read the mesh
    #print "Reading the mesh...",
    mesh, point_data, _ = \
        voropy.reader.read(args.filename, timestep=args.timestep)
    psi0 = point_data['psi'][:, 0] + 1j * point_data['psi'][:, 1]

    # build the model evaluator
    mu = 1.0e-1
    g = 1.0
    num_nodes = len(mesh.node_coords)
    V = -np.ones(num_nodes)
    modeleval = pynosh.modelevaluator_nls.NlsModelEvaluator(
        mesh, V=V, A=point_data['A']
        )

    # Get the preconditioner for in matrix form
    keo = modeleval._get_keo(mu)
    if g > 0.0:
        if modeleval.mesh.control_volumes is None:
            modeleval.mesh.compute_control_volumes(
                variant=modeleval.cv_variant
                )
        alpha = g * 2.0 * (psi0.real**2 + psi0.imag**2) \
            * modeleval.mesh.control_volumes.reshape(psi0.shape)
        num_unknowns = len(psi0)
        from scipy import sparse
        prec = keo \
            + sparse.spdiags(alpha, [0], num_unknowns, num_unknowns)
    else:
        prec = keo

    # https://code.google.com/p/pyamg/source/browse/trunk/Examples/SolverDiagnostics/solver_diagnostics.py
    solver_diagnostics(
        prec,
        fname='solver_diagnostic',
        definiteness='positive',
        symmetry='hermitian'
        )
    return
Esempio n. 2
0
def _main():
    """Main function.
    """
    args = _parse_input_arguments()

    # read the mesh
    # print "Reading the mesh...",
    mesh, point_data, _ = meshplex.reader.read(args.filename, timestep=args.timestep)
    psi0 = point_data["psi"][:, 0] + 1j * point_data["psi"][:, 1]

    # build the model evaluator
    mu = 1.0e-1
    g = 1.0
    num_nodes = len(mesh.node_coords)
    V = -np.ones(num_nodes)
    modeleval = pynosh.modelevaluator_nls.NlsModelEvaluator(
        mesh, V=V, A=point_data["A"]
    )

    # Get the preconditioner for in matrix form
    keo = modeleval._get_keo(mu)
    if g > 0.0:
        if modeleval.mesh.control_volumes is None:
            modeleval.mesh.compute_control_volumes(variant=modeleval.cv_variant)
        alpha = (
            g
            * 2.0
            * (psi0.real ** 2 + psi0.imag ** 2)
            * modeleval.mesh.control_volumes.reshape(psi0.shape)
        )
        num_unknowns = len(psi0)
        from scipy import sparse

        prec = keo + sparse.spdiags(alpha, [0], num_unknowns, num_unknowns)
    else:
        prec = keo

    # https://code.google.com/p/pyamg/source/browse/trunk/Examples/SolverDiagnostics/solver_diagnostics.py
    solver_diagnostics(
        prec, fname="solver_diagnostic", definiteness="positive", symmetry="hermitian"
    )
    return
Esempio n. 3
0
    type='FE', epsilon=0.001, theta=2 * np.pi / 16.0)
A = pyamg.gallery.stencil_grid(stencil, (50, 50), format='csr')

choice = eval(input('\nThere are four different test problems.  Enter \n' +
                    '1:  Isotropic diffusion example\n' +
                    '2:  Anisotropic diffusion example\n' +
                    '3:  Elasticity example\n' +
                    '4:  Nonsymmetric flow example\n\n '))

choice = int(choice)
if choice == 1:
    # Try a basic isotropic diffusion problem from finite differences
    # --> Only use V-cycles by specifying cycle_list
    # --> Don't specify symmetry and definiteness and allow for auto-detection
    A = pyamg.gallery.poisson((50, 50), format='csr')
    solver_diagnostics(A, fname='iso_diff_diagnostic', cycle_list=['V'])

    # To run the best solver found above, uncomment next two lines
    # from iso_diff_diagnostic import iso_diff_diagnostic
    # iso_diff_diagnostic(A)

if choice == 2:
    # Try a basic rotated anisotropic diffusion problem from bilinear finite elements
    # --> Only use V-cycles by specifying cycle_list
    # --> Specify symmetry and definiteness (the safest option)
    # --> Choose the rootnode_solver
    stencil = pyamg.gallery.diffusion.diffusion_stencil_2d(
        type='FE', epsilon=0.001, theta=2 * np.pi / 16.0)
    A = pyamg.gallery.stencil_grid(stencil, (50, 50), format='csr')
    solver_diagnostics(A, fname='rot_ani_diff_diagnostic',
                       cycle_list=['V'],