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

Assembling form in two steps

0 votes

Hello

I have a form

F = F1 + F2

where

F1 = independent of time
F2 = depends on time

So I want to assemble F1 only once. I try the following

V = VectorFunctionSpace(mesh, 'CG', udeg)
W = FunctionSpace(mesh, 'CG', pdeg)
X = V * W
u,p = TrialFunctions(X)
v,q = TestFunctions(X)
F1 = idt*inner(1.5*u - 2.0*u1 + 0.5*u0, v)*dx  \
       - p*div(v)*dx                               \
       + nu*inner(grad(u), grad(v))*dx             \
       - q*div(u)*dx
F2 = inner(grad(u)*uext, v)*dx

a  = lhs(F1)
L  = rhs(F1)

# This matrix is independent of time
A1 = PETScMatrix()
assemble(a, tensor=A1)

A  = PETScMatrix()
solver = LUSolver(A)
solver.parameters['same_nonzero_pattern'] = True

while t < Tf:
    A = A1.copy()
    assemble(F2, tensor=A, reset_sparsity=False, add_values=True)

But this gives error

*** Error: Unable to solve linear system using PETSc LU solver.
*** Reason: Cannot factorize non-square PETSc matrix.
*** Where: This error was encountered inside PETScLUSolver.cpp.
*** Process: 0

How to achieve this type of assembly ?

asked Jan 7, 2015 by praveen FEniCS User (2,760 points)
edited Jan 8, 2015 by praveen

You need to post a complete example.

I have added more details which should make the situation clear. But it is not complete code which will run.

...