18 #include "Teuchos_GlobalMPISession.hpp"
31 const PV eb =
dynamic_cast<const PV&
>(x);
32 size_type n = eb.numVectors();
34 for(size_type k=0; k<n; ++k) {
35 std::cout <<
"[subvector " << k <<
"]" << std::endl;
36 ROL::Ptr<const V> vec = eb.get(k);
37 ROL::Ptr<const std::vector<Real> > vp =
38 dynamic_cast<const SV&
>(*vec).getVector();
39 for(size_type i=0;i<vp->size();++i) {
40 std::cout << (*vp)[i] << std::endl;
46 int main(
int argc,
char *argv[]) {
48 using namespace Teuchos;
54 GlobalMPISession mpiSession(&argc, &argv);
56 int iprint = argc - 1;
58 ROL::Ptr<std::ostream> outStream;
62 outStream = ROL::makePtrFromRef(std::cout);
64 outStream = ROL::makePtrFromRef(bhs);
68 RealT errtol = ROL::ROL_THRESHOLD<RealT>();
81 RealT left = -1e0, right = 1e0;
83 std::vector<ROL::Ptr<V> > x_ptr;
84 std::vector<ROL::Ptr<V> > y_ptr;
85 std::vector<ROL::Ptr<V> > z_ptr;
88 ROL::Ptr<std::vector<RealT> > xk_ptr = ROL::makePtr<std::vector<RealT>>(dim[k]);
89 ROL::Ptr<std::vector<RealT> > yk_ptr = ROL::makePtr<std::vector<RealT>>(dim[k]);
90 ROL::Ptr<std::vector<RealT> > zk_ptr = ROL::makePtr<std::vector<RealT>>(dim[k]);
92 for(
int i=0; i<dim[k]; ++i ) {
93 (*xk_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
94 (*yk_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
95 (*zk_ptr)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
98 ROL::Ptr<V> xk = ROL::makePtr<SV>( xk_ptr );
99 ROL::Ptr<V> yk = ROL::makePtr<SV>( yk_ptr );
100 ROL::Ptr<V> zk = ROL::makePtr<SV>( zk_ptr );
110 ROL::Ptr<V> y = ROL::CreatePartitionedVector<RealT>(y_ptr[0],y_ptr[1],y_ptr[2]);
114 std::vector<RealT> consistency = x.checkVector(*y, z,
true, *outStream);
116 if (checkvec.
norm() > std::sqrt(errtol)) {
122 ROL::Ptr<ROL::Vector<RealT> > zp = x.clone();
124 RealT znorm = zp->norm();
125 *outStream <<
"Norm of ROL::Vector z (first basis vector): " << znorm <<
"\n";
126 if ( std::abs(znorm-1.0) > errtol ) {
127 *outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
131 zp = x.basis(total_dim/2);
133 *outStream <<
"\nNorm of ROL::Vector z ('middle' basis vector): " << znorm <<
"\n";
134 if ( std::abs(znorm-1.0) > errtol ) {
135 *outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
139 zp = x.basis(total_dim-1);
141 *outStream <<
"\nNorm of ROL::Vector z (last basis vector): " << znorm <<
"\n";
142 if ( std::abs(znorm-1.0) > errtol ) {
143 *outStream <<
"---> POSSIBLE ERROR ABOVE!\n";
149 consistency = x.checkVector(x, x,
true, *outStream);
150 if (checkvec.
norm() > 0.0) {
155 int m = atoi(argv[1]);
164 catch (std::logic_error& err) {
165 *outStream << err.what() <<
"\n";
170 std::cout <<
"End Result: TEST FAILED\n";
172 std::cout <<
"End Result: TEST PASSED\n";
PartitionedVector< Real > PV
typename PV< Real >::size_type size_type
Defines the linear algebra of vector space on a generic partitioned vector.
Contains definitions of custom data types in ROL.
Defines the linear algebra or vector space interface.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
void print_vector(const ROL::Vector< Real > &x)
Real norm() const
Returns where .
basic_nullstream< char, char_traits< char >> nullstream
int main(int argc, char *argv[])