44 #ifndef ROL_USERINPUTGENERATOR_HPP
45 #define ROL_USERINPUTGENERATOR_HPP
48 #include "ROL_ParameterList.hpp"
56 template<
typename Real>
61 void sample(std::string file_pt, std::string file_wt,
66 std::fstream input_pt, input_wt;
67 input_pt.open(file_pt.c_str(),std::ios::in);
68 input_wt.open(file_wt.c_str(),std::ios::in);
69 if ( !input_pt.is_open() || !input_wt.is_open() ) {
70 if ( !input_pt.is_open() ) {
71 if ( bman->batchID() == 0 ) {
72 std::cout <<
"CANNOT OPEN " << file_pt.c_str() << std::endl;
75 if ( !input_wt.is_open() ) {
76 if ( bman->batchID() == 0 ) {
77 std::cout <<
"CANNOT OPEN " << file_wt.c_str() << std::endl;
82 std::vector<std::vector<Real>> pt(n);
83 std::vector<Real> wt(n,0.0);
84 std::vector<Real> point(dim,0.0);;
85 for (
int i = 0; i < n; i++) {
86 for (
int j = 0; j <
dim; j++) {
93 int rank = bman->batchID();
94 int nProc = bman->numBatches();
99 if ( rank < rem ) N++;
100 std::vector<std::vector<Real>> my_pt(N);
101 std::vector<Real> my_wt(N,0.0);
103 for (
int i = 0; i < N; i++) {
104 index = i*nProc + rank;
105 my_pt[i] = pt[index];
106 my_wt[i] = wt[index];
119 ROL::ParameterList &list
120 = parlist.sublist(
"SOL").sublist(
"Sample Generator").sublist(
"User Input");
121 if ( list.isParameter(
"Points File") &&
122 list.isParameter(
"Weights File") &&
123 list.isParameter(
"Number of Samples") &&
124 list.isParameter(
"Dimension") ) {
125 std::string file_pt = list.get(
"Points File Name",
"points.txt");
126 std::string file_wt = list.get(
"Weights File Name",
"weights.txt");
127 int n = list.get(
"Number of Samples",100);
128 int dim = list.get(
"Dimension",4);
129 sample(file_pt,file_wt,n,dim,bman);
132 ROL_TEST_FOR_EXCEPTION(
true,std::invalid_argument,
133 ">>> (ROL::UserInputGenerator): ParameterList does not contain sufficient information.");
143 sample(file_pt,file_wt,n,dim,bman);
void setPoints(std::vector< std::vector< Real > > &p)
void setWeights(std::vector< Real > &w)