AbstractLinAlgPack_MatrixBasisNonbasisStd.cpp

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 // 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 Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <stdexcept>
00030 #include <string>
00031 
00032 #include "AbstractLinAlgPack_MatrixBasisNonbasisStd.hpp"
00033 
00034 namespace AbstractLinAlgPack {
00035 
00036 MatrixBasisNonbasisStd::MatrixBasisNonbasisStd()
00037   : C_(NULL), C_nonsingular_(NULL), N_(NULL)
00038 {}
00039 
00040 void MatrixBasisNonbasisStd::initialize(
00041     const C_ptr_t&                  C
00042   , const C_nonsingular_ptr_t&      C_nonsingular
00043   , const N_ptr_t&                  N
00044   )
00045 {
00046   if( C.get() == NULL && N.get() != NULL )
00047     throw std::logic_error(
00048       "MatrixBasisNonbasisStd::initialize(...) : Error , "
00049       "If N!=NULL then C must be non-NULL" );
00050   if( C.get() == NULL && C_nonsingular.get() != NULL )
00051     throw std::logic_error(
00052       "MatrixBasisNonbasisStd::initialize(...) : Error , "
00053       "If C_nonsingular!=NULL then C must be non-NULL" );
00054   if( C.get() != NULL ) {
00055     if( C->rows() != C->cols() )
00056       throw std::length_error(
00057         "MatrixBasisNonbasisStd::initialize(...) : Error , "
00058         "C->rows() must equal C->cols()" );
00059      if( N.get()!=NULL && C->rows() != N->rows() ) {
00060       throw std::length_error(
00061         "MatrixBasisNonbasisStd::initialize(...) : Error , "
00062         "N->rows() must equal C->cols()" );
00063     }
00064      if( C_nonsingular.get()!=NULL
00065       && (C_nonsingular->rows() != C->rows() || C_nonsingular->cols() != C->cols() ) )
00066     {
00067       throw std::length_error(
00068         "MatrixBasisNonbasisStd::initialize(...) : Error , "
00069         "C_nonsingular must be the same dimension as C" );
00070     }
00071   }
00072   C_             = C;             // Will delete the Old C if C_->count() == 1
00073   C_nonsingular_ = C_nonsingular; // Same here
00074   N_             = N;             // Same here
00075 } 
00076 
00077 // Overridden from MatrixOp
00078 
00079 size_type MatrixBasisNonbasisStd::rows() const
00080 {
00081   return C_.get() ? C_->cols() + (N_.get() ? N_->cols() : 0) : 0;
00082 }
00083 
00084 size_type MatrixBasisNonbasisStd::cols() const
00085 {
00086   return C_.get() ? C_->rows() : 0;
00087 }
00088   
00089 // Overridden from MatrixBasisNonbasis
00090 
00091 const MatrixOp& MatrixBasisNonbasisStd::C() const
00092 {
00093   if(C_.get()==NULL)
00094     throw std::logic_error(
00095       "MatrixBasisNonbasisStd::C() : Error, "
00096       "Matrix not initialized!" );
00097   return *C_;
00098 }
00099 
00100 const MatrixFactorized& MatrixBasisNonbasisStd::C_nonsingular() const
00101 {
00102   if(C_.get()==NULL)
00103     throw std::logic_error(
00104       "MatrixBasisNonbasisStd::C_nonsingular() : Error, "
00105       "Matrix not set!" );
00106   return *C_nonsingular_;
00107 }
00108 
00109 const MatrixOp& MatrixBasisNonbasisStd::N() const
00110 {
00111   if(N_.get()==NULL)
00112     throw std::logic_error(
00113       "MatrixBasisNonbasisStd::N() : Error, "
00114       "Matrix has not been initialized or there is no N matrix!" );
00115   return *N_;
00116 }
00117 
00118 } // end namespace AbstractLinAlgPack 

Generated on Thu Sep 18 12:33:51 2008 for AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects by doxygen 1.3.9.1