def readItem(l1, db): if '.' in l1[0]: l2 = l1[0].split('.', 1) if l2[0] in db: if type(db[l2[0]]) == dict: child = db[l2[0]] else: child = Properties() else: child = Properties() l1[0] = l2[1] ln = readItem(l1, child) db[l2[0]] = child return ln else: l2 = l1[1].split(';', 1) if l2[0][0] == '[': l3 = l2[0][1:-1].split(',') storeValue(db, l1[0], l3) else: storeValue(db, l1[0], l2[0]) return l2[1]
def __init__(self, props, globdat): self.prefix = globdat.prefix self.extension = ".out" self.onScreen = False BaseModule.__init__(self, props) if not hasattr(self, "filename"): self.filename = self.prefix + self.extension self.columndata = [] for i, col in enumerate(self.columns): if hasattr(self, col): colProps = getattr(self, col) else: colProps = Properties() if not hasattr(colProps, "type"): colProps.type = col if not hasattr(colProps, "factor"): colProps.factor = 1.0 if hasattr(colProps, "node"): if type(colProps.node) == str: colProps.node = globdat.nodes.groups[colProps.node] self.columndata.append(colProps) if self.onScreen and hasattr(globdat, "onScreen"): self.onScreen = False else: globdat.onScreen = True self.fig = gcf() self.fig.show() self.fig.canvas.draw() self.outfile = open(self.filename, 'w') if self.onScreen: self.output = [] xlabel(self.columns[0]) ylabel(self.columns[1]) ion() self.run(props, globdat)
def fileParser( fileName ): db = Properties() f = open(fileName) f2 = '' for line in f: if not line.startswith('#'): f2 = f2+line ln = open(fileName).read().replace('\n','').replace('\t','').replace(' ','').replace('\r','') ln = f2.replace('\n','').replace('\t','').replace(' ','').replace('\r','') readBlock( ln , db ) return db
def readBlock(ln, db): while True: if ln[0:7] == 'include': l1 = ln.split(';', 1) deepFileParser(l1[0][8:-1], db) ln = l1[1] continue l1 = ln.split('=', 1) if len(l1) == 1: return ln if l1[0][0:2] == '};': return ln[2:] if l1[0][0:2] == '//': ln = l1[1].split(';', 1)[1] continue #if l1[0][0:1] == '#': # ln = l1[1].split(';',1)[1] # continue if l1[1][0] == '{': child = Properties() ln = l1[1][1:] ln = readBlock(ln, child) db.store(l1[0], child) else: ln = readItem(l1, db)
#External load increment DF = 50 #N #Solver parameters N = 30 tol = 1e-6 iterMax = 5 ############################## # Store data in properties # ############################## from pyfem.util.dataStructures import Properties props = Properties() props.TrussElem = Properties({'type': 'Truss', 'E': 5e6, 'Area': 1.0}) props.SpringElem = Properties({'type': 'Spring', 'k': 2000.}) ############################# # Defining finite element # # data structures # ############################# #NodeSet from pyfem.fem.NodeSet import NodeSet nodes = NodeSet() nodes.add(1, [ 0., 0.
#External load increment DF = 50 #N #Solver parameters N = 30 tol = 1e-6 iterMax = 5 ############################## # Store data in properties # ############################## from pyfem.util.dataStructures import Properties props = Properties() props.TrussElem = Properties( { 'type' : 'Truss' , 'E' : 5e6 , 'Area' : 1.0 } ) props.SpringElem = Properties( { 'type' : 'Spring' , 'k' : 2000. } ) ############################# # Defining finite element # # data structures # ############################# #NodeSet from pyfem.fem.NodeSet import NodeSet nodes = NodeSet() nodes.add( 1, [ 0.,0. ] ) #Attachement point of spring (can be positioned anywhere along the y-axis) nodes.add( 2, [-10.,0. ] ) #Left support