Replies: 2 comments
-
It looks like you are using ParaView to do the visualization. ParaView can use a data array for the normal vectors. This can be used to make the surface look much smoother. You can create a piecewise linear GridFunction whose values at the vertices are the averages of the normal vectors of the adjacent elements, and then use this array as the surface normal array in ParaView. H1_FECollection h1_fec(1, bdr_mesh.Dimension());
FiniteElementSpace h1_fes(&bdr_mesh, &h1_fec, bdr_mesh.SpaceDimension());
GridFunction normals(&h1_fes);
normals = 0.0;
Array<int> multiplicity(normals.Size());
multiplicity = 0;
for (int e = 0; e < bdr_mesh.GetNE(); ++e)
{
auto &T = *bdr_mesh.GetElementTransformation(e);
Array<int> vdofs;
h1_fes.GetElementVDofs(e, vdofs);
const auto &ir = h1_fes.GetFE(e)->GetNodes();
for (int i = 0; i < ir.Size(); ++i)
{
T.SetIntPoint(&ir[i]);
Vector normal_vector(bdr_mesh.SpaceDimension());
CalcOrtho(T.Jacobian(), normal_vector);
for (int d = 0; d < bdr_mesh.SpaceDimension(); ++d)
{
const int vd = vdofs[i + d*ir.Size()];
normals[vd] += normal_vector[d];
++multiplicity[vd];
}
}
}
for (int i = 0; i < normals.Size(); ++i)
{
normals[i] /= multiplicity[i];
}
ParaViewDataCollection pv("SmoothedSurface", &bdr_mesh);
pv.SetPrefixPath("ParaView");
pv.RegisterField("normals", &normals);
pv.SetCycle(0);
pv.SetTime(0.0);
pv.Save(); Without normal array: With normal array: The setting is here: |
Beta Was this translation helpful? Give feedback.
-
Yes, that works quite well. Here is the smoothed plot: Thanks for the quick help! Brian |
Beta Was this translation helpful? Give feedback.
-
I have generated a 2D triangular mesh in 3D space, calculated scalar values at the mesh vertices, and set a GridFunction with those values using an H1 finite element space with order=1 and dim=2. The results look like this:
I would like to smooth this plot to obtain a publication quality figure. I can certainly make the plot smoother by increasing the mesh density, but this gets to be very slow for a smooth-looking result. Is there a way within MFEM to apply smoothing to obtain a smooth plot from the coarser data?
Beta Was this translation helpful? Give feedback.
All reactions