← Back to team overview

dolfin team mailing list archive

Re: [HG DOLFIN] bug fix from Ilmar

 

Created different output for missing trilinos support in dolfin and for missing pytrilinos module.

Have a look at the patch. Changed the file slightly to fit with demo/la/eigensolver.

ilmar

DOLFIN wrote:
One or more new changesets pushed to the primary dolfin repository.
A short summary of the last three changesets is included below.

changeset:   4107:b4f9a3e292ddcadea5b7cc30970cb7ec0249b77a
tag:         tip
user:        Kent-Andre Mardal <kent-and@xxxxxxxxx>
date:        Mon Apr 28 15:34:26 2008 +0200
files:       demo/la/trilinos/python/demo.py
description:
bug fix from Ilmar


changeset:   4106:ab92801fdca8ae501ecbda5bfdea8bc054a62649
user:        Johannes Ring <johannr@xxxxxxxxx>
date:        Mon Apr 28 15:01:49 2008 +0200
files:       scons/simula-scons/simula_scons/pkgconfiggenerators/trilinos.py
description:
Minor fix (reported by Ilmar).


changeset:   4105:8e62d656495158e9ff2e2751d5bc1d1872cec6fa
user:        "Anders Logg <logg@xxxxxxxxx>"
date:        Mon Apr 28 14:27:14 2008 +0200
files:       dolfin/function/DiscreteFunction.cpp
description:
Remove some debugging output

----------------------------------------------------------------------
For more details, visit http://www.fenics.org/hg/dolfin
_______________________________________________
DOLFIN-dev mailing list
DOLFIN-dev@xxxxxxxxxx
http://www.fenics.org/mailman/listinfo/dolfin-dev
diff -r b4f9a3e292dd demo/la/trilinos/python/demo.py
--- a/demo/la/trilinos/python/demo.py	Mon Apr 28 15:34:26 2008 +0200
+++ b/demo/la/trilinos/python/demo.py	Mon Apr 28 15:54:53 2008 +0200
@@ -1,109 +1,111 @@
 """ This demo implements a Poisson equations solver
 based on the demo "dolfin/demo/pde/poisson/python/demo.py"
 in Dolfin using Epetra matrices, the AztecOO CG solver and ML 
-AMG preconditioner" 
+AMG preconditioner 
 """
 
 __author__ = "Kent-Andre Mardal (kent-and@xxxxxxxxx)"
 __date__ = "2008-04-24"
 __copyright__ = "Copyright (C) 2008 Kent-Andre Mardal"
 
-try: 
-    # import Trilinos stuff
+from dolfin import *
+
+# Test for Trilinos:
+try:
+    dolfin.EpetraMatrix
+except:
+    print "PyDOLFIN has not been configured with Trilinos. Exiting."
+    exit()
+
+try:
     from PyTrilinos import Epetra, AztecOO, TriUtils, ML 
-    from dolfin import *
-    EpetraMatrix
-    trilinos_installed = True
-except: 
-    print "You Need to have PyTrilinos with Epetra, AztecOO, TriUtils and ML installed for this demo to run"
-    trilinos_installed = False 
+except:
+    print "You Need to have PyTrilinos with Epetra, AztecOO, TriUtils and ML installed for this demo to run",
+    print "Exiting."
+    exit()
 
+# Create mesh and finite element
+mesh = UnitSquare(20,20)
+element = FiniteElement("Lagrange", "triangle", 1)
 
-if trilinos_installed: 
+# Source term
+class Source(Function):
+    def __init__(self, element, mesh):
+        Function.__init__(self, element, mesh)
+    def eval(self, values, x):
+        dx = x[0] - 0.5
+        dy = x[1] - 0.5
+        values[0] = 500.0*exp(-(dx*dx + dy*dy)/0.02)
 
+# Neumann boundary condition
+class Flux(Function):
+    def __init__(self, element, mesh):
+        Function.__init__(self, element, mesh)
+    def eval(self, values, x):
+        if x[0] > DOLFIN_EPS:
+            values[0] = 25.0*sin(5.0*DOLFIN_PI*x[1])
+        else:
+            values[0] = 0.0
 
-    # Create mesh and finite element
-    mesh = UnitSquare(20,20)
-    element = FiniteElement("Lagrange", "triangle", 1)
+# Sub domain for Dirichlet boundary condition
+class DirichletBoundary(SubDomain):
+    def inside(self, x, on_boundary):
+        return bool(on_boundary and x[0] < DOLFIN_EPS)
 
-    # Source term
-    class Source(Function):
-        def __init__(self, element, mesh):
-            Function.__init__(self, element, mesh)
-        def eval(self, values, x):
-            dx = x[0] - 0.5
-            dy = x[1] - 0.5
-            values[0] = 500.0*exp(-(dx*dx + dy*dy)/0.02)
+# Define variational problem
+v = TestFunction(element)
+u = TrialFunction(element)
+f = Source(element, mesh)
+g = Flux(element, mesh)
 
-    # Neumann boundary condition
-    class Flux(Function):
-        def __init__(self, element, mesh):
-            Function.__init__(self, element, mesh)
-        def eval(self, values, x):
-            if x[0] > DOLFIN_EPS:
-                values[0] = 25.0*sin(5.0*DOLFIN_PI*x[1])
-            else:
-                values[0] = 0.0
+a = dot(grad(v), grad(u))*dx
+L = v*f*dx + v*g*ds
 
-    # Sub domain for Dirichlet boundary condition
-    class DirichletBoundary(SubDomain):
-        def inside(self, x, on_boundary):
-            return bool(on_boundary and x[0] < DOLFIN_EPS)
+# Create backend
+backend = EpetraFactory.instance()
 
-    # Define variational problem
-    v = TestFunction(element)
-    u = TrialFunction(element)
-    f = Source(element, mesh)
-    g = Flux(element, mesh)
+# Assemble matrices
+A = assemble(a, mesh, backend=backend)
+b = assemble(L, mesh, backend=backend) 
 
-    a = dot(grad(v), grad(u))*dx
-    L = v*f*dx + v*g*ds
+# Define boundary condition
+u0 = Function(mesh, 0.0)
+boundary = DirichletBoundary()
+bc = DirichletBC(u0, mesh, boundary)
+bc.apply(A, b, a)
 
-    # Create backend
-    backend = EpetraFactory.instance()
+# Create solution vector (also used as start vector) 
+x = b.copy()
+x.zero()
 
-    # Assemble matrices
-    A = assemble(a, mesh, backend=backend)
-    b = assemble(L, mesh, backend=backend) 
+# Sets up the parameters for ML using a python dictionary
+MLList = {"max levels"        : 3, 
+          "output"            : 10,
+          "smoother: type"    : "ML symmetric Gauss-Seidel",
+          "aggregation: type" : "Uncoupled",
+          "ML validate parameter list" : False
+}
 
-    # Define boundary condition
-    u0 = Function(mesh, 0.0)
-    boundary = DirichletBoundary()
-    bc = DirichletBC(u0, mesh, boundary)
-    bc.apply(A, b, a)
+# Create the preconditioner 
+Prec = ML.MultiLevelPreconditioner(A.mat(), False)
+Prec.SetParameterList(MLList)
+Prec.ComputePreconditioner()
 
-    # Create solution vector (also used as start vector) 
-    x = b.copy()
-    x.zero()
+# Create solver and solve system 
+Solver = AztecOO.AztecOO(A.mat(), x.vec(), b.vec())
+Solver.SetPrecOperator(Prec)
+Solver.SetAztecOption(AztecOO.AZ_solver, AztecOO.AZ_cg)
+Solver.SetAztecOption(AztecOO.AZ_output, 16)
+Solver.Iterate(1550, 1e-5)
 
-    # Sets up the parameters for ML using a python dictionary
-    MLList = {"max levels"        : 3, 
-              "output"            : 10,
-              "smoother: type"    : "ML symmetric Gauss-Seidel",
-              "aggregation: type" : "Uncoupled",
-              "ML validate parameter list" : False
-    }
+# plot the solution
+U = Function(element, mesh, x)
+plot(U)
+interactive()
 
-    # Create the preconditioner 
-    Prec = ML.MultiLevelPreconditioner(A.mat(), False)
-    Prec.SetParameterList(MLList)
-    Prec.ComputePreconditioner()
+# Save solution to file
+file = File("poisson.pvd")
+file << U
 
-    # Create solver and solve system 
-    Solver = AztecOO.AztecOO(A.mat(), x.vec(), b.vec())
-    Solver.SetPrecOperator(Prec)
-    Solver.SetAztecOption(AztecOO.AZ_solver, AztecOO.AZ_cg)
-    Solver.SetAztecOption(AztecOO.AZ_output, 16)
-    Solver.Iterate(1550, 1e-5)
 
-    # plot the solution
-    U = Function(element, mesh, x)
-    plot(U)
-    interactive()
 
-    # Save solution to file
-    file = File("poisson.pvd")
-    file << U
-
-
-

References