from matplotlib import pyplot
import pathlib

import rodney

args = rodney.parse_command_line()
maindir = pathlib.Path(__file__).absolute().parents[1]

# Load force coefficients for simulation with AR=1.27.
label = 'AR = 1.27'
simudir = maindir / 'Re200_St0.6_AR1.27_psi90'
config = rodney.WingKinematics(Re=200, AR=1.27, nt_period=2000)
filepath = simudir / 'output' / 'forces-0.txt'
solution = rodney.load_force_coefficients(filepath, config)
rodney.print_stats(label, *rodney.get_stats(solution, limits=(4, 5)))
plot_kwargs = dict(color='C3', linestyle='-')

# Load force coefficients for simulation with AR=1.91.
label2 = 'AR = 1.91'
simudir2 = maindir / 'Re200_St0.6_AR1.91_psi90'
config2 = rodney.WingKinematics(Re=200, AR=1.91, nt_period=2000)
filepath = simudir2 / 'output' / 'forces-0.txt'
solution2 = rodney.load_force_coefficients(filepath, config2)
rodney.print_stats(label2, *rodney.get_stats(solution2, limits=(4, 5)))
plot_kwargs2 = dict(color='black', linestyle='--')

# Load force coefficients for simulation with AR=2.55.
label3 = 'AR = 2.55'
simudir3 = maindir / 'Re200_St0.6_AR2.55_psi90'
config3 = rodney.WingKinematics(Re=200, AR=2.55, nt_period=2000)
import numpy
import pathlib

import rodney

args = rodney.parse_command_line()
display_kinematics = True  # Add kinematics to the figure
maindir = pathlib.Path(__file__).absolute().parents[1]

# Load force coefficients.
label = 'PetIBM'
simudir = maindir
config = rodney.WingKinematics(Re=200, nt_period=2000)
filepath = simudir / 'output' / 'forces-0.txt'
solution = rodney.load_force_coefficients(filepath, config)
rodney.print_stats(label, *rodney.get_stats(solution, limits=(4, 5)))

# Compute and print additional statistics (max of abs).
mask = numpy.where((solution.t >= 4) & (solution.t <= 5))[0]
ct, cl, cz = solution.ct[mask], solution.cl[mask], solution.cz[mask]
print('max(|C_T|)', numpy.max(numpy.abs(ct)))
print('max(|C_L|)', numpy.max(numpy.abs(cl)))
print('max(|C_Z|)', numpy.max(numpy.abs(cz)))

# Plot the history of the force coefficients.
pyplot.rc('font', family='serif', size=12)
fig, (ax1, ax2, ax3) = pyplot.subplots(ncols=3, figsize=(12.0, 3.0))
xlim, ylim = (3.0, 5.0), (-6.0, 6.0)
# Plot the history of the thrust coefficient.
ax1.set_xlabel('$t / T$')
ax1.set_ylabel('$C_T$')