Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

_dyn_slow.C

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00011 //
00012 //  _dyn_slow.C: functions related to slow binary motion.  Manipulations
00013 //               are defined for the _dyn_ class, but are presently used
00014 //               only in kira, for hdyn objects.
00015 //
00016 //.............................................................................
00017 //    version 1:  Jul 1999   Steve McMillan
00018 //    version 2:
00019 //.............................................................................
00020 //
00021 // Externally visible functions:
00022 //
00023 //      void _dyn_::create_slow
00024 //      void _dyn_::delete_slow
00025 //      void _dyn_::extend_slow
00026 //
00027 //      void _dyn_::check_slow_perturbed
00028 //      slow_perturbed *_dyn_::find_slow_perturbed
00029 //      slow_perturbed *_dyn_::add_slow_perturbed
00030 //      void _dyn_::remove_slow_perturbed
00031 //      int _dyn_::count_slow_perturbed
00032 //
00033 // Note that there is a great deal of overlap in coding between the functions
00034 // in each group.
00035 
00036 #include "_dyn_.h"
00037 
00038 void _dyn_::create_slow(int k)          // default = 1
00039 {
00040     if (!is_low_level_node()) {
00041         warning("create_slow: not a low-level node");
00042         return;
00043     }
00044 
00045     slow = new slow_binary(k);
00046 
00047     slow->set_t_init(get_time());
00048     slow->set_t_apo(get_time());
00049 
00050     // New dtau is the old timestep.
00051 
00052     slow->set_dtau(timestep);
00053     timestep *= k;
00054 
00055     // Correct the non-2-body portion of the acceleration.
00056     // (Assume binaries, not multiples, for now...)
00057 
00058     _dyn_ *s = get_younger_sister();
00059 
00060     if (!s) {
00061 
00062         warning("create_slow: no younger sister");
00063 
00064     } else {
00065 
00066         real m2 = get_binary_sister()->mass;
00067         vector sep = pos * (1 + mass/m2);
00068         real r2 = sep*sep;
00069         vector a2 = -m2*sep / (r2*sqrt(r2));
00070 
00071         acc = a2 + (acc - a2) * k;
00072         old_acc = acc;                  // OK because we do this between steps
00073 
00074         // Update the younger sister.
00075 
00076         s->slow = slow;
00077         real factor = -s->mass / mass;
00078         s->acc = factor * acc;
00079         s->old_acc = s->acc;
00080 
00081     }
00082 }
00083 
00084 void _dyn_::delete_slow()
00085 {
00086     if (!slow) {
00087 
00088         cerr << "warning: delete_slow: " << format_label()
00089              << " is not a slow binary" << endl;
00090         return;
00091 
00092     } else {
00093 
00094         int k = get_kappa();
00095 
00096         timestep /= k;
00097 
00098         // Correct the non-2-body portion of the acceleration.
00099         // (Assume binaries, not multiples, for now...)
00100 
00101         // Assume that this function is invoked from the elder sister
00102         // of a binary.
00103 
00104         _dyn_ *s = get_younger_sister();
00105 
00106         if (!s) {
00107 
00108             warning("delete_slow: no younger sister...");
00109 
00110         } else {
00111 
00112             real m2 = s->mass;
00113             vector sep = pos * (1 + mass/m2);
00114             real r2 = sep*sep;
00115             vector a2 = -m2*sep / (r2*sqrt(r2));
00116 
00117             acc = a2 + (acc - a2) / k;
00118             old_acc = acc;              // OK because we do this between steps
00119 
00120             // Update the sister.
00121 
00122             real factor = -s->mass / mass;
00123             s->acc = factor * acc;
00124             s->old_acc = s->acc;
00125 
00126         }
00127 
00128         delete slow;
00129 
00130         slow = NULL;
00131         if (s) s->slow = NULL;
00132     }
00133 }
00134 
00135 void _dyn_::extend_slow(int k)          // no default
00136 {
00137     if (!slow) {
00138 
00139         cerr << "warning: extend_slow: " << format_label()
00140              << " is not a slow binary" << endl;
00141         return;
00142 
00143     } else {
00144 
00145         real k_fac = ((real)k) / get_kappa();
00146         slow->set_kappa(k);
00147 
00148         slow->set_t_init(get_time());
00149         slow->set_t_apo(get_time());
00150 
00151         // Must reset tau to zero; dtau is unchanged...
00152 
00153         slow->set_tau(0);
00154         slow->init_tau_pred();
00155 
00156         timestep *= k_fac;
00157 
00158         // Correct the non-2-body portion of the acceleration.
00159         // (Assume binaries, not multiples, for now...)
00160 
00161         _dyn_ *s = get_younger_sister();
00162 
00163         if (!s) {
00164 
00165             warning("extend_slow: no younger sister");
00166 
00167         } else {
00168 
00169             real m2 = get_binary_sister()->mass;
00170             vector sep = pos * (1 + mass/m2);
00171             real r2 = sep*sep;
00172             vector a2 = -m2*sep / (r2*sqrt(r2));
00173 
00174             acc = a2 + (acc - a2) * k_fac;
00175             old_acc = acc;              // OK because we do this between steps
00176 
00177             // Update the younger sister.
00178 
00179             real factor = -s->mass / mass;
00180             s->acc = factor * acc;
00181             s->old_acc = s->acc;
00182 
00183         }
00184     }
00185 }
00186 
00187 // Member functions relating to the slow_perturbed lists.
00188 
00189 bool is_valid_slow(_dyn_ *pert_node)
00190 {
00191     if (!pert_node
00192         || !pert_node->is_valid()
00193         || !pert_node->get_oldest_daughter()
00194         || !pert_node->get_oldest_daughter()->get_slow())
00195         return false;
00196     else
00197         return true;
00198 }
00199 
00200 typedef slow_perturbed* sp_ptr;
00201 
00202 local void delete_slow_perturbed(_dyn_ *b,
00203                                  sp_ptr &s,
00204                                  slow_perturbed *prev,
00205                                  sp_ptr &sp,
00206                                  bool verbose)
00207 {
00208     // Remove entry s from the slow_perturbed list of b.
00209 
00210     slow_perturbed *next = s->get_next();
00211 
00212     if (prev)
00213         prev->set_next(next);
00214     else
00215         sp = next;
00216 
00217     if (verbose) {
00218         cerr << "deleted " << s->get_node()->format_label();
00219         cerr << " from slow_perturbed list of " << b->format_label()
00220              << " at time " << b->get_system_time()
00221              << endl;
00222     }
00223 
00224     s->set_next(NULL);          // so we don't delete the entire chain
00225     delete s;
00226     s = next;
00227 }
00228 
00229 void _dyn_::check_slow_perturbed(bool verbose)          // default = false
00230 {
00231     slow_perturbed *s = sp, *prev = NULL;
00232     while (s) {
00233         _dyn_ *pert_node = s->get_node();
00234 
00235         // Apply basic checks:
00236 
00237         if (!is_valid_slow(pert_node))
00238 
00239             delete_slow_perturbed(this, s, prev, sp, verbose);
00240 
00241         else {
00242 
00243             prev = s;
00244             s = s->get_next();
00245 
00246         }
00247     }
00248 }
00249 
00250 slow_perturbed* _dyn_::find_slow_perturbed(_dyn_ *n,      // checks, too...
00251                                            bool verbose)  // default = false
00252 {
00253     slow_perturbed *s = sp, *prev = NULL;
00254     while (s) {
00255         _dyn_ *pert_node = s->get_node();
00256 
00257         // Apply basic checks:
00258 
00259         if (!is_valid_slow(pert_node))
00260 
00261             delete_slow_perturbed(this, s, prev, sp, verbose);
00262 
00263         else {
00264 
00265             if (pert_node == n) return s;
00266 
00267             prev = s;
00268             s = s->get_next();
00269 
00270         }
00271     }
00272     return NULL;
00273 }
00274 
00275 slow_perturbed* _dyn_::add_slow_perturbed(_dyn_ *n,
00276                                           bool verbose)   // default = false
00277 {
00278     if (!is_valid_slow(n)) return NULL;
00279 
00280     slow_perturbed *s = sp, *prev = NULL;
00281     while (s) {
00282         if (s->get_node() == n) return s;
00283         prev = s;
00284         s = s->get_next();
00285     }
00286 
00287     s = new slow_perturbed();
00288     s->set_node(n);
00289     s->set_kappa(n->get_oldest_daughter()->get_kappa());
00290 
00291     if (prev)
00292         prev->set_next(s);
00293     else
00294         sp = s;
00295 
00296     if (verbose) {
00297         cerr << "added " << n->format_label();
00298         cerr << " to slow_perturbed list of " << format_label()
00299              << " at time " << get_system_time()
00300              << endl;
00301     }
00302 
00303     return s;
00304 }
00305         
00306 void _dyn_::remove_slow_perturbed(_dyn_ *n,
00307                                   bool verbose)         // default = false
00308 {
00309     slow_perturbed *s = sp, *prev = NULL;
00310     while (s) {
00311 
00312         if (s->get_node() == n) {
00313             delete_slow_perturbed(this, s, prev, sp, verbose);
00314             return;
00315         }
00316 
00317         prev = s;
00318         s = s->get_next();
00319     }
00320 }
00321 
00322 bool _dyn_::copy_slow_perturbed(_dyn_ *to,
00323                                 bool overwrite,         // default = false
00324                                 bool verbose)           // default = false
00325 {
00326     // Copy the slow_perturbed list from this node to another.
00327     // Optionally delete any existing slow_perturbed list before overwriting.
00328 
00329     if (!sp) return false;
00330 
00331     if (to->get_sp()) {
00332         if (overwrite) {
00333             if (verbose) cerr << "copy_slow_perturbed: "
00334                               << "deleting existing slow_perturbed list"
00335                               << endl;
00336             delete to->get_sp();
00337         } else {
00338             if (verbose) cerr << "copy_slow_perturbed: "
00339                               << "adding to existing slow_perturbed list"
00340                               << endl;
00341         }
00342     }
00343 
00344     slow_perturbed *s = sp;
00345     while (s) {
00346         to->add_slow_perturbed(s->get_node(), verbose);
00347         s = s->get_next();
00348     }
00349 
00350     return true;
00351 }
00352 
00353 void _dyn_::dump_slow_perturbed(char *string)           // default = ""
00354 {
00355     // Dump all slow_perturber data.
00356 
00357     if (!sp) return;
00358 
00359     cerr << string
00360          << "dump slow_perturbed list for "
00361          << format_label() << " at time " << get_system_time() << ":"
00362          << endl;
00363 
00364     slow_perturbed *s = sp;
00365     int n = 0;
00366     while (s) {
00367         n++;
00368 
00369         cerr << string; PRC(n); PRL(s);
00370         cerr << string; PRI(4); PRC(s->get_node());
00371                         PRL(s->get_node()->format_label());
00372         cerr << string; PRI(4); PRL(s->get_kappa());
00373         cerr << string; PRI(4); PRL(s->get_next());
00374 
00375         s = s->get_next();
00376     }
00377 }
00378 
00379 void _dyn_::print_slow_perturbed()      // print the slow_perturbed node list
00380 {
00381     if (!sp) return;
00382 
00383     cerr << "slow_perturbed list of " << format_label() << ":"
00384          << endl;
00385 
00386     slow_perturbed *s = sp;
00387     while (s) {
00388         cerr << " " << s->get_node()->format_label();
00389         s = s->get_next();
00390     }
00391     cerr << endl;
00392 }
00393 
00394 int _dyn_::count_slow_perturbed()
00395 {
00396     slow_perturbed *s = sp;
00397     int n = 0;
00398     while (s) {
00399         n++;
00400         s = s->get_next();
00401     }
00402     return n;
00403 }
00404         

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