DOLFINx
DOLFINx C++ interface
VTKFile.h
1 // Copyright (C) 2020 Garth N. Wells
2 //
3 // This file is part of DOLFINx (https://www.fenicsproject.org)
4 //
5 // SPDX-License-Identifier: LGPL-3.0-or-later
6 
7 #pragma once
8 
9 #include <dolfinx/common/MPI.h>
10 #include <dolfinx/fem/Function.h>
11 #include <functional>
12 #include <memory>
13 #include <string>
14 
15 namespace pugi
16 {
17 class xml_document;
18 }
19 
20 namespace dolfinx
21 {
22 namespace function
23 {
24 template <typename T>
25 class Function;
26 }
27 
28 namespace mesh
29 {
30 class Mesh;
31 } // namespace mesh
32 
33 namespace io
34 {
35 
42 
45 
46 class VTKFile
47 {
48 public:
50  VTKFile(MPI_Comm comm, const std::string filename,
51  const std::string file_mode);
52 
54  ~VTKFile();
55 
57  void close();
58 
60  void flush();
61 
66  void write(const mesh::Mesh& mesh, double time = 0.0);
67 
71  void write(
72  const std::vector<std::reference_wrapper<const fem::Function<double>>>& u,
73  double t);
74 
78  void write(
79  const std::vector<
80  std::reference_wrapper<const fem::Function<std::complex<double>>>>& u,
81  double t);
82 
83 private:
84  std::unique_ptr<pugi::xml_document> _pvd_xml;
85 
86  std::string _filename;
87 
88  // MPI communicator
89  dolfinx::MPI::Comm _comm;
90 };
91 } // namespace io
92 } // namespace dolfinx
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:36
This class represents a function in a finite element function space , given by.
Definition: Function.h:48
Definition: VTKFile.h:25
Output of meshes and functions in VTK/ParaView format. Isoparametric meshes of arbitrary degree are s...
Definition: VTKFile.h:47
~VTKFile()
Destructor.
Definition: VTKFile.cpp:733
void flush()
Flushes XML files to disk.
Definition: VTKFile.cpp:753
void write(const mesh::Mesh &mesh, double time=0.0)
Write mesh to file. Supports arbitrary order Lagrange isoparametric cells.
Definition: VTKFile.cpp:777
void close()
Close file.
Definition: VTKFile.cpp:739
VTKFile(MPI_Comm comm, const std::string filename, const std::string file_mode)
Create VTK file.
Definition: VTKFile.cpp:721
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:56