示例#1
0
def forceCoeff(F, Swett, u=None, Re=None, Fr=None, **kwargs):
    """
    Calculates the force coefficient by

    ..math::

        C = \\frac{F}{0.5\\rho S_{wett} u^2}

    :param F: Force
    :type F: float
    :param Swett: Wetted surface area
    :type Swett: float
    :param u: Velocity
    :type u: float
    :param Re: Reynoldsnumber
    :type Re: float
    :param Fr: Froudenumber
    :type Fr: float

    :rtype: float

    :Author: Jens Hoepken <*****@*****.**>
    """

    if not 'rho' in kwargs.iterkeys():
        rho = Constants.water['rho']
    else:
        rho = kwargs['rho']

    if Re:
        u = FlowProperties.Re(Re=Re, L=kwargs['L'])
    elif Fr:
        u = FlowProperties.Fr(Fr=Fr, L=kwargs['L'])

    return F / (0.5 * rho * Swett * u**2)
示例#2
0
    def calculateCoeffs(self):
        """
        If forces exist, the respective coefficients are calculated accordingly.
        Otherwise a ValueError is raised.

        :param L: Reference length
        :type L: float
        :param A: Reference area
        :type A: float
        """
        self.uInf = Utilities.mag(self.inletVelocity)
        self.Re = FlowProperties.Re(L=self.L, u=self.uInf)
        self.Fr = FlowProperties.Fr(L=self.L, u=self.uInf)

        if self.forces:
            self.t = self.forces[0]
            self.resistances['RF'] = self.direction * self.forces[
                abs(self.direction) + 3]
            self.resistances['RT'] = self.resistances['RF'] +\
                                    self.direction*self.forces[abs(self.direction)]
            self.resistances['CF'] = Resistance.forceCoeff(
                self.resistances['RF'], self.A, u=self.uInf)
            self.resistances['CT'] = Resistance.forceCoeff(
                self.resistances['RT'], self.A, u=self.uInf)
        else:
            raise ValueError
 def testVelToRe(self):
     """
     Tests the conversion from velocity to Reynoldsnumber
     """
     for vel, Reynolds in self.vRe:
         result = FlowProperties.Re(u=vel, L=1.0, nu=Constants.water['nu'])
         self.assertEqual(Reynolds, result)
 def testVelToFr(self):
     """
     Tests the conversion from velocity to Froude number
     """
     for vel, Froude in self.vFr:
         result = FlowProperties.Fr(u=vel, L=1.0, nu=Constants.water['nu'])
         self.assertEqual(Froude, result)
 def testReToVel(self):
     """
     Tests the conversion from Reynoldsnumber to velocity
     """
     for vel, Reynolds in self.vRe:
         result = FlowProperties.Re(Re=Reynolds,
                                    L=1.0,
                                    nu=Constants.water['nu'])
         self.assertEqual(vel, result)
 def testFrToVel(self):
     """
     Tests the conversion from Froude nubmer to velocity
     """
     for vel, Froude in self.vFr:
         result = FlowProperties.Fr(Fr=Froude,
                                    L=1.0,
                                    nu=Constants.water['nu'])
         self.assertEqual(vel, result)
示例#7
0
    def updateInletVelocity(self):
        """
        Reads and updates the inlet velocity. This has to be done without
        pyFoam, as this takes *ages* for a file with precalculated
        velocities.
        """
        inletFound = False
        with open(join(self.name, self.first, 'U'), 'r') as bc:
            for line in bc:
                for patchI in self.inletPatch:
                    if patchI in line:
                        inletFound = True
                    if inletFound:
                        if "uniform" in line:
                            vIn = line
                            break

        numberRe = compile(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?")
        self.inletVelocity = [float(uI) for uI in findall(numberRe, vIn)]
        self.uInf = Utilities.mag(self.inletVelocity)
        self.Re = FlowProperties.Re(L=self.L, u=self.uInf)
        self.Fr = FlowProperties.Fr(L=self.L, u=self.uInf)
示例#8
0
def schoenherr(**kwargs):
    """
    Calculates the viscous drag coefficient :math:`C_{F0}` for the skin friction
    according to the Schoenherr line.

    ..math::

        \\frac{0.242}{\sqrt{C_F}} = \log_{10} (C_F Re)

    It is not necessary to hand a Reynoldsnumber to the function. If a velocity
    or Froudenumber and a reference length is passed, the Reynoldsnumber is
    derived accordingly.

    :param Re: Reynoldsnumber
    :type Re: float
    :param Fr: Froudenumber
    :type Fr: float
    :param u: Velocity :math:`[\\frac{m}{s}]`
    :type u: float
    :param L: Reference length :math:`[m]`
    :type L: float

    :rtype: float

    :Author: Jens Hoepken <*****@*****.**>
    """
    if 'Re' in kwargs.iterkeys():
        Re = kwargs['Re']
    else:
        u, Fr, Re = FlowProperties.uFrRe(**kwargs)

    iteration = 100.0

    for CdI in arange(0.001, 0.007, 0.00001):
        if abs(0.242 / sqrt(CdI) - log(CdI * Re, 10)) < iteration:
            iteration = 0.242 / sqrt(CdI) - log(CdI * Re, 10)
            Cd = CdI
        else:
            return Cd
    return 0.0
示例#9
0
def schoenherr(**kwargs):
    """
    Calculates the viscous drag coefficient :math:`C_{F0}` for the skin friction
    according to the Schoenherr line.

    ..math::

        \\frac{0.242}{\sqrt{C_F}} = \log_{10} (C_F Re)

    It is not necessary to hand a Reynoldsnumber to the function. If a velocity
    or Froudenumber and a reference length is passed, the Reynoldsnumber is
    derived accordingly.

    :param Re: Reynoldsnumber
    :type Re: float
    :param Fr: Froudenumber
    :type Fr: float
    :param u: Velocity :math:`[\\frac{m}{s}]`
    :type u: float
    :param L: Reference length :math:`[m]`
    :type L: float

    :rtype: float

    :Author: Jens Hoepken <*****@*****.**>
    """
    if "Re" in kwargs.iterkeys():
        Re = kwargs["Re"]
    else:
        u, Fr, Re = FlowProperties.uFrRe(**kwargs)

    iteration = 100.0

    for CdI in arange(0.001, 0.007, 0.00001):
        if abs(0.242 / sqrt(CdI) - log(CdI * Re, 10)) < iteration:
            iteration = 0.242 / sqrt(CdI) - log(CdI * Re, 10)
            Cd = CdI
        else:
            return Cd
    return 0.0
示例#10
0
def ittc57(**kwargs):
    """
    Calculates the viscous drag coefficient :math:`C_D` for the skin friction 
    according to the ITTC'57 correlation line, which already accounts for 
    approximately 12% of pressure induced friction and should therefore 
    overestimate the skin friction of e.g. a plain turbulent plate.

    ..math::

        C_F = \\frac{0.075}{(\log Re - 2)^2}

    It is not necessary to hand a Reynoldsnumber to the function. If a velocity
    or Froudenumber and a reference length is passed, the Reynoldsnumber is
    derived accordingly.

    :param Re: Reynoldsnumber
    :type Re: float
    :param Fr: Froudenumber
    :type Fr: float
    :param u: Velocity :math:`[\\frac{m}{s}]`
    :type u: float
    :param L: Reference length :math:`[m]`
    :type L: float

    :rtype: float

    :Author: Jens Hoepken <*****@*****.**>
    """
    if 'Re' in kwargs.iterkeys():
        Re = kwargs['Re']
    else:
        u, Fr, Re = FlowProperties.uFrRe(**kwargs)

    try:
        return 0.075 / ((log(Re, 10) - 2)**2)
    except TypeError:
        return 0.075 / ((log10(Re) - 2)**2)
示例#11
0
def ittc57(**kwargs):
    """
    Calculates the viscous drag coefficient :math:`C_D` for the skin friction 
    according to the ITTC'57 correlation line, which already accounts for 
    approximately 12% of pressure induced friction and should therefore 
    overestimate the skin friction of e.g. a plain turbulent plate.

    ..math::

        C_F = \\frac{0.075}{(\log Re - 2)^2}

    It is not necessary to hand a Reynoldsnumber to the function. If a velocity
    or Froudenumber and a reference length is passed, the Reynoldsnumber is
    derived accordingly.

    :param Re: Reynoldsnumber
    :type Re: float
    :param Fr: Froudenumber
    :type Fr: float
    :param u: Velocity :math:`[\\frac{m}{s}]`
    :type u: float
    :param L: Reference length :math:`[m]`
    :type L: float

    :rtype: float

    :Author: Jens Hoepken <*****@*****.**>
    """
    if "Re" in kwargs.iterkeys():
        Re = kwargs["Re"]
    else:
        u, Fr, Re = FlowProperties.uFrRe(**kwargs)

    try:
        return 0.075 / ((log(Re, 10) - 2) ** 2)
    except TypeError:
        return 0.075 / ((log10(Re) - 2) ** 2)
示例#12
0
def huges(**kwargs):
    """
    Calculates the viscous drag coefficient :math:`C_{F0}` for the skin friction
    according to the Hughes line. This is not used on a regular basis by the
    model basins, but for simulations dealing with the turbulent flow over e.g.
    a flat plate, this curve gives more accurate results to compare the CFD
    results to.

    ..math::

        C_{F0} = \\frac{0.066}{(\log Re - 2.03)^2}

    It is not necessary to hand a Reynoldsnumber to the function. If a velocity
    or Froudenumber and a reference length is passed, the Reynoldsnumber is
    derived accordingly.

    :param Re: Reynoldsnumber
    :type Re: float
    :param Fr: Froudenumber
    :type Fr: float
    :param u: Velocity :math:`[\\frac{m}{s}]`
    :type u: float
    :param L: Reference length :math:`[m]`
    :type L: float

    :rtype: float

    :Author: Jens Hoepken <*****@*****.**>
    """

    if 'Re' in kwargs.iterkeys():
        Re = kwargs['Re']
    else:
        u, Fr, Re = FlowProperties.uFrRe(**kwargs)

    return 0.066 / ((log(Re, 10) - 2.03)**2)
示例#13
0
def huges(**kwargs):
    """
    Calculates the viscous drag coefficient :math:`C_{F0}` for the skin friction
    according to the Hughes line. This is not used on a regular basis by the
    model basins, but for simulations dealing with the turbulent flow over e.g.
    a flat plate, this curve gives more accurate results to compare the CFD
    results to.

    ..math::

        C_{F0} = \\frac{0.066}{(\log Re - 2.03)^2}

    It is not necessary to hand a Reynoldsnumber to the function. If a velocity
    or Froudenumber and a reference length is passed, the Reynoldsnumber is
    derived accordingly.

    :param Re: Reynoldsnumber
    :type Re: float
    :param Fr: Froudenumber
    :type Fr: float
    :param u: Velocity :math:`[\\frac{m}{s}]`
    :type u: float
    :param L: Reference length :math:`[m]`
    :type L: float

    :rtype: float

    :Author: Jens Hoepken <*****@*****.**>
    """

    if "Re" in kwargs.iterkeys():
        Re = kwargs["Re"]
    else:
        u, Fr, Re = FlowProperties.uFrRe(**kwargs)

    return 0.066 / ((log(Re, 10) - 2.03) ** 2)
示例#14
0
def main():
    parser = OptionParser(
        usage="usage: %prog [options] area ref.Length (case)",
        version="%prog 1.0")

    parser.add_option(
        "-U",
        "--velocity",
        action="store",
        dest="U",
        type="string",
        default="False",
        help="Velocity vector as a list \"[x,y,z]\". If nothing is\
                        stated, a inlet patch needs to be specified. From that\
                        patch, the velocity is read automatically.")
    parser.add_option("-i",
                      "--inlet",
                      action="store",
                      dest="inletPatch",
                      type="string",
                      default="XMAX",
                      help="Name of the inlet patch. (default=XMAX)")
    parser.add_option(
        "-s",
        "--start",
        action="store",
        dest="startAtTime",
        type="float",
        default=0.0,
        help="Starttime of the plotting interval, spanning from that\
                        time to the end. (default=0.0)")
    parser.add_option(
        "-d",
        "--deviation-start",
        action="store",
        dest="deviationInterval",
        type="float",
        default=0.5,
        help="Specifies over which part of the plotted interval, the\
                        relative deviation between CF and ITTC\'57 as well as\
                        the average of CF should be calculated. (default=0.5)")
    parser.add_option("-f",
                      action="store",
                      type="choice",
                      choices=['1', '2', '3'],
                      dest="direction",
                      default=1,
                      help="Main flow direction (1=x,2=y,3=z). (default=1)")

    (options, args) = parser.parse_args()

    if len(args) == 2:
        caseDir = getcwd()
    elif len(args) == 3:
        caseDir = args[2]
    else:
        parser.error("wrong number of arguments")

    area = float(args[0])
    L = float(args[1])
    U = eval(options.U)

    startAtElement = 0
    deviationStartElement = 0

    case = Case.case(caseDir,
                     archive=None,
                     paraviewLink=False,
                     inletPatch=options.inletPatch,
                     U=U)

    uInf = Utilities.mag(case.inletVelocity)
    Re = FlowProperties.Re(L=L, u=uInf)

    data = case.forces

    t = data[0]
    RF = abs(data[options.direction + 3])
    RT = RF + abs(data[options.direction])

    # The list element of the time has to be figured out, beyond which the
    # plotting should start.
    if options.startAtTime > 0.0:
        for i in range(0, len(data[0])):
            if data[0][i] > options.startAtTime:
                startAtElement = i
                break

    # Determine the start element for the deviation calculation
    deviationStartElement = startAtElement + \
            int(len(t[startAtElement:])*(1-options.deviationInterval))

    # Gather all data
    CF = Resistance.forceCoeff(RF, area, u=uInf)
    CT = Resistance.forceCoeff(RT, area, u=uInf)
    ittc57 = ones(len(CT)) * SkinFriction.ittc57(Re=Re)
    deviationList = CF * 100.0 / ittc57 - 100

    # Calculate the relative error between CF and ITTC57 for the respective
    # intervall
    deviation = sum(deviationList[deviationStartElement:]) / \
                len(deviationList[deviationStartElement:])

    # Calculate mean value of CF for the respective interval
    CFmean = mean(CF[deviationStartElement:])

    fig = plt.figure()

    plt.title("case: %s\nCFmean = %.2e, rel.Error = %.2f%%, Re = %.2e" %
              (case.shortCasePath, CFmean, deviation, Re))
    plt.grid(True)
    ax1 = fig.add_subplot(111)
    plt.grid(True)
    ax2 = ax1.twinx()
    CFPlot = ax1.plot(t[startAtElement:],
                      CF[startAtElement:],
                      '-',
                      label='C_F',
                      color='green')
    ittc57Plot = ax1.plot(t[startAtElement:],
                          ittc57[startAtElement:],
                          '-',
                          label='ITTC57',
                          color='red')

    CTPlot = ax2.plot(t[startAtElement:],
                      CT[startAtElement:],
                      '-',
                      label='C_T')

    ax1.fill_between(t[deviationStartElement:],
                     CF[deviationStartElement:],
                     ittc57[deviationStartElement:],
                     color="green",
                     alpha=0.5)

    ax1.set_xlabel("simulation time [s]")
    ax1.set_ylabel("CF [-]")
    ax2.set_ylabel("CT [-]")
    #ax1.set_ylim([
    #            0,
    #            1.2*max(CF[startAtElement].max(),ittc57[0])
    #            ])

    lines = CFPlot + ittc57Plot + CTPlot
    labels = [l.get_label() for l in lines]
    plt.legend(
        lines,
        labels,
        loc=9,
        #bbox_to_anchor=(0., 1.02, 1., .102),
        ncol=3,
        mode="expand")
    plt.show()