DOLFIN
DOLFIN C++ interface
Public Types | Public Member Functions | Static Public Member Functions | List of all members
dolfin::File Class Reference

#include <File.h>

Public Types

enum  Type {
  x3d, xml, vtk, raw,
  xyz, binary, svg
}
 File formats.
 

Public Member Functions

 File (const std::string filename, std::string encoding="ascii")
 
 File (MPI_Comm comm, const std::string filename, std::string encoding="ascii")
 
 File (const std::string filename, Type type, std::string encoding="ascii")
 
 File (MPI_Comm comm, const std::string filename, Type type, std::string encoding="ascii")
 
 File (std::ostream &outstream)
 
 ~File ()
 Destructor.
 
template<typename T >
void operator>> (T &t)
 Read from file.
 
template<typename T >
void read (T &t)
 Read from file.
 
void operator<< (const std::pair< const Mesh *, double > mesh)
 
void operator<< (const std::pair< const MeshFunction< int > *, double > f)
 
void operator<< (const std::pair< const MeshFunction< std::size_t > *, double > f)
 
void operator<< (const std::pair< const MeshFunction< double > *, double > f)
 
void operator<< (const std::pair< const MeshFunction< bool > *, double > f)
 
void operator<< (const std::pair< const Function *, double > u)
 
template<typename X >
void operator<< (const X &x)
 Write object to file.
 
template<typename X >
void write (const X &x)
 Write object to file.
 
template<typename X >
void write (const X &x, double time)
 Write object to file with time.
 

Static Public Member Functions

static bool exists (std::string filename)
 
static void create_parent_path (std::string filename)
 

Detailed Description

A File represents a data file for reading and writing objects. Unless specified explicitly, the format is determined by the file name suffix. A list of objects that can be read/written to file can be found in GenericFile.h. Compatible file formats include:

Constructor & Destructor Documentation

◆ File() [1/5]

File::File ( const std::string  filename,
std::string  encoding = "ascii" 
)

Create a file with given name

Arguments filename (std::string) Name of file. encoding (std::string) Optional argument specifying encoding, ASCII is default.

Example .. code-block:: c++

 // Save solution to file
 File file("solution.pvd");
 file << u;

 // Read mesh data from file
 File mesh_file("mesh.xml");
 mesh_file >> mesh;

 // Using compressed binary format
 File comp_file("solution.pvd", "compressed");

◆ File() [2/5]

File::File ( MPI_Comm  comm,
const std::string  filename,
std::string  encoding = "ascii" 
)

Create a file with given name with MPI communicator

Arguments communicator (MPI_Comm) The MPI communicator. filename (std::string) Name of file. encoding (std::string) Optional argument specifying encoding, ascii is default.

Example .. code-block:: c++

 // Save solution to file
 File file(u.mesh()->mpi_comm(), "solution.pvd");
 file << u;

 // Read mesh data from file
 File mesh_file(MPI_COMM_WORLD, "mesh.xml");
 mesh_file >> mesh;

 // Using compressed binary format
 File comp_file(u.mesh()->mpi_comm(), "solution.pvd",
                "compressed");

◆ File() [3/5]

File::File ( const std::string  filename,
Type  type,
std::string  encoding = "ascii" 
)

Create a file with given name and type (format)

Arguments filename (std::string) Name of file. type (Type) File format. encoding (std::string) Optional argument specifying encoding, ascii is default.

Example .. code-block:: c++

File file("solution", vtk);

◆ File() [4/5]

File::File ( MPI_Comm  comm,
const std::string  filename,
Type  type,
std::string  encoding = "ascii" 
)

Create a file with given name and type (format) with MPI communicator

Arguments communicator (MPI_Comm) The MPI communicator. filename (std::string) Name of file. type (Type) File format. encoding (std::string) Optional argument specifying encoding, ascii is default.

Example .. code-block:: c++

File file(MPI_COMM_WORLD, "solution", vtk);

◆ File() [5/5]

File::File ( std::ostream &  outstream)

Create an outfile object writing to stream

Arguments outstream (std::ostream) The stream.

Member Function Documentation

◆ create_parent_path()

void File::create_parent_path ( std::string  filename)
static

Arguments filename (std::string) Name of file / path.

◆ exists()

bool File::exists ( std::string  filename)
static

Check if file exists

Arguments filename (std::string) Name of file.

Returns bool True if the file exists.

◆ operator<<() [1/6]

void File::operator<< ( const std::pair< const Mesh *, double >  mesh)

Write Mesh to file with time

Example .. code-block:: c++

File file("mesh.pvd", "compressed");
file << std::make_pair<const Mesh*, double>(&mesh, t);

◆ operator<<() [2/6]

void File::operator<< ( const std::pair< const MeshFunction< int > *, double >  f)

Write MeshFunction to file with time

Example .. code-block:: c++

File file("markers.pvd", "compressed");
file << std::make_pair<const MeshFunction<int>*, double>(&f, t);

◆ operator<<() [3/6]

void File::operator<< ( const std::pair< const MeshFunction< std::size_t > *, double >  f)

Write MeshFunction to file with time

Example .. code-block:: c++

File file("markers.pvd", "compressed");
file << std::make_pair<const MeshFunction<std::size_t>*, double>(&f, t);

◆ operator<<() [4/6]

void File::operator<< ( const std::pair< const MeshFunction< double > *, double >  f)

Write MeshFunction to file with time

Example .. code-block:: c++

File file("markers.pvd", "compressed");
file << std::make_pair<const MeshFunction<double>*, double>(&f, t);

◆ operator<<() [5/6]

void File::operator<< ( const std::pair< const MeshFunction< bool > *, double >  f)

Write MeshFunction to file with time

Example .. code-block:: c++

File file("markers.pvd", "compressed");
file << std::make_pair<const MeshFunction<bool>*, double>(&f, t);

◆ operator<<() [6/6]

void File::operator<< ( const std::pair< const Function *, double >  u)

Write Function to file with time

Example .. code-block:: c++

File file("solution.pvd", "compressed");
file << std::make_pair<const Function*, double>(&u, t);

The documentation for this class was generated from the following files: