From: Wolfgang Bangerth Date: Tue, 3 Dec 2019 00:29:55 +0000 (-0700) Subject: Use a better way to create graphical output in step-61. X-Git-Tag: v9.2.0-rc1~820^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c32da4bdf6114becd66fb7fae5029266e9c4e1d7;p=dealii.git Use a better way to create graphical output in step-61. Specifically, rather than creating two output files for the cell pressures and the Darcy velocities, put them all into a single file using a method that @kronbichler introduced a while ago. --- diff --git a/examples/step-61/step-61.cc b/examples/step-61/step-61.cc index 5c77011b15..9495bb041c 100644 --- a/examples/step-61/step-61.cc +++ b/examples/step-61/step-61.cc @@ -958,15 +958,40 @@ namespace Step61 // because these are only available on interfaces and not cell // interiors. Consequently, you will see them shown as an invalid // value (such as an infinity). + // + // For the cell interior output, we also want to output the velocity + // variables. This is a bit tricky since it lives on the same mesh + // but uses a different DoFHandler object (the pressure variables live + // on the `dof_handler` object, the Darcy velocity on the `dof_handler_dgrt` + // object). Fortunately, there are variations of the + // DataOut::add_data_vector() function that allow specifying which + // DoFHandler a vector corresponds to, and consequently we can visualize + // the data from both DoFHandler objects within the same file. template void WGDarcyEquation::output_results() const { { DataOut data_out; - data_out.attach_dof_handler(dof_handler); - data_out.add_data_vector(solution, "Pressure_Interior"); + + // First attach the pressure solution to the DataOut object: + const std::vector solution_names = {"interior_pressure", + "interface_pressure"}; + data_out.add_data_vector(dof_handler, solution, solution_names); + + // Then do the same with the Darcy velocity field, and continue + // with writing everything out into a file. + const std::vector velocity_names(dim, "velocity"); + const std::vector< + DataComponentInterpretation::DataComponentInterpretation> + velocity_component_interpretation( + dim, DataComponentInterpretation::component_is_part_of_vector); + data_out.add_data_vector(dof_handler_dgrt, + darcy_velocity, + velocity_names, + velocity_component_interpretation); + data_out.build_patches(fe.degree); - std::ofstream output("Pressure_Interior.vtu"); + std::ofstream output("solution_interior.vtu"); data_out.write_vtu(output); } @@ -975,26 +1000,9 @@ namespace Step61 data_out_faces.attach_dof_handler(dof_handler); data_out_faces.add_data_vector(solution, "Pressure_Face"); data_out_faces.build_patches(fe.degree); - std::ofstream face_output("Pressure_Face.vtu"); + std::ofstream face_output("solution_interface.vtu"); data_out_faces.write_vtu(face_output); } - // Output Darcy velocity vectors. - { - std::vector solution_names(dim, "velocity"); - std::vector - data_component_interpretation( - dim, DataComponentInterpretation::component_is_part_of_vector); - - DataOut data_out_dgrt; - data_out_dgrt.attach_dof_handler(dof_handler_dgrt); - data_out_dgrt.add_data_vector(darcy_velocity, - solution_names, - DataOut::type_dof_data, - data_component_interpretation); - data_out_dgrt.build_patches(fe_dgrt.degree); - std::ofstream dgrt_output("Darcy_velocity.vtk"); - data_out_dgrt.write_vtk(dgrt_output); - } } diff --git a/include/deal.II/numerics/data_out_dof_data.h b/include/deal.II/numerics/data_out_dof_data.h index 7d6622dac4..4f8f14bf55 100644 --- a/include/deal.II/numerics/data_out_dof_data.h +++ b/include/deal.II/numerics/data_out_dof_data.h @@ -773,14 +773,15 @@ public: * discussion of the arguments except the first one) and allows to set a * vector with its own DoFHandler object. This DoFHandler needs to be * compatible with the other DoFHandler objects assigned with calls to @p - * add_data_vector or @p attach_dof_handler, in the sense that the + * add_data_vector or @p attach_dof_handler, in the sense that all of the * DoFHandler objects need to be based on the same triangulation. This - * function allows you to export data from multiple DoFHandlers that - * describe different solution components. + * function allows you to export data from multiple DoFHandler objects that + * describe different solution components. An example of using this function + * is given in step-61. * * Since this function takes a DoFHandler object and hence naturally * represents dof data, the data vector type argument present in the other - * methods above is skipped. + * methods above is not necessary. */ template void