On 11/27/22 21:09, 'yy.wayne' via deal.II User Group wrote:
>
> Sorry that I forget to mention *it only breaks when runnning with MPI, run in
> serialization is good.* PersistentTriangulation Class may not address this error.
> The intention of write & read a mesh here is to create a not-to-coarse coarse
> grid (so it's refine several times before output).
> I read the output grid and expect all cells are on level = 0. Preserving the
> multigrid structure is not preferred in this case.
Oh, I misread your message then. What is the error you observe?
Looking at your code, when you have this...
if(Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
{
Triangulation<dim> tria_coarse;
GridGenerator::hyper_shell(tria_coarse,
center,
inner_r,
outer_r,
n_cells);
tria_coarse.refine_global(3);
// write and re-read the mesh, so it becomes coarse mesh
std::cout << "write mesh" << std::endl;
GridOut grid_out;
grid_out.set_flags(GridOutFlags::Vtu(true));
std::ofstream out("coarse_mesh.vtk");
grid_out.write_vtk(tria_coarse, out);
out.close();
}
{// read coarse grid
tria.clear();
std::cout << "read mesh" << std::endl;
GridIn<dim> gridin;
gridin.attach_triangulation(tria);
std::ifstream fin("coarse_mesh.vtk");
gridin.read_vtk(fin);
fin.close();
std::cout << "read mesh done" << std::endl;
}
...then you will need a MPI_Barrier between the two blocks to make sure that
process 1 doesn't start reading the file before process 0 has completed
writing it.