MCPcopy Create free account
hub / github.com/OpenSees/OpenSees / toOpenSeesPy

Function toOpenSeesPy

SCRIPTS/toOpenSeesPy.py:81–162  ·  view source on GitHub ↗
(infile, outfile, alias='')

Source from the content-addressed store, hash-verified

79# Function that does the conversion
80#
81def toOpenSeesPy(infile, outfile, alias=''):
82 # Add a dot if needed
83 if len(alias) > 0 and alias[-1] != '.':
84 alias = alias + '.'
85
86 infile = open(infile,'r')
87 for line in infile:
88 info = line.split()
89 N = len(info)
90
91 # Skip a blank line
92 if N < 1:
93 outfile.write('\n')
94 continue
95 # Ignore a close brace
96 if info[0][0] == '}':
97 continue
98 # Echo a comment line
99 if info[0][0] == '#':
100 outfile.write(line)
101 continue
102
103 # Change print to printModel
104 if info[0] == 'print':
105 info[0] = 'printModel'
106
107 # A command with no arguments, e.g., wipe
108 if N == 1:
109 outfile.write(f"{alias}{info[0]}()\n")
110 continue
111
112 # Needs to be a special case due to beam integration
113 if N >= 8 and info[1] in ['nonlinearBeamColumn','forceBeamColumn','dispBeamColumn']:
114 eleTag = info[2]
115 secTag = info[6]
116 # The original element format
117 # element beamColumn tag ndI ndJ Np secTag transfTag
118 # 0 1 2 3 4 5 6 7
119 if isfloat(secTag):
120 Np = info[5]
121 transfTag = info[7]
122 if info[1] == 'dispBeamColumn':
123 outfile.write(f"{alias}beamIntegration('Legendre',{eleTag},{secTag},{Np})\n")
124 else:
125 outfile.write(f"{alias}beamIntegration('Lobatto',{eleTag},{secTag},{Np})\n")
126 # The newer element format
127 # element beamColumn tag ndI ndJ transfTag integrType ...
128 # 0 1 2 3 4 5 6
129 else:
130 transfTag = info[5]
131 outfile.write(f"{alias}beamIntegration('{info[6]}',{eleTag}")
132 for j in range(7,N):
133 outfile.write(f',{info[j]}')
134 outfile.write(')\n')
135 if info[1] == 'nonlinearBeamColumn':
136 info[1] = 'forceBeamColumn'
137 outfile.write(f"{alias}element('{info[1]}',{eleTag},{info[3]},{info[4]},{transfTag},{eleTag})\n")
138 continue

Callers

nothing calls this directly

Calls 3

isfloatFunction · 0.85
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected