Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

proto_star_dyn.C

Go to the documentation of this file.
00001 //
00002 // proto_star.C
00003 //
00004 
00005 #include "proto_star.h"
00006 #include "dyn.h"
00007 #include "kepler.h"
00008 
00009 local void add_secondary(dyn* original, real mass_ratio)
00010 {
00011     dyn* primary = new dyn;
00012     dyn* secondary = new dyn;
00013 
00014     // Add new links.
00015 
00016     original->set_oldest_daughter(primary);
00017 
00018     primary->set_parent(original);
00019     secondary->set_parent(original);
00020 
00021     primary->set_younger_sister(secondary);
00022     secondary->set_elder_sister(primary);
00023 
00024     // Set new masses.
00025 
00026     primary->set_mass(original->get_mass());
00027     secondary->set_mass(mass_ratio*original->get_mass());
00028     original->inc_mass(secondary->get_mass());
00029 
00030     // Naming convention:
00031 
00032     if (original->get_name() == NULL)
00033         if (original->get_index() >= 0) {
00034             char tmp[64];
00035             sprintf(tmp, "%d", original->get_index());
00036             original->set_name(tmp);
00037         }
00038 
00039     if (original->get_name() != NULL) {
00040 
00041         // Label components "a" and "b".
00042 
00043         primary->set_name(original->get_name());
00044         secondary->set_name(original->get_name());
00045         strcat(primary->get_name(), "a");
00046         strcat(secondary->get_name(), "b");
00047 
00048         // Make standard CM name.
00049 
00050         char tmp[256];
00051         sprintf(tmp, "(%s,%s)", primary->get_name(), secondary->get_name());
00052         original->set_name(tmp);
00053     }
00054 }
00055 
00056 #if 0
00057 // To be worked out
00058 local void set_kepler_orientation_from_aml(kepler *k, 
00059                                            vector angular_momentum) {
00060 
00061     // normal unit vector is normlaized angular momentum vector
00062     vector n = angular_momentum/abs(angular_momentum);
00063 
00064     vector temp = vector(1, 0, 0);
00065     if (abs(n[0]) > .5) temp = vector(0, 1, 0); // temp is not parallel to n
00066     if (n[2] < 0) temp = -temp;
00067 
00068     vector b = n ^ temp;
00069     b /= abs(b);
00070     vector a = b ^ n;
00071     if (n[2] < 0) a = -a;       // Force (a, b) to be (x, y) for n = +/-z
00072     
00073     // Construct *random* unit vectors l and t perpendicular to each
00074     // other and to n (psi = 0 ==> periastron along a):
00075 
00076     vector l = cos(psi)*a + sin(psi)*b;
00077     vector t = n ^ l;
00078 
00079     k.set_orientation(l, t, n);
00080 }
00081 #endif
00082 
00083 local void add_dynamics(dyn* cm, real ecc, real energy) 
00084                 //      vector angular_momentum)
00085 {
00086     dyn* primary = cm->get_oldest_daughter();
00087     dyn* secondary = primary->get_younger_sister();
00088 
00089     real m_total = cm->get_mass();
00090     real m1 = primary->get_mass();
00091     real m2 = secondary->get_mass();
00092 
00093     PRC(m_total);PRC(m1);PRL(m2);
00094 
00095     // Set internal orbital elements:
00096 
00097     kepler k;
00098 
00099     real peri = 1; // Default value (unimportant unless ecc = 1).
00100     if (ecc == 1) peri = 0;
00101 
00102     // For now, binary phase is random.
00103 
00104     real mean_anomaly = randinter(-PI, PI);
00105 
00106     // Energies here are really binding energies (i.e. > 0 for a bound
00107     // orbit) per unit mass; kepler package expects energy < 0.
00108 
00109     energy = -energy;
00110 
00111     make_standard_kepler(k, 0, m_total, energy, ecc,
00112                          peri, mean_anomaly);
00113 
00114     //PRC(m_total);
00115     //PRC(energy);
00116     //PRL(ecc);
00117 
00118     //Orientation for protostar should not be random.
00119     //set_random_orientation(k);
00120     // ceate normal vector from angular momentum vector.
00121     
00122     //    set_kepler_orientation_from_aml(k, angular_momentum);
00123     int planar = 0; // ??
00124     set_random_orientation(k, planar);
00125 
00126     k.initialize_from_shape_and_phase();
00127 
00128     k.print_elements(cerr);
00129 
00130     // Set positions and velocities.
00131 
00132     primary->set_pos(-m2 * k.get_rel_pos() / m_total);
00133     primary->set_vel(-m2 * k.get_rel_vel() / m_total);
00134 
00135     cerr << primary->get_pos() << endl;
00136     cerr << primary->get_vel() << endl;
00137 
00138     secondary->set_pos(m1 * k.get_rel_pos() / m_total);
00139     secondary->set_vel(m1 * k.get_rel_vel() / m_total);
00140 
00141     cerr << secondary->get_pos() << endl;
00142     cerr << secondary->get_vel() << endl;
00143 }
00144 
00145 void proto_star::create_binary_from_proto_star() {
00146 
00147   //    star_transformation_story(Main_Sequence);
00148   //    new main_sequence(*this);
00149   //    return;
00150 
00151     real m_tot = core_mass;
00152     real q = randinter(0, 1);
00153     real mprim = m_tot/(1+q);
00154     real msec = mprim*q;
00155 
00156     //  angular_momentum = sqrt(2 * total_mass * periastron);
00157 
00158     real am = 1;
00159     //    real am = angular_momentum();
00160 
00161     real a_min   = pow(am, 2)/m_tot;
00162     real two_r   = 2*core_radius;
00163     real ecc_min = max(0., 1 - pow(am/(two_r*m_tot), 2));
00164     real ecc_max = min(1., 1 - two_r/a_min);
00165 
00166     //  angular_momentum = sqrt(abs(1 - eccentricity * eccentricity)
00167     //                           * total_mass * semi_major_axis);
00168 
00169     //  periastron = semi_major_axis * abs(1 - eccentricity);
00170     PRC(am);PRC(q);PRC(mprim);PRC(msec);PRC(a_min);PRL(two_r);    
00171     PRC(ecc_min);PRL(ecc_max);
00172     
00173 //    if ((!cnsts.parameters(proto_star_to_binary) ||
00174 //        get_use_dyn()) && (ecc_max<0 || ecc_min>=1)) {
00175 
00176        star_transformation_story(Main_Sequence);
00177        new main_sequence(*this);
00178        return;
00179 //    }
00180 
00181     star_transformation_story(Double);
00182 
00183     //Was squared
00184     ecc_min = sqrt(ecc_min);
00185 
00186     real ecc = sqrt(randinter(ecc_min, ecc_max));
00187     real sma = pow(am, 2) / (m_tot*(1-pow(ecc, 2)));
00188     real energy = 0.5 * (mprim+msec) / sma;
00189 
00190     dump(cerr, false);
00191     PRC(ecc);PRC(sma);PRL(energy);
00192 
00193     relative_mass = mprim;
00194     get_node()->set_mass(conv_m_star_to_dyn(mprim));
00195 
00196     add_secondary(dynamic_cast(dyn*, get_node()), q);
00197     cerr << "Secondary added"<<endl;
00198 
00199     addstar(((dyn*)get_node())->get_parent(), 0., Main_Sequence);
00200     cerr << "star added"<<endl;
00201 
00202     add_dynamics(dynamic_cast(dyn*, get_node()->get_parent()), 
00203                  ecc, energy);
00204 
00205     cerr << "dynamics double created" << endl;
00206 
00207     for_all_leaves(dyn, ((dyn*)get_node())->get_root(), si) {
00208       cerr << si->format_label() << " ";
00209       PRL(si->get_starbase()->get_element_type());
00210       cerr << "pos: " << si->get_pos() << endl;
00211     }
00212 }
00213 
00214 
00215 
00216 
00217 
00218 

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