Unstructured moving mesh not displaying properly in ParaView

Hi all,

I am trying to visualise in ParaView an (initially structured) unstructured mesh that I have made from my own code, however, when I slice through the middle it displays the edges wrong. It seems to keep the old connectivity? However I know for a fact that those edges are not actually there. This only happens when I try to visualise the mesh in 3D. I have produced similar examples in 2D and it is fine. I am not sure why this is happening or how I can fix it.

It is a moving mesh and I am trying to visualise it at different stages. I have attached below what the mesh looks like (when slicing through the middle of the domain).

FinalMesh

Thanks in advance.

please share your data, both structured and unstructured if possible.

I have attached below a code snippet of how I output the unstructured mesh data. The same is used for the structured case, as the mesh initially is structured and then deforms into unstructured.

Side note: I have made a small MATLAB script that lets me plot a very small mesh to view if the connectivity is right and it displays as it should, however, when I view it Paraview it shows like the one above.

void OutputMesh(int ts, std::vector<Node> nodes, std::vector<Tetra> elements)
{
	std::stringstream ss;
	ss << "results/mesh_" << std::setfill('0') << std::setw(4) << ts + 1 << ".vtu";
	std::ofstream out(ss.str());
	if (!out.is_open())
	{
		std::cerr << "Failed to open file " << ss.str() << std::endl;
		exit(-1);
	}

	/*header*/
	out << "<?xml version=\"1.0\"?>\n";
	out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
	out << "<UnstructuredGrid>\n";
	out << "<Piece NumberOfPoints=\"" << nodes.size() << "\" NumberOfVerts=\"0\" NumberOfLines=\"0\" ";
	out << "NumberOfStrips=\"0\" NumberOfCells=\"" << elements.size() << "\">\n";

	/*points*/
	out << "<Points>\n";
	out << "<DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n";
	for (Node &node : nodes)
		out << node.pos[0] << " " << node.pos[1] << " " << node.pos[2] << "\n";
	out << "</DataArray>\n";
	out << "</Points>\n";

	/*Cells*/
	out << "<Cells>\n";
	out << "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
	for (Tetra &tetra : elements)
		out << tetra.con[0] << " " << tetra.con[1] << " " << tetra.con[2] << " " << tetra.con[3] << "\n";
	out << "</DataArray>\n";

	out << "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
	for (size_t e = 0; e < elements.size(); e++)
		out << (e + 1) * 4 << " ";
		//out << e << " ";
	out << "\n";
	out << "</DataArray>\n";

	out << "<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
	for (size_t e = 0; e < elements.size(); e++)
		out << "10 ";
	out << "\n";
	out << "</DataArray>\n";
	out << "</Cells>\n";

	/*save point data*/
	out << "<PointData Scalars=\"phi\">\n";
	out << "<DataArray type=\"Int32\" Name=\"node_index\" format=\"ascii\">\n";
	for (size_t n = 0; n < nodes.size(); n++)
		out << n << " ";
	out << "\n";
	out << "</DataArray>\n";
	///*
	out << "<DataArray type=\"Int32\" Name=\"node_type\" format=\"ascii\">\n";
	for (size_t n = 0; n < nodes.size(); n++)
		out << 0 << " ";
	out << "\n";
	out << "</DataArray>\n";
	//*/

	
	out << "<DataArray type=\"Float32\" Name=\"phi\" format=\"ascii\">\n";
	for (size_t n = 0; n < nodes.size(); n++)
		out << 0 << " ";
	out << "\n";
	out << "</DataArray>\n";

	out << "<DataArray type=\"Float32\" Name=\"ion_den\" format=\"ascii\">\n";
	for (size_t n = 0; n < nodes.size(); n++)
		out << 0 << " ";
	out << "\n";
	out << "</DataArray>\n";
	

	out << "</PointData>\n";

	/*save cell data*/
	out << "<CellData Vectors=\"ef\">\n";
	
	out << "<DataArray type=\"Float32\" NumberOfComponents=\"3\" Name=\"ef\" format=\"ascii\">\n";
	for (size_t e = 0; e < elements.size(); e++)
		out << 0 << " " << 0 << " " << 0 << " ";
	out << "\n";
	out << "</DataArray>\n";
	

	out << "<DataArray type=\"Float32\" Name=\"cell_volume\" format=\"ascii\">\n";
	for (Tetra &tet : elements)
		out << 0 << " ";
	out << "\n";
	out << "</DataArray>\n";

	out << "</CellData>\n";

	out << "</Piece>\n";
	out << "</UnstructuredGrid>\n";
	out << "</VTKFile>\n";

	out.close();
}

please share your data using a file sharing website

This is the .vtu file for a different mesh, but the exact same issue.

Link:

It looks likes your cells are not exactly aligned with the axes, resulting with these patterns in the slice.

Here are a few tetras I extracted from the mesh interior. one can see they are not aligned.

Is there any way in paraview to align the slicing plane with the tetras?

Your cells are all a bit over the place inside the volume, so there is no aligned plane possible.

When I check the initial mesh file in the “SpreadSheet View” the x,y,z coordinate of the nodes are correct, however, when one performs a slice, it modifies the y and z values slightly, which is what I believe is causing the issue. Is there anyway to prevent this? Otherwise, what would you advise to do in order to be able to visualise it?

This is not what I see at all:

As you can see, many point coordinates are not aligned with the same axes.