-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PrintVTK/SaveVTK #1398
Comments
Hi @NikolayYavich, When you set Hope this helps. |
Hi @pazner , Thanks a lot for the answer. |
There is not currently a way to output a GridFunction in VTK format without duplicated points. If the file size is the main concern, you can try using the ParaViewDataCollection with binary compression enabled, which should generate much smaller files. |
If you're specifically using linear finite elements as in your example, then you can use The following function will write a linear GridFunction in VTK format defined on such a mesh (not this will not work if you use finite elements with order greater than 1): void SaveLinearGridFunctionVTK(const GridFunction &gf, std::ostream &out,
const std::string &field_name)
{
const FiniteElementSpace *fes = gf.FESpace();
Mesh *mesh = fes->GetMesh();
Vector val;
DenseMatrix vval, pmat;
int vec_dim = gf.VectorDim();
MFEM_VERIFY(gf.Size()/vec_dim == mesh->GetNV(),
"GridFunction must have as many dofs as mesh vertices");
out << "POINT_DATA " << fes->GetNDofs() << '\n' << flush;
if (vec_dim == 1)
{
// scalar data
out << "SCALARS " << field_name << " double 1\n"
<< "LOOKUP_TABLE default\n";
for (int i=0; i < fes->GetNDofs(); ++i)
{
out << gf[i] << '\n';
}
}
else if ((vec_dim == 2 || vec_dim == 3) && mesh->SpaceDimension() > 1)
{
// vector data
out << "VECTORS " << field_name << " double\n";
Array<int> vdofs(vec_dim);
for (int i=0; i < fes->GetNDofs(); ++i)
{
vdofs.SetSize(1);
vdofs[0] = i;
fes->DofsToVDofs(vdofs);
out << gf[vdofs[0]] << ' ' << gf[vdofs[1]] << ' ';
if (vec_dim == 2)
{
out << 0.0;
}
else
{
out << gf[vdofs[2]];
}
out << '\n';
}
}
else
{
// other data: save the components as separate scalars
for (int vd = 0; vd < vec_dim; vd++)
{
out << "SCALARS " << field_name << vd << " double 1\n"
<< "LOOKUP_TABLE default\n";
Array<int> vdofs(vec_dim);
for (int i=0; i < fes->GetNDofs(); ++i)
{
vdofs.SetSize(1);
vdofs[0] = i;
fes->DofsToVDofs(vdofs);
out << gf[vdofs[vd]] << '\n';
}
}
}
out.flush();
} |
Hi @pazner Thanks a lot for the detailed answers, I'll check these options out. |
Dear All,
I carefully reviewed #797 and #558 before posting this.
My question is how to avoid refinement and extra points when exporting a field
modelled with linear elements to a VTK file.
From the mention posts it follows that setting ref = 1 in PrintVTK and SaveVTK does this.
However, this simple code bellow shows that this is not the case.
When I check the generated VTK file I see:
$ grep "POINTS" saving_test.vtk POINTS 3000 double
while the correct number of vertices in this example is 216.
Will appreciate any hint,
Thanks,
Nikolay.
The text was updated successfully, but these errors were encountered: