← Back to team overview

dolfin team mailing list archive

LinearPDE invalidates function

 

Hello,

I have struggled today with a mysterious problem. It occurred in my solver, where the assembly and linear algebra happens in a different function from the output. The Function that holds the data after the call to pde.solve(u) seems to be invalidated after the LinearSolver goes out of scope.

To illustrate what I mean, I made a small modification to the Poisson demo:

  PoissonBilinearForm a;
  PoissonLinearForm L(f, g);
  LinearPDE* pde = new LinearPDE(a, L, mesh, bc); // dynamic allocation

  // Solve PDE
  Function u;
  pde->solve(u);

  // Save solution to file
  File file("poisson.pvd");
  file << u;                             // this works

  delete pde;                            // pde goes out of scope

  File file2("poisson2.pvd");
  file2 << u;                            // segfault here

I do realize that the destructor in LinearPDE does not delete the pointer!

  Dag


Follow ups