<s> import alg3dpy <EOL> class Elements ( object ) : <EOL> __slots__ = [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self ) : <EOL> self . grids = [ ] <EOL> self . mask = False <EOL> self . panel = None <EOL> def rebuild ( self ) : <EOL> if getattr ( self , '<STR_LIT>' , False ) < > False : <EOL> prop = self . model . propdict [ int ( self . pid ) ] <EOL> self . pobj = prop <EOL> def calc_cg ( self ) : <EOL> self . cg = alg3dpy . Point ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> for grid in self . grids : <EOL> self . cg . x1 += grid . x1 <EOL> self . cg . x2 += grid . x2 <EOL> self . cg . x3 += grid . x3 <EOL> N = len ( self . grids ) <EOL> self . cg . x1 /= N <EOL> self . cg . x2 /= N <EOL> self . cg . x3 /= N <EOL> def add2model ( self , model ) : <EOL> self . model = model <EOL> model . elemdict [ self . id ] = self <EOL> def calc_Rmatrix ( self ) : <EOL> import scipy <EOL> import scipy . sparse as ss <EOL> cosb = alg3dpy . cosplanevec ( alg3dpy . XY , self . xvec ) <EOL> sinb = alg3dpy . sinplanevec ( alg3dpy . XY , self . xvec ) <EOL> cosg = alg3dpy . cosplanevec ( alg3dpy . XZ , self . xvec ) <EOL> sing = alg3dpy . sinplanevec ( alg3dpy . XZ , self . xvec ) <EOL> if self . __class__ . __name__ . find ( '<STR_LIT>' ) == - <NUM_LIT:1> : <EOL> Y2 = alg3dpy . Y * cosg - alg3dpy . X * sing <EOL> cosa = alg3dpy . cos2vecs ( Y2 , self . yvec ) <EOL> sina = alg3dpy . sin2vecs ( Y2 , self . yvec ) <EOL> else : <EOL> cosa = <NUM_LIT:1.> <EOL> sina = <NUM_LIT:0.> <EOL> gridnum = scipy . array ( len ( self . grids ) , dtype = '<STR_LIT>' ) <EOL> dim = gridnum * <NUM_LIT:6> <EOL> tmp = scipy . array ( [ cosb * cosg , cosb * sing , - sinb , <EOL> - cosa * sing + cosg * sina * sinb , cosa * cosg + sina * sinb * sing , cosb * sina , <EOL> sina * sing + cosa * cosg * sinb , - cosg * sina + cosa * sinb * sing , cosa * cosb ] , dtype = '<STR_LIT>' ) <EOL> row = scipy . array ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] , dtype = '<STR_LIT>' ) <EOL> col = scipy . array ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] , dtype = '<STR_LIT>' ) <EOL> self . Rcoord2el = ss . coo_matrix ( ( tmp , ( row , col ) ) , shape = ( <NUM_LIT:3> , <NUM_LIT:3> ) , dtype = '<STR_LIT>' ) <EOL> self . Rcoord2global = self . Rcoord2el . transpose ( ) <EOL> data = scipy . array ( scipy . zeros ( <NUM_LIT> * gridnum ) ) <EOL> for i in xrange ( gridnum ) : <EOL> for j in xrange ( <NUM_LIT:9> ) : <EOL> data [ <NUM_LIT> * i + j ] = tmp [ j ] <EOL> row = scipy . array ( [ i for i in xrange ( dim ) for j in xrange ( <NUM_LIT:3> ) ] , dtype = '<STR_LIT>' ) <EOL> col = scipy . array ( [ j + int ( i / <NUM_LIT:3> ) * <NUM_LIT:3> for i in xrange ( dim ) for j in xrange ( <NUM_LIT:3> ) ] , <EOL> dtype = '<STR_LIT>' ) <EOL> self . R2el = ss . coo_matrix ( ( data , ( row , col ) ) , shape = ( dim , dim ) , <EOL> dtype = '<STR_LIT>' ) <EOL> self . R2global = self . R2el . transpose ( ) <EOL> def build_k ( self ) : <EOL> import scipy <EOL> import scipy . sparse as ss <EOL> self . kelem = ss . coo_matrix ( self . kelem ) <EOL> R = self . R2el . tocsc ( ) <EOL> Rinv = self . R2global . tocsc ( ) <EOL> kelem = self . kelem . tocsc ( ) <EOL> k = np . dot ( Rinv , kelem ) <EOL> k = np . dot ( k , R ) <EOL> self . k = k . tocoo ( ) <EOL> def calc_displ ( self ) : <EOL> self . displ = { } <EOL> for sub in self . model . subcases . values ( ) : <EOL> displ = scipy . zeros ( <NUM_LIT:0> ) <EOL> for grid in self . grids : <EOL> count = <NUM_LIT:0> <EOL> lst = [ count * <NUM_LIT:6> for i in xrange ( <NUM_LIT:6> ) ] <EOL> scipy . insert ( displ , lst , grid . displ [ sub . id ] ) <EOL> count += <NUM_LIT:1> <EOL> self . displ [ sub . id ] = self . R2el * displ </s>
