00001 #include "EpetraExt_ConfigDefs.h"
00002 #ifdef HAVE_MPI
00003 #include "mpi.h"
00004 #include "Epetra_MpiComm.h"
00005 #else
00006 #include "Epetra_SerialComm.h"
00007 #endif
00008 #include <vector>
00009 #include "Epetra_Map.h"
00010 #include "Epetra_CrsMatrix.h"
00011 #include "Epetra_MultiVector.h"
00012 #include "EpetraExt_XMLReader.h"
00013 #include "EpetraExt_XMLWriter.h"
00014 #include "Teuchos_ParameterList.hpp"
00015
00016
00017
00018
00019
00020
00021
00022
00023 int main (int argc, char **argv)
00024 {
00025 #ifdef HAVE_MPI
00026 MPI_Init(&argc, &argv);
00027 Epetra_MpiComm Comm(MPI_COMM_WORLD);
00028 #else
00029 Epetra_SerialComm Comm;
00030 #endif
00031
00032
00033
00034 int n = Comm.NumProc() * 4;
00035 Epetra_Map Map(n, 0, Comm);
00036 Epetra_MultiVector x(Map, 2); x.Random();
00037 Epetra_MultiVector b(Map, 2); x.Random();
00038 Epetra_CrsMatrix Matrix(Copy, Map, 0);
00039
00040 for (int i = 0; i < Map.NumMyElements(); ++i)
00041 {
00042 int ii = Map.GID(i);
00043 double one = 1.0;
00044 Matrix.InsertGlobalValues(ii, 1, &one, &ii);
00045 }
00046 Matrix.FillComplete();
00047
00048 Teuchos::ParameterList List;
00049 List.set("int parameter", 10);
00050 List.set("double parameter", 10.0);
00051 List.set("string parameter", "string");
00052
00053
00054
00055
00056
00057 EpetraExt::XMLWriter XMLWriter(Comm, "data.xml");
00058
00059 vector<string> Content;
00060 Content.push_back("This is an example of description");
00061 Content.push_back("The description is as long as desired,");
00062 Content.push_back("just put it in a vector of strings.");
00063
00064 XMLWriter.Create("MyProblem");
00065 XMLWriter.Write("Author", "myself and others");
00066 XMLWriter.Write("Date", "May 2006");
00067 XMLWriter.Write("MyMap", Map);
00068 XMLWriter.Write("MyMatrix", Matrix);
00069 XMLWriter.Write("MyLHS", x);
00070 XMLWriter.Write("MyRHS", b);
00071 XMLWriter.Write("MyContent", Content);
00072 XMLWriter.Write("MyParameters", List);
00073 XMLWriter.Close();
00074
00075
00076
00077
00078
00079 EpetraExt::XMLReader XMLReader(Comm, "data.xml");
00080
00081 Epetra_Map* MyMap;
00082 Epetra_CrsMatrix* MyMatrix;
00083 Epetra_MultiVector* MyLHS;
00084 Epetra_MultiVector* MyRHS;
00085 Teuchos::ParameterList MyParameters;
00086 vector<string> Author;
00087 vector<string> Date;
00088 vector<string> MyContent;
00089
00090 XMLReader.Read("Author", Author);
00091 XMLReader.Read("Date", Date);
00092 XMLReader.Read("MyMap", MyMap);
00093 XMLReader.Read("MyMatrix", MyMatrix);
00094 XMLReader.Read("MyLHS", MyLHS);
00095 XMLReader.Read("MyRHS", MyRHS);
00096 XMLReader.Read("MyContent", MyContent);
00097 XMLReader.Read("MyParameters", MyParameters);
00098
00099 cout << *MyMap;
00100 cout << *MyMatrix;
00101 cout << *MyLHS;
00102 cout << *MyRHS;
00103 if (Comm.MyPID() == 0)
00104 {
00105 int Msize = (int) MyContent.size();
00106 for (int i = 0; i < Msize; ++i)
00107 cout << MyContent[i] << endl;
00108
00109 cout << MyParameters;
00110 cout << "Author = " << Author[0] << endl;
00111 cout << "Date = " << Date[0] << endl;
00112 }
00113
00114 delete MyMap;
00115 delete MyMatrix;
00116 delete MyLHS;
00117 delete MyRHS;
00118
00119 #ifdef HAVE_MPI
00120 MPI_Finalize();
00121 #endif
00122
00123 return(EXIT_SUCCESS);
00124 }