All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Xpetra_Utils.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 //
00003 // ***********************************************************************
00004 //
00005 //             Xpetra: A linear algebra interface package
00006 //                  Copyright 2012 Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact
00039 //                    Jonathan Hu       (jhu@sandia.gov)
00040 //                    Andrey Prokopenko (aprokop@sandia.gov)
00041 //                    Ray Tuminaro      (rstumin@sandia.gov)
00042 //
00043 // ***********************************************************************
00044 //
00045 // @HEADER
00046 #include "Xpetra_Utils.hpp"
00047 #include "Xpetra_Exceptions.hpp"
00048 
00049 namespace Xpetra {
00050 
00051   std::string toString(Xpetra::UnderlyingLib lib) {
00052     if (lib == Xpetra::UseTpetra) {
00053       return "Tpetra";
00054     } else if (lib == Xpetra::UseEpetra) {
00055       return "Epetra";
00056     } else {
00057       TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "lib != UseTpetra && lib != UseEpetra");
00058     }
00059   }
00060 
00061 #ifdef HAVE_XPETRA_TPETRA
00062 
00063   Xpetra::LookupStatus toXpetra(Tpetra::LookupStatus ls) {
00064 
00065     if (ls == Tpetra::AllIDsPresent)
00066       return Xpetra::AllIDsPresent;
00067     if (ls == Tpetra::IDNotPresent)
00068       return Xpetra::IDNotPresent;
00069 
00070     TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Unknown LookupStatus");
00071 
00072   }
00073 
00074   Tpetra::ProfileType toTpetra(Xpetra::ProfileType pt) {
00075 
00076     if (pt == Xpetra::StaticProfile)
00077       return Tpetra::StaticProfile;
00078     if (pt == Xpetra::DynamicProfile)
00079       return Tpetra::DynamicProfile;
00080 
00081     TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Unknown ProfileType");
00082 
00083   }
00084 
00085   Tpetra::OptimizeOption toTpetra(Xpetra::OptimizeOption os) {
00086 
00087     if (os == Xpetra::DoOptimizeStorage)
00088       return Tpetra::DoOptimizeStorage;
00089     if (os == Xpetra::DoNotOptimizeStorage)
00090       return Tpetra::DoNotOptimizeStorage;
00091 
00092     TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Unknown OptimizeOption");
00093 
00094   }
00095 
00096   Tpetra::CombineMode toTpetra(Xpetra::CombineMode cm) {
00097 
00098     if (cm == Xpetra::ADD)
00099       return Tpetra::ADD;
00100 
00101     if (cm == Xpetra::INSERT)
00102       return Tpetra::INSERT;
00103 
00104     if (cm == Xpetra::ABSMAX)
00105       return Tpetra::ABSMAX;
00106 
00107     TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Cannot convert Xpetra::CombineMode to Tpetra::CombineMode: unsupported CombineMode.");
00108 
00109   }
00110 
00111   Tpetra::LocalGlobal toTpetra(LocalGlobal lg) {
00112 
00113     if (lg == Xpetra::LocallyReplicated)
00114       return Tpetra::LocallyReplicated;
00115     if (lg == Xpetra::GloballyDistributed)
00116       return Tpetra::GloballyDistributed;
00117 
00118     TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Unknown LocalGlobal");
00119 
00120   }
00121 
00122 #endif // HAVE_XPETRA_TPETRA
00123 
00124 #ifdef HAVE_XPETRA_EPETRA
00125 
00126   Xpetra::LookupStatus toXpetra(int ls) {
00127     // This function is used only to convert the return value of Epetra_BlockMap::RemoteIDList() and Epetra_DirectoryBase::GetDirectoryEntries().
00128     // In the current implementation of Epetra (01/2012), these functions returns 0 (= success) or 1 (= a GID is not present on any processor).
00129 
00130     if (ls == 0)
00131       return Xpetra::AllIDsPresent;
00132     else if (ls == 1)
00133       return Xpetra::IDNotPresent;
00134 
00135     TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Epetra returned the following error code: " << ls << ". Xpetra do not know how to interpret this error code.");
00136   }
00137 
00138   bool toEpetra(Xpetra::ProfileType pt) {
00139 
00140     if (pt == Xpetra::StaticProfile)
00141       return true;
00142     if (pt == Xpetra::DynamicProfile)
00143       return false;
00144 
00145     TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Unknown ProfileType");
00146   }
00147 
00148   bool toEpetra(Xpetra::OptimizeOption os) {
00149 
00150     if (os == Xpetra::DoOptimizeStorage)
00151       return true;
00152     if (os == Xpetra::DoNotOptimizeStorage)
00153       return false;
00154 
00155     TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Unknown OptimizeOption");
00156 
00157   }
00158 
00159   Epetra_CombineMode toEpetra(Xpetra::CombineMode cm) {
00160     // Note: all the CombineMode are not supported.
00161     // According to Chris B., the behavior in Tpetra is the same as Epetra but I prefer to limit my tests for now.
00162     // See also the discussion of March 22 on the Tpetra developers mailing list.
00163 
00164     if (cm == Xpetra::ADD)
00165       return Add;
00166     if (cm == Xpetra::INSERT)
00167       return Insert;
00168     if (cm == Xpetra::ABSMAX)
00169       return AbsMax;
00170 
00171     TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Cannot convert Xpetra::CombineMode to Epetra_CombineMode: unsupported CombineMode.");
00172 
00173   }
00174 
00175 #endif // HAVE_XPETRA_EPETRA
00176 
00177 } // namespace xpetra
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines