From 11e19a10ca6f9682a3367f8dbd392688afafce5e Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Sat, 26 Oct 2019 01:51:26 +0200 Subject: [PATCH] Update tutorials to use write_vtu_with_pvtu_record --- examples/step-18/step-18.cc | 51 +++---------------------------------- examples/step-32/step-32.cc | 38 +++------------------------ examples/step-37/step-37.cc | 22 ++-------------- examples/step-40/step-40.cc | 39 ++++------------------------ examples/step-42/step-42.cc | 26 ++----------------- examples/step-45/step-45.cc | 23 ++--------------- examples/step-48/step-48.cc | 25 ++---------------- examples/step-55/step-55.cc | 21 ++------------- examples/step-64/step-64.cu | 22 ++-------------- 9 files changed, 23 insertions(+), 244 deletions(-) diff --git a/examples/step-18/step-18.cc b/examples/step-18/step-18.cc index f8a8129214..b2289a0dd8 100644 --- a/examples/step-18/step-18.cc +++ b/examples/step-18/step-18.cc @@ -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 solution-, 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 AssertThrow - // rather than Assert 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 Assert 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 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 diff --git a/examples/step-32/step-32.cc b/examples/step-32/step-32.cc index 9f402a3769..cc09986701 100644 --- a/examples/step-32/step-32.cc +++ b/examples/step-32/step-32.cc @@ -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 - // (.visit) and Paraview (.pvtu) 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 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++; } diff --git a/examples/step-37/step-37.cc b/examples/step-37/step-37.cc index b08866d4a7..52257c6905 100644 --- a/examples/step-37/step-37.cc +++ b/examples/step-37/step-37.cc @@ -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 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"; diff --git a/examples/step-40/step-40.cc b/examples/step-40/step-40.cc index e8058c8cd6..ea5111f287 100644 --- a/examples/step-40/step-40.cc +++ b/examples/step-40/step-40.cc @@ -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 solution-XX.PPPP.vtu where XX - // indicates the refinement cycle, PPPP 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 .vtu 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 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); } diff --git a/examples/step-42/step-42.cc b/examples/step-42/step-42.cc index 799c59e8be..3b4c8bda5a 100644 --- a/examples/step-42/step-42.cc +++ b/examples/step-42/step-42.cc @@ -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 // .visit 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 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); diff --git a/examples/step-45/step-45.cc b/examples/step-45/step-45.cc index 4a604e3857..f7e21ba318 100644 --- a/examples/step-45/step-45.cc +++ b/examples/step-45/step-45.cc @@ -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 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); } diff --git a/examples/step-48/step-48.cc b/examples/step-48/step-48.cc index 337be06173..b613390b59 100644 --- a/examples/step-48/step-48.cc +++ b/examples/step-48/step-48.cc @@ -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 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); } diff --git a/examples/step-55/step-55.cc b/examples/step-55/step-55.cc index e2d202e238..5403611a98 100644 --- a/examples/step-55/step-55.cc +++ b/examples/step-55/step-55.cc @@ -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 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); } diff --git a/examples/step-64/step-64.cu b/examples/step-64/step-64.cu index 1fb4c046be..62f6126cec 100644 --- a/examples/step-64/step-64.cu +++ b/examples/step-64/step-64.cu @@ -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 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 cellwise_norm(triangulation.n_active_cells()); VectorTools::integrate_difference(dof_handler, -- 2.39.5