NLPInterfacePack: C++ Interfaces and Implementation for Non-Linear Programs  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
NLPInterfacePack_test_basis_system.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 "NLPInterfacePack_test_basis_system.hpp"
43 #include "NLPInterfacePack_NLPFirstOrder.hpp"
44 #include "AbstractLinAlgPack_BasisSystem.hpp"
45 #include "AbstractLinAlgPack_BasisSystemTester.hpp"
46 #include "AbstractLinAlgPack_BasisSystemTesterSetOptions.hpp"
47 #include "AbstractLinAlgPack_MatrixOpNonsing.hpp"
48 
49 bool NLPInterfacePack::test_basis_system(
50  NLPFirstOrder *nlp
51  ,BasisSystem *basis_sys
53  ,std::ostream *out
54  )
55 {
56  namespace mmp = MemMngPack;
57 
58  const index_type
59  n = nlp->n(),
60  m = nlp->m();
61 
62  // Create the matrices Gc and Gh
63  NLPFirstOrder::mat_fcty_ptr_t::element_type::obj_ptr_t
64  Gc = ( m ? nlp->factory_Gc()->create() : Teuchos::null );
65 
66  // Compute the matrices at xinit
67  const Vector
68  &xo = nlp->xinit();
69  if(m)
70  nlp->set_Gc(Gc.get());
71  if(m)
72  nlp->calc_Gc(xo);
73 
74  // Create the matrices C and D
75  BasisSystem::mat_nonsing_fcty_ptr_t::element_type::obj_ptr_t
76  C = ( m ? basis_sys->factory_C()->create() : Teuchos::null);
77  BasisSystem::mat_fcty_ptr_t::element_type::obj_ptr_t
78  D = ( m && n > m && basis_sys->factory_C().get() ? basis_sys->factory_C()->create() : Teuchos::null);
79  BasisSystem::mat_fcty_ptr_t::element_type::obj_ptr_t
80  GcUP = ( m && n > m && basis_sys->factory_GcUP().get() ? basis_sys->factory_GcUP()->create() : Teuchos::null);
81 
82  // Initialize C and D with basis_sys
83  basis_sys->update_basis(
84  *Gc
85  ,C.get()
86  ,D.get()
87  ,GcUP.get()
88  );
89 
90  // Test the basis and basis system objects.
91  BasisSystemTester
92  basis_sys_tester;
93  if(options) {
94  BasisSystemTesterSetOptions
95  opt_setter(&basis_sys_tester);
96  opt_setter.set_options(*options);
97  }
98  const bool result = basis_sys_tester.test_basis_system(
99  *basis_sys
100  ,Gc.get()
101  ,C.get()
102  ,NULL // Create the N matrix internally
103  ,D.get()
104  ,GcUP.get()
105  ,out
106  );
107 
108  return result;
109 }