00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 #include "boost/numeric/interval.hpp"
00071
00072
00073 #include <iomanip>
00074
00075
00076 #include "chomp/system/config.h"
00077 #include "chomp/system/textfile.h"
00078 #include "chomp/system/timeused.h"
00079 #include "chomp/system/arg.h"
00080
00081
00082 #include "maphenon.h"
00083 #include "covboxes.h"
00084 #include "attractor.h"
00085 #include "graph.h"
00086 #include "streams.h"
00087 #include "plotcover.h"
00088 #include "savecover.h"
00089
00090
00091
00092
00093
00094
00095
00096 const char *title = "\
00097 Finite Resolution Dynamics - computations for the Henon attractor.\n\
00098 Ver. 0.01, April 12, 2010. Copyright (C) 1997-2010 by Pawel Pilarczyk.\n\
00099 This is free software. No warranty. Consult 'license.txt' for details.";
00100
00101
00102 const char *helpinfo = "\
00103 This program accompanies the paper \"Finite resolution dynamics\"\n\
00104 by S. Luzzatto and P. Pilarczyk. It runs computations aiming at proving\n\
00105 that the Henon attractor is mixing at all resolutions > some epsilon.\n\
00106 Call this program with the following arguments:\n\
00107 -p N - the number of cover parts in each direction (must be given),\n\
00108 -b filename.bmp - a file to save a plot of the cover to (default: none),\n\
00109 -w N - the width of the BMP file (default: 1000 pixels),\n\
00110 -s filename.txt - a text file to save the actual cover to (def: none),\n\
00111 -h - to display this brief help information only and exit.\n\
00112 For more information consult the accompanying documentation (if available)\n\
00113 or ask the program's author at http://www.PawelPilarczyk.com/.";
00114
00115
00116
00117
00118
00119
00120
00121 template <class NumType>
00122 void henonAttractor (int parts, const char *bitmapFilename,
00123 int bitmapWidth, const char *saveFilename)
00124 {
00125 using chomp::homology::timeused;
00126
00127 sout << "--- Running computations for the Henon map. ---\n";
00128 sout << std::setprecision (12);
00129
00130
00131 typedef tMapHenon<NumType> theMapType;
00132
00133
00134 typedef tCoverBoxes<NumType> theCoverType;
00135
00136
00137 const int dim = 2;
00138
00139
00140 NumType aNumerator = 14;
00141 NumType aDenominator = 10;
00142 NumType bNumerator = 3;
00143 NumType bDenominator = 10;
00144 sout << "Parameters of the Henon map: a = " <<
00145 aNumerator / aDenominator <<
00146 ", b = " << bNumerator / bDenominator << ".\n";
00147
00148
00149 tMapHenon<NumType> function (aNumerator, aDenominator,
00150 bNumerator, bDenominator);
00151
00152
00153 NumType leftCorner [dim] = {-1.4, -0.5};
00154 NumType boxWidths [dim] = {2.8, 1.0};
00155 for (int i = 0; i < dim; ++ i)
00156 {
00157 sout << (i ? ") x (" : "Phase space box: (") <<
00158 leftCorner [i] << "," <<
00159 (leftCorner [i] + boxWidths [i]);
00160 }
00161 sout << ").\n";
00162
00163
00164 int partCounts [dim];
00165 partCounts [0] = parts;
00166 for (int i = 1; i < dim; ++ i)
00167 {
00168 partCounts [i] = static_cast<int>
00169 (parts * boxWidths [i] / boxWidths [0] + 0.5);
00170 }
00171 NumType *overlap = 0;
00172 double partsCount = 1;
00173 for (int i = 0; i < dim; ++ i)
00174 {
00175 sout << (i ? " x " : "Number of cover elements: ") <<
00176 partCounts [i];
00177 partsCount *= partCounts [i];
00178 }
00179 sout << " = " << partsCount << ".\n";
00180 double area1 = 1;
00181 for (int i = 0; i < dim; ++ i)
00182 {
00183 double size = static_cast<double> (boxWidths [i]) /
00184 partCounts [i];
00185 sout << (i ? " x " : "Size of each box: ") << size;
00186 area1 *= size;
00187 }
00188 sout << ".\n";
00189 sout << "Area of each box: " << area1 << ".\n";
00190
00191
00192 tCoverBoxes<NumType> cover (dim, leftCorner, boxWidths,
00193 partCounts, overlap);
00194
00195
00196 Graph graph;
00197
00198
00199
00200 NumType initialPoint [dim] = {0.61989426930989, 0.17586130934794};
00201
00202
00203
00204 int iterCount = 1000;
00205
00206
00207 int maxCoverSize = 0;
00208
00209
00210 sout << "Computing a cover of the attractor...\n";
00211 timeused coverTime;
00212 double maxDiameter2 = constructAttractor (function, cover, graph,
00213 initialPoint, iterCount, maxCoverSize);
00214 double percentage = static_cast<double> (cover. size ()) * 100 /
00215 partsCount;
00216 sout << "A cover consisting of " << cover. size () <<
00217 " elements (" << percentage << "%) constructed.\n";
00218 sout << "Computed in " << coverTime << ".\n";
00219 double area = 1;
00220 for (int i = 0; i < dim; ++ i)
00221 area *= boxWidths [i] / partCounts [i];
00222 area *= cover. size ();
00223 sout << "Approximate area of the cover: " << area << ".\n";
00224 sout << "Max square of the diameter of map images: " <<
00225 maxDiameter2 << ".\n";
00226 sout << "Approx. max diameter of map images: " <<
00227 std::sqrt (maxDiameter2) << ".\n";
00228 sout << "The map graph has " << graph. countEdges () <<
00229 " edges.\n";
00230
00231
00232 if (bitmapFilename)
00233 {
00234 sout << "Plotting the computed cover in a "
00235 "black-and-white bitmap image...\n";
00236 plotCover (cover, bitmapFilename, bitmapWidth);
00237 }
00238
00239
00240 if (saveFilename)
00241 {
00242 sout << "Saving the computed cover to a text file...\n";
00243 saveCover (cover, saveFilename);
00244 }
00245
00246
00247 sout << "Releasing the cover from the memory...\n";
00248 timeused forgetTime;
00249 cover. forget ();
00250 chomp::homology::PointBase::forget ();
00251 sout << "Memory released in " << forgetTime << ".\n";
00252
00253
00254 sout << "Checking if the graph is strongly connected...\n";
00255 timeused strConnTime;
00256 if (graph. checkStronglyConnected ())
00257 sout << "Yes! The graph is strongly connected.\n";
00258 else
00259 throw "The constructed graph is not strongly connected.\n";
00260 sout << "Verified in " << strConnTime << ".\n";
00261
00262
00263 sout << "Checking if the graph is aperiodic...\n";
00264 timeused aperTime;
00265 if (graph. checkAperiodic ())
00266 sout << "Good! The graph is aperiodic.\n";
00267 else
00268 throw "The constructed graph is not aperiodic.\n";
00269 sout << "Verified in " << aperTime << ".\n";
00270
00271 sout << "--- The computations completed successfully. ---\n";
00272 return;
00273 }
00274
00275
00276
00277
00278
00279
00280
00281
00282 int main (int argc, char *argv [])
00283 {
00284 using namespace chomp::homology;
00285
00286
00287 program_time = "Aborted after";
00288
00289
00290 int parts = 0;
00291 char *bitmapFilename = 0;
00292 int bitmapWidth = 1000;
00293 char *saveFilename = 0;
00294
00295
00296 arguments a;
00297 arg (a, "p", parts);
00298 arg (a, "b", bitmapFilename);
00299 arg (a, "w", bitmapWidth);
00300 arg (a, "s", saveFilename);
00301 arghelp (a);
00302
00303 argstreamprepare (a);
00304 int argresult = a. analyze (argc, argv);
00305 argstreamset ();
00306
00307
00308 if (argresult >= 0)
00309 sout << title << '\n';
00310
00311
00312 if (argresult < 0)
00313 {
00314 sout << "Call with '--help' for help.\n";
00315 return 2;
00316 }
00317
00318
00319 if ((argresult > 0) || (parts <= 0))
00320 {
00321 sout << helpinfo << '\n';
00322 return 1;
00323 }
00324
00325
00326 try
00327 {
00328
00329 program_time = "Aborted after:";
00330
00331
00332 henonAttractor<double> (parts, bitmapFilename, bitmapWidth,
00333 saveFilename);
00334
00335
00336 program_time = "Total time used:";
00337 program_time = 1;
00338
00339
00340 return 0;
00341 }
00342 catch (const char *msg)
00343 {
00344 sout << "ERROR: " << msg << '\n';
00345 return -1;
00346 }
00347 catch (const std::exception &e)
00348 {
00349 sout << "ERROR: " << e. what () << '\n';
00350 return -1;
00351 }
00352 catch (...)
00353 {
00354 sout << "ABORT: An unknown error occurred.\n";
00355 return -1;
00356 }
00357 return 0;
00358 }
00359