Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drift test #45

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
28dc244
Added interpolation.h.
ScottHull Mar 11, 2021
b357a23
test implementation of GI_universal
ScottHull Mar 12, 2021
373db52
Added CalcMomentum in force.h.
ScottHull Mar 15, 2021
c15c126
Added total momentum.
ScottHull Mar 15, 2021
5bc49a7
Testing main.cpp.
ScottHull Mar 16, 2021
452bd24
Added postTimestepProcess for debugging momentum.
ScottHull Apr 5, 2021
dbb21e2
testing smoothed grav
ScottHull Apr 9, 2021
fdc8ba5
testing smoothed grav
ScottHull Apr 12, 2021
df467cc
testing smoothed grav
ScottHull Apr 13, 2021
ba98e2c
testing smoothed grav
ScottHull Apr 13, 2021
86e759b
testing smoothed grav
ScottHull Apr 15, 2021
d28b02f
testing smoothed grav
ScottHull Apr 15, 2021
89763d7
testing smoothed grav
ScottHull Apr 15, 2021
d0796f6
testing smoothed grav
ScottHull Apr 15, 2021
db8f578
testing smoothed grav
ScottHull Apr 15, 2021
412a37c
testing smoothed grav
ScottHull Apr 15, 2021
ff4e555
Fixed a bug in mode 2 where the tar mass and imp mass were being adde…
ScottHull Apr 29, 2021
5d2c899
Fixed a bug in mode 2 where the tar mass and imp mass were being adde…
ScottHull Apr 30, 2021
a5147f3
Removed COMM functions in GI.h.
ScottHull May 17, 2021
83f3122
New x_init in GI.h.
ScottHull May 17, 2021
9707196
fixed impact velocity
ScottHull May 24, 2021
50a53a0
temporarily AGranite
ScottHull Jun 7, 2021
4627ca2
temporarily AGranite
ScottHull Jun 7, 2021
9313891
added angular momentum to GI.h.
ScottHull Jun 8, 2021
ad0ec90
added angular momentum to GI.h.
ScottHull Jun 8, 2021
f361d34
added angular momentum to GI.h.
ScottHull Jun 8, 2021
56ce177
switch to AGranite
ScottHull Jun 13, 2021
8b96b4f
Testing initial separation
ScottHull Jun 14, 2021
f679a2c
Testing initial separation
ScottHull Jun 14, 2021
8323fd8
Testing initial separation
ScottHull Jun 14, 2021
d2677d8
This code produce duniteS2.rho_u.txt
mikinakajima Jun 28, 2021
9bdadbe
Fixed a bug in line 147 (from > to >=)
mikinakajima Jun 28, 2021
3da49fd
dunite used in Nakajima & Stevenson 2014, 2015
mikinakajima Jun 28, 2021
c3f09b6
Testing initial separation
ScottHull Jun 30, 2021
8f5b82b
added back entropy specification from input files in main.cpp
ScottHull Jul 15, 2021
c7b4c50
added back entropy specification from input files in main.cpp
ScottHull Jul 15, 2021
9fe6c38
Merge remote-tracking branch 'origin/drift_test' into drift_test
ScottHull Jul 15, 2021
68348dc
added back entropy specification from input files in main.cpp
ScottHull Jul 15, 2021
53e8514
Add files via upload
ScottHull Sep 24, 2021
6098ae7
ready for pull request to main
ScottHull Sep 24, 2021
9468bce
added mode 2 patch to prevent entropy errors
ScottHull Nov 8, 2021
3eb5a3c
testing mode 3
ScottHull Feb 4, 2022
723cf66
testing mode 3
ScottHull Feb 4, 2022
2b1cf4a
testing mode 3
ScottHull Feb 4, 2022
17be563
testing mode 3
ScottHull Feb 4, 2022
a5f70f6
testing mode 3
ScottHull Feb 4, 2022
a036874
Updating the min density
mikinakajima Jan 11, 2023
f1d8fc2
Making the input file compatible
mikinakajima Jan 11, 2023
9599cba
adding a comment about minimum density
mikinakajima Jan 11, 2023
7760262
added a pipeline for creating input text files
Oct 9, 2023
1509d74
Delete eos/granite.rho_u.txt
mikinakajima Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ MESSAGE(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
MESSAGE(STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
MESSAGE(STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")

ADD_EXECUTABLE(sph.out src/main.cpp)
ADD_EXECUTABLE(sph.out src/main.cpp src/interpolation.h)
259 changes: 259 additions & 0 deletions eos/ANEOS_conversion_mod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
# This is a python script that converts u(rho, T), P(rho, T), Cs(rho,T), S(rho, T)
# to T(rho, u), P(rho, u), Cs(rho, u), S(rho, u), which is more useful for SPH calculaitons
#

import matplotlib.pyplot as plt
import numpy as np
import sys
from scipy.interpolate import interp1d, interp2d
from scipy import interpolate

#----- A user has to change these three parameters ----------------

inputfilename="duniteS.table.txt" #input ANEOS file. This follows the format from iSALE
outputfilename="duniteS2.rho_u.txt" #output ANEOS file
nu=120 #number of the grid for the internal energy (exponential)

#-------------------------------------------------------------------

# This function is to correct the original ANEOS format that does not include "E"
# This seems to occur when the exponent reaches -101
def reformat(number):

if number.find('E') == -1:
for i in range(100,200):
number_to_find = '-' + str(i)
if number.find(number_to_find) >= 1:
exponent = number_to_find


mantissa = number.split(exponent)
return float(mantissa[0])*10**float(exponent)
else:
mantissa, exponent= number.split('E')

return float(mantissa)*10**float(exponent)







aneosfile= [line.split() for line in open(inputfilename)]

temperature=np.zeros(shape=(0,0))
density=np.zeros(shape=(0,0))

for i in range(1,len(aneosfile)):
try:
temperature=np.append(temperature,reformat(aneosfile[i][1]))
except IndexError:
nt=i-1
break



for i in range(1,len(aneosfile), nt+1):
density=np.append(density,reformat(aneosfile[i][0]))

nr=len(density) #density grid number

energy=np.zeros(shape=(nr,nt)) #J/kg
pressure=np.zeros(shape=(nr,nt)) #Pa
soundspeed=np.zeros(shape=(nr,nt)) #m/s
entropy=np.zeros(shape=(nr,nt)) #J/kg/K

i=1
for m in range(0,nr):
for n in range(0,nt):
try:
energy[m][n]=reformat(aneosfile[i][2])
pressure[m][n]=reformat(aneosfile[i][3])
soundspeed[m][n]=reformat(aneosfile[i][4])
entropy[m][n]=reformat(aneosfile[i][5])

except IndexError: #skipping a line
i=i+1
energy[m][n]=reformat(aneosfile[i][2])
pressure[m][n]=reformat(aneosfile[i][3])
soundspeed[m][n]=reformat(aneosfile[i][4])
entropy[m][n]=reformat(aneosfile[i][5])
i=i+1

#print(energy[m][n], pressure[m][n],soundspeed[m][n],entropy[m][n])


# Taking the min and max internal energy from the original ANEOS data
umin=np.min(energy)*1.01 # this is added to make interpolation working
umax=np.max(energy)
if umin < 0.0:
umin = 1.0

delta=(umax/umin)**(1.0/(nu*1.0-1.0))

print(nu,nr,delta, umax,umin)
#sys.exit()


new_energy=np.zeros(shape=(0,0))
for m in range(0,nu):
new_energy=np.append(new_energy,umin*delta**m) #exponential grid

new_temperature=np.zeros(shape=(nr,nu))
new_pressure=np.zeros(shape=(nr,nu))
new_soundspeed=np.zeros(shape=(nr,nu))
new_entropy=np.zeros(shape=(nr,nu))


def interpolation(p11, p12, p21, p22, alpha, beta):
A1 = p11 + alpha*(p12-p11) #fixed density
A2 = p21 + alpha*(p22-p21) #fixed density

return A1 + beta*(A2-A1)

def rho_u(energy_list, density_list, temperature_list, u_in, rho_in):
if rho_in < density[0]:
print("too small density")
sys.exit()

if rho_in>=density[len(density)-1]:
beta=0.0
index0=len(density)-1
index1=index0+1

else:
density_index = density_list.index(density[density>rho_in][0])
beta = (rho_in - density_list[density_index-1])/(density_list[density_index]-density_list[density_index-1])

index0=density_index-1
index1=density_index+1



temp_i_1 = [0, 0]
n_i = [0, 0]

k=0

for i in range(index0, index1):
energy_i_1 = energy[i][:]
energy_list_i_1 = list(energy_i_1)

if u_in > energy_list_i_1[len(energy_i_1)-1]:
temp_i_1[k]=temperature[len(energy_i_1)-1]

else:
n_i[k] = energy_list_i_1.index(energy_i_1[energy_i_1 >= u_in][0])

if n_i[k]==0:
alpha_i=0.0
temp_i_1[k]=temperature[0]

else:
alpha_i = (u_in - energy_i_1[n_i[k]-1])/(energy_i_1[n_i[k]]-energy_i_1[n_i[k]-1])
temp_i_1[k] = temperature[n_i[k]-1] + alpha_i * (temperature[n_i[k]] - temperature[n_i[k]-1])
k=k+1

if rho_in>=density[len(density)-1]:
temp_out = temp_i_1[0]
n_den_s=len(density)-1
n_den_l=len(density)-1

else:
temp_out = temp_i_1[0] + beta * (temp_i_1[1]-temp_i_1[0])
n_den_s=density_index-1
n_den_l=density_index

if np.abs(temp_out-temperature[len(temperature)-1])<0.001:
n_max = len(energy_i_1)-1
new_press= interpolation(pressure[n_den_s][n_max], pressure[n_den_s][n_max], pressure[n_den_l][n_max], pressure[n_den_l][n_max], 0.0, beta)
new_entropy= interpolation(entropy[n_den_s][n_max], entropy[n_den_s][n_max], entropy[n_den_l][n_max], entropy[n_den_l][n_max], 0.0, beta)
new_soundspeed= interpolation(soundspeed[n_den_s][n_max], soundspeed[n_den_s][n_max], soundspeed[n_den_l][n_max], soundspeed[n_den_l][n_max], 0.0, beta)
#print('a')
else:
#print('b')
temperature_index = temperature_list.index(temperature[temperature>temp_out][0])


if temperature_index == 1:
new_press= interpolation(pressure[n_den_s][0], pressure[n_den_s][0], pressure[n_den_l][0], pressure[n_den_l][0], 0.0, beta)
new_entropy= interpolation(entropy[n_den_s][0], entropy[n_den_s][0], entropy[n_den_l][0], entropy[n_den_l][0], 0.0, beta)
new_soundspeed= interpolation(soundspeed[n_den_s][0], soundspeed[n_den_s][0], soundspeed[n_den_l][0], soundspeed[n_den_l][0], 0.0, beta)

else:

alpha= (temp_out-temperature[temperature_index-1])/(temperature[temperature_index]-temperature[temperature_index-1])

new_press= interpolation(pressure[n_den_s][temperature_index-1], pressure[n_den_s][temperature_index], pressure[n_den_l][temperature_index-1], pressure[n_den_l][temperature_index], alpha, beta)
new_entropy= interpolation(entropy[n_den_s][temperature_index-1], entropy[n_den_s][temperature_index], entropy[n_den_l][temperature_index-1], entropy[n_den_l][temperature_index], alpha, beta)
new_soundspeed= interpolation(soundspeed[n_den_s][temperature_index-1], soundspeed[n_den_s][temperature_index], soundspeed[n_den_l][temperature_index-1], soundspeed[n_den_l][temperature_index], alpha, beta)


return temp_out, new_press, new_soundspeed, new_entropy


density_list = list(density)
energy_list = list(energy)
temperature_list = list(temperature)




h = open('test4.txt','w')


# 1D interpolation & extrapolation (linear)
for m in range(0,nr):
for n in range(0, nu):
new_temperature[m][n], new_pressure[m][n], new_soundspeed[m][n], new_entropy[m][n] = rho_u(energy_list, density_list, temperature_list, new_energy[n], density[m])

h.write("%15.8E %15.8E %15.8E %15.8E %15.8E %15.8E %i %i \n" % (density[m], new_temperature[m][n], new_energy[n], new_pressure[m][n], new_soundspeed[m][n], new_entropy[m][n], m,n))

#sys.exit()


#new_pressure = new_pressure.clip(min=0.0)








# producing a few output images to make sure that this fitting is doing an okay job
for m in range(0,nr, int(nr/6)):

ax=[0, 0, 0, 0]

fig=plt.figure(figsize=(10,6.128))

ax[0]=fig.add_subplot(221)
ax[1]=fig.add_subplot(222)
ax[2]=fig.add_subplot(223)
ax[3]=fig.add_subplot(224)

ax[0].semilogy(temperature*1e-3, energy[m,:]*1e-6, '--', label = "original ANEOS")
ax[0].semilogy(new_temperature[m, :]*1e-3, new_energy[:]*1e-6, '-.', label="modified")
ax[1].semilogy(temperature*1e-3, pressure[m,:]*1e-6,'--', new_temperature[m, :]*1e-3, new_pressure[m, :]*1e-6,'-.')
ax[2].plot(temperature*1e-3, soundspeed[m,:]*1e-3,'--', new_temperature[m, :]*1e-3, new_soundspeed[m, :]*1e-3,'-.')
ax[3].plot(temperature*1e-3, entropy[m,:]*1e-3,'--', new_temperature[m, :]*1e-3, new_entropy[m, :]*1e-3,'-.')

ax[0].legend(frameon=False)

ax[0].set_ylabel('Energy (MJ/kg)',fontsize=10); ax[1].set_ylabel('Pressure (MPa)',fontsize=10); ax[2].set_ylabel('Sound Speed (km/s)',fontsize=10)
ax[3].set_ylabel('Entropy (kJ/K/kg)',fontsize=10)
ax[2].set_xlabel('Temperature ($10^3$ K)',fontsize=10); ax[3].set_xlabel('Temperature ($10^3$ K)',fontsize=10)

fig.suptitle("Density: %3.3f kg/m$^3$" %(density[m]))
fig.savefig("Density" + str(m) + ".png")

h = open(outputfilename,'w')
h.write("%s %i %i %s \n" % ('# ', nr, nu , ':Grid numbers for density and internal energy'))
h.write('# Density (km/m3), Internal energy (kJ/kg), Temperature (K), Pressure (Pa), Sound speed (m/s), Entropy (J/K/kg) \n')


for m in range(0,nr):
for n in range(0,nu):
h.write("%15.8E %15.8E %15.8E %15.8E %15.8E %15.8E \n" % (density[m], new_energy[n], new_temperature[m][n], new_pressure[m][n], new_soundspeed[m][n], new_entropy[m][n]))
Loading