Skip to content

Commit

Permalink
added tests for viscosity in h2o
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideTisi committed Dec 10, 2023
1 parent d16eb37 commit 1a14e32
Show file tree
Hide file tree
Showing 5 changed files with 2,604 additions and 37 deletions.
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ def data_SiO2(data_SiO2_path):
print('T = {:f} K'.format(TEMPERATURE))
return jfile, DT_FS, TEMPERATURE, VOLUME

@pytest.fixture(scope='session')
def data_h2o(data_h2o_path):
import sportran as st
import numpy as np

jfile = st.i_o.TableFile(data_h2o_path, group_vectors=True)
jfile.read_datalines()
DT_FS = 1.0 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K] (983.173 K)
VOLUME = 1918.4149658 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))
print('V = {:f} A^3'.format(VOLUME))
return jfile, DT_FS, TEMPERATURE, VOLUME


@pytest.fixture
def check_reg(num_regression, data_regression):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_as_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def test_example_SiO2_fixed_K(data_SiO2, check_reg):
jf.cepstral_analysis(manual_cutoffK=42)
print(jf.cepstral_log)
check_reg(jf)

def test_example_viscosity_h2o(data_h2o, check_reg):
import sportran as st

jfile, DT_FS, TEMPERATURE, VOLUME = data_h2o
j = st.StressCurrent(np.column_stack([jfile.data['s_xy'], jfile.data['s_xz'], jfile.data['s_yz']]),
UNITS='real', DT_FS=DT_FS, TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 25.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)


if __name__ == '__main__':
Expand Down
112 changes: 75 additions & 37 deletions tests/test_as_example/regenerate_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sportran as st
import numpy as np
import yaml, pandas as pd
import argparse


def write_results(jf, filename):
Expand All @@ -24,48 +25,85 @@ def write_results(jf, filename):
with open(filename + '.yml', 'w') as f:
f.write(yaml.dump(d))

def main(inputs):
if (inputs == 'all' or inputs == 'NaCl' ):
# NaCl
jfile = st.i_o.TableFile('../data/NaCl/NaCl.dat', group_vectors=True)
jfile.read_datalines(start_step=0, NSTEPS=0, select_ckeys=['Temp', 'flux', 'vcm[1]'])
DT_FS = 5.0 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K]
VOLUME = 40.21**3 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))
print('V = {:f} A^3'.format(VOLUME))

# NaCl
jfile = st.i_o.TableFile('../data/NaCl/NaCl.dat', group_vectors=True)
jfile.read_datalines(start_step=0, NSTEPS=0, select_ckeys=['Temp', 'flux', 'vcm[1]'])
DT_FS = 5.0 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K]
VOLUME = 40.21**3 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))
print('V = {:f} A^3'.format(VOLUME))
j = st.HeatCurrent([jfile.data['flux'], jfile.data['vcm[1]']], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE,
VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 14.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)

j = st.HeatCurrent([jfile.data['flux'], jfile.data['vcm[1]']], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE,
VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 14.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)
write_results(jf, 'test_example_NaCl')

if (inputs == 'all' or inputs == 'SiO2' ):
# SiO2
jfile = st.i_o.TableFile('../data/Silica/Silica.dat', group_vectors=True)
jfile.read_datalines(start_step=0, NSTEPS=0, select_ckeys=['flux1', 'Temp'])
DT_FS = 1.0 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K]
VOLUME = 3130.431110818 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))

write_results(jf, 'test_example_NaCl')
j = st.HeatCurrent(jfile.data['flux1'], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 28.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)

# SiO2
jfile = st.i_o.TableFile('../data/Silica/Silica.dat', group_vectors=True)
jfile.read_datalines(start_step=0, NSTEPS=0, select_ckeys=['flux1', 'Temp'])
DT_FS = 1.0 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K]
VOLUME = 3130.431110818 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))
write_results(jf, 'test_example_SiO2')

j = st.HeatCurrent(jfile.data['flux1'], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 28.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)
j = st.HeatCurrent(jfile.data['flux1'], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 28.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis(manual_cutoffK=42)
print(jf.cepstral_log)

write_results(jf, 'test_example_SiO2')
write_results(jf, 'test_example_SiO2_fixed_K')

if (inputs == 'all' or inputs == 'h2o' ):
# Viscosity H2O
jfile = st.i_o.TableFile('../data/h2o/h2o.dat', group_vectors=True)
jfile.read_datalines()
DT_FS = 1 # time step [fs]
TEMPERATURE = np.mean(jfile.data['Temp']) # temperature [K] (983.173 K)
VOLUME = 1918.4149658 # volume [A^3]
print('T = {:f} K'.format(TEMPERATURE))
print('V = {:f} A^3'.format(VOLUME))

j = st.HeatCurrent(jfile.data['flux1'], DT_FS=DT_FS, UNITS='metal', TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 28.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis(manual_cutoffK=42)
print(jf.cepstral_log)
j = st.StressCurrent(np.column_stack([jfile.data['s_xy'], jfile.data['s_xz'], jfile.data['s_yz']]),
UNITS='real', DT_FS=DT_FS, TEMPERATURE=TEMPERATURE, VOLUME=VOLUME)
print(j.Nyquist_f_THz)
FSTAR_THZ = 25.0
jf = j.resample(fstar_THz=FSTAR_THZ, plot=False, freq_units='thz')
jf.cepstral_analysis()
print(jf.cepstral_log)

write_results(jf, 'test_example_SiO2_fixed_K')
write_results(jf, 'test_example_viscosity_h2o')


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Regenerate data for the test.')
parser.add_argument('-i', type=str,
help='''what data do you want to regenerate?
Valid options "all", "NaCl", "SiO2", "h2o".
Combinations can be done adding "_", e.g. "NaCl_SiO2"''')

inputs = parser.parse_args().i.split('_')
for i in inputs:
if i not in ["all", "NaCl", "SiO2", "h2o"]:
print('input values not valid use "-h" to get help')
else:
main(i)
Loading

0 comments on commit 1a14e32

Please sign in to comment.