|
EpetraExt Development
|
00001 //@HEADER 00002 // *********************************************************************** 00003 // 00004 // EpetraExt: Epetra Extended - Linear Algebra Services Package 00005 // Copyright (2001) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 00028 00029 #ifndef EPETRAEXT_HDF5_H 00030 #define EPETRAEXT_HDF5_H 00031 00032 #include "EpetraExt_ConfigDefs.h" 00033 #ifdef HAVE_EPETRAEXT_HDF5 00034 00035 #include "hdf5.h" 00036 class Epetra_Map; 00037 class Epetra_BlockMap; 00038 class Epetra_Comm; 00039 class Epetra_IntVector; 00040 class Epetra_MultiVector; 00041 class Epetra_CrsGraph; 00042 class Epetra_RowMatrix; 00043 class Epetra_CrsMatrix; 00044 class Epetra_VbrMatrix; 00045 namespace Teuchos { 00046 class ParameterList; 00047 } 00048 namespace EpetraExt { 00049 class Handle; 00050 template<class T> 00051 class DistArray; 00052 } 00053 00054 namespace EpetraExt 00055 { 00288 class HDF5 00289 { 00290 public: 00291 // @{ \name Constructor and destructor. 00293 HDF5(const Epetra_Comm& Comm); 00294 00296 ~HDF5() 00297 { 00298 if (IsOpen()) 00299 Close(); 00300 } 00301 00302 // @} 00303 // @{ \name Basic operations 00304 00306 void Create(const string FileName); 00307 00309 void Open(const string FileName, int AccessType = H5F_ACC_RDWR); 00310 00312 void Close() 00313 { 00314 H5Fclose(file_id_); 00315 IsOpen_ = false; 00316 } 00317 00319 void Flush() 00320 { 00321 H5Fflush(file_id_, H5F_SCOPE_GLOBAL); 00322 } 00323 00325 bool IsOpen() const 00326 { 00327 return(IsOpen_); 00328 } 00329 00331 void CreateGroup(const string& GroupName) 00332 { 00333 hid_t group_id = H5Gcreate(file_id_, GroupName.c_str(), 0, H5P_DEFAULT, H5P_DEFAULT); 00334 H5Gclose(group_id); 00335 } 00336 00338 bool IsContained(const string Name); 00339 00340 // @} 00341 // @{ \name basic non-distributed data types 00342 00344 void Write(const string& GroupName, const string& DataSetName, int data); 00345 00347 void Read(const string& GroupName, const string& DataSetName, int& data); 00348 00350 void Write(const string& GroupName, const string& DataSetName, double data); 00351 00353 void Read(const string& GroupName, const string& DataSetName, double& data); 00354 00356 void Write(const string& GroupName, const string& DataSetName, const string& data); 00357 00359 void Read(const string& GroupName, const string& DataSetName, string& data); 00360 00362 void Read(const string& GroupName, const string& DataSetName, 00363 const int type, const int Length, void* data); 00364 00366 void Write(const string& GroupName, const string& DataSetName, 00367 const int type, const int Length, 00368 void* data); 00369 00371 void WriteComment(const string& GroupName, string Comment) 00372 { 00373 H5Gset_comment(file_id_, GroupName.c_str(), Comment.c_str()); 00374 } 00375 00377 void ReadComment(const string& GroupName, string& Comment) 00378 { 00379 char comment[128]; 00380 H5Gget_comment(file_id_, GroupName.c_str(), 128, comment); 00381 Comment = comment; 00382 } 00383 00384 // @} 00385 // @{ \name Distributed arrays 00386 00388 void Write(const string& GroupName, const string& DataSetName, int MySize, int GlobalSize, int type, const void* data); 00389 00391 void Read(const string& GroupName, const string& DataSetName, 00392 int MySize, int GlobalSize, 00393 const int type, void* data); 00394 00395 // @} 00396 // @{ \name Epetra_Map/Epetra_BlockMap 00397 00399 void Write(const string& GroupName, const Epetra_Map& Map); 00400 00402 void Read(const string& GroupName, Epetra_Map*& Map); 00403 00405 void ReadMapProperties(const string& GroupName, 00406 int& NumGlobalElements, 00407 int& IndexBase, 00408 int& NumProc); 00409 00411 void Read(const string& GroupName, Epetra_BlockMap*& Map); 00412 00414 void Write(const string& GroupName, const Epetra_BlockMap& Map); 00415 00417 void ReadBlockMapProperties(const string& GroupName, 00418 int& NumGlobalElements, 00419 int& NumGlobalPoints, 00420 int& IndexBase, 00421 int& NumProc); 00422 00423 // @} 00424 // @{ \name Epetra_CrsGraph 00425 00427 void Read(const string& GroupName, Epetra_CrsGraph*& Graph); 00428 00430 void Read(const string& GroupName, const Epetra_Map& DomainMap, 00431 const Epetra_Map& RangeMap, Epetra_CrsGraph*& Graph); 00432 00434 void Write(const string& GroupName, const Epetra_CrsGraph& Graph); 00435 00437 void ReadCrsGraphProperties(const string& GroupName, 00438 int& NumGlobalRows, 00439 int& NumGlobalCols, 00440 int& NumGlobalNonzeros, 00441 int& NumGlobalDiagonals, 00442 int& MaxNumIndices); 00443 00444 // @} 00445 // @{ \name Epetra_IntVector 00446 00448 void Write(const string& GroupName, const Epetra_IntVector& x); 00449 00451 void Read(const string& GroupName, Epetra_IntVector*& X); 00452 00454 void Read(const string& GroupName, const Epetra_Map& Map, Epetra_IntVector*& X); 00455 00457 void ReadIntVectorProperties(const string& GroupName, int& GlobalLength); 00458 00459 // @} 00460 // @{ \name Epetra_MultiVector 00461 00463 void Write(const string& GroupName, const Epetra_MultiVector& x, bool writeTranspose = false); 00464 00466 void Read(const string& GroupName, Epetra_MultiVector*& X, 00467 bool writeTranspose = false, const int& indexBase = 0); 00468 00470 void Read(const string& GroupName, const Epetra_Map& Map, Epetra_MultiVector*& X, 00471 bool writeTranspose = false); 00472 00474 void ReadMultiVectorProperties(const string& GroupName, 00475 int& GlobalLength, 00476 int& NumVectors); 00477 00478 // @} 00479 // @{ \name Epetra_RowMatrix/Epetra_CrsMatrix 00480 00482 void Write(const string& GroupName, const Epetra_RowMatrix& Matrix); 00483 00485 void Read(const string& GroupName, Epetra_CrsMatrix*& A); 00486 00488 void Read(const string& GroupName, 00489 const Epetra_Map& DomainMap, 00490 const Epetra_Map& RangeMap, 00491 Epetra_CrsMatrix*& A); 00492 00494 void ReadCrsMatrixProperties(const string& GroupName, 00495 int& NumGlobalRows, 00496 int& NumGlobalCols, 00497 int& NumNonzeros, 00498 int& NumGlobalDiagonals, 00499 int& MaxNumEntries, 00500 double& NormOne, 00501 double& NormInf); 00502 00503 // @} 00504 // @{ \name Teuchos::ParameterList 00505 00507 void Write(const string& GroupName, const Teuchos::ParameterList& List); 00508 00510 void Read(const string& GroupName, Teuchos::ParameterList& List); 00511 00512 // @} 00513 // @{ \name EpetraExt::DistArray<int> 00514 00516 void Write(const string& GroupName, const DistArray<int>& array); 00517 00519 void Read(const string& GroupName, DistArray<int>*& array); 00520 00522 void Read(const string& GroupName, const Epetra_Map& Map, DistArray<int>*& array); 00523 00525 void ReadIntDistArrayProperties(const string& GroupName, 00526 int& GlobalLength, 00527 int& RowSize); 00528 00529 // @} 00530 // @{ \name EpetraExt::DistArray<double> 00531 00533 void Write(const string& GroupName, const DistArray<double>& array); 00534 00536 void Read(const string& GroupName, DistArray<double>*& array); 00537 00539 void Read(const string& GroupName, const Epetra_Map& Map, DistArray<double>*& array); 00540 00542 void ReadDoubleDistArrayProperties(const string& GroupName, 00543 int& GlobalLength, 00544 int& RowSize); 00545 // @} 00546 // @} 00547 // @{ \name Generic distributed object 00548 00550 void Write(const string& GroupName, const Handle& List); 00551 00553 void Read(const string& GroupName, Handle& List); 00554 00556 void ReadHandleProperties(const string& GroupName, 00557 string& Type, 00558 int& NumGlobalElements); 00559 00560 // @} 00561 private: 00562 // @{ \name Private Data 00563 00565 const Epetra_Comm& Comm() const 00566 { 00567 return(Comm_); 00568 } 00569 00571 const Epetra_Comm& Comm_; 00573 string FileName_; 00575 bool IsOpen_; 00576 00578 hid_t file_id_; 00579 hid_t plist_id_; 00580 herr_t status; 00581 00582 // @} 00583 }; 00584 } 00585 #endif 00586 #endif /* EPETRAEXT_HDF5_H */
1.7.4