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

optimization: avoiding assembly in a mixed function space

0 votes

Basically, I want to know how to extract a vector from ListTensor object or Indexed object.
He's a minimal code.

What I was trying to do is similar to the calculation of b in this demo.

from dolfin import *

mesh = UnitSquareMesh(32, 32)

V = VectorFunctionSpace(mesh, "CG", 1, dim=2)
W = FunctionSpace(mesh, "CG", 1) 
X = FunctionSpace(mesh, "CG", 1)
VWX = MixedFunctionSpace([V, W, X])  # mixed functions space

# Define trail and test functions
du_ = TrialFunction(VWX)
v_u, v_p, v_c = TestFunctions(VWX)

# define functions
u_ = Function(VWX)  # current solution
u0_ = Function(VWX)  # solution from previous step

# Split mixed functions
du, dp, dc = split(du_)
u, p, c = split(u_)
u0, p0, c0 = split(u0_)

a = inner(u, v_u)*dx
A = assemble(a)

# Class representing the initial conditions
class InitialConditions(Expression):
    def __init__(self):
        pass

    def eval(self, values, x):
        values[0] = 0
        values[1] = 0
        values[2] = 0
        values[3] = 0.01

    def value_shape(self):
        return (4,)

# Create initial conditions and interpolate
u_init_ = InitialConditions()

u_.interpolate(u_init_)
u0_.interpolate(u_init_)
t = 0
dt = 0.01

while (t < 1):
    b = A*u.vector()  # doesn't work!
asked Feb 21, 2014 by bshankar FEniCS Novice (790 points)
edited Feb 22, 2014 by bshankar

Your line "A = A*u.vector()" does not make much sense to me. Can you please be more specific on what you are trying to accomplish?

updated. thanks!

1 Answer

+2 votes

You want to access a DOLFIN SubFunction. u in your code is a UFL SubCoefficient. You need to use u_.split(deepcopy=True)[0].

The problem of distinguishing split(foo) and foo.split() is a know issue in DOLFIN.

answered Feb 24, 2014 by johanhake FEniCS Expert (22,480 points)
...