Beispiel #1
0
            A[i][i-1] = -aW[i+1]
            if i+2 <= self.__N-1:
                A[i][i+2] = -aEE[i+1]
                
        A[-1][-1] = aP[-2]
        A[-1][-2] = -aW[-2]

if __name__ == '__main__':

    a = Matrix(6)
    print('-' * 20)  
    print(a.mat())
    print('-' * 20)  
    
    from Diffusion import Diffusion1D        
    df1 = Diffusion1D(6, 1, 0.25)
    df1.alloc(6)
    df1.calcCoef()
    df1.source(100)
    print(df1.aP(), df1.aE(), df1.aW(), df1.Su(), sep = '\n')
    print('-' * 20)  

    df1.bcDirichlet('LEFT_WALL', 2)
    df1.bcDirichlet('RIGHT_WALL', 1)
    print(df1.aP(), df1.aE(), df1.aW(), df1.Su(), sep = '\n')
    print('-' * 20)  
    
    a.build(df1)
    print(a.mat())
    print('-' * 20)  
def printFrame(d):
    """
    Función que imprime el error calculado
    """
    # Calculo el error porcentual y agrego al DataFrame
    # una columna con esos datos llamada 'Error %'
    d['Error %'] = d['Error'] / d['Analytic'] 
    print(DataFrame(d))
    print('.'+ '-'*70 + '.')

def calcError(phiA, phiN):
    """
    Función que calcula el error entre la aproximación calculada y el valor real de la solución.
    
    @return: error
    """
    return np.absolute(phiA - phiN)
        
if __name__ == '__main__':
 
    Coefficients.alloc(5)
    m = Mesh(nodes = 5)
    d = Diffusion1D(m.volumes())
    ma = Matrix(m.volumes())
    a = Advection1D(m.volumes())

    print(m.delta(), d.aP(), a.aP(), ma.mat(), sep='\n')

    printData(nvx =5, nx = 6, longitud = 1.3)

Beispiel #3
0
                                                4 + i)

        # Construye el objeto CSR
        Asp = csr_matrix((data, indices.astype(int), indptr.astype(int)))
        return Asp


if __name__ == '__main__':
    n = 9
    a = Matrix(n)
    print('-' * 20)
    print(a.mat())
    print('-' * 20)

    from Diffusion import Diffusion1D
    df1 = Diffusion1D(n, 1, 0.25)
    df1.alloc(n)
    df1.calcCoef()
    df1.setSu(100)
    print(df1.aP(), df1.aE(), df1.aW(), df1.Su(), sep='\n')
    print('-' * 20)

    df1.bcDirichlet('LEFT_WALL', 2)
    df1.bcDirichlet('RIGHT_WALL', 1)
    print(df1.aP(), df1.aE(), df1.aW(), df1.Su(), sep='\n')
    print('-' * 20)

    a.build(df1)
    print(a.mat())
    print('-' * 20)