Ejemplo n.º 1
0
        def dC2_dx(x, y):
            # If called for x == 0 or x == Nx-1 return 0.0 (zero flux through boundaries).
            if (x == 0 or x == Nx - 1):
                return csNumber_t(0.0)

            ci1 = C2(x + 1, y)
            ci2 = C2(x - 1, y)
            return (ci1 - ci2) / (2 * dx)
Ejemplo n.º 2
0
        def dC2_dy(x, y):
            # If called for y == 0 or y == Ny-1  return 0.0 (zero flux through boundaries).
            if (y == 0 or y == Ny - 1):
                return csNumber_t(0.0)

            ci1 = C2(x, y + 1)
            ci2 = C2(x, y - 1)
            return (ci1 - ci2) / (2 * dy)
Ejemplo n.º 3
0
        def d2C2_dy2(x, y):
            # If called for y == 0 or y == Ny-1 return 0.0 (no diffusion through boundaries).
            if (y == 0 or y == Ny - 1):
                return csNumber_t(0.0)

            ci1 = C2(x, y + 1)
            ci = C2(x, y)
            ci2 = C2(x, y - 1)
            return (ci1 - 2 * ci + ci2) / (dy * dy)
Ejemplo n.º 4
0
        def d2C2_dx2(x, y):
            # If called for x == 0 or x == Nx-1 return 0.0 (no diffusion through boundaries).
            if (x == 0 or x == Nx - 1):
                return csNumber_t(0.0)

            ci1 = C2(x + 1, y)
            ci = C2(x, y)
            ci2 = C2(x - 1, y)
            return (ci1 - 2 * ci + ci2) / (dx * dx)
Ejemplo n.º 5
0
    def CreateEquations(self, y, time):
        # y is a list of csNumber_t objects representing model variables
        C1_values = y[self.C1_start_index:self.C2_start_index]
        C2_values = y[self.C2_start_index:self.Nequations]

        dx = self.dx
        dy = self.dy
        Nx = self.Nx
        Ny = self.Ny
        x_domain = self.x_domain
        y_domain = self.y_domain

        # Math. functions
        sin = pyOpenCS.sin
        acos = pyOpenCS.acos
        exp = pyOpenCS.exp
        cs_max = pyOpenCS.max

        nonzero = csNumber_t(1E-30)

        def Kv(y):
            return Kv0 * numpy.exp(y_domain[y] / 5.0)

        def q3(time):
            w = numpy.arccos(-1.0) / 43200.0
            sinwt = cs_max(nonzero, sin(w * time))
            return exp(-a3 / sinwt)

        def q4(time):
            w = numpy.arccos(-1.0) / 43200.0
            sinwt = cs_max(nonzero, sin(w * time))
            return exp(-a4 / sinwt)

        def R1(c1, c2, time):
            return -q1 * c1 * C3 - q2 * c1 * c2 + 2 * q3(time) * C3 + q4(
                time) * c2

        def R2(c1, c2, time):
            return q1 * c1 * C3 - q2 * c1 * c2 - q4(time) * c2

        def C1(x, y):
            index = self.GetIndex(x, y)
            return C1_values[index]

        def C2(x, y):
            index = self.GetIndex(x, y)
            return C2_values[index]

        # First order partial derivative per x.
        def dC1_dx(x, y):
            # If called for x == 0 or x == Nx-1 return 0.0 (zero flux through boundaries).
            if (x == 0 or x == Nx - 1):
                return csNumber_t(0.0)

            ci1 = C1(x + 1, y)
            ci2 = C1(x - 1, y)
            return (ci1 - ci2) / (2 * dx)

        def dC2_dx(x, y):
            # If called for x == 0 or x == Nx-1 return 0.0 (zero flux through boundaries).
            if (x == 0 or x == Nx - 1):
                return csNumber_t(0.0)

            ci1 = C2(x + 1, y)
            ci2 = C2(x - 1, y)
            return (ci1 - ci2) / (2 * dx)

        # First order partial derivative per y.
        def dC1_dy(x, y):
            # If called for y == 0 or y == Ny-1 return 0.0 (zero flux through boundaries).
            if (y == 0 or y == Ny - 1):
                return csNumber_t(0.0)

            ci1 = C1(x, y + 1)
            ci2 = C1(x, y - 1)
            return (ci1 - ci2) / (2 * dy)

        def dC2_dy(x, y):
            # If called for y == 0 or y == Ny-1  return 0.0 (zero flux through boundaries).
            if (y == 0 or y == Ny - 1):
                return csNumber_t(0.0)

            ci1 = C2(x, y + 1)
            ci2 = C2(x, y - 1)
            return (ci1 - ci2) / (2 * dy)

        # Second order partial derivative per x.
        def d2C1_dx2(x, y):
            # If called for x == 0 or x == Nx-1 return 0.0 (no diffusion through boundaries).
            if (x == 0 or x == Nx - 1):
                return csNumber_t(0.0)

            ci1 = C1(x + 1, y)
            ci = C1(x, y)
            ci2 = C1(x - 1, y)
            return (ci1 - 2 * ci + ci2) / (dx * dx)

        def d2C2_dx2(x, y):
            # If called for x == 0 or x == Nx-1 return 0.0 (no diffusion through boundaries).
            if (x == 0 or x == Nx - 1):
                return csNumber_t(0.0)

            ci1 = C2(x + 1, y)
            ci = C2(x, y)
            ci2 = C2(x - 1, y)
            return (ci1 - 2 * ci + ci2) / (dx * dx)

        # Second order partial derivative per y.
        def d2C1_dy2(x, y):
            # If called for y == 0 or y == Ny-1 return 0.0 (no diffusion through boundaries).
            if (y == 0 or y == Ny - 1):
                return csNumber_t(0.0)

            ci1 = C1(x, y + 1)
            ci = C1(x, y)
            ci2 = C1(x, y - 1)
            return (ci1 - 2 * ci + ci2) / (dy * dy)

        def d2C2_dy2(x, y):
            # If called for y == 0 or y == Ny-1 return 0.0 (no diffusion through boundaries).
            if (y == 0 or y == Ny - 1):
                return csNumber_t(0.0)

            ci1 = C2(x, y + 1)
            ci = C2(x, y)
            ci2 = C2(x, y - 1)
            return (ci1 - 2 * ci + ci2) / (dy * dy)

        eq = 0
        equations = [None] * self.Nequations
        # Component 2 (C1):
        for x in range(Nx):
            for y in range(Ny):
                equations[eq] = V  * dC1_dx(x,y) +  \
                                Kh * d2C1_dx2(x,y) + \
                                Kv(y) * (0.2 * dC1_dy(x,y) + d2C1_dy2(x,y)) + \
                                R1(C1(x,y), C2(x,y), time)
                eq += 1

        # Component 2 (C2):
        for x in range(Nx):
            for y in range(Ny):
                equations[eq] = V  * dC2_dx(x,y) + \
                                Kh * d2C2_dx2(x,y) + \
                                Kv(y) * (0.2 * dC2_dy(x,y) + d2C2_dy2(x,y)) + \
                                R2(C1(x,y), C2(x,y), time)
                eq += 1

        return equations