DOLFIN
DOLFIN C++ interface
XMLFile.h
1 // Copyright (C) 2011 Garth N. Wells
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Modified by Anders Logg, 2011.
19 //
20 // First added: 2009-03-03
21 // Last changed: 2011-09-17
22 
23 #ifndef __XMLFILE_H
24 #define __XMLFILE_H
25 
26 #include <map>
27 #include <ostream>
28 #include <string>
29 #include <vector>
30 #include <memory>
31 #include <dolfin/common/types.h>
32 #include <dolfin/common/MPI.h>
33 #include "GenericFile.h"
34 
35 namespace pugi
36 {
37  class xml_document;
38  class xml_node;
39 }
40 
41 namespace dolfin
42 {
43 
44  class Function;
45  class GenericVector;
46  class Mesh;
47  class Parameters;
48  class Table;
49  template<typename T> class Array;
50  template<typename T> class MeshFunction;
51  template<typename T> class MeshValueCollection;
52 
54 
55  class XMLFile : public GenericFile
56  {
57  public:
58 
60  XMLFile(MPI_Comm mpi_comm, const std::string filename);
61 
63  XMLFile(std::ostream& s);
64 
65  ~XMLFile();
66 
68  void read(Mesh& input);
70  void write(const Mesh& output);
71 
73  void read(GenericVector& input);
75  void read_vector(std::vector<double>& input,
76  std::vector<dolfin::la_index>& indices);
78  void write(const GenericVector& output);
79 
81  void read(Parameters& input);
83  void write(const Parameters& output);
84 
86  void read(Table& input);
88  void write(const Table& output);
89 
91  void read(Function& input);
93  void write(const Function& output);
94 
97  { read_mesh_function(input, "uint"); }
99  void write(const MeshFunction<std::size_t>& output)
100  { write_mesh_function(output, "uint"); }
101 
103  void read(MeshFunction<int>& input)
104  { read_mesh_function(input, "int"); }
106  void write(const MeshFunction<int>& output)
107  { write_mesh_function(output, "int"); }
108 
111  { read_mesh_function(input, "double"); }
113  void write(const MeshFunction<double>& output)
114  { write_mesh_function(output, "double"); }
115 
118  { read_mesh_function(input, "bool"); }
120  void write(const MeshFunction<bool>& input)
121  { write_mesh_function(input, "bool"); }
122 
125  { read_mesh_value_collection(input, "uint"); }
128  { write_mesh_value_collection(output, "uint"); }
129 
132  { read_mesh_value_collection(input, "int"); }
134  void write(const MeshValueCollection<int>& output)
135  { write_mesh_value_collection(output, "int"); }
136 
139  { read_mesh_value_collection(input, "double"); }
141  void write(const MeshValueCollection<double>& output)
142  { write_mesh_value_collection(output, "double"); }
143 
146  { read_mesh_value_collection(input, "bool"); }
148  void write(const MeshValueCollection<bool>& input)
149  { write_mesh_value_collection(input, "bool"); }
150 
151  private:
152 
153  // Read MeshFunction
154  template<typename T> void read_mesh_function(MeshFunction<T>& t,
155  const std::string type) const;
156 
157  // Write MeshFunction
158  template<typename T> void write_mesh_function(const MeshFunction<T>& t,
159  const std::string type);
160 
161  // Read MeshValueCollection
162  template<typename T>
163  void read_mesh_value_collection(MeshValueCollection<T>& t,
164  const std::string type) const;
165 
166  // Write MeshValueCollection
167  template<typename T>
168  void write_mesh_value_collection(const MeshValueCollection<T>& t,
169  const std::string type);
170 
171  // Load/open XML doc (from file)
172  void load_xml_doc(pugi::xml_document& xml_doc) const;
173 
174  // Save XML doc (to file or stream)
175  void save_xml_doc(const pugi::xml_document& xml_doc) const;
176 
177  // Get DOLFIN XML node
178  const pugi::xml_node get_dolfin_xml_node(pugi::xml_document& xml_doc) const;
179 
180  static pugi::xml_node write_dolfin(pugi::xml_document& doc);
181 
182  std::shared_ptr<std::ostream> outstream;
183 
184  // MPI communicator
185  dolfin::MPI::Comm _mpi_comm;
186 
187  };
188 
189 }
190 #endif
Definition: Table.h:49
void read(MeshValueCollection< bool > &input)
MeshValueCollection (bool) input.
Definition: XMLFile.h:145
void write(const MeshValueCollection< std::size_t > &output)
MeshValueCollection (std::size_t) output.
Definition: XMLFile.h:127
void write(const MeshValueCollection< bool > &input)
MeshValueCollection (bool) output.
Definition: XMLFile.h:148
void read(MeshFunction< bool > &input)
MeshFunction (bool) input.
Definition: XMLFile.h:117
Definition: adapt.h:29
Base class for file I/O objects.
Definition: GenericFile.h:44
void write(const MeshFunction< std::size_t > &output)
MeshFunction (uint) output.
Definition: XMLFile.h:99
void read(MeshFunction< int > &input)
MeshFunction (int) input.
Definition: XMLFile.h:103
void read(MeshFunction< double > &input)
MeshFunction (double) input.
Definition: XMLFile.h:110
void read(MeshFunction< std::size_t > &input)
MeshFunction (uint) input.
Definition: XMLFile.h:96
void read(MeshValueCollection< double > &input)
MeshValueCollection (double) input.
Definition: XMLFile.h:138
I/O of DOLFIN objects in XML format.
Definition: XMLFile.h:55
Definition: Parameters.h:94
Definition: Function.h:65
Definition: GenericFile.h:38
void write(const MeshFunction< double > &output)
MeshFunction (double) output.
Definition: XMLFile.h:113
void read(MeshValueCollection< int > &input)
MeshValueCollection (int) input.
Definition: XMLFile.h:131
Definition: VTKFile.h:27
void read(MeshValueCollection< std::size_t > &input)
MeshValueCollection (std::size_t) input.
Definition: XMLFile.h:124
void write(const MeshFunction< bool > &input)
MeshFunction (bool) output.
Definition: XMLFile.h:120
void write(const MeshFunction< int > &output)
MeshFunction (int) output.
Definition: XMLFile.h:106
void write(const MeshValueCollection< double > &output)
MeshValueCollection (double) output.
Definition: XMLFile.h:141
This class defines a common interface for vectors.
Definition: GenericVector.h:47
Definition: Mesh.h:82
Definition: MPI.h:76
void write(const MeshValueCollection< int > &output)
MeshValueCollection (int) output.
Definition: XMLFile.h:134