1 /* _______________________________________________________________________
2
3 PECOS: Parallel Environment for Creation Of Stochastics
4 Copyright (c) 2011, Sandia National Laboratories.
5 This software is distributed under the GNU Lesser General Public License.
6 For more information, see the README file in the top Pecos directory.
7 _______________________________________________________________________ */
8
9 //- Class: RefinablePointSet
10 //- Description: Implementation code for RefinablePointSet class
11 //-
12 //- Owner: Christopher Miller, University of Maryland
13 //- Contact: cmiller@math.umd.edu
14
15 #include "RefinablePointSet.hpp"
16
17 namespace Pecos{
18
RefinablePointSet(size_t map_starting_capacity)19 RefinablePointSet::RefinablePointSet(size_t map_starting_capacity):
20 current_level(1),
21 current_level_size(1),
22 num_interp_points(1),
23 interpPointsValid(false),
24 highestLevelPointsValid(false),
25 interpPts(1),
26 highestLevelPoints(1),
27 int_index_to_level_index_map(1)
28 {
29 int_index_to_level_index_map.reserve(map_starting_capacity);
30 }
31
~RefinablePointSet()32 RefinablePointSet::~RefinablePointSet()
33 {
34 }
35
refine_all()36 void RefinablePointSet::refine_all()
37 {
38 const BoolDeque bitset(current_level_size,true);
39 this->refine(bitset);
40 }
41
get_interp_point(unsigned int point) const42 const Real RefinablePointSet::get_interp_point(unsigned int point) const
43 {
44 return get_interp_point( int_index_to_level_index_map.at(point) );
45 }
46
47
get_interp_points()48 const RealArray& RefinablePointSet::get_interp_points()
49 {
50 update_interpPts();
51 return interpPts;
52 }
53
get_highest_level_points()54 const RealArray& RefinablePointSet::get_highest_level_points()
55 {
56 update_highestLevelPoints();
57 return highestLevelPoints;
58 }
59
get_current_level() const60 const unsigned int RefinablePointSet::get_current_level() const
61 {
62 return current_level;
63 }
64
get_current_level_size() const65 const unsigned int RefinablePointSet::get_current_level_size() const
66 {
67 return current_level_size;
68 }
69
get_num_interp_points() const70 const unsigned int RefinablePointSet::get_num_interp_points() const
71 {
72 return num_interp_points;
73 }
74
75 const IntArray& RefinablePointSet::
get_level_index_pair(unsigned int i) const76 get_level_index_pair(unsigned int i) const
77 {
78 return int_index_to_level_index_map.at(i);
79 }
80
update_interpPts()81 void RefinablePointSet::update_interpPts()
82 {
83 if ( !interpPointsValid ) {
84 interpPts.resize(num_interp_points);
85 for ( unsigned int idx = 0; idx < num_interp_points; idx++ ) {
86 interpPts[idx] = get_interp_point(int_index_to_level_index_map.at(idx));
87 }
88 std::sort( interpPts.begin(),interpPts.end() );
89 }
90
91 interpPointsValid = true;
92 }
93
update_highestLevelPoints()94 void RefinablePointSet::update_highestLevelPoints()
95 {
96 if ( !highestLevelPointsValid ) {
97 highestLevelPoints.resize(current_level_size);
98 IntArray levelIndex(2);
99 for ( unsigned int idx = num_interp_points-current_level_size;
100 idx < num_interp_points; idx++ ) {
101 levelIndex = int_index_to_level_index_map.at(idx);
102 highestLevelPoints[idx - ( num_interp_points-current_level_size ) ] =
103 get_interp_point( levelIndex );
104 }
105 }
106
107 highestLevelPointsValid = true;
108 }
109
110 std::ostream&
operator <<(std::ostream & ostr,const RefinablePointSet & pointSet)111 operator<<(std::ostream& ostr, const RefinablePointSet& pointSet)
112 {
113
114 ostr << "Index" << "\t" << "[level/index]" << "\t" << "Point" << std::endl;
115 ostr << "-----" << "\t" << "-------------" << "\t" << "-----" << std::endl;
116 IntArray value_from_map(2);
117 for ( unsigned int i = 0; i < pointSet.num_interp_points; i++ ) {
118 value_from_map = pointSet.int_index_to_level_index_map[i];
119 ostr << i << "\t[" << value_from_map[0] << "," << value_from_map[1]
120 << "]\t\t" << pointSet.get_interp_point(value_from_map) << std::endl;
121 }
122 return ostr;
123 }
124
125 } // End namespace Pecos
126