Skip to content
Snippets Groups Projects
Commit 8874a26a authored by podlesny's avatar podlesny
Browse files

more tools for experiment assessment

parent e7805b84
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ import matplotlib.pyplot as plt ...@@ -8,6 +8,7 @@ import matplotlib.pyplot as plt
from debug.outliers import outliers from debug.outliers import outliers
from debug.friction import truncated_friction from debug.friction import truncated_friction
from debug.state import aging_law from debug.state import aging_law
from debug.diffplot import diffplot
from support.maximum import maximum from support.maximum import maximum
from support.norm import norm from support.norm import norm
...@@ -16,6 +17,7 @@ from support.slip_beginnings import slip_beginnings ...@@ -16,6 +17,7 @@ from support.slip_beginnings import slip_beginnings
from support.slip_endings import slip_endings from support.slip_endings import slip_endings
from support.max_distance import max_distance from support.max_distance import max_distance
from support.iterations import iterations
NBODIES = 2 NBODIES = 2
FINAL_TIME = 15 # s FINAL_TIME = 15 # s
...@@ -65,7 +67,7 @@ for body_ID in range(NBODIES): ...@@ -65,7 +67,7 @@ for body_ID in range(NBODIES):
continue continue
# velocity data # velocity data
v = np.array(h5file[body + '/velocity']) v = abs(np.array(h5file[body + '/velocity']))
# statistics # statistics
avg_v = np.average(v[:,:,TANGENTIAL_COORDS], axis=1) avg_v = np.average(v[:,:,TANGENTIAL_COORDS], axis=1)
...@@ -124,6 +126,10 @@ for body_ID in range(NBODIES): ...@@ -124,6 +126,10 @@ for body_ID in range(NBODIES):
plt.ylabel('friction coefficient') plt.ylabel('friction coefficient')
#------------------------- #-------------------------
diffplot(friction_coeff[1], friction_coeff_calc[1], 'diff friction coeff')
iterations(h5file, FINAL_TIME)
plt.show() plt.show()
h5file.close() h5file.close()
\ No newline at end of file
import numpy as np
import matplotlib.pyplot as plt
def diffplot(v1, v2, title):
v_diff = v1 - v2
t = np.linspace(0, len(v_diff)-1, len(v_diff), endpoint=True)
# plot
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(t, v1, color='black', linestyle='--')
ax.plot(t, v2, color='gray', linestyle='--')
ax.plot(t, v_diff, color='red', linestyle='-')
ax.set_ylabel(title)
#-------------------------
fig.canvas.draw()
\ No newline at end of file
import configparser as cp
import os
import numpy as np
import csv
import h5py
import matplotlib.pyplot as plt
from debug.outliers import outliers
from debug.friction import truncated_friction
from debug.state import aging_law
from debug.diffplot import diffplot
from support.maximum import maximum
from support.norm import norm
from support.find_quakes import find_quakes
from support.slip_beginnings import slip_beginnings
from support.slip_endings import slip_endings
from support.max_distance import max_distance
from support.iterations import iterations
from support.friction_stats import friction_stats
def build_patch(coords, percentage):
x_coords = coords[:, 0]
xmin = np.min(x_coords)
xmax = np.max(x_coords)
delta_x = (1 - percentage)*(xmax - xmin)/2
xmin = xmin + delta_x
xmax = xmax - delta_x
return [i for i in range(len(x_coords)) if x_coords[i]>=xmin and x_coords[i]<=xmax]
NBODIES = 2
FINAL_TIME = 15 # s
FINAL_VELOCITY = 1e-5 # m/s
THRESHOLD_VELOCITY = 0.5*FINAL_VELOCITY # 1000e-6 + FINAL_VELOCITY
TANGENTIAL_COORDS = 1
# friction params
params = {
'L' : 1e-5,
'V0' : 1e-6,
'mu0': 0.6,
'a' : 0.010,
'b' : 0.015
}
# read config ini
config = cp.ConfigParser()
config_path = os.path.join('tools/config.ini')
config.read(config_path)
sim_path = config.get('directories', 'simulation')
exp_path = config.get('directories', 'experiment')
out_path = config.get('directories', 'output')
# read hdf5 output file
h5path = os.path.join(sim_path)
h5file = h5py.File(os.path.join(h5path, 'output.h5'), 'r')
print(list(h5file.keys()))
print(list(h5file['body1'].keys()))
iterations(h5file, FINAL_TIME)
for body_ID in range(NBODIES):
body = 'body' + str(body_ID)
if body not in h5file:
continue
coords = np.array(h5file[body + '/coordinates'])
patch = build_patch(coords, 0.1)
friction_stats(h5file, body_ID, FINAL_TIME, patch, [])
plt.show()
h5file.close()
\ No newline at end of file
import numpy as np
import matplotlib.pyplot as plt
TANGENTIAL_COORDS = 1
def friction_stats(h5file, body_ID, FINAL_TIME, patch=[], interval=[]):
body = 'body' + str(body_ID)
coords = np.array(h5file[body + '/coordinates'])
if len(patch) == 0:
patch = np.linspace(0, len(coords)-1, len(coords), endpoint=True, dtype='int8')
print(len(patch))
# read time
time = np.array(h5file['relativeTime']) * FINAL_TIME
time = np.delete(time, 0)
if len(interval) == 0:
interval = [0, FINAL_TIME]
t = [i for i in range(len(time)) if time[i]>=interval[0] and time[i]<=interval[1]]
time = time[t]
fig = plt.figure()
# velocity data
v = abs(np.array(h5file[body + '/velocity']))
v_t = v[t,:,TANGENTIAL_COORDS]
v_tx = v_t[:,patch]
# statistics
avg_v = np.average(v_tx, axis=1)
min_v = np.min(v_tx, axis=1)
max_v = np.max(v_tx, axis=1)
# plot
ax_slip = fig.add_subplot(3, 1, 1)
ax_slip.plot(time, min_v, color='gray', linestyle='--')
ax_slip.plot(time, avg_v, color='black', linestyle='-')
ax_slip.plot(time, max_v, color='gray', linestyle='--')
ax_slip.set_ylabel('slip rate')
#-------------------------
# state
states = np.array(h5file[body + '/state'])
states_t = states[t,:]
states_tx = states_t[:,patch]
# statistics
avg_states = np.average(states_tx, axis=1)
min_states = np.min(states_tx, axis=1)
max_states = np.max(states_tx, axis=1)
# plot
ax_state = fig.add_subplot(3, 1, 2)
ax_state.plot(time, min_states, color='gray', linestyle='--')
ax_state.plot(time, avg_states, color='black', linestyle='-')
ax_state.plot(time, max_states, color='gray', linestyle='--')
ax_state.set_ylabel('state')
#-------------------------
# friction coefficient
friction_coeff = np.array(h5file[body + '/coefficient'])
friction_coeff_t = friction_coeff[t,:]
friction_coeff_tx = friction_coeff_t[:,patch]
# statistics
avg_friction_coeff = np.average(friction_coeff_tx, axis=1)
min_friction_coeff = np.min(friction_coeff_tx, axis=1)
max_friction_coeff = np.max(friction_coeff_tx, axis=1)
# plot
ax_friction = fig.add_subplot(3, 1, 3)
ax_friction.plot(time, min_friction_coeff, color='gray', linestyle='--')
ax_friction.plot(time, avg_friction_coeff, color='black', linestyle='-')
ax_friction.plot(time, max_friction_coeff, color='gray', linestyle='--')
ax_friction.set_ylabel('friction coefficient')
#-------------------------
fig.canvas.draw()
\ No newline at end of file
import numpy as np
import matplotlib.pyplot as plt
def iterations(h5file, FINAL_TIME, interval = []):
# read time steps
tau = np.array(h5file['relativeTimeIncrement']) * FINAL_TIME
tau = np.delete(tau, 0)
# read fpi iterations
fpi_final = np.array(h5file['iterations/fixedPoint/final'])
fpi_final = np.delete(fpi_final, 0)
#fpi_total = np.array(h5file['iterations/fixedPoint/total'])
# read multigrid iterations
multigrid_final = np.array(h5file['iterations/multiGrid/final'])
multigrid_final = np.delete(multigrid_final, 0)
#multigrid_total = np.array(h5file['iterations/multiGrid/total'])
if len(interval) == 0:
interval = [0, len(tau)-1]
t = np.linspace(interval[0], interval[1], interval[1]-interval[0]+1, endpoint=True, dtype='int8')
# plot
fig = plt.figure()
ax_fpi = fig.add_subplot(3, 1, 1)
ax_fpi.plot(t, fpi_final[t], color='black', linestyle='-')
ax_fpi.set_ylabel('fpi')
#-------------------------
ax_mg = fig.add_subplot(3, 1, 2)
ax_mg.plot(t, multigrid_final[t], color='black', linestyle='-')
ax_mg.set_ylabel('multigrid')
#-------------------------
ax_tau = fig.add_subplot(3, 1, 3)
ax_tau.plot(t, tau[t], color='black', linestyle='-')
ax_tau.set_ylabel('tau')
#-------------------------
fig.canvas.draw()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment