This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

efficient solution of many patch problems

+4 votes

I have to assemble and solve a large number of local patch problems. This is (of course) very inefficient as done in the example below and becomes infeasible for larger meshes.
Is there a way to speed things up? Ideally, one would want to build more than one local problem in one call to assemble/solve. Maybe this could be achieved by identifying non-overlapping patches, defining a set of measures respectively etc. However, this seems rather complicated so I would be glad I there was another way to improve efficiency.

    from dolfin import *

    # setup
    mesh = UnitSquareMesh(50, 50)
    mesh.init()
    V = FunctionSpace(mesh, 'CG', 1)
    f = Constant(1.0)
    cf = CellFunction('size_t', mesh)

    # solve patch problems one after another, argh...
    for v in vertices(mesh):
      # mark patch
      cf.set_all(0)
      for cid in v.entities(2).tolist():
        cf[int(cid)] = 1

      # define restricted space
      restriction = Restriction(cf, 1)
      Vr = FunctionSpace(restriction, "CG", 1)

      # create patch element measure
      dx = Measure('dx')[cf]

      # define functions
      u = TrialFunction(Vr)
      v = TestFunction(Vr)

      # define forms
      a = dot(grad(u),grad(v))*dx(1)
      L = f*v*dx(1)

      # solve system
      # (doesn't make much sense like this, just for demonstration)
      u_local = Function(Vr)
      solve(a == L, u_local)
asked Mar 13, 2014 by meigel FEniCS User (1,520 points)
...