The Conley-Morse Graphs Software
m_twocirc.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file m_twocirc.h
4///
5/// Two circles - a simple test map with two invariant circles.
6///
7/// This map defines a simple test mapping with a formula given by Jacek.
8///
9/// @author Pawel Pilarczyk
10///
11/////////////////////////////////////////////////////////////////////////////
12
13// Copyright (C) 1997-2014 by Pawel Pilarczyk.
14//
15// This file is part of my research software package. This is free software:
16// you can redistribute it and/or modify it under the terms of the GNU
17// General Public License as published by the Free Software Foundation,
18// either version 3 of the License, or (at your option) any later version.
19//
20// This software is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23// GNU General Public License for more details.
24//
25// You should have received a copy of the GNU General Public License
26// along with this software; see the file "license.txt". If not,
27// please, see <https://www.gnu.org/licenses/>.
28
29// Started on May 21, 2011. Last revision: January 17, 2012.
30
31
32#ifndef _CMGRAPHS_TWOCIRC_H_
33#define _CMGRAPHS_TWOCIRC_H_
34
35
36// some standard header files
37#include <cmath>
38
39// include local header files
40#include "maptype.h"
41#include "typeintv.h"
42
43// for debugging
44#include "chomp/system/textfile.h"
45
46
47// --------------------------------------------------
48// ------------ a two circles model map -------------
49// --------------------------------------------------
50
51/// This class defines a test mapping by a formula from Jacek Szybowski.
52/// There is only one parameter to the map. If the left value is <= 1
53/// then the first map is selected, otherwise the second map is selected.
54class MapTwoCirc: public MapType
55{
56public:
57 /// The default constructor.
58 MapTwoCirc ();
59
60 /// Computes the image of a box whose left and right coordinates
61 /// are given. Fills in the images with the left and right
62 /// coordinates of the image box.
63 void compute (const double *xleft, const double *xright,
64 double *yleft, double *yright, int dim,
65 const spcCoord *coord, int subdiv) const;
66
67private:
68 /// Computes the core map. Replaces 'x' and 'y' with their images.
69 void computeMap0 (IntervalType &x, IntervalType &y, int root) const;
70
71}; /* class MapTwoCirc */
72
73// --------------------------------------------------
74
76{
78 return;
79} /* MapTwoCirc::MapTwoCirc */
80
82 int root) const
83{
84 using chomp::homology::sbug;
85
86 // apply the formula if at least one variable does not contain 0
87 if (((x. leftBound () > 0) || (x. rightBound () < 0)) ||
88 ((y. leftBound () > 0) || (y. rightBound () < 0)))
89 {
90 IntervalType denomTmp = power (x, 2) + power (y, 2);
91 IntervalType denominator = (root == 2) ?
92 sqrt (denomTmp) : power (denomTmp,
93 IntervalType (1.0 / root, 1.0 / root));
94 if ((denominator. leftBound () <= 0) &&
95 (denominator. rightBound () >= 0))
96 {
97 throw "Denominator contains zero.";
98 }
99 x /= denominator;
100 y /= denominator;
101 return;
102 }
103
104 // if x == 0
105 if ((x. leftBound () == 0) && (x. rightBound () == 0))
106 {
107 x = IntervalType (0.0, 0.0);
108 if (root == 2)
109 {
110 y = IntervalType (-1.0, 1.0);
111 return;
112 }
113 double yMin = y. leftBound ();
114 if (yMin != 0)
115 {
116 y = (IntervalType (yMin, yMin) /
117 power (IntervalType (-yMin, -yMin),
118 IntervalType (2.0 / root, 2.0 / root)));
119 }
120 double yMax = y. rightBound ();
121 if (yMax != 0)
122 {
123 y = (IntervalType (yMax, yMax) /
124 power (IntervalType (yMax, yMax),
125 IntervalType (2.0 / root, 2.0 / root)));
126 }
127 y = IntervalType (yMin, yMax);
128 return;
129 }
130
131 // if y == 0
132 if ((y. leftBound () == 0) && (y. rightBound () == 0))
133 {
134 computeMap0 (y, x, root);
135 return;
136 }
137
138 // calculate the endpoints separately if both variables contain 0
139 double xMaxAbs ((-(x. leftBound ()) > x. rightBound ()) ?
140 -(x. leftBound ()) : x. rightBound ());
141 double yMaxAbs ((-(y. leftBound ()) > y. rightBound ()) ?
142 -(y. leftBound ()) : y. rightBound ());
143 IntervalType xMaxAbs2 (power (IntervalType (xMaxAbs, xMaxAbs), 2));
144 IntervalType yMaxAbs2 (power (IntervalType (yMaxAbs, yMaxAbs), 2));
145
146 // calculate xLeft
147 double xLeft (0);
148 if (x. leftBound () == 0)
149 {
150 xLeft = (root == 2) ? -1 : 0;
151 }
152 else
153 {
154 IntervalType numerator (x. leftBound (), x. leftBound ());
155 IntervalType fraction2 (2.0 / root, 2.0 / root);
156 IntervalType denominator (power (-numerator, fraction2));
157 xLeft = (numerator / denominator). leftBound ();
158 }
159
160 // calculate yLeft
161 double yLeft (0);
162 if (y. leftBound () == 0)
163 {
164 yLeft = (root == 2) ? -1 : 0;
165 }
166 else
167 {
168 IntervalType numerator (y. leftBound (), y. leftBound ());
169 IntervalType fraction2 (2.0 / root, 2.0 / root);
170 IntervalType denominator (power (-numerator, fraction2));
171 yLeft = (numerator / denominator). leftBound ();
172 }
173
174 // calculate xRight
175 double xRight (0);
176 if (x. rightBound () == 0)
177 {
178 xRight = (root == 2) ? 1 : 0;
179 }
180 else
181 {
182 IntervalType numerator (x. rightBound (), x. rightBound ());
183 IntervalType fraction2 (2.0 / root, 2.0 / root);
184 IntervalType denominator (power (numerator, fraction2));
185 xRight = (numerator / denominator). leftBound ();
186 }
187
188 // calculate yRight
189 double yRight (0);
190 if (y. rightBound () == 0)
191 {
192 yRight = (root == 2) ? 1 : 0;
193 }
194 else
195 {
196 IntervalType numerator (y. rightBound (), y. rightBound ());
197 IntervalType fraction2 (2.0 / root, 2.0 / root);
198 IntervalType denominator (power (numerator, fraction2));
199 yRight = (numerator / denominator). leftBound ();
200 }
201
202 x = IntervalType (xLeft, xRight);
203 y = IntervalType (yLeft, yRight);
204
205 return;
206} /* MapTwoCirc::computeMap0 */
207
208inline void MapTwoCirc::compute (const double *xleft, const double *xright,
209 double *yleft, double *yright, int dim, const spcCoord *, int) const
210{
211 using chomp::homology::sbug;
212
213 // this formula is programmed for phase space of dim 2 only
214 if (dim != 2)
215 throw "Test mapping for two circles: dim = 2 only!";
216
217 // debug: show the values
218// sbug << "input = [" << xleft [0] << "," << xright [0] <<
219// "] x [" << xleft [1] << "," << xright [1] << "]\n";
220
221 // determine the map choice: 0, 1, 2 or 3,
222 // corresponding to Example 1, f_1 or f_2, and Example 2, f_1 or f_2
223 int whichMap = static_cast<int> (std::floor (getLeftParam (0)));
224
225 // get the intervals for the x and y variables
226 IntervalType x (xleft [0], xright [0]);
227 IntervalType y (xleft [1], xright [1]);
228
229 // check if the box is inside or outside the disk or radius 2
230 IntervalType radius2 = power (x, 2) + power (y, 2);
231
232 // compute the image of the auxiliary base map
233 IntervalType x4 (x);
234 IntervalType y4 (y);
235 computeMap0 (x4, y4, 4);
236 IntervalType x2 (x);
237 IntervalType y2 (y);
238 if (whichMap > 1)
239 computeMap0 (x2, y2, 2);
240
241 // determine the coefficients
242 double coefInt = 0;
243 double coefExt = 0;
244 IntervalType xInt (x4);
245 IntervalType yInt (y4);
246 IntervalType xExt (x4);
247 IntervalType yExt (y4);
248 switch (whichMap)
249 {
250 case 0:
251 coefInt = 1.0;
252 coefExt = std::sqrt (2);
253 break;
254 case 1:
255 coefInt = std::sqrt (2);
256 coefExt = std::sqrt (3);
257 break;
258 case 2:
259 coefInt = 1.0;
260 coefExt = std::sqrt (2);
261 xInt = x2;
262 yInt = y2;
263 break;
264 case 3:
265 coefInt = std::sqrt (2);
266 coefExt = 3;
267 xExt = x2;
268 yExt = y2;
269 break;
270 default:
271 throw "Wrong parameter value - unknown map requested.";
272 }
273
274 // multiply the result by the right coefficients
275 if (radius2. rightBound () < 4)
276 {
277 x = coefInt * xInt;
278 y = coefInt * yInt;
279 }
280 else if (radius2. leftBound () > 4)
281 {
282 x = coefExt * xExt;
283 y = coefExt * yExt;
284 }
285 else
286 {
287 x = intervalHull (coefInt * xInt, coefExt * xExt);
288 y = intervalHull (coefInt * yInt, coefExt * yExt);
289 }
290
291 // copy the result values
292 yleft [0] = x. leftBound ();
293 yright [0] = x. rightBound ();
294 yleft [1] = y. leftBound ();
295 yright [1] = y. rightBound ();
296
297 // debug: show the values
298/* sbug << "output = [" << yleft [0] << "," << yright [0] <<
299 "] x [" << yleft [1] << "," << yright [1] << "]\n";
300 double exp0 = (yright [0] - yleft [0]) / (xright [0] - xleft [0]);
301 double exp1 = (yright [1] - yleft [1]) / (xright [1] - xleft [1]);
302 sbug << "expansion: " << exp0 << " x " << exp1 << "\n";
303*/
304 // swich the rounding direction to the neutral one
305 resetRounding ();
306 return;
307} /* MapTwoCirc::compute */
308
309
310#endif // _CMGRAPHS_TWOCIRC_H_
311
This class defines a test mapping by a formula from Jacek Szybowski.
Definition: m_twocirc.h:55
void compute(const double *xleft, const double *xright, double *yleft, double *yright, int dim, const spcCoord *coord, int subdiv) const
Computes the image of a box whose left and right coordinates are given.
Definition: m_twocirc.h:208
void computeMap0(IntervalType &x, IntervalType &y, int root) const
Computes the core map. Replaces 'x' and 'y' with their images.
Definition: m_twocirc.h:81
MapTwoCirc()
The default constructor.
Definition: m_twocirc.h:75
This is an abstract class which defines the interface to other classes that describe maps for the use...
Definition: maptype.h:59
const double & getLeftParam(int n) const
Returns the left value of the given parameter.
Definition: maptype.h:196
An abstract map type.
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
bool testIntervals(bool throwException=false)
Testing interval arithmetic.
Definition: typeintv.h:82
capd::DInterval IntervalType
The type of an interval (from the CAPD library 2.9/3.0 beta).
Definition: typeintv.h:49
int spcCoord
The type of coordinates of cubes in the phase space.
Definition: typespace.h:50