00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "createEpetraProblem.hpp"
00030 #include "Teuchos_Workspace.hpp"
00031 #include "Trilinos_Util.h"
00032 #include "Epetra_CrsMatrix.h"
00033 #include "Epetra_MultiVector.h"
00034 #include "Epetra_Map.h"
00035 #ifdef EPETRA_MPI
00036 #include "Epetra_MpiComm.h"
00037 #else
00038 #include "Epetra_SerialComm.h"
00039 #endif
00040 #include "Epetra_Map.h"
00041
00042 int Belos::createEpetraProblem(
00043 std::string &filename
00044 ,RefCountPtr<Epetra_Map> *rowMap
00045 ,RefCountPtr<Epetra_CrsMatrix> *A
00046 ,RefCountPtr<Epetra_MultiVector> *B
00047 ,RefCountPtr<Epetra_MultiVector> *X
00048 ,int *MyPID_out
00049 )
00050 {
00051
00052 int &MyPID = *MyPID_out;
00053
00054 int i;
00055 int n_nonzeros, N_update;
00056 int *bindx=0, *update=0, *col_inds=0;
00057 double *val=0, *row_vals=0;
00058 double *xguess=0, *b=0, *xexact=0;
00059
00060 RefCountPtr<Epetra_Comm> epetraComm;
00061 #ifdef EPETRA_MPI
00062 epetraComm = rcp(new Epetra_MpiComm( MPI_COMM_WORLD ) );
00063 #else
00064 epetraComm = rcp(new Epetra_SerialComm());
00065 #endif
00066
00067 MyPID = epetraComm->MyPID();
00068
00069
00070
00071
00072
00073 int NumGlobalElements;
00074
00075
00076
00077 Trilinos_Util_read_hb(const_cast<char *>(filename.c_str()), MyPID, &NumGlobalElements, &n_nonzeros,
00078 &val, &bindx, &xguess, &b, &xexact);
00079
00080
00081
00082 Trilinos_Util_distrib_msr_matrix(*epetraComm, &NumGlobalElements, &n_nonzeros, &N_update,
00083 &update, &val, &bindx, &xguess, &b, &xexact);
00084
00085
00086
00087 int NumMyElements = N_update;
00088
00089
00090
00091
00092
00093 int * NumNz = new int[NumMyElements];
00094 for (i=0; i<NumMyElements; i++) {
00095 NumNz[i] = bindx[i+1] - bindx[i] + 1;
00096 }
00097
00098 RefCountPtr<Epetra_Map> epetraMap = rcp(new Epetra_Map(NumGlobalElements, NumMyElements, update, 0, *epetraComm));
00099 Teuchos::set_extra_data( epetraComm, "Map::Comm", &epetraMap );
00100 if(rowMap) *rowMap = epetraMap;
00101
00102
00103
00104 *A = rcp(new Epetra_CrsMatrix(Copy, *epetraMap, NumNz));
00105 Teuchos::set_extra_data( epetraMap, "Operator::Map", A );
00106
00107
00108
00109 int NumEntries;
00110 for (i=0; i<NumMyElements; i++) {
00111 row_vals = val + bindx[i];
00112 col_inds = bindx + bindx[i];
00113 NumEntries = bindx[i+1] - bindx[i];
00114 assert((*A)->InsertGlobalValues(update[i], NumEntries, row_vals, col_inds)==0);
00115 assert((*A)->InsertGlobalValues(update[i], 1, val+i, update+i)==0);
00116 }
00117
00118
00119
00120 assert((*A)->FillComplete()==0);
00121 assert((*A)->OptimizeStorage()==0);
00122 (*A)->SetTracebackMode(1);
00123
00124
00125
00126 if(B) {
00127 *B = rcp(new Epetra_MultiVector(::Copy, *epetraMap, b, NumMyElements, 1 ));
00128 Teuchos::set_extra_data( epetraMap, "B::Map", B );
00129 }
00130 if(X) {
00131 *X = rcp(new Epetra_MultiVector(*epetraMap, 1 ));
00132 Teuchos::set_extra_data( epetraMap, "X::Map", X );
00133 }
00134
00135
00136
00137 Teuchos::set_default_workspace_store(
00138 Teuchos::rcp(new Teuchos::WorkspaceStoreInitializeable(static_cast<size_t>(2e+6)))
00139 );
00140
00141
00142
00143 delete [] NumNz;
00144 free(update);
00145 free(val);
00146 free(bindx);
00147 if (xexact) free(xexact);
00148 if (xguess) free(xguess);
00149 if (b) free(b);
00150
00151 return (0);
00152 }