コード例 #1
0
    def __init__(self, dimNames, data):
        FunctionBase.__init__(self, dimNames)
        self.C0 = float(data.v('C0'))

        # call checkVariables method of FunctionBase to make sure that the input is correct
        FunctionBase.checkVariables(self, ('C0', self.C0))
        return
コード例 #2
0
    def derivative(self, x, **kwargs):
        if kwargs.get('dim') == 'x':
            coef = self.data.v('coef', x=x)
            H = self.data.v('grid', 'low', 'z', x=x) - self.data.v('grid', 'high', 'z', x=x)
            coefx = self.data.d('coef', x=x, dim='x')
            Hx = self.data.d('grid', 'low', 'z', x=x, dim='x') - self.data.d('grid', 'high', 'z', x=x, dim='x')

            val = coefx * ((H / self.H0) ** self.m) + coef * (self.m * Hx * (H / self.H0) ** self.m / H)
        elif kwargs.get('dim') == 'xx':
            coef = self.data.v('coef', x=x)
            H = self.data.v('grid', 'low', 'z', x=x) - self.data.v('grid', 'high', 'z', x=x)
            coefx = self.data.d('coef', x=x, dim='x')
            Hx = self.data.d('grid', 'low', 'z', x=x, dim='x') - self.data.d('grid', 'high', 'z', x=x, dim='x')
            coefxx = self.data.d('coef', x=x, dim='xx')
            Hxx = self.data.d('grid', 'low', 'z', x=x, dim='xx') - self.data.d('grid', 'high', 'z', x=x, dim='xx')

            val = coefxx * (H / self.H0) ** self.m + 2. * coefx * self.m * Hx * H ** (
            self.m - 1) / self.H0 ** self.m + coef * self.m * (self.m - 1) * Hx ** 2 * H ** (
            self.m - 2) / self.H0 ** self.m + coef * self.m * Hxx * H ** (self.m - 1) / self.H0 ** self.m

        elif 'z' in kwargs.get('dim'):
            val = 0.
        else:
            val = None
            FunctionBase.derivative(self)
        return val
コード例 #3
0
    def derivative(self, x, **kwargs):
        """
        Parameters:
            x - value between 0 and 1
        """
        x = x*self.L
        expC = np.exp(np.polyval(self.C1, x)/np.polyval(self.C2, x))
        C1x = np.polyder(self.C1)
        C2x = np.polyder(self.C2)

        if kwargs['dim'] == 'x':
            Cx = (np.polyval(C1x, x)*np.polyval(self.C2, x) -
                  np.polyval(self.C1, x)*np.polyval(C2x, x))/np.polyval(self.C2, x)**2
            return 1000*Cx*expC

        elif kwargs['dim'] == 'xx':
            C1xx = np.polyder(C1x)
            C2xx = np.polyder(C2x)
            Cx = (np.polyval(C1x, x)*np.polyval(self.C2, x) -
                  np.polyval(self.C1, x)*np.polyval(C2x, x))/np.polyval(self.C2, x)**2
            Cxx = (np.polyval(C1xx, x)*np.polyval(self.C2, x)**2 +
                   2*np.polyval(self.C1, x)*np.polyval(C2x, x)**2 -
                   2*np.polyval(C1x, x)*np.polyval(self.C2, x)*np.polyval(C2x, x) -
                   np.polyval(self.C1, x)*np.polyval(self.C2, x)*np.polyval(C2xx, x)) / np.polyval(self.C2, x)**3
            return 1000*(Cx**2 + Cxx)*expC
        else:
            FunctionBase.derivative(self)
            return
コード例 #4
0
 def __init__(self, dimNames, data):
     FunctionBase.__init__(self, dimNames)
     self.L = float(data.v('L'))
     self.C1 = np.array(data.v('C1'))
     self.C2 = np.array(data.v('C2'))
     FunctionBase.checkVariables(self, ('L', self.L), ('C1', self.C1), ('C2', self.C2))
     return
コード例 #5
0
ファイル: UniformXF.py プロジェクト: mstiegl/iFlow
    def __init__(self, dimNames, data, m):
        """Initialise a uniform profile.

        Args:
            dimNames: see function
            data (DataContainer) - DataContainer with
                 - magnitude (Av0)
                 - grid
            m (real) - power for H/H0
        """
        FunctionBase.__init__(self, dimNames)
        self.m = m
        self.data = data
        self.H0 = self.data.v('grid', 'low', 'z', x=0) - self.data.v(
            'grid', 'high', 'z', x=0)

        # change grid to remove z dimension
        self.data.data['grid'] = copy.copy(self.data.data['grid'])
        self.data.data['grid']['dimensions'] = dimNames
        if 'f' in dimNames:
            self.data.data['grid']['axis'] = copy.copy(
                self.data.data['grid']['axis'])

            lenf = self.data.data['grid']['axis']['f'].shape[-1]
            self.data.data['grid']['axis']['f'] = self.data.data['grid'][
                'axis']['f'].reshape(1, lenf)
            self.data.data['grid']['contraction'] = np.asarray([[0, 0], [0,
                                                                         0]])
        return
コード例 #6
0
 def __init__(self, dimNames, data):
     FunctionBase.__init__(self, dimNames)
     self.L = float(data.v('L'))
     self.C0 = float(data.v('C0'))
     self.CL = float(data.v('CL'))
     FunctionBase.checkVariables(self, ('C0', self.C0), ('CL', self.CL),
                                 ('L', self.L))
     return
コード例 #7
0
 def __init__(self, dimNames, data):
     FunctionBase.__init__(self, dimNames)
     self.L = float(data.v('L'))
     self.alpha = float(data.v('alpha'))
     self.beta = float(data.v('beta'))
     self.gamma = float(data.v('gamma'))
     self.xc = float(data.v('xc'))
     self.xl = float(data.v('xl'))
     FunctionBase.checkVariables(self, ('alpha', self.alpha),
                                 ('beta', self.beta), ('xc', self.xc),
                                 ('xl', self.xl), ('L', self.L))
     return
コード例 #8
0
    def derivative(self, x, f, **kwargs):
        if kwargs['dim'] == 'x':
            x = np.asarray(x*self.L)
            f = [1-bool(j) for j in toList(f)]
            f = np.asarray(f).reshape(1, len(f))

            sx = -self.ssea/self.Ls*np.exp(-x/self.Ls)
            sx = sx.reshape(len(sx), 1)*f
        else:
            sx = None
            FunctionBase.derivative(self)
        return sx
コード例 #9
0
    def derivative(self, x, f, **kwargs):
        if kwargs['dim'] == 'x':
            x = np.asarray(x*self.L)
            f = [1-bool(j) for j in toList(f)]
            f = np.asarray(f).reshape(1,len(f))

            sx = self.ssea/2.*(np.tanh((x-self.xc)/self.xl)**2-1)/self.xl
            sx = sx.reshape(len(sx),1)*f
        else:
            sx = None
            FunctionBase.derivative(self)
        return sx
コード例 #10
0
    def __init__(self, dimNames, data):
        FunctionBase.__init__(self, dimNames)
        self.L = float(data.v('L'))
        self.C0 = data.v('C0')
        self.C1 = data.v('C1')
        self.xc = float(data.v('xc'))
        self.xl = float(data.v('xl'))

        # call checkVariables method of FunctionBase to make sure that the input is correct
        FunctionBase.checkVariables(self, ('C0', self.C0), ('C1', self.C1),
                                    ('xc', self.xc), ('xl', self.xl),
                                    ('L', self.L))
        return
コード例 #11
0
    def __init__(self, dimNames, data):
        FunctionBase.__init__(self, dimNames)
        self.L = float(data.v('L'))
        self.C = np.array(data.v('C'))
        self.XL = float(np.array(data.v('XL')))
        FunctionBase.checkVariables(self, ('C', self.C), ('XL', self.XL),
                                    ('L', self.L))

        # coefficients for the linear function
        self.C_lin = np.asarray([
            np.polyval(np.polyder(self.C), self.XL),
            np.polyval(self.C, self.XL)
        ])
        return
コード例 #12
0
 def derivative(self, x, **kwargs):
     """
     Parameters:
         x - value between 0 and 1
     """
     if kwargs['dim'] == 'x':
         x = x * self.L
         return -self.C0 / self.Lc * exp(-x / self.Lc)
     elif kwargs['dim'] == 'xx':
         x = x * self.L
         return self.C0 / (self.Lc**2) * exp(-x / self.Lc)
     else:
         FunctionBase.derivative(self)
         return
コード例 #13
0
    def __init__(self, dimNames, data, m):
        """Initialise a uniform profile with x dependency via H/H0

        Args:
            dimNames: see function
            data (DataContainer) - DataContainer with
                 - magnitude (Av0)
                 - grid
            m (real) - power for H/H0
        """
        FunctionBase.__init__(self, dimNames)
        self.m = m
        self.data = data
        self.H0 = self.data.v('grid', 'low', 'z', x=0) - self.data.v('grid', 'high', 'z', x=0)
        return
コード例 #14
0
ファイル: Polynomial.py プロジェクト: mstiegl/iFlow
 def derivative(self, x, **kwargs):
     """
     Parameters:
         x - value between 0 and 1
     """
     x = x * self.L
     Cx = np.polyder(self.C)
     if kwargs['dim'] == 'x':
         return np.polyval(Cx, x)
     elif kwargs['dim'] == 'xx':
         Cxx = np.polyder(Cx)
         return np.polyval(Cxx, x)
     else:
         FunctionBase.derivative(self)
         return
コード例 #15
0
 def derivative(self, x, **kwargs):
     """
     Parameters:
         x - value between 0 and 1
     """
     if kwargs['dim'] == 'x':
         x = x * self.L
         return self.C1 * (1 - np.tanh(
             (x - self.xc) / self.xl)**2) / self.xl
     elif kwargs['dim'] == 'xx':
         x = x * self.L
         return -self.C1 * 2. * np.tanh(
             (x - self.xc) / self.xl) * (1 - np.tanh(
                 (x - self.xc) / self.xl)**2.) / self.xl**2
     else:
         FunctionBase.derivative(self)
         return
コード例 #16
0
    def __init__(self, dimNames, data, m):
        """Initialise a parabolic profile.

        Args:
            dimNames: see function
            coef (complex array) - needs to be a real/complex array in shape (x,1,f) (length of x may be 1)
            data (DataContainer) - DataContainer with
                 - roughness (z0*)
                 - roughness (zs*)
                 - magnitude (coef)
                 - grid
            m (real) - power for H/H0

        """
        FunctionBase.__init__(self, dimNames)
        self.data = data
        self.m = m
        self.H0 = self.data.v('grid', 'low', 'z', x=0) - self.data.v(
            'grid', 'high', 'z', x=0)

        return
コード例 #17
0
    def derivative(self, x, z, f, **kwargs):
        if kwargs.get('dim') == 'z':
            z = z.reshape((1, len(z), 1))
            coef = self.data.v('coef', x=x, z=z, f=f)
            H = self.data.v('grid', 'low', 'z', x=x, z=z, f=f) - self.data.v(
                'grid', 'high', 'z', x=x, z=z, f=f)
            z0_dimless = self.data.v('z0*', x=x, z=z, f=f)
            zs_dimless = self.data.v('zs*', x=x, z=z, f=f)

            Avz = coef / H * (-2. * (-z) - 1. - z0_dimless +
                              zs_dimless) * (H / self.H0)**self.m

        elif kwargs.get('dim') == 'zz':
            coef = self.data.v('coef', x=x, z=z, f=f)
            H = self.data.v('grid', 'low', 'z', x=x, z=z, f=f) - self.data.v(
                'grid', 'high', 'z', x=x, z=z, f=f)

            Avz = -2. * coef / H**2. * (H / self.H0)**self.m
        else:
            Avz = None
            FunctionBase.derivative(
                self)  # derivatives in other directions not implemented
        return Avz
コード例 #18
0
 def derivative(self, x, **kwargs):
     """
     Parameters:
         x - value between 0 and 1
     """
     x = x * self.L
     Cx = np.polyder(self.C)
     Cx_lin = np.polyder(self.C_lin)
     p = np.zeros(len(x))
     if kwargs['dim'] == 'x':
         p[np.where(x <= self.XL)] = np.polyval(Cx,
                                                x[np.where(x <= self.XL)])
         p[np.where(x > self.XL)] = np.polyval(
             Cx_lin, x[np.where(x > self.XL)] - self.XL)
         return p
     elif kwargs['dim'] == 'xx':
         Cxx = np.polyder(Cx)
         p[np.where(x <= self.XL)] = np.polyval(Cxx,
                                                x[np.where(x <= self.XL)])
         return p
     else:
         FunctionBase.derivative(self)
         return
コード例 #19
0
 def __init__(self, input):
     self.__input = input
     FunctionBase.__init__(self, ['x', 'f'])
     return
コード例 #20
0
 def __init__(self, dimNames, data):
     FunctionBase.__init__(self, dimNames)
     self.H = data
     return
コード例 #21
0
ファイル: Polynomial.py プロジェクト: mstiegl/iFlow
 def __init__(self, dimNames, data):
     FunctionBase.__init__(self, dimNames)
     self.L = float(data.v('L'))
     self.C = np.array(ny.toList(data.v('C')))
     FunctionBase.checkVariables(self, ('C', self.C), ('L', self.L))
     return