|
Intrepid
|
00001 // @HEADER 00002 // ************************************************************************ 00003 // 00004 // Intrepid Package 00005 // Copyright (2007) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Pavel Bochev (pbboche@sandia.gov) or 00025 // Denis Ridzal (dridzal@sandia.gov). 00026 // 00027 // ************************************************************************ 00028 // @HEADER 00029 00036 namespace Intrepid { 00037 00038 /************************************************************************** 00039 ** Function Definitions for Class CubatureSparse 00040 ***************************************************************************/ 00041 00042 template <class Scalar, int dimension_, class ArrayPoint, class ArrayWeight> 00043 CubatureSparse<Scalar,dimension_,ArrayPoint,ArrayWeight>::CubatureSparse(const int degree) : 00044 degree_(degree) { 00045 00046 if(dimension_ == 2) 00047 { 00048 if(degree == 1) 00049 level_ = 1; 00050 else if(degree <= 3) 00051 level_ = 2; 00052 else if(degree <= 7) 00053 level_ = 3; 00054 else if(degree <= 11) 00055 level_ = 4; 00056 else if(degree <= 15) 00057 level_ = 5; 00058 else if(degree <= 19) 00059 level_ = 6; 00060 else if(degree <= 23) 00061 level_ = 7; 00062 else if(degree <= 27) 00063 level_ = 8; 00064 else if(degree <= 31) 00065 level_ = 9; 00066 else if(degree <= 35) 00067 level_ = 10; 00068 else if(degree <= 39) 00069 level_ = 11; 00070 else if(degree <= 43) 00071 level_ = 12; 00072 else if(degree <= 47) 00073 level_ = 13; 00074 else if(degree <= 51) 00075 level_ = 14; 00076 else if(degree <= 55) 00077 level_ = 15; 00078 else if(degree <= 59) 00079 level_ = 16; 00080 } 00081 else if(dimension_ == 3) 00082 { 00083 if(degree == 1) 00084 level_ = 1; 00085 else if(degree <= 3) 00086 level_ = 2; 00087 else if(degree <= 5) 00088 level_ = 3; 00089 else if(degree <= 9) 00090 level_ = 4; 00091 else if(degree <= 13) 00092 level_ = 5; 00093 else if(degree <= 17) 00094 level_ = 6; 00095 else if(degree <= 21) 00096 level_ = 7; 00097 else if(degree <= 25) 00098 level_ = 8; 00099 else if(degree <= 29) 00100 level_ = 9; 00101 else if(degree <= 33) 00102 level_ = 10; 00103 else if(degree <= 37) 00104 level_ = 11; 00105 else if(degree <= 41) 00106 level_ = 12; 00107 else if(degree <= 45) 00108 level_ = 13; 00109 else if(degree <= 49) 00110 level_ = 14; 00111 else if(degree <= 53) 00112 level_ = 15; 00113 else if(degree <= 57) 00114 level_ = 16; 00115 } 00116 00117 numPoints_ = calculateNumPoints(dimension_,level_); 00118 } 00119 00120 00121 00122 template <class Scalar, int dimension_, class ArrayPoint, class ArrayWeight> 00123 void CubatureSparse<Scalar,dimension_,ArrayPoint,ArrayWeight>::getCubature(ArrayPoint & cubPoints, 00124 ArrayWeight & cubWeights) const{ 00125 Teuchos::Array<Scalar> dummy_point(1); 00126 dummy_point[0] = 0.0; 00127 Scalar dummy_weight = 1.0; 00128 SGNodes<Scalar, dimension_> grid; 00129 00130 iterateThroughDimensions(level_, dimension_, grid, dummy_point, dummy_weight); 00131 00132 grid.copyToArrays(cubPoints, cubWeights); 00133 } // end getCubature 00134 00135 00136 00137 template <class Scalar, int dimension_, class ArrayPoint, class ArrayWeight> 00138 int CubatureSparse<Scalar,dimension_,ArrayPoint,ArrayWeight>::getNumPoints() const { 00139 return numPoints_; 00140 } // end getNumPoints 00141 00142 00143 00144 template <class Scalar, int dimension_, class ArrayPoint, class ArrayWeight> 00145 int CubatureSparse<Scalar,dimension_,ArrayPoint,ArrayWeight>::getDimension() const { 00146 return dimension_; 00147 } // end dimension 00148 00149 00150 00151 template <class Scalar, int dimension_, class ArrayPoint, class ArrayWeight> 00152 void CubatureSparse<Scalar,dimension_,ArrayPoint,ArrayWeight>::getAccuracy(std::vector<int> & accuracy) const { 00153 accuracy.assign(1, degree_); 00154 } //end getAccuracy 00155 00156 00157 00158 /************************************************************************ 00159 ** Function Definition for iterateThroughDimensions() 00160 ** and its helper functions 00161 *************************************************************************/ 00162 00163 template< class Scalar, int DIM> 00164 void iterateThroughDimensions(int level, 00165 int dims_left, 00166 SGNodes<Scalar,DIM> & cubPointsND, 00167 Teuchos::Array<Scalar> & partial_node, 00168 Scalar partial_weight) 00169 { 00170 int l = level; 00171 int d = DIM; 00172 int add_on = d - dims_left; 00173 int start = dims_left > 1 ? 1 : (int)std::max(1, l); 00174 int end = l + add_on; 00175 00176 for(int k_i = start; k_i <= end; k_i++) 00177 { 00178 /******************* 00179 ** Slow-Gauss 00180 ********************/ 00181 int order1D = 2*k_i-1; 00182 00183 /******************* 00184 ** Fast-Gauss 00185 ********************/ 00186 //int order1D = (int)pow(2,k_i) - 1; 00187 00188 int cubDegree1D = 2*order1D - 1; 00189 CubatureDirectLineGauss<Scalar> Cub1D(cubDegree1D); 00190 FieldContainer<Scalar> cubPoints1D(order1D, 1); 00191 FieldContainer<Scalar> cubWeights1D(order1D); 00192 00193 Cub1D.getCubature(cubPoints1D, cubWeights1D); 00194 00195 for(int node1D = 0; node1D < order1D; node1D++) 00196 { 00197 Teuchos::Array<Scalar> node(d-dims_left+1); 00198 node[d-dims_left] = cubPoints1D(node1D,0); 00199 for(int m = 0; m < d-dims_left; m++) 00200 node[m] = partial_node[m]; 00201 00202 Scalar weight = cubWeights1D(node1D)*partial_weight; 00203 00204 if(dims_left != 1) 00205 { 00206 iterateThroughDimensions(l - k_i, dims_left-1, cubPointsND, node, weight); 00207 } 00208 else 00209 { 00210 weight = pow(-1.0, end - k_i)*combination(d-1, k_i - l)*weight; 00211 cubPointsND.addNode(&node[0], weight); 00212 } 00213 } 00214 } 00215 } 00216 00217 } // end namespace Intrepid
1.7.4