44 #include "NLPInterfacePack_test_nlp_direct.hpp"
45 #include "NLPInterfacePack_CalcFiniteDiffProd.hpp"
46 #include "NLPInterfacePack_CalcFiniteDiffProdSetOptions.hpp"
47 #include "NLPInterfacePack_NLPTester.hpp"
48 #include "NLPInterfacePack_NLPTesterSetOptions.hpp"
49 #include "NLPInterfacePack_NLPDirectTester.hpp"
50 #include "NLPInterfacePack_NLPDirectTesterSetOptions.hpp"
51 #include "NLPInterfacePack_NLPDirect.hpp"
52 #include "AbstractLinAlgPack_VectorSpace.hpp"
53 #include "AbstractLinAlgPack_VectorSpaceTester.hpp"
54 #include "AbstractLinAlgPack_VectorSpaceTesterSetOptions.hpp"
55 #include "AbstractLinAlgPack_VectorMutable.hpp"
56 #include "AbstractLinAlgPack_VectorOut.hpp"
57 #include "AbstractLinAlgPack_MatrixOp.hpp"
58 #include "AbstractLinAlgPack_MatrixOpOut.hpp"
59 #include "TestingHelperPack_update_success.hpp"
61 bool NLPInterfacePack::test_nlp_direct(
67 using TestingHelperPack::update_success;
77 <<
"\n****************************"
78 <<
"\n*** test_nlp_direct(...) ***"
79 <<
"\n*****************************\n";
81 nlp->initialize(
true);
85 *out <<
"\nTesting the vector spaces ...\n";
87 VectorSpaceTester vec_space_tester;
89 VectorSpaceTesterSetOptions
90 opt_setter(&vec_space_tester);
91 opt_setter.set_options(*options);
95 *out <<
"\nTesting nlp->space_x() ...\n";
96 result = vec_space_tester.check_vector_space(*nlp->space_x(),out);
99 *out <<
"nlp->space_x() checks out!\n";
101 *out <<
"nlp->space_x() check failed!\n";
103 update_success( result, &success );
105 *out <<
"\nTesting nlp->space_x()->sub_space(nlp->var_dep()) ...\n";
106 result = vec_space_tester.check_vector_space(
107 *nlp->space_x()->sub_space(nlp->var_dep()),out);
110 *out <<
"nlp->space_x()->sub_space(nlp->var_dep()) checks out!\n";
112 *out <<
"nlp->space_x()->sub_space(nlp->var_dep()) check failed!\n";
114 update_success( result, &success );
116 *out <<
"\nTesting nlp->space_x()->sub_space(nlp->var_indep()) ...\n";
117 result = vec_space_tester.check_vector_space(
118 *nlp->space_x()->sub_space(nlp->var_indep()),out);
121 *out <<
"nlp->space_x()->sub_space(nlp->var_indep()) checks out!\n";
123 *out <<
"nlp->space_x()->sub_space(nlp->var_indep()) check failed!\n";
125 update_success( result, &success );
127 *out <<
"\nTesting nlp->space_c() ...\n";
128 result = vec_space_tester.check_vector_space(*nlp->space_c(),out);
131 *out <<
"nlp->space_c() checks out!\n";
133 *out <<
"nlp->space_c() check failed!\n";
135 update_success( result, &success );
137 *out <<
"\nTesting nlp->space_c()->sub_space(nlp->con_decomp()) ...\n";
138 result = vec_space_tester.check_vector_space(
139 *nlp->space_c()->sub_space(nlp->con_decomp()),out);
142 *out <<
"nlp->space_c()->sub_space(nlp->con_decomp()) checks out!\n";
144 *out <<
"nlp->space_c()->sub_space(nlp->con_decomp()) check failed!\n";
146 update_success( result, &success );
147 if( nlp->con_decomp().size() < nlp->m() ) {
149 *out <<
"\nTesting nlp->space_c()->sub_space(nlp->con_undecomp()) ...\n";
150 result = vec_space_tester.check_vector_space(
151 *nlp->space_c()->sub_space(nlp->con_undecomp()),out);
154 *out <<
"nlp->space_c()->sub_space(nlp->con_undecomp()) checks out!\n";
156 *out <<
"nlp->space_c()->sub_space(nlp->con_undecomp()) check failed!\n";
158 update_success( result, &success );
163 NLPTester nlp_tester;
166 nlp_tester_opt_setter(&nlp_tester);
167 nlp_tester_opt_setter.set_options(*options);
169 const bool print_all_warnings = nlp_tester.print_all();
171 result = nlp_tester.test_interface(
172 nlp, nlp->xinit(), print_all_warnings, out );
173 update_success( result, &success );
177 const bool supports_Gf = nlp->supports_Gf();
180 *out <<
"\nCalling nlp->calc_point(...) at nlp->xinit() ...\n";
185 var_dep = nlp->var_dep(),
186 var_indep = nlp->var_indep(),
187 con_decomp = nlp->con_decomp(),
188 con_undecomp = nlp->con_undecomp();
189 VectorSpace::vec_mut_ptr_t
190 c = nlp->space_c()->create_member(),
191 Gf = nlp->space_x()->create_member(),
192 py = nlp->space_x()->sub_space(var_dep)->create_member(),
193 rGf = nlp->space_x()->sub_space(var_indep)->create_member();
194 NLPDirect::mat_fcty_ptr_t::element_type::obj_ptr_t
195 GcU = con_decomp.size() < m ? nlp->factory_GcU()->create() : Teuchos::null,
196 D = nlp->factory_D()->create(),
197 Uz = con_decomp.size() < m ? nlp->factory_Uz()->create() : Teuchos::null;
199 nlp->xinit(), NULL, c.get(),
true, supports_Gf?Gf.get():NULL, py.get(), rGf.get()
200 ,GcU.get(), D.get(), Uz.get() );
203 *out <<
"\n||Gf||inf = " << Gf->norm_inf();
204 if(nlp_tester.print_all())
205 *out <<
"\nGf =\n" << *Gf;
207 *out <<
"\n||py||inf = " << py->norm_inf();
208 if(nlp_tester.print_all())
209 *out <<
"\npy =\n" << *py;
210 *out <<
"\n||rGf||inf = " << rGf->norm_inf();
211 if(nlp_tester.print_all())
212 *out <<
"\nrGf =\n" << *rGf;
213 if(nlp_tester.print_all())
214 *out <<
"\nD =\n" << *D;
215 if( con_decomp.size() < m ) {
224 CalcFiniteDiffProdSetOptions
225 options_setter( &calc_fd_prod );
226 options_setter.set_options(*options);
229 nlp_first_order_direct_tester(
Teuchos::rcp(&calc_fd_prod,
false));
231 NLPDirectTesterSetOptions
232 nlp_tester_opt_setter(&nlp_first_order_direct_tester);
233 nlp_tester_opt_setter.set_options(*options);
235 result = nlp_first_order_direct_tester.finite_diff_check(
237 ,nlp->num_bounded_x() ? &nlp->xl() : NULL
238 ,nlp->num_bounded_x() ? &nlp->xu() : NULL
240 ,supports_Gf?Gf.get():NULL,py.get(),rGf.get(),GcU.get(),D.get(),Uz.get()
241 ,print_all_warnings, out
243 update_success( result, &success );
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)