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_MultiVectorInputFileFactory.hpp" 00007 00008 #include "MOR_MatrixMarketMVInputFile.hpp" 00009 #include "MOR_Hdf5MVInputFile.hpp" 00010 #include "MOR_ContainerUtils.hpp" 00011 00012 #include "Teuchos_Array.hpp" 00013 00014 #include "EpetraExt_ConfigDefs.h" 00015 00016 #include "Teuchos_TestForException.hpp" 00017 00018 #include <stdexcept> 00019 00020 namespace MOR { 00021 00022 using Teuchos::RCP; 00023 using Teuchos::rcp; 00024 using Teuchos::ParameterList; 00025 using Teuchos::Array; 00026 00027 MultiVectorInputFileFactory::MultiVectorInputFileFactory(const Teuchos::RCP<Teuchos::ParameterList> ¶ms) : 00028 params_(params) 00029 { 00030 initValidFileFormats(); 00031 initInputFileFormat(); 00032 initInputFileName(); 00033 } 00034 00035 RCP<MultiVectorInputFile> MultiVectorInputFileFactory::create() 00036 { 00037 RCP<MultiVectorInputFile> result; 00038 if (inputFileFormat_ == "Matrix Market") { 00039 result = rcp(new MatrixMarketMVInputFile(inputFileName_)); 00040 } 00041 if (inputFileFormat_ == "HDF5") { 00042 const std::string groupName = params_->get("Input File Group Name", "default"); 00043 result = rcp(new Hdf5MVInputFile(inputFileName_, groupName)); 00044 } 00045 00046 TEUCHOS_ASSERT(nonnull(result)); 00047 return result; 00048 } 00049 00050 void MultiVectorInputFileFactory::initValidFileFormats() 00051 { 00052 validFileFormats_.append("Matrix Market"); 00053 #ifdef HAVE_EPETRAEXT_HDF5 00054 validFileFormats_.append("HDF5"); 00055 #endif /* HAVE_EPETRAEXT_HDF5 */ 00056 } 00057 00058 void MultiVectorInputFileFactory::initInputFileFormat() 00059 { 00060 const std::string inputFileFormat = params_->get("Input File Format", validFileFormats_[0]); 00061 TEUCHOS_TEST_FOR_EXCEPTION(!contains(validFileFormats_, inputFileFormat), 00062 std::out_of_range, 00063 inputFileFormat + " not in " + validFileFormats_.toString()); 00064 inputFileFormat_ = inputFileFormat; 00065 } 00066 00067 void MultiVectorInputFileFactory::initInputFileName() { 00068 const std::string userInputFileName = params_->get("Input File Name", ""); 00069 const std::string defaultInputBaseFileName = params_->get("Input File Default Base File Name", "default_in"); 00070 00071 std::string defaultInputFilePostfix; 00072 if (inputFileFormat_ == "Matrix Market") defaultInputFilePostfix = "mtx"; 00073 if (inputFileFormat_ == "HDF5") defaultInputFilePostfix = "hdf5"; 00074 const std::string defaultInputFileName = defaultInputBaseFileName + "." + defaultInputFilePostfix; 00075 00076 const std::string inputFileName = !userInputFileName.empty() ? userInputFileName : defaultInputFileName; 00077 00078 inputFileName_ = inputFileName; 00079 } 00080 00081 } // namespace MOR