The Conley-Morse Graphs Software
maptype.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file maptype.h
4///
5/// An abstract map type.
6/// This file contains the definition of an abstract class
7/// of a multi-parameter map for the program "cmgraphs.cpp".
8/// Each class which defines a particular map should be derived
9/// from the class "MapType" defined in this file,
10/// or at least should have the same interface.
11///
12/// @author Pawel Pilarczyk
13///
14/////////////////////////////////////////////////////////////////////////////
15
16// Copyright (C) 1997-2014 by Pawel Pilarczyk.
17//
18// This file is part of my research software package. This is free software:
19// you can redistribute it and/or modify it under the terms of the GNU
20// General Public License as published by the Free Software Foundation,
21// either version 3 of the License, or (at your option) any later version.
22//
23// This software is distributed in the hope that it will be useful,
24// but WITHOUT ANY WARRANTY; without even the implied warranty of
25// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26// GNU General Public License for more details.
27//
28// You should have received a copy of the GNU General Public License
29// along with this software; see the file "license.txt". If not,
30// please, see <https://www.gnu.org/licenses/>.
31
32// Started on February 9, 2008. Last revision: September 4, 2014.
33
34
35#ifndef _CMGRAPHS_MAPTYPE_H_
36#define _CMGRAPHS_MAPTYPE_H_
37
38
39// include some standard C++ header files
40#include <vector>
41#include <string>
42
43// include selected header files from the CHomP library
44#include "chomp/multiwork/mwdata.h"
45#include "chomp/system/textfile.h"
46
47// include local header files
48#include "typespace.h"
49#include "typeintv.h"
50
51
52// --------------------------------------------------
53// ------------- the abstract map class -------------
54// --------------------------------------------------
55
56/// This is an abstract class which defines the interface to other classes
57/// that describe maps for the use for the program "cmgraphs.cpp".
59{
60public:
61 /// The default constructor of an object which describes a map.
62 MapType ();
63
64 /// The destructor of an object which describe a map.
65 virtual ~MapType ();
66
67 /// Sets the parameters to the given intervals defined by their
68 /// left and right coordinates.
69 virtual void setParam (const double *left, const double *right,
70 int n);
71
72 /// Returns the left value of the given parameter.
73 const double &getLeftParam (int n) const;
74
75 /// Returns the right value of the given parameter.
76 const double &getRightParam (int n) const;
77
78 /// Computes the image of a box whose left and right coordinates
79 /// are given. Fills in the images with the left and right
80 /// coordinates of the image box.
81 /// Whenever this information is relevant, the integer coordinates
82 /// of the box are provided, as well as the subdivision level
83 /// of the full phase space box; otherwise the pointer to the
84 /// coordinates is set to 0, and the subdivision level is undefined.
85 virtual void compute (const double *xleft, const double *xright,
86 double *yleft, double *yright, int dim,
87 const spcCoord *coord, int subdiv) const = 0;
88
89 /// An interface to the function 'compute' based on intervals.
90 void operator () (const IntervalType *x, IntervalType *y,
91 int dim, const spcCoord *coord, int subdiv) const;
92
93 /// Adjusts parameters if necessary after a successful computation
94 /// or after an unsuccessful computation of the graph of the map
95 /// at a specific subdivision level.
96 /// Returns true iff it is necessary to repeat the computation.
97 bool adjust (bool successful, int subdiv);
98
99 /// Gets a single line of information on optimization
100 /// of the computation of the map, so that it can be used
101 /// by maps created for the same and nearby parameter values.
102 std::string getOptInfo () const;
103
104 /// Uses a prevously saved line of information on optimization
105 /// of the computation of the map for the same or nearby
106 /// parameter values. The map object may be fed with several lines
107 /// and should interprete them to set up its optimization parameters.
108 void useOptInfo (const std::string &info);
109
110 /// Saves the internal parameters and other data of the map
111 /// to the mwData structure.
112 void saveInternals (chomp::multiwork::mwData &data) const;
113
114 /// Retrieves the internal paramters and other data of the map
115 /// from the mwData structure.
116 void loadInternals (chomp::multiwork::mwData &data);
117
118 /// Returns the time step, which is 1 for a map, or the time t
119 /// of integration in case of a time-t map of a flow.
120 /// This value may be different at each subdivision depth.
121 /// May return an approximate value, especially for flows.
122 virtual double getTimeStep (int subdiv) const;
123
124 /// Returns the name of the map.
125 /// This method should be replaced in derived classes.
126 virtual std::string name () const;
127
128private:
129 /// The left ends of the parameter intervals of the map.
130 double *leftParam;
131
132 /// The right ends of the parameter intervals of the map.
133 double *rightParam;
134
135 /// The number of parameters defined.
137
138 /// The copy constructor should not be used.
139 MapType (const MapType &);
140
141 /// The assignment operator should not be used.
142 MapType &operator = (const MapType &);
143
144}; /* class MapType */
145
146// --------------------------------------------------
147
148inline MapType::MapType (): leftParam (0), rightParam (0), nParam (0)
149{
150 return;
151} /* MapType::MapType */
152
154{
155 if (leftParam)
156 delete [] leftParam;
157 if (rightParam)
158 delete [] rightParam;
159 return;
160} /* MapType::~MapType */
161
162inline MapType::MapType (const MapType &)
163{
164 return;
165} /* MapType::MapType */
166
168{
169 return *this;
170} /* MapType::operator = */
171
172inline void MapType::setParam (const double *left, const double *right,
173 int n)
174{
175 if (n <= 0)
176 return;
177 if (n != nParam)
178 {
179 if (nParam)
180 {
181 delete [] leftParam;
182 delete [] rightParam;
183 }
184 leftParam = new double [n];
185 rightParam = new double [n];
186 nParam = n;
187 }
188 for (int i = 0; i < nParam; ++ i)
189 {
190 leftParam [i] = left [i];
191 rightParam [i] = right [i];
192 }
193 return;
194} /* MapType::setParam */
195
196inline const double &MapType::getLeftParam (int n) const
197{
198 if (!leftParam || (n >= nParam))
199 throw "Requested left parameter not defined.";
200 return leftParam [n];
201} /* MapType::getLeftParam */
202
203inline const double &MapType::getRightParam (int n) const
204{
205 if (!rightParam || (n >= nParam))
206 throw "Requested right parameter not defined.";
207 return rightParam [n];
208} /* MapType::getRightParam */
209
211 int dim, const spcCoord *coord, int subdiv) const
212{
213 double *buffer = new double [4 * dim];
214 double *xLeft = buffer;
215 double *xRight = buffer + dim;
216 for (int i = 0; i < dim; ++ i)
217 {
218 xLeft [i] = x [i]. leftBound ();
219 xRight [i] = x [i]. rightBound ();
220 }
221 double *yLeft = buffer + 2 * dim;
222 double *yRight = buffer + 3 * dim;
223 this -> compute (xLeft, xRight, yLeft, yRight, dim, coord, subdiv);
224 for (int i = 0; i < dim; ++ i)
225 y [i] = IntervalType (yLeft [i], yRight [i]);
226 delete [] buffer;
227 return;
228} /* MapType::operator () */
229
230inline bool MapType::adjust (bool, int)
231{
232 return false;
233} /* MapType::adjust */
234
235inline std::string MapType::getOptInfo () const
236{
237 return std::string ();
238} /* MapType::getOptInfo */
239
240inline void MapType::useOptInfo (const std::string &)
241{
242 return;
243} /* MapType::useOptInfo */
244
245inline void MapType::saveInternals (chomp::multiwork::mwData &data) const
246{
247 // save the number of parameters
248 data << nParam;
249
250 // save the parameter intervals
251 for (int i = 0; i < nParam; ++ i)
252 {
253 data << leftParam [i];
254 data << rightParam [i];
255 }
256
257 return;
258} /* MapType::saveInternals */
259
260inline void MapType::loadInternals (chomp::multiwork::mwData &data)
261{
262 // load the number of parameters
263 int n = 0;
264 data >> n;
265
266 // load the parameter intervals
267 double *left = (n > 0) ? new double [n] : 0;
268 double *right = (n > 0) ? new double [n] : 0;
269 for (int i = 0; i < n; ++ i)
270 {
271 data >> left [i];
272 data >> right [i];
273 }
274
275 // set the parameters
276 this -> setParam (left, right, n);
277
278 // forget the temporary arrays with the values of the parameters
279 if (left)
280 delete [] left;
281 if (right)
282 delete [] right;
283
284 return;
285} /* MapType::loadInternals */
286
287inline double MapType::getTimeStep (int /*subdiv*/) const
288{
289 return 1;
290} /* MapType::getTimeStep */
291
292inline std::string MapType::name () const
293{
294 return std::string ("map");
295} /* MapType::name */
296
297#endif // _CMGRAPHS_MAPTYPE_H_
298
This is an abstract class which defines the interface to other classes that describe maps for the use...
Definition: maptype.h:59
virtual void setParam(const double *left, const double *right, int n)
Sets the parameters to the given intervals defined by their left and right coordinates.
Definition: maptype.h:172
std::string getOptInfo() const
Gets a single line of information on optimization of the computation of the map, so that it can be us...
Definition: maptype.h:235
double * leftParam
The left ends of the parameter intervals of the map.
Definition: maptype.h:130
void useOptInfo(const std::string &info)
Uses a prevously saved line of information on optimization of the computation of the map for the same...
Definition: maptype.h:240
virtual double getTimeStep(int subdiv) const
Returns the time step, which is 1 for a map, or the time t of integration in case of a time-t map of ...
Definition: maptype.h:287
int nParam
The number of parameters defined.
Definition: maptype.h:136
bool adjust(bool successful, int subdiv)
Adjusts parameters if necessary after a successful computation or after an unsuccessful computation o...
Definition: maptype.h:230
virtual std::string name() const
Returns the name of the map.
Definition: maptype.h:292
void loadInternals(chomp::multiwork::mwData &data)
Retrieves the internal paramters and other data of the map from the mwData structure.
Definition: maptype.h:260
double * rightParam
The right ends of the parameter intervals of the map.
Definition: maptype.h:133
const double & getLeftParam(int n) const
Returns the left value of the given parameter.
Definition: maptype.h:196
virtual void compute(const double *xleft, const double *xright, double *yleft, double *yright, int dim, const spcCoord *coord, int subdiv) const =0
Computes the image of a box whose left and right coordinates are given.
virtual ~MapType()
The destructor of an object which describe a map.
Definition: maptype.h:153
MapType()
The default constructor of an object which describes a map.
Definition: maptype.h:148
MapType & operator=(const MapType &)
The assignment operator should not be used.
Definition: maptype.h:167
const double & getRightParam(int n) const
Returns the right value of the given parameter.
Definition: maptype.h:203
void operator()(const IntervalType *x, IntervalType *y, int dim, const spcCoord *coord, int subdiv) const
An interface to the function 'compute' based on intervals.
Definition: maptype.h:210
void saveInternals(chomp::multiwork::mwData &data) const
Saves the internal parameters and other data of the map to the mwData structure.
Definition: maptype.h:245
Data types for interval arithmetic.
capd::DInterval IntervalType
The type of an interval (from the CAPD library 2.9/3.0 beta).
Definition: typeintv.h:49
Customizable data types for the Conley-Morse graphs computation program.
int spcCoord
The type of coordinates of cubes in the phase space.
Definition: typespace.h:50