double starSystem::collectDust(double last_mass, double a, double e, double crit_mass, dust_bands* dust_band) { double mass_density, temp1, temp2, temp, temp_density, bandwidth, width, volume; temp = last_mass / (1.0 + last_mass); reduced_mass = pow(temp,(1.0 / 4.0)); r_inner = inner_effect_limit(a, e, reduced_mass); r_outer = outer_effect_limit(a, e, reduced_mass); if ((r_inner < 0.0)) r_inner = 0.0; if ((dust_band == NULL)) return(0.0); else { if ((dust_band->isDustPresent == FALSE)) temp_density = 0.0; else temp_density = dustDensity; if (((last_mass < crit_mass) || (dust_band->isGasPresent == FALSE))) mass_density = temp_density; else mass_density = K * temp_density / (1.0 + sqrt(crit_mass / last_mass) * (K - 1.0)); if (((dust_band->outerEdge <= r_inner) || (dust_band->innerEdge >= r_outer))) return(collectDust(last_mass,a,e,crit_mass, dust_band->next_band)); else { bandwidth = (r_outer - r_inner); temp1 = r_outer - dust_band->outerEdge; if (temp1 < 0.0) temp1 = 0.0; width = bandwidth - temp1; temp2 = dust_band->innerEdge - r_inner; if (temp2 < 0.0) temp2 = 0.0; width = width - temp2; temp = 4.0 * PI * pow(a,2.0) * reduced_mass * (1.0 - e * (temp1 - temp2) / bandwidth); volume = temp * width; return(volume * mass_density + collectDust(last_mass,a,e,crit_mass,dust_band->next_band)); } } }
planets * starSystem::distributePlanetaryMasses(double inner_dust, double outer_dust) { double a, e, mass, crit_mass, planetesimal_inner_bound, planetesimal_outer_bound; dust_bands* dust_head=new dust_bands(inner_dust,outer_dust); planets *planet_head=0; planets *&temp=planet_head; isDustLeft=TRUE; cloudEccentricity=0.2; planetesimal_inner_bound = innermost_planet(starMass); planetesimal_outer_bound = outermost_planet(starMass); while (isDustLeft) { a = random_number(planetesimal_inner_bound,planetesimal_outer_bound); e = random_eccentricity( ); mass = PROTOPLANET_MASS; #ifdef VERBOSE printf("Checking %10f AU: ",a); #endif if (dust_head->dustAvailable(inner_effect_limit(a, e, mass),outer_effect_limit(a, e, mass))) { #ifdef VERBOSE printf(".. Injecting protoplanet.\n"); #endif assert(a>0.0); dustDensity = DUST_DENSITY_COEFF * sqrt(starMass) * exp(-ALPHA * pow(a,(1.0 / N))); crit_mass = critical_limit(a,e,starLuminosity); accreteDust(dust_head,mass,a,e,crit_mass,planetesimal_inner_bound,planetesimal_outer_bound); if ((mass != 0.0) && (mass != PROTOPLANET_MASS)) coalescePlanetesimals(planet_head,dust_head,a,e,mass,crit_mass, planetesimal_inner_bound,planetesimal_outer_bound); #ifdef VERBOSE else printf(".. failed due to large neighbor.\n"); #endif } #ifdef VERBOSE else printf(".. failed.\n"); #endif } return temp; }
planet_pointer dist_planetary_masses(long double stell_mass_ratio, long double stell_luminosity_ratio, long double inner_dust, long double outer_dust, long double outer_planet_limit, long double dust_density_coeff, planet_pointer seed_system, int do_moons) { long double a; long double e; long double mass; long double dust_mass; long double gas_mass; long double crit_mass; long double planet_inner_bound; long double planet_outer_bound; planet_pointer seeds = seed_system; set_initial_conditions(inner_dust,outer_dust); planet_inner_bound = nearest_planet(stell_mass_ratio); if (outer_planet_limit == 0) planet_outer_bound = farthest_planet(stell_mass_ratio); else planet_outer_bound = outer_planet_limit; while (dust_left) { if (seeds != NULL) { a = seeds->a; e = seeds->e; seeds = seeds->next_planet; } else { a = random_number(planet_inner_bound,planet_outer_bound); e = random_eccentricity( ); } mass = PROTOPLANET_MASS; dust_mass = 0; gas_mass = 0; if (flag_verbose & 0x0200) fprintf (stderr, "Checking %Lg AU.\n",a); if (dust_available(inner_effect_limit(a, e, mass), outer_effect_limit(a, e, mass))) { if (flag_verbose & 0x0100) fprintf (stderr, "Injecting protoplanet at %Lg AU.\n", a); dust_density = dust_density_coeff * sqrt(stell_mass_ratio) * exp(-ALPHA * pow(a,(1.0 / N))); crit_mass = critical_limit(a,e,stell_luminosity_ratio); accrete_dust(&mass, &dust_mass, &gas_mass, a,e,crit_mass, planet_inner_bound, planet_outer_bound); dust_mass += PROTOPLANET_MASS; if (mass > PROTOPLANET_MASS) coalesce_planetesimals(a,e,mass,crit_mass, dust_mass, gas_mass, stell_luminosity_ratio, planet_inner_bound,planet_outer_bound, do_moons); else if (flag_verbose & 0x0100) fprintf (stderr, ".. failed due to large neighbor.\n"); } else if (flag_verbose & 0x0200) fprintf (stderr, ".. failed.\n"); } return(planet_head); }
long double collect_dust(long double last_mass, long double *new_dust, long double *new_gas, long double a, long double e, long double crit_mass, dust_pointer dust_band) { long double mass_density; long double temp1; long double temp2; long double temp; long double temp_density; long double bandwidth; long double width; long double volume; long double gas_density = 0.0; long double new_mass; long double next_mass; long double next_dust = 0; long double next_gas = 0; temp = last_mass / (1.0 + last_mass); reduced_mass = pow(temp,(1.0 / 4.0)); r_inner = inner_effect_limit(a, e, reduced_mass); r_outer = outer_effect_limit(a, e, reduced_mass); if ((r_inner < 0.0)) r_inner = 0.0; if (dust_band == NULL) return(0.0); else { if (dust_band->dust_present == FALSE) temp_density = 0.0; else temp_density = dust_density; if (((last_mass < crit_mass) || (dust_band->gas_present == FALSE))) mass_density = temp_density; else { mass_density = K * temp_density / (1.0 + sqrt(crit_mass / last_mass) * (K - 1.0)); gas_density = mass_density - temp_density; } if (((dust_band->outer_edge <= r_inner) || (dust_band->inner_edge >= r_outer))) { return(collect_dust(last_mass, new_dust, new_gas, a,e,crit_mass, dust_band->next_band)); } else { bandwidth = (r_outer - r_inner); temp1 = r_outer - dust_band->outer_edge; if (temp1 < 0.0) temp1 = 0.0; width = bandwidth - temp1; temp2 = dust_band->inner_edge - r_inner; if (temp2 < 0.0) temp2 = 0.0; width = width - temp2; temp = 4.0 * PI * pow(a,2.0) * reduced_mass * (1.0 - e * (temp1 - temp2) / bandwidth); volume = temp * width; new_mass = volume * mass_density; *new_gas = volume * gas_density; *new_dust = new_mass - *new_gas; next_mass = collect_dust(last_mass, &next_dust, &next_gas, a,e,crit_mass, dust_band->next_band); *new_gas = *new_gas + next_gas; *new_dust = *new_dust + next_dust; return(new_mass + next_mass); } } }