EpetraExt  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members
EpetraExt::XMLWriter Class Reference

class XMLWriter: A class for writing Trilinos objects to XML files. More...

#include <EpetraExt_XMLWriter.h>

 XMLWriter (const Epetra_Comm &Comm, const std::string &FileName)
 ctor More...
 
 ~XMLWriter ()
 dtor More...
 
void Create (const std::string &Label)
 Creates the file, giving Label to the whole object. More...
 
void Close ()
 Closes the file. No Write operations can follow. More...
 
void Write (const std::string &Label, const Epetra_Map &Map)
 Writes an Epetra_Map using label Label. More...
 
void Write (const std::string &Label, const Epetra_RowMatrix &Matrix)
 Writes an Epetra_RowMatrix using label Label. More...
 
void Write (const std::string &Label, const Epetra_MultiVector &MultiVector)
 Writes an Epetra_MultiVector using label Label. More...
 
void Write (const std::string &Label, const std::vector< std::string > &Content)
 Writes the std::vector of std::string's using label Label. More...
 
void Write (const std::string &Label, const std::string &Text)
 Writes input std::string using label Label. More...
 
void Write (const std::string &Label, Teuchos::ParameterList &List)
 Writes a Teuchos::ParameterList using label Label. More...
 

Detailed Description

class XMLWriter: A class for writing Trilinos objects to XML files.

Class EpetraExt::XMLWriter writes several Trilinos objects in an XML-compatible format. The list of supported objects contains:

All objects can be read and written, with the std::exception of Epetra_RowMatrix objects, that can only be written to files.

An example of usage is reported in file epetraext/example/inout/XML_IO.cpp.

Writing objects goes as follows. Let Map, Matrix, LHS and RHS an Epetra_Map, Epetra_CrsMatrix, and two Epetra_MultiVector's, respectively. First, we define an XMLWriter object

EpetraExt::XMLWriter XMLWriter(Comm, "data.xml");

and we open the file using MyProblem label:

XMLWriter.Create("MyProblem");

Writing objects simply goes as

XMLWriter.Write("MyMap", Map);
XMLWriter.Write("MyMatrix", Matrix);
XMLWriter.Write("MyLHS", LHS);
XMLWriter.Write("MyRHS", RHS);

A Teuchos::ParameterList (List), a std::string, and a std::vector<std::string> can be written as

XMLWriter.Write("MyParameters", List);
XMLWriter.Write("Author", "myself and others");
XMLWriter.Write("Date", "May 2006");

Finally, we close the file

XMLWriter.Close();

Note that only processor 0 writes the Teuchos::ParameterList, std::string, and std::vector<std::string>.

The written file is as follows:

<ObjectCollection Label="MyProblem">
<Text Label="Author">
myself and others
</Text>
<Text Label="Date">
May 2006
</Text>
<Map Label="MyMap" NumElements="4" IndexBase="0" NumProc="1" ElementsOnProc0="4">
<Proc ID="0">
0
1
2
3
</Proc>
</Map>
<PointMatrix Label="MyMatrix" Rows="4" Columns="4" Nonzeros="4" Type="double" StartingIndex="0">
0 0 1
1 1 1
2 2 1
3 3 1
</PointMatrix>
<MultiVector Label="MyLHS" Length="4" NumVectors="2" Type="double">
-0.232996 -0.893077
0.0388327 0.0594004
0.661931 0.342299
-0.930856 -0.984604
</MultiVector>
<MultiVector Label="MyRHS" Length="4" NumVectors="2" Type="double">
0 0
0 0
0 0
0 0
</MultiVector>
<Text Label="MyContent">
This is an example of description
The description is as long as desired,
just put it in a std::vector of strings.
</Text>
<List Label="MyParameters">
<ParameterList>
<Parameter name="double parameter" type="double" value="10"/>
<Parameter name="int parameter" type="int" value="10"/>
<Parameter name="std::string parameter" type="std::string" value="std::string"/>
</ParameterList>
</List>
</ObjectCollection>

This class requires Teuchos to be configured with the option –enable-teuchos-expat.

Author
Marzio Sala, D-INFK/ETHZ
Date
Last updated on 10-May-06.

Definition at line 168 of file EpetraExt_XMLWriter.h.

Constructor & Destructor Documentation

EpetraExt::XMLWriter::XMLWriter ( const Epetra_Comm Comm,
const std::string &  FileName 
)

ctor

Definition at line 64 of file EpetraExt_XMLWriter.cpp.

EpetraExt::XMLWriter::~XMLWriter ( )
inline

dtor

Definition at line 176 of file EpetraExt_XMLWriter.h.

Member Function Documentation

void EpetraExt::XMLWriter::Create ( const std::string &  Label)

Creates the file, giving Label to the whole object.

Definition at line 72 of file EpetraExt_XMLWriter.cpp.

void EpetraExt::XMLWriter::Close ( )

Closes the file. No Write operations can follow.

Definition at line 85 of file EpetraExt_XMLWriter.cpp.

void EpetraExt::XMLWriter::Write ( const std::string &  Label,
const Epetra_Map Map 
)

Writes an Epetra_Map using label Label.

Definition at line 223 of file EpetraExt_XMLWriter.cpp.

void EpetraExt::XMLWriter::Write ( const std::string &  Label,
const Epetra_RowMatrix Matrix 
)

Writes an Epetra_RowMatrix using label Label.

Definition at line 120 of file EpetraExt_XMLWriter.cpp.

void EpetraExt::XMLWriter::Write ( const std::string &  Label,
const Epetra_MultiVector MultiVector 
)

Writes an Epetra_MultiVector using label Label.

Definition at line 176 of file EpetraExt_XMLWriter.cpp.

void EpetraExt::XMLWriter::Write ( const std::string &  Label,
const std::vector< std::string > &  Content 
)

Writes the std::vector of std::string's using label Label.

Definition at line 99 of file EpetraExt_XMLWriter.cpp.

void EpetraExt::XMLWriter::Write ( const std::string &  Label,
const std::string &  Text 
)
inline

Writes input std::string using label Label.

Definition at line 200 of file EpetraExt_XMLWriter.h.

void EpetraExt::XMLWriter::Write ( const std::string &  Label,
Teuchos::ParameterList &  List 
)

Writes a Teuchos::ParameterList using label Label.

Definition at line 306 of file EpetraExt_XMLWriter.cpp.


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