def lin_buckle(name, job_name, n_longerons, bottom_diameter, top_diameter, pitch, young_modulus, shear_modulus, cross_section_props, twist_angle=0., transition_length_ratio=1., n_storeys=1, power=1., include_name='include_mesh', **kwargs): # create model model = mdb.Model(name=name) backwardCompatibility.setValues(reportDeprecated=False) if 'Model-1' in mdb.models.keys(): del mdb.models['Model-1'] # meshing cone_slope = (bottom_diameter - top_diameter) / bottom_diameter _meshing(model, n_longerons, bottom_diameter, pitch, cross_section_props, young_modulus, shear_modulus, cone_slope, include_name=include_name) # create linear buckling inp with open('{}.inp'.format(job_name), 'w') as File: File.write('** Include file with mesh of structure:\n') File.write('*INCLUDE, INPUT={}.inp\n'.format(include_name)) File.write('** \n') File.write('** STEP: Step-1\n') File.write('** \n') File.write('*Step, name=Step-1\n') File.write('*Buckle, eigensolver=lanczos\n') File.write('20, 0., , , \n') File.write('** \n') File.write('** BOUNDARY CONDITIONS\n') File.write('** \n') File.write('** Name: BC_Zminus Type: Displacement/Rotation\n') File.write('*Boundary\n') File.write('RP_ZmYmXm, 1, 6\n') File.write('** \n') File.write('** LOADS\n') File.write('** \n') File.write('** Name: Applied_Moment Type: Moment\n') File.write('*Cload\n') File.write('RP_ZpYmXm, 3, -1.00\n') File.write('** \n') File.write('*Node File\n') File.write('U \n') File.write('** \n') File.write('*EL PRINT,FREQUENCY=1\n') File.write('*NODE PRINT,FREQUENCY=1\n') File.write('*MODAL FILE\n') File.write('*OUTPUT,FIELD,VAR=PRESELECT\n') File.write('*OUTPUT,HISTORY,FREQUENCY=1\n') File.write('*MODAL OUTPUT\n') File.write('*End Step\n')
# -*- coding: utf-8 -*- #filename:abaqus_1.py ####################################调用模块 from random import * from abaqus import * from abaqusConstants import * from caeModules import * from driverUtils import executeOnCaeStartup from abaqus import backwardCompatibility backwardCompatibility.setValues(reportDeprecated=False) import os executeOnCaeStartup() ###################################设定参数 if os.path.exists('D:\\PythonCode\\bishe\\circle_force.txt'): os.remove('D:\\PythonCode\\bishe\\circle_force.txt') f = open('D:\\PythonCode\\bishe\\circle.txt', 'r') ffo = open('D:\\PythonCode\\bishe\\circle_force.txt', 'a+') ffo.write('name\t\tRF1\t\tU1\t\tRF2\t\tU2\n') #i=0 for line in f: #i=i+1 #print (i) data = line.split() bwidx = float(data[0]) #基体宽度 bwidy = float(data[1]) #基体长度 f_r = float(data[2]) #纤维半径 f_dis = float(data[3]) #纤维最小间距一半 f_num = int(data[4]) #纤维数目 size0 = float(data[5]) #网格尺寸 job_name = data[6] #工作名称
def lin_buckle(model_name, job_name, n_longerons, bottom_diameter, young_modulus, shear_modulus, ratio_top_diameter, ratio_pitch, ratio_d): # variables from ratios d = ratio_d * bottom_diameter pitch = ratio_pitch * bottom_diameter top_diameter = bottom_diameter * (1. - ratio_top_diameter) # variables with defaults n_storeys = 1 twist_angle = 0. transition_length_ratio = 1. # compute variables mast_radius = bottom_diameter / 2. mast_height = n_storeys * pitch cone_slope = (bottom_diameter - top_diameter) / bottom_diameter # create abaqus model model = mdb.Model(name=model_name) backwardCompatibility.setValues(reportDeprecated=False) if 'Model-1' in mdb.models.keys(): del mdb.models['Model-1'] # create joints joints = np.zeros((n_storeys + 1, n_longerons, 3)) for i_storey in range(0, n_storeys + 1, 1): zcoord = mast_height / n_storeys * i_storey aux1 = 2.0 * np.pi / n_longerons aux2 = twist_angle * min( zcoord / mast_height / transition_length_ratio, 1.0) for i_vertex in range(0, n_longerons): aux3 = aux1 * i_vertex + aux2 xcoord = mast_radius * np.cos(aux3) ycoord = mast_radius * np.sin(aux3) joints[i_storey, i_vertex, :] = ( xcoord * (1.0 - min(zcoord, transition_length_ratio * mast_height) / mast_height * cone_slope), ycoord * (1.0 - min(zcoord, transition_length_ratio * mast_height) / mast_height * cone_slope), zcoord) # create geometry longerons longerons_name = 'LONGERONS' part_longerons = model.Part(longerons_name, dimensionality=THREE_D, type=DEFORMABLE_BODY) longeron_points = [] for i_vertex in range(0, n_longerons): # get required points longeron_points.append([ joints[i_storey, i_vertex, :] for i_storey in range(0, n_storeys + 1) ]) # create wires part_longerons.WirePolyLine(points=longeron_points[-1], mergeType=IMPRINT, meshable=ON) # create surface surface_name = 'ANALYTICAL_SURF' s = model.ConstrainedSketch(name='SURFACE_SKETCH', sheetSize=mast_radius * 3.0) s.Line(point1=(0.0, -mast_radius * 1.1), point2=(0.0, mast_radius * 1.1)) part_surf = model.Part(name=surface_name, dimensionality=THREE_D, type=ANALYTIC_RIGID_SURFACE) part_surf.AnalyticRigidSurfExtrude(sketch=s, depth=mast_radius * 2.2) # create required sets and surfaces # surface part_surf.Surface(side1Faces=part_surf.faces, name=surface_name) # longeron edges = part_longerons.edges vertices = part_longerons.vertices # individual sets all_edges = [] for i_vertex, long_pts in enumerate(longeron_points): # get vertices and edges selected_vertices = [vertices.findAt((pt, )) for pt in long_pts] all_edges.append(EdgeArray([edges.findAt(pt) for pt in long_pts])) # individual sets long_name = 'LONGERON-{}'.format(i_vertex) part_longerons.Set(edges=all_edges[-1], name=long_name) # joints for i_storey, vertex in enumerate(selected_vertices): joint_name = 'JOINT-{}-{}'.format(i_storey, i_vertex) part_longerons.Set(vertices=vertex, name=joint_name) name = 'ALL_LONGERONS' part_longerons.Set(edges=all_edges, name=name) name = 'ALL_LONGERONS_SURF' part_longerons.Surface(circumEdges=all_edges, name=name) # joint sets selected_vertices = [] for i_storey in range(0, n_storeys + 1): selected_vertices.append([]) for i_vertex in range(0, n_longerons): name = 'JOINT-{}-{}'.format(i_storey, i_vertex) selected_vertices[-1].append(part_longerons.sets[name].vertices) name = 'BOTTOM_JOINTS' part_longerons.Set(name=name, vertices=selected_vertices[0]) name = 'TOP_JOINTS' part_longerons.Set(name=name, vertices=selected_vertices[-1]) name = 'ALL_JOINTS' all_vertices = list(itertools.chain(*selected_vertices)) part_longerons.Set(name=name, vertices=all_vertices) # create beam section # create section material material_name = 'LONGERON_MATERIAL' nu = young_modulus / (2 * shear_modulus) - 1 abaqusMaterial = model.Material(name=material_name) abaqusMaterial.Elastic(type=ISOTROPIC, table=((young_modulus, nu), )) # create profile profile_name = 'LONGERONS_PROFILE' r = d / 2. model.CircularProfile(name=profile_name, r=r) # create profile section_name = 'LONGERONS_SECTION' model.BeamSection(consistentMassMatrix=False, integration=DURING_ANALYSIS, material=material_name, name=section_name, poissonRatio=0.31, profile=profile_name, temperatureVar=LINEAR) # section assignment part_longerons.SectionAssignment( offset=0.0, offsetField='', offsetType=MIDDLE_SURFACE, region=part_longerons.sets['ALL_LONGERONS'], sectionName=section_name, thicknessAssignment=FROM_SECTION) # section orientation for i_vertex, pts in enumerate(longeron_points): dir_vec_n1 = np.array(pts[0]) - (0., 0., 0.) longeron_name = 'LONGERON-{}'.format(i_vertex) region = part_longerons.sets[longeron_name] part_longerons.assignBeamSectionOrientation(region=region, method=N1_COSINES, n1=dir_vec_n1) # generate mesh # seed part mesh_size = min(mast_radius, pitch) / 300. mesh_deviation_factor = .04 mesh_min_size_factor = .001 element_code = B31 part_longerons.seedPart(size=mesh_size, deviationFactor=mesh_deviation_factor, minSizeFactor=mesh_min_size_factor, constraint=FINER) # assign element type elem_type_longerons = mesh.ElemType(elemCode=element_code) part_longerons.setElementType(regions=(part_longerons.edges, ), elemTypes=(elem_type_longerons, )) # generate mesh part_longerons.generateMesh() # create instances modelAssembly = model.rootAssembly part_surf = model.parts[surface_name] modelAssembly.Instance(name=longerons_name, part=part_longerons, dependent=ON) modelAssembly.Instance(name=surface_name, part=part_surf, dependent=ON) # rotate surface modelAssembly.rotate(instanceList=(surface_name, ), axisPoint=(0., 0., 0.), axisDirection=(0., 1., 0.), angle=90.) # create reference points for boundary conditions ref_point_positions = ['BOTTOM', 'TOP'] for i, position in enumerate(ref_point_positions): sign = 1 if i else -1 rp = modelAssembly.ReferencePoint(point=(0., 0., i * mast_height + sign * 1.1 * mast_radius)) modelAssembly.Set( referencePoints=(modelAssembly.referencePoints[rp.id], ), name='Z{}_REF_POINT'.format(position)) # add constraints for loading instance_longerons = modelAssembly.instances[longerons_name] instance_surf = modelAssembly.instances[surface_name] ref_points = [ modelAssembly.sets['Z{}_REF_POINT'.format(position)] for position in ref_point_positions ] # bottom point and analytic surface surf = instance_surf.surfaces[surface_name] model.RigidBody('CONSTRAINT-RIGID_BODY-BOTTOM', refPointRegion=ref_points[0], surfaceRegion=surf) # create local datums datums = [] for i_vertex in range(0, n_longerons): origin = joints[0, i_vertex, :] point2 = joints[0, i_vertex - 1, :] name = 'LOCAL_DATUM_{}'.format(i_vertex) datums.append( part_longerons.DatumCsysByThreePoints(origin=origin, point2=point2, name=name, coordSysType=CARTESIAN, point1=(0.0, 0.0, 0.0))) # create coupling constraints for i_vertex in range(n_longerons): datum = instance_longerons.datums[datums[i_vertex].id] for i, i_storey in enumerate([0, n_storeys]): joint_name = 'JOINT-{}-{}'.format(i_storey, i_vertex) slave_region = instance_longerons.sets[joint_name] master_region = ref_points[i] constraint_name = 'CONSTRAINT-%s-%i-%i' % ('Z{}_REF_POINT'.format( ref_point_positions[i]), i_storey, i_vertex) model.Coupling(name=constraint_name, controlPoint=master_region, surface=slave_region, influenceRadius=WHOLE_SURFACE, couplingType=KINEMATIC, localCsys=datum, u1=ON, u2=ON, u3=ON, ur1=OFF, ur2=ON, ur3=ON) # from now on, there's differences between linear buckle and riks # create step step_name = 'BUCKLE_STEP' model.BuckleStep(step_name, numEigen=20, previous='Initial', minEigen=0.) # set bcs (displacement) region_name = 'Z{}_REF_POINT'.format(ref_point_positions[0]) loaded_region = modelAssembly.sets[region_name] model.DisplacementBC('BC_FIX', createStepName=step_name, region=loaded_region, u1=0., u2=0., u3=0., ur1=0., ur2=0., ur3=0., buckleCase=BUCKLING_MODES) # set bcs (load) applied_load = -1. region_name = 'Z{}_REF_POINT'.format(ref_point_positions[-1]) loaded_region = modelAssembly.sets[region_name] model.ConcentratedForce('APPLIED_FORCE', createStepName=step_name, region=loaded_region, cf3=applied_load) # create provisory inp modelJob = mdb.Job(model=model_name, name=job_name) modelJob.writeInput(consistencyChecking=OFF) # ask for node file with open('{}.inp'.format(job_name), 'r') as file: lines = file.readlines() line_cmp = '** {}\n'.format('OUTPUT REQUESTS') for i, line in reversed(list(enumerate(lines))): if line == line_cmp: break insert_line = i + 2 for line in reversed(['*NODE FILE, frequency=1', 'U']): lines.insert(insert_line, '{}\n'.format(line)) with open('{}.inp'.format(job_name), 'w') as file: file.writelines(lines)