# to view the visualization files
try:
    from scikits import delaunay
except:
    print "Must install scikits.delaunay to generate the visualization files (.vtu for paraview)."
# generate visualization files    
print "\n\n*************************************************************"
print "*************************************************************"
print "Generating visualization files in .vtu format for use with Paraview."
print "\nAll values from coarse levels are interpolated using the aggregates,\n" +\
      "i.e., there is no fixed geometric hierarchy.  Additionally, the mesh\n" +\
      "has been artificially shrunk towards each element's barycenter, in order\n" +\
      "to highlight the discontinuous nature of the discretization.\n"
print "-- Near null-space mode from level * is in the file\n"+\
      "   DG_Example_B_variable0_lvl*.vtu"
print "-- Aggregtes from level * are in the two file\n"+\
      "   DG_Example_aggs_lvl*_point-aggs,  and \n"+\
      "   DG_Example_aggs_lvl*_aggs.vtu"
print "-- The mesh from from level * is in the file\n"+\
      "   DG_Example_mesh_lvl*.vtu"
print "-- The error is in file\n"+\
      "   DG_Example_error_variable0.vtu"
print ""
from my_vis import shrink_elmts, my_vis
elements2,vertices2 =  shrink_elmts(elements, vertices)
my_vis(sa, vertices2, error=x, fname="DG_Example_", E2V=elements2[:,0:3])




                            'angles': list(np.linspace(-np.pi / 8., 5 * np.pi / 8., 4))}),
              None]

##
# Use constant in B for interpolation, but only between levels 0 and 1
use_constant = (True, {'last_level': 0})

# Construct solver using planewaves
sa = smoothed_aggregation_helmholtz_solver(
    A,
    planewaves=pwave_args,
    use_constant=use_constant,
    strength=strength,
    smooth=smooth,
    aggregate=aggregate,
    improve_candidates=improve_candidates,
    presmoother=smoother,
    postsmoother=smoother,
    **SA_build_args)

# Solve
residuals = []
x = sa.solve(b, x0=x0, residuals=residuals, **SA_solve_args)
print("*************************************************************")
print("Note the improved performance from using planewaves in B.")
for i, r in enumerate(residuals):
    print("residual at iteration {0:2}: {1:^6.2e}".format(i, r))

elements2, vertices2 = shrink_elmts(elements, vertices)
my_vis(sa, vertices2, error=abs(x), fname='helmholtz_', E2V=elements2)
                     'angles':list(linspace(-pi/8., 5*pi/8., 4)) }),
                   None ]

    ##
    # Use constant in B for interpolation, but only between levels 0 and 1
    use_constant = (True, {'last_level': 0})

    # Construct solver using planewaves
    sa = smoothed_aggregation_helmholtz_solver(
        A,
        planewaves=pwave_args,
        use_constant=use_constant,
        strength=strength,
        smooth=smooth,
        aggregate=aggregate,
        improve_candidates=improve_candidates,
        presmoother=smoother,
        postsmoother=smoother,
        **SA_build_args)

    # Solve
    residuals = []
    x = sa.solve(b, x0=x0, residuals=residuals, **SA_solve_args)
    print "\n*************************************************************"
    print "*************************************************************"
    print "Note the improved performance from using planewaves in B.\n"
    print_cycle_history(residuals, sa, verbose=True, plotting=False)

    elements2, vertices2 = shrink_elmts(elements, vertices)
    my_vis(sa, vertices2, error=abs(x), fname='helmholtz_', E2V=elements2)
Esempio n. 4
0
x = sa.solve(b, x0=x0, residuals=resvec, **SA_solve_args)
print("*************************************************************")
print("Now use appropriate parameters, especially \'energy\' prolongation\n" +
      "smoothing and a distance based strength measure on level 0.  This\n" +
      "yields a much more efficient solver.\n")
for i, r in enumerate(resvec):
    print("residual at iteration {0:2}: {1:^6.2e}".format(i, r))

# generate visualization files
print("*************************************************************")
print("Generating visualization files in .vtu format for use with Paraview.")
s = """All values from coarse levels are interpolated using the aggregates,
i.e., there is no fixed geometric hierarchy.  Additionally, the mesh
has been artificially shrunk towards each element's barycenter, in order
to highlight the discontinuous nature of the discretization.

-- Near null-space mode from level * is in the file
   DG_Example_B_variable0_lvl*.vtu
-- Aggregtes from level * are in the two file
   DG_Example_aggs_lvl*_point-aggs,  and
   DG_Example_aggs_lvl*_aggs.vtu
-- The mesh from from level * is in the file
   DG_Example_mesh_lvl*.vtu
-- The error is in file
   DG_Example_error_variable0.vtu
"""
print(s)

elements2, vertices2 = shrink_elmts(elements, vertices)
my_vis(sa, vertices2, error=x, fname="DG_Example_", E2V=elements2[:, 0:3])