← Back to team overview

dolfin team mailing list archive

Re: [Question #116136]: Double Free on Writing to File

 

Question #116136 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/116136

    Status: Answered => Open

Pietro Maximoff is still having a problem:
I assumed/assume the call  to 'new' in 
         xy = new Array<double>(dim, geometry.x(vertex->index()));
would be freed as the Array class has a destructor.

But the main problem seems to be writing to the output to VTK file

                 *** glibc detected *** ./colour_mesh: double free or
corruption (out):

Also, if I create a MATLAB output file, instead of a  VTK output file,
it works fine, i.e.,

File file("out.m"); 
file << u.vector();


What I've essentially tried to do in the code is:

Load a 2D mesh (shape of a doughnut).
For every vertex in the mesh,  if it's within a certain distance, the solution at that vertex is output as 20 otherwise as -86. 

I've used a vector to gather the individual entries and then converted
it to a function for output. Please let me know If there's a more
efficient way.

Thanks.

Pietro

===========

Vector temp(mesh.num_vertices());
double block[mesh.num_vertices()];
dolfin::uint rows[mesh.num_vertices()];

int i = 0;
 for (VertexIterator vertex(mesh); !vertex.end(); ++vertex) {
  xy = new Array<double>(dim, geometry.x(vertex->index()));
  x0 = (*xy)[0];
  x1 = (*xy)[1]; 

  if (sqrt(x0*x0 + x1*x1) < 21.5)
     block[i] = 20;;
  else
    block[i] = -86;

 ++i;
 }

 // Indices of the row of the vector to set --- ALL indices
 for (unsigned int i = 0; i < mesh.num_vertices(); ++i)
            rows[i] = i;

 // Output file in VTK format
 File file("out.pvd");

 temp.set(block, mesh.num_vertices(), rows);
 Function u(V, temp);

 file << u;

 plot(u);

You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.



Follow ups