I’m currently studying ways to integrate VTK into my electromagnetic solver. My main motivation for this is compatibility with paraview. I’ve actually managed to write valid XML with binary data myself without using VTK C++ library, but I wanted to try using it. The reason is the following: I am using SOA-type vectors, and want them to be displayed as such in paraview. I’ve found vtkSOADAtaArrayTemplate
which has method SetArray
and I was able to make it work with something like this:
// 2d mesh size
std::size_t nx = 10;
std::size_t ny = 10;
std::vector<double> fx(nx * ny);
std::vector<double> fy(nx * ny);
vtkNew<vtkSOADataArrayTemplate<double>> f;
f->SetName("f");
f->setNumberOfComponents(2);
f->setNumberOfTuples(nx * ny);
f->setArray(0, fx.data(), nx * ny, false, true);
f->setArray(0, fy.data(), nx * ny, false, true);
/*
Next code adds f to vtkImageData and saves with vtkXLMImageDataWriter
*/
So, questions:
- Is it overall a correct approach to use self-allocated memory?
- Am I safe in terms of memory management? Doesn’t vtk allocate additional memory before I pass my arrays to it? Doesn’t vtk try to delete my arrays itself?
- Is VTK as efficient in saving SOA arrays as with AOS?