// 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
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++;
}
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";
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);
}
// 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);
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);
}
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);
}
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);
}
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,