• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

MOR_Hdf5MVInputFile.cpp

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 #include "MOR_Hdf5MVInputFile.hpp"
00007 
00008 #include "Epetra_Comm.h"
00009 
00010 #include "EpetraExt_HDF5.h"
00011 
00012 #include "Teuchos_TestForException.hpp"
00013 #include "Teuchos_Assert.hpp"
00014 
00015 #include <stdexcept>
00016 #include <cstddef>
00017 
00018 namespace MOR {
00019 
00020 namespace Detail {
00021 
00022 #ifdef HAVE_EPETRAEXT_HDF5
00023 void openReadOnlyAndCheckGroupName(
00024     EpetraExt::HDF5 &handle,
00025     const std::string &path,
00026     const std::string &groupName)
00027 {
00028   handle.Open(path, H5F_ACC_RDONLY);
00029 
00030   TEUCHOS_TEST_FOR_EXCEPTION(!handle.IsOpen(),
00031       std::runtime_error,
00032       "Cannot open input file: " + path);
00033 
00034   TEUCHOS_TEST_FOR_EXCEPTION(!handle.IsContained(groupName),
00035       std::runtime_error,
00036       "Cannot find source group name :" + groupName + " in file: " + path);
00037 }
00038 #endif /* HAVE_EPETRAEXT_HDF5 */
00039 
00040 } // namespace Detail
00041 
00042 
00043 Hdf5MVInputFile::Hdf5MVInputFile(const std::string &path,
00044                                  const std::string &groupName) :
00045   MultiVectorInputFile(path),
00046   groupName_(groupName)
00047 {
00048   // Nothing to do
00049 }
00050 
00051 int Hdf5MVInputFile::readVectorCount(const Epetra_Comm &comm)
00052 {
00053 #ifdef HAVE_EPETRAEXT_HDF5
00054   EpetraExt::HDF5 hdf5Input(comm);
00055   Detail::openReadOnlyAndCheckGroupName(hdf5Input, this->path(), groupName_);
00056 
00057   int result, dummy;
00058   hdf5Input.ReadMultiVectorProperties(groupName_, dummy, result);
00059 
00060   hdf5Input.Close();
00061 
00062   return result;
00063 #else /* HAVE_EPETRAEXT_HDF5 */
00064   throw std::logic_error("HDF5 support disabled");
00065 #endif /* HAVE_EPETRAEXT_HDF5 */
00066 }
00067 
00068 Teuchos::RCP<Epetra_MultiVector> Hdf5MVInputFile::read(const Epetra_Map &map)
00069 {
00070 #ifdef HAVE_EPETRAEXT_HDF5
00071   EpetraExt::HDF5 hdf5Input(map.Comm());
00072   Detail::openReadOnlyAndCheckGroupName(hdf5Input, this->path(), groupName_);
00073 
00074   // Create an uninitialized raw pointer,
00075   // to be passed by reference to HDF5::Read for initialization
00076   Epetra_MultiVector *raw_result = NULL;
00077   hdf5Input.Read(groupName_, map, raw_result);
00078 
00079   // Take ownership of the returned newly allocated object
00080   Teuchos::RCP<Epetra_MultiVector> result = Teuchos::rcp(raw_result);
00081 
00082   hdf5Input.Close();
00083 
00084   TEUCHOS_TEST_FOR_EXCEPT(result.is_null());
00085   return result;
00086 #else /* HAVE_EPETRAEXT_HDF5 */
00087   throw std::logic_error("HDF5 support disabled");
00088 #endif /* HAVE_EPETRAEXT_HDF5 */
00089 }
00090 
00091 } // namespace MOR

Generated on Wed Mar 26 2014 18:36:40 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1