The Finite Resolution Dynamics Software
runhenon.cpp
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// @file runhenon.cpp
4 ///
5 /// The main computations for the Henon attractor.
6 /// This program runs rigorous numerical computations aimed at proving
7 /// that an attractor for the given dynamical system is mixing
8 /// at some finite resolution.
9 /// This program accompanies the paper "Finite resolution dynamics"
10 /// by S. Luzzatto and P. Pilarczyk, and follows the algorithms
11 /// introduced there.
12 ///
13 /// @author Pawel Pilarczyk
14 ///
15 /////////////////////////////////////////////////////////////////////////////
16 ///
17 /// @mainpage The Finite Resolution Dynamics Software
18 ///
19 /// \section intro Introduction
20 ///
21 /// This website contains the documentation of software designed and
22 /// programmed by Pawel Pilarczyk which accompanies the paper
23 /// <em>Finite resolution dynamics</em> by S. Luzzatto and P. Pilarczyk.
24 ///
25 /// \section License
26 ///
27 /// In order to make this software freely available for wide audience,
28 /// it is provided here under the terms of the GNU General Public License,
29 /// version 2 or any later version. Please, see the
30 /// <a href="http://www.gnu.org/copyleft/gpl.html">GNU website</a>
31 /// for details.
32 ///
33 /// \section browsing Browsing
34 ///
35 /// Although a lot of effort was put into making this software as transparent
36 /// and clear as possible, and to keep this documentation complete,
37 /// I am sure that there is a lot of important information
38 /// that might have been included here but was not.
39 /// Therefore, this documentation was generated in such a way
40 /// that it contains the source code which can be browsed and checked
41 /// in case of any doubt.
42 ///
43 /// So, what are you waiting for? Dive and read. Have a happy browsing!
44 ///
45 /// Pawel Pilarczyk
46 ///
47 /////////////////////////////////////////////////////////////////////////////
48 
49 // Copyright (C) 1997-2010 by Pawel Pilarczyk.
50 //
51 // This file is part of my research software package. This is free software;
52 // you can redistribute it and/or modify it under the terms of the GNU
53 // General Public License as published by the Free Software Foundation;
54 // either version 2 of the License, or (at your option) any later version.
55 //
56 // This software is distributed in the hope that it will be useful,
57 // but WITHOUT ANY WARRANTY; without even the implied warranty of
58 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59 // GNU General Public License for more details.
60 //
61 // You should have received a copy of the GNU General Public License along
62 // with this software; see the file "license.txt". If not, write to the
63 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
64 // MA 02111-1307, USA.
65 
66 // Started on December 22, 2008. Last revision: April 12, 2010.
67 
68 
69 // BOOST (this header must be included first)
70 #include "boost/numeric/interval.hpp"
71 
72 // include some standard C++ header files
73 #include <iomanip>
74 
75 // include some headers from the CHomP library
76 #include "chomp/system/config.h"
77 #include "chomp/system/textfile.h"
78 #include "chomp/system/timeused.h"
79 #include "chomp/system/arg.h"
80 
81 // include local header files
82 #include "maphenon.h"
83 #include "covboxes.h"
84 #include "attractor.h"
85 #include "graph.h"
86 #include "streams.h"
87 #include "plotcover.h"
88 #include "savecover.h"
89 
90 
91 // --------------------------------------------------
92 // -------------------- OVERTURE --------------------
93 // --------------------------------------------------
94 
95 /// The title of the program with brief licensing information.
96 const char *title = "\
97 Finite Resolution Dynamics - computations for the Henon attractor.\n\
98 Ver. 0.01, April 12, 2010. Copyright (C) 1997-2010 by Pawel Pilarczyk.\n\
99 This is free software. No warranty. Consult 'license.txt' for details.";
100 
101 /// Short help information about the program's usage.
102 const char *helpinfo = "\
103 This program accompanies the paper \"Finite resolution dynamics\"\n\
104 by S. Luzzatto and P. Pilarczyk. It runs computations aiming at proving\n\
105 that the Henon attractor is mixing at all resolutions > some epsilon.\n\
106 Call this program with the following arguments:\n\
107 -p N - the number of cover parts in each direction (must be given),\n\
108 -b filename.bmp - a file to save a plot of the cover to (default: none),\n\
109 -w N - the width of the BMP file (default: 1000 pixels),\n\
110 -s filename.txt - a text file to save the actual cover to (def: none),\n\
111 -h - to display this brief help information only and exit.\n\
112 For more information consult the accompanying documentation (if available)\n\
113 or ask the program's author at http://www.PawelPilarczyk.com/.";
114 
115 
116 // --------------------------------------------------
117 // ---------------- HENON ATTRACTOR -----------------
118 // --------------------------------------------------
119 
120 /// Runs the computations for the Henon attractor.
121 template <class NumType>
122 void henonAttractor (int parts, const char *bitmapFilename,
123  int bitmapWidth, const char *saveFilename)
124 {
125  using chomp::homology::timeused;
126 
127  sout << "--- Running computations for the Henon map. ---\n";
128  sout << std::setprecision (12);
129 
130  // define the type of the map to be used for the computations
131  typedef tMapHenon<NumType> theMapType;
132 
133  // define the type of the map to be used for the computations
134  typedef tCoverBoxes<NumType> theCoverType;
135 
136  // set the dimension of the phase space
137  const int dim = 2;
138 
139  // prepare the parameters of the Henon map
140  NumType aNumerator = 14;
141  NumType aDenominator = 10;
142  NumType bNumerator = 3;
143  NumType bDenominator = 10;
144  sout << "Parameters of the Henon map: a = " <<
145  aNumerator / aDenominator <<
146  ", b = " << bNumerator / bDenominator << ".\n";
147 
148  // create a dynamical system generator
149  tMapHenon<NumType> function (aNumerator, aDenominator,
150  bNumerator, bDenominator);
151 
152  // prepare the phase space box to cover
153  NumType leftCorner [dim] = {-1.4, -0.5}; //{-1.3, -0.4};
154  NumType boxWidths [dim] = {2.8, 1.0}; //{2.6, 0.8};
155  for (int i = 0; i < dim; ++ i)
156  {
157  sout << (i ? ") x (" : "Phase space box: (") <<
158  leftCorner [i] << "," <<
159  (leftCorner [i] + boxWidths [i]);
160  }
161  sout << ").\n";
162 
163  // prepare the number of elements in each direction
164  int partCounts [dim];
165  partCounts [0] = parts;
166  for (int i = 1; i < dim; ++ i)
167  {
168  partCounts [i] = static_cast<int>
169  (parts * boxWidths [i] / boxWidths [0] + 0.5);
170  }
171  NumType *overlap = 0;
172  double partsCount = 1;
173  for (int i = 0; i < dim; ++ i)
174  {
175  sout << (i ? " x " : "Number of cover elements: ") <<
176  partCounts [i];
177  partsCount *= partCounts [i];
178  }
179  sout << " = " << partsCount << ".\n";
180  double area1 = 1;
181  for (int i = 0; i < dim; ++ i)
182  {
183  double size = static_cast<double> (boxWidths [i]) /
184  partCounts [i];
185  sout << (i ? " x " : "Size of each box: ") << size;
186  area1 *= size;
187  }
188  sout << ".\n";
189  sout << "Area of each box: " << area1 << ".\n";
190 
191  // create an initially empty cover
192  tCoverBoxes<NumType> cover (dim, leftCorner, boxWidths,
193  partCounts, overlap);
194 
195  // prepare an empty directed graph to store the map on the attractor
196  Graph graph;
197 
198  // set up an initial point that is supposedly in the attraction
199  // basin of the expected attractor
200  NumType initialPoint [dim] = {0.61989426930989, 0.17586130934794};
201 
202  // set the number of iterations that need to be done
203  // until the point gets close enough to the attractor
204  int iterCount = 1000;
205 
206  // define the maximal allowed cover size
207  int maxCoverSize = 0;
208 
209  // construct a cover of the attractor
210  sout << "Computing a cover of the attractor...\n";
211  timeused coverTime;
212  double maxDiameter2 = constructAttractor (function, cover, graph,
213  initialPoint, iterCount, maxCoverSize);
214  double percentage = static_cast<double> (cover. size ()) * 100 /
215  partsCount;
216  sout << "A cover consisting of " << cover. size () <<
217  " elements (" << percentage << "%) constructed.\n";
218  sout << "Computed in " << coverTime << ".\n";
219  double area = 1;
220  for (int i = 0; i < dim; ++ i)
221  area *= boxWidths [i] / partCounts [i];
222  area *= cover. size ();
223  sout << "Approximate area of the cover: " << area << ".\n";
224  sout << "Max square of the diameter of map images: " <<
225  maxDiameter2 << ".\n";
226  sout << "Approx. max diameter of map images: " <<
227  std::sqrt (maxDiameter2) << ".\n";
228  sout << "The map graph has " << graph. countEdges () <<
229  " edges.\n";
230 
231  // plot the resulting cover in a bitmap image file
232  if (bitmapFilename)
233  {
234  sout << "Plotting the computed cover in a "
235  "black-and-white bitmap image...\n";
236  plotCover (cover, bitmapFilename, bitmapWidth);
237  }
238 
239  // save the computed cover to a text file
240  if (saveFilename)
241  {
242  sout << "Saving the computed cover to a text file...\n";
243  saveCover (cover, saveFilename);
244  }
245 
246  // clean up the cover and cubical sets from the memory
247  sout << "Releasing the cover from the memory...\n";
248  timeused forgetTime;
249  cover. forget ();
250  chomp::homology::PointBase::forget ();
251  sout << "Memory released in " << forgetTime << ".\n";
252 
253  // verify if the constructed graph is strongly connected
254  sout << "Checking if the graph is strongly connected...\n";
255  timeused strConnTime;
256  if (graph. checkStronglyConnected ())
257  sout << "Yes! The graph is strongly connected.\n";
258  else
259  throw "The constructed graph is not strongly connected.\n";
260  sout << "Verified in " << strConnTime << ".\n";
261 
262  // verify if the constructed graph is aperiodic
263  sout << "Checking if the graph is aperiodic...\n";
264  timeused aperTime;
265  if (graph. checkAperiodic ())
266  sout << "Good! The graph is aperiodic.\n";
267  else
268  throw "The constructed graph is not aperiodic.\n";
269  sout << "Verified in " << aperTime << ".\n";
270 
271  sout << "--- The computations completed successfully. ---\n";
272  return;
273 } /* henonAttractor */
274 
275 
276 // --------------------------------------------------
277 // ---------------------- MAIN ----------------------
278 // --------------------------------------------------
279 
280 /// The main function of the program.
281 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
282 int main (int argc, char *argv [])
283 {
284  using namespace chomp::homology;
285 
286  // turn on a message that will appear if the program does not finish
287  program_time = "Aborted after";
288 
289  // prepare user-configurable data
290  int parts = 0;
291  char *bitmapFilename = 0;
292  int bitmapWidth = 1000;
293  char *saveFilename = 0;
294 
295  // analyze the command line
296  arguments a;
297  arg (a, "p", parts);
298  arg (a, "b", bitmapFilename);
299  arg (a, "w", bitmapWidth);
300  arg (a, "s", saveFilename);
301  arghelp (a);
302 
303  argstreamprepare (a);
304  int argresult = a. analyze (argc, argv);
305  argstreamset ();
306 
307  // show the program's title
308  if (argresult >= 0)
309  sout << title << '\n';
310 
311  // if something was incorrect, show an additional message and exit
312  if (argresult < 0)
313  {
314  sout << "Call with '--help' for help.\n";
315  return 2;
316  }
317 
318  // if help requested or no part number defined, show help information
319  if ((argresult > 0) || (parts <= 0))
320  {
321  sout << helpinfo << '\n';
322  return 1;
323  }
324 
325  // try running the main function and catch an error message if thrown
326  try
327  {
328  // set an appropriate program time message
329  program_time = "Aborted after:";
330 
331  // run the main procedure
332  henonAttractor<double> (parts, bitmapFilename, bitmapWidth,
333  saveFilename);
334 
335  // set an appropriate program time message
336  program_time = "Total time used:";
337  program_time = 1;
338 
339  // finalize
340  return 0;
341  }
342  catch (const char *msg)
343  {
344  sout << "ERROR: " << msg << '\n';
345  return -1;
346  }
347  catch (const std::exception &e)
348  {
349  sout << "ERROR: " << e. what () << '\n';
350  return -1;
351  }
352  catch (...)
353  {
354  sout << "ABORT: An unknown error occurred.\n";
355  return -1;
356  }
357  return 0;
358 } /* main */
359 
Saving a cover to a file.
Various output streams for the program.
The Henon map.
Definition: maphenon.h:54
const char * helpinfo
Short help information about the program&#39;s usage.
Definition: runhenon.cpp:102
A cover of a subset in R^n consisting of open boxes.
Definition: covboxes.h:73
A box cover type.
void plotCover(const CoverType &cover, const char *filename, int width)
Definition: plotcover.h:50
Plotting a cover in a bitmap image file.
A directed graph class with some algorithms built-in.
Definition: graph.h:63
int main(int argc, char *argv [])
The main function of the program.
Definition: runhenon.cpp:282
void henonAttractor(int parts, const char *bitmapFilename, int bitmapWidth, const char *saveFilename)
Runs the computations for the Henon attractor.
Definition: runhenon.cpp:122
void saveCover(const tCoverBoxes< double > &cover, const char *filename)
Saves the given cover to a text file.
Definition: savecover.h:94
The Henon map.
A directed graph class and some algorithms.
Construction of a cover of an attractor.
const char * title
The title of the program with brief licensing information.
Definition: runhenon.cpp:96
double constructAttractor(const MapType &function, CoverType &cover, GraphType &graph, NumArray initialPoint, int iterCount, int maxCoverSize)
Constructs a cover of an attractor for a given dynamical system.
Definition: attractor.h:101