Esempio n. 1
0
    def __init__(self, h_in, x0_in=None):
        assert type(h_in) in [list, tuple], 'h_in must be a list'
        assert len(h_in) in [1,2,3], 'h_in must be of dimension 1, 2, or 3'
        h = range(len(h_in))
        for i, h_i in enumerate(h_in):
            if Utils.isScalar(h_i) and type(h_i) is not np.ndarray:
                # This gives you something over the unit cube.
                h_i = self._unitDimensions[i] * np.ones(int(h_i))/int(h_i)
            elif type(h_i) is list:
                h_i = Utils.meshTensor(h_i)
            assert isinstance(h_i, np.ndarray), ("h[%i] is not a numpy array." % i)
            assert len(h_i.shape) == 1, ("h[%i] must be a 1D numpy array." % i)
            h[i] = h_i[:] # make a copy.

        x0 = np.zeros(len(h))
        if x0_in is not None:
            assert len(h) == len(x0_in), "Dimension mismatch. x0 != len(h)"
            for i in range(len(h)):
                x_i, h_i = x0_in[i], h[i]
                if Utils.isScalar(x_i):
                    x0[i] = x_i
                elif x_i == '0':
                    x0[i] = 0.0
                elif x_i == 'C':
                    x0[i] = -h_i.sum()*0.5
                elif x_i == 'N':
                    x0[i] = -h_i.sum()
                else:
                    raise Exception("x0[%i] must be a scalar or '0' to be zero, 'C' to center, or 'N' to be negative." % i)

        BaseRectangularMesh.__init__(self, np.array([x.size for x in h]), x0)

        # Ensure h contains 1D vectors
        self._h = [Utils.mkvc(x.astype(float)) for x in h]
Esempio n. 2
0
    def _fastInnerProduct(self, projType, prop=None, invProp=False, invMat=False):
        """
            Fast version of getFaceInnerProduct.
            This does not handle the case of a full tensor prop.

            :param numpy.array prop: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
            :param str projType: 'E' or 'F'
            :param bool returnP: returns the projection matrices
            :param bool invProp: inverts the material property
            :param bool invMat: inverts the matrix
            :rtype: scipy.sparse.csr_matrix
            :return: M, the inner product matrix (nF, nF)
        """
        assert projType in ['F', 'E'], ("projType must be 'F' for faces or 'E'"
                                        " for edges")

        if prop is None:
            prop = np.ones(self.nC)

        if invProp:
            prop = 1./prop

        if Utils.isScalar(prop):
            prop = prop*np.ones(self.nC)

        # number of elements we are averaging (equals dim for regular
        # meshes, but for cyl, where we use symmetry, it is 1 for edge
        # variables and 2 for face variables)
        if self._meshType == 'CYL':
            n_elements = np.sum(getattr(self, 'vn'+projType).nonzero())
        else:
            n_elements = self.dim

        # Isotropic? or anisotropic?
        if prop.size == self.nC:
            Av = getattr(self, 'ave'+projType+'2CC')
            Vprop = self.vol * Utils.mkvc(prop)
            M = n_elements * Utils.sdiag(Av.T * Vprop)

        elif prop.size == self.nC*self.dim:
            Av = getattr(self, 'ave'+projType+'2CCV')

            # if cyl, then only certain components are relevant due to symmetry
            # for faces, x, z matters, for edges, y (which is theta) matters
            if self._meshType == 'CYL':
                if projType == 'E':
                    prop = prop[:, 1] # this is the action of a projection mat
                elif projType == 'F':
                    prop = prop[:, [0, 2]]

            V = sp.kron(sp.identity(n_elements), Utils.sdiag(self.vol))
            M = Utils.sdiag(Av.T * V * Utils.mkvc(prop))
        else:
            return None

        if invMat:
            return Utils.sdInv(M)
        else:
            return M
Esempio n. 3
0
 def transform(self, u, m):
     self.setModel(m)
     f = np.exp(self.Ks)*self.A/(self.A+abs(u)**self.gamma)
     if Utils.isScalar(self.Ks):
         f[u >= 0] = np.exp(self.Ks)
     else:
         f[u >= 0] = np.exp(self.Ks[u >= 0])
     return f
Esempio n. 4
0
 def transform(self, u, m):
     self.setModel(m)
     f = np.exp(self.Ks)*self.A/(self.A+abs(u)**self.gamma)
     if Utils.isScalar(self.Ks):
         f[u >= 0] = np.exp(self.Ks)
     else:
         f[u >= 0] = np.exp(self.Ks[u >= 0])
     return f
Esempio n. 5
0
 def transform(self, u, m):
     self.setModel(m)
     f = self.alpha * (self.theta_s - self.theta_r) / (self.alpha + abs(u) ** self.beta) + self.theta_r
     if Utils.isScalar(self.theta_s):
         f[u >= 0] = self.theta_s
     else:
         f[u >= 0] = self.theta_s[u >= 0]
     return f
Esempio n. 6
0
    def _fastInnerProduct(self, projType, prop=None, invProp=False, invMat=False):
        """
            Fast version of getFaceInnerProduct.
            This does not handle the case of a full tensor prop.

            :param numpy.array prop: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
            :param str projType: 'E' or 'F'
            :param bool returnP: returns the projection matrices
            :param bool invProp: inverts the material property
            :param bool invMat: inverts the matrix
            :rtype: scipy.sparse.csr_matrix
            :return: M, the inner product matrix (nF, nF)
        """
        assert projType in ["F", "E"], "projType must be 'F' for faces or 'E'" " for edges"

        if prop is None:
            prop = np.ones(self.nC)

        if invProp:
            prop = 1.0 / prop

        if Utils.isScalar(prop):
            prop = prop * np.ones(self.nC)

        # number of elements we are averaging (equals dim for regular
        # meshes, but for cyl, where we use symmetry, it is 1 for edge
        # variables and 2 for face variables)
        if self._meshType == "CYL":
            n_elements = np.sum(getattr(self, "vn" + projType).nonzero())
        else:
            n_elements = self.dim

        # Isotropic? or anisotropic?
        if prop.size == self.nC:
            Av = getattr(self, "ave" + projType + "2CC")
            Vprop = self.vol * Utils.mkvc(prop)
            M = n_elements * Utils.sdiag(Av.T * Vprop)

        elif prop.size == self.nC * self.dim:
            Av = getattr(self, "ave" + projType + "2CCV")

            # if cyl, then only certain components are relevant due to symmetry
            # for faces, x, z matters, for edges, y (which is theta) matters
            if self._meshType == "CYL":
                if projType == "E":
                    prop = prop[:, 1]  # this is the action of a projection mat
                elif projType == "F":
                    prop = prop[:, [0, 2]]

            V = sp.kron(sp.identity(n_elements), Utils.sdiag(self.vol))
            M = Utils.sdiag(Av.T * V * Utils.mkvc(prop))
        else:
            return None

        if invMat:
            return Utils.sdInv(M)
        else:
            return M
Esempio n. 7
0
 def transform(self, u, m):
     self.setModel(m)
     f = (self.alpha*(self.theta_s  -    self.theta_r  )/
                     (self.alpha    + abs(u)**self.beta) + self.theta_r)
     if Utils.isScalar(self.theta_s):
         f[u >= 0] = self.theta_s
     else:
         f[u >= 0] = self.theta_s[u >= 0]
     return f
Esempio n. 8
0
    def transform(self, u, m):
        self.setModel(m)
        m = 1 - 1.0 / self.n
        f = (self.theta_s - self.theta_r) / ((1 + abs(self.alpha * u) ** self.n) ** m) + self.theta_r
        if Utils.isScalar(self.theta_s):
            f[u >= 0] = self.theta_s
        else:
            f[u >= 0] = self.theta_s[u >= 0]

        return f
Esempio n. 9
0
    def __init__(self, h_in, x0_in=None):
        assert type(h_in) in [list, tuple], 'h_in must be a list'
        assert len(h_in) in [1, 2, 3], 'h_in must be of dimension 1, 2, or 3'
        h = list(range(len(h_in)))
        for i, h_i in enumerate(h_in):
            if Utils.isScalar(h_i) and type(h_i) is not np.ndarray:
                # This gives you something over the unit cube.
                h_i = self._unitDimensions[i] * np.ones(int(h_i)) / int(h_i)
            elif type(h_i) is list:
                h_i = Utils.meshTensor(h_i)
            assert isinstance(
                h_i, np.ndarray), ("h[{0:d}] is not a numpy array.".format(i))
            assert len(h_i.shape) == 1, (
                "h[{0:d}] must be a 1D numpy array.".format(i))
            h[i] = h_i[:]  # make a copy.

        x0 = np.zeros(len(h))
        if x0_in is not None:
            assert len(h) == len(x0_in), "Dimension mismatch. x0 != len(h)"
            for i in range(len(h)):
                x_i, h_i = x0_in[i], h[i]
                if Utils.isScalar(x_i):
                    x0[i] = x_i
                elif x_i == '0':
                    x0[i] = 0.0
                elif x_i == 'C':
                    x0[i] = -h_i.sum() * 0.5
                elif x_i == 'N':
                    x0[i] = -h_i.sum()
                else:
                    raise Exception(
                        "x0[{0:d}] must be a scalar or '0' to be zero, "
                        "'C' to center, or 'N' to be negative.".format(i))

        if isinstance(self, BaseRectangularMesh):
            BaseRectangularMesh.__init__(self, np.array([x.size for x in h]),
                                         x0)
        else:
            BaseMesh.__init__(self, np.array([x.size for x in h]), x0)

        # Ensure h contains 1D vectors
        self._h = [Utils.mkvc(x.astype(float)) for x in h]
Esempio n. 10
0
    def transform(self, u, m):
        self.setModel(m)
        m = 1 - 1.0/self.n
        f = ((  self.theta_s  -  self.theta_r  )/
             ((1+abs(self.alpha*u)**self.n)**m)   +  self.theta_r)
        if Utils.isScalar(self.theta_s):
            f[u >= 0] = self.theta_s
        else:
            f[u >= 0] = self.theta_s[u >= 0]

        return f
Esempio n. 11
0
    def transform(self, u, m):
        self.setModel(m)

        alpha = self.alpha
        I = self.I
        n = self.n
        Ks = self.Ks
        m = 1.0 - 1.0/n

        theta_e = 1.0/((1.0+abs(alpha*u)**n)**m)
        f = np.exp(Ks)*theta_e**I* ( ( 1.0 - ( 1.0 - theta_e**(1.0/m) )**m )**2 )
        if Utils.isScalar(self.Ks):
            f[u >= 0] = np.exp(self.Ks)
        else:
            f[u >= 0] = np.exp(self.Ks[u >= 0])
        return f
Esempio n. 12
0
    def transform(self, u, m):
        self.setModel(m)

        alpha = self.alpha
        I = self.I
        n = self.n
        Ks = self.Ks
        m = 1.0 - 1.0/n

        theta_e = 1.0/((1.0+abs(alpha*u)**n)**m)
        f = np.exp(Ks)*theta_e**I* ( ( 1.0 - ( 1.0 - theta_e**(1.0/m) )**m )**2 )
        if Utils.isScalar(self.Ks):
            f[u >= 0] = np.exp(self.Ks)
        else:
            f[u >= 0] = np.exp(self.Ks[u >= 0])
        return f
Esempio n. 13
0
    def _fastInnerProduct(self,
                          projType,
                          prop=None,
                          invProp=False,
                          invMat=False):
        """
            Fast version of getFaceInnerProduct.
            This does not handle the case of a full tensor prop.

            :param numpy.array prop: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
            :param str projType: 'E' or 'F'
            :param bool returnP: returns the projection matrices
            :param bool invProp: inverts the material property
            :param bool invMat: inverts the matrix
            :rtype: scipy.csr_matrix
            :return: M, the inner product matrix (nF, nF)
        """
        assert projType in [
            'F', 'E'
        ], "projType must be 'F' for faces or 'E' for edges"

        if prop is None:
            prop = np.ones(self.nC)

        if invProp:
            prop = 1. / prop

        if Utils.isScalar(prop):
            prop = prop * np.ones(self.nC)

        if prop.size == self.nC:
            Av = getattr(self, 'ave' + projType + '2CC')
            Vprop = self.vol * Utils.mkvc(prop)
            M = self.dim * Utils.sdiag(Av.T * Vprop)
        elif prop.size == self.nC * self.dim:
            Av = getattr(self, 'ave' + projType + '2CCV')
            V = sp.kron(sp.identity(self.dim), Utils.sdiag(self.vol))
            M = Utils.sdiag(Av.T * V * Utils.mkvc(prop))
        else:
            return None

        if invMat:
            return Utils.sdInv(M)
        else:
            return M
Esempio n. 14
0
    def _fastInnerProduct(self, projType, prop=None, invProp=False, invMat=False):
        """
            Fast version of getFaceInnerProduct.
            This does not handle the case of a full tensor prop.

            :param numpy.array prop: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
            :param str projType: 'E' or 'F'
            :param bool returnP: returns the projection matrices
            :param bool invProp: inverts the material property
            :param bool invMat: inverts the matrix
            :rtype: scipy.csr_matrix
            :return: M, the inner product matrix (nF, nF)
        """
        assert projType in ['F', 'E'], "projType must be 'F' for faces or 'E' for edges"

        if prop is None:
            prop = np.ones(self.nC)

        if invProp:
            prop = 1./prop

        if Utils.isScalar(prop):
            prop = prop*np.ones(self.nC)

        if prop.size == self.nC:
            Av = getattr(self, 'ave'+projType+'2CC')
            Vprop = self.vol * Utils.mkvc(prop)
            M = self.dim * Utils.sdiag(Av.T * Vprop)
        elif prop.size == self.nC*self.dim:
            Av = getattr(self, 'ave'+projType+'2CCV')
            V = sp.kron(sp.identity(self.dim), Utils.sdiag(self.vol))
            M = Utils.sdiag(Av.T * V * Utils.mkvc(prop))
        else:
            return None

        if invMat:
            return Utils.sdInv(M)
        else:
            return M