def analyzeTruss(mesh_file, bound, loadNode): #Create Geometry ele = element.Data() for i in range(23): ele.E[i] = 100. ele.A[i] = 10. ele.TYPE[i] = 'Truss' mesh = gmsh.Parse(mesh_file) model = structure.Builder(mesh, ele, bound) trialLoad = findMaxLoad(mesh, model, ele, loadNode, 0, 10, -100) maxLoad = trialLoad XYZplot = model.XYZ for design in range(10): for coord in range(len(model.XYZ)): if coord > 1 and coord != loadNode: model.XYZ[coord][0] = XYZplot[coord][0] + random.randint(-2, 2) if model.XYZ[coord][0] < 0: model.XYZ[coord][0] * -1 model.XYZ[coord][1] = XYZplot[coord][1] + random.randint(-2, 2) if coord == loadNode: model.XYZ[coord][1] = XYZplot[coord][1] + random.randint(-2, 2) try: trialLoad = findMaxLoad(mesh, model, ele, loadNode, 0, 10, -300) print(model.XYZ) print(trialLoad) if trialLoad < maxLoad: maxLoad = trialLoad XYZplot = model.XYZ print('better') print(XYZplot) except LinAlgError: continue print(maxLoad) print(XYZplot) nodal_load = {loadNode: [0, maxLoad]} U, Q = displmethod.solver(mesh, model, ele, nodal_load) plotter.axialforce(model, Q) plt.show()
from sapy import gmsh from sapy import structure from sapy import plotter mesh_file = 'warren' # these are the constraints # this says that node 0 is fixed/restrained in both x and y # directions (a pin connection) and node 4 is constrained in # only the y direction (a roller, with the angle theta set to 0 degrees) bound = {0: [1, 1], 3: [0, 1]} # this is the loading on the truss. nodal_load = {5: [0, -10]} # parse the mesh file to create mesh.xyz (list of Points) and # mesh.con (list of connections (beams) between Points) mesh = gmsh.Parse(mesh_file) # this is to create the composition of the beams in the truss ele = element.Data() for i in range(len(mesh.con)): ele.E[i] = 100. # sectional area? ele.A[i] = 10. # Young's modulus? ele.TYPE[i] = 'Truss' # Truss or Frame model = structure.Builder(mesh, ele, bound) U, Q = displmethod.solver(mesh, model, ele, nodal_load) plotter.undeformed(model) plotter.deformed(model, U) plotter.axialforce(model, Q) plotter.show()