|
EpetraExt
Development
|
00001 /* 00002 //@HEADER 00003 // *********************************************************************** 00004 // 00005 // EpetraExt: Epetra Extended - Linear Algebra Services Package 00006 // Copyright (2011) Sandia Corporation 00007 // 00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 // the U.S. Government retains certain rights in this software. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00039 // 00040 // *********************************************************************** 00041 //@HEADER 00042 */ 00043 00044 #include "EpetraExt_ConfigDefs.h" 00045 #ifdef HAVE_MPI 00046 #include "Epetra_MpiComm.h" 00047 #include "mpi.h" 00048 #else 00049 #include "Epetra_SerialComm.h" 00050 #endif 00051 #include "EpetraExt_XMLReader.h" 00052 #include "Teuchos_ParameterList.hpp" 00053 #include "Teuchos_RefCountPtr.hpp" 00054 #include "Teuchos_XMLObject.hpp" 00055 #include "Teuchos_StringInputSource.hpp" 00056 #include "Teuchos_FileInputSource.hpp" 00057 #include "Teuchos_ParameterList.hpp" 00058 #include "Teuchos_XMLParameterListReader.hpp" 00059 #include "Teuchos_Assert.hpp" 00060 #include "Epetra_ConfigDefs.h" 00061 #include "Epetra_Map.h" 00062 #include "Epetra_CrsGraph.h" 00063 #include "Epetra_FECrsGraph.h" 00064 #include "Epetra_RowMatrix.h" 00065 #include "Epetra_CrsMatrix.h" 00066 #include "Epetra_FECrsMatrix.h" 00067 #include "Epetra_MultiVector.h" 00068 #include "Epetra_Import.h" 00069 00070 #if defined(__PGI) 00071 #include <sstream> 00072 #endif 00073 00074 // ============================================================================ 00075 static void Tokenize(const std::string& str, std::vector<std::string>& tokens, 00076 const std::string& delimiters = " ") 00077 { 00078 // Skip delimiters at beginning. 00079 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); 00080 // Find first "non-delimiter". 00081 std::string::size_type pos = str.find_first_of(delimiters, lastPos); 00082 00083 while (std::string::npos != pos || std::string::npos != lastPos) 00084 { 00085 // Found a token, add it to the std::vector. 00086 tokens.push_back(str.substr(lastPos, pos - lastPos)); 00087 // Skip delimiters. Note the "not_of" 00088 lastPos = str.find_first_not_of(delimiters, pos); 00089 // Find next "non-delimiter" 00090 pos = str.find_first_of(delimiters, lastPos); 00091 } 00092 } 00093 using namespace Teuchos; 00094 00095 // ============================================================================ 00096 EpetraExt::XMLReader::XMLReader(const Epetra_Comm& comm, const std::string& FileName) : 00097 Comm_(comm) 00098 { 00099 #ifdef HAVE_TEUCHOS_EXPAT 00100 FileInputSource fileSrc(FileName); 00101 fileXML_ = rcp(new XMLObject(fileSrc.getObject())); 00102 IsOpen_ = true; 00103 #else 00104 std::cerr << "Teuchos was not configured with support for expat." << std::endl; 00105 std::cerr << "Please reconfigure teuchos with --enable-teuchos-expat." << std::endl; 00106 exit(EXIT_FAILURE); 00107 #endif 00108 } 00109 00110 // ============================================================================ 00111 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 00112 void EpetraExt::XMLReader:: 00113 Read(const std::string& Label, Epetra_CrsGraph*& Graph) 00114 { 00115 TEUCHOS_TEST_FOR_EXCEPTION(IsOpen_ == false, std::logic_error, 00116 "No file has been opened"); 00117 00118 Graph = 0; 00119 00120 for (int i = 0; i < fileXML_->numChildren(); ++i) 00121 { 00122 const XMLObject& child = fileXML_->getChild(i); 00123 std::string tag = child.getTag(); 00124 00125 if (tag == "Graph") 00126 { 00127 if (child.hasAttribute("Label") && child.getRequired("Label") == Label) 00128 { 00129 bool debug = false; 00130 int NumGlobalRows = child.getRequiredInt("Rows"); 00131 int NumGlobalCols = child.getRequiredInt("Columns"); 00132 int NumGlobalEntries = child.getRequiredInt("Entries"); 00133 int Offset = child.getRequiredInt("StartingIndex"); 00134 if (debug) std::cout << NumGlobalCols << NumGlobalEntries << Offset << std::endl; 00135 00136 Epetra_Map map(NumGlobalRows, 0, Comm_); 00137 Graph = new Epetra_CrsGraph(Copy, map, 0); 00138 00139 for (int j = 0; j < child.numContentLines(); ++j) 00140 { 00141 std::vector<std::string> tokens; 00142 const std::string& line = child.getContentLine(j); 00143 Tokenize(line, tokens, " \n\r\t"); 00144 if (tokens.size() < 2) continue; 00145 00146 int row, col; 00147 row = atoi((char*)tokens[0].c_str()); 00148 col = atoi((char*)tokens[1].c_str()); 00149 00150 if (map.LID(row) != -1) 00151 Graph->InsertGlobalIndices(row, 1, &col); 00152 } 00153 Graph->FillComplete(); 00154 } 00155 } 00156 } 00157 } 00158 #endif 00159 00160 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 00161 void EpetraExt::XMLReader:: 00162 Read64(const std::string& Label, Epetra_CrsGraph*& Graph) 00163 { 00164 TEUCHOS_TEST_FOR_EXCEPTION(IsOpen_ == false, std::logic_error, 00165 "No file has been opened"); 00166 00167 Graph = 0; 00168 00169 for (int i = 0; i < fileXML_->numChildren(); ++i) 00170 { 00171 const XMLObject& child = fileXML_->getChild(i); 00172 std::string tag = child.getTag(); 00173 00174 if (tag == "Graph") 00175 { 00176 if (child.hasAttribute("Label") && child.getRequired("Label") == Label) 00177 { 00178 bool debug = false; 00179 long long NumGlobalRows = child.getRequired<long long>("Rows"); 00180 long long NumGlobalCols = child.getRequired<long long>("Columns"); 00181 long long NumGlobalEntries = child.getRequired<long long>("Entries"); 00182 int Offset = child.getRequiredInt("StartingIndex"); 00183 if (debug) std::cout << NumGlobalCols << NumGlobalEntries << Offset << std::endl; 00184 00185 Epetra_Map map(NumGlobalRows, 0, Comm_); 00186 Graph = new Epetra_CrsGraph(Copy, map, 0); 00187 00188 for (int j = 0; j < child.numContentLines(); ++j) 00189 { 00190 std::vector<std::string> tokens; 00191 const std::string& line = child.getContentLine(j); 00192 Tokenize(line, tokens, " \n\r\t"); 00193 if (tokens.size() < 2) continue; 00194 00195 long long row, col; 00196 char *endp; 00197 const int base = 10; 00198 #if defined(_MSC_VER) 00199 row = _strtoi64((char*)tokens[0].c_str(), &endp, base); 00200 col = _strtoi64((char*)tokens[1].c_str(), &endp, base); 00201 #else 00202 #if defined(__PGI) 00203 std::istringstream ss_row(tokens[0]); 00204 ss_row >> row; 00205 std::istringstream ss_col(tokens[1]); 00206 ss_col >> col; 00207 #else 00208 row = strtoll((char*)tokens[0].c_str(), &endp, base); 00209 col = strtoll((char*)tokens[1].c_str(), &endp, base); 00210 #endif 00211 #endif 00212 00213 if (map.LID(row) != -1) 00214 Graph->InsertGlobalIndices(row, 1, &col); 00215 } 00216 Graph->FillComplete(); 00217 } 00218 } 00219 } 00220 } 00221 #endif 00222 00223 // ============================================================================ 00224 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 00225 void EpetraExt::XMLReader:: 00226 Read(const std::string& Label, Epetra_CrsMatrix*& matrix) 00227 { 00228 TEUCHOS_TEST_FOR_EXCEPTION(IsOpen_ == false, std::logic_error, 00229 "No file has been opened"); 00230 00231 matrix = 0; 00232 00233 for (int i = 0; i < fileXML_->numChildren(); ++i) 00234 { 00235 const XMLObject& child = fileXML_->getChild(i); 00236 std::string tag = child.getTag(); 00237 00238 if (tag == "PointMatrix") 00239 { 00240 if (child.hasAttribute("Label") && child.getRequired("Label") == Label) 00241 { 00242 bool debug = false; 00243 int NumGlobalRows = child.getRequiredInt("Rows"); 00244 int NumGlobalCols = child.getRequiredInt("Columns"); 00245 int NumGlobalNonzeros = child.getRequiredInt("Nonzeros"); 00246 int Offset = child.getRequiredInt("StartingIndex"); 00247 if (debug) std::cout << NumGlobalCols << NumGlobalNonzeros << Offset << std::endl; 00248 00249 Epetra_Map map(NumGlobalRows, 0, Comm_); 00250 matrix = new Epetra_CrsMatrix(Copy, map, 0); 00251 00252 for (int j = 0; j < child.numContentLines(); ++j) 00253 { 00254 std::vector<std::string> tokens; 00255 const std::string& line = child.getContentLine(j); 00256 Tokenize(line, tokens, " \n\r\t"); 00257 if (tokens.size() < 3) continue; 00258 00259 int row, col; 00260 double val; 00261 row = atoi((char*)tokens[0].c_str()); 00262 col = atoi((char*)tokens[1].c_str()); 00263 sscanf((char*)tokens[2].c_str(), "%lg", &val); 00264 //val = atof((char*)tokens[2].c_str()); 00265 00266 if (map.LID(row) != -1) 00267 matrix->InsertGlobalValues(row, 1, &val, &col); 00268 } 00269 matrix->FillComplete(); 00270 } 00271 } 00272 } 00273 } 00274 #endif 00275 00276 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 00277 void EpetraExt::XMLReader:: 00278 Read64(const std::string& Label, Epetra_CrsMatrix*& matrix) 00279 { 00280 TEUCHOS_TEST_FOR_EXCEPTION(IsOpen_ == false, std::logic_error, 00281 "No file has been opened"); 00282 00283 matrix = 0; 00284 00285 for (int i = 0; i < fileXML_->numChildren(); ++i) 00286 { 00287 const XMLObject& child = fileXML_->getChild(i); 00288 std::string tag = child.getTag(); 00289 00290 if (tag == "PointMatrix") 00291 { 00292 if (child.hasAttribute("Label") && child.getRequired("Label") == Label) 00293 { 00294 bool debug = false; 00295 long long NumGlobalRows = child.getRequiredInt("Rows"); 00296 long long NumGlobalCols = child.getRequiredInt("Columns"); 00297 long long NumGlobalNonzeros = child.getRequiredInt("Nonzeros"); 00298 int Offset = child.getRequiredInt("StartingIndex"); 00299 if (debug) std::cout << NumGlobalCols << NumGlobalNonzeros << Offset << std::endl; 00300 00301 Epetra_Map map(NumGlobalRows, 0, Comm_); 00302 matrix = new Epetra_CrsMatrix(Copy, map, 0); 00303 00304 for (int j = 0; j < child.numContentLines(); ++j) 00305 { 00306 std::vector<std::string> tokens; 00307 const std::string& line = child.getContentLine(j); 00308 Tokenize(line, tokens, " \n\r\t"); 00309 if (tokens.size() < 3) continue; 00310 00311 long long row, col; 00312 double val; 00313 char *endp; 00314 const int base = 10; 00315 #if defined(_MSC_VER) 00316 row = _strtoi64((char*)tokens[0].c_str(), &endp, base); 00317 col = _strtoi64((char*)tokens[1].c_str(), &endp, base); 00318 #else 00319 #if defined(__PGI) 00320 std::istringstream ss_row(tokens[0]); 00321 ss_row >> row; 00322 std::istringstream ss_col(tokens[1]); 00323 ss_col >> col; 00324 #else 00325 row = strtoll((char*)tokens[0].c_str(), &endp, base); 00326 col = strtoll((char*)tokens[1].c_str(), &endp, base); 00327 #endif 00328 #endif 00329 sscanf((char*)tokens[2].c_str(), "%lg", &val); 00330 //val = atof((char*)tokens[2].c_str()); 00331 00332 if (map.LID(row) != -1) 00333 matrix->InsertGlobalValues(row, 1, &val, &col); 00334 } 00335 matrix->FillComplete(); 00336 } 00337 } 00338 } 00339 } 00340 #endif 00341 // ============================================================================ 00342 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 00343 void EpetraExt::XMLReader:: 00344 Read(const std::string& Label, Epetra_MultiVector*& MultiVector) 00345 { 00346 TEUCHOS_TEST_FOR_EXCEPTION(IsOpen_ == false, std::logic_error, 00347 "No file has been opened"); 00348 00349 MultiVector = 0; 00350 00351 // read all file and create all objects in memory. 00352 for (int i = 0; i < fileXML_->numChildren(); ++i) 00353 { 00354 const XMLObject& child = fileXML_->getChild(i); 00355 std::string tag = child.getTag(); 00356 00357 if (tag == "MultiVector") 00358 { 00359 if (child.hasAttribute("Label") && child.getRequired("Label") == Label) 00360 { 00361 int GlobalLength = child.getRequiredInt("Length"); 00362 int NumVectors = child.getRequiredInt("NumVectors"); 00363 00364 Epetra_Map Map(GlobalLength, 0, Comm_); 00365 MultiVector = new Epetra_MultiVector(Map, NumVectors); 00366 00367 int count = 0; 00368 double val; 00369 for (int j = 0; j < child.numContentLines(); ++j) 00370 { 00371 std::vector<std::string> tokens; 00372 00373 const std::string& line = child.getContentLine(j); 00374 00375 Tokenize(line, tokens, " \n\r\t"); 00376 00377 if (tokens.size() == 0) continue; 00378 00379 TEUCHOS_TEST_FOR_EXCEPTION(tokens.size() != (unsigned) NumVectors, std::logic_error, 00380 "wrong number of tokens in line; " 00381 << "tokens.size() = " << tokens.size() 00382 << ", NumVectors = " << NumVectors); 00383 int tsize = (int) tokens.size(); 00384 for (int k = 0; k < tsize; ++k) 00385 { 00386 if (Map.LID(count) != -1) 00387 { 00388 sscanf((char*)(tokens[k].c_str()), "%lf", &val); 00389 00390 (*MultiVector)[k][Map.LID(count)] = val; 00391 } 00392 } 00393 ++count; 00394 } 00395 } 00396 } 00397 } 00398 } 00399 #endif 00400 00401 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 00402 void EpetraExt::XMLReader:: 00403 Read64(const std::string& Label, Epetra_MultiVector*& MultiVector) 00404 { 00405 TEUCHOS_TEST_FOR_EXCEPTION(IsOpen_ == false, std::logic_error, 00406 "No file has been opened"); 00407 00408 MultiVector = 0; 00409 00410 // read all file and create all objects in memory. 00411 for (int i = 0; i < fileXML_->numChildren(); ++i) 00412 { 00413 const XMLObject& child = fileXML_->getChild(i); 00414 std::string tag = child.getTag(); 00415 00416 if (tag == "MultiVector") 00417 { 00418 if (child.hasAttribute("Label") && child.getRequired("Label") == Label) 00419 { 00420 long long GlobalLength = child.getRequired<long long>("Length"); 00421 int NumVectors = child.getRequiredInt("NumVectors"); 00422 00423 Epetra_Map Map(GlobalLength, 0, Comm_); 00424 MultiVector = new Epetra_MultiVector(Map, NumVectors); 00425 00426 long long count = 0; 00427 double val; 00428 for (long long j = 0; j < child.numContentLines(); ++j) 00429 { 00430 std::vector<std::string> tokens; 00431 00432 const std::string& line = child.getContentLine(j); 00433 00434 Tokenize(line, tokens, " \n\r\t"); 00435 00436 if (tokens.size() == 0) continue; 00437 00438 TEUCHOS_TEST_FOR_EXCEPTION(tokens.size() != (unsigned) NumVectors, std::logic_error, 00439 "wrong number of tokens in line; " 00440 << "tokens.size() = " << tokens.size() 00441 << ", NumVectors = " << NumVectors); 00442 int tsize = (int) tokens.size(); 00443 for (int k = 0; k < tsize; ++k) 00444 { 00445 if (Map.LID(count) != -1) 00446 { 00447 sscanf((char*)(tokens[k].c_str()), "%lf", &val); 00448 00449 (*MultiVector)[k][Map.LID(count)] = val; 00450 } 00451 } 00452 ++count; 00453 } 00454 } 00455 } 00456 } 00457 } 00458 #endif 00459 // ============================================================================ 00460 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 00461 void EpetraExt::XMLReader:: 00462 Read(const std::string& Label, Epetra_Map*& Map) 00463 { 00464 TEUCHOS_TEST_FOR_EXCEPTION(IsOpen_ == false, std::logic_error, 00465 "No file has been opened"); 00466 00467 Map = 0; 00468 00469 // read all file and create all objects in memory. 00470 for (int i = 0; i < fileXML_->numChildren(); ++i) 00471 { 00472 const XMLObject& child = fileXML_->getChild(i); 00473 std::string tag = child.getTag(); 00474 00475 if (tag == "Map") 00476 { 00477 if (child.hasAttribute("Label") && child.getRequired("Label") == Label) 00478 { 00479 int NumGlobalElements = child.getRequiredInt("NumElements"); 00480 int IndexBase = child.getRequiredInt("IndexBase"); 00481 int NumProc = child.getRequiredInt("NumProc"); 00482 00483 TEUCHOS_TEST_FOR_EXCEPTION(NumProc != Comm_.NumProc(), std::logic_error, 00484 "Requested map defined with different number of processors, " 00485 << "NumProc = " << NumProc << " while " 00486 << "Comm.NumProc() = " << Comm_.NumProc()); 00487 00488 char str[80]; 00489 sprintf(str, "ElementsOnProc%d", Comm_.MyPID()); 00490 int NumMyElements = child.getRequiredInt(str); 00491 00492 sprintf(str, "ElementsOnProc%d", Comm_.MyPID()); 00493 00494 std::vector<int> MyGlobalElements(NumMyElements); 00495 00496 for (int iproc = 0; iproc < child.numChildren(); ++iproc) 00497 { 00498 const XMLObject& newChild = child.getChild(iproc); 00499 int count = 0; 00500 00501 if (newChild.hasAttribute("ID") && 00502 newChild.getRequiredInt("ID") == Comm_.MyPID()) 00503 { 00504 for (int j = 0; j < newChild.numContentLines(); ++j) 00505 { 00506 std::vector<std::string> tokens; 00507 00508 const std::string& line = newChild.getContentLine(j); 00509 00510 Tokenize(line, tokens, " \n\r\t"); 00511 int tsize = (int) tokens.size(); 00512 for (int k = 0; k < tsize; ++k) 00513 { 00514 MyGlobalElements[count++] = atoi((char*)tokens[k].c_str()); 00515 } 00516 } 00517 } 00518 } 00519 00520 Map = new Epetra_Map(NumGlobalElements, NumMyElements, 00521 &MyGlobalElements[0], IndexBase, Comm_); 00522 } 00523 } 00524 } 00525 } 00526 #endif 00527 00528 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 00529 void EpetraExt::XMLReader:: 00530 Read64(const std::string& Label, Epetra_Map*& Map) 00531 { 00532 TEUCHOS_TEST_FOR_EXCEPTION(IsOpen_ == false, std::logic_error, 00533 "No file has been opened"); 00534 00535 Map = 0; 00536 00537 // read all file and create all objects in memory. 00538 for (int i = 0; i < fileXML_->numChildren(); ++i) 00539 { 00540 const XMLObject& child = fileXML_->getChild(i); 00541 std::string tag = child.getTag(); 00542 00543 if (tag == "Map") 00544 { 00545 if (child.hasAttribute("Label") && child.getRequired("Label") == Label) 00546 { 00547 long long NumGlobalElements = child.getRequired<long long>("NumElements"); 00548 long long IndexBase = child.getRequired<long long>("IndexBase"); 00549 int NumProc = child.getRequiredInt("NumProc"); 00550 00551 TEUCHOS_TEST_FOR_EXCEPTION(NumProc != Comm_.NumProc(), std::logic_error, 00552 "Requested map defined with different number of processors, " 00553 << "NumProc = " << NumProc << " while " 00554 << "Comm.NumProc() = " << Comm_.NumProc()); 00555 00556 char str[80]; 00557 sprintf(str, "ElementsOnProc%d", Comm_.MyPID()); 00558 int NumMyElements = child.getRequiredInt(str); 00559 00560 sprintf(str, "ElementsOnProc%d", Comm_.MyPID()); 00561 00562 std::vector<long long> MyGlobalElements(NumMyElements); 00563 00564 for (int iproc = 0; iproc < child.numChildren(); ++iproc) 00565 { 00566 const XMLObject& newChild = child.getChild(iproc); 00567 int count = 0; 00568 00569 if (newChild.hasAttribute("ID") && 00570 newChild.getRequiredInt("ID") == Comm_.MyPID()) 00571 { 00572 for (int j = 0; j < newChild.numContentLines(); ++j) 00573 { 00574 std::vector<std::string> tokens; 00575 00576 const std::string& line = newChild.getContentLine(j); 00577 00578 Tokenize(line, tokens, " \n\r\t"); 00579 int tsize = (int) tokens.size(); 00580 for (int k = 0; k < tsize; ++k) 00581 { 00582 char *endp; 00583 const int base = 10; 00584 #if defined(_MSC_VER) 00585 MyGlobalElements[count++] = _strtoi64((char*)tokens[k].c_str(), &endp, base); 00586 #else 00587 #if defined(__PGI) 00588 std::istringstream ss(tokens[k]); 00589 ss >> MyGlobalElements[count++]; 00590 #else 00591 MyGlobalElements[count++] = strtoll((char*)tokens[k].c_str(), &endp, base); 00592 #endif 00593 #endif 00594 } 00595 } 00596 } 00597 } 00598 00599 Map = new Epetra_Map(NumGlobalElements, NumMyElements, 00600 &MyGlobalElements[0], IndexBase, Comm_); 00601 } 00602 } 00603 } 00604 } 00605 #endif 00606 00607 // ============================================================================ 00608 void EpetraExt::XMLReader:: 00609 Read(const std::string& Label, std::vector<std::string>& Content) 00610 { 00611 TEUCHOS_TEST_FOR_EXCEPTION(IsOpen_ == false, std::logic_error, 00612 "No file has been opened"); 00613 00614 for (int i = 0; i < fileXML_->numChildren(); ++i) 00615 { 00616 const XMLObject& child = fileXML_->getChild(i); 00617 std::string tag = child.getTag(); 00618 00619 if (tag == "Text") 00620 { 00621 if (child.hasAttribute("Label") && child.getRequired("Label") == Label) 00622 { 00623 for (int j = 0; j < child.numContentLines(); ++j) 00624 { 00625 const std::string& line = child.getContentLine(j); 00626 if (line == "\n") continue; 00627 Content.push_back(line); 00628 } 00629 } 00630 } 00631 } 00632 } 00633 00634 // ============================================================================ 00635 void EpetraExt::XMLReader:: 00636 Read(const std::string& Label, Teuchos::ParameterList& List) 00637 { 00638 TEUCHOS_TEST_FOR_EXCEPTION(IsOpen_ == false, std::logic_error, 00639 "No file has been opened"); 00640 00641 for (int i = 0; i < fileXML_->numChildren(); ++i) 00642 { 00643 const XMLObject& child = fileXML_->getChild(i); 00644 std::string tag = child.getTag(); 00645 00646 if (tag == "List") 00647 { 00648 if (child.hasAttribute("Label") && child.getRequired("Label") == Label) 00649 { 00650 Teuchos::XMLParameterListReader ListReader; 00651 List = ListReader.toParameterList(child.getChild(0)); 00652 } 00653 } 00654 } 00655 }
1.7.6.1