Skip to content

Commit

Permalink
0802
Browse files Browse the repository at this point in the history
  • Loading branch information
Su Tian committed Aug 2, 2021
1 parent c7c13c0 commit 5ce91b7
Show file tree
Hide file tree
Showing 8 changed files with 420 additions and 277 deletions.
194 changes: 96 additions & 98 deletions msgpi/ms/beam.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,81 @@
import typing
import numpy as np
import msgpi.sg as sgi
import msgpi.sg as msg
import msgpi.io.utils as ioutil
import msgpi.utils as utils
import pprint


class BeamSegment(object):
"""Class for a beam segment.
class GEBTBeamMember():
"""Class for a GEBT beam memebr.
"""

def __init__(self):
self.member_id = None

#: list of ints: Point labels.
#: `[beginning point, ending point]`
self.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.
#: `[beginning, ending]`
self.css = []

self.cs_template = []

#: float: Rotation around a1.
self.rotate_a1 = 0.0
#: float: Twist.
self.twist = 0.0
# self.dihedral = 0.
# self.sweep = 0.
#: int: Local frame id.
self.local_frame_id = 0
#: int: Frame id
self.frame_id = 0
self.frame_id: int = 0
#: int: Curvature id
self.curv_id = 0
self.curv_id: int = 0

#: int: Number of division of the segment.
self.num_divisions = 1
self.num_divisions: int = 1


def __str__(self):
s = f'{self.member_id:4d}'
s += f'{self.points[0]:4d}{self.points[1]:4d}'
s += f'{self.css[0]:4d}{self.css[1]:4d}'
s += f'{self.frame_id:4d}{self.num_divisions:4d}{self.curv_id:4d}'
return s

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

def summary(self):
print(' points:', self.points)
print(' coords:', self.coords)
print(' cs names:', self.css)
print(' cs templates:', self.cs_template)
print(' cs parameters:', self.cs_parameters)
print('member:', self.member_id)
print('points:', self.points)
print('sectional properties:', self.css)
print('frame:', self.frame_id)
print('divisions:', self.num_divisions)
print('initial curvature:', self.curv_id)

def calcLengthSq(self):
"""Calculate the square of the segment length.

Returns
-------
float
Squred length of the segment.
"""
return ((np.array(self.coords[0]) - np.array(self.coords[1]))**2).sum()
def writeGEBTInput(self, file):
file.write(self.__str__())
file.write('\n')




class GEBTCondition():
def __init__(self):
self.object_id = None
self.dofs = [0, 0, 0, 0, 0, 0]
self.values = [0., 0., 0., 0., 0., 0.]
self.time_funcs = [0, 0, 0, 0, 0, 0]
self.followers = [0, 0, 0, 0, 0, 0]

def summary(self):
print('member:', self.object_id)
print('dofs:', self.dofs)
print('values:', self.values)
print('time functions:', self.time_funcs)
print('follower loads:', self.followers)

def writeGEBTInput(self, file):
file.write(f'{self.object_id}\n')
ioutil.writeFormatIntegers(file, self.dofs, '16d')
ioutil.writeFormatFloats(file, self.values, '16.6E')
ioutil.writeFormatIntegers(file, self.time_funcs, '16d')
ioutil.writeFormatIntegers(file, self.followers, '16d')
file.write('\n')



Expand Down Expand Up @@ -161,7 +174,7 @@ def printAll(self, analysis):



class Beam(object):
class GEBTBeam(object):
"""Class for a slender beam-like structure.
This class is mainly for the GEBT code.
Expand Down Expand Up @@ -199,30 +212,30 @@ def __init__(self):
#: `{ptid: [x1, x2, x3], ...}`
self.points = {}

#: dict of {int, msgpi.ms.beam.BeamSegment}: Beam segments
#: `{bsid: BeamSegment object, ...}`
self.segments = {}
#: dict of {int, msgpi.ms.beam.GEBTBeamMember}: Beam members
#: `{bsid: GEBTBeamMember object, ...}`
self.members: typing.Dict[int, GEBTBeamMember] = {}

# self.divisions = [] # Divisions of members
#: list: Point conditions (B.C. and loads).
self.pconditions = []
self.pconditions: typing.List[GEBTCondition] = []
#: list: Member conditions (B.C. and loads).
self.mconditions = []
self.mconditions: typing.List[GEBTCondition] = []

#: dict of {int, msgpi.sg.BeamProperty}: Effective properties of cross-sections.
#: `{sid: BeamProperty object, ...}`
self.sections = {}
self.sections: typing.Dict[int, msg.BeamProperty] = {}

# {section name: template name, ...}
self.section_templates = {}
# self.section_templates = {}

self.frames = {} #: Local frames
self.distrloads = [] #: Distribution loads
self.timefunctions = [] #: Time functions
self.initcurvatures = [] #: Initial curvatures

self.functions = {} #: Functions
self.distributions = {} #: Distributions
# self.functions = {} #: Functions
# self.distributions = {} #: Distributions

# Results
# self.results = None #: Results of GEBT analysis
Expand Down Expand Up @@ -252,18 +265,13 @@ def summary(self):
for pid, coords in self.points.items():
print(f'{pid}: ( {coords[0]} , {coords[1]} , {coords[2]} )')

print('\nSegments')
for k, v in self.segments.items():
print('segment', k)
print('\nMembers')
for k, v in self.members.items():
v.summary()

print('\nPoint B.C.')

print('\nMember B.C.')

print('\nSection templates')
for sn, st in self.section_templates.items():
print(f'{sn}: {st}')
print('\nPoint conditions')
for pc in self.pconditions:
pc.summary()

print('\nSectional properties')
for sid, bp in self.sections.items():
Expand All @@ -275,13 +283,9 @@ def summary(self):
pp.pprint(bp.mass)
print('')

print('\nDistributions')
pp.pprint(self.distributions)

print('\nFunctions')
# pp.pprint(self.functions)
for k, v in self.functions.items():
print(k, ':', v)
print('\nMember conditions')
for mc in self.mconditions:
mc.summary()



Expand Down Expand Up @@ -434,7 +438,7 @@ def writeGEBTIn(self, fn_gebt_in=''):
fout.write('\n')

line = [
len(self.points), len(self.segments), len(self.pconditions),
len(self.points), len(self.members), len(self.pconditions),
len(self.sections), len(self.frames), len(self.mconditions),
len(self.distrloads), len(self.timefunctions), len(self.initcurvatures)
]
Expand All @@ -449,52 +453,46 @@ def writeGEBTIn(self, fn_gebt_in=''):

# Write the block of members
# for i, member in enumerate(members):
for bsid, bs in self.segments.items():
line = [
bsid, bs.points[0], bs.points[1], bs.css[0], bs.css[1],
bs.frame_id, bs.num_divisions, bs.curv_id
]
ioutil.writeFormatIntegers(fout, line, '4d')
for bmid in range(1, len(self.members)+1):
bm = self.members[bmid]
bm.writeGEBTInput(fout)
# line = [
# bmid, bm.points[0], bm.points[1], bm.css[0], bm.css[1],
# bm.frame_id, bm.num_divisions, bm.curv_id
# ]
# ioutil.writeFormatIntegers(fout, line, '4d')
fout.write('\n')

# Write the block of point conditions
for condition in self.pconditions:
fout.write('{0:4d}\n'.format(condition['point']))
ioutil.writeFormatIntegers(fout, condition['components'], '16d')
ioutil.writeFormatFloats(fout, condition['values'])
ioutil.writeFormatIntegers(
fout, np.zeros(6, dtype=np.int8), '16d')
ioutil.writeFormatIntegers(
fout, np.zeros(6, dtype=np.int8), '16d')
for pc in self.pconditions:
pc.writeGEBTInput(fout)
# fout.write('{0:4d}\n'.format(condition['point']))
# ioutil.writeFormatIntegers(fout, condition['components'], '16d')
# ioutil.writeFormatFloats(fout, condition['values'])
# ioutil.writeFormatIntegers(
# fout, np.zeros(6, dtype=np.int8), '16d')
# ioutil.writeFormatIntegers(
# fout, np.zeros(6, dtype=np.int8), '16d')
fout.write('\n')

# Write the block of cross sectional properties
# for i, member in enumerate(members):
for sid, ms in self.sections.items():
fmt = '20.10E'
for sid in range(1, len(self.sections)+1):
bp = self.sections[sid]
fout.write('{0:4d}\n'.format(sid))
# tcm = st['tcm']
# for row in tcm:
# utl.writeFormatFloats(fout, row)
# if len(ms.eff_props[1]['compliance']['refined']) > 0:
if not ms.compliance_refined is None:
# for row in ms.eff_props[1]['compliance']['refined']:
for row in ms.compliance_refined:
ioutil.writeFormatFloats(fout, row)
if len(bp.cmpl_t) > 0:
for row in bp.cmpl_t:
ioutil.writeFormatFloats(fout, row, fmt=fmt)
else:
# for i, row in enumerate(ms.eff_props[1]['compliance']['classical']):
for i, row in enumerate(ms.compliance):
ioutil.writeFormatFloats(fout, (row[0], 0, 0, row[1], row[2], row[3]))
for i, row in enumerate(bp.cmpl):
ioutil.writeFormatFloats(fout, (row[0], 0, 0, row[1], row[2], row[3]), fmt=fmt)
if i == 0:
ioutil.writeFormatFloats(fout, np.zeros(6))
ioutil.writeFormatFloats(fout, np.zeros(6))
ioutil.writeFormatFloats(fout, np.zeros(6), fmt=fmt)
ioutil.writeFormatFloats(fout, np.zeros(6), fmt=fmt)
fout.write('\n')
if self.analysis_type != 0:
# mass = st['mass']
# for row in mass:
# utl.writeFormatFloats(fout, row)
# for row in ms.eff_props[1]['mass']['origin']:
for row in ms.mass_origin:
ioutil.writeFormatFloats(fout, row)
for row in bp.mass:
ioutil.writeFormatFloats(fout, row, fmt=fmt)
fout.write('\n')

# Write the block of self.frames
Expand Down
45 changes: 33 additions & 12 deletions msgpi/ms/blade.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pprint
import xml.etree.ElementTree as et
import msgpi.cross_section as mcs
import msgpi.ms.beam as msbeam
import msgpi.utils as utils


Expand Down Expand Up @@ -101,22 +102,28 @@ def __init__(self):
self.section_templates = {}


# Model
self.model = None
self.solver = None
self.analysis = None




def summary(self):
pp = pprint.PrettyPrinter(indent=4, compact=False)

print('\nAnalysis')
print('analysis type:', self.analysis_type)
print('max iteration:', self.max_iteration)
print('number of steps:', self.num_steps)
if self.analysis_type != 0:
print('angular velocity:', self.angular_velocity)
print('time function:', self.av_tf)
print('linear velocity:', self.linear_velocity)
print('time function:', self.lv_tf)
if self.analysis_type == 3:
print('number of eigen results:', self.num_eigens)
# print('\nAnalysis')
# print('analysis type:', self.analysis_type)
# print('max iteration:', self.max_iteration)
# print('number of steps:', self.num_steps)
# if self.analysis_type != 0:
# print('angular velocity:', self.angular_velocity)
# print('time function:', self.av_tf)
# print('linear velocity:', self.linear_velocity)
# print('time function:', self.lv_tf)
# if self.analysis_type == 3:
# print('number of eigen results:', self.num_eigens)

print('\nPoints')
# pp.pprint(self.points)
Expand Down Expand Up @@ -227,14 +234,22 @@ def genCrossSectionDesign(self, segi, csj):
return cs_name, cs_params


def createGEBTBeamModel(self):
gbm = msbeam.GEBTBeam()

# Create members from segments

self.model = gbm
return








def readBladeInput(fn_blade):
def readBladeInput(fn_blade: str) -> Blade:

blade = Blade()

Expand Down Expand Up @@ -371,6 +386,12 @@ def readBladeInput(fn_blade):
blade.segments[bslabel] = bs


# Read modeling inputs
xe_model = xr_beam.find('model')




return blade


Expand Down
Loading

0 comments on commit 5ce91b7

Please sign in to comment.