Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

dyndiff.C

Go to the documentation of this file.
00001 
00006 
00007 //.............................................................................
00008 //    version 1:  Nov 1993   Piet Hut              email: piet@guinness.ias.edu
00009 //                           Institute for Advanced Study, Princeton, NJ, USA
00010 //.............................................................................
00011 //  non-local function: 
00012 //    dyndiff
00013 //.............................................................................
00014 
00015 #include "dyn.h"
00016 
00017 #ifdef TOOLBOX
00018 
00019 //-----------------------------------------------------------------------------
00020 //  dyndiff  --  determine the rms difference between the 6N coordinates of
00021 //               two N-body systems
00022 //               NOTE: simple version for flat tree only.
00023 //-----------------------------------------------------------------------------
00024 
00025 real  dyndiff(dyn * b1, dyn * b2, bool r_flag)
00026 {
00027     //  quick fix to determine  n  for a flat tree:
00028 
00029     int  n1, n2;
00030     dyn * bi1;
00031     dyn * bi2;
00032     for (n1 = 0, bi1 = b1->get_oldest_daughter(); bi1 != NULL;
00033          bi1 = bi1->get_younger_sister())
00034         n1++;
00035     for (n2 = 0, bi2 = b2->get_oldest_daughter(); bi2 != NULL;
00036          bi2 = bi2->get_younger_sister())
00037         n2++;
00038     if (n1 != n2)
00039         {
00040         cerr << "dyndiff: N1 = " << n1 << " != N2 = " << n2 << endl;
00041         exit(1);
00042         }
00043 
00044     real sum_sq_diff = 0;     // sum of the squares of the 6N differences
00045 
00046     for (bi1 = b1->get_oldest_daughter(), bi2 = b2->get_oldest_daughter();
00047          bi1 != NULL;
00048          bi1 = bi1->get_younger_sister(), bi2 = bi2->get_younger_sister())
00049         {
00050         vector  dr = bi1->get_pos() - bi2->get_pos();
00051         sum_sq_diff += dr*dr;
00052         
00053         if (!r_flag)
00054             {
00055             vector  dv = bi1->get_vel() - bi2->get_vel();
00056             sum_sq_diff += dv*dv;
00057             }
00058         }
00059 
00060     if (r_flag)
00061         return sqrt(sum_sq_diff / (3 * n1));
00062     else
00063         return sqrt(sum_sq_diff / (6 * n1));
00064 }
00065 
00066 main(int argc, char ** argv)
00067 {
00068     bool  r_flag = FALSE;      // if TRUE: check only spatial differences
00069 
00070     check_help();
00071 
00072     extern char *poptarg;
00073     int c;
00074     char* param_string = "r";
00075 
00076     while ((c = pgetopt(argc, argv, param_string)) != -1)
00077         switch(c) {
00078 
00079             case 'r': r_flag = TRUE;
00080                       break;
00081             case '?': params_to_usage(cerr, argv[0], param_string);
00082                       get_help();
00083                       exit(1);
00084         }            
00085 
00086     dyn * b1;
00087     dyn * b2;
00088     b1 = get_dyn(cin);
00089     b2 = get_dyn(cin);
00090 
00091     real  rmsdiff = dyndiff(b1, b2, r_flag);
00092 
00093     if (r_flag)
00094         cout << "  rms configuration space differences per coordinate:   "
00095              << rmsdiff << endl;
00096     else
00097         cout << "  rms phasespace differences per coordinate:   "
00098              << rmsdiff << endl;
00099 }
00100 
00101 #endif
00102 
00103 // endof: dyndiff.C

Generated at Sun Feb 24 09:56:59 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001