Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "Albany_Utils.hpp"
00007 #include "Teuchos_TestForException.hpp"
00008 #include <cstdlib>
00009 #include <stdexcept>
00010
00011
00012 #ifdef ALBANY_MPI
00013
00014 const Albany_MPI_Comm Albany::getMpiCommFromEpetraComm(const Epetra_Comm& ec) {
00015 const Epetra_MpiComm& emc = dynamic_cast<const Epetra_MpiComm&>(ec);
00016 return emc.Comm();
00017 }
00018
00019 Albany_MPI_Comm Albany::getMpiCommFromEpetraComm(Epetra_Comm& ec) {
00020 Epetra_MpiComm& emc = dynamic_cast<Epetra_MpiComm&>(ec);
00021 return emc.Comm();
00022 }
00023
00024 Teuchos::RCP<Epetra_Comm> Albany::createEpetraCommFromMpiComm(const Albany_MPI_Comm& mc) {
00025 return Teuchos::rcp(new Epetra_MpiComm(mc));
00026 }
00027
00028 Teuchos::RCP<Teuchos::Comm<int> > Albany::createTeuchosCommFromMpiComm(const Albany_MPI_Comm& mc) {
00029 return Teuchos::rcp(new Teuchos::MpiComm<int>(Teuchos::opaqueWrapper(mc)));
00030 }
00031
00032 #else
00033
00034 const Albany_MPI_Comm Albany::getMpiCommFromEpetraComm(const Epetra_Comm& ec) { return 1; }
00035
00036 Albany_MPI_Comm Albany::getMpiCommFromEpetraComm(Epetra_Comm& ec) { return 1; }
00037
00038 Teuchos::RCP<Epetra_Comm> Albany::createEpetraCommFromMpiComm(const Albany_MPI_Comm& mc) {
00039 return Teuchos::rcp(new Epetra_SerialComm);
00040 }
00041
00042 Teuchos::RCP<Teuchos::Comm<int> > Albany::createTeuchosCommFromMpiComm(const Albany_MPI_Comm& mc) {
00043 return Teuchos::rcp(new Teuchos::SerialComm<int>());
00044 }
00045 #endif
00046
00047
00048 std::string Albany::strint(const std::string s, const int i) {
00049 std::ostringstream ss;
00050 ss << s << " " << i;
00051 return ss.str();
00052 }
00053
00054 bool Albany::isValidInitString(const std::string& initString) {
00055
00056
00057 std::string verbiage("initial value ");
00058 size_t pos = initString.find(verbiage);
00059 if(pos != 0)
00060 return false;
00061
00062
00063 std::string valueString = initString.substr(verbiage.size(), initString.size() - verbiage.size());
00064 int decimalPointCount = 0;
00065 for(std::string::iterator it=valueString.begin() ; it!=valueString.end() ; it++){
00066 std::string charAsString(1, *it);
00067 size_t pos = charAsString.find_first_of("0123456789.-+eE");
00068 if(pos == std::string::npos)
00069 return false;
00070 }
00071
00072 return true;
00073 }
00074
00075 std::string Albany::doubleToInitString(double val) {
00076 std::string verbiage("initial value ");
00077 std::stringstream ss;
00078 ss << verbiage << val;
00079 return ss.str();
00080 }
00081
00082 double Albany::initStringToDouble(const std::string& initString) {
00083 TEUCHOS_TEST_FOR_EXCEPTION(!Albany::isValidInitString(initString), std::range_error,
00084 " initStringToDouble() called with invalid initialization string: " + initString + "\n");
00085 std::string verbiage("initial value ");
00086 std::string valueString = initString.substr(verbiage.size(), initString.size() - verbiage.size());
00087 return std::atof(valueString.c_str());
00088 }
00089
00090 void Albany::splitStringOnDelim(const std::string &s, char delim, std::vector<std::string> &elems) {
00091 std::stringstream ss(s);
00092 std::string item;
00093 while(std::getline(ss, item, delim)) {
00094 elems.push_back(item);
00095 }
00096 }