75 static void Tokenize(
const std::string& str, std::vector<std::string>& tokens,
76 const std::string& delimiters =
" ")
79 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
81 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
83 while (std::string::npos != pos || std::string::npos != lastPos)
86 tokens.push_back(str.substr(lastPos, pos - lastPos));
88 lastPos = str.find_first_not_of(delimiters, pos);
90 pos = str.find_first_of(delimiters, lastPos);
99 #ifdef HAVE_TEUCHOS_EXPAT 104 std::cerr <<
"Teuchos was not configured with support for expat." << std::endl;
105 std::cerr <<
"Please reconfigure teuchos with --enable-teuchos-expat." << std::endl;
111 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 116 "No file has been opened");
120 for (
int i = 0; i < fileXML_->numChildren(); ++i)
123 std::string tag = child.
getTag();
134 if (debug) std::cout << NumGlobalCols << NumGlobalEntries << Offset << std::endl;
141 std::vector<std::string> tokens;
144 if (tokens.size() < 2)
continue;
147 row = atoi((
char*)tokens[0].c_str());
148 col = atoi((
char*)tokens[1].c_str());
150 if (map.
LID(row) != -1)
160 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 165 "No file has been opened");
169 for (
int i = 0; i < fileXML_->numChildren(); ++i)
172 std::string tag = child.
getTag();
179 long long NumGlobalRows = child.
getRequired<
long long>(
"Rows");
180 long long NumGlobalCols = child.
getRequired<
long long>(
"Columns");
181 long long NumGlobalEntries = child.
getRequired<
long long>(
"Entries");
183 if (debug) std::cout << NumGlobalCols << NumGlobalEntries << Offset << std::endl;
190 std::vector<std::string> tokens;
193 if (tokens.size() < 2)
continue;
198 #if defined(_MSC_VER) 199 row = _strtoi64((
char*)tokens[0].c_str(), &endp, base);
200 col = _strtoi64((
char*)tokens[1].c_str(), &endp, base);
203 std::istringstream ss_row(tokens[0]);
205 std::istringstream ss_col(tokens[1]);
208 row = strtoll((
char*)tokens[0].c_str(), &endp, base);
209 col = strtoll((
char*)tokens[1].c_str(), &endp, base);
213 if (map.
LID(row) != -1)
224 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 229 "No file has been opened");
233 for (
int i = 0; i < fileXML_->numChildren(); ++i)
236 std::string tag = child.
getTag();
238 if (tag ==
"PointMatrix")
247 if (debug) std::cout << NumGlobalCols << NumGlobalNonzeros << Offset << std::endl;
254 std::vector<std::string> tokens;
257 if (tokens.size() < 3)
continue;
261 row = atoi((
char*)tokens[0].c_str());
262 col = atoi((
char*)tokens[1].c_str());
263 sscanf((
char*)tokens[2].c_str(),
"%lg", &val);
266 if (map.
LID(row) != -1)
276 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 281 "No file has been opened");
285 for (
int i = 0; i < fileXML_->numChildren(); ++i)
288 std::string tag = child.
getTag();
290 if (tag ==
"PointMatrix")
299 if (debug) std::cout << NumGlobalCols << NumGlobalNonzeros << Offset << std::endl;
306 std::vector<std::string> tokens;
309 if (tokens.size() < 3)
continue;
315 #if defined(_MSC_VER) 316 row = _strtoi64((
char*)tokens[0].c_str(), &endp, base);
317 col = _strtoi64((
char*)tokens[1].c_str(), &endp, base);
320 std::istringstream ss_row(tokens[0]);
322 std::istringstream ss_col(tokens[1]);
325 row = strtoll((
char*)tokens[0].c_str(), &endp, base);
326 col = strtoll((
char*)tokens[1].c_str(), &endp, base);
329 sscanf((
char*)tokens[2].c_str(),
"%lg", &val);
332 if (map.
LID(row) != -1)
342 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 347 "No file has been opened");
352 for (
int i = 0; i < fileXML_->numChildren(); ++i)
355 std::string tag = child.
getTag();
357 if (tag ==
"MultiVector")
371 std::vector<std::string> tokens;
377 if (tokens.size() == 0)
continue;
380 "wrong number of tokens in line; " 381 <<
"tokens.size() = " << tokens.size()
382 <<
", NumVectors = " << NumVectors);
383 int tsize = (int) tokens.size();
384 for (
int k = 0; k < tsize; ++k)
386 if (Map.
LID(count) != -1)
388 sscanf((
char*)(tokens[k].c_str()),
"%lf", &val);
390 (*MultiVector)[k][Map.
LID(count)] = val;
401 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 406 "No file has been opened");
411 for (
int i = 0; i < fileXML_->numChildren(); ++i)
414 std::string tag = child.
getTag();
416 if (tag ==
"MultiVector")
420 long long GlobalLength = child.
getRequired<
long long>(
"Length");
430 std::vector<std::string> tokens;
436 if (tokens.size() == 0)
continue;
439 "wrong number of tokens in line; " 440 <<
"tokens.size() = " << tokens.size()
441 <<
", NumVectors = " << NumVectors);
442 int tsize = (int) tokens.size();
443 for (
int k = 0; k < tsize; ++k)
445 if (Map.
LID(count) != -1)
447 sscanf((
char*)(tokens[k].c_str()),
"%lf", &val);
449 (*MultiVector)[k][Map.
LID(count)] = val;
460 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 465 "No file has been opened");
470 for (
int i = 0; i < fileXML_->numChildren(); ++i)
473 std::string tag = child.
getTag();
484 "Requested map defined with different number of processors, " 485 <<
"NumProc = " << NumProc <<
" while " 486 <<
"Comm.NumProc() = " << Comm_.NumProc());
489 sprintf(str,
"ElementsOnProc%d", Comm_.MyPID());
492 sprintf(str,
"ElementsOnProc%d", Comm_.MyPID());
494 std::vector<int> MyGlobalElements(NumMyElements);
496 for (
int iproc = 0; iproc < child.
numChildren(); ++iproc)
506 std::vector<std::string> tokens;
511 int tsize = (int) tokens.size();
512 for (
int k = 0; k < tsize; ++k)
514 MyGlobalElements[count++] = atoi((
char*)tokens[k].c_str());
520 Map =
new Epetra_Map(NumGlobalElements, NumMyElements,
521 &MyGlobalElements[0], IndexBase, Comm_);
528 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 533 "No file has been opened");
538 for (
int i = 0; i < fileXML_->numChildren(); ++i)
541 std::string tag = child.
getTag();
547 long long NumGlobalElements = child.
getRequired<
long long>(
"NumElements");
548 long long IndexBase = child.
getRequired<
long long>(
"IndexBase");
552 "Requested map defined with different number of processors, " 553 <<
"NumProc = " << NumProc <<
" while " 554 <<
"Comm.NumProc() = " << Comm_.NumProc());
557 sprintf(str,
"ElementsOnProc%d", Comm_.MyPID());
560 sprintf(str,
"ElementsOnProc%d", Comm_.MyPID());
562 std::vector<long long> MyGlobalElements(NumMyElements);
564 for (
int iproc = 0; iproc < child.
numChildren(); ++iproc)
574 std::vector<std::string> tokens;
579 int tsize = (int) tokens.size();
580 for (
int k = 0; k < tsize; ++k)
584 #if defined(_MSC_VER) 585 MyGlobalElements[count++] = _strtoi64((
char*)tokens[k].c_str(), &endp, base);
588 std::istringstream ss(tokens[k]);
589 ss >> MyGlobalElements[count++];
591 MyGlobalElements[count++] = strtoll((
char*)tokens[k].c_str(), &endp, base);
599 Map =
new Epetra_Map(NumGlobalElements, NumMyElements,
600 &MyGlobalElements[0], IndexBase, Comm_);
609 Read(
const std::string& Label, std::vector<std::string>& Content)
612 "No file has been opened");
614 for (
int i = 0; i < fileXML_->numChildren(); ++i)
617 std::string tag = child.
getTag();
626 if (line ==
"\n")
continue;
627 Content.push_back(line);
639 "No file has been opened");
641 for (
int i = 0; i < fileXML_->numChildren(); ++i)
644 std::string tag = child.
getTag();
int getRequiredInt(const std::string &name) const
bool hasAttribute(const std::string &name) const
void Read(const std::string &Label, Epetra_Map *&Map)
Reads the Epetra_Map stored with label Label.
Teuchos::RCP< Teuchos::XMLObject > fileXML_
parsed XML object.
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const XMLObject & getChild(int i) const
RCP< ParameterList > toParameterList(const XMLObject &xml, RCP< DependencySheet > depSheet) const
int InsertGlobalIndices(int_type GlobalRow, int NumIndices, int_type *Indices)
int FillComplete(bool OptimizeDataStorage=true)
const std::string & getContentLine(int i) const
static void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
XMLReader(const Epetra_Comm &Comm, const std::string &FileName)
ctor
int numContentLines() const
const std::string & getTag() const
bool getRequired(const std::string &name) const
void Read64(const std::string &Label, Epetra_Map *&Map)
Reads the Epetra_Map stored with label Label. Long Long version.
bool IsOpen_
If true, then the file has been successfully opened.