46 #ifndef INTREPID_CUBATURE_SPARSE_HELPER_HPP
47 #define INTREPID_CUBATURE_SPARSE_HELPER_HPP
49 #include "Intrepid_ConfigDefs.hpp"
52 #include "Teuchos_Assert.hpp"
53 #include "Teuchos_Array.hpp"
61 template<
class Scalar,
int D>
69 bool operator<(const SGPoint<Scalar, D> & right)
const;
78 template<
class Scalar,
int D,
class ArrayPo
int=FieldContainer<Scalar>,
class ArrayWeight=ArrayPo
int>
81 Teuchos::Array< SGPoint<Scalar, D> > nodes;
82 Teuchos::Array< Scalar > weights;
83 bool addNode(Scalar new_node[D], Scalar weight);
84 void copyToArrays(ArrayPoint & cubPoints, ArrayWeight & cubWeights)
const;
86 int size()
const {
return nodes.size();}
92 template<
class Scalar,
int D>
95 for(
int i = 0; i < D; i++)
101 template<
class Scalar,
int D>
102 SGPoint<Scalar, D>::SGPoint(Scalar p[D])
104 for(
int i = 0; i < D; i++)
110 template<
class Scalar,
int D>
111 bool SGPoint<Scalar, D>::operator==(
const SGPoint<Scalar, D> & right)
const
115 for(
int i = 0; i < D; i++)
117 if(coords[i] != right.coords[i])
124 template<
class Scalar,
int D>
125 bool SGPoint<Scalar, D>::operator<(
const SGPoint<Scalar, D> & right)
const
127 for(
int i = 0; i < D; i++)
129 if(coords[i] < right.coords[i])
131 else if(coords[i] > right.coords[i])
138 template<
class Scalar,
int D>
139 bool SGPoint<Scalar, D>::operator>(
const SGPoint<Scalar, D> & right)
const
141 if(
this < right ||
this == right)
147 template<
class Scalar,
int D>
148 std::ostream & operator<<(std::ostream & o, SGPoint<Scalar, D> & p)
151 for(
int i = 0; i<D;i++)
152 o<< p.coords[i] <<
" ";
162 template<
class Scalar,
int D,
class ArrayPo
int,
class ArrayWeight>
163 bool SGNodes<Scalar,D,ArrayPoint,ArrayWeight>::addNode(Scalar new_node[D], Scalar weight)
165 SGPoint<Scalar, D> new_point(new_node);
166 bool new_and_added =
true;
168 if(nodes.size() == 0)
170 nodes.push_back(new_point);
171 weights.push_back(weight);
176 int right = (int)nodes.size();
177 int mid_node = (int)ceil(nodes.size()/2.0)-1;
179 bool iterate_continue =
true;
181 while(iterate_continue)
183 if(new_point == nodes[mid_node]){
184 weights[mid_node] += weight;
185 iterate_continue =
false;
186 new_and_added =
false;
188 else if(new_point < nodes[mid_node]){
189 if(right - left <= 2)
192 nodes.insert(nodes.begin()+mid_node, new_point);
193 weights.insert(weights.begin()+mid_node,weight);
194 iterate_continue =
false;
199 mid_node += (int)ceil((left-mid_node)/2.0);
204 if(mid_node == (
int)nodes.size()-1)
206 nodes.push_back(new_point);
207 weights.push_back(weight);
208 iterate_continue =
false;
210 else if(right - left <= 2)
213 nodes.insert(nodes.begin()+mid_node+1, new_point);
214 weights.insert(weights.begin()+mid_node+1,weight);
215 iterate_continue =
false;
220 mid_node += (int)ceil((right-mid_node)/2.0);
226 return new_and_added;
229 template<
class Scalar,
int D,
class ArrayPo
int,
class ArrayWeight>
230 void SGNodes<Scalar,D,ArrayPoint,ArrayWeight>::copyToArrays(ArrayPoint & cubPoints, ArrayWeight & cubWeights)
const
232 int numPoints = size();
234 for(
int i = 0; i < numPoints; i++)
236 for (
int j=0; j<D; j++) {
237 cubPoints(i,j) = nodes[i].coords[j];
239 cubWeights(i) = weights[i];
264 #if defined(Intrepid_SHOW_DEPRECATED_WARNINGS)
266 #warning "The Intrepid package is deprecated"
Header file for utility class to provide multidimensional containers.
Contains definitions of custom data types in Intrepid.