ConstrainedOptPack: C++ Tools for Constrained (and Unconstrained) Optimization  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ConstrainedOptPack_DecompositionSystemCoordinate.cpp
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 
42 #include <assert.h>
43 
44 #include "ConstrainedOptPack_DecompositionSystemCoordinate.hpp"
45 #include "ConstrainedOptPack_MatrixIdentConcatStd.hpp"
46 #include "AbstractLinAlgPack_MatrixOpNonsing.hpp"
47 #include "AbstractLinAlgPack_MatrixOpSubView.hpp"
48 #include "AbstractLinAlgPack_MatrixZero.hpp"
49 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
50 #include "Teuchos_AbstractFactoryStd.hpp"
51 #include "Teuchos_dyn_cast.hpp"
52 #include "Teuchos_Assert.hpp"
53 
54 namespace ConstrainedOptPack {
55 
57  const VectorSpace::space_ptr_t &space_x
58  ,const VectorSpace::space_ptr_t &space_c
59  ,const basis_sys_ptr_t &basis_sys
60  ,const basis_sys_tester_ptr_t &basis_sys_tester
61  ,EExplicitImplicit D_imp
62  ,EExplicitImplicit Uz_imp
63  )
65  space_x, space_c, basis_sys, basis_sys_tester
66  ,D_imp, Uz_imp )
67 {}
68 
69 // Overridden from DecompositionSystem
70 
73 {
74  namespace rcp = MemMngPack;
75  return Teuchos::rcp(
77  );
78 }
79 
82 {
83  if( basis_sys().get() )
84  return basis_sys()->factory_C();
85  return Teuchos::null;
86 }
87 
90 {
92 }
93 
94 // Overridden from DecompositionSystemVarReductImp
95 
96 DecompositionSystem::mat_nonsing_fcty_ptr_t::element_type::obj_ptr_t
98  std::ostream *out
99  ,EOutputLevel olevel
100  ,MatrixOp *Y
101  ,MatrixOpNonsing *R
102  ,MatrixOp *Uy
103  ) const
104 {
105  namespace rcp = MemMngPack;
106  using Teuchos::dyn_cast;
107 
108  //
109  // Get pointers to concreate matrices
110  //
111 
112  MatrixOpSubView
113  *Uy_sv = Uy ? &dyn_cast<MatrixOpSubView>(*Uy) : NULL;
114 
115  //
116  // Only uninitialize the sub_view matrices
117  //
118 
119  if(Uy_sv)
120  Uy_sv->initialize(Teuchos::null);
121 
122  //
123  // Return the basis matrix object R == C as a smart pointer that is
124  // not owned. This matrix object (if R != NULL) will get updated
125  // by the basis_sys object as C in the method
126  //
127  // DecompositionSystemVarReductImp::update_decomp(...)
128  //
129 
130  return Teuchos::rcp(R,false);
131 
132 }
133 
135  std::ostream *out
136  ,EOutputLevel olevel
137  ,const mat_nonsing_fcty_ptr_t::element_type::obj_ptr_t &C
138  ,const mat_fcty_ptr_t::element_type::obj_ptr_t &D
139  ,MatrixOp *Y
140  ,MatrixOpNonsing *R
141  ,MatrixOp *Uy
142  ,EMatRelations mat_rel
143  ) const
144 {
145  namespace rcp = MemMngPack;
146  using Teuchos::dyn_cast;
147 
148  const size_type
149  n = this->n(),
150  r = this->r();
151  const Range1D
152  var_dep(1,r),
153  var_indep(r+1,n);
154 
155  //
156  // Get pointers to concreate matrices
157  //
158 
160  *Y_coor = Y ? &dyn_cast<MatrixIdentConcatStd>(*Y) : NULL;
161  MatrixOpSubView
162  *Uy_sv = Uy ? &dyn_cast<MatrixOpSubView>(*Uy) : NULL;
163 
164  //
165  // Initialize the matrices
166  //
167 
168  if( Y_coor && Y_coor->D_ptr().get() == NULL ) {
169  Y_coor->initialize(
170  space_x() // space_cols
171  ,space_x()->sub_space(var_dep)->clone() // space_rows
172  ,MatrixIdentConcatStd::BOTTOM // top_or_bottom
173  ,0.0 // alpha
174  ,Teuchos::rcp(
175  new MatrixZero(
176  space_x()->sub_space(var_indep)->clone()
177  ,space_x()->sub_space(var_dep)->clone()
178  ) ) // D_ptr
179  ,BLAS_Cpp::no_trans // D_trans
180  );
181  }
182  TEUCHOS_TEST_FOR_EXCEPT( !( Uy_sv == NULL ) ); // ToDo: Implement for undecomposed equalities
183 
184  // The R = C matrix object should already be updateded
185 
186 }
187 
189  std::ostream& out, const std::string& L ) const
190 {
191  out
192  << L << "*** Coordinate decompositon Y, R and Uy matrices (class DecompositionSystemCoordinate)\n"
193  << L << "Y = [ I; 0 ] (using class MatrixIdentConcatStd with MatrixZero)\n"
194  << L << "R = Gc(var_dep,equ_decomp)' = C\n"
195  << L << "Uy = Gc(var_dep,equ_undecomp)'\n"
196  ;
197 }
198 
199 } // end namespace ConstrainedOptPack
DecompositionSystemCoordinate(const VectorSpace::space_ptr_t &space_x=Teuchos::null, const VectorSpace::space_ptr_t &space_c=Teuchos::null, const basis_sys_ptr_t &basis_sys=Teuchos::null, const basis_sys_tester_ptr_t &basis_sys_tester=Teuchos::null, EExplicitImplicit D_imp=MAT_IMP_AUTO, EExplicitImplicit Uz_imp=MAT_IMP_AUTO)
EOutputLevel
Enumeration for the amount of output to create from update_decomp().
T_To & dyn_cast(T_From &from)
const basis_sys_ptr_t & basis_sys() const
T * get() const
void print_update_matrices(std::ostream &out, const std::string &leading_str) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Concrete implementation class for a matrix vertically concatonated with an identity matrix...
size_t size_type
void initialize_matrices(std::ostream *out, EOutputLevel olevel, const mat_nonsing_fcty_ptr_t::element_type::obj_ptr_t &C, const mat_fcty_ptr_t::element_type::obj_ptr_t &D, MatrixOp *Y, MatrixOpNonsing *R, MatrixOp *Uy, EMatRelations mat_rel) const
mat_nonsing_fcty_ptr_t::element_type::obj_ptr_t uninitialize_matrices(std::ostream *out, EOutputLevel olevel, MatrixOp *Y, MatrixOpNonsing *R, MatrixOp *Uy) const
virtual void initialize(const VectorSpace::space_ptr_t &space_cols, const VectorSpace::space_ptr_t &space_rows, ETopBottom top_or_bottom, value_type alpha, const D_ptr_t &D_ptr, BLAS_Cpp::Transp D_trans)
Setup with a matrix object.
size_type r() const
Returns this->basis_sys()->equ_decomp().size().
virtual const D_ptr_t & D_ptr() const
Return the smart reference counted point to the D matrix.
const VectorSpace::space_ptr_t & space_x() const
Specialization node implementation subclass of DecompositionSystem for variable reduction decompositi...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)