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 <filesystem>
12 #include <functional>
13 #include <memory>
14 #include <string>
15 
16 namespace pugi
17 {
18 class xml_document;
19 }
20 
21 namespace dolfinx::function
22 {
23 template <typename T>
24 class Function;
25 }
26 
27 namespace dolfinx::mesh
28 {
29 class Mesh;
30 }
31 
32 namespace dolfinx::io
33 {
34 
41 
44 
45 class VTKFile
46 {
47 public:
49  VTKFile(MPI_Comm comm, const std::filesystem::path& filename,
50  const std::string file_mode);
51 
53  ~VTKFile();
54 
56  void close();
57 
59  void flush();
60 
65  void write(const mesh::Mesh& mesh, double time = 0.0);
66 
70  void write(
71  const std::vector<std::reference_wrapper<const fem::Function<double>>>& u,
72  double t);
73 
77  void write(
78  const std::vector<
79  std::reference_wrapper<const fem::Function<std::complex<double>>>>& u,
80  double t);
81 
82 private:
83  std::unique_ptr<pugi::xml_document> _pvd_xml;
84 
85  std::filesystem::path _filename;
86 
87  // MPI communicator
88  dolfinx::MPI::Comm _comm;
89 };
90 } // namespace dolfinx::io
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:32
This class represents a function in a finite element function space , given by.
Definition: Function.h:47
Definition: VTKFile.h:24
Output of meshes and functions in VTK/ParaView format. Isoparametric meshes of arbitrary degree are s...
Definition: VTKFile.h:46
~VTKFile()
Destructor.
Definition: VTKFile.cpp:730
void flush()
Flushes XML files to disk.
Definition: VTKFile.cpp:750
void write(const mesh::Mesh &mesh, double time=0.0)
Write mesh to file. Supports arbitrary order Lagrange isoparametric cells.
Definition: VTKFile.cpp:774
void close()
Close file.
Definition: VTKFile.cpp:736
VTKFile(MPI_Comm comm, const std::filesystem::path &filename, const std::string file_mode)
Create VTK file.
Definition: VTKFile.cpp:718
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:53
Support for file IO.
Definition: cells.h:22
Mesh data structures and algorithms on meshes.
Definition: DirichletBC.h:20