44 #ifndef ROL_SPARSEGRIDGENERATOR_DEF_HPP
45 #define ROL_SPARSEGRIDGENERATOR_DEF_HPP
63 int dim_num = info.
dim;
65 std::vector<EROLBurkardt> rule1D = info.
rule1D;
66 std::vector<EROLGrowth> growth1D = info.
growth1D;
77 const char* SGinfo,
const char* SGdata,
89 for (
unsigned l = 0; l < index.size(); l++ ) {
91 level = std::max(level,index[l]);
97 if ( level >= (this->info_).maxLevel ) {
105 for (
int i = 0; i < (this->info_).dim; i++ ) {
106 if ( index[i] > 1 && i != direction ) {
108 if ( !((this->oldIndex_).count(index)) ) {
120 for (
int i = 0; i < (this->info_).dim; i++ ) {
121 numPoints =
growthRule1D(index[i],((this->info_).growth1D)[i],((this->info_).rule1D)[i]);
122 Quadrature<Real> diffRule(((this->info_).rule1D)[i],numPoints,((this->info_).normalize));
123 if ( numPoints != 1 ) {
124 numPoints =
growthRule1D(index[i]-1,((this->info_).growth1D)[i],((this->info_).rule1D)[i]);
125 Quadrature<Real> rule(((this->info_).rule1D)[i],numPoints,((this->info_).normalize));
126 diffRule.
update(-1.0,rule);
128 outRule = kron_prod<Real>(outRule,diffRule);
135 if ( this->adaptive_ ) {
137 (this->index_).clear();
138 this->direction_ = 0;
140 (this->activeIndex_).clear();
141 (this->oldIndex_).clear();
148 if ( this->adaptive_ ) {
150 for (
int i = 0; i < SampleGenerator<Real>::numMySamples(); i++ ) {
155 error = std::abs(error);
157 this->error_ += error;
158 if ( (this->activeIndex_).end() != (this->activeIndex_).begin() ) {
159 (this->activeIndex_).insert((this->activeIndex_).end()--,
160 std::pair<Real,std::vector<int> >(error,this->search_index_));
163 (this->activeIndex_).insert(std::pair<Real,std::vector<int> >(error,this->search_index_));
175 if ( this->adaptive_ ) {
176 Teuchos::RCP<Vector<Real> > mydiff = x.
clone();
178 for (
int i = 0; i < SampleGenerator<Real>::numMySamples(); i++ ) {
181 Teuchos::RCP<Vector<Real> > diff = mydiff->clone();
183 Real error = diff->norm();
185 this->error_ += error;
186 if ( (this->activeIndex_).end() != (this->activeIndex_).begin() ) {
187 (this->activeIndex_).insert((this->activeIndex_).end()--,
188 std::pair<Real,std::vector<int> >(error,this->search_index_));
191 (this->activeIndex_).insert(std::pair<Real,std::vector<int> >(error,this->search_index_));
203 if ( this->adaptive_ ) {
205 if ( !((this->index_).empty()) && ((this->direction_) < ((this->info_).dim-1)) ) {
207 this->search_index_ = (this->index_);
209 (this->search_index_)[this->direction_]++;
213 if ( (this->index_).empty() ) {
214 (this->index_).resize((this->info_).dim,1);
215 this->search_index_ = this->index_;
216 this->direction_ = (this->info_).dim;
219 typename std::multimap<Real,std::vector<int> >::iterator it = (this->activeIndex_).end();
221 this->error_ -= it->first;
222 this->index_ = it->second;
223 (this->activeIndex_).erase(it);
224 (this->oldIndex_).insert((this->oldIndex_).end(),(this->index_));
225 this->search_index_ = (this->index_);
226 this->direction_ = 0;
227 (this->search_index_)[this->direction_]++;
232 if ( !(this->checkMaxLevel(this->search_index_)) ) {
234 if ( this->isAdmissible((this->search_index_),this->direction_) ) {
236 this->buildDiffRule(rule,this->search_index_);
240 this->updateSamples(rule);
247 std::vector<std::vector<Real> > pts;
248 std::vector<Real> wts;
249 this->grid_->getCubature(pts,wts);
260 for (
int i = 0; i < npts; i++ ) {
262 mywts[i] = wts[index];
263 mypts[i] = pts[index];
270 std::cout <<
"Number of Global Points: " << (this->grid_)->getNumPoints() <<
"\n";
272 if ( this->adaptive_ || inConstructor ) {
274 std::vector<std::vector<Real> > mypts;
275 std::vector<Real> mywts;
276 this->splitSamples(mypts,mywts);
286 this->grid_->update(1.0,grid);
288 std::vector<std::vector<Real> > mypts;
289 std::vector<Real> mywts;
290 this->splitSamples(mypts,mywts);
292 std::vector<std::vector<Real> > pts_inc;
293 std::vector<Real> wts_inc;
296 std::vector<std::vector<Real> > pts_inter;
297 typename std::vector<std::vector<Real> >::iterator mypts_it;
298 typename std::vector<std::vector<Real> >::iterator pts_inc_it;
299 for ( pts_inc_it=pts_inc.begin(); pts_inc_it!=pts_inc.end(); pts_inc_it++ ) {
300 for ( mypts_it=mypts.begin(); mypts_it!=mypts.end(); mypts_it++ ) {
301 if ( *mypts_it == *pts_inc_it ) {
302 pts_inter.push_back(*mypts_it);
308 std::vector<Real> wts_inter;
309 for (
unsigned i = 0; i < pts_inter.size(); i++ ) {
310 wts_inter.push_back(grid.
getWeight(pts_inter[i]));
virtual void update(const Vector< Real > &x)
void splitSamples(std::vector< std::vector< Real > > &mypts, std::vector< Real > &mywts)
virtual void getCubature(std::vector< std::vector< Real > > &cubPoints, std::vector< Real > &cubWeights) const
std::vector< int > index_
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual Real getMyWeight(const int i) const
bool checkMaxLevel(std::vector< int > &index)
Defines the linear algebra or vector space interface.
void buildDiffRule(Quadrature< Real > &outRule, std::vector< int > &index)
void sumAll(Real *input, Real *output, int dim) const
virtual void update(Real alpha, Quadrature< Real > &rule)
bool isAdmissible(std::vector< int > &index, int direction)
std::multimap< Real, std::vector< int > > activeIndex_
std::vector< EROLBurkardt > rule1D
Real computeError(std::vector< Real > &vals)
std::set< std::vector< int > > oldIndex_
SparseGridGenerator(Teuchos::RCP< BatchManager< Real > > &bman, SparseGridInfo &info, bool adaptive=false)
void updateSamples(Quadrature< Real > &grid)
virtual Real getWeight(int node)
Teuchos::RCP< Quadrature< Real > > grid_
void update(const Vector< Real > &x)
int numBatches(void) const
int growthRule1D(int index, EROLGrowth growth, EROLBurkardt rule)
void setPoints(std::vector< std::vector< Real > > &p)
void setSamples(bool inConstructor=false)
void setWeights(std::vector< Real > &w)
std::vector< EROLGrowth > growth1D