def __init__(self,
              output_path,
              center=True,
              centering_resolution=1e5,
              centering_delta=1e7,
              number_expected_bodies=1,
              center_on_target_iron=False,
              plot=False,
              relative_velocity=True,
              center_plot=False):
     self.centering_resolution = centering_resolution
     self.centering_delta = centering_delta
     self.num_bodies = number_expected_bodies
     self.__relative_velocity = relative_velocity
     self.__center_on_target_iron = center_on_target_iron
     self.__center_plot = center_plot
     self.output = pd.read_csv(output_path,
                               skiprows=2,
                               header=None,
                               delimiter="\t")
     if center_on_target_iron:
         self.com = center_of_mass(x_coords=self.output[3],
                                   y_coords=self.output[4],
                                   z_coords=self.output[5],
                                   masses=self.output[2],
                                   particle_ids=self.output[1],
                                   target_iron=self.__center_on_target_iron)
     else:
         self.com = [0, 0, 0]
     if center:
         self.earth_center = find_center(
             x=self.output[3],
             y=self.output[4],
             z=self.output[5],
             mass=self.output[2],
             particle_ids=self.output[1],
             resolution=self.centering_resolution,
             delta_x=self.centering_delta,
             delta_y=self.centering_delta,
             delta_z=self.centering_delta,
             target_iron_centering=self.__center_on_target_iron)
     else:
         self.earth_center = self.com
     self.a = (12713.6 / 2.0
               ) * 1000.0  # present-day equitorial radius of the Earth in m
     self.b = (12756.2 /
               2.0) * 1000.0  # present-day polar radius of the Earth in m
     self.oblateness = self.calc_oblateness(a=self.a, b=self.b)
     self.mass_protoearth = self.calc_mass_protoearth(a=self.a, b=self.b)
     self.plot = plot
M_moon = 7.35 * 10**22  # kg
G = 6.67 * 10**-11
roche = 2.9 * R_earth
start_target = [p for p in pm_start if p.particle_id < 2]
start_impactor = [p for p in pm_start if p.particle_id >= 2]
disk = [p for p in pm_end if p.label == "DISK"]
escape = [p for p in pm_end if p.label == "ESCAPE"]
planet = [p for p in pm_end if p.label == "PLANET"]

total_tar_mass = sum([p.mass for p in start_target])
total_imp_mass = sum([p.mass for p in start_impactor])
total_mass = total_tar_mass + total_imp_mass
imp_mass_ratio = total_imp_mass / total_mass
com_tar_x, com_tar_y, com_tar_z = centering.center_of_mass(
    x_coords=[p.position_vector[0] for p in start_target],
    y_coords=[p.position_vector[1] for p in start_target],
    z_coords=[p.position_vector[2] for p in start_target],
    masses=[p.mass for p in start_target],
)
com_imp_x, com_imp_y, com_imp_z = centering.center_of_mass(
    x_coords=[p.position_vector[0] for p in start_impactor],
    y_coords=[p.position_vector[1] for p in start_impactor],
    z_coords=[p.position_vector[2] for p in start_impactor],
    masses=[p.mass for p in start_impactor],
)
imp_tar_x_offset = com_imp_x - com_tar_x
imp_tar_y_offset = com_imp_y - com_tar_y
impact_angle = atan(imp_tar_y_offset / imp_tar_x_offset) * (180.0 / pi)
print("IMPACTOR:MASS RATIO: {}".format(imp_mass_ratio))
print("IMPACT ANGLE: {}".format(impact_angle))

disk_mass = sum([p.mass for p in disk])
Esempio n. 3
0
    def __make_scene(self, savefig=True, file_num=None, alpha=1.0):
        fig = plt.figure()
        fig.set_size_inches(18.5, 10.5)
        if self.dimension == '3':
            ax = Axes3D(fig)
            if self.focus_process is None:
                for proc in range(0, self.num_processes, 1):
                    self.curr_process = proc
                    if savefig:
                        particle_id, x, y, z, colors, mass = self.__read_sph_file()
                    else:
                        savestate = copy(self.curr_file)
                        self.curr_file = file_num
                        particle_id, x, y, z, colors, mass = self.__read_sph_file()
                        self.curr_file = savestate
                    print(self.__get_filename())
                    if self.colorize_particles:
                        ax.scatter(x, y, z, c=colors, alpha=alpha)
                    else:
                        ax.scatter(x, y, z, c='black', alpha=alpha)
                    self.curr_process = proc
            else:
                self.curr_process = self.focus_process
                if savefig:
                    particle_id, x, y, z, colors, mass = self.__read_sph_file()
                else:
                    savestate = copy(self.curr_file)
                    self.curr_file = file_num
                    particle_id, x, y, z, colors, mass = self.__read_sph_file()
                    self.curr_file = savestate
                if self.colorize_particles:
                    ax.scatter(x, y, z, c=colors, alpha=alpha)
                else:
                    ax.scatter(x, y, z, c='black', alpha=alpha)
            ax.set_xlabel('x')
            ax.set_ylabel('y')
            ax.set_zlabel('z')
            ax.set_xbound(-9e6, 9e6)
            ax.set_ybound(-9e6, 9e6)
            ax.set_zbound(-9e6, 9e6)
        else:
            ax = fig.add_subplot(111)
            x = np.array([])
            y = np.array([])
            z = np.array([])
            particle_id = np.array([])
            colors = np.array([])
            mass = np.array([])
            for proc in range(0, self.num_processes, 1):
                savestate = copy(self.curr_file)
                self.curr_file = file_num
                particle_id_t, x_t, y_t, z_t, colors_t, mass_t = self.__read_sph_file()
                x = np.concatenate((x, x_t))
                y = np.concatenate((y, y_t))
                z = np.concatenate((z, z_t))
                particle_id = np.concatenate((particle_id, particle_id_t))
                colors = np.concatenate((colors, colors_t))
                mass = np.concatenate((mass, mass_t))
                self.curr_file = savestate
                self.curr_process = proc
                print(self.__get_filename())
            if self.center:
                com = center_of_mass(x_coords=x, y_coords=y, z_coords=z, masses=mass, particle_ids=particle_id,
                                     target_iron=self.__center_on_target_iron)
                x = x - com[0]
                y = y - com[1]
                z = z - com[2]
            x = np.array(
                [i for index, i in enumerate(x) if particle_id[index] % 2 == 0] + [i for index, i in enumerate(x) if
                                                                                   particle_id[index] % 2 != 0])
            y = np.array(
                [i for index, i in enumerate(y) if particle_id[index] % 2 == 0] + [i for index, i in enumerate(y) if
                                                                                   particle_id[index] % 2 != 0])
            z = np.array(
                [i for index, i in enumerate(z) if particle_id[index] % 2 == 0] + [i for index, i in enumerate(z) if
                                                                                   particle_id[index] % 2 != 0])
            colors = np.array([i for index, i in enumerate(colors) if particle_id[index] % 2 == 0] + [i for index, i in
                                                                                                      enumerate(colors)
                                                                                                      if particle_id[
                                                                                                          index] % 2 != 0])
            mass = np.array(
                [i for index, i in enumerate(mass) if particle_id[index] % 2 == 0] + [i for index, i in enumerate(mass)
                                                                                      if particle_id[index] % 2 != 0])
            particle_id = np.array(
                [i for index, i in enumerate(particle_id) if particle_id[index] % 2 == 0] + [i for index, i in
                                                                                             enumerate(particle_id) if
                                                                                             particle_id[
                                                                                                 index] % 2 != 0])
            if self.colorize_particles:
                ax.scatter(x, y, c=colors, alpha=alpha)
            else:
                ax.scatter(x, y, c='black', alpha=alpha)
            ax.set_xlabel('x')
            ax.set_ylabel('y')
            ax.set_xbound(-5e7, 5e7)
            ax.set_ybound(-5e7, 5e7)
            # ax.axis('equal')
        if savefig:
            ax.set_title("Iteration: {}".format(self.curr_file))
            print("Built scene: {}".format(self.curr_file))
            fig.savefig(self.to_path + "/output_{}.png".format(self.curr_file), format='png', dpi=100)
            self.curr_file += self.interval
        else:
            plt.show()

        fig.clear()
        plt.close(fig)

        self.curr_process = 0
Esempio n. 4
0
interval = 1
number_processes = 100
path = "/scratch/shull4/impactor"

coms = []
for time in np.arange(start_time, end_time + interval, interval):
    combined_file = CombineFile(num_processes=number_processes,
                                time=time,
                                output_path=path).combine()
    sph_file = os.getcwd() + "/merged_{}.dat".format(time)
    df = pd.read_csv(sph_file, header=None, skiprows=2, delimiter="\t")
    os.remove(sph_file)
    tag, x, y, z, mass = df[1], df[3], df[4], df[5], df[2]
    com = center_of_mass(x_coords=x,
                         y_coords=y,
                         z_coords=z,
                         masses=mass,
                         particle_ids=tag,
                         target_iron=False)
    coms.append(com)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(np.arange(start_time, end_time + interval, interval),
           [sqrt(i[0]**2 + i[1]**2 + i[2]**2) / 1000.0 for i in coms],
           marker="+",
           color="black")
ax.set_xlabel("Time Iteration")
ax.set_ylabel("Distance from Original Center (km)")
ax.set_title("Center of Mass Drift in Mode 2")
ax.grid()
plt.savefig("com_drift.png", format="png")
Esempio n. 5
0
    div = det(xdiff, ydiff)
    if div == 0:
        raise Exception('lines do not intersect')

    d = (det(*line1), det(*line2))
    x = det(d, xdiff) / div
    y = det(d, ydiff) / div
    return x, y


impactor = [i for i in pm if i.particle_id > 1]
target = [i for i in pm if i.particle_id <= 1]

com_x_tar, com_y_tar, com_z_tar = centering.center_of_mass(
    x_coords=[p.position_vector[0] for p in target],
    y_coords=[p.position_vector[1] for p in target],
    z_coords=[p.position_vector[2] for p in target],
    masses=[p.mass for p in target],
)
com_x_imp, com_y_imp, com_z_imp = centering.center_of_mass(
    x_coords=[p.position_vector[0] for p in impactor],
    y_coords=[p.position_vector[1] for p in impactor],
    z_coords=[p.position_vector[2] for p in impactor],
    masses=[p.mass for p in impactor],
)

min_x_imp = min([i.position_vector[0] for i in impactor])
max_x_imp = max([i.position_vector[0] for i in impactor])
min_y_imp = min([i.position_vector[1] for i in impactor])
max_y_imp = max([i.position_vector[1] for i in impactor])
min_z_imp = min([i.position_vector[2] for i in impactor])
max_z_imp = max([i.position_vector[2] for i in impactor])
Esempio n. 6
0
gi_vz_tar = [i for index, i in enumerate(gi_vz) if gi_tags[index] < 2]
gi_x_imp = [i for index, i in enumerate(gi_x) if gi_tags[index] >= 2]
gi_y_imp = [i for index, i in enumerate(gi_y) if gi_tags[index] >= 2]
gi_z_imp = [i for index, i in enumerate(gi_z) if gi_tags[index] >= 2]
gi_mass_imp = [i for index, i in enumerate(gi_mass) if gi_tags[index] >= 2]
gi_vx_imp = [i for index, i in enumerate(gi_vx) if gi_tags[index] >= 2]
gi_vy_imp = [i for index, i in enumerate(gi_vy) if gi_tags[index] >= 2]
gi_vz_imp = [i for index, i in enumerate(gi_vz) if gi_tags[index] >= 2]


def get_radius_body(coords):
    return max([np.linalg.norm(i) for i in coords])


com_tar_x, com_tar_y, com_tar_z = centering.center_of_mass(x_coords=tar_x,
                                                           y_coords=tar_y,
                                                           z_coords=tar_z,
                                                           masses=tar_mass)
com_imp_x, com_imp_y, com_imp_z = centering.center_of_mass(x_coords=imp_x,
                                                           y_coords=imp_y,
                                                           z_coords=imp_z,
                                                           masses=imp_mass)
# com_tar_gi_x, com_tar_gi_y, com_tar_gi_z = centering.center_of_mass(
#     x_coords=gi_x_tar,
#     y_coords=gi_y_tar,
#     z_coords=gi_z_tar,
#     masses=gi_mass_tar
# )
# com_imp_gi_x, com_imp_gi_y, com_imp_gi_z = centering.center_of_mass(
#     x_coords=gi_x_imp,
#     y_coords=gi_y_imp,
#     z_coords=gi_z_imp,
Esempio n. 7
0
total_N = 0
time = 0
df = pd.read_csv(path, sep='\t', skiprows=2, header=None)

if "input_recenter.csv" in os.listdir(os.getcwd()):
    os.remove("input_recenter.csv")

with open(path, 'r') as infile:
    reader = csv.reader(infile, delimiter="\t")
    time = float(next(reader)[0])
    total_N = int(next(reader)[0])
    infile.close()

tags, mass, x, y, z, vx, vy, vz = df[1], df[2], df[3], df[4], df[5], df[6], df[7], df[8]

com_x, com_y, com_z = centering.center_of_mass(x_coords=x, y_coords=y, z_coords=z, masses=mass, particle_ids=tags)

for row in df.index:
    df[3][row] -= com_x
    df[4][row] -= com_y
    df[5][row] -= com_z
    df[6][row] = 0.0
    df[7][row] = 0.0
    df[8][row] = 0.0

df.to_csv("tmp.dat", index=False, header=False, sep='\t')

outfile = open("input_recenter.csv", 'w')
outfile.write(str(time) + "\n")
outfile.write(str(total_N) + "\n")
with open("tmp.dat", 'r') as infile: