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_MultiVectorOutputFileFactory.hpp" 00007 00008 #include "MOR_MatrixMarketMVOutputFile.hpp" 00009 #include "MOR_Hdf5MVOutputFile.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 MultiVectorOutputFileFactory::MultiVectorOutputFileFactory(const Teuchos::RCP<Teuchos::ParameterList> ¶ms) : 00028 params_(params) 00029 { 00030 initValidFileFormats(); 00031 initOutputFileFormat(); 00032 initOutputFileName(); 00033 } 00034 00035 RCP<MultiVectorOutputFile> MultiVectorOutputFileFactory::create() 00036 { 00037 RCP<MultiVectorOutputFile> result; 00038 if (outputFileFormat_ == "Matrix Market") { 00039 result = rcp(new MatrixMarketMVOutputFile(outputFileName_)); 00040 } 00041 if (outputFileFormat_ == "HDF5") { 00042 const std::string groupName = params_->get("Output File Group Name", "default"); 00043 result = rcp(new Hdf5MVOutputFile(outputFileName_, groupName)); 00044 } 00045 00046 TEUCHOS_ASSERT(nonnull(result)); 00047 return result; 00048 } 00049 00050 void MultiVectorOutputFileFactory::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 MultiVectorOutputFileFactory::initOutputFileFormat() 00059 { 00060 const std::string outputFileFormat = params_->get("Output File Format", validFileFormats_[0]); 00061 TEUCHOS_TEST_FOR_EXCEPTION(!contains(validFileFormats_, outputFileFormat), 00062 std::out_of_range, 00063 outputFileFormat + " not in " + validFileFormats_.toString()); 00064 outputFileFormat_ = outputFileFormat; 00065 } 00066 00067 void MultiVectorOutputFileFactory::initOutputFileName() 00068 { 00069 const std::string userOutputFileName = params_->get("Output File Name", ""); 00070 const std::string defaultOutputBaseFileName = params_->get("Output File Default Base File Name", "default_out"); 00071 00072 std::string defaultOutputFilePostfix; 00073 if (outputFileFormat_ == "Matrix Market") defaultOutputFilePostfix = "mtx"; 00074 if (outputFileFormat_ == "HDF5") defaultOutputFilePostfix = "hdf5"; 00075 const std::string defaultOutputFileName = defaultOutputBaseFileName + "." + defaultOutputFilePostfix; 00076 00077 const std::string outputFileName = !userOutputFileName.empty() ? userOutputFileName : defaultOutputFileName; 00078 00079 outputFileName_ = outputFileName; 00080 } 00081 00082 } // namespace MOR