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

Assemble two forms in one step

0 votes

Dear all,

I need something easy, in theory: assemble two forms. Let's say I have two RHS forms, and only one LHS, right now I have this code, assembling just one form:

// Init variables
A.reset(new dolfin::PETScMatrix());
b.reset(new dolfin::PETScVector());

// Init assembler
assembler_.reset(new dolfin::SystemAssembler(dolfin::reference_to_no_delete_pointer(lhs), dolfin::reference_to_no_delete_pointer(rhs), bcsptr));

// Initial assmebly
assembler_->assemble(*A);
assembler_->assemble(*b);

What if now I want to keep A, and assemble only another b with another form with the same BCs?

Thanks!

asked Jun 8, 2016 by senseiwa FEniCS User (2,620 points)

1 Answer

+1 vote
 
Best answer

You can use assembler class.

For instance, this works:

// Assemble LHS
dolfin::Assembler assembler;

assembler.assemble(*A, lhs);

// Apply BCs on A
for (auto &p : bcs_)
{
    p->apply(*A);
}

and then

assembler.assemble(*b, rhs);

// Apply BCs on b
for (auto &p : bcs_)
{
    p->apply(*b);
}
answered Jun 8, 2016 by gifo75 FEniCS Novice (650 points)
selected Jun 8, 2016 by senseiwa
...