From: Wolfgang Bangerth Date: Thu, 16 Dec 2010 18:56:32 +0000 (+0000) Subject: DataOut was not prepared to deal with processors that have no locally owned cells... X-Git-Tag: v8.0.0~4683 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42e88dc7dd5e37c2752e681b88266583217f02cf;p=dealii.git DataOut was not prepared to deal with processors that have no locally owned cells at all. Once fixed, DataOutBase was not prepared to deal with no patches. Fix this. git-svn-id: https://svn.dealii.org/trunk@22976 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/source/base/data_out_base.cc b/deal.II/source/base/data_out_base.cc index 2ae5a1074a..aefae526a6 100644 --- a/deal.II/source/base/data_out_base.cc +++ b/deal.II/source/base/data_out_base.cc @@ -1909,8 +1909,26 @@ void DataOutBase::write_ucd (const std::vector > &patches, { AssertThrow (out, ExcIO()); +#ifndef DEAL_II_COMPILER_SUPPORTS_MPI + // verify that there are indeed + // patches to be written out. most + // of the times, people just forget + // to call build_patches when there + // are no patches, so a warning is + // in order. that said, the + // assertion is disabled if we + // support MPI since then it can + // happen that on the coarsest + // mesh, a processor simply has no + // cells it actually owns, and in + // that case it is legit if there + // are no patches Assert (patches.size() > 0, ExcNoPatches()); - +#else + if (patches.size() == 0) + return; +#endif + const unsigned int n_data_sets = data_names.size(); UcdStream ucd_out(out, flags); @@ -1990,7 +2008,25 @@ void DataOutBase::write_dx (const std::vector > &patches, { AssertThrow (out, ExcIO()); +#ifndef DEAL_II_COMPILER_SUPPORTS_MPI + // verify that there are indeed + // patches to be written out. most + // of the times, people just forget + // to call build_patches when there + // are no patches, so a warning is + // in order. that said, the + // assertion is disabled if we + // support MPI since then it can + // happen that on the coarsest + // mesh, a processor simply has no + // cells it actually owns, and in + // that case it is legit if there + // are no patches Assert (patches.size() > 0, ExcNoPatches()); +#else + if (patches.size() == 0) + return; +#endif // Stream with special features for dx output DXStream dx_out(out, flags); @@ -2256,8 +2292,26 @@ void DataOutBase::write_gnuplot (const std::vector > &patche { AssertThrow (out, ExcIO()); +#ifndef DEAL_II_COMPILER_SUPPORTS_MPI + // verify that there are indeed + // patches to be written out. most + // of the times, people just forget + // to call build_patches when there + // are no patches, so a warning is + // in order. that said, the + // assertion is disabled if we + // support MPI since then it can + // happen that on the coarsest + // mesh, a processor simply has no + // cells it actually owns, and in + // that case it is legit if there + // are no patches Assert (patches.size() > 0, ExcNoPatches()); - +#else + if (patches.size() == 0) + return; +#endif + const unsigned int n_data_sets = data_names.size(); // write preamble @@ -2473,7 +2527,25 @@ void DataOutBase::write_povray (const std::vector > &patches { AssertThrow (out, ExcIO()); +#ifndef DEAL_II_COMPILER_SUPPORTS_MPI + // verify that there are indeed + // patches to be written out. most + // of the times, people just forget + // to call build_patches when there + // are no patches, so a warning is + // in order. that said, the + // assertion is disabled if we + // support MPI since then it can + // happen that on the coarsest + // mesh, a processor simply has no + // cells it actually owns, and in + // that case it is legit if there + // are no patches Assert (patches.size() > 0, ExcNoPatches()); +#else + if (patches.size() == 0) + return; +#endif Assert (dim==2, ExcNotImplemented()); // only for 2-D surfaces on a 2-D plane Assert (spacedim==2, ExcNotImplemented()); @@ -2819,8 +2891,26 @@ void DataOutBase::write_eps (const std::vector > &patches, { Assert (out, ExcIO()); +#ifndef DEAL_II_COMPILER_SUPPORTS_MPI + // verify that there are indeed + // patches to be written out. most + // of the times, people just forget + // to call build_patches when there + // are no patches, so a warning is + // in order. that said, the + // assertion is disabled if we + // support MPI since then it can + // happen that on the coarsest + // mesh, a processor simply has no + // cells it actually owns, and in + // that case it is legit if there + // are no patches Assert (patches.size() > 0, ExcNoPatches()); - +#else + if (patches.size() == 0) + return; +#endif + // Do not allow volume rendering AssertThrow (dim==2, ExcNotImplemented()); @@ -3181,8 +3271,27 @@ void DataOutBase::write_gmv (const std::vector > &patches, { Assert(dim<=3, ExcNotImplemented()); AssertThrow (out, ExcIO()); + +#ifndef DEAL_II_COMPILER_SUPPORTS_MPI + // verify that there are indeed + // patches to be written out. most + // of the times, people just forget + // to call build_patches when there + // are no patches, so a warning is + // in order. that said, the + // assertion is disabled if we + // support MPI since then it can + // happen that on the coarsest + // mesh, a processor simply has no + // cells it actually owns, and in + // that case it is legit if there + // are no patches Assert (patches.size() > 0, ExcNoPatches()); - +#else + if (patches.size() == 0) + return; +#endif + GmvStream gmv_out(out, flags); const unsigned int n_data_sets = data_names.size(); // check against # of data sets in @@ -3317,8 +3426,26 @@ void DataOutBase::write_tecplot (const std::vector > &patche { AssertThrow (out, ExcIO()); +#ifndef DEAL_II_COMPILER_SUPPORTS_MPI + // verify that there are indeed + // patches to be written out. most + // of the times, people just forget + // to call build_patches when there + // are no patches, so a warning is + // in order. that said, the + // assertion is disabled if we + // support MPI since then it can + // happen that on the coarsest + // mesh, a processor simply has no + // cells it actually owns, and in + // that case it is legit if there + // are no patches Assert (patches.size() > 0, ExcNoPatches()); - +#else + if (patches.size() == 0) + return; +#endif + TecplotStream tecplot_out(out, flags); const unsigned int n_data_sets = data_names.size(); @@ -3590,8 +3717,26 @@ void DataOutBase::write_tecplot_binary (const std::vector > AssertThrow (out, ExcIO()); +#ifndef DEAL_II_COMPILER_SUPPORTS_MPI + // verify that there are indeed + // patches to be written out. most + // of the times, people just forget + // to call build_patches when there + // are no patches, so a warning is + // in order. that said, the + // assertion is disabled if we + // support MPI since then it can + // happen that on the coarsest + // mesh, a processor simply has no + // cells it actually owns, and in + // that case it is legit if there + // are no patches Assert (patches.size() > 0, ExcNoPatches()); - +#else + if (patches.size() == 0) + return; +#endif + const unsigned int n_data_sets = data_names.size(); // check against # of data sets in // first patch. checks against all @@ -3883,8 +4028,26 @@ DataOutBase::write_vtk (const std::vector > &patches, { AssertThrow (out, ExcIO()); +#ifndef DEAL_II_COMPILER_SUPPORTS_MPI + // verify that there are indeed + // patches to be written out. most + // of the times, people just forget + // to call build_patches when there + // are no patches, so a warning is + // in order. that said, the + // assertion is disabled if we + // support MPI since then it can + // happen that on the coarsest + // mesh, a processor simply has no + // cells it actually owns, and in + // that case it is legit if there + // are no patches Assert (patches.size() > 0, ExcNoPatches()); - +#else + if (patches.size() == 0) + return; +#endif + VtkStream vtk_out(out, flags); const unsigned int n_data_sets = data_names.size(); @@ -4116,8 +4279,26 @@ DataOutBase::write_vtu (const std::vector > &patches, { AssertThrow (out, ExcIO()); +#ifndef DEAL_II_COMPILER_SUPPORTS_MPI + // verify that there are indeed + // patches to be written out. most + // of the times, people just forget + // to call build_patches when there + // are no patches, so a warning is + // in order. that said, the + // assertion is disabled if we + // support MPI since then it can + // happen that on the coarsest + // mesh, a processor simply has no + // cells it actually owns, and in + // that case it is legit if there + // are no patches Assert (patches.size() > 0, ExcNoPatches()); - +#else + if (patches.size() == 0) + return; +#endif + VtuStream vtu_out(out, flags); const unsigned int n_data_sets = data_names.size(); @@ -5125,6 +5306,7 @@ merge (const DataOutReader &source) { typedef typename dealii::DataOutBase::Patch Patch; + const std::vector source_patches = source.get_patches (); Assert (patches.size () != 0, ExcNoPatches ()); Assert (source_patches.size () != 0, ExcNoPatches ()); diff --git a/deal.II/source/numerics/data_out.cc b/deal.II/source/numerics/data_out.cc index d72ff30abb..b1467ebd1c 100644 --- a/deal.II/source/numerics/data_out.cc +++ b/deal.II/source/numerics/data_out.cc @@ -983,13 +983,17 @@ void DataOut::build_patches (const Mapping > all_cells; { // set the index of the first - // cell. if first_locally_owned_cell/next_locally_owned_cell + // cell. if + // first_locally_owned_cell / + // next_locally_owned_cell // returns non-active cells, then // the index is not usable // anyway, but otherwise we // should keep track where we are unsigned int index; - if (first_locally_owned_cell()->has_children()) + if ((first_locally_owned_cell() == this->dofs->end()) + || + (first_locally_owned_cell()->has_children())) index = 0; else index = std::distance (this->dofs->begin_active(), diff --git a/tests/mpi/p4est_data_out_01.cc b/tests/mpi/p4est_data_out_01.cc new file mode 100644 index 0000000000..23c15fb15f --- /dev/null +++ b/tests/mpi/p4est_data_out_01.cc @@ -0,0 +1,107 @@ +//--------------------------------------------------------------------------- +// $Id: 2d_coarse_grid_01.cc 17444 2008-10-31 19:35:14Z bangerth $ +// Version: $Name$ +// +// Copyright (C) 2009, 2010 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- + + +// create a parallel DoFHandler and output data on a single +// cell. DataOut was not prepared to handle situations where a +// processor has no active cells at all. + +#include "../tests.h" +#include "coarse_grid_common.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + + +template +void test() +{ + unsigned int myid = Utilities::System::get_this_mpi_process (MPI_COMM_WORLD); + + if (Utilities::System::get_this_mpi_process (MPI_COMM_WORLD) == 0) + deallog << "hyper_cube" << std::endl; + + parallel::distributed::Triangulation tr(MPI_COMM_WORLD); + + GridGenerator::hyper_cube(tr); + DoFHandler dofh(tr); + + static const FE_Q fe(2); + dofh.distribute_dofs (fe); + + DataOut data_out; + data_out.attach_dof_handler (dofh); + + TrilinosWrappers::MPI::Vector x; + x.reinit(dofh.locally_owned_dofs(), MPI_COMM_WORLD); + x=2.0; + + data_out.add_data_vector (x, "x"); + data_out.build_patches (); + + if (myid==0) + { + for (unsigned int i=0; i(); + deallog.pop(); + } + else + test<2>(); + +#ifdef DEAL_II_COMPILER_SUPPORTS_MPI + MPI_Finalize(); +#endif +} diff --git a/tests/mpi/p4est_data_out_01/ncpu_10/cmp/generic b/tests/mpi/p4est_data_out_01/ncpu_10/cmp/generic new file mode 100644 index 0000000000..3cdf9a9098 --- /dev/null +++ b/tests/mpi/p4est_data_out_01/ncpu_10/cmp/generic @@ -0,0 +1,12 @@ + +DEAL:0:2d::hyper_cube +DEAL:0:2d::0 +DEAL:0:2d::0 +DEAL:0:2d::0 +DEAL:0:2d::0 +DEAL:0:2d::0 +DEAL:0:2d::0 +DEAL:0:2d::0 +DEAL:0:2d::0 +DEAL:0:2d::0 +DEAL:0:2d::9 diff --git a/tests/mpi/p4est_data_out_01/ncpu_4/cmp/generic b/tests/mpi/p4est_data_out_01/ncpu_4/cmp/generic new file mode 100644 index 0000000000..f884b80ca0 --- /dev/null +++ b/tests/mpi/p4est_data_out_01/ncpu_4/cmp/generic @@ -0,0 +1,6 @@ + +DEAL:0:2d::hyper_cube +DEAL:0:2d::0 +DEAL:0:2d::0 +DEAL:0:2d::0 +DEAL:0:2d::9