from __future__ import division

import torch
import torch.autograd as autograd
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import numpy as np
import sys
import os
import time


#
# TORCH INSTALLATION: refer to https://pytorch.org/get-started/locally/
#



def update_progress(job_title, progress):
    length = 20 # modify this to change the length
    block = int(round(length*progress))
    msg = "\r{0}: [{1}] {2}%".format(job_title, "#"*block + "-"*(length-block), round(progress*100, 2))
    if progress >= 1: msg += " DONE\r\n"
    sys.stdout.write(msg)
    sys.stdout.flush()

def cls():
    os.system('cls' if os.name=='nt' else 'clear')


cls()


################################################################################################################

# Initialize torch tensor for coordiantes 
coords_data  = [[ 0.0           , 0.0 , 0.0           ],
                [ 1.0/(2.0**0.5), 0.0 , 1.0/(2.0**0.5)],
                [ 1.0/(2.0**0.5), 0.0 ,-1.0/(2.0**0.5)],
                [ 2.0**0.5      , 0.0 , 0.0           ],
                [ 0.0           , 1.0 , 0.0           ],
                [ 1.0/(2.0**0.5), 1.0 , 1.0/(2.0**0.5)],
                [ 1.0/(2.0**0.5), 1.0 ,-1.0/(2.0**0.5)],
                [ 2.0**0.5      , 1.0 , 0.0           ],
                ] 
coords = torch.tensor(coords_data,requires_grad=True,dtype=torch.float64)


nnodes_r   = coords.size(0)
nnodes_ie  = 8 
nnodes_if  = 4 
nterms_s   = 8
ndirs      = 3
coord_sys  = 'CARTESIAN'



# Define matrix of polynomial basis terms at support nodes
val_r_data = [[ 1.0,-1.0,-1.0,-1.0, 1.0, 1.0, 1.0,-1.0],
              [ 1.0,-1.0,-1.0, 1.0,-1.0,-1.0, 1.0, 1.0],
              [ 1.0, 1.0,-1.0,-1.0,-1.0, 1.0,-1.0, 1.0],
              [ 1.0, 1.0,-1.0, 1.0, 1.0,-1.0,-1.0,-1.0],
              [ 1.0,-1.0, 1.0,-1.0, 1.0,-1.0,-1.0, 1.0],
              [ 1.0,-1.0, 1.0, 1.0,-1.0, 1.0,-1.0,-1.0],
              [ 1.0, 1.0, 1.0,-1.0,-1.0,-1.0, 1.0,-1.0],
              [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
              ] 
val_r = torch.tensor(val_r_data,requires_grad=False,dtype=torch.float64)


# Define matrices at interpolation nodes (quadrature, level = 1)
val_i_data = [[ 1.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), 1.0/3.0, 1.0/3.0, 1.0/3.0,-1.0/3.0*np.sqrt(1.0/3.0)],
              [ 1.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0/3.0,-1.0/3.0, 1.0/3.0, 1.0/3.0*np.sqrt(1.0/3.0)],
              [ 1.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0/3.0, 1.0/3.0,-1.0/3.0, 1.0/3.0*np.sqrt(1.0/3.0)],
              [ 1.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), 1.0/3.0,-1.0/3.0,-1.0/3.0,-1.0/3.0*np.sqrt(1.0/3.0)],
              [ 1.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), 1.0/3.0,-1.0/3.0,-1.0/3.0, 1.0/3.0*np.sqrt(1.0/3.0)],
              [ 1.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0/3.0, 1.0/3.0,-1.0/3.0,-1.0/3.0*np.sqrt(1.0/3.0)],
              [ 1.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0/3.0,-1.0/3.0, 1.0/3.0,-1.0/3.0*np.sqrt(1.0/3.0)],
              [ 1.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), 1.0/3.0, 1.0/3.0, 1.0/3.0, 1.0/3.0*np.sqrt(1.0/3.0)],
              ]
val_i = torch.tensor(val_i_data,requires_grad=False,dtype=torch.float64)


ddxi_i_data  = [[ 0.0,0.0,0.0,1.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),0.0, 1.0/3.0],
                [ 0.0,0.0,0.0,1.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),0.0, 1.0/3.0],
                [ 0.0,0.0,0.0,1.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),0.0,-1.0/3.0],
                [ 0.0,0.0,0.0,1.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),0.0,-1.0/3.0],
                [ 0.0,0.0,0.0,1.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),0.0,-1.0/3.0],
                [ 0.0,0.0,0.0,1.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),0.0,-1.0/3.0],
                [ 0.0,0.0,0.0,1.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),0.0, 1.0/3.0],
                [ 0.0,0.0,0.0,1.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),0.0, 1.0/3.0],
                ]
ddxi_i = torch.tensor(ddxi_i_data,requires_grad=False,dtype=torch.float64)

ddeta_i_data = [[ 0.0,1.0,0.0,0.0,-np.sqrt(1.0/3.0),0.0,-np.sqrt(1.0/3.0), 1.0/3.0],
                [ 0.0,1.0,0.0,0.0, np.sqrt(1.0/3.0),0.0,-np.sqrt(1.0/3.0),-1.0/3.0],
                [ 0.0,1.0,0.0,0.0,-np.sqrt(1.0/3.0),0.0,-np.sqrt(1.0/3.0), 1.0/3.0],
                [ 0.0,1.0,0.0,0.0, np.sqrt(1.0/3.0),0.0,-np.sqrt(1.0/3.0),-1.0/3.0],
                [ 0.0,1.0,0.0,0.0,-np.sqrt(1.0/3.0),0.0, np.sqrt(1.0/3.0),-1.0/3.0],
                [ 0.0,1.0,0.0,0.0, np.sqrt(1.0/3.0),0.0, np.sqrt(1.0/3.0), 1.0/3.0],
                [ 0.0,1.0,0.0,0.0,-np.sqrt(1.0/3.0),0.0, np.sqrt(1.0/3.0),-1.0/3.0],
                [ 0.0,1.0,0.0,0.0, np.sqrt(1.0/3.0),0.0, np.sqrt(1.0/3.0), 1.0/3.0],
                ]
ddeta_i = torch.tensor(ddeta_i_data,requires_grad=False,dtype=torch.float64)

ddzeta_i_data= [[ 0.0,0.0,1.0,0.0,0.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), 1.0/3.0],
                [ 0.0,0.0,1.0,0.0,0.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0/3.0],
                [ 0.0,0.0,1.0,0.0,0.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0/3.0],
                [ 0.0,0.0,1.0,0.0,0.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), 1.0/3.0],
                [ 0.0,0.0,1.0,0.0,0.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), 1.0/3.0],
                [ 0.0,0.0,1.0,0.0,0.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0/3.0],
                [ 0.0,0.0,1.0,0.0,0.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0/3.0],
                [ 0.0,0.0,1.0,0.0,0.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), 1.0/3.0],
                ]
ddzeta_i = torch.tensor(ddzeta_i_data,requires_grad=False,dtype=torch.float64)

# Define element interpolation nodes weights for linear element
weights_e_data = [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0] 
weights_e = torch.tensor(weights_e_data,requires_grad=False,dtype=torch.float64)


# Define val_f for each face
# Face 1, XI_MIN
val_1_data   = [[ 1.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), 1.0/3.0,-1.0/3.0],
               [ 1.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0/3.0, 1.0/3.0],
               [ 1.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0/3.0, 1.0/3.0],
               [ 1.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), 1.0/3.0,-1.0/3.0],
               ]
val_1 = torch.tensor(val_1_data,requires_grad=False,dtype=torch.float64)

# Face 2, XI_MAX
val_2_data   = [[ 1.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),1.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), 1.0/3.0, 1.0/3.0],
                [ 1.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),1.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0/3.0,-1.0/3.0],
                [ 1.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),1.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0/3.0,-1.0/3.0],
                [ 1.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),1.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), 1.0/3.0, 1.0/3.0],
                ] 
val_2 = torch.tensor(val_2_data,requires_grad=False,dtype=torch.float64)

# Face 3, ETA_MIN
val_3_data   = [[ 1.0,-1.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), 1.0/3.0, np.sqrt(1.0/3.0),-1.0/3.0],
                [ 1.0,-1.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0/3.0, np.sqrt(1.0/3.0), 1.0/3.0],
                [ 1.0,-1.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0/3.0,-np.sqrt(1.0/3.0), 1.0/3.0],
                [ 1.0,-1.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), 1.0/3.0,-np.sqrt(1.0/3.0),-1.0/3.0],
                ] 
val_3 = torch.tensor(val_3_data,requires_grad=False,dtype=torch.float64)

# Face 4, ETA_MAX
val_4_data   = [[ 1.0,1.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), 1.0/3.0,-np.sqrt(1.0/3.0), 1.0/3.0],
                [ 1.0,1.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0/3.0,-np.sqrt(1.0/3.0),-1.0/3.0],
                [ 1.0,1.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0/3.0, np.sqrt(1.0/3.0),-1.0/3.0],
                [ 1.0,1.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), 1.0/3.0, np.sqrt(1.0/3.0), 1.0/3.0],
                ]
val_4 = torch.tensor(val_4_data,requires_grad=False,dtype=torch.float64)

# Face 5, ZETA_MIN
val_5_data   = [[ 1.0,-np.sqrt(1.0/3.0),-1.0,-np.sqrt(1.0/3.0), 1.0/3.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0/3.0],
                [ 1.0,-np.sqrt(1.0/3.0),-1.0, np.sqrt(1.0/3.0),-1.0/3.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), 1.0/3.0],
                [ 1.0, np.sqrt(1.0/3.0),-1.0,-np.sqrt(1.0/3.0),-1.0/3.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), 1.0/3.0],
                [ 1.0, np.sqrt(1.0/3.0),-1.0, np.sqrt(1.0/3.0), 1.0/3.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0/3.0],
                ]
val_5 = torch.tensor(val_5_data,requires_grad=False,dtype=torch.float64)

# Face 6, ZETA_MAX
val_6_data   = [[ 1.0,-np.sqrt(1.0/3.0),1.0,-np.sqrt(1.0/3.0), 1.0/3.0,-np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0), 1.0/3.0],
                [ 1.0,-np.sqrt(1.0/3.0),1.0, np.sqrt(1.0/3.0),-1.0/3.0, np.sqrt(1.0/3.0),-np.sqrt(1.0/3.0),-1.0/3.0],
                [ 1.0, np.sqrt(1.0/3.0),1.0,-np.sqrt(1.0/3.0),-1.0/3.0,-np.sqrt(1.0/3.0), np.sqrt(1.0/3.0),-1.0/3.0],
                [ 1.0, np.sqrt(1.0/3.0),1.0, np.sqrt(1.0/3.0), 1.0/3.0, np.sqrt(1.0/3.0), np.sqrt(1.0/3.0), 1.0/3.0],
                ]
val_6 = torch.tensor(val_6_data,requires_grad=False,dtype=torch.float64)





#--------------------------------------------------------------------

# Matrix modes_to_nodes
val_r_inv = torch.inverse(val_r)


# Computes coordiantes modes
coords_modes = torch.mm(val_r_inv,coords)


# Initialized coordiantes
interp_coords = torch.mm(val_i,coords_modes)


# Initialized jacobian
jacobian = torch.empty(3,3,nnodes_ie, dtype=torch.float64) 
for inode in range(0,nnodes_ie):
    jacobian[0,0,inode] = torch.dot(ddxi_i[inode,:]   , coords_modes[:,0])
    jacobian[0,1,inode] = torch.dot(ddeta_i[inode,:]  , coords_modes[:,0])
    jacobian[0,2,inode] = torch.dot(ddzeta_i[inode,:] , coords_modes[:,0])
    jacobian[1,0,inode] = torch.dot(ddxi_i[inode,:]   , coords_modes[:,1])
    jacobian[1,1,inode] = torch.dot(ddeta_i[inode,:]  , coords_modes[:,1])
    jacobian[1,2,inode] = torch.dot(ddzeta_i[inode,:] , coords_modes[:,1])
    jacobian[2,0,inode] = torch.dot(ddxi_i[inode,:]   , coords_modes[:,2])
    jacobian[2,1,inode] = torch.dot(ddeta_i[inode,:]  , coords_modes[:,2])
    jacobian[2,2,inode] = torch.dot(ddzeta_i[inode,:] , coords_modes[:,2])
    update_progress("Computing Jacobian                 ", inode/(nnodes_ie-1))
if coord_sys == 'CYLINDRICAL':
    scaling_factor = torch.mm(val_i,coords_modes[:,0])
    for inode in range(0,nnodes_ie):
        jacobian[1,0,inode] = jacobian[1,0,inode] * scaling_factor[inode]
        jacobian[1,1,inode] = jacobian[1,1,inode] * scaling_factor[inode]
        jacobian[1,2,inode] = jacobian[1,2,inode] * scaling_factor[inode]



# Matrics and Determinant
metrics = torch.empty(3,3,nnodes_ie, dtype=torch.float64) 
jinv    = torch.empty(nnodes_ie, dtype=torch.float64) 
for inode in range(0,nnodes_ie):
    ijacobian = torch.empty(3,3, dtype=torch.float64)
    imetric   = torch.empty(3,3, dtype=torch.float64)
    for irow in range(0,3):
        for icol in range(0,3):
            ijacobian[irow,icol] = jacobian[irow,icol,inode]
    # Compute jacobian for the ith node
    update_progress("Computing Jinv and Metric          ", inode/(nnodes_ie-1))
    jinv[inode] = torch.det(ijacobian) 
    imetric     = torch.inverse(ijacobian)
    for irow in range(0,3):
        for icol in range(0,3):
            metrics[irow,icol,inode] = imetric[irow,icol]

 
# Compute inverse Mass matrix
invmass = torch.empty(nterms_s,nterms_s,nnodes_ie, dtype=torch.float64)
mass    = torch.empty(nterms_s,nterms_s,nnodes_ie, dtype=torch.float64)
val_tmp = torch.empty(nterms_s,nnodes_ie, dtype=torch.float64)
i = 1
for iterm in range(0,nterms_s):
    for inode in range(0,nnodes_ie):
        val_tmp[inode,iterm] = val_i[inode,iterm] * weights_e[inode] * jinv[inode]
        update_progress("Computing invmass                  ", i/(nterms_s*nnodes_ie))
        i += 1
mass    = torch.mm(torch.t(val_tmp),val_i)
invmass = torch.inverse(mass)


# Compute BR2_VOL for each face
br2_vol_face1 = torch.mm(val_i,torch.mm(invmass,torch.t(val_1)))
br2_vol_face2 = torch.mm(val_i,torch.mm(invmass,torch.t(val_2)))
br2_vol_face3 = torch.mm(val_i,torch.mm(invmass,torch.t(val_3)))
br2_vol_face4 = torch.mm(val_i,torch.mm(invmass,torch.t(val_4)))
br2_vol_face5 = torch.mm(val_i,torch.mm(invmass,torch.t(val_5)))
br2_vol_face6 = torch.mm(val_i,torch.mm(invmass,torch.t(val_6)))
update_progress("Computing br2_vol                  ", 1)


# Compute BR2_FACE for each face
br2_face_face1 = torch.mm(val_1,torch.mm(invmass,torch.t(val_1)))
br2_face_face2 = torch.mm(val_2,torch.mm(invmass,torch.t(val_2)))
br2_face_face3 = torch.mm(val_3,torch.mm(invmass,torch.t(val_3)))
br2_face_face4 = torch.mm(val_4,torch.mm(invmass,torch.t(val_4)))
br2_face_face5 = torch.mm(val_5,torch.mm(invmass,torch.t(val_5)))
br2_face_face6 = torch.mm(val_6,torch.mm(invmass,torch.t(val_6)))
update_progress("Computing br2_face                 ", 1)


# Grad1, Grad2, and Grad3
grad1 = torch.empty(nnodes_ie,nterms_s, dtype=torch.float64)
grad2 = torch.empty(nnodes_ie,nterms_s, dtype=torch.float64)
grad3 = torch.empty(nnodes_ie,nterms_s, dtype=torch.float64)
i = 1
for iterm in range(0,nterms_s):
    for inode in range(0,nnodes_ie):
        grad1[inode,iterm] = metrics[0,0,inode] * ddxi_i[inode,iterm] + metrics[1,0,inode] * ddeta_i[inode,iterm] + metrics[2,0,inode] * ddzeta_i[inode,iterm] 
        grad2[inode,iterm] = metrics[0,1,inode] * ddxi_i[inode,iterm] + metrics[1,1,inode] * ddeta_i[inode,iterm] + metrics[2,1,inode] * ddzeta_i[inode,iterm] 
        grad3[inode,iterm] = metrics[0,2,inode] * ddxi_i[inode,iterm] + metrics[1,2,inode] * ddeta_i[inode,iterm] + metrics[2,2,inode] * ddzeta_i[inode,iterm] 
        update_progress("Computing grad1, grad2, grad3      ", i/(nnodes_ie*nterms_s))
        i += 1







#WRITE_____________________

#
# Metrics
#
f = open("metrics.txt","w")
i = 1
for inode in range (0,nnodes_ie):
    f.write("Metric interpolation node %d \n" % (inode+1))
    array = np.zeros([3, 3])
    for irow in range(0,3):
        for icol in range(0,3):
            array[irow,icol] = metrics[irow,icol,inode].item() 
            update_progress("Writing metrics to file            ", i/(nnodes_ie*9))
            i += 1
    np.savetxt(f,array)
f.close()

#
# jinv
#
f = open("jinv.txt","w")
array = np.zeros([1])
i = 1
for inode in range (0,nnodes_ie):
    f.write("Jinv interpolation node %d \n" % (inode+1))
    array[0] = jinv[inode].item()
    np.savetxt(f,array)
    update_progress("Writing jinv to file               ", i/(nnodes_ie))
    i += 1
f.close()

#
# Grad1
#
f = open("grad1.txt","w")
f.write("Grad1 \n")
array = np.zeros([nnodes_ie,nterms_s])
i = 1
for inode in range (0,nnodes_ie):
    for iterm in range(0,nterms_s):
        array[inode,iterm] = grad1[inode,iterm].item()
        update_progress("Writing grad1 to file              ", i/(nnodes_ie*nterms_s))
        i += 1
np.savetxt(f,array)
f.close()

#
# Grad2
#
f = open("grad2.txt","w")
f.write("Grad2 \n")
array = np.zeros([nnodes_ie,nterms_s])
i = 1
for inode in range (0,nnodes_ie):
    for iterm in range(0,nterms_s):
        array[inode,iterm] = grad2[inode,iterm].item()
        update_progress("Writing grad2 to file              ", i/(nnodes_ie*nterms_s))
        i += 1
np.savetxt(f,array)
f.close()

#
# Grad3
#
f = open("grad3.txt","w")
f.write("Grad3 \n")
array = np.zeros([nnodes_ie,nterms_s])
i = 1
for inode in range (0,nnodes_ie):
    for iterm in range(0,nterms_s):
        array[inode,iterm] = grad3[inode,iterm].item()
        update_progress("Writing grad3 to file              ", i/(nnodes_ie*nterms_s))
        i += 1
np.savetxt(f,array)
f.close()

#
# dmetric_dx
#
f = open("dmetric_dx.txt","w")
i = 1
for inode in range (0,nnodes_ie):
    for inode_diff in range(0,nnodes_r):
        for idir in range(0,ndirs):
            array = np.zeros([3,3])
            f.write("dmetric_dx interpolation node %s, diff_node %s, diff_dir %s \n" % (inode+1,inode_diff+1,idir+1))
            for irow in range(0,3):
                for icol in range(0,3):
                    data = metrics[irow,icol,inode]
                    data.backward(retain_graph=True)
                    ddata = coords.grad
                    ddata_np = ddata.numpy()
                    array[irow,icol] = ddata_np[inode_diff,idir]
                    update_progress("Writing dmetric_dx to file         ", i/(nnodes_ie*nnodes_r*ndirs*3*3))
                    # This avoid to accumulate derivatives
                    dummy = coords.grad.data.zero_()
                    i += 1
            np.savetxt(f,array)
f.close()

#
# interp_coords_dx
#
f = open("dinterp_xcoords_dx.txt","w")
i = 1
f.write("xcoord interpolation, coord 1,  row=node, col=nnodes_r*dir \n")
array = np.zeros([nnodes_ie,nnodes_r*ndirs])
for inode in range (0,nnodes_ie):
    data = interp_coords[inode,0]
    data.backward(retain_graph=True)
    ddata = coords.grad
    ddata_np = ddata.numpy()
    for inode_diff in range(0,nnodes_r):
        for idir in range(0,ndirs):
            if idir == 0:
                index = inode_diff
            elif idir == 1:
                index = nnodes_r + inode_diff
            elif idir == 2:
                index = 2*nnodes_r + inode_diff
            array[inode,index] = ddata_np[inode_diff,idir]
            update_progress("Writing interp_xcoords_dx to file  ", i/(nnodes_ie*nnodes_r*3))
            i += 1
    # This avoid to accumulate derivatives
    dummy = coords.grad.data.zero_()
np.savetxt(f,array)
f.close()
f = open("dinterp_ycoords_dx.txt","w")
i = 1
f.write("ycoord interpolation, coord 2,  row=node, col=nnodes_r*dir \n")
array = np.zeros([nnodes_ie,nnodes_r*ndirs])
for inode in range (0,nnodes_ie):
    data = interp_coords[inode,1]
    data.backward(retain_graph=True)
    ddata = coords.grad
    ddata_np = ddata.numpy()
    for inode_diff in range(0,nnodes_r):
        for idir in range(0,ndirs):
            if idir == 0:
                index = inode_diff
            elif idir == 1:
                index = nnodes_r + inode_diff
            elif idir == 2:
                index = 2*nnodes_r + inode_diff
            array[inode,index] = ddata_np[inode_diff,idir]
            update_progress("Writing interp_ycoords_dx to file  ", i/(nnodes_ie*nnodes_r*3))
            i += 1
    # This avoid to accumulate derivatives
    dummy = coords.grad.data.zero_()
np.savetxt(f,array)
f.close()
f = open("dinterp_zcoords_dx.txt","w")
i = 1
f.write("zcoord interpolation, coord 3,  row=node, col=nnodes_r*dir \n")
array = np.zeros([nnodes_ie,nnodes_r*ndirs])
for inode in range (0,nnodes_ie):
    data = interp_coords[inode,2]
    data.backward(retain_graph=True)
    ddata = coords.grad
    ddata_np = ddata.numpy()
    for inode_diff in range(0,nnodes_r):
        for idir in range(0,ndirs):
            if idir == 0:
                index = inode_diff
            elif idir == 1:
                index = nnodes_r + inode_diff
            elif idir == 2:
                index = 2*nnodes_r + inode_diff
            array[inode,index] = ddata_np[inode_diff,idir]
            update_progress("Writing interp_zcoords_dx to file  ", i/(nnodes_ie*nnodes_r*3))
            i += 1
    # This avoid to accumulate derivatives
    dummy = coords.grad.data.zero_()
np.savetxt(f,array)
f.close()

#
# djinv_dx
#
f = open("djinv_dx.txt","w")
i = 1
for inode in range (0,nnodes_ie):
    array = np.zeros([nnodes_r,ndirs])
    f.write("djinv_dx interpolation node %s, row=inode_diff, col=dir \n" % (inode+1))
    for inode_diff in range(0,nnodes_r):
        for idir in range(0,ndirs):
                data = jinv[inode]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[inode_diff,idir] = ddata_np[inode_diff,idir]
                update_progress("Writing djinv_dx to file           ", i/(nnodes_ie*nnodes_r*ndirs))
                dummy = coords.grad.data.zero_()
                i += 1
    np.savetxt(f,array)
f.close()

#
# dmass_dx
# 
f = open("dmass_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dmass_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nterms_s,nterms_s])
        for irow in range(0,nterms_s):
            for icol in range(0,nterms_s):
                data = mass[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dmass_dx to file           ", i/(nterms_s*nnodes_r*ndirs*nterms_s))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()

#
# dinvmass_dx
# 
f = open("dinvmass_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dinvmass_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nterms_s,nterms_s])
        for irow in range(0,nterms_s):
            for icol in range(0,nterms_s):
                data = invmass[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dinvmass_dx to file        ", i/(nterms_s*nnodes_r*ndirs*nterms_s))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()

#
# dbr2_vol_dx
#
# 
f = open("dbr2_vol_face1_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_vol_face1_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_ie,nnodes_if])
        for irow in range(0,nnodes_ie):
            for icol in range(0,nnodes_if):
                data = br2_vol_face1[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_vol_face1_dx to file  ", i/(nnodes_ie*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()
f = open("dbr2_vol_face2_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_vol_face2_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_ie,nnodes_if])
        for irow in range(0,nnodes_ie):
            for icol in range(0,nnodes_if):
                data = br2_vol_face2[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_vol_face2_dx to file  ", i/(nnodes_ie*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()
f = open("dbr2_vol_face3_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_vol_face3_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_ie,nnodes_if])
        for irow in range(0,nnodes_ie):
            for icol in range(0,nnodes_if):
                data = br2_vol_face3[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_vol_face3_dx to file  ", i/(nnodes_ie*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()
f = open("dbr2_vol_face4_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_vol_face4_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_ie,nnodes_if])
        for irow in range(0,nnodes_ie):
            for icol in range(0,nnodes_if):
                data = br2_vol_face4[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_vol_face4_dx to file  ", i/(nnodes_ie*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()
f = open("dbr2_vol_face5_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_vol_face5_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_ie,nnodes_if])
        for irow in range(0,nnodes_ie):
            for icol in range(0,nnodes_if):
                data = br2_vol_face5[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_vol_face5_dx to file  ", i/(nnodes_ie*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()
f = open("dbr2_vol_face6_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_vol_face6_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_ie,nnodes_if])
        for irow in range(0,nnodes_ie):
            for icol in range(0,nnodes_if):
                data = br2_vol_face6[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_vol_face6_dx to file  ", i/(nnodes_ie*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()

#
# dbr2_face_dx
#
# 
f = open("dbr2_face_face1_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_face_face1_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_if,nnodes_if])
        for irow in range(0,nnodes_if):
            for icol in range(0,nnodes_if):
                data = br2_face_face1[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_face_face1_dx to file ", i/(nnodes_if*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()
f = open("dbr2_face_face2_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_face_face2_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_if,nnodes_if])
        for irow in range(0,nnodes_if):
            for icol in range(0,nnodes_if):
                data = br2_face_face2[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_face_face2_dx to file ", i/(nnodes_if*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()
f = open("dbr2_face_face3_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_face_face3_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_if,nnodes_if])
        for irow in range(0,nnodes_if):
            for icol in range(0,nnodes_if):
                data = br2_face_face3[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_face_face3_dx to file ", i/(nnodes_if*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()
f = open("dbr2_face_face4_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_face_face4_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_if,nnodes_if])
        for irow in range(0,nnodes_if):
            for icol in range(0,nnodes_if):
                data = br2_face_face4[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_face_face4_dx to file ", i/(nnodes_if*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()
f = open("dbr2_face_face5_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_face_face5_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_if,nnodes_if])
        for irow in range(0,nnodes_if):
            for icol in range(0,nnodes_if):
                data = br2_face_face5[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_face_face5_dx to file ", i/(nnodes_if*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()
f = open("dbr2_face_face6_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dbr2_face_face6_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_if,nnodes_if])
        for irow in range(0,nnodes_if):
            for icol in range(0,nnodes_if):
                data = br2_face_face6[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dbr2_face_face6_dx to file ", i/(nnodes_if*nnodes_r*ndirs*nnodes_if))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()

#
# dgrad1_dx
#
f = open("dgrad1_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dgrad1_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_ie,nterms_s])
        for irow in range(0,nnodes_ie):
            for icol in range(0,nterms_s):
                data = grad1[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dgrad1_dx to file          ", i/(nnodes_ie*nnodes_r*ndirs*nterms_s))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()

#
# dgrad2_dx
#
f = open("dgrad2_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dgrad2_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_ie,nterms_s])
        for irow in range(0,nnodes_ie):
            for icol in range(0,nterms_s):
                data = grad2[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dgrad2_dx to file          ", i/(nnodes_ie*nnodes_r*ndirs*nterms_s))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()

#
# dgrad3_dx
#
f = open("dgrad3_dx.txt","w")
i = 1
for inode_diff in range(0,nnodes_r):
    for idir in range(0,ndirs):
        f.write("dgrad3_dx => diff_node %s, diff_dir %s \n" % (inode_diff+1,idir+1))
        array = np.zeros([nnodes_ie,nterms_s])
        for irow in range(0,nnodes_ie):
            for icol in range(0,nterms_s):
                data = grad3[irow,icol]
                data.backward(retain_graph=True)
                ddata = coords.grad
                ddata_np = ddata.numpy()
                array[irow,icol] = ddata_np[inode_diff,idir]
                update_progress("Writing dgrad3_dx to file          ", i/(nnodes_ie*nnodes_r*ndirs*nterms_s))
                dummy = coords.grad.data.zero_()
                i += 1
        np.savetxt(f,array)
f.close()









[(47, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (69, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (82, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (94, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (105, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (116, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (120, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (130, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (138, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (146, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (154, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (162, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (170, 'torch.tensor', 'torch.tensor', False, 'import torch\n'), (179, 'torch.inverse', 'torch.inverse', False, 'import torch\n'), (183, 'torch.mm', 'torch.mm', False, 'import torch\n'), (187, 'torch.mm', 'torch.mm', False, 'import torch\n'), (191, 'torch.empty', 'torch.empty', False, 'import torch\n'), (213, 'torch.empty', 'torch.empty', False, 'import torch\n'), (214, 'torch.empty', 'torch.empty', False, 'import torch\n'), (231, 'torch.empty', 'torch.empty', False, 'import torch\n'), (232, 'torch.empty', 'torch.empty', False, 'import torch\n'), (233, 'torch.empty', 'torch.empty', False, 'import torch\n'), (241, 'torch.inverse', 'torch.inverse', False, 'import torch\n'), (265, 'torch.empty', 'torch.empty', False, 'import torch\n'), (266, 'torch.empty', 'torch.empty', False, 'import torch\n'), (267, 'torch.empty', 'torch.empty', False, 'import torch\n'), (305, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (320, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (327, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (335, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (342, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (350, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (357, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (390, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (409, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (414, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (433, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (438, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (457, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (25, 'sys.stdout.write', 'sys.stdout.write', False, 'import sys\n'), (26, 'sys.stdout.flush', 'sys.stdout.flush', False, 'import sys\n'), (29, 'os.system', 'os.system', False, 'import os\n'), (193, 'torch.dot', 'torch.dot', False, 'import torch\n'), (194, 'torch.dot', 'torch.dot', False, 'import torch\n'), (195, 'torch.dot', 'torch.dot', False, 'import torch\n'), (196, 'torch.dot', 'torch.dot', False, 'import torch\n'), (197, 'torch.dot', 'torch.dot', False, 'import torch\n'), (198, 'torch.dot', 'torch.dot', False, 'import torch\n'), (199, 'torch.dot', 'torch.dot', False, 'import torch\n'), (200, 'torch.dot', 'torch.dot', False, 'import torch\n'), (201, 'torch.dot', 'torch.dot', False, 'import torch\n'), (204, 'torch.mm', 'torch.mm', False, 'import torch\n'), (216, 'torch.empty', 'torch.empty', False, 'import torch\n'), (217, 'torch.empty', 'torch.empty', False, 'import torch\n'), (223, 'torch.det', 'torch.det', False, 'import torch\n'), (224, 'torch.inverse', 'torch.inverse', False, 'import torch\n'), (240, 'torch.t', 'torch.t', False, 'import torch\n'), (292, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (298, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (310, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (466, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (478, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (74, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (75, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (76, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (76, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (77, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (78, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (78, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (79, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (79, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (80, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (80, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (80, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (87, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (88, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (89, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (90, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (91, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (91, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (92, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (92, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (97, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (99, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (100, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (101, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (101, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (102, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (103, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (103, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (108, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (109, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (110, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (110, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (112, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (113, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (114, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (114, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (125, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (125, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (126, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (126, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (127, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (127, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (128, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (128, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (134, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (134, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (135, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (135, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (136, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (136, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (136, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (136, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (141, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (141, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (142, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (142, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (143, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (143, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (144, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (144, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (150, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (150, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (151, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (151, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (152, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (152, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (152, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (152, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (157, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (157, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (158, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (158, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (159, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (159, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (160, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (160, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (166, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (166, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (167, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (167, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (168, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (168, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (168, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (168, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (245, 'torch.t', 'torch.t', False, 'import torch\n'), (246, 'torch.t', 'torch.t', False, 'import torch\n'), (247, 'torch.t', 'torch.t', False, 'import torch\n'), (248, 'torch.t', 'torch.t', False, 'import torch\n'), (249, 'torch.t', 'torch.t', False, 'import torch\n'), (250, 'torch.t', 'torch.t', False, 'import torch\n'), (255, 'torch.t', 'torch.t', False, 'import torch\n'), (256, 'torch.t', 'torch.t', False, 'import torch\n'), (257, 'torch.t', 'torch.t', False, 'import torch\n'), (258, 'torch.t', 'torch.t', False, 'import torch\n'), (259, 'torch.t', 'torch.t', False, 'import torch\n'), (260, 'torch.t', 'torch.t', False, 'import torch\n'), (489, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (500, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (511, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (522, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (534, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (545, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (552, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (563, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (570, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (581, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (588, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (599, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (606, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (617, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (624, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (635, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (647, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (658, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (665, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (676, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (683, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (694, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (701, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (712, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (719, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (730, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (737, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (748, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (759, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (770, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (781, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (792, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (803, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (814, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n'), (73, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (73, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (73, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (73, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (74, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (74, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (74, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (75, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (75, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (75, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (76, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (76, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (77, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (77, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (77, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (78, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (78, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (79, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (79, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (80, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (85, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (85, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (86, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (86, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (87, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (88, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (89, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (90, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (96, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (96, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (97, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (98, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (98, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (99, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (100, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (102, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (107, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (107, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (108, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (109, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (111, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (111, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (112, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (113, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (125, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (125, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (126, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (126, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (127, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (127, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (128, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (128, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (133, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (133, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (133, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (133, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (134, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (134, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (135, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (135, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (141, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (141, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (142, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (142, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (143, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (143, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (144, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (144, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (149, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (149, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (149, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (149, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (150, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (150, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (151, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (151, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (157, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (157, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (158, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (158, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (159, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (159, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (160, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (160, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (165, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (165, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (165, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (165, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (166, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (166, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (167, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (167, 'numpy.sqrt', 'np.sqrt', True, 'import numpy as np\n'), (368, 'numpy.zeros', 'np.zeros', True, 'import numpy as np\n'), (381, 'numpy.savetxt', 'np.savetxt', True, 'import numpy as np\n')]