#!/usr/local/bin/python ## import sys ## import string ## #import FemLib ## #import DMatrix ## from Vec3D import Vec3D ## from Numeric import * ## from LinearAlgebra import * ## from pprint import pprint ## from Utilities import * from SimpleFemModel import * import os if os.name == 'posix': sys.path.append('/afs/.msc.cornell.edu/i386_linux22/usr/local/pub/dm/lib/python2.1/site-packages') import Sybase if os.name == 'nt': import dbi import odbc class DBFemModel(SimpleFemModel): """The DBFemModel class acts as a container to hold a description of a mesh and associated elements and boundary conditions.""" # constructor that reads a model description from database def __init__(self,server,database,lengthScale,randomNumberSeed): """Reads the entire mesh from the database """ #CONVERTED FROM PyFemModel TO READ DIRECTLY FROM DATABASE #connect to database username = "cmi" password = "cmi4now" if os.name == 'posix': self.PosixDB = Sybase.connect(server,username,password,'['+database+']') if os.name == 'nt': odbcString=database + "/" + username + "/" + password self.NTODBC = odbc.odbc(odbcString) self.NTDB = self.NTODBC.cursor() # read the node coordinates self.nodes = {} nodeData = self.ExecuteQuery("SELECT VertexID,x,y,z FROM Vertices") for i in xrange(len(nodeData)): #rows in table self.nodes[nodeData[i][0]] = (lengthScale*nodeData[i][1],lengthScale*nodeData[i][2],lengthScale*nodeData[i][3]) # the element data self.elem = {} elementData = self.ExecuteQuery("SELECT ElemID, v0, v1, v2, v3 FROM Tetrahedra") self.edgeNodeMap = {} for i in xrange(len(elementData)): id = elementData[i][0] type = "Tet2I" #XXX FOR NOW matData = self.ExecuteQuery("SELECT AttribID FROM ElementAttributes WHERE ElemID = " + str(id)) mat = matData[0][0] conn = [] for node in elementData[i][1:]: conn.append(int(node)) self.elem[id] = (type,mat,conn) ## cornerNodes = conn[:] ## # for some reason these need to be in a very specific order ## for i in xrange(1,len(cornerNodes)): ## for j in xrange(1,i+1): ## newEdgeNodeID = self.GetEdgeNode((cornerNodes[i-j],cornerNodes[i])) ## self.elem[id][2].append(newEdgeNodeID) # get a list of material numbers matData = self.ExecuteQuery("SELECT DISTINCT AttribID FROM ElementAttributes WHERE ElemID IN (SELECT ElemID FROM Tetrahedra)") self.materials = {} orientFile = open("orientations.dat","w") for i in xrange(len(matData)): id = matData[i][0] # for now, the materials only consist of different grains # and we make up random orientations here orientation = GetRandomRotationMatrix(randomNumberSeed+id) orientFile.write(str(orientation)+"\n") self.materials[id] = orientation # now read the boundary conditions # bc will be stored as a dictionary of faces # and their displacements # we will also need a list of faces and triangles # find attribute bindings # key is faceID queryString = """ SELECT AttribID, CAST(Attribute as varchar(5000)) FROM Attributes WHERE Attribute LIKE '