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);
93 using namespace Teuchos;
99 #ifdef HAVE_TEUCHOS_EXPAT
105 std::cerr <<
"Teuchos was not configured with support for expat." << std::endl;
106 std::cerr <<
"Please reconfigure teuchos with --enable-teuchos-expat." << std::endl;
112 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
117 "No file has been opened");
121 for (
int i = 0; i < fileXML_->numChildren(); ++i)
124 std::string tag = child.
getTag();
135 if (debug) std::cout << NumGlobalCols << NumGlobalEntries << Offset << std::endl;
142 std::vector<std::string> tokens;
145 if (tokens.size() < 2)
continue;
148 row = atoi((
char*)tokens[0].c_str());
149 col = atoi((
char*)tokens[1].c_str());
151 if (map.
LID(row) != -1)
161 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
166 "No file has been opened");
170 for (
int i = 0; i < fileXML_->numChildren(); ++i)
173 std::string tag = child.
getTag();
180 long long NumGlobalRows = child.
getRequired<
long long>(
"Rows");
181 long long NumGlobalCols = child.
getRequired<
long long>(
"Columns");
182 long long NumGlobalEntries = child.
getRequired<
long long>(
"Entries");
184 if (debug) std::cout << NumGlobalCols << NumGlobalEntries << Offset << std::endl;
191 std::vector<std::string> tokens;
194 if (tokens.size() < 2)
continue;
199 #if defined(_MSC_VER)
200 row = _strtoi64((
char*)tokens[0].c_str(), &endp, base);
201 col = _strtoi64((
char*)tokens[1].c_str(), &endp, base);
204 std::istringstream ss_row(tokens[0]);
206 std::istringstream ss_col(tokens[1]);
209 row = strtoll((
char*)tokens[0].c_str(), &endp, base);
210 col = strtoll((
char*)tokens[1].c_str(), &endp, base);
214 if (map.
LID(row) != -1)
225 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
230 "No file has been opened");
234 for (
int i = 0; i < fileXML_->numChildren(); ++i)
237 std::string tag = child.
getTag();
239 if (tag ==
"PointMatrix")
248 if (debug) std::cout << NumGlobalCols << NumGlobalNonzeros << Offset << std::endl;
255 std::vector<std::string> tokens;
258 if (tokens.size() < 3)
continue;
262 row = atoi((
char*)tokens[0].c_str());
263 col = atoi((
char*)tokens[1].c_str());
264 sscanf((
char*)tokens[2].c_str(),
"%lg", &val);
267 if (map.
LID(row) != -1)
277 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
282 "No file has been opened");
286 for (
int i = 0; i < fileXML_->numChildren(); ++i)
289 std::string tag = child.
getTag();
291 if (tag ==
"PointMatrix")
300 if (debug) std::cout << NumGlobalCols << NumGlobalNonzeros << Offset << std::endl;
307 std::vector<std::string> tokens;
310 if (tokens.size() < 3)
continue;
316 #if defined(_MSC_VER)
317 row = _strtoi64((
char*)tokens[0].c_str(), &endp, base);
318 col = _strtoi64((
char*)tokens[1].c_str(), &endp, base);
321 std::istringstream ss_row(tokens[0]);
323 std::istringstream ss_col(tokens[1]);
326 row = strtoll((
char*)tokens[0].c_str(), &endp, base);
327 col = strtoll((
char*)tokens[1].c_str(), &endp, base);
330 sscanf((
char*)tokens[2].c_str(),
"%lg", &val);
333 if (map.
LID(row) != -1)
343 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
348 "No file has been opened");
353 for (
int i = 0; i < fileXML_->numChildren(); ++i)
356 std::string tag = child.
getTag();
358 if (tag ==
"MultiVector")
372 std::vector<std::string> tokens;
378 if (tokens.size() == 0)
continue;
381 "wrong number of tokens in line; "
382 <<
"tokens.size() = " << tokens.size()
383 <<
", NumVectors = " << NumVectors);
384 int tsize = (int) tokens.size();
385 for (
int k = 0; k < tsize; ++k)
387 if (Map.
LID(count) != -1)
389 sscanf((
char*)(tokens[k].c_str()),
"%lf", &val);
391 (*MultiVector)[k][Map.
LID(count)] = val;
402 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
407 "No file has been opened");
412 for (
int i = 0; i < fileXML_->numChildren(); ++i)
415 std::string tag = child.
getTag();
417 if (tag ==
"MultiVector")
421 long long GlobalLength = child.
getRequired<
long long>(
"Length");
431 std::vector<std::string> tokens;
437 if (tokens.size() == 0)
continue;
440 "wrong number of tokens in line; "
441 <<
"tokens.size() = " << tokens.size()
442 <<
", NumVectors = " << NumVectors);
443 int tsize = (int) tokens.size();
444 for (
int k = 0; k < tsize; ++k)
446 if (Map.
LID(count) != -1)
448 sscanf((
char*)(tokens[k].c_str()),
"%lf", &val);
450 (*MultiVector)[k][Map.
LID(count)] = val;
461 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
466 "No file has been opened");
471 for (
int i = 0; i < fileXML_->numChildren(); ++i)
474 std::string tag = child.
getTag();
485 "Requested map defined with different number of processors, "
486 <<
"NumProc = " << NumProc <<
" while "
487 <<
"Comm.NumProc() = " << Comm_.NumProc());
490 sprintf(str,
"ElementsOnProc%d", Comm_.MyPID());
493 sprintf(str,
"ElementsOnProc%d", Comm_.MyPID());
495 std::vector<int> MyGlobalElements(NumMyElements);
497 for (
int iproc = 0; iproc < child.
numChildren(); ++iproc)
507 std::vector<std::string> tokens;
512 int tsize = (int) tokens.size();
513 for (
int k = 0; k < tsize; ++k)
515 MyGlobalElements[count++] = atoi((
char*)tokens[k].c_str());
521 Map =
new Epetra_Map(NumGlobalElements, NumMyElements,
522 &MyGlobalElements[0], IndexBase, Comm_);
529 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
534 "No file has been opened");
539 for (
int i = 0; i < fileXML_->numChildren(); ++i)
542 std::string tag = child.
getTag();
548 long long NumGlobalElements = child.
getRequired<
long long>(
"NumElements");
549 long long IndexBase = child.
getRequired<
long long>(
"IndexBase");
553 "Requested map defined with different number of processors, "
554 <<
"NumProc = " << NumProc <<
" while "
555 <<
"Comm.NumProc() = " << Comm_.NumProc());
558 sprintf(str,
"ElementsOnProc%d", Comm_.MyPID());
561 sprintf(str,
"ElementsOnProc%d", Comm_.MyPID());
563 std::vector<long long> MyGlobalElements(NumMyElements);
565 for (
int iproc = 0; iproc < child.
numChildren(); ++iproc)
575 std::vector<std::string> tokens;
580 int tsize = (int) tokens.size();
581 for (
int k = 0; k < tsize; ++k)
585 #if defined(_MSC_VER)
586 MyGlobalElements[count++] = _strtoi64((
char*)tokens[k].c_str(), &endp, base);
589 std::istringstream ss(tokens[k]);
590 ss >> MyGlobalElements[count++];
592 MyGlobalElements[count++] = strtoll((
char*)tokens[k].c_str(), &endp, base);
600 Map =
new Epetra_Map(NumGlobalElements, NumMyElements,
601 &MyGlobalElements[0], IndexBase, Comm_);
610 Read(
const std::string& Label, std::vector<std::string>& Content)
613 "No file has been opened");
615 for (
int i = 0; i < fileXML_->numChildren(); ++i)
618 std::string tag = child.
getTag();
627 if (line ==
"\n")
continue;
628 Content.push_back(line);
640 "No file has been opened");
642 for (
int i = 0; i < fileXML_->numChildren(); ++i)
645 std::string tag = child.
getTag();
const std::string & getTag() 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)
int getRequiredInt(const std::string &name) const
int InsertGlobalIndices(int_type GlobalRow, int NumIndices, int_type *Indices)
int FillComplete(bool OptimizeDataStorage=true)
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
RCP< ParameterList > toParameterList(const XMLObject &xml, RCP< DependencySheet > depSheet) const
int numContentLines() const
const XMLObject & getChild(int i) const
bool hasAttribute(const std::string &name) const
const std::string & getContentLine(int i) const
const std::string & 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.