51 template<
class Scalar,
class UserVector>
53 std::vector<int> index,
55 std::set<std::vector<int> > inOldIndex,
62 for (
int i=0; i<dimension; i++) {
63 if (index[i]>1 && i!=direction) {
65 if (!inOldIndex.count(index)) {
74 template<
class Scalar,
class UserVector>
77 std::vector<int> index,
83 std::vector<EIntrepidBurkardt> rule1D; problem_data.
getRule(rule1D);
84 std::vector<EIntrepidGrowth> growth1D; problem_data.
getGrowth(growth1D);
86 for (
int i=0; i<dimension; i++) {
88 numPoints = growthRule1D(index[i],growth1D[i],rule1D[i]);
92 numPoints = growthRule1D(index[i]-1,growth1D[i],rule1D[i]);
94 diffRule1.
update(-1.0,rule1,1.0);
97 outRule = kron_prod<Scalar>(outRule,diffRule1);
101 template<
class Scalar,
class UserVector>
104 std::vector<int> index,
int dimension,
105 std::vector<EIntrepidBurkardt> rule1D,
106 std::vector<EIntrepidGrowth> growth1D,
110 for (
int i=0; i<dimension; i++) {
112 numPoints = growthRule1D(index[i],growth1D[i],rule1D[i]);
116 numPoints = growthRule1D(index[i]-1,growth1D[i],rule1D[i]);
118 diffRule1.
update(-1.0,rule1,1.0);
121 outRule = kron_prod<Scalar>(outRule,diffRule1);
126 template<
class Scalar,
class UserVector>
128 typename std::multimap<Scalar,std::vector<int> > & indexSet,
129 UserVector & integralValue,
133 std::vector<EIntrepidBurkardt> rule1D; problem_data.
getRule(rule1D);
134 std::vector<EIntrepidGrowth> growth1D; problem_data.
getGrowth(growth1D);
137 typename std::multimap<Scalar,std::vector<int> >::iterator it;
138 std::set<std::vector<int> > oldSet;
139 std::set<std::vector<int> >::iterator it1(oldSet.begin());
140 for (it=indexSet.begin(); it!=indexSet.end(); it++) {
141 oldSet.insert(it1,it->second);
148 std::vector<int> index(dimension,0);
149 typename std::multimap<Scalar,std::vector<int> > activeSet;
150 for (it1=oldSet.begin(); it1!=oldSet.end(); it1++) {
152 for (
int i=0; i<dimension; i++) {
154 flag = (int)(!oldSet.count(index));
157 activeSet.insert(std::pair<Scalar,std::vector<int> >(1.0,index));
165 typename std::multimap<Scalar,std::vector<int> >::iterator it2;
168 Teuchos::RCP<UserVector> s = integralValue.Create();
169 for (it2=activeSet.begin(); it2!=activeSet.end(); it2++) {
173 build_diffRule(diffRule,index,problem_data);
180 activeSet.erase(it2);
181 activeSet.insert(it2,std::pair<Scalar,std::vector<int> >(G,index));
186 eta = refine_grid(activeSet,oldSet,integralValue,eta,
187 dimension,rule1D,growth1D);
190 indexSet.insert(activeSet.begin(),activeSet.end());
191 for (it1=oldSet.begin(); it1!=oldSet.end(); it1++) {
193 indexSet.insert(std::pair<Scalar,std::vector<int> >(-1.0,index));
200 template<
class Scalar,
class UserVector>
202 typename std::multimap<Scalar,std::vector<int> > & activeIndex,
203 std::set<std::vector<int> > & oldIndex,
204 UserVector & integralValue,
205 Scalar globalErrorIndicator,
208 TEUCHOS_TEST_FOR_EXCEPTION((activeIndex.empty()),std::out_of_range,
209 ">>> ERROR (AdaptiveSparseGrid): Active Index set is empty.");
212 std::vector<EIntrepidBurkardt> rule1D; problem_data.
getRule(rule1D);
213 std::vector<EIntrepidGrowth> growth1D; problem_data.
getGrowth(growth1D);
216 bool maxLevelFlag =
true;
217 bool isAdmissibleFlag =
true;
220 Teuchos::RCP<UserVector> s = integralValue.Create();
222 std::set<std::vector<int> >::iterator it1(oldIndex.end());
225 typename std::multimap<Scalar,std::vector<int> >::iterator it;
228 Scalar eta = globalErrorIndicator;
231 it = activeIndex.end(); it--;
232 Scalar G = it->first;
234 std::vector<int> index = it->second;
235 activeIndex.erase(it);
237 oldIndex.insert(it1,index); it1 = oldIndex.end();
240 for (
int k=0; k<dimension; k++) {
243 maxLevelFlag = problem_data.
max_level(index);
246 isAdmissibleFlag = isAdmissible(index,k,oldIndex,problem_data);
247 if (isAdmissibleFlag) {
250 build_diffRule(diffRule,index,problem_data);
256 integralValue.Update(*s);
260 if (activeIndex.end()!=activeIndex.begin())
261 activeIndex.insert(activeIndex.end()--,
262 std::pair<Scalar,std::vector<int> >(G,index));
264 activeIndex.insert(std::pair<Scalar,std::vector<int> >(G,index));
279 template<
class Scalar,
class UserVector>
281 typename std::multimap<Scalar,std::vector<int> > & activeIndex,
282 std::set<std::vector<int> > & oldIndex,
283 UserVector & integralValue,
285 Scalar globalErrorIndicator,
288 TEUCHOS_TEST_FOR_EXCEPTION((activeIndex.empty()),std::out_of_range,
289 ">>> ERROR (AdaptiveSparseGrid): Active Index set is empty.");
292 std::vector<EIntrepidBurkardt> rule1D; problem_data.
getRule(rule1D);
293 std::vector<EIntrepidGrowth> growth1D; problem_data.
getGrowth(growth1D);
296 bool maxLevelFlag =
true;
297 bool isAdmissibleFlag =
true;
300 Teuchos::RCP<UserVector> s = integralValue.Create();
303 std::set<std::vector<int> >::iterator it1(oldIndex.end());
306 typename std::multimap<Scalar,std::vector<int> >::iterator it;
309 Scalar eta = globalErrorIndicator;
312 it = activeIndex.end(); it--;
313 Scalar G = it->first;
315 std::vector<int> index = it->second;
316 activeIndex.erase(it);
318 oldIndex.insert(it1,index); it1 = oldIndex.end();
321 for (
int k=0; k<dimension; k++) {
324 maxLevelFlag = problem_data.
max_level(index);
327 isAdmissibleFlag = isAdmissible(index,k,oldIndex,problem_data);
328 if (isAdmissibleFlag) {
331 build_diffRule(diffRule,index,problem_data);
337 integralValue.Update(*s);
341 if (activeIndex.end()!=activeIndex.begin())
342 activeIndex.insert(activeIndex.end()--,
343 std::pair<Scalar,std::vector<int> >(G,index));
345 activeIndex.insert(std::pair<Scalar,std::vector<int> >(G,index));
351 cubRule.
update(1.0,diffRule,1.0);
362 template<
class Scalar,
class UserVector>
365 int dimension,
int maxlevel,
366 std::vector<EIntrepidBurkardt> rule1D,
367 std::vector<EIntrepidGrowth> growth1D,
370 if (dimension == 2) {
371 std::vector<int> index(dimension,0);
372 for (
int i=0; i<maxlevel; i++) {
373 for (
int j=0; j<maxlevel; j++) {
374 if(i+j+dimension <= maxlevel+dimension-1) {
375 index[0] = i+1; index[1] = j+1;
377 build_diffRule(diffRule,index,dimension,rule1D,growth1D,isNormalized);
378 output.
update(1.0,diffRule,1.0);
383 else if (dimension == 3) {
384 std::vector<int> index(dimension,0);
385 for (
int i=0; i<maxlevel; i++) {
386 for (
int j=0; j<maxlevel; j++) {
387 for (
int k=0; k<maxlevel; k++) {
388 if(i+j+k+dimension <= maxlevel+dimension-1) {
389 index[0] = i+1; index[1] = j+1; index[2] = k+1;
391 build_diffRule(diffRule,index,dimension,rule1D,
392 growth1D,isNormalized);
393 output.
update(1.0,diffRule,1.0);
399 else if (dimension == 4) {
400 std::vector<int> index(dimension,0);
401 for (
int i=0; i<maxlevel; i++) {
402 for (
int j=0; j<maxlevel; j++) {
403 for (
int k=0; k<maxlevel; k++) {
404 for (
int l=0; l<maxlevel; l++) {
405 if(i+j+k+l+dimension <= maxlevel+dimension-1) {
406 index[0] = i+1; index[1] = j+1; index[2] = k+1; index[3] = l+1;
408 build_diffRule(diffRule,index,dimension,rule1D,
409 growth1D,isNormalized);
410 output.
update(1.0,diffRule,1.0);
417 else if (dimension == 5) {
418 std::vector<int> index(dimension,0);
419 for (
int i=0; i<maxlevel; i++) {
420 for (
int j=0; j<maxlevel; j++) {
421 for (
int k=0; k<maxlevel; k++) {
422 for (
int l=0; l<maxlevel; l++) {
423 for (
int m=0; m<maxlevel; m++) {
424 if(i+j+k+l+m+dimension <= maxlevel+dimension-1) {
425 index[0] = i+1; index[1] = j+1; index[2] = k+1;
426 index[3] = l+1; index[4] = m+1;
428 build_diffRule(diffRule,index,dimension,rule1D,
429 growth1D,isNormalized);
430 output.
update(1.0,diffRule,1.0);
439 std::cout <<
"Dimension Must Be Less Than 5\n";
444 #if defined(Intrepid_SHOW_DEPRECATED_WARNINGS)
446 #warning "The Intrepid package is deprecated"
static void buildSparseGrid(CubatureTensorSorted< Scalar > &output, int dimension, int maxlevel, std::vector< EIntrepidBurkardt > rule1D, std::vector< EIntrepidGrowth > growth1D, bool isNormalized)
Build a classic isotropic sparse grid.
void getRule(std::vector< EIntrepidBurkardt > &rule1D)
Return user defined 1D quadrature rules.
static Scalar refine_grid(typename std::multimap< Scalar, std::vector< int > > &indexSet, UserVector &integralValue, AdaptiveSparseGridInterface< Scalar, UserVector > &problem_data)
Update adaptive sparse grid.
Utilizes cubature (integration) rules contained in the library sandia_rules (John Burkardt...
static void build_diffRule(CubatureTensorSorted< Scalar > &outRule, std::vector< int > index, AdaptiveSparseGridInterface< Scalar, UserVector > &problem_data)
Given an index, build the corresponding differential cubature rule.
void update(Scalar alpha2, CubatureLineSorted< Scalar > &cubRule2, Scalar alpha1)
Replace CubatureLineSorted values with "this = alpha1*this+alpha2*cubRule2".
virtual Scalar error_indicator(UserVector &input)=0
User defined error indicator function.
int getDimension()
Return dimension of integration domain.
static bool isAdmissible(std::vector< int > index, int direction, std::set< std::vector< int > > inOldIndex, AdaptiveSparseGridInterface< Scalar, UserVector > &problem_data)
Check admissibility of an index set, outputs true if admissible.
void update(Scalar alpha2, CubatureTensorSorted< Scalar > &cubRule2, Scalar alpha1)
Replace CubatureLineSorted values with "this = alpha1*this+alpha2*cubRule2".
bool isNormalized()
Return whether or not cubature weights are normalized.
virtual bool max_level(std::vector< int > index)
User defined test for maximum level of cubature.
virtual void eval_cubature(UserVector &output, CubatureTensorSorted< Scalar > &cubRule)
Evaluate the cubature rule.
void getGrowth(std::vector< EIntrepidGrowth > &growth1D)
Return user defined 1D growth rules.
Utilizes 1D cubature (integration) rules contained in the library sandia_rules (John Burkardt...