35 #ifndef _FINRESDYN_COVBOXES_H_ 36 #define _FINRESDYN_COVBOXES_H_ 44 #include "chomp/struct/hashsets.h" 45 #include "chomp/cubes/pointset.h" 46 #include "chomp/cubes/cube.h" 72 template <
class NumType>
80 tCoverBoxes (
const int spaceDim,
const NumType *leftCorner,
81 const NumType *boxWidths,
const int *partCounts,
82 const NumType *overlap = 0);
95 template <
class ResultType>
96 void get (
const int n,
97 ResultType *leftBounds, ResultType *rightBounds)
const;
100 template <
class ResultType>
101 void getLeftCorner (ResultType *leftCorner)
const;
104 template <
class ResultType>
105 void getBoxWidths (ResultType *boxWidths)
const;
115 template <
class InputType,
class BoxNumbers>
116 void cover (
const InputType *leftBounds,
117 const InputType *rightBounds, BoxNumbers &boxNumbers,
121 template <
class InputType>
122 void cover (
const InputType *x);
155 typedef chomp::homology::tCubeBase<CoordType>
CubeType;
158 chomp::homology::hashedset<CubeType>
boxes;
162 NumType leftBound (
int coord,
int dir)
const;
166 NumType rightBound (
int coord,
int dir)
const;
170 CoordType leftCoord (
const NumType &bound,
int dir)
const;
174 CoordType rightCoord (
const NumType &bound,
int dir)
const;
186 template <
class NumType>
188 const NumType *leftCorner,
const NumType *boxWidths,
189 const int *partCounts,
const NumType *overlap)
192 if ((spaceDim <= 0) || (spaceDim > 100000))
193 throw "Wrong space dimension for a box open cover.";
194 this -> spaceDim = spaceDim;
197 for (
int i = 0; i < spaceDim; ++ i)
199 if (boxWidths [i] <= 0)
200 throw "Trying to use a non-positive box width.";
201 if (partCounts [i] <= 0)
202 throw "Trying to use a non-positive no. of parts.";
203 if (overlap && (overlap [i] <= 0))
204 throw "Trying to use a too small overlap.";
205 if (overlap && (2.00001 * overlap [i] >=
206 boxWidths [i] / partCounts [i]))
208 throw "Trying to use too large overlap.";
213 this -> leftCorner =
new NumType [spaceDim];
214 for (
int i = 0; i < spaceDim; ++ i)
215 this -> leftCorner [i] = leftCorner [i];
218 this -> boxWidths =
new NumType [spaceDim];
219 for (
int i = 0; i < spaceDim; ++ i)
220 this -> boxWidths [i] = boxWidths [i];
223 this -> rightCorner =
new NumType [spaceDim];
224 for (
int i = 0; i < spaceDim; ++ i)
227 (
this -> leftCorner [i],
this -> boxWidths [i]);
231 this -> partCounts =
new int [spaceDim];
232 for (
int i = 0; i < spaceDim; ++ i)
233 this -> partCounts [i] = partCounts [i];
236 this -> overlap =
new NumType [spaceDim];
239 const NumType min_number =
241 for (
int i = 0; i < spaceDim; ++ i)
242 this -> overlap [i] = min_number;
246 for (
int i = 0; i < spaceDim; ++ i)
247 this -> overlap [i] = overlap [i];
251 this -> buffer =
new CoordType [2 * spaceDim];
256 template <
class NumType>
259 throw "Trying to use the copy constructor for an open cover.";
263 template <
class NumType>
267 throw "Trying to use the assignment operator for an open cover.";
271 template <
class NumType>
274 delete [] leftCorner;
276 delete [] rightCorner;
277 delete [] partCounts;
283 template <
class NumType>
289 template <
class NumType>
292 return boxes. size ();
295 template <
class NumType>
298 chomp::homology::hashedset<CubeType> empty;
303 template <
class NumType>
307 return leftCorner [dir];
309 NumType left1 = rnd::mul_down (boxWidths [dir], coord);
310 NumType left2 = rnd::div_down (left1, partCounts [dir]);
311 return rnd::add_down (leftCorner [dir], left2);
314 template <
class NumType>
318 if (coord == partCounts [dir])
319 return rnd::add_up (leftCorner [dir], boxWidths [dir]);
320 NumType right1 = rnd::mul_up (boxWidths [dir], coord + 1);
321 NumType right2 = rnd::div_up (right1, partCounts [dir]);
322 NumType right3 = rnd::add_up (right2, overlap [dir]);
323 return rnd::add_up (leftCorner [dir], right3);
326 template <
class NumType>
329 (
const NumType &bound,
int dir)
const 332 if (bound < leftCorner [dir])
333 throw "Trying to cover a box that is too large (left).";
336 if (bound == leftCorner [dir])
340 NumType offset = bound - leftCorner [dir];
342 (offset * partCounts [dir] / boxWidths [dir]);
347 if ((coord + 1 < partCounts [dir]) &&
348 (leftBound (coord + 1, dir) <= bound))
350 sbug <<
"* Left bound inc improve.\n";
356 if ((coord > 0) && (leftBound (coord, dir) > bound))
358 sbug <<
"* Left bound dec cover.\n";
363 if ((coord > 0) && (rightBound (coord - 1, dir) > bound))
365 sbug <<
"* Left bound dec overlap.\n";
372 template <
class NumType>
375 (
const NumType &bound,
int dir)
const 378 if (bound > rightCorner [dir])
379 throw "Trying to cover a box that is too large (right).";
382 if (bound == rightCorner [dir])
383 return partCounts [dir];
386 NumType offset = bound - leftCorner [dir] - overlap [dir];
387 int coord = (offset > 0) ? (static_cast<CoordType>
388 (offset * partCounts [dir] / boxWidths [dir]) + 1) : 1;
389 if (coord >= partCounts [dir])
390 return partCounts [dir];
393 if ((coord > 1) && (rightBound (coord - 2, dir) >= bound))
395 sbug <<
"* Right bound inc improve.\n";
401 if ((coord < partCounts [dir]) &&
402 (rightBound (coord - 1, dir) < bound))
404 sbug <<
"* Right bound inc cover.\n";
409 if ((coord < partCounts [dir]) &&
410 (leftBound (coord, dir) < bound))
412 sbug <<
"* Right bound inc overlap.\n";
419 template <
class NumType>
420 template <
class ResultType>
422 ResultType *leftBounds, ResultType *rightBounds)
const 428 if ((n < 0) || (n >= boxes. size ()))
429 throw "Wrong cover element requested.";
433 boxes [n]. coord (boxCoord);
436 for (
int i = 0; i < spaceDim; ++ i)
438 leftBounds [i] = leftBound (boxCoord [i], i);
439 rightBounds [i] = rightBound (boxCoord [i], i);
444 template <
class NumType>
445 template <
class ResultType>
449 for (
int i = 0; i < spaceDim; ++ i)
450 leftCorner [i] =
this -> leftCorner [i];
454 template <
class NumType>
455 template <
class ResultType>
459 for (
int i = 0; i < spaceDim; ++ i)
460 boxWidths [i] =
this -> boxWidths [i];
464 template <
class NumType>
465 template <
class InputType,
class BoxNumbers>
467 const InputType *rightBounds, BoxNumbers &boxNumbers,
475 for (
int i = 0; i < spaceDim; ++ i)
477 left [i] = leftCoord (leftBounds [i], i);
478 right [i] = rightCoord (rightBounds [i], i);
485 for (
int i = 0; i < spaceDim; ++ i)
488 (rightBound (right [i], i),
489 leftBound (left [i], i));
496 *diameter2 = squares;
500 chomp::homology::tRectangle<CoordType> r (left, right, spaceDim);
502 while ((c = r. get ()) != 0)
505 int n = boxes. getnumber (q);
510 boxNumbers.
add (boxes. size ());
518 template <
class NumType>
519 template <
class InputType>
526 NumType *xLeft =
new NumType [spaceDim];
527 NumType *xRight =
new NumType [spaceDim];
528 NumType min_number = rnd::min_number ();
529 for (
int i = 0; i < spaceDim; ++ i)
531 xLeft [i] = rnd::add_down (x [i], min_number);
532 xRight [i] = rnd::add_up (x [i], min_number);
537 this -> cover (xLeft, xRight, d);
545 template <
class NumType>
549 int dim = cover. dim ();
550 NumType *buffer =
new NumType [dim << 1];
551 NumType *leftBound = buffer;
552 NumType *rightBound = buffer + dim;
553 for (
int n = 0; n < cover. size (); ++ n)
555 cover.
get (n, leftBound, rightBound);
556 for (
int i = 0; i < dim; ++ i)
558 out << (i ?
" x [" :
"[") << leftBound [i] <<
559 "," << rightBound [i] <<
"]";
568 #endif // _FINRESDYN_COVBOXES_H_ void cover(const InputType *leftBounds, const InputType *rightBounds, BoxNumbers &boxNumbers, NumType *diameter2=0)
Covers the given box and adds numbers of all the boxes in the cover to a list using the provided clas...
int dim() const
Returns the dimension of the phase space.
Various output streams for the program.
void get(const int n, ResultType *leftBounds, ResultType *rightBounds) const
Returns the coordinates of the given box.
NumType * overlap
The minimal overlap width.
int CoordType
The type of integer coordinates for boxes that represent cover elements.
Rigorous rounding of arithmetic operations.
A cover of a subset in R^n consisting of open boxes.
tCoverBoxes(const int spaceDim, const NumType *leftCorner, const NumType *boxWidths, const int *partCounts, const NumType *overlap=0)
The constructor of an open cover object.
NumType * boxWidths
The widths of the covered rectangle in all the directions.
NumType NumberType
The type of numbers in the Henon map.
A dummy class for adding box numbers.
~tCoverBoxes()
The destructor of an open cover object.
CoordType leftCoord(const NumType &bound, int dir) const
Computes the left coordinate in the given direction of the leftmost box to cover the given real coord...
chomp::homology::tCubeBase< CoordType > CubeType
The type of a cube that represents a cover element.
A class for rounding operations which uses the BOOST library.
void forget()
Forgets the cover elements.
chomp::homology::hashedset< CubeType > boxes
The set of boxes in the cover.
int spaceDim
The dimension of the space.
int size() const
Returns the number of boxes in the cover.
NumType leftBound(int coord, int dir) const
Computes the real left coordinate in the given direction of a box represented by integer coordinates...
NumType * rightCorner
The upper right corner of the covered rectangle.
static NumType min_number()
The smallest positive representable number.
NumType diameter2(const int dim, const NumType *leftBounds, const NumType *rightBounds)
Computes an upper bound for the square of the diameter of a given box.
void add(int)
Forgets the box number.
void getLeftCorner(ResultType *leftCorner) const
Returns the coordinates of the left corner of the range box.
void getBoxWidths(ResultType *boxWidths) const
Returns the width of the range box in each direction.
std::ostream & operator<<(std::ostream &out, const tCoverBoxes< NumType > &cover)
NumType * leftCorner
The lower left corner of the covered rectangle.
NumType rightBound(int coord, int dir) const
Computes the real right coordinate in the given direction of a box represented by integer coordinates...
int * partCounts
The numbers of parts into which the box is subdivided in each direction.
CoordType * buffer
A temporary buffer for the coordinates of two cubes.
CoordType rightCoord(const NumType &bound, int dir) const
Computes the right coordinate in the given direction of the rightmost box to cover the given real coo...