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

Assemble only the time-dependet part of a bilinearfrom in timeloop and add this to a time-independet part (C++)

+2 votes

Hi all,

for time-dependent problems, there is a small PYTHON example (on the fenics webpage http://fenicsproject.org/documentation/tutorial/timedep.html resp. in the file d2_d2D.py) for handling bilinearforms where only the stiffness matrix is time-dependent and the mass matrix does not depend on time. As shown in the example, it is (of course) more efficient to assemble the time-independent part only once before going into the time loop, where the time-dependent part has to be assembled, and add both (assembled) parts together.

My question is now the following: Is there a similar way (or even an example how) to implement such a problem in CPP? To my understanding, I have to create two *.ufl files, one for each part (mass- and stiffness-matrix) of the bilinearform which are added to one matrix. Is this correct? However, I think there is no operation like adding to matrices available (yet), is this right?

Cheers,
mischa

asked Mar 12, 2014 by mischa FEniCS Novice (240 points)
edited Mar 12, 2014 by mischa

1 Answer

+1 vote
 
Best answer

Yes, you need to create two UFL files.

You should be able to add matrices (see `GenericMatrix::operator+=), but I haven't tested it.

You could also copy your 'fixed' matrix, and pass the copy to the assembler and set

assembler.add_values = true;

This way, the assembler will not zero the matrix that you pass in, but will just add to entries.

answered Mar 12, 2014 by Garth N. Wells FEniCS Expert (35,930 points)
selected Mar 13, 2014 by mischa

Thank you very much!

...