NLPInterfacePack_ExampleBasisSystem.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 "NLPInterfacePack_ExampleBasisSystem.hpp"
00030 #include "AbstractLinAlgPack_MatrixSymDiagStd.hpp"
00031 #include "AbstractLinAlgPack_MatrixComposite.hpp"
00032 #include "AbstractLinAlgPack_VectorStdOps.hpp"
00033 #include "Teuchos_AbstractFactoryStd.hpp"
00034 #include "Teuchos_dyn_cast.hpp"
00035 #include "Teuchos_TestForException.hpp"
00036 
00037 namespace NLPInterfacePack {
00038  
00039 ExampleBasisSystem::ExampleBasisSystem(
00040   const VectorSpace::space_ptr_t       &space_x
00041   ,const Range1D                       &var_dep
00042   ,const Range1D                       &var_indep
00043   )
00044   :BasisSystemComposite(
00045     space_x
00046     ,var_dep
00047     ,var_indep
00048     ,space_x->sub_space(var_dep)
00049     ,Teuchos::rcp(
00050       new Teuchos::AbstractFactoryStd<MatrixOpNonsing,MatrixSymDiagStd>())       // C
00051     ,Teuchos::rcp(
00052       new Teuchos::AbstractFactoryStd<MatrixSymOp,MatrixSymDiagStd>())           // D'*D
00053     ,Teuchos::rcp(
00054       new Teuchos::AbstractFactoryStd<MatrixSymOpNonsing,MatrixSymDiagStd>())    // S
00055     ,Teuchos::rcp(
00056       new Teuchos::AbstractFactoryStd<MatrixOp,MatrixSymDiagStd>())              // D
00057     )
00058 {}
00059   
00060 void ExampleBasisSystem::initialize(
00061   const VectorSpace::space_ptr_t       &space_x
00062   ,const Range1D                       &var_dep
00063   ,const Range1D                       &var_indep
00064   )
00065 {
00066   namespace mmp = MemMngPack;
00067   TEST_FOR_EXCEPTION(
00068     space_x.get() == NULL, std::invalid_argument
00069     ,"ExampleBasisSystem::initialize(...) : Error, space_x must be specified!"
00070     );
00071   BasisSystemComposite::initialize(
00072     space_x
00073     ,var_dep
00074     ,var_indep
00075     ,space_x->sub_space(var_dep)
00076     ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOpNonsing,MatrixSymDiagStd>())      // C
00077     ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixSymOp,MatrixSymDiagStd>())          // D'*D
00078     ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixSymOpNonsing,MatrixSymDiagStd>())   // S
00079     ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOp,MatrixSymDiagStd>())             // D
00080     );
00081 }
00082 
00083 void ExampleBasisSystem::update_D(
00084   const MatrixOpNonsing   &C
00085   ,const MatrixOp         &N
00086   ,MatrixOp               *D
00087   ,EMatRelations          mat_rel
00088   ) const
00089 {
00090   using Teuchos::dyn_cast;
00091 
00092   TEST_FOR_EXCEPTION(
00093     D == NULL, std::logic_error
00094     ,"ExampleBasisSystem::update_D(...): Error!" );
00095 
00096   const MatrixSymDiagStd
00097     &C_aggr = dyn_cast<const MatrixSymDiagStd>(C),
00098     &N_aggr = dyn_cast<const MatrixSymDiagStd>(N);
00099   MatrixSymDiagStd
00100     &D_sym_diag = dyn_cast<MatrixSymDiagStd>(*D);
00101   if( D_sym_diag.rows() != C.rows() )
00102     D_sym_diag.initialize(
00103       this->space_x()->sub_space(this->var_dep())->create_member()
00104       );
00105   AbstractLinAlgPack::ele_wise_divide(                           // D_diag = - N_diag ./ C_diag
00106     -1.0, N_aggr.diag(), C_aggr.diag(), &D_sym_diag.diag() );  // ...
00107 }
00108 
00109 } // end namespace NLPInterfacePack

Generated on Wed May 12 21:57:50 2010 for MOOCHO by  doxygen 1.4.7