In [1]:
from __future__ import print_function
In [2]:
from salib import extend, import_notebooks
from Tables import Table
In [3]:
from Frame2D_Base import Frame2D
import Frame2D_Input
In [4]:
#test:
f = Frame2D('frame-1')
f.input_all()
Define a general method to write all tables. By default, a table of a given name
will be used from the 'self.rawdata
' object. If table 'xxx
' does not exist
there, it will be created by calling method '.list_xxx()
' to generate the data,
and formed by using the list of columns in class attribute '.COLUMNS_xxx
'.
.list_xxx()
must return a list of tuples or dictionaries, each of these being one
row of the table. If a tuple, that data is obviously given in the same order as the columns.
If a dictionary, the keys are the column names (see 'Member Loads', below).
In [5]:
@extend
class Frame2D:
def write_table(self,table_name,ds_name=None,prefix=None,record=True,precision=None,args=(),makedir=False):
t = getattr(self.rawdata,table_name,None)
if t is None:
methodname = 'list_'+table_name
method = getattr(self,methodname,None)
if method and callable(method):
data = method(*args)
t = Table(table_name,data=data,columns=getattr(self,'COLUMNS_'+table_name))
if t is None:
raise ValueError("Unable to find table '{}'".format(table_name))
t.write(ds_name=ds_name,prefix=prefix,precision=precision,makedir=makedir)
if record:
setattr(self.rawdata,table_name,t)
return t
In [6]:
##test:
try:
f.write_table('foobarzx3')
except Exception, e:
print('**** Error:',e)
In [7]:
@extend
class Frame2D:
def list_nodes(self):
return [(n.id,n.x,n.y) for n in self.nodes.values()]
In [8]:
##test:
t = f.write_table('nodes','test-1')
t.file_name
Out[8]:
In [9]:
##test:
%cat test-1.d/nodes.csv
Delete the nodes
table from .rawdata
so that we can test that .list_nodes()
is properly called
to regenerated the table.
In [10]:
##test:
if hasattr(f.rawdata,'nodes'):
delattr(f.rawdata,'nodes')
%rm test-1.d/nodes.csv
t = f.write_table('nodes','test-1')
t.file_name
Out[10]:
In [11]:
##test:
%cat test-1.d/nodes.csv
In [12]:
@extend
class Frame2D:
def list_supports(self):
ans = []
for node in self.nodes.values():
if node.constraints:
cl = tuple(node.constraints)
if len(cl) < 3:
cl = cl + ('',)*(3-len(cl))
ans.append((node.id,)+cl)
return ans
In [13]:
##test:
f.list_supports()
Out[13]:
In [14]:
##test:
t = f.write_table('supports','test-1')
t.file_name
Out[14]:
In [15]:
##test:
%cat test-1.d/supports.csv
In [16]:
##test:
x = 'supports'
if hasattr(f.rawdata,x):
delattr(f.rawdata,x)
%rm test-1.d/supports.csv
t = f.write_table(x,'test-1')
t.file_name
Out[16]:
In [17]:
##test:
%cat test-1.d/supports.csv
In [18]:
@extend
class Frame2D:
def list_members(self):
return [(m.id,m.nodej.id,m.nodek.id) for m in self.members.values()]
In [19]:
##test:
f.list_members()
Out[19]:
In [20]:
##test:
f.write_table('members','test-1')
%cat test-1.d/members.csv
In [21]:
@extend
class Frame2D:
def list_releases(self):
return [(m.id,)+tuple(m.releases) for m in self.members.values() if m.releases]
In [22]:
##test:
f.list_releases()
Out[22]:
In [23]:
##test:
f.write_table('releases','test-1')
%cat test-1.d/releases.csv
In [24]:
@extend
class Frame2D:
def list_properties(self):
return [(m.id,m.size,m.Ix,m.A) for m in self.members.values()]
In [25]:
##test:
f.list_properties()
Out[25]:
In [26]:
##test:
f.write_table('properties','test-1')
%cat test-1.d/properties.csv
In [27]:
@extend
class Frame2D:
def list_node_loads(self):
ans = []
dirns = ['FX','FY','FZ']
for loadid,node,nload in self.nodeloads:
for i in [0,1,2]:
if nload[i]:
ans.append((loadid,node.id,dirns[i],nload[i]))
return ans
In [28]:
##test:
f.list_node_loads()
Out[28]:
In [29]:
##test:
f.write_table('node_loads','test-1')
%cat test-1.d/node_loads.csv
In [30]:
@extend
class Frame2D:
def list_support_displacements(self):
ans = []
dirns = ['DX','DY','RZ']
for loadid,node,nload in self.nodedeltas:
for i in [0,1,2]:
if nload[i]:
ans.append((loadid,node.id,dirns[i],nload[i]))
return ans
In [31]:
##test:
f.list_support_displacements()
Out[31]:
In [32]:
##test:
f.write_table('support_displacements','test-1')
%cat test-1.d/support_displacements.csv
In [33]:
from MemberLoads import unmakeMemberLoad
@extend
class Frame2D:
def list_member_loads(self):
ans = []
for loadid,memb,mload in self.memberloads:
ml = unmakeMemberLoad(mload)
ml['MEMBERID'] = memb.id
ml['LOAD'] = loadid
ans.append(ml)
return ans
In [34]:
##test:
f.list_member_loads()
Out[34]:
In [35]:
##test:
f.write_table('member_loads','test-1')
%cat test-1.d/member_loads.csv
In [36]:
##test:
if hasattr(f.rawdata,'member_loads'):
delattr(f.rawdata,'member_loads')
%rm test-1.d/member_loads.csv
f.write_table('member_loads','test-1')
%cat test-1.d/member_loads.csv
In [37]:
@extend
class Frame2D:
def list_load_combinations(self):
return [(case,load,factor) for case,load,factor in self.loadcombinations]
In [38]:
##test:
f.list_load_combinations()
Out[38]:
In [39]:
##test:
f.write_table('load_combinations','test-1')
%cat test-1.d/load_combinations.csv
In [40]:
##test:
vars(f.rawdata).keys()
Out[40]:
In [41]:
@extend
class Frame2D:
COLUMNS_signatures = ['NAME','PATH','SIGNATURE']
def list_signatures(self):
return [t.signature() for tn,t in vars(self.rawdata).items() if type(t) is Table]
In [42]:
##test:
f.list_signatures()
Out[42]:
In [43]:
##test:
f.write_table('signatures','test-1',record=False)
%cat test-1.d/signatures.csv
In [44]:
import os, os.path
@extend
class Frame2D:
def write_all(self,ds_name,mkdir=False):
if mkdir:
dname = ds_name + '.d'
if not os.path.exists(dname):
os.mkdir(dname)
self.write_table('nodes',ds_name)
self.write_table('supports',ds_name)
self.write_table('members',ds_name)
self.write_table('releases',ds_name)
self.write_table('properties',ds_name)
self.write_table('node_loads',ds_name)
self.write_table('support_displacements',ds_name)
self.write_table('member_loads',ds_name)
self.write_table('load_combinations',ds_name)
self.write_table('signatures',ds_name,record=False)
In [45]:
##test:
%rm test-1.d/*
%ls -l test-1.d
f.reset()
f.input_all()
f.write_all('test-1')
%ls -l test-1.d
In [46]:
##test:
%cat test-1.d/signatures.csv
In [47]:
##test:
import Frame2D_SolveFirstOrder
f.reset()
f.input_all()
rs = f.solve('all')
In [48]:
@extend
class Frame2D:
COLUMNS_node_displacements = ['NODEID','DX','DY','RZ']
def list_node_displacements(self,rs):
if not hasattr(rs,'node_displacements'):
return []
ans = []
D = rs.node_displacements
for node in self.nodes.values():
d = D[node.dofnums]
ans.append((node.id,d[0,0],d[1,0],d[2,0]))
return ans
In [49]:
##test:
f.list_node_displacements(rs)
Out[49]:
In [50]:
##test:
f.write_table('node_displacements',ds_name='test-1',prefix=rs.loadcase,record=False,precision=15,args=(rs,))
%cat test-1.d/all/node_displacements.csv
In [51]:
@extend
class Frame2D:
COLUMNS_reaction_forces = ['NODEID','FX','FY','MZ']
def list_reaction_forces(self,rs):
if not hasattr(rs,'reaction_forces'):
return []
R = rs.reaction_forces
ans = []
for node in self.nodes.values():
if node.constraints:
l = [node.id,None,None,None]
for dirn in node.constraints:
i = node.DIRECTIONS[dirn]
j = node.dofnums[i]
val = R[j-self.nfree,0]
l[i+1] = val
ans.append(l)
return ans
In [52]:
##test:
f.list_reaction_forces(rs)
Out[52]:
In [53]:
##test:
f.write_table('reaction_forces',ds_name='test-1',prefix=rs.loadcase,record=False,precision=15,args=(rs,))
%cat test-1.d/all/reaction_forces.csv
In [54]:
@extend
class Frame2D:
COLUMNS_member_end_forces = 'MEMBERID,FXJ,FYJ,MZJ,FXK,FYK,MZK'.split(',')
def list_member_end_forces(self,rs):
if not hasattr(rs,'member_efs'):
return []
mefs = rs.member_efs
ans = []
for memb in self.members.values():
efs = mefs[memb].fefs
ans.append((memb.id,efs[0,0],efs[1,0],efs[2,0],efs[3,0],efs[4,0],efs[5,0]))
return ans
In [55]:
##test:
f.list_member_end_forces(rs)
Out[55]:
In [56]:
##test:
f.write_table('member_end_forces',ds_name='test-1',prefix=rs.loadcase,record=False,precision=15,args=(rs,))
%cat test-1.d/all/member_end_forces.csv
In [57]:
@extend
class Frame2D:
def write_results(self,ds_name,rs):
self.write_table('node_displacements',ds_name=ds_name,prefix=rs.loadcase,record=False,
precision=15,args=(rs,),makedir=True)
self.write_table('reaction_forces',ds_name=ds_name,prefix=rs.loadcase,record=False,
precision=15,args=(rs,))
self.write_table('member_end_forces',ds_name=ds_name,prefix=rs.loadcase,record=False,
precision=15,args=(rs,))
if rs.pdelta:
self.write_table('pdelta_forces',ds_name=ds_name,prefix=rs.loadcase,record=False,
precision=15,args=(rs,))
In [58]:
##test:
f.reset()
f.input_all()
rs = f.solve('One')
f.write_results('test-1',rs)
%ls -l test-1.d/One
%cat test-1.d/One/node_displacements.csv
%cat test-1.d/One/reaction_forces.csv
%cat test-1.d/One/member_end_forces.csv
In [ ]: