From 8874a26a2f9c7073d1a4bb069fba557682a0f89a Mon Sep 17 00:00:00 2001 From: podlesny <podlesny@zedat.fu-berlin.de> Date: Fri, 26 Feb 2021 15:06:01 +0100 Subject: [PATCH] more tools for experiment assessment --- data/tools/debug.py | 8 ++- data/tools/debug/diffplot.py | 17 ++++++ data/tools/main.py | 81 ++++++++++++++++++++++++++++ data/tools/support/friction_stats.py | 73 +++++++++++++++++++++++++ data/tools/support/iterations.py | 42 +++++++++++++++ 5 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 data/tools/debug/diffplot.py create mode 100644 data/tools/main.py create mode 100644 data/tools/support/friction_stats.py create mode 100644 data/tools/support/iterations.py diff --git a/data/tools/debug.py b/data/tools/debug.py index cd37940a..34c7775a 100644 --- a/data/tools/debug.py +++ b/data/tools/debug.py @@ -8,6 +8,7 @@ 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 @@ -16,6 +17,7 @@ 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 NBODIES = 2 FINAL_TIME = 15 # s @@ -65,7 +67,7 @@ for body_ID in range(NBODIES): continue # velocity data - v = np.array(h5file[body + '/velocity']) + v = abs(np.array(h5file[body + '/velocity'])) # statistics avg_v = np.average(v[:,:,TANGENTIAL_COORDS], axis=1) @@ -124,6 +126,10 @@ for body_ID in range(NBODIES): plt.ylabel('friction coefficient') #------------------------- + diffplot(friction_coeff[1], friction_coeff_calc[1], 'diff friction coeff') + + iterations(h5file, FINAL_TIME) + plt.show() h5file.close() \ No newline at end of file diff --git a/data/tools/debug/diffplot.py b/data/tools/debug/diffplot.py new file mode 100644 index 00000000..f4860ee5 --- /dev/null +++ b/data/tools/debug/diffplot.py @@ -0,0 +1,17 @@ +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 diff --git a/data/tools/main.py b/data/tools/main.py new file mode 100644 index 00000000..4502ed00 --- /dev/null +++ b/data/tools/main.py @@ -0,0 +1,81 @@ +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 diff --git a/data/tools/support/friction_stats.py b/data/tools/support/friction_stats.py new file mode 100644 index 00000000..a921632c --- /dev/null +++ b/data/tools/support/friction_stats.py @@ -0,0 +1,73 @@ +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 diff --git a/data/tools/support/iterations.py b/data/tools/support/iterations.py new file mode 100644 index 00000000..88fb3bee --- /dev/null +++ b/data/tools/support/iterations.py @@ -0,0 +1,42 @@ +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 -- GitLab