From: bangerth Date: Wed, 30 May 2012 12:53:31 +0000 (+0000) Subject: Patch by Marco Engelhard: Add DataOutInterface::write_pvd_record. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa46ad57256cfa01839983f28b81c4d8331029ff;p=dealii-svn.git Patch by Marco Engelhard: Add DataOutInterface::write_pvd_record. git-svn-id: https://svn.dealii.org/trunk@25569 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 68f51af953..be820c9c3b 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -48,12 +48,6 @@ used for boundary indicators.
    -
  1. New: DoFTools::make_periodicity_constraints implemented which -inserts algebraic constraints due to periodic boundary conditions -into a ConstraintMatrix. -
    -(Matthias Maier, 2012/05/22) -
  2. New: step-48 demonstrates the solution of a nonlinear wave equation with an explicit time stepping method. The usage of Gauss-Lobatto @@ -81,7 +75,7 @@ implemented using the FEEvaluation class. (Katharina Kormann and Martin Kronbichler, 2012/05/05)
  3. -New: step-44 demonstrates one approach to modelling large +New: step-44 demonstrates one approach to modeling large deformations of nearly-incompressible elastic solids. The elastic response is governed by a non-linear, hyperelastic free-energy function. The geometrical response is also @@ -207,11 +201,23 @@ enabled due to a missing include file in file

    Specific improvements

      +
    1. New: The function DataOutInterface::write_pvd_record can be used +to provide Paraview with metadata that describes which time in a +simulation a particular output file corresponds to. +
      +(Marco Engelhard 2012/05/30) +
    2. Fixed: Bug in 3d with hanging nodes in GridTools::find_cells_adjacent_to_vertex() that caused find_active_cell_around_point() to fail in those cases.
      (Timo Heister, Wolfgang Bangerth 2012/05/30) +
    3. New: DoFTools::make_periodicity_constraints implemented which +inserts algebraic constraints due to periodic boundary conditions +into a ConstraintMatrix. +
      +(Matthias Maier, 2012/05/22) +
    4. New: The GridIn::read_unv function can now read meshes generated by the Salome framework, see http://www.salome-platform.org/ .
      diff --git a/deal.II/include/deal.II/base/data_out_base.h b/deal.II/include/deal.II/base/data_out_base.h index 560e09e55e..f0fc486f74 100644 --- a/deal.II/include/deal.II/base/data_out_base.h +++ b/deal.II/include/deal.II/base/data_out_base.h @@ -2348,6 +2348,61 @@ class DataOutInterface : private DataOutBase void write_pvtu_record (std::ostream &out, const std::vector &piece_names) const; + /** + * In ParaView it is possible to visualize time- + * dependent data tagged with the current + * integration time of a time dependent simulation. To use this + * feature you need a .pvd + * file that describes which VTU or PVTU file + * belongs to which timestep. This function writes a file that + * provides this mapping, i.e., it takes a list of pairs each of + * which indicates a particular time instant and the corresponding + * file that contains the graphical data for this time instant. + * + * A typical use case, in program that computes a time dependent + * solution, would be the following (time and + * time_step are member variables of the class with types + * double and unsigned int, respectively; + * the variable times_and_names is of type + * std::vector@ @>): + * + * @code + * template + * void MyEquation::output_results () const + * { + * DataOut data_out; + * + * data_out.attach_dof_handler (dof_handler); + * data_out.add_data_vector (solution, "U"); + * data_out.build_patches (); + * + * const std::string filename = "solution-" + + * Utilities::int_to_string (timestep_number, 3) + + * ".vtu"; + * std::ofstream output (filename.c_str()); + * data_out.write_vtu (output); + * + * times_and_names.push_back (std::pair (time, filename)); + * std::ofstream pvd_output ("solution.pvd"); + * data_out.write_pvd_record (pvd_output, times_and_names); + * } + * @endcode + * + * @note See DataOutBase::write_vtu or + * DataOutBase::write_pvtu_record for + * writing solutions at each timestep. + * + * @note The second element of each pair, i.e., the file in which + * the graphical data for each time is stored, may itself be again + * a file that references other files. For example, it could be + * the name for a .pvtu file that references multiple + * parts of a parallel computation. + * + * @author Marco Engelhard, 2012 + */ + void write_pvd_record (std::ostream &out, + const std::vector > ×_and_names) const; + /** * This function is the exact * equivalent of the diff --git a/deal.II/source/base/data_out_base.cc b/deal.II/source/base/data_out_base.cc index 557c59aac0..98380bf568 100644 --- a/deal.II/source/base/data_out_base.cc +++ b/deal.II/source/base/data_out_base.cc @@ -5389,6 +5389,44 @@ void DataOutInterface::write_vtu_in_parallel (const char* filename } +template +void +DataOutInterface:: +write_pvd_record (std::ostream &out, + const std::vector > ×_and_names) const +{ + AssertThrow (out, ExcIO()); + + out << "\n"; + + std::time_t time1= std::time (0); + std::tm *time = std::localtime(&time1); + out << "\n"; + + out << "\n"; + out << " \n"; + + for(unsigned int i=0; i\n"; + + out << " \n"; + out << "\n"; + + out.flush(); + + AssertThrow (out, ExcIO()); +} + template void diff --git a/tests/base/data_out_base_pvd.cc b/tests/base/data_out_base_pvd.cc new file mode 100644 index 0000000000..8af1b7727b --- /dev/null +++ b/tests/base/data_out_base_pvd.cc @@ -0,0 +1,71 @@ +//----------------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2006, 2007, 2010, 2012 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//----------------------------------------------------------------------------- + +// write the pvd master record for parallel visualization through the +// vtu file format + +#include "../tests.h" +#include +#include + +#include +#include +#include +#include +#include + +#include "patches.h" + + + +std::vector > patches; + +class DataOutX : public DataOutInterface<2,2> +{ + virtual + const std::vector< ::DataOutBase::Patch<2,2> > & + get_patches () const + { + return patches; + } + + virtual + std::vector + get_dataset_names () const + { + return std::vector(); + } +}; + + +template +void check(std::ostream& out) +{ + std::vector > names(5); + names[0] = std::make_pair(0,"x1"); + names[1] = std::make_pair(1,"x2"); + names[2] = std::make_pair(1e1,"x3"); + names[3] = std::make_pair(3.141,"d"); + names[4] = std::make_pair(42e19,"i"); + + DataOutX x; + x.write_pvd_record (out, names); +} + + + +int main() +{ + std::ofstream logfile("data_out_base_pvd/output"); + check<2,2>(logfile); +} diff --git a/tests/base/data_out_base_pvd/cmp/generic b/tests/base/data_out_base_pvd/cmp/generic new file mode 100644 index 0000000000..8524c7748b --- /dev/null +++ b/tests/base/data_out_base_pvd/cmp/generic @@ -0,0 +1,13 @@ + + + + + + + + + + +