Intrepid
Intrepid_AdaptiveSparseGridInterfaceDef.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Pavel Bochev (pbboche@sandia.gov)
38 // Denis Ridzal (dridzal@sandia.gov), or
39 // Kara Peterson (kjpeter@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
49 namespace Intrepid {
50 
51 template<class Scalar, class UserVector>
53  int dimension,
54  std::vector<EIntrepidBurkardt> rule1D,
55  std::vector<EIntrepidGrowth> growth1D,
56  int maxLevel,
57  bool isNormalized) {
58 
59  TEUCHOS_TEST_FOR_EXCEPTION((dimension!=(int)rule1D.size()||
60  dimension!=(int)growth1D.size()),std::out_of_range,
61  ">>> ERROR (AdaptiveSparseGridInterface): Dimension mismatch for inputs.");
62 
63  dimension_ = dimension;
64  rule1D_ = rule1D;
65  growth1D_ = growth1D;
66  maxLevel_ = maxLevel;
67  isNormalized_ = isNormalized;
68 }
69 
70 template<class Scalar, class UserVector>
72  std::vector<int> index(dimension_,1);
74  dimension_,index,rule1D_,growth1D_,isNormalized_);
75 
76  // Evaluate the initial contribution to the integral
77  initialDiff_ = 1.0;
78  output.Update(-1.0,output);
79  eval_cubature(output,cubRule);
80 
81  // Compute the initial error indicator
82  initialDiff_ = error_indicator(output);
83  if (std::abs(initialDiff_)<INTREPID_TOL)
84  initialDiff_ = 1.0;
85 }
86 
87 template<class Scalar, class UserVector>
89  std::vector<int> index) {
90  int dimension = (int)index.size();
91  int sum = 0;
92  for (int i=0; i<dimension; i++) {
93  sum += index[i];
94  }
95  if (sum <= maxLevel_ + dimension - 1)
96  return true;
97  return false;
98 }
99 
100 template<class Scalar, class UserVector>
102  UserVector & output,
103  CubatureTensorSorted<Scalar> & cubRule) {
104 
105  //int dimf = 0; // Dimension of the integrand
106  Scalar weight = 0.0;
107  std::vector<Scalar> point(dimension_,(Scalar)0.0);
108  //std::vector<Scalar> f(1,0.0);
109  Teuchos::RCP<UserVector> f = output.Create(); output.Update(-1.0,output);
110 
111  typename std::map<std::vector<Scalar>,int>::iterator it;
112  for (it=cubRule.begin(); it!=cubRule.end(); it++) {
113  // Evaluate Function
114  point.assign((it->first).begin(),(it->first).end()); // Extract point
115  f->Update(-1.0,*f);
116  eval_integrand(*f,point); // Evaluate Integrand at point
117 
118  // Update integral
119  weight = cubRule.getWeight(it->second);
120  output.Update(weight,*f);
121  }
122 }
123 
124 template<class Scalar, class UserVector>
126  std::vector<EIntrepidBurkardt> & rule1D) {
127  rule1D.clear();
128  rule1D.resize(rule1D_.size());
129  rule1D = rule1D_;
130 }
131 
132 template<class Scalar, class UserVector>
134  std::vector<EIntrepidGrowth> & growth1D) {
135  growth1D.clear();
136  growth1D.resize(growth1D_.size());
137  growth1D = growth1D_;
138 }
139 
140 template<class Scalar, class UserVector>
142  return dimension_;
143 }
144 
145 template<class Scalar, class UserVector>
147  return isNormalized_;
148 }
149 
150 template<class Scalar, class UserVector>
152  return initialDiff_;
153 }
154 
155 } // end Intrepid namespace
156 
157 
158 
159 
160 #if defined(Intrepid_SHOW_DEPRECATED_WARNINGS)
161 #ifdef __GNUC__
162 #warning "The Intrepid package is deprecated"
163 #endif
164 #endif
165 
std::map< std::vector< Scalar >, int >::iterator begin()
Initiate iterator at the beginning of data.
void getRule(std::vector< EIntrepidBurkardt > &rule1D)
Return user defined 1D quadrature rules.
Scalar getInitialDiff()
Return initial error indicator.
int getDimension()
Return dimension of integration domain.
void init(UserVector &output)
Compute initial quantities for sparse grid adaptation.
Scalar getWeight(int node)
Get a specific weight described by the integer location.
AdaptiveSparseGridInterface(int dimension, std::vector< EIntrepidBurkardt > rule1D, std::vector< EIntrepidGrowth > growth1D, int maxLevel, bool isNormalized)
Constructor starts with index [1,...,1].
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...
std::map< std::vector< Scalar >, int >::iterator end()
Initiate iterator at the end of data.