MOOCHO (Single Doxygen Collection) Version of the Day
AbstractLinAlgPack_MatrixSymNonsingSerial.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) 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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include <assert.h>
00043 
00044 #include "AbstractLinAlgPack_MatrixSymNonsingSerial.hpp"
00045 #include "AbstractLinAlgPack_MatrixSymOpGetGMSSymMutable.hpp"
00046 #include "AbstractLinAlgPack_MatrixOpSerial.hpp"
00047 #include "AbstractLinAlgPack_EtaVector.hpp"
00048 #include "DenseLinAlgPack_DMatrixClass.hpp"
00049 #include "DenseLinAlgPack_DMatrixOp.hpp"
00050 #include "DenseLinAlgPack_DMatrixAsTriSym.hpp"
00051 #include "AbstractLinAlgPack_LinAlgOpPackHack.hpp"
00052 #include "DenseLinAlgPack_AssertOp.hpp"
00053 #include "Teuchos_dyn_cast.hpp"
00054 
00055 namespace LinAlgOpPack {
00056   using AbstractLinAlgPack::Vp_StMtV;
00057   using AbstractLinAlgPack::Mp_StMtM;
00058 }
00059 
00060 namespace AbstractLinAlgPack {
00061 
00062 void MatrixSymNonsingSerial::M_StMtInvMtM(
00063     DMatrixSliceSym* S, value_type a, const MatrixOpSerial& B
00064   , BLAS_Cpp::Transp B_trans, EMatrixDummyArg ) const
00065 {
00066   using BLAS_Cpp::trans;
00067   using BLAS_Cpp::no_trans;
00068   using BLAS_Cpp::trans_not;
00069   using AbstractLinAlgPack::M_StInvMtM;
00070   using DenseLinAlgPack::nonconst_tri_ele;
00071   using DenseLinAlgPack::tri_ele;
00072   using DenseLinAlgPack::assign;
00073   using LinAlgOpPack::M_StMtM;
00074   //
00075   // S = a * op(B) * inv(M) * op(B')
00076   //
00077   // We will form S won column at a time:
00078   //
00079   // S(:,j) = a * op(B) * inv(M) * op(B') * e(j)
00080   //
00081   // for j = 1 ... op(B').cols()
00082   //   t1 = op(B')*e(j)
00083   //   t2 = inv(M)*t1
00084   //   t3 = a*op(B)*t2
00085   //   S(:,j) = t3
00086   //
00087   // Above we only need to set the lower (lower triangle stored)
00088   // or upper (upper triangle stored) part of S(:,k)
00089   //
00090   DenseLinAlgPack::MtM_assert_sizes( rows(), cols(), no_trans
00091     , B.rows(), B.cols(), trans_not(B_trans) );
00092   DenseLinAlgPack::Mp_MtM_assert_sizes( S->rows(), S->cols(), no_trans
00093     , B.rows(), B.cols(), B_trans
00094     , B.rows(), B.cols(), trans_not(B_trans) );
00095 
00096   DVector t1, t2, t3; // ToDo: Use temp workspace!
00097   const size_type
00098     opBT_cols = BLAS_Cpp::cols( B.cols(), B.rows(), B_trans ),
00099     m         = S->rows();
00100   for( size_type j = 1; j <= m; ++j ) {
00101     EtaVector e_j(j,opBT_cols);                               // e(j)
00102     LinAlgOpPack::V_MtV( &t1, B, trans_not(B_trans), e_j() ); // t1 = op(B')*e(j)
00103     AbstractLinAlgPack::V_InvMtV( &t2, *this, no_trans, t1() ); // t2 = inv(M)*t1
00104     LinAlgOpPack::V_StMtV( &t3, a, B, B_trans, t2() );        // t3 = a*op(B)*t2
00105     Range1D
00106       rng = ( S->uplo() == BLAS_Cpp::upper ? Range1D(1,j) : Range1D(j,m) );
00107     S->gms().col(j)(rng) = t3(rng);
00108   }
00109 }
00110 
00111 // Overridden from MatrixSymNonsing
00112 
00113 void MatrixSymNonsingSerial::M_StMtInvMtM(
00114   MatrixSymOp* symwo_lhs, value_type alpha
00115   ,const MatrixOp& mwo, BLAS_Cpp::Transp mwo_trans
00116   ,EMatrixDummyArg dummy
00117   ) const
00118 {
00119   using Teuchos::dyn_cast;
00120   this->M_StMtInvMtM(
00121     &MatrixDenseSymMutableEncap(symwo_lhs)(), alpha
00122     ,dyn_cast<const MatrixOpSerial>(mwo), mwo_trans
00123     ,dummy );
00124 }
00125 
00126 } // end namespace AbstractLinAlgPack
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines