Debian Codegraph @

packages/rol/adapters/tpetra/test/function/test_01.cpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 /*! \file test_01.cpp
11 \brief Test TpetraBoundConstraint class
12 \author Created by G. von Winckel
13 */
14
15 #include "ROL_StdBoundConstraint.hpp"
16 #include "ROL_TpetraBoundConstraint.hpp"
17
18 #include "ROL_Types.hpp"
19
20 #include "ROL_Stream.hpp"
21 #include "Teuchos_GlobalMPISession.hpp"
22
23 #include "Tpetra_Core.hpp"
24
25 using Teuchos::ArrayRCP;
26
27 typedef double RealT;
28
29 typedef Tpetra::Map<>::local_ordinal_type LO;
30 typedef Tpetra::Map<>::global_ordinal_type GO;
31 typedef Tpetra::Map<>::node_type Node;
32 typedef Tpetra::Map<LO, GO, Node> Map;
33 typedef Tpetra::MultiVector<RealT, LO, GO, Node> MV;
34
35 typedef std::vector<RealT> SV;
36 typedef ROL::Ptr<MV> MVP;
37 typedef ROL::Ptr<SV> SVP;
38
39
40 int test(ROL::Ptr<const Teuchos::Comm<int> > comm, int dim) {
41
42 // Get number of processes
43 const int numProc = comm->getSize();
44
45 // Total size over all processes
46 const int numGblIndices = numProc*dim;
47
48 ROL::Ptr<Map> map = ROL::makePtr<Map>(numGblIndices,0,comm);
49
50 int errorFlag = 0;
51
52 // Upper bound is +0.75
53 MVP u = ROL::makePtr<MV>(map,1,true);
54 u->putScalar(0.9);
55
56 // Lower bound is -0.75
57 MVP l = ROL::makePtr<MV>(map,1,true);
58 l->putScalar(-0.9);
59
60 // Optimization variable
61 MVP x = ROL::makePtr<MV>(map,1,true);
62 x->randomize();
63
64 ROL::TpetraBoundConstraint<RealT,LO,GO,Node> tcon(l,u);
65
66 ROL::TpetraMultiVector<RealT,LO,GO,Node> X(x);
67
68 // Prune the vector
69 tcon.project(X);
70
71 if(!tcon.isFeasible(X)) {
72 ++errorFlag;
73 }
74
75 return errorFlag;
76 }
77
78
79
80
81 int main(int argc, char *argv[]) {
82
83
84 int iprint = argc - 1;
85 ROL::Ptr<std::ostream> outStream;
86 ROL::nullstream bhs; // outputs nothing
87 Teuchos::GlobalMPISession mpiSession (&argc, &argv, &bhs);
88
89 if (iprint > 0)
90 ROL::makePtrFromRef(std::cout);
91 else
92 ROL::makePtrFromRef(bhs);
93
94 int errorFlag = 0;
95
96 try {
97
98 ROL::Ptr<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
99
100
101 // Maximum dimension of test for a given process
102 int maxdim = 100;
103
104 for(int i = 10;i<maxdim;++i) {
105 errorFlag += test(comm,10);
106 }
107
108 typedef std::vector<int> ivec;
109 ROL::Ptr<ivec> a_ptr = ROL::makePtr<ivec>(2,1);
110 ROL::Ptr<ivec> b_ptr = ROL::makePtr<ivec>(3,2);
111 Teuchos::ArrayRCP<ROL::Ptr<ivec>> v(2);
112 v[0] = a_ptr;
113 v[1] = b_ptr;
114 (*b_ptr)[2] = 3;
115
116 }
117
118 catch (std::logic_error& err) {
119 *outStream << err.what() << "\n";
120 errorFlag = -1000;
121 }; // end try
122
123 if (errorFlag != 0)
124 std::cout << "End Result: TEST FAILED\n";
125 else
126 std::cout << "End Result: TEST PASSED\n";
127
128 return 0;
129
130 }
131
132
133