示例#1
0
 def setUp(self):
     a = np.array([1, 1, 1])
     b = np.array([1, 2])
     c = np.array([1, 4])
     gridIt = lambda h: [np.cumsum(np.r_[0, x]) for x in h]
     X, Y = ndgrid(gridIt([a, b]), vector=False)
     self.TM2 = TensorMesh([a, b])
     self.Curv2 = CurvilinearMesh([X, Y])
     X, Y, Z = ndgrid(gridIt([a, b, c]), vector=False)
     self.TM3 = TensorMesh([a, b, c])
     self.Curv3 = CurvilinearMesh([X, Y, Z])
 def setUp(self):
     a = np.array([1, 1, 1])
     b = np.array([1, 2])
     c = np.array([1, 4])
     gridIt = lambda h: [np.cumsum(np.r_[0, x]) for x in h]
     X, Y = ndgrid(gridIt([a, b]), vector=False)
     self.TM2 = TensorMesh([a, b])
     self.Curv2 = CurvilinearMesh([X, Y])
     X, Y, Z = ndgrid(gridIt([a, b, c]), vector=False)
     self.TM3 = TensorMesh([a, b, c])
     self.Curv3 = CurvilinearMesh([X, Y, Z])
示例#3
0
def interactive_two_configurations_comparison(log_sig0,log_sig1,log_sig2,R0,R1,xstart,ystart,xend,yend,dipole_number,electrode_spacing,matching_spheres_example):
    
    sig0,sig1 = conductivity_log_wrapper(log_sig0,log_sig1)
    sig2 = 10.**log_sig2
    E0   = 1.           # inducing field strength in V/m
    n = 100             #level of discretisation
    xr = np.linspace(-200., 200., n) # X-axis discretization
    yr = xr.copy()      # Y-axis discretization
    zr = np.r_[0]          # identical to saying `zr = np.array([0])`
    XYZ = ndgrid(xr,yr,zr) # Space Definition
    PlotOpt = 'Total'
    
    if matching_spheres_example:
        sig0 = 10.**(-3)         
        sig1 = 10.**(-2)         
        sig2 = 1.310344828 * 10**(-3)
        R0   = 20.          
        R1   = 40.

        two_configurations_comparison(XYZ,sig0,sig1,sig2,R0,R1,E0,xstart,ystart,xend,yend,dipole_number,electrode_spacing,PlotOpt)

    else:
        two_configurations_comparison(XYZ,sig0,sig1,sig2,R0,R1,E0,xstart,ystart,xend,yend,dipole_number,electrode_spacing,PlotOpt)

    plt.tight_layout(True)
    plt.show()
示例#4
0
    def _getEdgePxxx(M):
        i, j, k = np.arange(M.nCx), np.arange(M.nCy), np.arange(M.nCz)

        iijjkk = ndgrid(i, j, k)
        ii, jj, kk = iijjkk[:, 0], iijjkk[:, 1], iijjkk[:, 2]

        if M._meshType == 'Curv':
            eT1 = M.r(M.tangents, 'E', 'Ex', 'M')
            eT2 = M.r(M.tangents, 'E', 'Ey', 'M')
            eT3 = M.r(M.tangents, 'E', 'Ez', 'M')

        def Pxxx(xEdge, yEdge, zEdge):

            # no  | node        | e1          | e2          | e3
            # 000 | i  ,j  ,k   | i  ,j  ,k   | i  ,j  ,k   | i  ,j  ,k
            # 100 | i+1,j  ,k   | i  ,j  ,k   | i+1,j  ,k   | i+1,j  ,k
            # 010 | i  ,j+1,k   | i  ,j+1,k   | i  ,j  ,k   | i  ,j+1,k
            # 110 | i+1,j+1,k   | i  ,j+1,k   | i+1,j  ,k   | i+1,j+1,k
            # 001 | i  ,j  ,k+1 | i  ,j  ,k+1 | i  ,j  ,k+1 | i  ,j  ,k
            # 101 | i+1,j  ,k+1 | i  ,j  ,k+1 | i+1,j  ,k+1 | i+1,j  ,k
            # 011 | i  ,j+1,k+1 | i  ,j+1,k+1 | i  ,j  ,k+1 | i  ,j+1,k
            # 111 | i+1,j+1,k+1 | i  ,j+1,k+1 | i+1,j  ,k+1 | i+1,j+1,k

            posX = [0, 0] if xEdge == 'eX0' else [
                1, 0
            ] if xEdge == 'eX1' else [0, 1] if xEdge == 'eX2' else [1, 1]
            posY = [0, 0] if yEdge == 'eY0' else [
                1, 0
            ] if yEdge == 'eY1' else [0, 1] if yEdge == 'eY2' else [1, 1]
            posZ = [0, 0] if zEdge == 'eZ0' else [
                1, 0
            ] if zEdge == 'eZ1' else [0, 1] if zEdge == 'eZ2' else [1, 1]

            ind1 = sub2ind(M.vnEx, np.c_[ii, jj + posX[0], kk + posX[1]])
            ind2 = sub2ind(M.vnEy, np.c_[ii + posY[0], jj,
                                         kk + posY[1]]) + M.nEx
            ind3 = sub2ind(M.vnEz, np.c_[ii + posZ[0], jj + posZ[1],
                                         kk]) + M.nEx + M.nEy

            IND = np.r_[ind1, ind2, ind3].flatten()

            PXXX = sp.coo_matrix((np.ones(3 * M.nC), (range(3 * M.nC), IND)),
                                 shape=(3 * M.nC, M.nE)).tocsr()

            if M._meshType == 'Curv':
                I3x3 = inv3X3BlockDiagonal(
                    getSubArray(eT1[0], [i, j + posX[0], k + posX[1]]),
                    getSubArray(eT1[1], [i, j + posX[0], k + posX[1]]),
                    getSubArray(eT1[2], [i, j + posX[0], k + posX[1]]),
                    getSubArray(eT2[0], [i + posY[0], j, k + posY[1]]),
                    getSubArray(eT2[1], [i + posY[0], j, k + posY[1]]),
                    getSubArray(eT2[2], [i + posY[0], j, k + posY[1]]),
                    getSubArray(eT3[0], [i + posZ[0], j + posZ[1], k]),
                    getSubArray(eT3[1], [i + posZ[0], j + posZ[1], k]),
                    getSubArray(eT3[2], [i + posZ[0], j + posZ[1], k]))
                PXXX = I3x3 * PXXX

            return PXXX

        return Pxxx
示例#5
0
    def test_ndgrid_2D(self):
        XY = ndgrid([self.a, self.b])

        X1_test = np.array([1, 2, 3, 1, 2, 3])
        X2_test = np.array([1, 1, 1, 2, 2, 2])

        self.assertTrue(np.all(XY[:, 0] == X1_test))
        self.assertTrue(np.all(XY[:, 1] == X2_test))
示例#6
0
    def test_ndgrid_2D(self):
        XY = ndgrid([self.a, self.b])

        X1_test = np.array([1, 2, 3, 1, 2, 3])
        X2_test = np.array([1, 1, 1, 2, 2, 2])

        self.assertTrue(np.all(XY[:, 0] == X1_test))
        self.assertTrue(np.all(XY[:, 1] == X2_test))
示例#7
0
    def test_ndgrid_3D(self):
        XYZ = ndgrid([self.a, self.b, self.c])

        X1_test = np.array([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3])
        X2_test = np.array([1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2])
        X3_test = np.array([1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4])

        self.assertTrue(np.all(XYZ[:, 0] == X1_test))
        self.assertTrue(np.all(XYZ[:, 1] == X2_test))
        self.assertTrue(np.all(XYZ[:, 2] == X3_test))
示例#8
0
    def test_ndgrid_3D(self):
        XYZ = ndgrid([self.a, self.b, self.c])

        X1_test = np.array([
            1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1,
            2, 3
        ])
        X2_test = np.array([
            1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2,
            2, 2
        ])
        X3_test = np.array([
            1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
            4, 4
        ])

        self.assertTrue(np.all(XYZ[:, 0] == X1_test))
        self.assertTrue(np.all(XYZ[:, 1] == X2_test))
        self.assertTrue(np.all(XYZ[:, 2] == X3_test))
示例#9
0
    def _getEdgePxx(M):
        i, j = np.arange(M.nCx), np.arange(M.nCy)

        iijj = ndgrid(i, j)
        ii, jj = iijj[:, 0], iijj[:, 1]

        if M._meshType == 'Curv':
            eT1 = M.r(M.tangents, 'E', 'Ex', 'M')
            eT2 = M.r(M.tangents, 'E', 'Ey', 'M')

        def Pxx(xEdge, yEdge):
            # no | node      | e1      | e2
            # 00 | i  ,j     | i  ,j   | i  ,j
            # 10 | i+1,j     | i  ,j   | i+1,j
            # 01 | i  ,j+1   | i  ,j+1 | i  ,j
            # 11 | i+1,j+1   | i  ,j+1 | i+1,j
            posX = 0 if xEdge == 'eX0' else 1
            posY = 0 if yEdge == 'eY0' else 1

            ind1 = sub2ind(M.vnEx, np.c_[ii, jj + posX])
            ind2 = sub2ind(M.vnEy, np.c_[ii + posY, jj]) + M.nEx

            IND = np.r_[ind1, ind2].flatten()

            PXX = sp.coo_matrix((np.ones(2 * M.nC), (range(2 * M.nC), IND)),
                                shape=(2 * M.nC, M.nE)).tocsr()

            if M._meshType == 'Curv':
                I2x2 = inv2X2BlockDiagonal(getSubArray(eT1[0], [i, j + posX]),
                                           getSubArray(eT1[1], [i, j + posX]),
                                           getSubArray(eT2[0], [i + posY, j]),
                                           getSubArray(eT2[1], [i + posY, j]))
                PXX = I2x2 * PXX

            return PXX

        return Pxx
示例#10
0
def interact_conductiveSphere(R,log_sig0,log_sig1,Figure1a,Figure1b,Figure2a,Figure2b):
     
    sig0,sig1 = conductivity_log_wrapper(log_sig0,log_sig1)
    E0   = 1.           # inducing field strength in V/m
    n = 100             #level of discretisation
    xr = np.linspace(-200., 200., n) # X-axis discretization
    yr = xr.copy()      # Y-axis discretization
    zr = np.r_[0]          # identical to saying `zr = np.array([0])`
    XYZ = ndgrid(xr,yr,zr) # Space Definition

    fig, ax = plt.subplots(1,2,figsize=(18,6))

    #Setup figure 1 with options Configuration, Total or Secondary, 
    #then Potential, ElectricField, Current Density or Charges Density
    if Figure1a == 'Configuration':
        ax[0] = get_Setup(XYZ,sig0,sig1,R,E0,ax[0],True,[0.1,0.1,0.6])
        
    elif Figure1a == 'Total':
        
        if Figure1b == 'Potential':
            ax[0] = Plot_Total_Potential(XYZ,sig0,sig1,R,E0,ax[0])

        elif Figure1b == 'ElectricField':
            ax[0] = Plot_Total_ElectricField(XYZ,sig0,sig1,R,E0,ax[0])
            
        elif Figure1b == 'CurrentDensity':
            ax[0] = Plot_Total_Currents(XYZ,sig0,sig1,R,E0,ax[0])
            
        elif Figure1b == 'ChargesDensity':
            ax[0] = Plot_ChargesDensity(XYZ,sig0,sig1,R,E0,ax[0])
            
    elif Figure1a == 'Secondary':
        
        if Figure1b == 'Potential':
            ax[0] = Plot_Secondary_Potential(XYZ,sig0,sig1,R,E0,ax[0])
        
        elif Figure1b == 'ElectricField':
            ax[0] = Plot_Secondary_ElectricField(XYZ,sig0,sig1,R,E0,ax[0])
            
        elif Figure1b == 'CurrentDensity':
            ax[0] = Plot_Secondary_Currents(XYZ,sig0,sig1,R,E0,ax[0])
            
        elif Figure1b == 'ChargesDensity':
            ax[0] = Plot_ChargesDensity(XYZ,sig0,sig1,R,E0,ax[0])
            
            
    if Figure1a== 'Configuration':
        ax[1] = Plot_Primary_Potential(XYZ,sig0,sig1,R,E0,ax[1])
        print 'While figure1 is plotting Configuration, figure2 plots the primary field'
        
    elif Figure2a == 'Total':      
        if Figure2b == 'Potential':
            ax[1] = Plot_Total_Potential(XYZ,sig0,sig1,R,E0,ax[1])

        elif Figure2b == 'ElectricField':
            ax[1] = Plot_Total_ElectricField(XYZ,sig0,sig1,R,E0,ax[1])

        elif Figure2b == 'CurrentDensity':
            ax[1]=Plot_Total_Currents(XYZ,sig0,sig1,R,E0,ax[1])

        elif Figure2b == 'ChargesDensity':
            ax[1] = Plot_ChargesDensity(XYZ,sig0,sig1,R,E0,ax[1])

    
    elif Figure2a == 'Secondary':      
        if Figure2b == 'Potential':
            ax[1] = Plot_Secondary_Potential(XYZ,sig0,sig1,R,E0,ax[1])

        elif Figure2b == 'ElectricField':
            ax[1] = Plot_Secondary_ElectricField(XYZ,sig0,sig1,R,E0,ax[1])

        elif Figure2b == 'CurrentDensity':
            ax[1] = Plot_Secondary_Currents(XYZ,sig0,sig1,R,E0,ax[1])

        elif Figure2b == 'ChargesDensity':
             ax[1] = Plot_ChargesDensity(XYZ,sig0,sig1,R,E0,ax[1])

    plt.tight_layout(True)
    plt.show()
示例#11
0
    plt.tight_layout(True)
    plt.show()



if __name__ == '__main__':
    sig0 = -3.          # conductivity of the wholespace
    sig1 = -1.         # conductivity of the sphere
    sig0, sig1 = conductivity_log_wrapper(sig0,sig1)
    R    = 50.          # radius of the sphere
    E0   = 1.           # inducing field strength
    n = 100             #level of discretisation
    xr = np.linspace(-2.*R, 2.*R, n) # X-axis discretization
    yr = xr.copy()      # Y-axis discretization
    zr = np.r_[0]          # identical to saying `zr = np.array([0])`
    XYZ = ndgrid(xr,yr,zr) # Space Definition

    fig, ax = plt.subplots(2,5,figsize=(50,10))
    ax[0,0] = get_Setup(XYZ,sig0,sig1,R,E0,ax[0,0],True,[0.6,0.1,0.1])
    ax[1,0] = Plot_Primary_Potential(XYZ,sig0,sig1,R,E0,ax[1,0])
    ax[0,1] = Plot_Total_Potential(XYZ,sig0,sig1,R,E0,ax[0,1])
    ax[1,1] = Plot_Secondary_Potential(XYZ,sig0,sig1,R,E0,ax[1,1])
    ax[0,2] = Plot_Total_ElectricField(XYZ,sig0,sig1,R,E0,ax[0,2])
    ax[1,2] = Plot_Secondary_ElectricField(XYZ,sig0,sig1,R,E0,ax[1,2])
    ax[0,3] = Plot_Total_Currents(XYZ,sig0,sig1,R,E0,ax[0,3])
    ax[1,3] = Plot_Secondary_Currents(XYZ,sig0,sig1,R,E0,ax[1,3])
    ax[0,4] = Plot_Primary_Potential(XYZ,sig0,sig1,R,E0,ax[0,4])
    ax[1,4] = Plot_ChargesDensity(XYZ,sig0,sig1,R,E0,ax[1,4])
    

    plt.show()
示例#12
0
    def _getFacePxxx(M):
        """returns a function for creating projection matrices

            Mats takes you from faces a subset of all faces on only the
            faces that you ask for.

            These are centered around a single nodes.
        """

        i, j, k = np.arange(M.nCx), np.arange(M.nCy), np.arange(M.nCz)

        iijjkk = ndgrid(i, j, k)
        ii, jj, kk = iijjkk[:, 0], iijjkk[:, 1], iijjkk[:, 2]

        if M._meshType == 'Curv':
            fN1 = M.r(M.normals, 'F', 'Fx', 'M')
            fN2 = M.r(M.normals, 'F', 'Fy', 'M')
            fN3 = M.r(M.normals, 'F', 'Fz', 'M')

        def Pxxx(xFace, yFace, zFace):
            """
                xFace is 'fXp' or 'fXm'
                yFace is 'fYp' or 'fYm'
                zFace is 'fZp' or 'fZm'
            """

            # no  | node        | f1        | f2        | f3
            # 000 | i  ,j  ,k   | i  , j, k | i, j  , k | i, j, k
            # 100 | i+1,j  ,k   | i+1, j, k | i, j  , k | i, j, k
            # 010 | i  ,j+1,k   | i  , j, k | i, j+1, k | i, j, k
            # 110 | i+1,j+1,k   | i+1, j, k | i, j+1, k | i, j, k
            # 001 | i  ,j  ,k+1 | i  , j, k | i, j  , k | i, j, k+1
            # 101 | i+1,j  ,k+1 | i+1, j, k | i, j  , k | i, j, k+1
            # 011 | i  ,j+1,k+1 | i  , j, k | i, j+1, k | i, j, k+1
            # 111 | i+1,j+1,k+1 | i+1, j, k | i, j+1, k | i, j, k+1

            posX = 0 if xFace == 'fXm' else 1
            posY = 0 if yFace == 'fYm' else 1
            posZ = 0 if zFace == 'fZm' else 1

            ind1 = sub2ind(M.vnFx, np.c_[ii + posX, jj, kk])
            ind2 = sub2ind(M.vnFy, np.c_[ii, jj + posY, kk]) + M.nFx
            ind3 = sub2ind(M.vnFz, np.c_[ii, jj, kk + posZ]) + M.nFx + M.nFy

            IND = np.r_[ind1, ind2, ind3].flatten()

            PXXX = sp.coo_matrix((np.ones(3 * M.nC), (range(3 * M.nC), IND)),
                                 shape=(3 * M.nC, M.nF)).tocsr()

            if M._meshType == 'Curv':
                I3x3 = inv3X3BlockDiagonal(
                    getSubArray(fN1[0], [i + posX, j, k]),
                    getSubArray(fN1[1], [i + posX, j, k]),
                    getSubArray(fN1[2], [i + posX, j, k]),
                    getSubArray(fN2[0], [i, j + posY, k]),
                    getSubArray(fN2[1], [i, j + posY, k]),
                    getSubArray(fN2[2], [i, j + posY, k]),
                    getSubArray(fN3[0], [i, j, k + posZ]),
                    getSubArray(fN3[1], [i, j, k + posZ]),
                    getSubArray(fN3[2], [i, j, k + posZ]))
                PXXX = I3x3 * PXXX

            return PXXX

        return Pxxx
示例#13
0
    def _getFacePxx(M):
        """returns a function for creating projection matrices

            Mats takes you from faces a subset of all faces on only the
            faces that you ask for.

            These are centered around a single nodes.

            For example, if this was your entire mesh:

                            f3(Yp)
                      2_______________3
                      |               |
                      |               |
                      |               |
              f0(Xm)  |       x       |  f1(Xp)
                      |               |
                      |               |
                      |_______________|
                      0               1
                            f2(Ym)

            Pxx('fXm','fYm') = | 1, 0, 0, 0 |
                               | 0, 0, 1, 0 |

            Pxx('fXp','fYm') = | 0, 1, 0, 0 |
                               | 0, 0, 1, 0 |

            """
        i, j = np.arange(M.nCx), np.arange(M.nCy)

        iijj = ndgrid(i, j)
        ii, jj = iijj[:, 0], iijj[:, 1]

        if M._meshType == 'Curv':
            fN1 = M.r(M.normals, 'F', 'Fx', 'M')
            fN2 = M.r(M.normals, 'F', 'Fy', 'M')

        def Pxx(xFace, yFace):
            """
                xFace is 'fXp' or 'fXm'
                yFace is 'fYp' or 'fYm'
            """
            # no | node      | f1     | f2
            # 00 | i  ,j     | i  , j | i, j
            # 10 | i+1,j     | i+1, j | i, j
            # 01 | i  ,j+1   | i  , j | i, j+1
            # 11 | i+1,j+1   | i+1, j | i, j+1

            posFx = 0 if xFace == 'fXm' else 1
            posFy = 0 if yFace == 'fYm' else 1

            ind1 = sub2ind(M.vnFx, np.c_[ii + posFx, jj])
            ind2 = sub2ind(M.vnFy, np.c_[ii, jj + posFy]) + M.nFx

            IND = np.r_[ind1, ind2].flatten()

            PXX = sp.csr_matrix((np.ones(2 * M.nC), (range(2 * M.nC), IND)),
                                shape=(2 * M.nC, M.nF))

            if M._meshType == 'Curv':
                I2x2 = inv2X2BlockDiagonal(getSubArray(fN1[0], [i + posFx, j]),
                                           getSubArray(fN1[1], [i + posFx, j]),
                                           getSubArray(fN2[0], [i, j + posFy]),
                                           getSubArray(fN2[1], [i, j + posFy]))
                PXX = I2x2 * PXX

            return PXX

        return Pxx