Skip to content

Commit

Permalink
0423
Browse files Browse the repository at this point in the history
  • Loading branch information
tian50 committed Apr 24, 2021
1 parent d4503c5 commit d5380da
Show file tree
Hide file tree
Showing 41 changed files with 1,549,950 additions and 49 deletions.
20 changes: 15 additions & 5 deletions msgpi/dakota_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import csv
import datetime as dt
import json
import logging
import os
import platform
import subprocess as sbp
Expand All @@ -16,6 +17,8 @@
import dakota.interfacing as di


log_level = 20

# Format string
msgfmt_w_ts = '- [{ts:%H}:{ts:%M}] {msg}' # string format with time stamp
fse = ' x [{0:%H}:{0:%M}:{0:%S}] EVAL {1:d}: {2:s}'
Expand All @@ -27,6 +30,11 @@ def process(fn_json_args):
with open(fn_json_args, 'r') as fo:
interface_args = json.load(fo)

logging.basicConfig(
filename='app.log', filemode='w',
format='%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S',
level=20
)

# Load data processing module
if 'data_process_functions_file' in interface_args.keys():
Expand All @@ -53,10 +61,11 @@ def process(fn_json_args):
di.dprepro(template=fn_t, parameters=params, output=fn_i)

evid = int(params.eval_id)
print(msgfmt_w_ts.format(
ts=dt.datetime.now(),
msg=' '.join(('eval', str(evid), 'start'))
))
# print(msgfmt_w_ts.format(
# ts=dt.datetime.now(),
# msg=' '.join(('eval', str(evid), 'start'))
# ))
logging.info(' '.join(('eval', str(evid), 'start')))


try:
Expand Down Expand Up @@ -164,7 +173,8 @@ def process(fn_json_args):
# Write output
results.write()

print(' - done.')
# print(' - done.')
logging.info('done')

return

Expand Down
66 changes: 66 additions & 0 deletions msgpi/ms/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,72 @@ def calcLengthSq(self):
return ((np.array(self.coords[0]) - np.array(self.coords[1]))**2).sum()









class GEBTNodeResult():
"""One set of result of a keypoint or element mid point.
"""

def __init__(self):
#: str: Type of the node ('point' or 'element')
self.type = None

#: int: ID of the node
self.id = 0

#: list of floats: Coordinates of the node
self.coord = [0, 0, 0]

#: list of floats: Global displacement at the node
self.u = [0, 0, 0]

#: list of floats: Global rotation at the node
self.r = [0, 0, 0]

#: list of floats: Sectional force at the node
self.f = [0, 0, 0]

#: list of floats: Sectional moment at the node
self.m = [0, 0, 0]

#: list of floats: Linear momenta at the node
self.p = [0, 0, 0]

#: list of floats: Angular momenta at the node
self.h = [0, 0, 0]


def outputRecordInOneLine(self, analysis):
record = ''

record += '{:8s}'.format(self.type)
record += '{:8d}'.format(self.id)

record += utils.listToString(self.coord, fmt='16.7E')
record += utils.listToString(self.u, fmt='16.7E')
record += utils.listToString(self.r, fmt='16.7E')
record += utils.listToString(self.f, fmt='16.7E')
record += utils.listToString(self.m, fmt='16.7E')

if analysis > 0:
record += utils.listToString(self.p, fmt='16.7E')
record += utils.listToString(self.h, fmt='16.7E')

return record









class Beam(object):
"""Class for a slender beam-like structure.
Expand Down
16 changes: 10 additions & 6 deletions msgpi/ms/iogebt.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def readGEBTIn(fn_gebt_in):


# --------------------------------------------------------------------
# def read

def readGEBTOutNode(lines):
"""Read GEBT nodal results.
Expand Down Expand Up @@ -369,7 +370,7 @@ def readGEBTOutEigen(fn_gebt_out, beam):



def readGEBTOut(fn_gebt_out, beam):
def readGEBTOut(fn_gebt_out, beam, method=0):
"""Read GEBT results.
Parameters
Expand All @@ -382,12 +383,15 @@ def readGEBTOut(fn_gebt_out, beam):
Returns
-------
"""
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)

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:




Expand Down
78 changes: 78 additions & 0 deletions msgpi/sg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import numpy as np
import msgpi.io.utils as ioutil


class MaterialSection(object):
Expand Down Expand Up @@ -706,6 +707,8 @@ def summary(self):
print('')
print('SUMMARY OF THE SG')
print('')
print('Name: {0}'.format(self.name))
print('')
print('Structure gene dimension: {0}'.format(self.sgdim))
print('Structure model dimension: {0}'.format(self.smdim))
print('')
Expand Down Expand Up @@ -755,6 +758,81 @@ def findComboByMaterialOrientation(self, name, angle):
return 0


def writeGmshNodes(self, fo, nid_begin=1, loc=[0, 0, 0]):
for i in range(len(self.nodes)):
nid = i + 1
ncoords = copy.deepcopy(self.nodes[nid])
fo.write('{0:8d}'.format(i+nid_begin))
if self.sgdim == 2:
ncoords.insert(0, 0.0)
ncoords = [ncoords[i] + loc[i] for i in range(3)]
ioutil.writeFormatFloats(fo, ncoords)


def writeGmshElements(self, fo, nid_begin=1, eid_begin=1):
for i in range(len(self.elements)):
eid = i + 1
econnct = copy.deepcopy(self.elements[eid])
if self.sgdim == 2:
elem_type = 2
if len(econnct) == 4:
elem_type = 3
line = [i+eid_begin, elem_type, 2, 1, 1]
econnct = [nid + nid_begin - 1 for nid in econnct]
line = line + econnct
ioutil.writeFormatIntegers(fo, line)


def writeGmshMsh(self, fo, nid_begin=1, eid_begin=1, loc=[0, 0, 0], *args, **kwargs):
# if fn == '':
# fn = self.name + '.msh'

# with open(self.fn_gmsh_msh, 'w') as fo:
fo.write('$MeshFormat\n')
fo.write('2.2 0 8\n')
fo.write('$EndMeshFormat\n')
fo.write('\n')


# Write nodes
fo.write('$Nodes\n')
fo.write(str(len(self.nodes))+'\n')

self.writeGmshNodes(fo, nid_begin, loc)

fo.write('$EndNodes\n')
fo.write('\n')


# Write Elements
fo.write('$Elements\n')
fo.write(str(len(self.elements))+'\n')

self.writeGmshElements(fo, nid_begin, eid_begin)

fo.write('$EndElements\n')
fo.write('\n')


# Write options
# fn_gmsh_msh_opt = fn + '.opt'
# with open(fn_gmsh_msh_opt, 'w') as fout:
# fout.write('General.Axes = ' + str(3) + ';\n')
# fout.write('General.Orthographic = ' + str(1) + ';\n')
# fout.write('General.RotationX = ' + str(270) + ';\n')
# fout.write('General.RotationY = ' + str(360) + ';\n')
# fout.write('General.RotationZ = ' + str(270) + ';\n')
# fout.write('General.ScaleX = ' + str(2) + ';\n')
# fout.write('General.ScaleY = ' + str(2) + ';\n')
# fout.write('General.ScaleZ = ' + str(2) + ';\n')
# fout.write('General.Trackball = ' + str(0) + ';\n')
# fout.write('Geometry.LineWidth = ' + str(1) + ';\n')
# fout.write('Mesh.ColorCarousel = ' + str(2) + ';\n')
# fout.write('Mesh.SurfaceFaces = ' + str(1) + ';\n')


return




Expand Down
Loading

0 comments on commit d5380da

Please sign in to comment.