The Conley-Morse Graphs Software
coverrect.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file coverrect.h
4///
5/// Covering a rotated rectangular set or a paralellepiped with cubes
6/// with respect to a fixed grid in R^n.
7///
8/// @author Pawel Pilarczyk, Tomasz Kapela
9///
10/////////////////////////////////////////////////////////////////////////////
11
12// Copyright (C) 1997-2014 by Pawel Pilarczyk and Tomasz Kapela.
13//
14// This file is part of my research software package. This is free software:
15// you can redistribute it and/or modify it under the terms of the GNU
16// General Public License as published by the Free Software Foundation,
17// either version 3 of the License, or (at your option) any later version.
18//
19// This software is distributed in the hope that it will be useful,
20// but WITHOUT ANY WARRANTY; without even the implied warranty of
21// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22// GNU General Public License for more details.
23//
24// You should have received a copy of the GNU General Public License
25// along with this software; see the file "license.txt". If not,
26// please, see <https://www.gnu.org/licenses/>.
27
28// Started on July 16, 2012. Last revision: July 8, 2014.
29
30
31#ifndef _CMGRAPHS_COVERRECT_H_
32#define _CMGRAPHS_COVERRECT_H_
33
34
35// include some standard C++ header files
36#include <iostream>
37#include <algorithm>
38#include <string>
39#include <new>
40
41// include selected header files from the CHomP library
42#include "chomp/system/config.h"
43#include "chomp/system/textfile.h"
44#include "chomp/struct/autoarray.h"
45
46// include all the necessary header files from the CAPD library
47#ifdef _CAPD29_
48#include "capd/vectalg/lib.h"
49#include "capd/dynset/lib.h"
50#include "capd/dynsys/lib.h"
51#else
52//#include "capd/capdlib.h"
53#define CAPD_USER_NAMESPACE capd
54#define CAPD_DEFAULT_DIMENSION spaceDim
55#include "capd/fdcapdlib.h"
56#undef CAPD_USER_NAMESPACE
57#undef CAPD_DEFAULT_DIMENSION
58#endif
59
60// include local header files
61#include "typeintv.h"
62#include "typerect.h"
63
64
65// --------------------------------------------------
66// ----------------- COVER RECT SET -----------------
67// --------------------------------------------------
68
69/// Covers a rectangular set by cubes with respect
70/// to a uniform subdivision of a rectangular area
71/// defined by the offset of the lower left corner
72/// and the width of the area.
73/// \param rectSet - the rectangular set to be covered
74/// \param offset - the real offset of the central box in the phase space
75/// \param width - the real width of the central box in the phase space
76/// \param intWidth - the width of the grid on the central box
77/// in each direction
78/// \param dim - the dimension of the phase space
79/// \param image - the set of cubes in which to store the cubes
80/// that cover the given rectangular set
81/// \param left - the left bound on grid elements in the image
82/// \param right - the right bound on grid elements in the image
83/// \param codomain - a codomain (possibly very large) to which
84/// the image should be restricted
85/// \param disjoint - a set of cubes from which the image
86/// should be disjoint (these cubes are not added even if
87/// they might actually intersect the rectangular set)
88
89template <class DoubleArray1, class DoubleArray2,
90 class CoordType, class CubSetType>
91void coverRectSet (const RectSetType &rectSet,
92 const DoubleArray1 &offset, const DoubleArray2 &width,
93 const CoordType *intWidth, int dim,
94 CubSetType &image,
95 const CoordType *left, const CoordType *right,
96 const CubSetType *codomain, const CubSetType *disjoint)
97{
98 // extract the type of a single cube
99 typedef typename CubSetType::value_type CubeType;
100
101 // extract the types related to the rectangular sets
102 typedef capd::C0Rect2Set C0SetType;
103 typedef typename C0SetType::MatrixType MatrixType;
104 typedef typename C0SetType::VectorType VectorType;
105
106 // iterate all the cubes in the given rectangular box;
107 // there is no need to check any cubes outside of this area,
108 // e.g. because of phase space cropping;
109 // each cube is represented by its minimal (lower left etc.) corner,
110 // e.g., the cube [0,1]x[3,4]x[-2,-1] is represented by (0,3,-2)
111 chomp::homology::tRectangle<CoordType> r (left, right, dim);
112 const CoordType *coord;
113
114 // C0RectSet has representation x + C*r0 + B*r;
115 // first we transform it into two representations
116 // x + C * w1 where w1 = r0 + (C_1*B)*r,
117 // x + B * w2 where w2 = r + (B_1*C)*r0;
118 // then for given box Z we transform it
119 // to those representations computing
120 // z1 = C_1 * (Z - x),
121 // z2 = B_1 * (Z - x);
122 // finally, if w1 is disjoint from z1 or w2 is disjoint from z2
123 // then box Z is disjoint from rectSet.
124 using capd::matrixAlgorithms::gaussInverseMatrix;
125 MatrixType C_1 = gaussInverseMatrix (
127 rectSet. corrector. get_C ()
128#else
129 rectSet. get_C ()
130#endif
131 );
132 MatrixType B_1 = gaussInverseMatrix (
134 rectSet. corrector. get_B ()
135#else
136 rectSet. get_B ()
137#endif
138 );
139
140 VectorType w1 =
141#ifdef PREDICTOR_CORRECTOR
142 rectSet. corrector. get_r0 () +
143 (C_1 * rectSet. corrector. get_B ()) *
144 rectSet. corrector. get_r ();
145#else
146 rectSet. get_r0 () +
147 (C_1 * rectSet. get_B ()) * rectSet. get_r ();
148#endif
149 VectorType w2 =
150#ifdef PREDICTOR_CORRECTOR
151 rectSet. corrector. get_r () +
152 (B_1 * rectSet. corrector. get_C ()) *
153 rectSet. corrector. get_r0 ();
154#else
155 rectSet. get_r () +
156 (B_1 * rectSet. get_C ()) * rectSet. get_r0 ();
157#endif
158
159 // get the center of the rectangular set
160 VectorType x =
161#ifdef PREDICTOR_CORRECTOR
162 rectSet. corrector. get_x ();
163#else
164 rectSet. get_x ();
165#endif
166
167 // prepare non-initialized vectors to be used across the while loop
168 VectorType Z (dim, false);
169 VectorType Z_x (x. dimension (), false);
170 VectorType z1 (x. dimension (), false);
171 VectorType z2 (x. dimension (), false);
172
173 while ((coord = r. get ()) != 0)
174 {
175 // create a cube that will be considered
176 CubeType q (coord, dim);
177
178 // if the cube is not in the codomain then skip it
179 if (codomain && !codomain -> check (q))
180 continue;
181
182 // if the cube is in the set from which the image should be
183 // disjoint then also skip it
184 if (disjoint && disjoint -> check (q))
185 continue;
186
187 // compute the actual box corresponding to the cube
188 for (int i = 0; i < dim; ++ i)
189 {
190 Z [i] = IntervalType (coord [i], coord [i] + 1);
191 Z [i] /= intWidth [i];
192 Z [i] *= width [i];
193 Z [i] += offset [i];
194 }
195 Z_x = Z - x;
196
197 // check if the box is disjoint from the rectangular set
198 z1 = C_1 * Z_x;
199 if (capd::vectalg::intersectionIsEmpty (z1, w1))
200 continue;
201 z2 = B_1 * Z_x;
202 if(capd::vectalg::intersectionIsEmpty(z2, w2))
203 continue;
204
205 // add the cube to the image if the box is not proved
206 // to be disjoint from the rectangular set
207 image. add (q);
208 }
209
210 // switch rounding mode back to the default one if necessary
211 resetRounding ();
212
213 return;
214} /* coverRectSet */
215
216
217#endif // _CMGRAPHS_COVERRECT_H_
218
void coverRectSet(const RectSetType &rectSet, const DoubleArray1 &offset, const DoubleArray2 &width, const CoordType *intWidth, int dim, CubSetType &image, const CoordType *left, const CoordType *right, const CubSetType *codomain, const CubSetType *disjoint)
Covers a rectangular set by cubes with respect to a uniform subdivision of a rectangular area defined...
Definition: coverrect.h:91
bool disjoint(const pointset &p, const pointset &q)
Definition: psetjoin.cpp:139
Data types for interval arithmetic.
void resetRounding()
This function resets rounding switches of the processor and sets rounding to the nearest.
Definition: typeintv.h:65
capd::DInterval IntervalType
The type of an interval (from the CAPD library 2.9/3.0 beta).
Definition: typeintv.h:49
Data type for the rectangular (Lohner-type) set from CAPD.
capd::C0HORect2Set RectSetType
The type of the rectangular set to use.
Definition: typerect.h:57
#define PREDICTOR_CORRECTOR
Definition: typerect.h:58