The Conley-Morse Graphs Software
m_twotorus.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file m_twotorus.h
4///
5/// Two circles at a torus - 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 January 20, 2012. Last revision: January 20, 2012.
30
31
32#ifndef _CMGRAPHS_TWOTORUS_H_
33#define _CMGRAPHS_TWOTORUS_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 MapTwoTorus: public MapType
55{
56public:
57 /// The default constructor.
58 MapTwoTorus ();
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) const;
70
71}; /* class MapTwoTorus */
72
73// --------------------------------------------------
74
76{
78 return;
79} /* MapTwoTorus::MapTwoTorus */
80
82{
83 using chomp::homology::sbug;
84
85 y = 16 * power (y - x / 2 - 1.0 / 4, 3) + 1.0 / 4 + x / 2;
86
87 return;
88} /* MapTwoTorus::computeMap0 */
89
90inline void MapTwoTorus::compute (const double *xleft, const double *xright,
91 double *yleft, double *yright, int dim, const spcCoord *, int) const
92{
93 using chomp::homology::sbug;
94
95 // this formula is programmed for phase space of dim 2 only
96 if (dim != 2)
97 throw "Mapping for two circles on a torus: dim = 2 only!";
98
99 // debug: show the values
100// sbug << "input = [" << xleft [0] << "," << xright [0] <<
101// "] x [" << xleft [1] << "," << xright [1] << "]\n";
102
103 // determine the map choice: 0, 1
104 // corresponding to Example 3, f_1 or f_2
105 int whichMap = static_cast<int> (std::floor (getLeftParam (0)));
106
107 // the first map is very simple, so apply the formula immediately
108 if (whichMap == 0)
109 {
110 IntervalType y (xleft [1], xright [1]);
111 y = 4 * power (y - 1.0 / 2, 3) + 1.0 / 2;
112 yleft [0] = xleft [0];
113 yright [0] = xright [0];
114 yleft [1] = y. leftBound ();
115 yright [1] = y. rightBound ();
116 return;
117 }
118
119 // get the intervals for the x and y variables
120 IntervalType x (xleft [0], xright [0]);
121 IntervalType y (xleft [1], xright [1]);
122
123 // check if the box touches the inside and the outside the region D
124 bool inside (((x / 2). leftBound () <= y. rightBound ()) &&
125 (y. leftBound () <= (x / 2 + 1.0 / 2). rightBound ()));
126 bool outside (((x / 2). rightBound () > y. leftBound ()) ||
127 (y. rightBound () > (x / 2 + 1.0 / 2). leftBound ()));
128
129 // compute the image in the region D if necessary
130 IntervalType xInD (x);
131 IntervalType yInD (y);
132 if (inside)
133 {
134 computeMap0 (xInD, yInD);
135 }
136
137 // compute the image outside the region D if necessary
138 IntervalType xOutD (x);
139 IntervalType yOutD (y);
140 if (outside)
141 {
142 // prepare y + 1/2
143 IntervalType yHalf (yOutD + 1.0 / 2);
144
145 // if it sticks out of the [0,1] interval, shift it backwards
146 if (yHalf. leftBound () >= 1.0)
147 yHalf -= 1.0;
148
149 // compute f_0 (x, y + 1/2); it may be necessary to split y
150 if (yHalf. rightBound () <= 1.0)
151 {
152 IntervalType xCopy (xOutD);
153 computeMap0 (xCopy, yHalf);
154 }
155 else
156 {
157 IntervalType xCopy1 (xOutD);
158 IntervalType y1 (yHalf. leftBound (), 1.0);
159 computeMap0 (xCopy1, y1);
160 IntervalType xCopy2 (xOutD);
161 IntervalType y2 (0.0, (yHalf - 1.0). rightBound ());
162 computeMap0 (xCopy2, y2);
163 yHalf = intervalHull (y1, y2);
164 }
165
166 // add 1/2 to the result
167 yOutD = yHalf + IntervalType (1.0 / 2, 1.0 / 2);
168
169 // if it sticks out of the [0,1] interval, shift it backwards
170 if (yOutD. leftBound () >= 1.0)
171 yOutD -= 1.0;
172 }
173
174 // compute the resulting interval
175 if (!outside)
176 {
177 x = xInD;
178 y = yInD;
179 }
180 else if (!inside)
181 {
182 x = xOutD;
183 y = yOutD;
184 }
185 else
186 {
187 x = intervalHull (xInD, xOutD);
188 y = intervalHull (yInD, yOutD);
189 }
190
191 // copy the result values to the output variables
192 yleft [0] = x. leftBound ();
193 yright [0] = x. rightBound ();
194 yleft [1] = y. leftBound ();
195 yright [1] = y. rightBound ();
196
197 // swich the rounding direction to the neutral one
198 resetRounding ();
199 return;
200} /* MapTwoTorus::compute */
201
202
203#endif // _CMGRAPHS_TWOTORUS_H_
204
This class defines a test mapping by a formula from Jacek Szybowski.
Definition: m_twotorus.h:55
MapTwoTorus()
The default constructor.
Definition: m_twotorus.h:75
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_twotorus.h:90
void computeMap0(IntervalType &x, IntervalType &y) const
Computes the core map. Replaces 'x' and 'y' with their images.
Definition: m_twotorus.h:81
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