예제 #1
0
def printFormMatrix(cell):
    faces = qd.CellFaceIterator(cell)
    face = faces.next()
    while face != None:
        faceid = face.getID()
        print " ========================================================================================"
        print faceid
        print "MU  ", [
            face.getMu1(),
            face.getMu2(),
            face.getMu3(),
            face.getMu4()
        ]
        print "CF  ", [
            qd.getCurrentFormMatrix(face, 0, 0),
            (qd.getCurrentFormMatrix(face, 0, 1)),
            qd.getCurrentFormMatrix(face, 1, 0),
            (qd.getCurrentFormMatrix(face, 1, 1))
        ]
        print "TF  ", [
            qd.getTargetFormMatrix(face, 0, 0),
            (qd.getTargetFormMatrix(face, 0, 1)),
            qd.getTargetFormMatrix(face, 1, 0),
            (qd.getTargetFormMatrix(face, 1, 1))
        ]
        face = faces.next()
    return
def plotMatrices(cell, targetfaceid,matrixarray,growthtimearray, stepgrowtharray):
    #getting the matrix array
    mudeterminant = matrixarray[0]
    currentFormdeterminant = matrixarray[1]
    targetFormdeterminant = matrixarray[2]
    #calculating the matrices
    faces = qd.CellFaceIterator(cell)
    face = faces.next()
    while face!=None:
        faceid = face.getID()
        if faceid != targetfaceid:
            face= faces.next()
            continue
        mudeterminant.append((face.getMu1()*face.getMu4()-face.getMu2()*face.getMu3()))
        currentFormdeterminant.append((qd.getCurrentFormMatrix(face,0,0)*(qd.getCurrentFormMatrix(face,1,1))-qd.getCurrentFormMatrix(face,1,0)*(qd.getCurrentFormMatrix(face,0,1))))
        targetFormdeterminant.append((qd.getTargetFormMatrix(face,0,0)*(qd.getTargetFormMatrix(face,1,1))-qd.getTargetFormMatrix(face,1,0)*(qd.getTargetFormMatrix(face,0,1))))
        break
        #face = faces.next()
    #starting the plot
    plt.figure(21)
    plt.title("Determinant of Matrices for Face : %d"%targetfaceid)
    plt.plot(growthtimearray, mudeterminant,'-s',color='k', label="Mu")
    plt.plot(growthtimearray, currentFormdeterminant,'-*',color='m', label="CF")
    plt.plot(growthtimearray, targetFormdeterminant,'-1', color='b',label="TF")
    #making verticle lines for growthsteps
    for vline in stepgrowtharray:
        plt.axvline(x=vline, c = 'r')
    plt.legend(loc='best')
    plt.savefig('matrix_plot_faceid_%d.png'%targetfaceid,transparent=True)
    plt.clf()
    plt.close('all')
    ######
    return [mudeterminant,currentFormdeterminant,targetFormdeterminant]
def getCurrentFormEllipsePoints(cell,targetface = 10):
    #getting the Target Form Matrix
    faces = qd.CellFaceIterator(cell)
    face = faces.next()
    while True:
        if face.getID() == targetface:
            break
        face = faces.next()
    #print "Face Id : ", face.getID()
    targetformmatrix = np.array([[qd.getCurrentFormMatrix(face, 0,0),qd.getCurrentFormMatrix(face, 0,1)],
                                 [qd.getCurrentFormMatrix(face, 1,0),qd.getCurrentFormMatrix(face, 1,1)]
                                 ])
    unitx = face.getUnitx()
    unity = face.getUnity()
    unitz = face.getUnitz()
    unit_mat = np.matrix([[qd.doublearray_getitem(unitx,0),qd.doublearray_getitem(unitx,1),qd.doublearray_getitem(unitx,2)],
                         [qd.doublearray_getitem(unity,0),qd.doublearray_getitem(unity,1),qd.doublearray_getitem(unity,2)],
                         [qd.doublearray_getitem(unitz,0),qd.doublearray_getitem(unitz,1),qd.doublearray_getitem(unitz,2)]])
    #transposing unitmatrix
    transpose_unitmat = np.matrix(np.transpose(unit_mat))
    #Getting Centroid of face
    xcent = face.getXCentralised()
    ycent = face.getYCentralised()
    zcent = face.getZCentralised()
    ##### getting data from ellipse & getting transformed coordinate to 3d Cartesian
    data = ep.plot_ellipse(cov=targetformmatrix, data_out=True)
    points = np.matrix(np.vstack((data,np.zeros(len(data[0])))))
    transformedpoints = transpose_unitmat*points
    transformedpoints[0]+= xcent
    transformedpoints[1]+= ycent
    transformedpoints[2]+= zcent
    ################################
    return transformedpoints
예제 #4
0
def getFormMatrix(cell, targetfaceid):
    faces = qd.CellFaceIterator(cell)
    face = faces.next()
    while face != None:
        faceid = face.getID()
        if faceid != targetfaceid:
            face = faces.next()
            continue
        targetForm = np.array([[
            qd.getTargetFormMatrix(face, 0, 0),
            qd.getTargetFormMatrix(face, 0, 1)
        ],
                               [
                                   qd.getTargetFormMatrix(face, 1, 0),
                                   qd.getTargetFormMatrix(face, 1, 1)
                               ]])
        currentForm = np.array([[
            qd.getCurrentFormMatrix(face, 0, 0),
            qd.getCurrentFormMatrix(face, 0, 1)
        ],
                                [
                                    qd.getCurrentFormMatrix(face, 1, 0),
                                    qd.getCurrentFormMatrix(face, 1, 1)
                                ]])
        break
    return targetForm, currentForm
def cartesianEnergyObjective(inputcoordinates, grad):
    global numOfLayer, alpha, beta, pressure, cell, functionCallCounter, bendingThreshold, meanFormMatrix
    #making of hexagonal lattic
    #Reshape the tempcoordinates, to x-y-z arrays
    ####iterating the vertices to feed the new coordinates in
    tempcoordinates = inputcoordinates.reshape((3, numberofvertices))
    ####iterating the vertices to feed the new coordinates in
    vertices = qd.CellVertexIterator(cell)
    vertex = vertices.next()
    counter = 0  #counter to change vertex positions
    while vertex != None:
        vertex.setXcoordinate(tempcoordinates[0,
                                              counter])  #setting x coordinate
        vertex.setYcoordinate(tempcoordinates[1,
                                              counter])  #setting y coordinate
        vertex.setZcoordinate(tempcoordinates[2,
                                              counter])  #setting z coordinate
        counter += 1
        vertex = vertices.next()
    ######################################################
    #cell = settingParameters(cell)
    cell.setParameters()
    ######################################################
    faces = qd.CellFaceIterator(cell)
    face = faces.next()
    faceFormMatrix = np.zeros((2, 2))
    energyvalue = 0.
    while face != None:
        faceFormMatrix[0, 0] = qd.getCurrentFormMatrix(face, 0, 0)
        faceFormMatrix[0, 1] = qd.getCurrentFormMatrix(face, 0, 1)
        faceFormMatrix[1, 0] = qd.getCurrentFormMatrix(face, 1, 0)
        faceFormMatrix[1, 1] = qd.getCurrentFormMatrix(face, 1, 1)
        #####################
        differenceMatrix = faceFormMatrix - meanFormMatrix
        #####################
        differenceMatrix = np.power(differenceMatrix, 2)
        energyvalue += np.sum(differenceMatrix)
        face = faces.next()
    ######################################################
    #returning the total energy
    return energyvalue
예제 #6
0
def getCurrentFormMatrix(cell):
	#getting all the target form matrix
	formmatrixDictionary = {}#dictionary to save all the targetformmatrix
	## Getting and saving matrix in array
	faces = qd.CellFaceIterator(cell)
	face = faces.next()
	matrixArray = np.zeros((2,2))
	#starting Iteration
	while face != None:
		faceid = face.getID()
		if faceid == 1:
			face = faces.next()
			continue
		matrixArray[0,0] = qd.getCurrentFormMatrix(face, 0,0)
		matrixArray[0,1] = qd.getCurrentFormMatrix(face, 0,1)
		matrixArray[1,0] = qd.getCurrentFormMatrix(face, 1,0)
		matrixArray[1,1] = qd.getCurrentFormMatrix(face, 1,1)
		#saving this in dictionary
		#print matrixArray
		formmatrixDictionary[faceid] = np.copy(matrixArray)
		face = faces.next()
	return formmatrixDictionary
                         for i in range(cell.countFaces() - 1)]  #target matrix
#faceid = []
plt.figure(21)
plt.title("Matrices")
faces = qd.CellFaceIterator(cell)
face = faces.next()
facecounter = 0
while face != None:
    faceid = face.getID()
    if faceid == 1:
        face = faces.next()
        continue
    (mudeterminant[facecounter]).append(
        (face.getMu1() * face.getMu4() - face.getMu2() * face.getMu3()))
    (currentFormdeterminant[facecounter]).append(
        (qd.getCurrentFormMatrix(face, 0, 0) *
         (qd.getCurrentFormMatrix(face, 1, 1)) -
         qd.getCurrentFormMatrix(face, 1, 0) *
         (qd.getCurrentFormMatrix(face, 0, 1))))
    (targetFormdeterminant[facecounter]).append(
        (qd.getTargetFormMatrix(face, 0, 0) *
         (qd.getTargetFormMatrix(face, 1, 1)) -
         qd.getTargetFormMatrix(face, 1, 0) *
         (qd.getTargetFormMatrix(face, 0, 1))))
    #now plotting
    if faceid % 4 == 0:
        plt.plot(growthtimearray,
                 mudeterminant[facecounter],
                 '-x',
                 label="Mu : %d" % faceid)
        plt.plot(growthtimearray,
mudeterminant = [[] for i in range(cell.countFaces()-1)]#Mu-matrix is the strain matrix
currentFormdeterminant = [[] for i in range(cell.countFaces()-1)]#current-form matrix
targetFormdeterminant = [[] for i in range(cell.countFaces()-1)]#target matrix
#faceid = []
plt.figure(21)
plt.title("Matrices")
faces = qd.CellFaceIterator(cell)
face = faces.next()
facecounter = 0
while face!=None:
    faceid = face.getID()
    if faceid == 1:
        face= faces.next()
        continue
    (mudeterminant[facecounter]).append((face.getMu1()*face.getMu4()-face.getMu2()*face.getMu3()))
    (currentFormdeterminant[facecounter]).append((qd.getCurrentFormMatrix(face,0,0)*(qd.getCurrentFormMatrix(face,1,1))-qd.getCurrentFormMatrix(face,1,0)*(qd.getCurrentFormMatrix(face,0,1))))
    (targetFormdeterminant[facecounter]).append((qd.getTargetFormMatrix(face,0,0)*(qd.getTargetFormMatrix(face,1,1))-qd.getTargetFormMatrix(face,1,0)*(qd.getTargetFormMatrix(face,0,1))))
    #now plotting
    if faceid%4 == 0:
        plt.plot(growthtimearray, mudeterminant[facecounter],'-x', label="Mu : %d"%faceid)
        plt.plot(growthtimearray, currentFormdeterminant[facecounter],'-*', label="CF : %d"%faceid)
        plt.plot(growthtimearray, targetFormdeterminant[facecounter],'-o', label="TF : %d"%faceid)
    facecounter+=1
    face = faces.next()
plt.legend(loc='upper left')
plt.savefig('matrix_plot.png',transparent=True)
plt.clf()
plt.close('all')

#plotting the determinant of Target Form Matrix
meandeterminantarray = plotMeanTargetArea(cell,meandeterminantarray,growthtimearray)