File size: 3,065 Bytes
d513eb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Plot recorded measurements; never infer a benchmark score from the replay."""
import argparse
import json
from pathlib import Path

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('result', type=Path)
    args = parser.parse_args()
    root = args.result
    report = json.loads((root / 'report.json').read_text(encoding='utf-8'))
    rows = json.loads((root / 'trajectory.json').read_text(encoding='utf-8'))
    t = np.array([r['time'] for r in rows])
    displacement = np.array([r['tray_m'][1] for r in rows]) - report['config']['initial_y']
    radius = report['config']['cup_radius']
    area = .5 * 32 * radius**2 * np.sin(2*np.pi/32)
    expected = np.array(report['total_liquid_mass_kg']) / report['config']['liquid_density'] / area
    heights = np.array([[c['height_q99_m'] for c in r['cups']] for r in rows])
    force = -np.array([r['fluid_force_z_N'] for r in rows])
    center_rows = json.loads((root / 'replay_center_trajectory.json').read_text(encoding='utf-8'))
    center_t = np.array([r['time'] for r in center_rows])
    center_ratios = np.array([[c['center_height_ratio'] for c in r['cups']] for r in center_rows])
    fig, axes = plt.subplots(4, 1, figsize=(9, 9), sharex=True, layout='constrained')
    colors = ('#187984', '#C47A23')
    axes[0].plot(t, displacement * 100, color='#33465D')
    axes[0].axhline(50, color='#708090', linestyle=':', label='Target')
    axes[0].set_ylabel('Tray travel (cm)')
    axes[0].legend(loc='lower right')
    for k, color in enumerate(colors):
        axes[1].plot(t, heights[:, k] / expected[k], color=color, label=f'Cup {k+1}')
        axes[2].plot(center_t, center_ratios[:, k], color=color, label=f'Cup {k+1}')
        # Lagged impulses produce a zero at initialization. Do not smooth or
        # conceal this; omit only the first undefined feedback point.
        axes[3].plot(t[1:], force[1:, k], color=color, label=f'Cup {k+1}')
    axes[1].axhline(1, color='#708090', linestyle=':')
    axes[1].set_ylabel('q99 height / M/(rho*A)')
    axes[1].legend(loc='upper right')
    axes[2].axhline(1, color='#708090', linestyle=':')
    axes[2].set_ylabel('COM height / (M/(rho*A)/2)')
    axes[3].axhline(report['total_liquid_mass_kg'][0]*9.81, color='#708090', linestyle=':', label='Static weight')
    axes[3].set_ylabel('Downward liquid load (N)')
    axes[3].set_xlabel('Simulation time (s)')
    axes[3].legend(loc='lower right')
    for ax in axes:
        for boundary in (3, 4.5, 6, 9):
            ax.axvline(boundary, color='#AAAAAA', linewidth=.6, alpha=.6)
        ax.grid(axis='y', color='#D7DCE2', linewidth=.5)
        ax.spines[['top', 'right']].set_visible(False)
    axes[0].set_title('Recorded Newton transport: two free cups, 216.3 g liquid each\nDiagnostic case; no benchmark score')
    fig.savefig(root / 'transport_diagnostics.png', dpi=180)
    fig.savefig(root / 'transport_diagnostics.pdf')
    plt.close(fig)


if __name__ == '__main__':
    main()