|
EpetraExt
Development
|
00001 //@HEADER 00002 // *********************************************************************** 00003 // 00004 // EpetraExt: Epetra Extended - Linear Algebra Services Package 00005 // Copyright (2011) Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 //@HEADER 00041 00042 #ifndef EPETRAEXT_HDF5_H 00043 #define EPETRAEXT_HDF5_H 00044 00045 #include "EpetraExt_ConfigDefs.h" 00046 #ifdef HAVE_EPETRAEXT_HDF5 00047 00048 #include <string> 00049 #include "hdf5.h" 00050 class Epetra_Map; 00051 class Epetra_BlockMap; 00052 class Epetra_Comm; 00053 class Epetra_IntVector; 00054 class Epetra_MultiVector; 00055 class Epetra_CrsGraph; 00056 class Epetra_RowMatrix; 00057 class Epetra_CrsMatrix; 00058 class Epetra_VbrMatrix; 00059 namespace Teuchos { 00060 class ParameterList; 00061 } 00062 namespace EpetraExt { 00063 class Handle; 00064 template<class T> 00065 class DistArray; 00066 } 00067 00068 namespace EpetraExt 00069 { 00326 class HDF5 00327 { 00328 public: 00329 // @{ \name Constructor and destructor. 00330 00332 HDF5(const Epetra_Comm& Comm); 00333 00335 ~HDF5() 00336 { 00337 if (IsOpen()) 00338 Close(); 00339 } 00340 00341 // @} 00342 // @{ \name Basic operations 00343 00345 void Create(const std::string FileName); 00346 00348 void Open(const std::string FileName, int AccessType = H5F_ACC_RDWR); 00349 00351 void Close() 00352 { 00353 H5Fclose(file_id_); 00354 IsOpen_ = false; 00355 } 00356 00358 void Flush() 00359 { 00360 H5Fflush(file_id_, H5F_SCOPE_GLOBAL); 00361 } 00362 00364 bool IsOpen() const 00365 { 00366 return(IsOpen_); 00367 } 00368 00370 void CreateGroup(const std::string& GroupName) 00371 { 00372 hid_t group_id = H5Gcreate(file_id_, GroupName.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); 00373 H5Gclose(group_id); 00374 } 00375 00377 bool IsContained(const std::string Name); 00378 00379 // @} 00380 // @{ \name basic non-distributed data types 00381 00383 void Write(const std::string& GroupName, const std::string& DataSetName, int data); 00384 00386 void Read(const std::string& GroupName, const std::string& DataSetName, int& data); 00387 00389 void Write(const std::string& GroupName, const std::string& DataSetName, double data); 00390 00392 void Read(const std::string& GroupName, const std::string& DataSetName, double& data); 00393 00395 void Write(const std::string& GroupName, const std::string& DataSetName, const std::string& data); 00396 00398 void Read(const std::string& GroupName, const std::string& DataSetName, std::string& data); 00399 00401 void Read(const std::string& GroupName, const std::string& DataSetName, 00402 const int type, const int Length, void* data); 00403 00405 void Write(const std::string& GroupName, const std::string& DataSetName, 00406 const int type, const int Length, 00407 void* data); 00408 00410 void WriteComment(const std::string& GroupName, std::string Comment) 00411 { 00412 H5Gset_comment(file_id_, GroupName.c_str(), Comment.c_str()); 00413 } 00414 00416 void ReadComment(const std::string& GroupName, std::string& Comment) 00417 { 00418 char comment[128]; 00419 H5Gget_comment(file_id_, GroupName.c_str(), 128, comment); 00420 Comment = comment; 00421 } 00422 00423 // @} 00424 // @{ \name Distributed arrays 00425 00427 void Write(const std::string& GroupName, const std::string& DataSetName, int MySize, int GlobalSize, int type, const void* data); 00428 00430 void Read(const std::string& GroupName, const std::string& DataSetName, 00431 int MySize, int GlobalSize, 00432 const int type, void* data); 00433 00434 // @} 00435 // @{ \name Epetra_Map/Epetra_BlockMap 00436 00438 void Write(const std::string& GroupName, const Epetra_Map& Map); 00439 00441 void Read(const std::string& GroupName, Epetra_Map*& Map); 00442 00444 void ReadMapProperties(const std::string& GroupName, 00445 int& NumGlobalElements, 00446 int& IndexBase, 00447 int& NumProc); 00448 00450 void Read(const std::string& GroupName, Epetra_BlockMap*& Map); 00451 00453 void Write(const std::string& GroupName, const Epetra_BlockMap& Map); 00454 00456 void ReadBlockMapProperties(const std::string& GroupName, 00457 int& NumGlobalElements, 00458 int& NumGlobalPoints, 00459 int& IndexBase, 00460 int& NumProc); 00461 00462 // @} 00463 // @{ \name Epetra_CrsGraph 00464 00466 void Read(const std::string& GroupName, Epetra_CrsGraph*& Graph); 00467 00469 void Read(const std::string& GroupName, const Epetra_Map& DomainMap, 00470 const Epetra_Map& RangeMap, Epetra_CrsGraph*& Graph); 00471 00473 void Write(const std::string& GroupName, const Epetra_CrsGraph& Graph); 00474 00476 void ReadCrsGraphProperties(const std::string& GroupName, 00477 int& NumGlobalRows, 00478 int& NumGlobalCols, 00479 int& NumGlobalNonzeros, 00480 int& NumGlobalDiagonals, 00481 int& MaxNumIndices); 00482 00483 // @} 00484 // @{ \name Epetra_IntVector 00485 00487 void Write(const std::string& GroupName, const Epetra_IntVector& x); 00488 00490 void Read(const std::string& GroupName, Epetra_IntVector*& X); 00491 00493 void Read(const std::string& GroupName, const Epetra_Map& Map, Epetra_IntVector*& X); 00494 00496 void ReadIntVectorProperties(const std::string& GroupName, int& GlobalLength); 00497 00498 // @} 00499 // @{ \name Epetra_MultiVector 00500 00504 void Write(const std::string& GroupName, const Epetra_MultiVector& x, bool writeTranspose = false); 00505 00510 void Read(const std::string& GroupName, Epetra_MultiVector*& X, 00511 bool writeTranspose = false, const int& indexBase = 0); 00512 00516 void Read(const std::string& GroupName, const Epetra_Map& Map, Epetra_MultiVector*& X, 00517 bool writeTranspose = false); 00518 00520 void ReadMultiVectorProperties(const std::string& GroupName, 00521 int& GlobalLength, 00522 int& NumVectors); 00523 00524 // @} 00525 // @{ \name Epetra_RowMatrix/Epetra_CrsMatrix 00526 00528 void Write(const std::string& GroupName, const Epetra_RowMatrix& Matrix); 00529 00531 void Read(const std::string& GroupName, Epetra_CrsMatrix*& A); 00532 00534 void Read(const std::string& GroupName, 00535 const Epetra_Map& DomainMap, 00536 const Epetra_Map& RangeMap, 00537 Epetra_CrsMatrix*& A); 00538 00540 void ReadCrsMatrixProperties(const std::string& GroupName, 00541 int& NumGlobalRows, 00542 int& NumGlobalCols, 00543 int& NumNonzeros, 00544 int& NumGlobalDiagonals, 00545 int& MaxNumEntries, 00546 double& NormOne, 00547 double& NormInf); 00548 00549 // @} 00550 // @{ \name Teuchos::ParameterList 00551 00553 void Write(const std::string& GroupName, const Teuchos::ParameterList& List); 00554 00556 void Read(const std::string& GroupName, Teuchos::ParameterList& List); 00557 00558 // @} 00559 // @{ \name EpetraExt::DistArray<int> 00560 00562 void Write(const std::string& GroupName, const DistArray<int>& array); 00563 00565 void Read(const std::string& GroupName, DistArray<int>*& array); 00566 00568 void Read(const std::string& GroupName, const Epetra_Map& Map, DistArray<int>*& array); 00569 00571 void ReadIntDistArrayProperties(const std::string& GroupName, 00572 int& GlobalLength, 00573 int& RowSize); 00574 00575 // @} 00576 // @{ \name EpetraExt::DistArray<double> 00577 00579 void Write(const std::string& GroupName, const DistArray<double>& array); 00580 00582 void Read(const std::string& GroupName, DistArray<double>*& array); 00583 00585 void Read(const std::string& GroupName, const Epetra_Map& Map, DistArray<double>*& array); 00586 00588 void ReadDoubleDistArrayProperties(const std::string& GroupName, 00589 int& GlobalLength, 00590 int& RowSize); 00591 // @} 00592 // @} 00593 // @{ \name Generic distributed object 00594 00596 void Write(const std::string& GroupName, const Handle& List); 00597 00599 void Read(const std::string& GroupName, Handle& List); 00600 00602 void ReadHandleProperties(const std::string& GroupName, 00603 std::string& Type, 00604 int& NumGlobalElements); 00605 00606 // @} 00607 private: 00608 // @{ \name Private Data 00609 00611 const Epetra_Comm& Comm() const 00612 { 00613 return(Comm_); 00614 } 00615 00617 const Epetra_Comm& Comm_; 00619 std::string FileName_; 00621 bool IsOpen_; 00622 00624 hid_t file_id_; 00625 hid_t plist_id_; 00626 herr_t status; 00627 00628 // @} 00629 }; 00630 } 00631 #endif 00632 #endif /* EPETRAEXT_HDF5_H */
1.7.6.1