# This file is part of postcipes
# (c) Timofey Mukha
# The code is released under the MIT Licence.
# See LICENCE.txt and the Legal section in the README for more information

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from .postcipe import Postcipe
import turbulucid as tbl
from scipy.interpolate import interp1d
import numpy as np
import h5py

__all__ = ["HydraulicJump"]


class HydraulicJump(Postcipe):

    def __init__(self, path):
        Postcipe.__init__(self)
        self.case = tbl.Case(path)
        self.case['alphag'] = 1 - self.case['alpha.waterMean']
        self.U = self.case.boundary_data("inlet", sort="y")[1]['UMean'][0, 0]

        y_inlet = self.case.boundary_data("inlet", sort="y")[0][:, 1]
        inlet_edge_length = tbl.edge_lengths(self.case, "inlet")
        self.d = y_inlet[-1] + 0.5*inlet_edge_length[-1]
        self.Fr1 = self.U/np.sqrt(9.81*self.d)
        self.d2 = self.d*(np.sqrt(1 + 8*self.Fr1**2) - 1)/2
        self.Fr2 = self.U/np.sqrt(9.81*self.d2)

        iso05 = tbl.isoline(self.case, "alpha.waterMean", 0.5)
        idx = iso05[:, 0].argsort()
        self.xfs = iso05[idx, 0]
        self.yfs = iso05[idx, 1]

        idx_toe = np.argmin(np.abs(self.d*1.1 - self.yfs[:int(self.yfs.size/2)]))
        self.xtoe = self.xfs[idx_toe]

[((22, 20, 22, 34), 'turbulucid.Case', 'tbl.Case', ({(22, 29, 22, 33): 'path'}, {}), '(path)', True, 'import turbulucid as tbl\n'), ((27, 28, 27, 64), 'turbulucid.edge_lengths', 'tbl.edge_lengths', ({(27, 45, 27, 54): 'self.case', (27, 56, 27, 63): '"""inlet"""'}, {}), "(self.case, 'inlet')", True, 'import turbulucid as tbl\n'), ((33, 16, 33, 62), 'turbulucid.isoline', 'tbl.isoline', ({(33, 28, 33, 37): 'self.case', (33, 39, 33, 56): '"""alpha.waterMean"""', (33, 58, 33, 61): '0.5'}, {}), "(self.case, 'alpha.waterMean', 0.5)", True, 'import turbulucid as tbl\n'), ((29, 26, 29, 46), 'numpy.sqrt', 'np.sqrt', ({(29, 34, 29, 45): '(9.81 * self.d)'}, {}), '(9.81 * self.d)', True, 'import numpy as np\n'), ((31, 26, 31, 47), 'numpy.sqrt', 'np.sqrt', ({(31, 34, 31, 46): '(9.81 * self.d2)'}, {}), '(9.81 * self.d2)', True, 'import numpy as np\n'), ((30, 26, 30, 52), 'numpy.sqrt', 'np.sqrt', ({(30, 34, 30, 51): '(1 + 8 * self.Fr1 ** 2)'}, {}), '(1 + 8 * self.Fr1 ** 2)', True, 'import numpy as np\n')]