Thyra_AssertOp.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef THYRA_ASSERT_OP_HPP
00030 #define THYRA_ASSERT_OP_HPP
00031 
00032 #include "Thyra_OperatorVectorTypes.hpp"
00033 #include "Thyra_VectorSpaceBase.hpp"
00034 #include "Thyra_VectorBase.hpp"
00035 #include "Thyra_LinearOpBase.hpp"
00036 #include "Teuchos_TestForException.hpp"
00037 
00038 namespace Thyra {
00039 
00040 /* Utility struct for dumping vector space names, dimension etc.
00041  */
00042 template<class Scalar>
00043 struct dump_vec_spaces_t {
00044 public:
00045   dump_vec_spaces_t(
00046     const Thyra::VectorSpaceBase<Scalar>& _vec_space1, const std::string &_vec_space1_name
00047     ,const Thyra::VectorSpaceBase<Scalar>& _vec_space2, const std::string &_vec_space2_name
00048     )
00049     :vec_space1(_vec_space1),vec_space1_name(_vec_space1_name)
00050     ,vec_space2(_vec_space2),vec_space2_name(_vec_space2_name)
00051     {}
00052   const Thyra::VectorSpaceBase<Scalar> &vec_space1;
00053   const std::string                    vec_space1_name;
00054   const Thyra::VectorSpaceBase<Scalar> &vec_space2;
00055   const std::string                    vec_space2_name;
00056 }; // end dum_vec_spaces
00057 
00058 /* Utility function for dumping vector space names, dimension etc.
00059  */
00060 template<class Scalar>
00061 inline dump_vec_spaces_t<Scalar> dump_vec_spaces(
00062   const Thyra::VectorSpaceBase<Scalar>& vec_space1, const std::string &vec_space1_name
00063   ,const Thyra::VectorSpaceBase<Scalar>& vec_space2, const std::string &vec_space2_name
00064   )
00065 {
00066   return dump_vec_spaces_t<Scalar>(vec_space1,vec_space1_name,vec_space2,vec_space2_name);
00067 }
00068 
00069 // Notice!!!!!!!  Place a breakpoint in following function in order to halt the
00070 // program just before an exception is thrown!
00071 
00072 /* Utility ostream operator for dumping vector space names, dimension etc.
00073  */
00074 template<class Scalar>
00075 std::ostream& operator<<( std::ostream& o, const dump_vec_spaces_t<Scalar>& d )
00076 {
00077   o << "Error, " << d.vec_space1_name << " at address " << &d.vec_space1
00078     << " described as " << d.vec_space1.description()
00079     << " with dimension " << d.vec_space1_name << ".dim() = " << d.vec_space1.dim()
00080     << " is not compatible with "
00081     << d.vec_space2_name  << " at address " << &d.vec_space2
00082     << " described as " << d.vec_space2.description()
00083     << " with dimension " << d.vec_space2_name << ".dim() = " << d.vec_space2.dim();
00084   return o;
00085 }
00086 
00087 /* Utility enum for selecting domain or range spaces
00088  */
00089 enum EM_VS { VS_RANGE, VS_DOMAIN };
00090 
00095 template<class Scalar>
00096 const Thyra::VectorSpaceBase<Scalar>& linear_op_op(
00097   const Thyra::LinearOpBase<Scalar>&     M
00098   ,Thyra::ETransp                        M_trans
00099   ,EM_VS                                 M_VS
00100   )
00101 {
00102   if(real_trans(M_trans) == NOTRANS && M_VS == VS_RANGE)
00103     return *M.range();
00104   if((real_trans(M_trans) == TRANS || M_trans == CONJTRANS) && M_VS == VS_RANGE)
00105     return *M.domain();
00106   if(real_trans(M_trans) == NOTRANS && M_VS == VS_DOMAIN)
00107     return *M.domain();
00108   // (M_trans == TRANS || M_trans == CONJTRANS) && M_VS == VS_DOMAIN
00109   return *M.range();
00110 }
00111 
00112 } // end namespace Thyra
00113 
00118 #define THYRA_ASSERT_LHS_ARG(FUNC_NAME,LHS_ARG) \
00119   TEST_FOR_EXCEPTION( \
00120     (LHS_ARG) == NULL, std::invalid_argument \
00121     ,FUNC_NAME << " : Error!" \
00122     );
00123 
00124 // Notice!!!!!!!  Setting a breakpoint at the line number that is printed by this macro
00125 // and then trying to set the condition !isCompatible does not work (at least not
00126 // in gdb).
00127 
00132 #define THYRA_ASSERT_VEC_SPACES_NAMES(FUNC_NAME,VS1,VS1_NAME,VS2,VS2_NAME) \
00133 { \
00134   const bool isCompatible = (VS1).isCompatible(VS2); \
00135   TEST_FOR_EXCEPTION( \
00136     !isCompatible, ::Thyra::Exceptions::IncompatibleVectorSpaces \
00137     ,FUNC_NAME << " : " << ::Thyra::dump_vec_spaces(VS1,VS1_NAME,VS2,VS2_NAME) \
00138     ) \
00139 }
00140 
00152 #define THYRA_ASSERT_VEC_SPACES(FUNC_NAME,VS1,VS2)\
00153 THYRA_ASSERT_VEC_SPACES_NAMES(FUNC_NAME,VS1,#VS1,VS2,#VS2)
00154 
00162 #define THYRA_ASSERT_MAT_VEC_SPACES(FUNC_NAME,M,M_T,M_VS,VS) \
00163 { \
00164   std::ostringstream M_VS_name; \
00165   M_VS_name << "(" #M << ( (M_T) == Thyra::NOTRANS ? "" : "'" ) << ")" \
00166             << "." << ( (M_VS) == Thyra::VS_RANGE ? "range()" : "domain()" ); \
00167   THYRA_ASSERT_VEC_SPACES_NAMES( \
00168     FUNC_NAME \
00169     ,::Thyra::linear_op_op(M,M_T,M_VS),M_VS_name.str().c_str() \
00170     ,(VS),#VS \
00171     ) \
00172 }
00173 
00186 #define THYRA_ASSERT_LINEAR_OP_VEC_APPLY_SPACES(FUNC_NAME,M,M_T,X,Y) \
00187   THYRA_ASSERT_LHS_ARG(FUNC_NAME,Y); \
00188   THYRA_ASSERT_MAT_VEC_SPACES(FUNC_NAME,M,M_T,::Thyra::VS_RANGE,*(Y)->space()); \
00189   THYRA_ASSERT_MAT_VEC_SPACES(FUNC_NAME,M,M_T,::Thyra::VS_DOMAIN,*(X).space());
00190 
00203 #define THYRA_ASSERT_LINEAR_OP_MULTIVEC_APPLY_SPACES(FUNC_NAME,M,M_T,X,Y) \
00204   THYRA_ASSERT_LHS_ARG(FUNC_NAME,Y); \
00205   THYRA_ASSERT_VEC_SPACES(FUNC_NAME,*(X).domain(),*(Y)->domain()); \
00206   THYRA_ASSERT_MAT_VEC_SPACES(FUNC_NAME,M,M_T,::Thyra::VS_RANGE,*(Y)->range()); \
00207   THYRA_ASSERT_MAT_VEC_SPACES(FUNC_NAME,M,M_T,::Thyra::VS_DOMAIN,*(X).range());
00208 
00215 #define THYRA_ASSERT_MAT_MAT_SPACES(FUNC_NAME,M1,M1_T,M1_VS,M2,M2_T,M2_VS) \
00216 { \
00217   std::ostringstream M1_VS_name, M2_VS_name; \
00218   M1_VS_name << "(" #M1 << ( M1_T == ::Thyra::NOTRANS ? "" : "'" ) << ")" \
00219          << "." << ( M1_VS == ::Thyra::VS_RANGE ? "range()" : "domain()" ); \
00220   M2_VS_name << "(" #M2 << ( M2_T == ::Thyra::NOTRANS ? "" : "'" ) << ")" \
00221          << "." << ( M2_VS == ::Thyra::VS_RANGE ? "range()" : "domain()" ); \
00222   THYRA_ASSERT_VEC_SPACES_NAMES( \
00223     FUNC_NAME \
00224     ,::Thyra::linear_op_op(M1,M1_T,M1_VS),M1_VS_name.str().c_str() \
00225     ,::Thyra::linear_op_op(M2,M2_T,M2_VS),M2_VS_name.str().c_str() \
00226     ); \
00227 }
00228 
00229 #endif // THYRA_ASSERT_OP_HPP

Generated on Thu Sep 18 12:33:02 2008 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1