Skip to content

Commit

Permalink
0430
Browse files Browse the repository at this point in the history
  • Loading branch information
tian50 committed Apr 30, 2021
1 parent d5380da commit 165d751
Show file tree
Hide file tree
Showing 11 changed files with 1,004 additions and 5,120 deletions.
56 changes: 51 additions & 5 deletions msgpi/ms/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class BeamSegment(object):

def __init__(self):
#: list of ints: Point labels.
#: `[starting point, ending point]`
#: `[beginning point, ending point]`
self.points = []
#: list of lists of floats: Coordinates of starting and ending points.
#: list of lists of floats: Coordinates of beginning and ending points.
#: `[[x1, x2, x3], [x1, x2, x3]]`
self.coords = []
#: list of ints: Cross-section labels.
#: `[starting, ending]`
#: `[beginning, ending]`
self.css = []

self.cs_template = []
Expand All @@ -38,7 +38,9 @@ def __init__(self):
#: int: Number of division of the segment.
self.num_divisions = 1

self.cs_parameters = {} #: Parameter distributions
#: dict: Parameter distributions
#: `{name: [beginning value, ending value], ...}`
self.cs_parameters = {}

def summary(self):
print(' points:', self.points)
Expand Down Expand Up @@ -124,6 +126,41 @@ def outputRecordInOneLine(self, analysis):



class GEBTBeamResult():
"""Results of the whole beam for a single step or eigenvalue
"""

def __init__(self):
self.points = []
self.members = []

def printAll(self, analysis):
head = '{0:8s}{1:>8s}'.format('type', 'id')
for name in ['x', 'u', 'r', 'f', 'm']:
for i in ['1', '2', '3']:
head += '{0:>16s}'.format(name+i)
if analysis > 0:
for name in ['p', 'm']:
for i in ['1', '2', '3']:
head += '{0:>16s}'.format(name+i)
print(head)

for p in self.points:
print(p.outputRecordInOneLine(analysis))

for i, m in enumerate(self.members):
print('member', i+1)
for e in m:
print(e.outputRecordInOneLine(analysis))









class Beam(object):
"""Class for a slender beam-like structure.
Expand All @@ -142,7 +179,7 @@ def __init__(self):
#: int: Number of analysis steps.
self.num_steps = 1
#: int: Number of eigen analysis resutls.
self.num_eigens = 0
self.num_eigens = 0

# Design
#: list of floats: Angular velocity of the rotating beam.
Expand Down Expand Up @@ -180,6 +217,8 @@ def __init__(self):

# Results
# self.results = None #: Results of GEBT analysis
self.results_steps = []
self.results_eigen = []


def summary(self):
Expand Down Expand Up @@ -222,6 +261,13 @@ def echo(self):
)
print('')


def printResults(self):
for i, step in enumerate(self.results_steps):
print('step', i+1)
step.printAll(self.analysis_type)


def findPtCoordByName(self, name):
"""Find key point coordinates by point id.
Expand Down
173 changes: 169 additions & 4 deletions msgpi/ms/iogebt.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def readGEBTIn(fn_gebt_in):
# --------------------------------------------------------------------
# def read

def readGEBTOutNode(lines):
def readGEBTOutNode(lines, node_type, node_id, analysis=0, method=0):
"""Read GEBT nodal results.
Parameters
Expand All @@ -108,10 +108,106 @@ def readGEBTOutNode(lines):
list of lists of floats
Table of result numbers for this node.
"""

out = []
for l in lines:
out += list(map(float, l.strip().split()))
return out

if method == 0:
return out
elif method == 1:
node_result = msb.GEBTNodeResult()
node_result.type = node_type
node_result.id = node_id
node_result.coord = out[0:3]
node_result.u = out[3:6]
node_result.r = out[6:9]
node_result.f = out[9:12]
node_result.m = out[12:15]
if node_type == 'element' and analysis > 0:
node_result.p = out[15:18]
node_result.h = out[18:21]
return node_result









def readGEBTOutBeam(lines, i, beam):
"""Read the result of the whole beam for a single step or eigenvalue
"""
# print('readGEBTOutBeam')

beam_result = msb.GEBTBeamResult()

# i = 0
pid = 0
mid = 0
while i < len(lines):
line = lines[i].strip()
if (line == '') or ('===' in line) or ('---' in line):
i += 1
# continue
elif 'Point' in line:
# print('- reading point results...')
pid += 1
# Read point result
# out = readGEBTOutNode(lines[i + 2:i + 5])
# results_step['point'].append(out)
node_result = readGEBTOutNode(
lines[i + 2:i + 5], 'point', pid,
analysis=beam.analysis_type, method=1
)
beam_result.points.append(node_result)
i += 5
# points_results.append(out)
# continue
elif 'Member' in line:
# print('- reading member results...')
# Read member result
mid += 1
nelem = beam.segments[mid].num_divisions # number of divisions
i += 2
member_out = []
eid = 0
for j in range(nelem):
# print(' - reading element results...')
eid += 1
if beam.analysis_type == 0:
# Static
# out = readGEBTOutNode(lines[i:i + 3])
elem_result = readGEBTOutNode(
lines[i:i + 3], 'element', eid,
analysis=beam.analysis_type, method=1
)
i += 4
else:
# Dynamic
# out = readGEBTOutNode(lines[i:i + 4])
elem_result = readGEBTOutNode(
lines[i:i + 4], 'element', eid,
analysis=beam.analysis_type, method=1
)
i += 5
# member_out.append(out)
member_out.append(elem_result)
# results_step['member'].append(member_out)
beam_result.members.append(member_out)
# members_results.append(member_out)
# if mid == nmemb:
# results.append(results_step)
# continue
else:
i += 1

if mid == len(beam.segments):
break

return beam_result



Expand Down Expand Up @@ -384,14 +480,83 @@ def readGEBTOut(fn_gebt_out, beam, method=0):
-------
"""

flag_analysis = beam.analysis_type
nstep = beam.num_steps
nkp = len(beam.points)
nmemb = len(beam.segments)

if method == 0:
flag_analysis = beam.analysis_type
if flag_analysis <= 1:
return readGEBTOutStatic(fn_gebt_out, beam)
elif flag_analysis == 3:
return readGEBTOutEigen(fn_gebt_out, beam)

elif method == 1:

with open(fn_gebt_out, 'r') as fin:
all_lines = fin.readlines()

i = 0

# Read results of all steps
sid = 0 # at least one step
while i < len(all_lines):
line = all_lines[i].strip()

if (line == '') or ('===' in line) or ('---' in line):
i += 1
continue
elif ('Step' in line) or ((nstep == 1) and (sid == 0)):
sid += 1 # step number
print('step', sid)
# results_step = {'point': [], 'member': []} # point results, member results
beam_result = readGEBTOutBeam(all_lines, i, beam)
beam.results_steps.append(beam_result)
i += 1
continue
else:
i += 1

if sid == beam.num_steps:
break

# Read results of all eigenvalues
if beam.analysis_type == 3:
# eva = [] # Eigenvalues: [[eva11, eva12], [eva21, eva22], ...]
eig = 0
while i < len(all_lines):
line = all_lines[i].strip()

if (line == '') or ('===' in line) or ('---' in line):
i += 1
continue
elif 'Eigenvalue' in line:
eig += 1
# print 'eigenvalue:', eig
# eva.append(list(map(float, all_lines[i + 1].split())))
eva = list(map(float, all_lines[i + 1].split()))
# evei = [[], []]
# store all Point results for an Eigenvalue temporarily
# evei_p = [] # = [[x11, x12, x13, u11, u12, u13, t11, t12, t13], ...]
# store all Member results for an Eigenvalue temporarily
# evei_m = [] # = [[[x11, x12, x13, u11, u12, u13, t11, t12, t13], [], ...], ...]
# mid = 0 # Member id
# pid = 0
beam_result = readGEBTOutBeam(all_lines, i, beam)
beam.results_eigen.append([eva, beam_result])
# i += 1
continue
# i += 2
# continue
else:
i += 1

if eig == beam.num_eigens:
break

# if beam.analysis_type < 3:
# #
# elif beam.analysis_type == 3:




Expand Down
13 changes: 11 additions & 2 deletions msgpi/ms/prebeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,17 @@ def preBeam2(fn_beam):
# Cross-section parameters
for xe_param in xe_sgm.findall('parameter'):
name = xe_param.find('name').text.strip()
value = float(xe_param.find('value').text.strip())
bs.cs_parameters[name] = value
values = [0, 0]
for xe_value in xe_param.findall('value'):
apply = xe_value.get('apply', default='all')
value = float(xe_value.text.strip())
if apply == 'all':
values = [value, value]
elif apply == 'begin':
values[0] = value
elif apply == 'end':
values[1] = value
bs.cs_parameters[name] = values


beam.segments[bslabel] = bs
Expand Down
2 changes: 1 addition & 1 deletion msgpi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def listToString(flist, delimiter='', fmt=''):
s = ''
for i, n in enumerate(flist):
if i > 0:
s = s + delimiter + ' '
s = s + delimiter
s += sfmt.format(n)
return s

Expand Down
2 changes: 1 addition & 1 deletion tests/test_read_gebt_inout/cantilever1.dat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
2 1.0 0.0 0.0


1 1 2 1 1 0 600 0 # kp_1 kp_2 mate_no1 mate_no2 frame# #divisions, curvature# velocity#
1 1 2 1 1 0 11 0 # kp_1 kp_2 mate_no1 mate_no2 frame# #divisions, curvature# velocity#

1 #point conditions
1 2 3 4 5 6
Expand Down
2 changes: 1 addition & 1 deletion tests/test_read_gebt_inout/cantilever1.dat.ech
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
----------------------------------------------------------------
Member NO: 1
--------------------------------
1 2 1 1 0 600 0
1 2 1 1 0 11 0


Prescribed Point Conditions
Expand Down
Loading

0 comments on commit 165d751

Please sign in to comment.