Thyra_apply_op_helper.hpp

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_APPLY_OP_HELPER_HPP
00030 #define THYRA_APPLY_OP_HELPER_HPP
00031 
00032 #include "Thyra_apply_op_helper_decl.hpp"
00033 #include "Thyra_VectorBase.hpp"
00034 #include "Thyra_VectorSpaceBase.hpp"
00035 #include "Thyra_AssertOp.hpp"
00036 #include "Teuchos_TestForException.hpp"
00037 #include "Teuchos_as.hpp"
00038 
00039 
00040 template<class Scalar>
00041 void Thyra::apply_op_validate_input(
00042   const std::string &func_name,
00043   const VectorSpaceBase<Scalar> &space,
00044   const RTOpPack::RTOpT<Scalar> &op,
00045   const ArrayView<const Ptr<const VectorBase<Scalar> > > &vecs,
00046   const ArrayView<const Ptr<VectorBase<Scalar> > > &targ_vecs,
00047   const Ptr<RTOpPack::ReductTarget> &reduct_obj,
00048   const Index first_ele_offset_in,
00049   const Index sub_dim_in,
00050   const Index global_offset_in
00051   )
00052 {
00053   const int num_vecs = vecs.size();
00054   const int num_targ_vecs = targ_vecs.size();
00055   const Index
00056     dim = space.dim();
00057   TEST_FOR_EXCEPTION(
00058     global_offset_in < 0, std::logic_error
00059     ,func_name << " : Error! global_offset_in = "
00060     <<global_offset_in<<" is not valid" );
00061   TEST_FOR_EXCEPTION(
00062     first_ele_offset_in+1 > dim, std::logic_error
00063     ,func_name << " : Error! first_ele_offset_in = "
00064     <<first_ele_offset_in<<" is not compatible with space.dim() = " << dim );
00065   TEST_FOR_EXCEPTION(
00066     (sub_dim_in > 0 && sub_dim_in > dim-first_ele_offset_in), std::logic_error
00067     ,func_name << " : Error! first_ele_offset_in = "
00068     <<first_ele_offset_in<<" and sub_dim_in = "<<sub_dim_in
00069     <<" is not compatible with space.dim() = " << dim );
00070   for (int k = 0; k < num_vecs; ++k)
00071     THYRA_ASSERT_VEC_SPACES(func_name,space,*vecs[k]->space());
00072   for (int k = 0; k < num_targ_vecs; ++k)
00073     THYRA_ASSERT_VEC_SPACES(func_name,space,*targ_vecs[k]->space());
00074 }
00075 
00076 
00077 template<class Scalar>
00078 void Thyra::apply_op_validate_input(
00079   const std::string &func_name,
00080   const VectorSpaceBase<Scalar> &domain,
00081   const VectorSpaceBase<Scalar> &range,
00082   const RTOpPack::RTOpT<Scalar> &primary_op,
00083   const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
00084   const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
00085   const ArrayView<const Ptr<RTOpPack::ReductTarget> > &reduct_objs,
00086   const Index primary_first_ele_offset_in,
00087   const Index primary_sub_dim_in,
00088   const Index primary_global_offset_in,
00089   const Index secondary_first_ele_offset_in,
00090   const Index secondary_sub_dim_in
00091   )
00092 {
00093   using Teuchos::as;
00094   // Validate primary range arguments
00095   const Index
00096     range_dim = range.dim();
00097   TEST_FOR_EXCEPTION(
00098     primary_global_offset_in < 0, std::logic_error
00099     ,func_name << " : Error! primary_global_offset_in = "
00100     <<primary_global_offset_in<<" is not valid" );
00101   TEST_FOR_EXCEPTION(
00102     primary_first_ele_offset_in < 0 || range_dim < primary_first_ele_offset_in+1, std::logic_error
00103     ,func_name << " : Error! primary_first_ele_offset_in = "
00104     <<primary_first_ele_offset_in<<" is not compatible with range.dim() = " << range_dim );
00105   TEST_FOR_EXCEPTION(
00106     (primary_sub_dim_in > 0 && primary_sub_dim_in > range_dim-primary_first_ele_offset_in)
00107     , std::logic_error
00108     ,func_name << " : Error! primary_first_ele_offset_in = "
00109     <<primary_first_ele_offset_in<<" and primary_sub_dim_in = "<<primary_sub_dim_in
00110     <<" are not compatible with range.dim() = " << range_dim );
00111   // Validate secondary domain arguments
00112   const Index
00113     domain_dim = domain.dim();
00114   TEST_FOR_EXCEPTION(
00115     secondary_first_ele_offset_in < 0 || domain_dim < secondary_first_ele_offset_in+1, std::logic_error
00116     ,func_name << " : Error! secondary_first_ele_offset_in = "
00117     <<secondary_first_ele_offset_in<<" is not compatible with domain.dim() = " << domain_dim );
00118   TEST_FOR_EXCEPTION(
00119     (secondary_sub_dim_in > 0 && secondary_sub_dim_in > domain_dim-secondary_first_ele_offset_in)
00120     , std::logic_error
00121     ,func_name << " : Error! secondary_first_ele_offset_in = "
00122     <<secondary_first_ele_offset_in<<" and secondary_sub_dim_in = "<<secondary_sub_dim_in
00123     <<" are not compatible with domain.dim() = " << domain_dim );
00124   // Validate spaces
00125   for (int k = 0; k < multi_vecs.size(); ++k) {
00126     THYRA_ASSERT_VEC_SPACES(func_name,domain,*multi_vecs[k]->domain());
00127     THYRA_ASSERT_VEC_SPACES(func_name,range,*multi_vecs[k]->range());
00128   }
00129   for (int k = 0; k < targ_multi_vecs.size(); ++k) {
00130     THYRA_ASSERT_VEC_SPACES(func_name,domain,*targ_multi_vecs[k]->domain());
00131     THYRA_ASSERT_VEC_SPACES(func_name,range,*targ_multi_vecs[k]->range());
00132   }
00133 }
00134 
00135 
00136 #endif // THYRA_APPLY_OP_HELPER_HPP

Generated on Wed May 12 21:42:27 2010 for Thyra Operator/Vector Support by  doxygen 1.4.7