i] + 'on proc' + str(p)
            patchNodes = passiveList[pos:index[(p * len(patchNames)) +
                                               i], :, :] * scale
            #pos:index[(p*len(patchNames))+i]

            #So we will be making an a, b c and d vector files
            aCoefs = np.zeros((np.shape(patchNodes)[0], 3, cMshape[0] + 1))
            bCoefs = np.zeros((np.shape(patchNodes)[0], 3, cMshape[0] + 1))
            cCoefs = np.zeros((np.shape(patchNodes)[0], 3, cMshape[0] + 1))
            dCoefs = np.zeros((np.shape(patchNodes)[0], 3, cMshape[0] + 1))
            #Loop through the number of nodes, and calculate the spines for x, y and z
            print 'Splining patch:', patchNames[i]
            for j in range(np.shape(patchNodes)[0]):
                for k in range(3):  #number of dimensions
                    yn = patchNodes[j, k, :]
                    [a, b, c, d] = IT.basicCubicSpline(cMshape[0] + 1,
                                                       timeVector, yn)
                    [a, b, c, d
                     ] = IT.transformCubicCoeffiencets(a, b, c, d, timeVector)

                    aCoefs[j, k, :] = a
                    bCoefs[j, k, :] = b
                    cCoefs[j, k, :] = c
                    dCoefs[j, k, :] = d

            #once we have filled the vectors, we write them to the time files
            print 'saving time files...', patchNames[i]
            #for time 0, we need our OF vector files
            #np.savetxt(workingDirOF+'processor'+str(p)+'/constant/patchPositions/'+str(patchNames[i])+'/'+str(0)+'/patchDisplacements',patchNodes[:,:,0])
            FT.writeVectorField(
                workingDirOF + 'processor' + str(p) +
                '/constant/patchDisplacements/' + str(patchNames[i]) + '/' +
예제 #2
0
#Set working directory.
workingDir='/home/stephen/OpenFOAM/Simulations2/Rumens/RumenBMES/constant/patchDisplacements'
fileName='wall'
numDT=25
splineData=np.zeros((numDT))
xValue=2000



for i in range(numDT):
	nodes=np.loadtxt(workingDir+'Tests/'+fileName+str(i))
	splineData[i]=nodes[xValue,0]
	plt.plot(i,nodes[xValue,0],'or')
	
#Calculate spline values
[a,b,c,d]=IT.basicCubicSpline(numDT,range(numDT),splineData)
IT.basicCubicSplinePlot(a,b.tolist(),c.tolist(),d.tolist(),range(numDT))


#fig3=plt.figure(3)
#ax3D=fig3.add_subplot(111, projection='3d')
#ax3D.plot(nodes[:,0],nodes[:,1],nodes[:,2],'.b')
#ax3D.plot(nodes[xValue:xValue+1,0],nodes[xValue:xValue+1,1],nodes[xValue:xValue+1,2],'or')
test=np.zeros(4)
#Now we are going to check the outfiles from me thingy
for i in range(numDT):
	#read in a b c and d from a time file
	a=np.loadtxt(workingDir+'Coeffs/'+fileName+'/'+str(i)+'/a')
	b=np.loadtxt(workingDir+'Coeffs/'+fileName+'/'+str(i)+'/b')
	c=np.loadtxt(workingDir+'Coeffs/'+fileName+'/'+str(i)+'/c')
	d=np.loadtxt(workingDir+'Coeffs/'+fileName+'/'+str(i)+'/d')
dC=np.zeros((arraySize[0],arraySize[1],arraySize[2]))

#read in time 0
meshPos=FT.readPatchFile(meshDir,patchName+'PatchNodes') #hack line
Displacements=np.zeros((arraySize[0],arraySize[1],arraySize[2]))

Displacements[:,:,0]=meshPos
for i in range(start,stop):
	Displacements[:,:,i+1]=np.loadtxt(workingDir+patchName+'/'+str(i)+'/patchDisplacements')

#Now we each points, x y and z.
print 'Splinging, this will take a while'
timeVector=range(start,stop+1)
for i in range(Displacements.shape[0]):
	for j in range(Displacements.shape[1]):
		[a,b,c,d]=IT.basicCubicSpline((stop-start+1),timeVector,Displacements[i,j,:])
		[a,b,c,d]=IT.transformCubicCoeffiencets(a,b,c,d,timeVector)
		aC[i,j,:]=a
		bC[i,j,:]=b
		cC[i,j,:]=c
		dC[i,j,:]=d

print 'Writing out files'
os.mkdir(outDir+patchName)
for i in range(len(timeVector)-1):
	os.mkdir(outDir+patchName+'/'+str(timeVector[i]))
	np.savetxt(outDir+patchName+'/'+str(timeVector[i])+'/a',aC[:,:,i])
	np.savetxt(outDir+patchName+'/'+str(timeVector[i])+'/b',bC[:,:,i])
	np.savetxt(outDir+patchName+'/'+str(timeVector[i])+'/c',cC[:,:,i])
	np.savetxt(outDir+patchName+'/'+str(timeVector[i])+'/d',dC[:,:,i])
예제 #4
0
import numpy as np
import imageTools as IT
import matplotlib.pyplot as plt

import numpy as np
print 'running test script'
#xn = [0,1,2,3,4,5,6,7]
#yn = [0,0,0.1,1,2.5,3.2,1,0]
xn = [0, 1, 2, 3]
yn = [0, 1, 3, -1]
n = np.size(xn)
print 'Test paramaters:'
print '\t-n', n
print '\t-xn', xn
print '\t-yn', yn

[a, b, c, d] = IT.basicCubicSpline(n, xn, yn)

print 'a:', np.shape(a)
print 'b:', np.shape(b)
print 'c:', np.shape(c)
#print
print 'd:', np.shape(d)

check = IT.basicCubicSplinePlot(a, b.tolist(), c.tolist(), d.tolist(), xn)
if check:
    print 'Test Script Completed, no errors'

plt.plot(xn, yn, 'x')
plt.show()