```python
import pandas as pd
import numpy as np
import math
from matplotlib import pyplot as plt
import sympy as sp
#Autor: PabloF - 14/01: calculamatrices fallos corregidos, añadido cálculo de esfuerzo de forma manual
# 15/01 ensamblaje arreglado
# 16/01 bug en ensamblaje con cierto tipo de problemas (enero 2018 pej) arreglado
# 18/01 esfuerzos en barras y cálculo simbólico
# 19/01 ensamblaje arreglado (lo había tocado el 16/01 y la lié cambiando una cosa q funcionaba). Arreglado ensamblaje.
```

Índice:

- Funciónes
- Cálculo de esfuerzos con cálculo numérico. Matrices de barras, sistema reducido, desplazamientos
- Plot de la estructura
- Esfuerzos
- Cálculo de esfuerzos locales y desplazamientos locales en barras
- Esfuerzos globales (reacciones)
- Cálculo simbólico

Funciones:
- calculamatrices(EA,EI,L,cos,sen,tipo) -------------return M
- esfuerzos(EA, EI, L, cos, sen, tipo, desplaz)-----return(result, despl, M)
- localesaglobales(vect, cos, sen)---------------------return(glob)
- calculamatricesSIMB(EA,EI,L,cos,sen,tipo) ------return M
- globalesalocales(vect,cos,sen)-----------------------return(loc)

```python
localesaglobales(np.array([-624.711521, 206.284930,-291.730946,0,0,0]),0.7071068,-0.7071068)
```

    array([-295.8722878 ,  587.60324128, -291.730946  ,    0.        ,
              0.        ,    0.        ])

```python
def calculamatrices(EA,EI,L,cos,sen,tipo):

    M = np.zeros(shape = (6,6))
    Ka = EA/L
    Ki = 12*EI/(L*L*L)

    if tipo == 'AA':

        M[0][0] = cos*cos
        M[1][1] = sen*sen
        M[0][1] = cos*sen
        M[1][0] = cos*sen

        M[2][2] = 0
        M[2][1] = 0
        M[1][2] = 0
        M[2][0] = 0
        M[0][2] = 0
        M[2][3] = 0
        M[3][2] = 0
        M[4][2] = 0
        M[2][4] = 0
        M[2][5] = 0
        M[5][2] = 0

        M[5][5] = 0
        M[5][1] = 0
        M[1][5] = 0
        M[5][0] = 0
        M[0][5] = 0
        M[5][3] = 0
        M[3][5] = 0
        M[4][5] = 0
        M[5][4] = 0
        M[2][5] = 0
        M[5][2] = 0

        M[3][3] = cos*cos
        M[4][4] = sen*sen
        M[3][4] = cos*sen
        M[4][3] = cos*sen

        M[0][3] = -cos*cos
        M[0][4] = -cos*sen
        M[1][4] = -sen*sen
        M[1][3] = -cos*sen
        M[3][0] = -cos*cos
        M[3][1] = -cos*sen
        M[4][0] = -cos*sen
        M[4][1] = -sen*sen

        M = EA/L*M

    if tipo == 'AR':

        M[0][0] = Ka*cos*cos + 0.25*Ki*sen*sen
        M[1][1] = Ka*sen*sen + 0.25*Ki*cos*cos
        M[0][1] = (Ka-0.25*Ki)*cos*sen
        M[1][0] = (Ka-0.25*Ki)*cos*sen

        M[2][2] = 0
        M[2][1] = 0
        M[1][2] = 0
        M[2][0] = 0
        M[0][2] = 0
        M[2][3] = 0
        M[3][2] = 0
        M[4][2] = 0
        M[2][4] = 0
        M[2][5] = 0
        M[5][2] = 0

        M[5][5] = 0.25*L*L*Ki
        M[5][1] = 0.25*L*Ki*cos
        M[1][5] = 0.25*L*Ki*cos
        M[5][0] = -0.25*L*Ki*sen
        M[0][5] = -0.25*L*Ki*sen
        M[5][3] = 0.25*L*Ki*sen
        M[3][5] = 0.25*L*Ki*sen
        M[4][5] = -0.25*L*Ki*cos
        M[5][4] = -0.25*L*Ki*cos
        M[2][5] = 0
        M[5][2] = 0

        M[3][3] = Ka*cos*cos + 0.25*Ki*sen*sen
        M[4][4] = Ka*sen*sen + 0.25*Ki*cos*cos
        M[3][4] = (Ka-0.25*Ki)*cos*sen
        M[4][3] = (Ka-0.25*Ki)*cos*sen

        M[0][3] = -Ka*cos*cos-0.25*Ki*sen*sen
        M[0][4] = -(Ka-0.25*Ki)*cos*sen
        M[1][4] = -Ka*sen*sen-0.25*Ki*cos*cos
        M[1][3] = -(Ka-0.25*Ki)*cos*sen
        M[3][0] = -Ka*cos*cos-0.25*Ki*sen*sen
        M[3][1] = -(Ka-0.25*Ki)*cos*sen
        M[4][0] = -(Ka-0.25*Ki)*cos*sen
        M[4][1] = -Ka*sen*sen-0.25*Ki*cos*cos

    if tipo == 'RA':

        M[0][0]=Ka*(cos*cos)+(0.25*Ki*(sen*sen))
        M[0][1]=(Ka-(0.25*Ki))*cos*sen
        M[0][2]=-L*0.25*Ki*sen
        M[0][3]=(-Ka*cos*cos)-(0.25*Ki*sen*sen)
        M[0][4]=-(Ka-(0.25*Ki))*cos*sen
        M[0][5]=0

        M[1][0]=(Ka-(0.25*Ki))*cos*sen
        M[1][1]=Ka*sen*sen+0.25*Ki*cos*cos
        M[1][2]=0.25*Ki*cos*L
        M[1][3]=-(Ka-0.25*Ki)*cos*sen
        M[1][4]=(-Ka*sen*sen)-(0.25*Ki*cos*cos)
        M[1][5]=0

        M[2][0]=-L*0.25*Ki*sen
        M[2][1]=0.25*Ki*cos*L
        M[2][2]=L*L*0.25*Ki
        M[2][3]=L*0.25*Ki*sen
        M[2][4]=-L*0.25*Ki*cos
        M[2][5]=0

        M[3][0]=(-Ka*cos*cos)-(0.25*Ki*sen*sen)
        M[3][1]=-(Ka-0.25*Ki)*cos*sen
        M[3][2]=L*0.25*Ki*sen
        M[3][3]=Ka*cos*cos+0.25*Ki*sen*sen
        M[3][4]=(Ka-0.25*Ki)*cos*sen
        M[3][5]=0

        M[4][0]=-(Ka-(0.25*Ki))*cos*sen
        M[4][1]=(-Ka*sen*sen)-(0.25*Ki*cos*cos)
        M[4][2]=-L*0.25*Ki*cos
        M[4][3]=(Ka-0.25*Ki)*cos*sen
        M[4][4]=Ka*sen*sen+0.25*Ki*cos*cos
        M[4][5]=0

        M[5][0]=0
        M[5][1]=0
        M[5][2]=0
        M[5][3]=0
        M[5][4]=0
        M[5][5]=0

    if tipo == 'RR':

        M[0][0] = Ka*cos*cos+Ki*sen*sen
        M[0][1] = (Ka-Ki)*cos*sen
        M[0][2] = -(L/2)*Ki*sen
        M[0][3] = -Ka*cos*cos-Ki*sen*sen
        M[0][4] = -(Ka-Ki)*cos*sen
        M[0][5] = -(L/2)*Ki*sen

        M[1][0] = (Ka-Ki)*cos*sen
        M[1][1] = Ka*sen*sen+Ki*cos*cos
        M[1][2] = (L/2)*Ki*cos
        M[1][3] = -(Ka-Ki)*cos*sen
        M[1][4] = -Ka*sen*sen-Ki*cos*cos
        M[1][5] = (L/2)*Ki*cos

        M[2][0] = -(L/2)*Ki*sen
        M[2][1] = (L/2)*Ki*cos
        M[2][2] = (L*L/3)*Ki
        M[2][3] = (L/2)*Ki*sen
        M[2][4] = -(L/2)*Ki*cos
        M[2][5] = (L*L/6)*Ki

        M[3][0] = -Ka*cos*cos-Ki*sen*sen
        M[3][1] = -(Ka-Ki)*cos*sen
        M[3][2] = (L/2)*Ki*sen
        M[3][3] = Ka*cos*cos+Ki*sen*sen
        M[3][4] = (Ka-Ki)*cos*sen
        M[3][5] = (L/2)*Ki*sen

        M[4][0] = -(Ka-Ki)*cos*sen
        M[4][1] = -Ka*sen*sen-Ki*cos*cos
        M[4][2] = -(L/2)*Ki*cos
        M[4][3] = (Ka-Ki)*cos*sen
        M[4][4] = Ka*sen*sen+Ki*cos*cos
        M[4][5]= -(L/2)*Ki*cos

        M[5][0] = -(L/2)*Ki*sen
        M[5][1] = (L/2)*Ki*cos
        M[5][2] = (L*L/6)*Ki
        M[5][3] = (L/2)*Ki*sen
        M[5][4]= -(L/2)*Ki*cos
        M[5][5] = (L*L/3)*Ki

    return M
```

```python
def esfuerzos(EA, EI, L, cos, sen, tipo, desplaz):

    R = np.zeros(shape = (6,6))

    R[0][0] = cos
    R[0][1] = sen
    R[0][2] = 0
    R[0][3] = 0
    R[0][4] = 0
    R[0][5] = 0

    R[1][0] = -sen
    R[1][1] = cos
    R[1][2] = 0
    R[1][3] = 0
    R[1][4] = 0
    R[1][5] = 0

    R[2][0] = 0
    R[2][1] = 0
    R[2][2] = 1
    R[2][3] = 0
    R[2][4] = 0
    R[2][5] = 0

    R[3][0] = 0
    R[3][1] = 0
    R[3][2] = 0
    R[3][3] = cos
    R[3][4] = sen
    R[3][5] = 0

    R[4][0] = 0
    R[4][1] = 0
    R[4][2] = 0
    R[4][3] = -sen
    R[4][4] = cos
    R[4][5] = 0

    R[5][0] = 0
    R[5][1] = 0
    R[5][2] = 0
    R[5][3] = 0
    R[5][4] = 0
    R[5][5] = 1

    M = calculamatrices(EA,EI,L,1,0,tipo)

    despl = np.dot(R,desplaz)

    result = np.dot(M,despl)

    return(result, despl, M)
```

```python
def globalesalocales(vect,cos,sen):

    R = np.zeros(shape = (6,6))

    R[0][0] = cos
    R[0][1] = sen
    R[0][2] = 0
    R[0][3] = 0
    R[0][4] = 0
    R[0][5] = 0

    R[1][0] = -sen
    R[1][1] = cos
    R[1][2] = 0
    R[1][3] = 0
    R[1][4] = 0
    R[1][5] = 0

    R[2][0] = 0
    R[2][1] = 0
    R[2][2] = 1
    R[2][3] = 0
    R[2][4] = 0
    R[2][5] = 0

    R[3][0] = 0
    R[3][1] = 0
    R[3][2] = 0
    R[3][3] = cos
    R[3][4] = sen
    R[3][5] = 0

    R[4][0] = 0
    R[4][1] = 0
    R[4][2] = 0
    R[4][3] = -sen
    R[4][4] = cos
    R[4][5] = 0

    R[5][0] = 0
    R[5][1] = 0
    R[5][2] = 0
    R[5][3] = 0
    R[5][4] = 0
    R[5][5] = 1

    desploca = np.dot(R,vect)

    return(desploca)
```

```python
def localesaglobales(vect, cos, sen):

    R = np.zeros(shape = (6,6))

    R[0][0] = cos
    R[0][1] = -sen
    R[0][2] = 0
    R[0][3] = 0
    R[0][4] = 0
    R[0][5] = 0

    R[1][0] = sen
    R[1][1] = cos
    R[1][2] = 0
    R[1][3] = 0
    R[1][4] = 0
    R[1][5] = 0

    R[2][0] = 0
    R[2][1] = 0
    R[2][2] = 1
    R[2][3] = 0
    R[2][4] = 0
    R[2][5] = 0

    R[3][0] = 0
    R[3][1] = 0
    R[3][2] = 0
    R[3][3] = cos
    R[3][4] = -sen
    R[3][5] = 0

    R[4][0] = 0
    R[4][1] = 0
    R[4][2] = 0
    R[4][3] = sen
    R[4][4] = cos
    R[4][5] = 0

    R[5][0] = 0
    R[5][1] = 0
    R[5][2] = 0
    R[5][3] = 0
    R[5][4] = 0
    R[5][5] = 1

    glob = np.dot(R,vect)

    return(glob)

```

```python
def calculamatricesSIMB(EA,EI,L,cos,sen,tipo):

    H = sp.Symbol('H')
    a = sp.Symbol('a')
    I = sp.Symbol('I')
    E = sp.Symbol('E')
    L = L*H
    EA = I*a*E
    EI = EI*I*E

    M = np.zeros(shape = (6,6))

    M = pd.DataFrame(M)
    Ka = EA/L
    Ki = 12*EI/(L*L*L)

    if tipo == 'AA':

        M[0][0] = cos*cos
        M[1][1] = sen*sen
        M[0][1] = cos*sen
        M[1][0] = cos*sen

        M[2][2] = 0
        M[2][1] = 0
        M[1][2] = 0
        M[2][0] = 0
        M[0][2] = 0
        M[2][3] = 0
        M[3][2] = 0
        M[4][2] = 0
        M[2][4] = 0
        M[2][5] = 0
        M[5][2] = 0

        M[5][5] = 0
        M[5][1] = 0
        M[1][5] = 0
        M[5][0] = 0
        M[0][5] = 0
        M[5][3] = 0
        M[3][5] = 0
        M[4][5] = 0
        M[5][4] = 0
        M[2][5] = 0
        M[5][2] = 0

        M[3][3] = cos*cos
        M[4][4] = sen*sen
        M[3][4] = cos*sen
        M[4][3] = cos*sen

        M[0][3] = -cos*cos
        M[0][4] = -cos*sen
        M[1][4] = -sen*sen
        M[1][3] = -cos*sen
        M[3][0] = -cos*cos
        M[3][1] = -cos*sen
        M[4][0] = -cos*sen
        M[4][1] = -sen*sen

        M = EA/L*M

    if tipo == 'AR':

        M[0][0] = Ka*cos*cos + 0.25*Ki*sen*sen
        M[1][1] = Ka*sen*sen + 0.25*Ki*cos*cos
        M[0][1] = (Ka-0.25*Ki)*cos*sen
        M[1][0] = (Ka-0.25*Ki)*cos*sen

        M[2][2] = 0
        M[2][1] = 0
        M[1][2] = 0
        M[2][0] = 0
        M[0][2] = 0
        M[2][3] = 0
        M[3][2] = 0
        M[4][2] = 0
        M[2][4] = 0
        M[2][5] = 0
        M[5][2] = 0

        M[5][5] = 0.25*L*L*Ki
        M[5][1] = 0.25*L*Ki*cos
        M[1][5] = 0.25*L*Ki*cos
        M[5][0] = -0.25*L*Ki*sen
        M[0][5] = -0.25*L*Ki*sen
        M[5][3] = 0.25*L*Ki*sen
        M[3][5] = 0.25*L*Ki*sen
        M[4][5] = -0.25*L*Ki*cos
        M[5][4] = -0.25*L*Ki*cos
        M[2][5] = 0
        M[5][2] = 0

        M[3][3] = Ka*cos*cos + 0.25*Ki*sen*sen
        M[4][4] = Ka*sen*sen + 0.25*Ki*cos*cos
        M[3][4] = (Ka-0.25*Ki)*cos*sen
        M[4][3] = (Ka-0.25*Ki)*cos*sen

        M[0][3] = -Ka*cos*cos-0.25*Ki*sen*sen
        M[0][4] = -(Ka-0.25*Ki)*cos*sen
        M[1][4] = -Ka*sen*sen-0.25*Ki*cos*cos
        M[1][3] = -(Ka-0.25*Ki)*cos*sen
        M[3][0] = -Ka*cos*cos-0.25*Ki*sen*sen
        M[3][1] = -(Ka-0.25*Ki)*cos*sen
        M[4][0] = -(Ka-0.25*Ki)*cos*sen
        M[4][1] = -Ka*sen*sen-0.25*Ki*cos*cos

    if tipo == 'RA':

        M[0][0]=Ka*(cos*cos)+(0.25*Ki*(sen*sen))
        M[0][1]=(Ka-(0.25*Ki))*cos*sen
        M[0][2]=-L*0.25*Ki*sen
        M[0][3]=(-Ka*cos*cos)-(0.25*Ki*sen*sen)
        M[0][4]=-(Ka-(0.25*Ki))*cos*sen
        M[0][5]=0

        M[1][0]=(Ka-(0.25*Ki))*cos*sen
        M[1][1]=Ka*sen*sen+0.25*Ki*cos*cos
        M[1][2]=0.25*Ki*cos*L
        M[1][3]=-(Ka-0.25*Ki)*cos*sen
        M[1][4]=(-Ka*sen*sen)-(0.25*Ki*cos*cos)
        M[1][5]=0

        M[2][0]=-L*0.25*Ki*sen
        M[2][1]=0.25*Ki*cos*L
        M[2][2]=L*L*0.25*Ki
        M[2][3]=L*0.25*Ki*sen
        M[2][4]=-L*0.25*Ki*cos
        M[2][5]=0

        M[3][0]=(-Ka*cos*cos)-(0.25*Ki*sen*sen)
        M[3][1]=-(Ka-0.25*Ki)*cos*sen
        M[3][2]=L*0.25*Ki*sen
        M[3][3]=Ka*cos*cos+0.25*Ki*sen*sen
        M[3][4]=(Ka-0.25*Ki)*cos*sen
        M[3][5]=0

        M[4][0]=-(Ka-(0.25*Ki))*cos*sen
        M[4][1]=(-Ka*sen*sen)-(0.25*Ki*cos*cos)
        M[4][2]=-L*0.25*Ki*cos
        M[4][3]=(Ka-0.25*Ki)*cos*sen
        M[4][4]=Ka*sen*sen+0.25*Ki*cos*cos
        M[4][5]=0

        M[5][0]=0
        M[5][1]=0
        M[5][2]=0
        M[5][3]=0
        M[5][4]=0
        M[5][5]=0

    if tipo == 'RR':

        M[0][0] = Ka*cos*cos+Ki*sen*sen
        M[0][1] = (Ka-Ki)*cos*sen
        M[0][2] = -(L/2)*Ki*sen
        M[0][3] = -Ka*cos*cos-Ki*sen*sen
        M[0][4] = -(Ka-Ki)*cos*sen
        M[0][5] = -(L/2)*Ki*sen

        M[1][0] = (Ka-Ki)*cos*sen
        M[1][1] = Ka*sen*sen+Ki*cos*cos
        M[1][2] = (L/2)*Ki*cos
        M[1][3] = -(Ka-Ki)*cos*sen
        M[1][4] = -Ka*sen*sen-Ki*cos*cos
        M[1][5] = (L/2)*Ki*cos

        M[2][0] = -(L/2)*Ki*sen
        M[2][1] = (L/2)*Ki*cos
        M[2][2] = (L*L/3)*Ki
        M[2][3] = (L/2)*Ki*sen
        M[2][4] = -(L/2)*Ki*cos
        M[2][5] = (L*L/6)*Ki

        M[3][0] = -Ka*cos*cos-Ki*sen*sen
        M[3][1] = -(Ka-Ki)*cos*sen
        M[3][2] = (L/2)*Ki*sen
        M[3][3] = Ka*cos*cos+Ki*sen*sen
        M[3][4] = (Ka-Ki)*cos*sen
        M[3][5] = (L/2)*Ki*sen

        M[4][0] = -(Ka-Ki)*cos*sen
        M[4][1] = -Ka*sen*sen-Ki*cos*cos
        M[4][2] = -(L/2)*Ki*cos
        M[4][3] = (Ka-Ki)*cos*sen
        M[4][4] = Ka*sen*sen+Ki*cos*cos
        M[4][5]= -(L/2)*Ki*cos

        M[5][0] = -(L/2)*Ki*sen
        M[5][1] = (L/2)*Ki*cos
        M[5][2] = (L*L/6)*Ki
        M[5][3] = (L/2)*Ki*sen
        M[5][4]= -(L/2)*Ki*cos
        M[5][5] = (L*L/3)*Ki

    M = M.to_numpy()

    return M
```

```python
estructura = pd.read_excel('Estructura.xlsx', sheet_name='Estructuras')
estructura = estructura.sort_values('nodoi')
maxlen = np.array([estructura['nodoi'].max(),estructura['nodof'].max()]).max()
```

# No olvidar cambiar EA EI Fijarse en que todo está correcto!

Si hay simetría la fuerza va en ambos lados!  (ej: v3 = v5 pues F3 = F5)

```python
estructura = pd.read_excel('Estructura.xlsx', sheet_name='Estructuras')
estructura = estructura.sort_values('nodoi')
maxlen = np.array([estructura['nodoi'].max(),estructura['nodof'].max()]).max()

A = np.zeros(shape=(3*(maxlen),3*(maxlen)))

printinfo = []

for row in estructura.iterrows():
    cualprimero = 0
    inforow = row[1]
    iterator = inforow['nodoi']
    finnode = inforow['nodof']
    infobarra = inforow['barra']
    EA = inforow['EA']
    EI = inforow['EI']

    condini = 0
    condfin = 3
    esquinacol = 3
    esquinafila = 0

    M = calculamatrices(EA,EI,inforow['L'],inforow['cos'],inforow['sen'],inforow['tipo'])

    for i in range(0,3):
        for j in range(0,3):
            A[3*(iterator-1)+i][3*(iterator-1)+j] =  A[3*(iterator-1)+i][3*(iterator-1)+j]  + M[condini+i][condini+j]  # aquí el generador de elementos
            #print('\n \n','Barra ',inforow['barra'],' Tipo 1 ',' Nodo ', inforow['nodoi'], '-', inforow['nodof'], ' Término ',[condini+i,condini+j] , ' = ', M[condini+i][condini+j],' Ensamblado en elemento ',  [3*(iterator-1)+i,3*(iterator-1)+j] ,' sumado a ',  A[3*(iterator-1)+i][3*(iterator-1)+j] - M[condini+i][condini+j] ,' \n \n')

    for i in range(0,3):
        for j in range(0,3):
            A[3*(finnode-1)+i][3*(finnode-1)+j] =  A[3*(finnode-1)+i][3*(finnode-1)+j]  + M[condfin+i][condfin+j]  # aquí el generador de elementos
            #print('\n \n','Barra ',inforow['barra'],' Tipo 2 ',' Nodo ', inforow['nodoi'], '-', inforow['nodof'], ' Término ',[condfin+i, condfin+j] , ' = ', M[condfin+i][condfin+j],' Ensamblado en elemento ', [3*(finnode-1)+i,3*(finnode-1)+j],' sumado a ', A[3*(finnode-1)+i][3*(finnode-1)+j] - M[condfin+i][condfin+j],' \n \n')

    for i in range(0,3):
        for j in range(0,3):
            A[3*(iterator-1)+i][3*(finnode-1)+j] =  A[3*(iterator-1)+i][3*(finnode-1)+j] + M[i+esquinafila][j+esquinacol]  # aquí el generador de elementos
            #print('\n \n','Barra ',inforow['barra'],' Tipo 3 ',' Nodo ', inforow['nodoi'], '-', inforow['nodof'], ' Término ',[i+esquinafila,j+esquinacol] , ' = ', M[i+esquinafila][j+esquinacol],' Ensamblado en elemento ', [3*(iterator-1)+i,3*(finnode-1)+j] ,' sumado a ', A[3*(iterator-1)+i][3*(finnode-1)+j] - M[i+esquinafila][j+esquinacol],' \n \n')

    for i in range(0,3):
        for j in range(0,3):
            A[3*(finnode-1)+j][3*(iterator-1)+i] = A[3*(finnode-1)+j][3*(iterator-1)+i]  +  M[j+esquinacol][i+esquinafila] # aquí el generador de elementos
            #print('\n \n','Barra ',inforow['barra'],' Tipo 4 ',' Nodo ', inforow['nodoi'], '-', inforow['nodof'], ' Término ',[i+esquinafila,j+esquinacol] , ' = ', M[i+esquinafila][j+esquinacol],' Ensamblado en elemento ', [3*(iterator-1)+i,3*(finnode-1)+j] ,' sumado a ', A[3*(iterator-1)+i][3*(finnode-1)+j] - M[i+esquinafila][j+esquinacol],' \n \n')

    printinfo.append([infobarra,M,iterator,finnode])

printinfo = sorted(printinfo, key=lambda tup: tup[0])

for i in range(0,len(printinfo)):
    print('\n  \n Barra', printinfo[i][0], ' - Cuidado con el orden ! \n \n')#, '\n \n',printinfo[i][1], '\n \n')

    cols = ['U'+str(printinfo[i][2]),   'V'+str(printinfo[i][2]),   'A'+str(printinfo[i][2]),   'U'+str(printinfo[i][3]),   'V'+str(printinfo[i][3]),    'A'+str(printinfo[i][3])]
    df = pd.DataFrame(printinfo[i][1], columns=cols, index=cols)
    print(df)

print('\n \n \n Assembly: \n ')

pd.DataFrame(A).to_excel('FullMatrix.xlsx')

print('Full Matrix dropped to FullMatrix.xlsx \n')

despl = pd.read_excel('Estructura.xlsx', sheet_name='Desplazamientos')
despl = despl.to_numpy()
mxmin = np.where(despl == 1)

mn = mxmin[0].min()
mx = mxmin[0].max()

B = np.zeros(shape=(mx+1-mn,mx+1-mn))
ln = len(B)

for i in range(mn,mx+1):
    B = np.append(B,[A[i][mn:mx+1]],axis = 0)

B = np.delete(B,slice(0,ln),axis = 0)

Forces = pd.read_excel('Estructura.xlsx', sheet_name='Fuerzas')
Forces = Forces.to_numpy()
if(len(Forces) != len(despl)):
    print('/n Warning - Force shape != Despl shape - Check everything is OK /n')

Forces = Forces[mn:mx+1]

Eliminate = despl[mn:mx+1]
Eliminate = np.where(Eliminate == 0)

Forces = np.delete(Forces, Eliminate[0] , 0)

B = np.delete(B, Eliminate[0],0)
B = np.delete(B, Eliminate[0],1)

X = np.linalg.inv(B).dot(Forces)

Result = np.where(despl == 1)[0]

pd.DataFrame(B).to_excel('ReducedMatrix.xlsx')

print('Reduced matrix dropped to ReducedMatrix.xlsx \n')

vect = []

for i in range(0,len(Result)):
    indicat = math.floor(Result[i]/3) + 1

    if (math.floor(Result[i]/3))*3 == Result[i]:

        vect.append(['u',indicat])

    if (math.floor(Result[i]/3))*3 + 1 == Result[i]:

        vect.append(['v',indicat])

    if (math.floor(Result[i]/3))*3 + 2 == Result[i]:

        vect.append(['ang',indicat])

print('\n  System:\n ')

print(pd.DataFrame(B))

print('\n Multiplied by: \n')

print(pd.DataFrame(vect, columns = ['type','node']))

print('\n Equaled to: \n')

print(pd.DataFrame(Forces, columns=['Forces']))

print(' \n  \n As indicated in the despl vector, the despl and results are, in order: \n')

for i in range(0,len(vect)):
    print(vect[i][0],vect[i][1], '=', X[i])
```

     Barra 1  - Cuidado con el orden !

              U1        V1        A1        U3        V3   A3
    U1  3.053309 -2.256420 -0.876579 -3.053309  2.256420  0.0
    V1 -2.256420  3.053309 -0.876579  2.256420 -3.053309  0.0
    A1 -0.876579 -0.876579  1.928473  0.876579  0.876579  0.0
    U3 -3.053309  2.256420  0.876579  3.053309 -2.256420  0.0
    V3  2.256420 -3.053309  0.876579 -2.256420  3.053309  0.0
    A3  0.000000  0.000000  0.000000  0.000000  0.000000  0.0

     Barra 2  - Cuidado con el orden !

              U1        V1        A1        U2        V2        A2
    U1  9.015778 -0.000000 -4.958678 -9.015778  0.000000 -4.958678
    V1 -0.000000  7.509091  0.000000  0.000000 -7.509091  0.000000
    A1 -4.958678  0.000000  3.636364  4.958678 -0.000000  1.818182
    U2 -9.015778  0.000000  4.958678  9.015778 -0.000000  4.958678
    V2  0.000000 -7.509091 -0.000000 -0.000000  7.509091 -0.000000
    A2 -4.958678  0.000000  1.818182  4.958678 -0.000000  3.636364

     Barra 3  - Cuidado con el orden !

              U3        V3   A3        U2        V2        A2
    U3  7.509091  0.000000  0.0 -7.509091 -0.000000 -0.000000
    V3  0.000000  2.253944  0.0 -0.000000 -2.253944  2.479339
    A3  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
    U2 -7.509091 -0.000000  0.0  7.509091  0.000000  0.000000
    V2 -0.000000 -2.253944  0.0  0.000000  2.253944 -2.479339
    A2 -0.000000  2.479339  0.0  0.000000 -2.479339  2.727273

     Barra 4  - Cuidado con el orden !

              U5        V5        A5        U3        V3   A3
    U5  3.053309  2.256420 -0.876579 -3.053309 -2.256420  0.0
    V5  2.256420  3.053309  0.876579 -2.256420 -3.053309  0.0
    A5 -0.876579  0.876579  1.928473  0.876579 -0.876579  0.0
    U3 -3.053309 -2.256420  0.876579  3.053309  2.256420  0.0
    V3 -2.256420 -3.053309 -0.876579  2.256420  3.053309  0.0
    A3  0.000000  0.000000  0.000000  0.000000  0.000000  0.0

     Barra 5  - Cuidado con el orden !

              U5        V5        A5        U4        V4        A4
    U5  9.015778 -0.000000 -4.958678 -9.015778  0.000000 -4.958678
    V5 -0.000000  7.509091  0.000000  0.000000 -7.509091  0.000000
    A5 -4.958678  0.000000  3.636364  4.958678 -0.000000  1.818182
    U4 -9.015778  0.000000  4.958678  9.015778 -0.000000  4.958678
    V4  0.000000 -7.509091 -0.000000 -0.000000  7.509091 -0.000000
    A4 -4.958678  0.000000  1.818182  4.958678 -0.000000  3.636364

     Barra 6  - Cuidado con el orden !

              U3        V3   A3        U4        V4        A4
    U3  7.509091 -0.000000  0.0 -7.509091  0.000000 -0.000000
    V3 -0.000000  2.253944  0.0  0.000000 -2.253944 -2.479339
    A3  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
    U4 -7.509091  0.000000  0.0  7.509091 -0.000000  0.000000
    V4  0.000000 -2.253944  0.0 -0.000000  2.253944  2.479339
    A4 -0.000000 -2.479339  0.0  0.000000  2.479339  2.727273

     Barra 7  - Cuidado con el orden !

              U5        V5        A5        U7        V7   A7
    U5  3.053309 -2.256420  0.876579 -3.053309  2.256420  0.0
    V5 -2.256420  3.053309  0.876579  2.256420 -3.053309  0.0
    A5  0.876579  0.876579  1.928473 -0.876579 -0.876579  0.0
    U7 -3.053309  2.256420 -0.876579  3.053309 -2.256420  0.0
    V7  2.256420 -3.053309 -0.876579 -2.256420  3.053309  0.0
    A7  0.000000  0.000000  0.000000  0.000000  0.000000  0.0

     Barra 8  - Cuidado con el orden !

              U5        V5        A5        U6        V6        A6
    U5  9.015778  0.000000  4.958678 -9.015778 -0.000000  4.958678
    V5  0.000000  7.509091  0.000000 -0.000000 -7.509091  0.000000
    A5  4.958678  0.000000  3.636364 -4.958678 -0.000000  1.818182
    U6 -9.015778 -0.000000 -4.958678  9.015778  0.000000 -4.958678
    V6 -0.000000 -7.509091 -0.000000  0.000000  7.509091 -0.000000
    A6  4.958678  0.000000  1.818182 -4.958678 -0.000000  3.636364

     Barra 9  - Cuidado con el orden !

              U7        V7   A7        U6        V6        A6
    U7  7.509091 -0.000000  0.0 -7.509091  0.000000 -0.000000
    V7 -0.000000  2.253944  0.0  0.000000 -2.253944 -2.479339
    A7  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
    U6 -7.509091  0.000000  0.0  7.509091 -0.000000  0.000000
    V6  0.000000 -2.253944  0.0 -0.000000  2.253944  2.479339
    A6 -0.000000 -2.479339  0.0  0.000000  2.479339  2.727273

     Barra 10  - Cuidado con el orden !

              U1        V1        A1        U7        V7   A7
    U1  3.053309  2.256420  0.876579 -3.053309 -2.256420  0.0
    V1  2.256420  3.053309 -0.876579 -2.256420 -3.053309  0.0
    A1  0.876579 -0.876579  1.928473 -0.876579  0.876579  0.0
    U7 -3.053309 -2.256420 -0.876579  3.053309  2.256420  0.0
    V7 -2.256420 -3.053309  0.876579  2.256420  3.053309  0.0
    A7  0.000000  0.000000  0.000000  0.000000  0.000000  0.0

     Barra 11  - Cuidado con el orden !

              U1        V1        A1        U8        V8        A8
    U1  9.015778  0.000000  4.958678 -9.015778 -0.000000  4.958678
    V1  0.000000  7.509091  0.000000 -0.000000 -7.509091  0.000000
    A1  4.958678  0.000000  3.636364 -4.958678 -0.000000  1.818182
    U8 -9.015778 -0.000000 -4.958678  9.015778  0.000000 -4.958678
    V8 -0.000000 -7.509091 -0.000000  0.000000  7.509091 -0.000000
    A8  4.958678  0.000000  1.818182 -4.958678 -0.000000  3.636364

     Barra 12  - Cuidado con el orden !

              U7        V7   A7        U8        V8        A8
    U7  7.509091  0.000000  0.0 -7.509091 -0.000000 -0.000000
    V7  0.000000  2.253944  0.0 -0.000000 -2.253944  2.479339
    A7  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
    U8 -7.509091 -0.000000  0.0  7.509091  0.000000  0.000000
    V8 -0.000000 -2.253944  0.0  0.000000  2.253944 -2.479339
    A8 -0.000000  2.479339  0.0  0.000000 -2.479339  2.727273

     Assembly:

    Full Matrix dropped to FullMatrix.xlsx

    /n Warning - Force shape != Despl shape - Check everything is OK /n
    Reduced matrix dropped to ReducedMatrix.xlsx

      System:

               0          1         2          3         4          5          6  \
    0  21.124801  -1.753157  0.000000  -3.053309  0.000000   0.000000   0.000000
    1  -1.753157  11.129673  1.818182   0.876579  0.000000   0.000000   0.000000
    2   0.000000   1.818182  6.363636   2.479339  0.000000   0.000000   0.000000
    3  -3.053309   0.876579  2.479339  10.614508 -2.479339  -3.053309  -0.876579
    4   0.000000   0.000000  0.000000  -2.479339  6.363636   0.000000   1.818182
    5   0.000000   0.000000  0.000000  -3.053309  0.000000  21.124801   1.753157
    6   0.000000   0.000000  0.000000  -0.876579  1.818182   1.753157  11.129673
    7   0.000000   0.000000  0.000000   0.000000  0.000000   0.000000   1.818182
    8  -3.053309   0.876579  0.000000   0.000000  0.000000  -3.053309  -0.876579
    9   0.000000   1.818182  0.000000   0.000000  0.000000   0.000000   0.000000

              7          8         9
    0  0.000000  -3.053309  0.000000
    1  0.000000   0.876579  1.818182
    2  0.000000   0.000000  0.000000
    3  0.000000   0.000000  0.000000
    4  0.000000   0.000000  0.000000
    5  0.000000  -3.053309  0.000000
    6  1.818182  -0.876579  0.000000
    7  6.363636  -2.479339  0.000000
    8 -2.479339  10.614508  2.479339
    9  0.000000   2.479339  6.363636

     Multiplied by:

      type  node
    0    v     1
    1  ang     1
    2  ang     2
    3    v     3
    4  ang     4
    5    v     5
    6  ang     5
    7  ang     6
    8    v     7
    9  ang     8

     Equaled to:

       Forces
    0    0.00
    1  -20.22
    2    0.00
    3  -49.00
    4    0.00
    5    0.00
    6   20.22
    7    0.00
    8  -49.00
    9    0.00

     As indicated in the despl vector, the despl and results are, in order:

    v 1 = [-2.24193591]
    ang 1 = [-2.15541821]
    ang 2 = [3.39640169]
    v 3 = [-7.13679098]
    ang 4 = [-3.39640169]
    v 5 = [-2.24193591]
    ang 5 = [2.15541821]
    ang 6 = [-3.39640169]
    v 7 = [-7.13679098]
    ang 8 = [3.39640169]

```python
X = np.array([[-2.4354 ],
       [-1.8771],
       [ 4.6677 ],
       [-7.8865 ],
       [-4.6677],
       [-2.4354 ],
       [ 1.8771],
       [-4.6677],
       [-7.8865 ],
       [ 4.6677]])
```

Si pongo en función de EI, esto sale entre EI... Careful! Y en función de p pues por p. Y la matriz pues por EI.

```python
##X = np.array([[1],[0.0101034],[-0.24169674],[0.0101034],[-0.24169674]])
```

```python
# X = np.array([[],[],[]]) # Se mete primero desplazamientos en excel con el impuesto 0 y se saca, luego se completa metiendo el que toque donde toque y volviendo a poner 1
```

# PLOT

Ajusta la escala según el desplazamiento que ha salido arriba! Si es por ejemplo 0.0005 lo suyo para que se vea es un *100.

```python
scale = 0.0010
```

```python
positions = []
posicionados = []
barra = []
count = 0
valuu = 0
for i in range(0,len(estructura)):

    barr = estructura.iloc[i]['barra']
    nodoini = estructura.iloc[i]['nodoi']
    nodofin = estructura.iloc[i]['nodof']
    Long = estructura.iloc[i]['L']
    cose = estructura.iloc[i]['cos']
    seno = estructura.iloc[i]['sen']

    if (nodoini == 1 and count == 0):
        print('\n Initial node found. Coordinates set')
        count = count + 1
        posicionados.append(nodoini)
        posicionados.append(nodofin)
        positions.append([0,0])
        positions.append([positions[0][0]+cose*Long, positions[0][1]+seno*Long])
        barra.append(barr)
        barra.append(barr)

        print('\n node ', nodofin, ' coordinates set \n')

    if nodoini in posicionados and nodofin not in posicionados:

        indixe = posicionados.index(nodoini)
        posicionados.append(nodofin)
        positions.append([positions[indixe][0] + cose*Long, positions[indixe][1] + seno*Long])

        print('\n node ',nodofin,' coordinates set \n')

    if nodofin in posicionados and nodoini not in posicionados:

        indixe = posicionados.index(nodofin)
        posicionados.append(nodoini)
        positions.append([positions[indixe][0] - cose*Long, positions[indixe][1] - seno*Long])

        print('\n node ',nodoini,' coordinates set \n')

print('All displacements are *',scale)

x = []
y = []
for i in positions:
    x.append(i[0])
    y.append(i[1])

plt.scatter(x,y)

for i in range(0,len(estructura)):

    inic = estructura.iloc[i]['nodoi']
    fina = estructura.iloc[i]['nodof']

    indixini = posicionados.index(inic)
    indixfin = posicionados.index(fina)

    x_values = [x[indixini],x[indixfin]]
    y_values = [y[indixini],y[indixfin]]

    plt.plot(x_values,y_values, alpha = 0.5, color = 'b')

newpositions = positions

for i in range(0,len(Result)):
    indicat = math.floor(Result[i]/3) + 1

    indicex = posicionados.index(indicat)

    if (math.floor(Result[i]/3))*3 == Result[i]:

        newpositions[indicex][0] = positions[indicex][0] + X[i]*scale
        print('\n u', indicat, 'added \n')

    if (math.floor(Result[i]/3))*3 + 1 == Result[i]:

        newpositions[indicex][1] = positions[indicex][1] + X[i]*scale
        print('\n v', indicat, 'added \n')

xn = []
yn = []
for i in newpositions:
    xn.append(i[0])
    yn.append(i[1])

plt.scatter(xn,yn)

for i in range(0,len(estructura)):

    inic = estructura.iloc[i]['nodoi']
    fina = estructura.iloc[i]['nodof']

    indixini = posicionados.index(inic)
    indixfin = posicionados.index(fina)

    xn_values = [xn[indixini],xn[indixfin]]
    yn_values = [yn[indixini],yn[indixfin]]

    plt.plot(xn_values,yn_values, color = 'r')

plt.gca().set_aspect('equal', adjustable='box')

```

# Esfuerzos

#  MANUAL

```python

EA = 2000000
EI = 1666.66666666666
L = 4
cos = -0.5
sen = 0.866
tipo = 'AA'

desplaz = [0,0,0,0.00015577,-0.01104339,-0.72090746]

R = np.zeros(shape = (6,6))

R[0][0] = cos
R[0][1] = sen
R[0][2] = 0
R[0][3] = 0
R[0][4] = 0
R[0][5] = 0

R[1][0] = -sen
R[1][1] = cos
R[1][2] = 0
R[1][3] = 0
R[1][4] = 0
R[1][5] = 0

R[2][0] = 0
R[2][1] = 0
R[2][2] = 1
R[2][3] = 0
R[2][4] = 0
R[2][5] = 0

R[3][0] = 0
R[3][1] = 0
R[3][2] = 0
R[3][3] = cos
R[3][4] = sen
R[3][5] = 0

R[4][0] = 0
R[4][1] = 0
R[4][2] = 0
R[4][3] = -sen
R[4][4] = cos
R[4][5] = 0

R[5][0] = 0
R[5][1] = 0
R[5][2] = 0
R[5][3] = 0
R[5][4] = 0
R[5][5] = 1

M = calculamatrices(EA,EI,L,1,0,tipo)

despla = np.dot(R,desplaz)

result = np.dot(M,despla)

```

```python
despla # Desplazamiento en coordenadas locales. (con la matriz de giro del prontuario)
```

    array([ 0.        ,  0.        ,  0.        , -0.00964146,  0.0053868 ,
           -0.72090746])

```python
result # EL RESULTADO SALE EN LA DIRECCIÓN DE LA BARRA! El signo NO INDICA tracción / compresión sino DIRECCION DEL ESFUERZO en la REFERENCIA LOCAL en el NODO correspondiente
```

    array([ 4820.73037,     0.     ,     0.     , -4820.73037,     0.     ,
               0.     ])

```python
pd.DataFrame(M) # Matriz de la barra en horizontal
```

<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
      <th>1</th>
      <th>2</th>
      <th>3</th>
      <th>4</th>
      <th>5</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>0</td>
      <td>500000.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>-500000.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>1</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>2</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>3</td>
      <td>-500000.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>500000.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>4</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <td>5</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
  </tbody>
</table>
</div>

# Cálculo AUTOMÁTICO de ESFUERZOS en TODA la Estructura

```python
desplazamientos = pd.read_excel('Estructura.xlsx', sheet_name='Desplazamientos')
desplazamientos = desplazamientos.to_numpy()
desplazamientos = desplazamientos.astype(float)

j = 0

print('\n \n ------ Cuidado, no aplica superposición de esfuerzos! ------ \n')

print(' Si hay un nodo que no es un apoyo y está afectado por una fuerza los diagramas y valores extremos pueden variar \n ')

for i in range(len(desplazamientos)):
    if desplazamientos[i] == 1:
        desplazamientos[i] = X[j]
        j = j + 1

desplaz = np.zeros(shape = (6,1))

for row in estructura.iterrows():

    inforow = row[1]

    nodoi = inforow['nodoi']
    nodof = inforow['nodof']
    barra = inforow['barra']

    L = inforow['L']
    cos = inforow['cos']
    sen = inforow['sen']
    EA = inforow['EA']
    EI = inforow['EI']
    tipo = inforow['tipo']

    desplaz[0:3] = desplazamientos[(nodoi-1)*3:(nodoi-1)*3+3]
    desplaz[3:6] = desplazamientos[(nodof-1)*3:(nodof-1)*3+3]

    esf, desploc, M = esfuerzos(EA, EI, L, cos, sen, tipo, desplaz)

    cols = ['Fx N' + str(nodoi),   'Fy N' + str(nodoi),   'Mz N' + str(nodoi),   'Fx N' + str(nodof),   'Fy N' + str(nodof),    'Mz N' + str(nodof)]

    df = pd.DataFrame(esf, index=cols)

    print('\n Esfuerzos en la barra ', barra, ' que conecta los nodos ', nodoi, nodof, ': (Cuidado! no suma reacciones) \n')

    print(df)

    print('\n Desplazamientos Locales (de ', nodoi, ' a ', nodof, ') \n')

    print(np.rot90(desploc))

    cols = ['U'+str(nodoi),   'V'+str(nodoi),   'A'+str(nodoi),   'U'+str(nodof),   'V'+str(nodof),    'A'+str(nodof)]

    M = pd.DataFrame(M, columns=cols, index = cols)

    print('\n \n Matriz utilizada en coordenadas locales: \n \n ', M, ' \n \n')

    print('\n \n')

```

     ------ Cuidado, no aplica superposición de esfuerzos! ------

     Si hay un nodo que no es un apoyo y está afectado por una fuerza los diagramas y valores extremos pueden variar

     Esfuerzos en la barra  1  que conecta los nodos  1 3 : (Cuidado! no suma reacciones)

                   0
    Fx N1  20.466403
    Fy N1  -5.398603
    Mz N1  -8.398255
    Fx N3 -20.466403
    Fy N3   5.398603
    Mz N3   0.000000

     Desplazamientos Locales (de  1  a  3 )

    [[-1.72208785  1.72208785 -1.8771     -5.57659763  5.57659763  0.        ]]

     Matriz utilizada en coordenadas locales:

                U1        V1        A1        U3        V3   A3
    U1  5.309729  0.000000 -0.000000 -5.309729 -0.000000  0.0
    V1  0.000000  0.796890  1.239669 -0.000000 -0.796890  0.0
    A1 -0.000000  1.239669  1.928473  0.000000 -1.239669  0.0
    U3 -5.309729 -0.000000  0.000000  5.309729  0.000000  0.0
    V3 -0.000000 -0.796890 -1.239669  0.000000  0.796890  0.0
    A3  0.000000  0.000000  0.000000  0.000000  0.000000  0.0

     Esfuerzos en la barra  2  que conecta los nodos  1 2 : (Cuidado! no suma reacciones)

                   0
    Fx N1 -18.287640
    Fy N1  13.837686
    Mz N1   1.660909
    Fx N2  18.287640
    Fy N2 -13.837686
    Mz N2  13.560545

     Desplazamientos Locales (de  1  a  2 )

    [[-2.4354  0.     -1.8771  0.      0.      4.6677]]

     Matriz utilizada en coordenadas locales:

                U1        V1        A1        U2        V2        A2
    U1  7.509091 -0.000000 -0.000000 -7.509091  0.000000 -0.000000
    V1 -0.000000  9.015778  4.958678  0.000000 -9.015778  4.958678
    A1 -0.000000  4.958678  3.636364  0.000000 -4.958678  1.818182
    U2 -7.509091  0.000000  0.000000  7.509091 -0.000000  0.000000
    V2  0.000000 -9.015778 -4.958678 -0.000000  9.015778 -4.958678
    A2 -0.000000  4.958678  1.818182  0.000000 -4.958678  3.636364

     Esfuerzos en la barra  10  que conecta los nodos  1 7 : (Cuidado! no suma reacciones)

                   0
    Fx N1 -20.466403
    Fy N1  -5.398603
    Mz N1  -8.398255
    Fx N7  20.466403
    Fy N7   5.398603
    Mz N7   0.000000

     Desplazamientos Locales (de  1  a  7 )

    [[ 1.72208785  1.72208785 -1.8771      5.57659763  5.57659763  0.        ]]

     Matriz utilizada en coordenadas locales:

                U1        V1        A1        U7        V7   A7
    U1  5.309729  0.000000 -0.000000 -5.309729 -0.000000  0.0
    V1  0.000000  0.796890  1.239669 -0.000000 -0.796890  0.0
    A1 -0.000000  1.239669  1.928473  0.000000 -1.239669  0.0
    U7 -5.309729 -0.000000  0.000000  5.309729  0.000000  0.0
    V7 -0.000000 -0.796890 -1.239669  0.000000  0.796890  0.0
    A7  0.000000  0.000000  0.000000  0.000000  0.000000  0.0

     Esfuerzos en la barra  11  que conecta los nodos  1 8 : (Cuidado! no suma reacciones)

                   0
    Fx N1  18.287640
    Fy N1  13.837686
    Mz N1   1.660909
    Fx N8 -18.287640
    Fy N8 -13.837686
    Mz N8  13.560545

     Desplazamientos Locales (de  1  a  8 )

    [[ 2.4354  0.     -1.8771  0.      0.      4.6677]]

     Matriz utilizada en coordenadas locales:

                U1        V1        A1        U8        V8        A8
    U1  7.509091 -0.000000 -0.000000 -7.509091  0.000000 -0.000000
    V1 -0.000000  9.015778  4.958678  0.000000 -9.015778  4.958678
    A1 -0.000000  4.958678  3.636364  0.000000 -4.958678  1.818182
    U8 -7.509091  0.000000  0.000000  7.509091 -0.000000  0.000000
    V8  0.000000 -9.015778 -4.958678 -0.000000  9.015778 -4.958678
    A8 -0.000000  4.958678  1.818182  0.000000 -4.958678  3.636364

     Esfuerzos en la barra  3  que conecta los nodos  3 2 : (Cuidado! no suma reacciones)

                  0
    Fx N3  0.000000
    Fy N3 -6.202923
    Mz N3  0.000000
    Fx N2  0.000000
    Fy N2  6.202923
    Mz N2 -6.823215

     Desplazamientos Locales (de  3  a  2 )

    [[ 0.     -7.8865  0.      0.      0.      4.6677]]

     Matriz utilizada en coordenadas locales:

                U3        V3   A3        U2        V2        A2
    U3  7.509091  0.000000  0.0 -7.509091 -0.000000 -0.000000
    V3  0.000000  2.253944  0.0 -0.000000 -2.253944  2.479339
    A3  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
    U2 -7.509091 -0.000000  0.0  7.509091  0.000000  0.000000
    V2 -0.000000 -2.253944  0.0  0.000000  2.253944 -2.479339
    A2 -0.000000  2.479339  0.0  0.000000 -2.479339  2.727273

     Esfuerzos en la barra  6  que conecta los nodos  3 4 : (Cuidado! no suma reacciones)

                  0
    Fx N3  0.000000
    Fy N3  6.202923
    Mz N3  0.000000
    Fx N4  0.000000
    Fy N4 -6.202923
    Mz N4  6.823215

     Desplazamientos Locales (de  3  a  4 )

    [[ 0.      7.8865  0.      0.      0.     -4.6677]]

     Matriz utilizada en coordenadas locales:

                U3        V3   A3        U4        V4        A4
    U3  7.509091  0.000000  0.0 -7.509091 -0.000000 -0.000000
    V3  0.000000  2.253944  0.0 -0.000000 -2.253944  2.479339
    A3  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
    U4 -7.509091 -0.000000  0.0  7.509091  0.000000  0.000000
    V4 -0.000000 -2.253944  0.0  0.000000  2.253944 -2.479339
    A4 -0.000000  2.479339  0.0  0.000000 -2.479339  2.727273

     Esfuerzos en la barra  4  que conecta los nodos  5 3 : (Cuidado! no suma reacciones)

                   0
    Fx N5  20.466403
    Fy N5   5.398603
    Mz N5   8.398255
    Fx N3 -20.466403
    Fy N3  -5.398603
    Mz N3   0.000000

     Desplazamientos Locales (de  5  a  3 )

    [[-1.72208785 -1.72208785  1.8771     -5.57659763 -5.57659763  0.        ]]

     Matriz utilizada en coordenadas locales:

                U5        V5        A5        U3        V3   A3
    U5  5.309729  0.000000 -0.000000 -5.309729 -0.000000  0.0
    V5  0.000000  0.796890  1.239669 -0.000000 -0.796890  0.0
    A5 -0.000000  1.239669  1.928473  0.000000 -1.239669  0.0
    U3 -5.309729 -0.000000  0.000000  5.309729  0.000000  0.0
    V3 -0.000000 -0.796890 -1.239669  0.000000  0.796890  0.0
    A3  0.000000  0.000000  0.000000  0.000000  0.000000  0.0

     Esfuerzos en la barra  5  que conecta los nodos  5 4 : (Cuidado! no suma reacciones)

                   0
    Fx N5 -18.287640
    Fy N5 -13.837686
    Mz N5  -1.660909
    Fx N4  18.287640
    Fy N4  13.837686
    Mz N4 -13.560545

     Desplazamientos Locales (de  5  a  4 )

    [[-2.4354  0.      1.8771  0.      0.     -4.6677]]

     Matriz utilizada en coordenadas locales:

                U5        V5        A5        U4        V4        A4
    U5  7.509091 -0.000000 -0.000000 -7.509091  0.000000 -0.000000
    V5 -0.000000  9.015778  4.958678  0.000000 -9.015778  4.958678
    A5 -0.000000  4.958678  3.636364  0.000000 -4.958678  1.818182
    U4 -7.509091  0.000000  0.000000  7.509091 -0.000000  0.000000
    V4  0.000000 -9.015778 -4.958678 -0.000000  9.015778 -4.958678
    A4 -0.000000  4.958678  1.818182  0.000000 -4.958678  3.636364

     Esfuerzos en la barra  7  que conecta los nodos  5 7 : (Cuidado! no suma reacciones)

                   0
    Fx N5 -20.466403
    Fy N5   5.398603
    Mz N5   8.398255
    Fx N7  20.466403
    Fy N7  -5.398603
    Mz N7   0.000000

     Desplazamientos Locales (de  5  a  7 )

    [[ 1.72208785 -1.72208785  1.8771      5.57659763 -5.57659763  0.        ]]

     Matriz utilizada en coordenadas locales:

                U5        V5        A5        U7        V7   A7
    U5  5.309729  0.000000 -0.000000 -5.309729 -0.000000  0.0
    V5  0.000000  0.796890  1.239669 -0.000000 -0.796890  0.0
    A5 -0.000000  1.239669  1.928473  0.000000 -1.239669  0.0
    U7 -5.309729 -0.000000  0.000000  5.309729  0.000000  0.0
    V7 -0.000000 -0.796890 -1.239669  0.000000  0.796890  0.0
    A7  0.000000  0.000000  0.000000  0.000000  0.000000  0.0

     Esfuerzos en la barra  8  que conecta los nodos  5 6 : (Cuidado! no suma reacciones)

                   0
    Fx N5  18.287640
    Fy N5 -13.837686
    Mz N5  -1.660909
    Fx N6 -18.287640
    Fy N6  13.837686
    Mz N6 -13.560545

     Desplazamientos Locales (de  5  a  6 )

    [[ 2.4354  0.      1.8771  0.      0.     -4.6677]]

     Matriz utilizada en coordenadas locales:

                U5        V5        A5        U6        V6        A6
    U5  7.509091 -0.000000 -0.000000 -7.509091  0.000000 -0.000000
    V5 -0.000000  9.015778  4.958678  0.000000 -9.015778  4.958678
    A5 -0.000000  4.958678  3.636364  0.000000 -4.958678  1.818182
    U6 -7.509091  0.000000  0.000000  7.509091 -0.000000  0.000000
    V6  0.000000 -9.015778 -4.958678 -0.000000  9.015778 -4.958678
    A6 -0.000000  4.958678  1.818182  0.000000 -4.958678  3.636364

     Esfuerzos en la barra  9  que conecta los nodos  7 6 : (Cuidado! no suma reacciones)

                  0
    Fx N7  0.000000
    Fy N7  6.202923
    Mz N7  0.000000
    Fx N6  0.000000
    Fy N6 -6.202923
    Mz N6  6.823215

     Desplazamientos Locales (de  7  a  6 )

    [[ 0.      7.8865  0.      0.      0.     -4.6677]]

     Matriz utilizada en coordenadas locales:

                U7        V7   A7        U6        V6        A6
    U7  7.509091  0.000000  0.0 -7.509091 -0.000000 -0.000000
    V7  0.000000  2.253944  0.0 -0.000000 -2.253944  2.479339
    A7  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
    U6 -7.509091 -0.000000  0.0  7.509091  0.000000  0.000000
    V6 -0.000000 -2.253944  0.0  0.000000  2.253944 -2.479339
    A6 -0.000000  2.479339  0.0  0.000000 -2.479339  2.727273

     Esfuerzos en la barra  12  que conecta los nodos  7 8 : (Cuidado! no suma reacciones)

                  0
    Fx N7  0.000000
    Fy N7 -6.202923
    Mz N7  0.000000
    Fx N8  0.000000
    Fy N8  6.202923
    Mz N8 -6.823215

     Desplazamientos Locales (de  7  a  8 )

    [[ 0.     -7.8865  0.      0.      0.      4.6677]]

     Matriz utilizada en coordenadas locales:

                U7        V7   A7        U8        V8        A8
    U7  7.509091  0.000000  0.0 -7.509091 -0.000000 -0.000000
    V7  0.000000  2.253944  0.0 -0.000000 -2.253944  2.479339
    A7  0.000000  0.000000  0.0  0.000000  0.000000  0.000000
    U8 -7.509091 -0.000000  0.0  7.509091  0.000000  0.000000
    V8 -0.000000 -2.253944  0.0  0.000000  2.253944 -2.479339
    A8 -0.000000  2.479339  0.0  0.000000 -2.479339  2.727273

# Reacciones

```python
desplazamientos = pd.read_excel('Estructura.xlsx', sheet_name='Desplazamientos')
desplazamientos = desplazamientos.to_numpy()
desplazamientos = desplazamientos.astype(float)
j = 0

for i in range(len(desplazamientos)):
    if desplazamientos[i] == 1:
        desplazamientos[i] = X[j]
        j = j + 1

desplaz = np.zeros(shape = (6,1))

information = []

for row in estructura.iterrows():

    inforow = row[1]

    nodoi = inforow['nodoi']
    nodof = inforow['nodof']
    barra = inforow['barra']

    L = inforow['L']
    cos = inforow['cos']
    sen = inforow['sen']
    EA = inforow['EA']
    EI = inforow['EI']
    tipo = inforow['tipo']

    desplaz[0:3] = desplazamientos[(nodoi-1)*3:(nodoi-1)*3+3]
    desplaz[3:6] = desplazamientos[(nodof-1)*3:(nodof-1)*3+3]

    esf, desploc, M = esfuerzos(EA, EI, L, cos, sen, tipo, desplaz)

    cols = ['Fx N' + str(nodoi),   'Fy N' + str(nodoi),   'Mz N' + str(nodoi),   'Fx N' + str(nodof),   'Fy N' + str(nodof),    'Mz N' + str(nodof)]

    df = pd.DataFrame(esf, index=cols)

    cols = ['U'+str(nodoi),   'V'+str(nodoi),   'A'+str(nodoi),   'U'+str(nodof),   'V'+str(nodof),    'A'+str(nodof)]

    M = pd.DataFrame(M, columns=cols, index = cols)

    esfuerzoglobal = localesaglobales(esf, cos,
                                      sen)

    information.append([nodoi,esfuerzoglobal[0:3]])
    information.append([nodof,esfuerzoglobal[3:6]])

    test = pd.DataFrame(information)

Esforzo = []

toremove = []

for i in range(0,len(information)):

    esf = 0

    for j in range(0,len(information)):

        if information[i][0] == information[j][0]:
            esf = esf + information[j][1]

    Esforzo.append([information[i][0], esf])

repeatedindx = []
yavisto = []

for i in range(0,len(Esforzo)):

    for j in range(0,len(Esforzo)):

        if Esforzo[i][0] == Esforzo[j][0] and j != i and Esforzo[i][0] not in yavisto:

                   repeatedindx.append(j)

    yavisto.append(Esforzo[i][0])

repeatedindx = list(dict.fromkeys(repeatedindx))

somelist = [i for j, i in enumerate(Esforzo) if j not in repeatedindx]

somelist.sort()

reacc = pd.read_excel('Estructura.xlsx', sheet_name = 'Reacciones')['Reacc']

apoyos = pd.read_excel('Estructura.xlsx', sheet_name = 'Reacciones')['Apoyos'].to_list()

reacc = pd.DataFrame(reacc)

for i in range(0,len(somelist)):

    printeo = []

    if somelist[i][0] in apoyos:
        print('\n En el nodo ', somelist[i][0], ' las reacciones en coordenadas globales sumando las fuerzas aplicadas son las siguientes: \n')

        printeo = reacc.loc[i*3:i*3+2] + somelist[i][1]

        printeo = printeo.to_numpy()

        deifei = pd.DataFrame(printeo, index = ['Rx', 'Ry', 'Mz'], columns = ['Valor'])
        print(deifei)

```

     En el nodo  3  las reacciones en coordenadas globales sumando las fuerzas aplicadas son las siguientes:

              Valor
    Rx    62.904914
    Ry  1412.396774
    Mz  -912.396774

     En el nodo  5  las reacciones en coordenadas globales sumando las fuerzas aplicadas son las siguientes:

             Valor
    Rx -295.872280
    Ry  587.603226
    Mz -291.730946

     En el nodo  7  las reacciones en coordenadas globales sumando las fuerzas aplicadas son las siguientes:

              Valor
    Rx   -62.904914
    Ry  1412.396774
    Mz   912.396774

     En el nodo  8  las reacciones en coordenadas globales sumando las fuerzas aplicadas son las siguientes:

             Valor
    Rx  295.872280
    Ry  587.603226
    Mz  291.730946

# Cálculo simbólico

Va a dar warnings y no es muy visual pero da el sistema reducido que es lo importante.

```python
estructura = pd.read_excel('Estructura.xlsx', sheet_name='Estructuras')
estructura = estructura.sort_values('nodoi')
maxlen = np.array([estructura['nodoi'].max(),estructura['nodof'].max()]).max()
```

```python
estructura = pd.read_excel('Estructura.xlsx', sheet_name='Estructuras')
estructura = estructura.sort_values('nodoi')
maxlen = np.array([estructura['nodoi'].max(),estructura['nodof'].max()]).max()

A = np.zeros(shape=(3*(maxlen),3*(maxlen)))
A = pd.DataFrame(A)

printinfo = []

for row in estructura.iterrows():
    cualprimero = 0
    inforow = row[1]
    iterator = inforow['nodoi']
    finnode = inforow['nodof']
    infobarra = inforow['barra']
    EA = inforow['EA']
    EI = inforow['EI']

    condini = 0
    condfin = 3
    esquinacol = 3
    esquinafila = 0

    M = calculamatricesSIMB(EA,EI,inforow['L'],inforow['cos'],inforow['sen'],inforow['tipo'])

    for i in range(0,3):
        for j in range(0,3):
            A[3*(iterator-1)+i][3*(iterator-1)+j] =  A[3*(iterator-1)+i][3*(iterator-1)+j]  + M[condini+i][condini+j]  # aquí el generador de elementos
            #print('\n \n','Barra ',inforow['barra'],' Tipo 1 ',' Nodo ', inforow['nodoi'], '-', inforow['nodof'], ' Término ',[condini+i,condini+j] , ' = ', M[condini+i][condini+j],' Ensamblado en elemento ',  [3*(iterator-1)+i,3*(iterator-1)+j] ,' sumado a ',  A[3*(iterator-1)+i][3*(iterator-1)+j] - M[condini+i][condini+j] ,' \n \n')

    for i in range(0,3):
        for j in range(0,3):
            A[3*(finnode-1)+i][3*(finnode-1)+j] =  A[3*(finnode-1)+i][3*(finnode-1)+j]  + M[condfin+i][condfin+j]  # aquí el generador de elementos
            #print('\n \n','Barra ',inforow['barra'],' Tipo 2 ',' Nodo ', inforow['nodoi'], '-', inforow['nodof'], ' Término ',[condfin+i, condfin+j] , ' = ', M[condfin+i][condfin+j],' Ensamblado en elemento ', [3*(finnode-1)+i,3*(finnode-1)+j],' sumado a ', A[3*(finnode-1)+i][3*(finnode-1)+j] - M[condfin+i][condfin+j],' \n \n')

    for i in range(0,3):
        for j in range(0,3):
            A[3*(iterator-1)+i][3*(finnode-1)+j] =  A[3*(iterator-1)+i][3*(finnode-1)+j] + M[i+esquinafila][j+esquinacol]  # aquí el generador de elementos
            #print('\n \n','Barra ',inforow['barra'],' Tipo 3 ',' Nodo ', inforow['nodoi'], '-', inforow['nodof'], ' Término ',[i+esquinafila,j+esquinacol] , ' = ', M[i+esquinafila][j+esquinacol],' Ensamblado en elemento ', [3*(iterator-1)+i,3*(finnode-1)+j] ,' sumado a ', A[3*(iterator-1)+i][3*(finnode-1)+j] - M[i+esquinafila][j+esquinacol],' \n \n')

    for i in range(0,3):
        for j in range(0,3):
            A[3*(finnode-1)+j][3*(iterator-1)+i] = A[3*(finnode-1)+j][3*(iterator-1)+i]  +  M[j+esquinacol][i+esquinafila] # aquí el generador de elementos
            #print('\n \n','Barra ',inforow['barra'],' Tipo 4 ',' Nodo ', inforow['nodoi'], '-', inforow['nodof'], ' Término ',[i+esquinafila,j+esquinacol] , ' = ', M[i+esquinafila][j+esquinacol],' Ensamblado en elemento ', [3*(iterator-1)+i,3*(finnode-1)+j] ,' sumado a ', A[3*(iterator-1)+i][3*(finnode-1)+j] - M[i+esquinafila][j+esquinacol],' \n \n')

    printinfo.append([infobarra,M,iterator,finnode])

printinfo = sorted(printinfo, key=lambda tup: tup[0])

for i in range(0,len(printinfo)):
    print('\n  \n Barra', printinfo[i][0], '\n \n')#, '\n \n',printinfo[i][1], '\n \n')

    cols = ['U'+str(printinfo[i][2]),   'V'+str(printinfo[i][2]),   'A'+str(printinfo[i][2]),   'U'+str(printinfo[i][3]),   'V'+str(printinfo[i][3]),    'A'+str(printinfo[i][3])]
    df = pd.DataFrame(printinfo[i][1], columns=cols, index=cols)
    print(df)

print('\n \n \n Assembly: \n ')

pd.DataFrame(A).to_excel('FullMatrix.xlsx')

print('Full Matrix dropped to FullMatrix.xlsx \n')

despl = pd.read_excel('Estructura.xlsx', sheet_name='Desplazamientos')
despl = despl.to_numpy()
mxmin = np.where(despl == 1)

mn = mxmin[0].min()
mx = mxmin[0].max()

B = np.zeros(shape=(mx+1-mn,mx+1-mn))
ln = len(B)

for i in range(mn,mx+1):
    B = np.append(B,[A[i][mn:mx+1]],axis = 0)

B = np.delete(B,slice(0,ln),axis = 0)

Eliminate = despl[mn:mx+1]
Eliminate = np.where(Eliminate == 0)

B = np.delete(B, Eliminate[0],0)
B = np.delete(B, Eliminate[0],1)

Result = np.where(despl == 1)[0]

pd.DataFrame(B).to_excel('ReducedMatrix.xlsx')

print('Reduced matrix dropped to ReducedMatrix.xlsx \n')

Forces = pd.read_excel('Estructura.xlsx', sheet_name='Fuerzas')
Forces = Forces.to_numpy()
if(len(Forces) != len(despl)):
    print('/n Warning - Force shape != Despl shape - Check everything is OK /n')

Forces = Forces[mn:mx+1]
Eliminate = despl[mn:mx+1]
Eliminate = np.where(Eliminate == 0)

Forces = np.delete(Forces, Eliminate[0] , 0)

vect = []

for i in range(0,len(Result)):
    indicat = math.floor(Result[i]/3) + 1

    if (math.floor(Result[i]/3))*3 == Result[i]:

        vect.append(['u',indicat])

    if (math.floor(Result[i]/3))*3 + 1 == Result[i]:

        vect.append(['v',indicat])

    if (math.floor(Result[i]/3))*3 + 2 == Result[i]:

        vect.append(['ang',indicat])

print('\n  System:\n ')

print(pd.DataFrame(B))

print('\n Multiplied by: \n')

print(pd.DataFrame(vect, columns = ['type','node']))

print('\n Equaled to: \n')

print(pd.DataFrame(Forces, columns=['Forces']))

```

    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:120: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:121: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:127: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:128: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:134: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:135: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:136: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:137: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:138: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:139: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:141: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:142: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:148: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:149: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:150: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:151: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:152: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:153: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:28: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:33: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:38: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:43: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:129: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:130: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:131: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:132: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:69: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:73: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:74: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:75: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:76: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:77: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:78: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:79: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:80: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:81: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:82: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:83: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:85: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:87: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:88: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:89: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:90: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:91: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:92: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:93: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:94: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:95: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:97: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:98: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:99: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:100: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:102: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:103: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:104: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:105: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:106: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:107: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:108: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    C:\Users\clean\Anaconda3\lib\site-packages\ipykernel_launcher.py:109: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

     Barra 1

                  U1             V1             A1            U2             V2 A2
    U1   1.0*E*I*a/H              0              0  -1.0*E*I*a/H              0  0
    V1             0   3.0*E*I/H**3   3.0*E*I/H**2             0  -3.0*E*I/H**3  0
    A1             0   3.0*E*I/H**2      3.0*E*I/H             0  -3.0*E*I/H**2  0
    U2  -1.0*E*I*a/H              0              0   1.0*E*I*a/H              0  0
    V2             0  -3.0*E*I/H**3  -3.0*E*I/H**2             0   3.0*E*I/H**3  0
    A2             0              0              0             0              0  0

     Barra 2

                  U2             V2 A2            U3             V3             A3
    U2   1.0*E*I*a/H              0  0  -1.0*E*I*a/H              0              0
    V2             0   3.0*E*I/H**3  0             0  -3.0*E*I/H**3   3.0*E*I/H**2
    A2             0              0  0             0              0              0
    U3  -1.0*E*I*a/H              0  0   1.0*E*I*a/H              0              0
    V3             0  -3.0*E*I/H**3  0             0   3.0*E*I/H**3  -3.0*E*I/H**2
    A3             0   3.0*E*I/H**2  0             0  -3.0*E*I/H**2      3.0*E*I/H

     Barra 3

                   U1            V1             A1             U3            V3 A3
    U1   3.0*E*I/H**3             0  -3.0*E*I/H**2  -3.0*E*I/H**3             0  0
    V1              0   1.0*E*I*a/H              0              0  -1.0*E*I*a/H  0
    A1  -3.0*E*I/H**2             0      3.0*E*I/H   3.0*E*I/H**2             0  0
    U3  -3.0*E*I/H**3             0   3.0*E*I/H**2   3.0*E*I/H**3             0  0
    V3              0  -1.0*E*I*a/H              0              0   1.0*E*I*a/H  0
    A3              0             0              0              0             0  0

     Barra 4

                                U4                          V4 A4  \
    U4   0.353553390593274*E*I*a/H  -0.353553390593274*E*I*a/H  0
    V4  -0.353553390593274*E*I*a/H   0.353553390593274*E*I*a/H  0
    A4                           0                           0  0
    U2  -0.353553390593274*E*I*a/H   0.353553390593274*E*I*a/H  0
    V2   0.353553390593274*E*I*a/H  -0.353553390593274*E*I*a/H  0
    A2                           0                           0  0

                                U2                          V2 A2
    U4  -0.353553390593274*E*I*a/H   0.353553390593274*E*I*a/H  0
    V4   0.353553390593274*E*I*a/H  -0.353553390593274*E*I*a/H  0
    A4                           0                           0  0
    U2   0.353553390593274*E*I*a/H  -0.353553390593274*E*I*a/H  0
    V2  -0.353553390593274*E*I*a/H   0.353553390593274*E*I*a/H  0
    A2                           0                           0  0

     Barra 5

                                                       U2  \
    U2  0.353553390593274*E*I*a/H + 0.53033008588991*E...
    V2  -0.353553390593274*E*I*a/H + 0.53033008588991*...
    A2                                                  0
    U5  -0.353553390593274*E*I*a/H - 0.53033008588991*...
    V5  0.353553390593274*E*I*a/H - 0.53033008588991*E...
    A5                          1.06066017177982*E*I/H**2

                                                       V2 A2  \
    U2  -0.353553390593274*E*I*a/H + 0.53033008588991*...  0
    V2  0.353553390593274*E*I*a/H + 0.53033008588991*E...  0
    A2                                                  0  0
    U5  0.353553390593274*E*I*a/H - 0.53033008588991*E...  0
    V5  -0.353553390593274*E*I*a/H - 0.53033008588991*...  0
    A5                          1.06066017177982*E*I/H**2  0

                                                       U5  \
    U2  -0.353553390593274*E*I*a/H - 0.53033008588991*...
    V2  0.353553390593274*E*I*a/H - 0.53033008588991*E...
    A2                                                  0
    U5  0.353553390593274*E*I*a/H + 0.53033008588991*E...
    V5  -0.353553390593274*E*I*a/H + 0.53033008588991*...
    A5                         -1.06066017177982*E*I/H**2

                                                       V5  \
    U2  0.353553390593274*E*I*a/H - 0.53033008588991*E...
    V2  -0.353553390593274*E*I*a/H - 0.53033008588991*...
    A2                                                  0
    U5  -0.353553390593274*E*I*a/H + 0.53033008588991*...
    V5  0.353553390593274*E*I*a/H + 0.53033008588991*E...
    A5                         -1.06066017177982*E*I/H**2

                                A5
    U2   1.06066017177982*E*I/H**2
    V2   1.06066017177982*E*I/H**2
    A2                           0
    U5  -1.06066017177982*E*I/H**2
    V5  -1.06066017177982*E*I/H**2
    A5      2.12132034355964*E*I/H

     Barra 6

                  U1             V1             A1            U6             V6 A6
    U1   1.0*E*I*a/H              0              0  -1.0*E*I*a/H              0  0
    V1             0   3.0*E*I/H**3  -3.0*E*I/H**2             0  -3.0*E*I/H**3  0
    A1             0  -3.0*E*I/H**2      3.0*E*I/H             0   3.0*E*I/H**2  0
    U6  -1.0*E*I*a/H              0              0   1.0*E*I*a/H              0  0
    V6             0  -3.0*E*I/H**3   3.0*E*I/H**2             0   3.0*E*I/H**3  0
    A6             0              0              0             0              0  0

     Barra 7

                  U6             V6 A6            U7             V7             A7
    U6   1.0*E*I*a/H              0  0  -1.0*E*I*a/H              0              0
    V6             0   3.0*E*I/H**3  0             0  -3.0*E*I/H**3  -3.0*E*I/H**2
    A6             0              0  0             0              0              0
    U7  -1.0*E*I*a/H              0  0   1.0*E*I*a/H              0              0
    V7             0  -3.0*E*I/H**3  0             0   3.0*E*I/H**3   3.0*E*I/H**2
    A7             0  -3.0*E*I/H**2  0             0   3.0*E*I/H**2      3.0*E*I/H

     Barra 8

                                U4                          V4 A4  \
    U4   0.353553390593274*E*I*a/H   0.353553390593274*E*I*a/H  0
    V4   0.353553390593274*E*I*a/H   0.353553390593274*E*I*a/H  0
    A4                           0                           0  0
    U6  -0.353553390593274*E*I*a/H  -0.353553390593274*E*I*a/H  0
    V6  -0.353553390593274*E*I*a/H  -0.353553390593274*E*I*a/H  0
    A6                           0                           0  0

                                U6                          V6 A6
    U4  -0.353553390593274*E*I*a/H  -0.353553390593274*E*I*a/H  0
    V4  -0.353553390593274*E*I*a/H  -0.353553390593274*E*I*a/H  0
    A4                           0                           0  0
    U6   0.353553390593274*E*I*a/H   0.353553390593274*E*I*a/H  0
    V6   0.353553390593274*E*I*a/H   0.353553390593274*E*I*a/H  0
    A6                           0                           0  0

     Barra 9

                                                       U6  \
    U6  0.353553390593274*E*I*a/H + 0.53033008588991*E...
    V6  0.353553390593274*E*I*a/H - 0.53033008588991*E...
    A6                                                  0
    U8  -0.353553390593274*E*I*a/H - 0.53033008588991*...
    V8  -0.353553390593274*E*I*a/H + 0.53033008588991*...
    A8                          1.06066017177982*E*I/H**2

                                                       V6 A6  \
    U6  0.353553390593274*E*I*a/H - 0.53033008588991*E...  0
    V6  0.353553390593274*E*I*a/H + 0.53033008588991*E...  0
    A6                                                  0  0
    U8  -0.353553390593274*E*I*a/H + 0.53033008588991*...  0
    V8  -0.353553390593274*E*I*a/H - 0.53033008588991*...  0
    A8                         -1.06066017177982*E*I/H**2  0

                                                       U8  \
    U6  -0.353553390593274*E*I*a/H - 0.53033008588991*...
    V6  -0.353553390593274*E*I*a/H + 0.53033008588991*...
    A6                                                  0
    U8  0.353553390593274*E*I*a/H + 0.53033008588991*E...
    V8  0.353553390593274*E*I*a/H - 0.53033008588991*E...
    A8                         -1.06066017177982*E*I/H**2

                                                       V8  \
    U6  -0.353553390593274*E*I*a/H + 0.53033008588991*...
    V6  -0.353553390593274*E*I*a/H - 0.53033008588991*...
    A6                                                  0
    U8  0.353553390593274*E*I*a/H - 0.53033008588991*E...
    V8  0.353553390593274*E*I*a/H + 0.53033008588991*E...
    A8                          1.06066017177982*E*I/H**2

                                A8
    U6   1.06066017177982*E*I/H**2
    V6  -1.06066017177982*E*I/H**2
    A6                           0
    U8  -1.06066017177982*E*I/H**2
    V8   1.06066017177982*E*I/H**2
    A8      2.12132034355964*E*I/H

     Assembly:

    Full Matrix dropped to FullMatrix.xlsx

    Reduced matrix dropped to ReducedMatrix.xlsx

      System:

                                0  \
    0  1.0*E*I*a/H + 6.0*E*I/H**3
    1                           0
    2               -3.0*E*I/H**3
    3                           0
    4                           0
    5               -3.0*E*I/H**3

                                                       1  \
    0                                                  0
    1  2.70710678118655*E*I*a/H + 0.53033008588991*E*...
    2  -0.707106781186548*E*I*a/H + 0.53033008588991*...
    3                          0.353553390593274*E*I*a/H
    4                                                  0
    5                                                  0

                                                       2  \
    0                                      -3.0*E*I/H**3
    1  -0.707106781186548*E*I*a/H + 0.53033008588991*...
    2  0.707106781186548*E*I*a/H + 6.53033008588991*E...
    3                         -0.353553390593274*E*I*a/H
    4                                                  0
    5                                                  0

                                3  \
    0                           0
    1   0.353553390593274*E*I*a/H
    2  -0.353553390593274*E*I*a/H
    3   0.707106781186548*E*I*a/H
    4  -0.353553390593274*E*I*a/H
    5  -0.353553390593274*E*I*a/H

                                                       4  \
    0                                                  0
    1                                                  0
    2                                                  0
    3                         -0.353553390593274*E*I*a/H
    4  2.70710678118655*E*I*a/H + 0.53033008588991*E*...
    5  0.707106781186548*E*I*a/H - 0.53033008588991*E...

                                                       5
    0                                      -3.0*E*I/H**3
    1                                                  0
    2                                                  0
    3                         -0.353553390593274*E*I*a/H
    4  0.707106781186548*E*I*a/H - 0.53033008588991*E...
    5  0.707106781186548*E*I*a/H + 6.53033008588991*E...

     Multiplied by:

      type  node
    0    v     1
    1    u     2
    2    v     2
    3    v     4
    4    u     6
    5    v     6

     Equaled to:

       Forces
    0       0
    1       0
    2  137782
    3 -137782
    4       0
    5       0

```python
localesaglobales(np.array([1512000,0,-5040,-1512000,0,5040]),-0.8,0.6)
```

    array([-1209600.,   907200.,    -5040.,  1209600.,  -907200.,     5040.])

```python
globalesalocales(np.array([1,-1,0,0,0,0]),0,1)
```

    array([-1., -1.,  0.,  0.,  0.,  0.])


# import module

```python
import numpy as np
import numba
import xarray as xr
```

# Continuous Equation

$$
    \begin{align}
        \frac{\partial h}{\partial t}+\frac{\partial q_x}{\partial x} +\frac{\partial q_y}{\partial y} = 0
    \end{align}
$$

```python
@numba.jit(nopython=True, parallel=False)
def conEq(dep, qx, qy, dt, dx, dy, hmin):
    imax, jmax = len(dep), len(dep[0])
    depn = np.empty_like(dep)
    fluxx = np.zeros((imax+1, jmax))
    fluxy = np.zeros((imax, jmax+1))

#     flux = lambda Qp, Qm : Qm if Qp > 0.0 and Qm > 0.0 else (Qp if Qp < 0.0 and Qm < 0.0 else 0.5*Qp+0.5*Qm )
    def flux( Qp, Qm) :
        if Qp > 0.0 and Qm > 0.0 :
            r = Qm
        elif Qp < 0.0 and Qm < 0.0 :
            r = Qp
        else :
# treatment of dry-bed
            if Qp == 0.0 and Qm == 0.0 :
                r = 0.0
            elif Qp == 0.0 :
                r = Qm if Qm > 0.0 else 0.0
            elif Qm == 0.0 :
                r = Qp if Qp < 0.0 else 0.0
            else :
                r = 0.5*Qp+0.5*Qm

        return r

    for i in numba.prange( imax ):
        for j in numba.prange( jmax ):
            c, xm, ym = (i,j), (i-1,j), (i,j-1)
            fluxx[c] = flux(qx[c], qx[xm])
            fluxy[c] = flux(qy[c], qy[ym])

# continuous boundary
    fluxx[-1,:] = fluxx[0,:]
    fluxy[:,-1] = fluxy[:,0]

    for i in numba.prange(imax):
        for j in numba.prange(jmax):
            c, xp, yp = (i, j), (i+1, j), (i, j+1)
            depn[c] = dep[c] - dt*(fluxx[xp] - fluxx[c])/dx - dt*(fluxy[yp] - fluxy[c])/dy
            if depn[c] < hmin*2 : depn[c] = hmin

    return depn
```

# Momentum Equation

$$
    \begin{align}
        \frac{\partial q_x}{\partial t}+\frac{\partial u q_x}{\partial x}+\frac{\partial v q_x}{\partial y}+gh\frac{\partial H}{\partial x}+\frac{\tau_{0x}}{\rho}
        - \nu_t h \left(\frac{\partial^2 u}{\partial x^2}+\frac{\partial^2 u}{\partial y^2} \right)= 0 \\
        \frac{\partial q_y}{\partial t}+\frac{\partial u q_y}{\partial x}+\frac{\partial v q_y}{\partial y}+gh\frac{\partial H}{\partial y}+\frac{\tau_{0y}}{\rho}- \nu_t h \left(\frac{\partial^2 v}{\partial x^2}+\frac{\partial^2 v}{\partial y^2} \right)
        = 0
    \end{align}
$$

```python
@numba.jit(nopython=True, parallel=False)
def momentEq(dep, qx, qy, depn, zb, dt, dx, dy, hmin, direction):
    #direction = 1:x, 2:y
    gravity = 9.8
    cManing = 0.02
    ib = 1.0/670.0

    q = qx if direction == 1 else qy
    u, v = qx/dep, qy/dep

    imax, jmax = len(q), len(q[0])

    qn = np.empty_like(q)
    fluxx = np.zeros((imax+1, jmax))
    fluxy = np.zeros((imax, jmax+1))

    flux = lambda vp,vm,qp,qm : vm*qm if vp > 0.0 and vm > 0.0 \
                 else (vp*qp if vp < 0.0 and vm < 0.0 else (0.5*vp+0.5*vm)*(0.5*qp+0.5*qm) )

    for i in numba.prange( imax ):
        for j in numba.prange( jmax ):
            c, xm, ym = (i,j), (i-1,j), (i,j-1)
            fluxx[c] = flux( u[c], u[xm], q[c], q[xm] )
            fluxy[c] = flux( v[c], v[ym], q[c], q[ym] )

# continuous boundary
    fluxx[-1,:] = fluxx[0,:]
    fluxy[:,-1] = fluxy[:,0]

    for i in numba.prange(imax):
        for j in numba.prange(jmax):
            c = (i, j)
            if depn[c] <= hmin*2 :
                qn[c] = 0.0
            else:
        # pressure & gravity term
                c, xm, ym = (i,j), (i-1, j), (i, j-1)
                xp = (0, j) if i == imax - 1 else (i+1, j  )
                yp = (i, 0) if j == jmax - 1 else (i  , j+1)

                if direction == 1 :
                    dp, dm, delta = xp, xm, dx
                else :
                    dp, dm, delta = yp, ym, dy

                Vc, Vp, Vm = q[c]/dep[c], q[dp]/dep[dp], q[dm]/dep[dm]
                Hc, Hp, Hm = depn[c]+zb[c], depn[dp]+zb[dp], depn[dm]+zb[dm]

                if Vc > 0.0 and Vp > 0.0 and Vm > 0.0:
                    Cr1, Cr2 = 0.5*(abs(Vc)+abs(Vp))*dt/delta, 0.5*(abs(Vc)+abs(Vm))*dt/delta
                    dHdx1, dHdx2 = (Hp-Hc)/delta-ib, (Hc-Hm)/delta-ib
                elif Vc < 0.0 and Vp < 0.0 and Vm < 0.0:
                    Cr1, Cr2 = 0.5*(abs(Vc)+abs(Vm))*dt/delta, 0.5*(abs(Vc)+abs(Vp))*dt/delta
                    dHdx1, dHdx2 = (Hc-Hm)/delta-ib, (Hp-Hc)/delta-ib
                else:
                    Cr1 = Cr2 = 0.5*(abs(0.5*(Vc+Vp))+abs(0.5*(Vc+Vm)))*dt/delta
                    dHdx1 = dHdx2 = (0.5*(Hc+Hp) - 0.5*(Hc+Hm)) / delta - ib

                w1, w2 = 1-Cr1**0.5, Cr2**0.5
                dHdx = w1 * dHdx1 + w2 * dHdx2

#viscous sublayer
                Cf = gravity*cManing**2.0/dep[c]**(1.0/3.0)
                Vnorm = np.sqrt(u[c]**2.0+v[c]**2.0)
                Vis = Cf * Vnorm * u[c] if direction == 1 else  Cf * Vnorm * v[c]
#turbulence
#                kenergy = 2.07*Cf*Vnorm**2
                nut = 0.4/6.0*dep[c]*np.sqrt(Cf)*np.abs(Vnorm)

                turb = nut * ( u[xp] - 2.0*u[c] + u[xm] )/ dx**2 \
                     + nut * ( u[yp] - 2.0*u[c] + u[ym] )/ dy**2

                c, xp, yp = (i,j), (i+1,j), (i,j+1)
                qn[c] = q[c] - dt * ( fluxx[xp] - fluxx[c] ) / dx \
                             - dt * ( fluxy[yp] - fluxy[c] ) / dy \
                             - dt * gravity * depn[c] * dHdx \
                             - dt * Vis \
                             + dt * dep[c] * turb

    return qn
```

```python
@numba.jit(nopython=True, parallel=False)
def simulation(dep, qx, qy, zb, dt, dx, dy, hmin):
    depn = conEq(dep, qx, qy, dt, dx, dy, hmin)
    qxn = momentEq(dep, qx, qy, depn, zb, dt, dx, dy, hmin, 1)
    qyn = momentEq(dep, qx, qy, depn, zb, dt, dx, dy, hmin, 2)
    CFL = ((np.abs(qxn/depn))/dx + (np.abs(qyn/depn))/dy)*dt
    CFLmin = np.max(CFL)
    return depn, qxn, qyn, CFLmin
```

# Main routine

## read elevation data

```python
ds = xr.open_dataset('dz.nc')
dza = ds['dz']
dz = dza.values
ds.close()
```

## main

```python
%%time

hmin = 10.0**(-3)
nxmax = len(dz)
nymax = len(dz[0])
dx = 5.0
dy = 5.0
dt = 0.1
dtout= 200.0
tmax = 3600.0

qx = np.zeros((nxmax,nymax))
qy = np.zeros_like(qx)
zb = dz #np.zeros_like(qx)

# Initial Condition
dep = np.full_like(zb, 0.4)

def timeGenerater():
    it, itout = 0, 1
    isTiter, isOut = True, False
    yield it*dt, isTiter, isOut

    while True:
        it += 1
        if it*dt >= itout*dtout:
            itout += 1
            isOut = True
        else:
            isOut = False

        if it*dt >= tmax: isTiter = False

        yield it*dt, isTiter, isOut

tgen = timeGenerater()
t, isTiter, isOut = next(tgen)
tarr = [t]
deparr = np.array([dep])
uarr = np.array([qx/dep])
varr = np.array([qy/dep])

nout= 1
while isTiter:
    dep, qx, qy, CFLmin = simulation(dep, qx, qy, zb, dt, dx, dy, hmin)
    t, isTiter, isOut = next(tgen)
    if isOut:
        tarr.append(round(t,2))
        deparr = np.append(deparr, np.array([dep]), axis=0)
        uarr = np.append(uarr, np.array([qx/dep]), axis=0)
        varr = np.append(varr, np.array([qy/dep]), axis=0)
        print(t,CFLmin)
        nout += 1

dss = xr.Dataset({'depth': (['t','x','y'], deparr), 'u': (['t','x','y'], uarr), 'v': (['t','x','y'], varr)}, coords={'xc': (('x', 'y'), dza['xc'])
                                             , 'yc': (('x', 'y'), dza['yc'])
                                             , 't': tarr})

dss.to_netcdf('output.nc')
```

    200.0 0.12994759757305765
    400.0 0.05324376553275483
    600.0 0.13465034344958737
    800.0 0.08917062844146038
    1000.0 0.06319218033460254
    1200.0 0.11995618722432487
    1400.0 0.07224942603327707
    1600.0 0.12386222201873731
    1800.0 0.06899316890484393
    2000.0 0.170605601280248
    2200.0 0.06517755577401307
    2400.0 0.1353129352137529
    2600.0 0.0615231283218484
    2800.0 0.07240785399189434
    3000.0 0.07694049275220537
    3200.0 0.06135978323502305
    3400.0 0.08224366525350822
    3600.0 0.061249249226995206
    Wall time: 21.4 s

## check total volume

```python
np.sum( deparr[-1] ), np.sum( deparr[0] )
```

    (1524.5068734878676, 1527.6000000000004)