From: Wolfgang Bangerth Date: Tue, 6 Dec 2016 02:19:41 +0000 (-0700) Subject: Also extract the functionality of the write_pvtu_record(). X-Git-Tag: v8.5.0-rc1~343^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3658%2Fhead;p=dealii.git Also extract the functionality of the write_pvtu_record(). Move it to the DataOutBase namespace, and let the original function call the one into which it has been refactored. --- diff --git a/include/deal.II/base/data_out_base.h b/include/deal.II/base/data_out_base.h index 2796d5df92..9e4d8b543d 100644 --- a/include/deal.II/base/data_out_base.h +++ b/include/deal.II/base/data_out_base.h @@ -1708,14 +1708,14 @@ namespace DataOutBase const VtkFlags &flags); /** - * This writes the footer for the xml based vtu file format. This routine is + * This function writes the footer for the xml based vtu file format. This routine is * used internally together with DataOutInterface::write_vtu_header() and * DataOutInterface::write_vtu_main() by DataOutBase::write_vtu(). */ void write_vtu_footer (std::ostream &out); /** - * This writes the main part for the xml based vtu file format. This routine + * This function writes the main part for the xml based vtu file format. This routine * is used internally together with DataOutInterface::write_vtu_header() and * DataOutInterface::write_vtu_footer() by DataOutBase::write_vtu(). */ @@ -1726,6 +1726,53 @@ namespace DataOutBase const VtkFlags &flags, std::ostream &out); + /** + * Some visualization programs, such as ParaView, can read several separate + * VTU files that all form part of the same simulation, in order to + * parallelize visualization. In that case, you need a + * .pvtu file that describes which VTU files (written, for + * example, through the DataOutInterface::write_vtu() function) form a group. + * The current function can generate such a master record. + * + * This function is typically not called by itself from user space, but + * you may want to call it through DataOutInterface::write_pvtu_record() + * since the DataOutInterface class has access to information that you + * would have to provide to the current function by hand. + * + * In any case, whether this function is called directly or via + * DataOutInterface::write_pvtu_record(), the master record file so + * written contains a list of (scalar or vector) fields that describes which + * fields can actually be found in the individual files that comprise the set of + * parallel VTU files along with the names of these files. This function + * gets the names and types of fields through the third and fourth + * argument; you can determine these by hand, but in practice, this function + * is most easily called by calling DataOutInterfaces::write_pvtu_record(), + * which determines the last two arguments by calling + * DataOutInterface::get_dataset_names() and + * DataOutInterface::get_vector_data_ranges() functions. The second argument + * to this function specifies the names of the files that form the parallel + * set. + * + * @note Use DataOutBase::write_vtu() and DataOutInterface::write_vtu() + * for writing each piece. Also note that + * only one parallel process needs to call the current function, listing the + * names of the files written by all parallel processes. + * + * @note In order to tell Paraview to group together multiple + * pvtu files that each describe one time step of a time + * dependent simulation, see the DataOutBase::write_pvd_record() + * function. + * + * @note Older versions of VisIt (before 2.5.1), can not read + * pvtu records. However, it can read visit records as written + * by the write_visit_record() function. + */ + void + write_pvtu_record (std::ostream &out, + const std::vector &piece_names, + const std::vector &data_names, + const std::vector > &vector_data_ranges); + /** * In ParaView it is possible to visualize time-dependent data tagged with * the current integration time of a time dependent simulation. To use this @@ -1764,7 +1811,8 @@ namespace DataOutBase * } * @endcode * - * @note See DataOutInterface::write_vtu or DataOutInterface::write_pvtu_record + * @note See DataOutInterface::write_vtu, DataOutInterface::write_pvtu_record, + * and DataOutInterface::write_vtu_in_parallel * for writing solutions at each timestep. * * @note The second element of each pair, i.e., the file in which the @@ -2271,24 +2319,28 @@ public: * performance on parallel filesystems. Also see * DataOutInterface::write_vtu(). */ - void write_vtu_in_parallel (const char *filename, MPI_Comm comm) const; + void write_vtu_in_parallel (const char *filename, + MPI_Comm comm) const; /** * Some visualization programs, such as ParaView, can read several separate - * VTU files to parallelize visualization. In that case, you need a + * VTU files that all form part of the same simulation, in order to + * parallelize visualization. In that case, you need a * .pvtu file that describes which VTU files (written, for - * example, through the write_vtu() function) form a group. The current - * function can generate such a master record. + * example, through the DataOutInterface::write_vtu() function) form a group. + * The current function can generate such a master record. * - * The file so written contains a list of (scalar or vector) fields whose - * values are described by the individual files that comprise the set of + * The master record file generated by this function + * contains a list of (scalar or vector) fields that describes which + * fields can actually be found in the individual files that comprise the set of * parallel VTU files along with the names of these files. This function - * gets the names and types of fields through the get_patches() function of - * this class like all the other write_xxx() functions. The second argument + * gets the names and types of fields through the get_dataset_names() and + * get_vector_data_ranges() functions of this class. The second argument * to this function specifies the names of the files that form the parallel * set. * - * @note See DataOutBase::write_vtu for writing each piece. Also note that + * @note Use DataOutBase::write_vtu() and DataOutInterface::write_vtu() + * for writing each piece. Also note that * only one parallel process needs to call the current function, listing the * names of the files written by all parallel processes. * @@ -2296,7 +2348,7 @@ public: * * @note In order to tell Paraview to group together multiple * pvtu files that each describe one time step of a time - * dependent simulation, see the DataOutInterface::write_pvd_record() + * dependent simulation, see the DataOutBase::write_pvd_record() * function. * * @note Older versions of VisIt (before 2.5.1), can not read diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 53ba05fc3c..dcf22b3723 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -5318,6 +5318,102 @@ namespace DataOutBase } + + void + write_pvtu_record (std::ostream &out, + const std::vector &piece_names, + const std::vector &data_names, + const std::vector > &vector_data_ranges) + { + AssertThrow (out, ExcIO()); + + const unsigned int n_data_sets = data_names.size(); + + out << "\n"; + + out << "\n"; + + out << "\n"; + out << " \n"; + out << " \n"; + + // We need to output in the same order as + // the write_vtu function does: + std::vector data_set_written (n_data_sets, false); + for (unsigned int n_th_vector=0; n_th_vector(vector_data_ranges[n_th_vector]) >= + std_cxx11::get<0>(vector_data_ranges[n_th_vector]), + ExcLowerRange (std_cxx11::get<1>(vector_data_ranges[n_th_vector]), + std_cxx11::get<0>(vector_data_ranges[n_th_vector]))); + AssertThrow (std_cxx11::get<1>(vector_data_ranges[n_th_vector]) < n_data_sets, + ExcIndexRange (std_cxx11::get<1>(vector_data_ranges[n_th_vector]), + 0, n_data_sets)); + AssertThrow (std_cxx11::get<1>(vector_data_ranges[n_th_vector]) + 1 + - std_cxx11::get<0>(vector_data_ranges[n_th_vector]) <= 3, + ExcMessage ("Can't declare a vector with more than 3 components " + "in VTK")); + + // mark these components as already + // written: + for (unsigned int i=std_cxx11::get<0>(vector_data_ranges[n_th_vector]); + i<=std_cxx11::get<1>(vector_data_ranges[n_th_vector]); + ++i) + data_set_written[i] = true; + + // write the + // header. concatenate all the + // component names with double + // underscores unless a vector + // name has been specified + out << " (vector_data_ranges[n_th_vector]) != "") + out << std_cxx11::get<2>(vector_data_ranges[n_th_vector]); + else + { + for (unsigned int i=std_cxx11::get<0>(vector_data_ranges[n_th_vector]); + i(vector_data_ranges[n_th_vector]); + ++i) + out << data_names[i] << "__"; + out << data_names[std_cxx11::get<1>(vector_data_ranges[n_th_vector])]; + } + + out << "\" NumberOfComponents=\"3\" format=\"ascii\"/>\n"; + } + + for (unsigned int data_set=0; data_set\n"; + } + + out << " \n"; + + out << " \n"; + out << " \n"; + out << " \n"; + + for (unsigned int i=0; i\n"; + + out << " \n"; + out << "\n"; + + out.flush(); + + // assert the stream is still ok + AssertThrow (out, ExcIO()); + } + + + void write_pvd_record (std::ostream &out, const std::vector > ×_and_names) @@ -6332,95 +6428,10 @@ void DataOutInterface::write_pvtu_record (std::ostream &out, const std::vector &piece_names) const { - AssertThrow (out, ExcIO()); - - const std::vector data_names = get_dataset_names(); - const std::vector > vector_data_ranges - = get_vector_data_ranges(); - - const unsigned int n_data_sets = data_names.size(); - - out << "\n"; - - out << "\n"; - - out << "\n"; - out << " \n"; - out << " \n"; - - // We need to output in the same order as - // the write_vtu function does: - std::vector data_set_written (n_data_sets, false); - for (unsigned int n_th_vector=0; n_th_vector(vector_data_ranges[n_th_vector]) >= - std_cxx11::get<0>(vector_data_ranges[n_th_vector]), - ExcLowerRange (std_cxx11::get<1>(vector_data_ranges[n_th_vector]), - std_cxx11::get<0>(vector_data_ranges[n_th_vector]))); - AssertThrow (std_cxx11::get<1>(vector_data_ranges[n_th_vector]) < n_data_sets, - ExcIndexRange (std_cxx11::get<1>(vector_data_ranges[n_th_vector]), - 0, n_data_sets)); - AssertThrow (std_cxx11::get<1>(vector_data_ranges[n_th_vector]) + 1 - - std_cxx11::get<0>(vector_data_ranges[n_th_vector]) <= 3, - ExcMessage ("Can't declare a vector with more than 3 components " - "in VTK")); - - // mark these components as already - // written: - for (unsigned int i=std_cxx11::get<0>(vector_data_ranges[n_th_vector]); - i<=std_cxx11::get<1>(vector_data_ranges[n_th_vector]); - ++i) - data_set_written[i] = true; - - // write the - // header. concatenate all the - // component names with double - // underscores unless a vector - // name has been specified - out << " (vector_data_ranges[n_th_vector]) != "") - out << std_cxx11::get<2>(vector_data_ranges[n_th_vector]); - else - { - for (unsigned int i=std_cxx11::get<0>(vector_data_ranges[n_th_vector]); - i(vector_data_ranges[n_th_vector]); - ++i) - out << data_names[i] << "__"; - out << data_names[std_cxx11::get<1>(vector_data_ranges[n_th_vector])]; - } - - out << "\" NumberOfComponents=\"3\" format=\"ascii\"/>\n"; - } - - for (unsigned int data_set=0; data_set\n"; - } - - out << " \n"; - - out << " \n"; - out << " \n"; - out << " \n"; - - for (unsigned int i=0; i\n"; - - out << " \n"; - out << "\n"; - - out.flush(); - - // assert the stream is still ok - AssertThrow (out, ExcIO()); + DataOutBase::write_pvtu_record(out, + piece_names, + get_dataset_names(), + get_vector_data_ranges()); }