MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NLPInterfacePack_ExampleBasisSystem.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
47 #include "Teuchos_dyn_cast.hpp"
48 #include "Teuchos_Assert.hpp"
49 
50 namespace NLPInterfacePack {
51 
53  const VectorSpace::space_ptr_t &space_x
54  ,const Range1D &var_dep
55  ,const Range1D &var_indep
56  )
57  :BasisSystemComposite(
58  space_x
59  ,var_dep
60  ,var_indep
61  ,space_x->sub_space(var_dep)
62  ,Teuchos::rcp(
63  new Teuchos::AbstractFactoryStd<MatrixOpNonsing,MatrixSymDiagStd>()) // C
64  ,Teuchos::rcp(
65  new Teuchos::AbstractFactoryStd<MatrixSymOp,MatrixSymDiagStd>()) // D'*D
66  ,Teuchos::rcp(
67  new Teuchos::AbstractFactoryStd<MatrixSymOpNonsing,MatrixSymDiagStd>()) // S
68  ,Teuchos::rcp(
69  new Teuchos::AbstractFactoryStd<MatrixOp,MatrixSymDiagStd>()) // D
70  )
71 {}
72 
74  const VectorSpace::space_ptr_t &space_x
75  ,const Range1D &var_dep
76  ,const Range1D &var_indep
77  )
78 {
79  namespace mmp = MemMngPack;
81  space_x.get() == NULL, std::invalid_argument
82  ,"ExampleBasisSystem::initialize(...) : Error, space_x must be specified!"
83  );
84  BasisSystemComposite::initialize(
85  space_x
86  ,var_dep
87  ,var_indep
88  ,space_x->sub_space(var_dep)
93  );
94 }
95 
97  const MatrixOpNonsing &C
98  ,const MatrixOp &N
99  ,MatrixOp *D
100  ,EMatRelations mat_rel
101  ) const
102 {
103  using Teuchos::dyn_cast;
104 
106  D == NULL, std::logic_error
107  ,"ExampleBasisSystem::update_D(...): Error!" );
108 
109  const MatrixSymDiagStd
110  &C_aggr = dyn_cast<const MatrixSymDiagStd>(C),
111  &N_aggr = dyn_cast<const MatrixSymDiagStd>(N);
112  MatrixSymDiagStd
113  &D_sym_diag = dyn_cast<MatrixSymDiagStd>(*D);
114  if( D_sym_diag.rows() != C.rows() )
115  D_sym_diag.initialize(
116  this->space_x()->sub_space(this->var_dep())->create_member()
117  );
118  AbstractLinAlgPack::ele_wise_divide( // D_diag = - N_diag ./ C_diag
119  -1.0, N_aggr.diag(), C_aggr.diag(), &D_sym_diag.diag() ); // ...
120 }
121 
122 } // end namespace NLPInterfacePack
void update_D(const MatrixOpNonsing &C, const MatrixOp &N, MatrixOp *D, EMatRelations mat_rel) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void ele_wise_divide(const value_type &alpha, const Vector &v_rhs1, const Vector &v_rhs2, VectorMutable *v_lhs)
v_lhs(i) = alpha * v_rhs1(i) / v_rhs2(i), i = 1,,,dim.
void initialize(const VectorSpace::space_ptr_t &space_x, const Range1D &var_dep, const Range1D &var_indep)
Initialize given the vector space for the dependent and independent variables.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
T_To & dyn_cast(T_From &from)
const LAPACK_C_Decl::f_int const LAPACK_C_Decl::f_int const LAPACK_C_Decl::f_int const LAPACK_C_Decl::f_dbl_prec const LAPACK_C_Decl::f_int const LAPACK_C_Decl::f_dbl_prec LAPACK_C_Decl::f_dbl_prec * C
const f_int const f_int & N