]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Update tutorials to use write_vtu_with_pvtu_record
authorPeter Munch <peterrmuench@gmail.com>
Fri, 25 Oct 2019 23:51:26 +0000 (01:51 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Mon, 28 Oct 2019 21:14:11 +0000 (22:14 +0100)
examples/step-18/step-18.cc
examples/step-32/step-32.cc
examples/step-37/step-37.cc
examples/step-40/step-40.cc
examples/step-42/step-42.cc
examples/step-45/step-45.cc
examples/step-48/step-48.cc
examples/step-55/step-55.cc
examples/step-64/step-64.cu

index f8a8129214c0cd5eba48ca81cf2dd754e94611c4..b2289a0dd85ddc75e86beece6778e2349e9eba00 100644 (file)
@@ -1271,59 +1271,14 @@ namespace Step18
     // all these solution and other data vectors:
     data_out.build_patches();
 
-
-    // Let us determine the name of the file we will want to write it to. We
-    // compose it of the prefix <code>solution-</code>, followed by the time
-    // step number, and finally the processor id (encoded as a three digit
-    // number):
-    std::string filename =
-      "solution-" + Utilities::int_to_string(timestep_no, 4) + "." +
-      Utilities::int_to_string(this_mpi_process, 3) + ".vtu";
-
-    // The following assertion makes sure that there are less than 1000
-    // processes (a very conservative check, but worth having anyway) as our
-    // scheme of generating process numbers would overflow if there were 1000
-    // processes or more. Note that we choose to use <code>AssertThrow</code>
-    // rather than <code>Assert</code> since the number of processes is a
-    // variable that depends on input files or the way the process is started,
-    // rather than static assumptions in the program code. Therefore, it is
-    // inappropriate to use <code>Assert</code> that is optimized away in
-    // optimized mode, whereas here we actually can assume that users will run
-    // the largest computations with the most processors in optimized mode,
-    // and we should check our assumptions in this particular case, and not
-    // only when running in debug mode:
-    AssertThrow(n_mpi_processes < 1000, ExcNotImplemented());
-
-    // With the so-completed filename, let us open a file and write the data
-    // we have generated into it:
-    std::ofstream output(filename);
-    data_out.write_vtu(output);
+    // Let us open a file and write the data we have generated into it:
+    const auto pvtu_master_filename = data_out.write_vtu_with_pvtu_record(
+      "./", "solution-", timestep_no, 4, mpi_communicator);
 
     // The record files must be written only once and not by each processor,
     // so we do this on processor 0:
     if (this_mpi_process == 0)
       {
-        // Here we collect all filenames of the current timestep (same format as
-        // above)
-        std::vector<std::string> filenames;
-        for (unsigned int i = 0; i < n_mpi_processes; ++i)
-          filenames.push_back("solution-" +
-                              Utilities::int_to_string(timestep_no, 4) + "." +
-                              Utilities::int_to_string(i, 3) + ".vtu");
-
-        // Now we write the .visit file. The naming is similar to the .vtu
-        // files, only that the file obviously doesn't contain a processor id.
-        const std::string visit_master_filename =
-          ("solution-" + Utilities::int_to_string(timestep_no, 4) + ".visit");
-        std::ofstream visit_master(visit_master_filename);
-        DataOutBase::write_visit_record(visit_master, filenames);
-
-        // Similarly, we write the paraview .pvtu:
-        const std::string pvtu_master_filename =
-          ("solution-" + Utilities::int_to_string(timestep_no, 4) + ".pvtu");
-        std::ofstream pvtu_master(pvtu_master_filename);
-        data_out.write_pvtu_record(pvtu_master, filenames);
-
         // Finally, we write the paraview record, that references all .pvtu
         // files and their respective time. Note that the variable
         // times_and_names is declared static, so it will retain the entries
index 9f402a376989f270b032a91040ec506b654c1839..cc0998670130bdfda50b12d56dabe22702703c31 100644 (file)
@@ -3243,41 +3243,9 @@ namespace Step32
     data_out.add_data_vector(locally_relevant_joint_solution, postprocessor);
     data_out.build_patches();
 
-    static int        out_index = 0;
-    const std::string filename =
-      ("solution-" + Utilities::int_to_string(out_index, 5) + "." +
-       Utilities::int_to_string(triangulation.locally_owned_subdomain(), 4) +
-       ".vtu");
-    std::ofstream output(filename);
-    data_out.write_vtu(output);
-
-
-    // At this point, all processors have written their own files to disk. We
-    // could visualize them individually in Visit or Paraview, but in reality
-    // we of course want to visualize the whole set of files at once. To this
-    // end, we create a master file in each of the formats understood by Visit
-    // (<code>.visit</code>) and Paraview (<code>.pvtu</code>) on the zeroth
-    // processor that describes how the individual files are defining the
-    // global data set.
-    if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
-      {
-        std::vector<std::string> filenames;
-        for (unsigned int i = 0;
-             i < Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
-             ++i)
-          filenames.push_back(std::string("solution-") +
-                              Utilities::int_to_string(out_index, 5) + "." +
-                              Utilities::int_to_string(i, 4) + ".vtu");
-        const std::string pvtu_master_filename =
-          ("solution-" + Utilities::int_to_string(out_index, 5) + ".pvtu");
-        std::ofstream pvtu_master(pvtu_master_filename);
-        data_out.write_pvtu_record(pvtu_master, filenames);
-
-        const std::string visit_master_filename =
-          ("solution-" + Utilities::int_to_string(out_index, 5) + ".visit");
-        std::ofstream visit_master(visit_master_filename);
-        DataOutBase::write_visit_record(visit_master, filenames);
-      }
+    static int out_index = 0;
+    data_out.write_vtu_with_pvtu_record(
+      "./", "solution-", out_index, 5, MPI_COMM_WORLD);
 
     out_index++;
   }
index b08866d4a7937f95d0ae2b403179a6823f1ae889..52257c690565a9afb2084b53081a0ff23643be9d 100644 (file)
@@ -1128,29 +1128,11 @@ namespace Step37
     data_out.add_data_vector(solution, "solution");
     data_out.build_patches();
 
-    std::ofstream output(
-      "solution-" + std::to_string(cycle) + "." +
-      std::to_string(Utilities::MPI::this_mpi_process(MPI_COMM_WORLD)) +
-      ".vtu");
     DataOutBase::VtkFlags flags;
     flags.compression_level = DataOutBase::VtkFlags::best_speed;
     data_out.set_flags(flags);
-    data_out.write_vtu(output);
-
-    if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
-      {
-        std::vector<std::string> filenames;
-        for (unsigned int i = 0;
-             i < Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
-             ++i)
-          filenames.emplace_back("solution-" + std::to_string(cycle) + "." +
-                                 std::to_string(i) + ".vtu");
-
-        std::string master_name =
-          "solution-" + Utilities::to_string(cycle) + ".pvtu";
-        std::ofstream master_output(master_name);
-        data_out.write_pvtu_record(master_output, filenames);
-      }
+    data_out.write_vtu_with_pvtu_record(
+      "./", "solution-", cycle, 3, MPI_COMM_WORLD);
 
     time_details << "Time write output          (CPU/wall) " << time.cpu_time()
                  << "s/" << time.wall_time() << "s\n";
index e8058c8cd6f6b686655ea042eb62ef26a430fd2e..ea5111f28704ef30f8f4c981d2e96889dbe2456b 100644 (file)
@@ -572,40 +572,11 @@ namespace Step40
 
     data_out.build_patches();
 
-    // The next step is to write this data to disk. We choose file names of
-    // the form <code>solution-XX.PPPP.vtu</code> where <code>XX</code>
-    // indicates the refinement cycle, <code>PPPP</code> refers to the
-    // processor number (enough for up to 10,000 processors, though we hope
-    // that nobody ever tries to generate this much data -- you would likely
-    // overflow all file system quotas), and <code>.vtu</code> indicates the
-    // XML-based Visualization Toolkit for Unstructured grids (VTU) file
-    // format.
-    const std::string filename =
-      ("solution-" + Utilities::int_to_string(cycle, 2) + "." +
-       Utilities::int_to_string(triangulation.locally_owned_subdomain(), 4));
-    std::ofstream output(filename + ".vtu");
-    data_out.write_vtu(output);
-
-    // The last step is to write a "master record" that lists for the
-    // visualization program the names of the various files that combined
-    // represents the graphical data for the entire domain. The
-    // DataOutBase::write_pvtu_record does this, and it needs a list of
-    // filenames that we create first. Note that only one processor needs to
-    // generate this file; we arbitrarily choose processor zero to take over
-    // this job.
-    if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
-      {
-        std::vector<std::string> filenames;
-        for (unsigned int i = 0;
-             i < Utilities::MPI::n_mpi_processes(mpi_communicator);
-             ++i)
-          filenames.push_back("solution-" + Utilities::int_to_string(cycle, 2) +
-                              "." + Utilities::int_to_string(i, 4) + ".vtu");
-
-        std::ofstream master_output(
-          "solution-" + Utilities::int_to_string(cycle, 2) + ".pvtu");
-        data_out.write_pvtu_record(master_output, filenames);
-      }
+    // The next step is to write this data to disk. We write up to 8 VTU files
+    // in parallel with the help of MPI-IO. Additionally a PVTU record is
+    // generated, which groups the written VTU files.
+    data_out.write_vtu_with_pvtu_record(
+      "./", "solution-", cycle, 2, mpi_communicator, 8);
   }
 
 
index 799c59e8be59eba92d7b60cfba41926a99812c40..3b4c8bda5aecb0da7b6e5779c93ec35e4513dac4 100644 (file)
@@ -2046,32 +2046,10 @@ namespace Step42
     // output files. We then do the same again for the competitor of
     // Paraview, the Visit visualization program, by creating a matching
     // <code>.visit</code> file.
-    const std::string filename =
-      (output_dir + filename_base + "-" +
-       Utilities::int_to_string(triangulation.locally_owned_subdomain(), 4));
-
-    std::ofstream output_vtu((filename + ".vtu"));
-    data_out.write_vtu(output_vtu);
+    data_out.write_vtu_with_pvtu_record(
+      output_dir, filename_base, 0, 1, mpi_communicator);
     pcout << output_dir + filename_base << ".pvtu" << std::endl;
 
-    if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
-      {
-        std::vector<std::string> filenames;
-        for (unsigned int i = 0;
-             i < Utilities::MPI::n_mpi_processes(mpi_communicator);
-             ++i)
-          filenames.push_back(filename_base + "-" +
-                              Utilities::int_to_string(i, 4) + ".vtu");
-
-        std::ofstream pvtu_master_output(
-          (output_dir + filename_base + ".pvtu"));
-        data_out.write_pvtu_record(pvtu_master_output, filenames);
-
-        std::ofstream visit_master_output(
-          (output_dir + filename_base + ".visit"));
-        DataOutBase::write_visit_record(visit_master_output, filenames);
-      }
-
     TrilinosWrappers::MPI::Vector tmp(solution);
     tmp *= -1;
     move_mesh(tmp);
index 4a604e3857e16fa07a695a59e7854491f98b7af9..f7e21ba318fbfa5706bdfa950a18d30e7ccacfa7 100644 (file)
@@ -739,27 +739,8 @@ namespace Step45
     data_out.add_data_vector(subdomain, "subdomain");
     data_out.build_patches(mapping, degree + 1);
 
-    std::ofstream output(
-      "solution-" + Utilities::int_to_string(refinement_cycle, 2) + "." +
-      Utilities::int_to_string(triangulation.locally_owned_subdomain(), 2) +
-      ".vtu");
-    data_out.write_vtu(output);
-
-    if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
-      {
-        std::vector<std::string> filenames;
-        for (unsigned int i = 0;
-             i < Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
-             ++i)
-          filenames.push_back(std::string("solution-") +
-                              Utilities::int_to_string(refinement_cycle, 2) +
-                              "." + Utilities::int_to_string(i, 2) + ".vtu");
-        const std::string pvtu_master_filename =
-          ("solution-" + Utilities::int_to_string(refinement_cycle, 2) +
-           ".pvtu");
-        std::ofstream pvtu_master(pvtu_master_filename);
-        data_out.write_pvtu_record(pvtu_master, filenames);
-      }
+    data_out.write_vtu_with_pvtu_record(
+      "./", "solution-", refinement_cycle, 2, MPI_COMM_WORLD);
   }
 
 
index 337be061734ed7bf11249252ea182b623522a95d..b613390b596092d648f26405be4fa3e1b5472951 100644 (file)
@@ -500,29 +500,8 @@ namespace Step48
     data_out.add_data_vector(solution, "solution");
     data_out.build_patches();
 
-    const std::string filename =
-      "solution-" + Utilities::int_to_string(timestep_number, 3);
-
-    std::ofstream output(
-      filename + "." +
-      Utilities::int_to_string(Utilities::MPI::this_mpi_process(MPI_COMM_WORLD),
-                               4) +
-      ".vtu");
-    data_out.write_vtu(output);
-
-    if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
-      {
-        std::vector<std::string> filenames;
-        for (unsigned int i = 0;
-             i < Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
-             ++i)
-          filenames.push_back("solution-" +
-                              Utilities::int_to_string(timestep_number, 3) +
-                              "." + Utilities::int_to_string(i, 4) + ".vtu");
-
-        std::ofstream master_output((filename + ".pvtu"));
-        data_out.write_pvtu_record(master_output, filenames);
-      }
+    data_out.write_vtu_with_pvtu_record(
+      "./", "solution-", timestep_number, 3, MPI_COMM_WORLD);
   }
 
 
index e2d202e2380f59e1e8862640cb3ac8ba17aa83f8..5403611a984011a18f42563be27758f92084565c 100644 (file)
@@ -749,25 +749,8 @@ namespace Step55
 
     data_out.build_patches();
 
-    const std::string filename =
-      ("solution-" + Utilities::int_to_string(cycle, 2) + "." +
-       Utilities::int_to_string(triangulation.locally_owned_subdomain(), 4));
-    std::ofstream output((filename + ".vtu"));
-    data_out.write_vtu(output);
-
-    if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
-      {
-        std::vector<std::string> filenames;
-        for (unsigned int i = 0;
-             i < Utilities::MPI::n_mpi_processes(mpi_communicator);
-             ++i)
-          filenames.push_back("solution-" + Utilities::int_to_string(cycle, 2) +
-                              "." + Utilities::int_to_string(i, 4) + ".vtu");
-
-        std::ofstream master_output(
-          "solution-" + Utilities::int_to_string(cycle, 2) + ".pvtu");
-        data_out.write_pvtu_record(master_output, filenames);
-      }
+    data_out.write_vtu_with_pvtu_record(
+      "./", "solution-", cycle, 2, mpi_communicator);
   }
 
 
index 1fb4c046beb58de3462383d0a4514bea91a58c1e..62f6126cec0f980b7eaef3969a73c5995fe44610 100644 (file)
@@ -544,29 +544,11 @@ namespace Step64
     data_out.add_data_vector(ghost_solution_host, "solution");
     data_out.build_patches();
 
-    std::ofstream output(
-      "solution-" + std::to_string(cycle) + "." +
-      std::to_string(Utilities::MPI::this_mpi_process(mpi_communicator)) +
-      ".vtu");
     DataOutBase::VtkFlags flags;
     flags.compression_level = DataOutBase::VtkFlags::best_speed;
     data_out.set_flags(flags);
-    data_out.write_vtu(output);
-
-    if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
-      {
-        std::vector<std::string> filenames;
-        for (unsigned int i = 0;
-             i < Utilities::MPI::n_mpi_processes(mpi_communicator);
-             ++i)
-          filenames.emplace_back("solution-" + std::to_string(cycle) + "." +
-                                 std::to_string(i) + ".vtu");
-
-        std::string master_name =
-          "solution-" + Utilities::to_string(cycle) + ".pvtu";
-        std::ofstream master_output(master_name);
-        data_out.write_pvtu_record(master_output, filenames);
-      }
+    data_out.write_vtu_with_pvtu_record(
+      "./", "solution-", cycle, 2, mpi_communicator);
 
     Vector<float> cellwise_norm(triangulation.n_active_cells());
     VectorTools::integrate_difference(dof_handler,

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.