收藏 分销(赏)

在abaqus中利用python语言建模例子.pdf

上传人:曲**** 文档编号:226687 上传时间:2023-03-11 格式:PDF 页数:11 大小:358.92KB
下载 相关 举报
在abaqus中利用python语言建模例子.pdf_第1页
第1页 / 共11页
在abaqus中利用python语言建模例子.pdf_第2页
第2页 / 共11页
在abaqus中利用python语言建模例子.pdf_第3页
第3页 / 共11页
在abaqus中利用python语言建模例子.pdf_第4页
第4页 / 共11页
在abaqus中利用python语言建模例子.pdf_第5页
第5页 / 共11页
点击查看更多>>
资源描述

1、3.1 Creating a partThe first example shows how you can use an Abaqus/CAE script to replicate the functionality of Abaqus/CAE.The script does the following:Creates a new model in the model database.Creates a two-dimensional sketch.Creates a three-dimensional,deformable part.Extrudes the two-dimension

2、al sketch to create the first geometric feature of the part.Creates a new viewport.Displays a shaded image of the new part in the new viewport.The new viewport and the shaded part are shown in Figure 3 7.Figure 3-1 The example creates a new viewport and a part.YQ Viewport for Model A Model:Model A P

3、art:Part A B QThe example scripts from this manual can be copied to the user5 s working directory by using the Abaqus fetch utility:abaqus fetch job=scriptNamewhere scriptName.py is the name of the script(see“Execution procedure for fetching sample input files,“Section 3.2.12 of the Abaqus Analysis

4、Users Manual).Use the following command to retrieve the script for this example:xyCoordsOuter 二(TO,30),(10,30),(40,-30),(30,-30),(20,-10),(-20,-10),(-30,-30),(-40,-30),(-10,30)for i in range(len(xyCoordsInner)-l):mySketch.Line(pointl=xyCoordsInneri,point2=xyCoordsInneri+1)for i in range(len(xyCoords

5、Outer)-1):mySketch.Line(point 1=xyCoordsOuteri,point2=xyCoords0uteri+1)myPart=myModel.Part(name=,Part A,,dimensionality=THREE_D,type=DEFORMABLE_BODY)myPart.BaseSolidExtrude(sketch=mySketch,depth=20.0)myViewport=session.Viewport(name=,Viewport for Model A,origin=(10,10),width=150,height=100)myViewpor

6、t.setValues(displayedObject=myPart)myViewport.partDisplay.setValues(renderStyle=SHADED)3.1.2 How does the script work?This section explains each portion of the example script.from abaqus import*This statement makes the basic Abaqus objects accessible to the script.It also provides access to a defaul

7、t model database using the variable named mdb.The statement,from abaqusConstants import*,makes the Symbolic Constants defined by the Abaqus Scripting Interface available to the script,import sketch import partThese statements provide access to the objects related to sketches and parts,sketch and par

8、t are cal led Python modules.The next statement in the script is shown in Figure 3-2.You can read this statement from right to left as follows:1.Create a new model named Model A.2.Store the new model in the model database mdb.3.Assign the new model to a variable called myModel.Figure 3-2 Creating a

9、new model.3.Assign a variable to the new model1.Create a new model named Model AmyModel=mdb.Model(name=1 Model A)2.Store the new model in the model database mdbmySketch=myModel.ConstrainedSketch(name=,Sketch A,sheetSize=200.0)This statement creates a new sketch object named Sketch A in myModel.The v

10、ariable mySketch is assigned to the new sketch.The sketch will be placed on a sheet 200 units square.Note the following:A command that creates something(an“object“in object-oriented programming terms)is called a constructor and starts with an uppercase character.You have seen the Model and Sketch co

11、mmands that create Model objects and Sketch objects,respectively.The command uses the variable myModel that we created in the previous statement.Using variables with meaningful names in a script makes the script easier to read and understand.xyCoordsInner=(-5,20),(5,20),(15,0),(-15,0),(-5,20)xyCoord

12、sOuter=(-10,30),(10,30),(40,-30),(30,-30),(20,-10),(-20,-10),(-30,-30),(-40,-30),(-10,30)These two statements define the X-andcoordinates of the vertices that form the inner and outer profile of the letter A.The variable xyCoordsInner refers to the vertices of the inner profile,and the variable xyCo

13、ordsOuter refers to the vertices of the outer profile,for i in range(len(xyCoordsInner)-1):mySketch.Line(pointl=xyCoordsInneri,point2=xyCoordsInneri+1)This loop creates the inner profile of the letter A in mySketch.Four lines are created using the 产 and coordinates of the vertices in xyCoordsInner t

14、o define the beginning point and the end point of each line.Note the following:Python uses only indentation to signify the start and the end of a loop.Python does not use the brackets of C and C+.The len()function returns the number of coordinate pairs in xyCoordsInnerfive in our example.The range()

15、function returns a sequence of integers.In Python,as in C and C+,the index of an array starts at zero.In our example range(4)returns 0,1,2,3.For each iteration of the loop in the example the variable i is assigned to the next value in the sequence of integers.Similarly,a second loop creates the oute

16、r profile of the A character.myPart=myModel.Part(name=,Part A,dimensionality=THREE_D,type=DEFORMABLE_BODY)This statement creates a three-dimensional,deformable part named Part A in myModel.The new part is assigned to the variable myPart.myPart.BaseSolidExtrude(sketch=mySketch,depth=20.0)This stateme

17、nt creates a base solid extrude feature in myPart by extruding mySketch through a depth of 20.0.myViewport=session.Viewport(name=,Viewport for Model A,origin=(20,20),width=150,height=100)This statement creates a new viewport named Viewport for Model A in session.The new viewport is assigned to the v

18、ariable myViewport.The origin of the viewport is at(20,20),and it has a width of 150 and a height of 100.myViewport.setValues(displayedObject=myPart)This statement tells Abaqus to display the new part,myPart,in the new viewport,myViewport.myViewport.partDisplayOptions.setValues(renderStyle=SHADED)Th

19、is statement sets the render style of the part display options in myViewport to shaded.As a result,myPart appears in the shaded render style.3.2 Reading from an output databaseThe second example shows how you can use the Abaqus Scripting Interface to read an output database,manipulate the data,and d

20、isplay the results using the Visualization module in Abaqus/CAE.The Abaqus Scripting Interface allows you to display the data even though you have not written it back to an output database.The script does the following:Opens the tutorial output database.Creates variables that refer to the first and

21、second steps in the output database.Creates variables that refer to the last frame of the first and second steps.Creates vari ables that refer to the di splacement fi eld output i n the last frame of the first and second steps.Creates variables that refer to the stress field output in the last frame

22、 of the first and second steps.Subtracts the displacement field output from the two steps and puts the result in a variable called deltaDisplacement.Subtracts the stress field output from the two steps and puts the result in a variable called deltaStress.Selects deltaDisplacement as the default defo

23、rmed variable.Selects the von Mises invariant of deltaStress as the default field output variable.Plots a contour plot of the result.The resulting contour plot is shown in Figure 3-3.Figure 3-3 The resulting contour plot.S-S/Mises(Aug:75%)+4.012e-02+3.678e-02+3.344e-02+3.01 le-02+2.677e-02+2.343e-02

24、+2.010e-02+1.676e-02+1.342e-02+1.009e-02+6.750e-03+3.414e-03+7.711e-05XStep:Session Step,Step for Viewer non-persistent fields Session FramePrimary Var:S-S?MisesDeformed Var:U-U Deformation Scale Factor:+1.000e+00Use the following commands to retrieve the script and the output databasethat is readby

25、 the script:abaqus fetch abaqus fetchjob=odbExample job=viewer_tutorial3.2.1 The example script odbExample.pyScript to open an output database,superimpose variables from the last frame of different steps,and display a contour plot of the result.from abaqus import*from abaqusConstants import*import v

26、isualizationmyViewport=session.Viewport(name=,Superposition example,origin=(10,10),width=150,height=100)#Open the tutorial output database.myOdb=visualization.openOdb(path=viewer_tutorial.odb,)#Associate the output database with the viewport.myViewport.setValues(displayedObject=myOdb)#Create variabl

27、es that refer to the first two steps.f irstStep=myOdb.stepsStep-1secondStep=myOdb.steps Step-2#Read displacement and stress data from the last frame#of the first two steps.frame1=firstStep.frames-1frame2=secondStep.frames-1displacement!=framel.fieldOutputsU,displacement2=frame2.fieldOutputsU,stressl

28、=framel.fieldOutputsS5stress2=frame2.fieldOutputsS#Find the added displacement and stress caused by the loading in the second step.deltaDisplacement=displacement2-displacement1deltaStress=stress2-stressl#Create a Mises stress contour plot of the result.myViewport.odbDisplay.setDeformedVariable(delta

29、Displacement)myViewport.odbDisplay.setPrimaryVariable(field=deltaStress,outputPosit ion=INTEGRATION_POINT,refinement=(INVARIANT,Mises)myViewport.odbDisplay.display.setValues(plotState=(CONTOURS_ON_DEF,)3.2.2 How does the script work?This section explains each portion of the example script.from abaqu

30、s import*from abaqusConstants import*These statements make the basic Abaqus objects accessible to the script as well as all the Symbolic Constants defined in the Abaqus Scripting Interface.import visualizationThis statement provides access to the commands that replicate the functionality of the Visu

31、alization module in Abaqus/CAE(Abaqus/Viewer).myViewport=session.Viewport(name=,Superposition example)This statement creates a new viewport named Superposition example in the session.The new viewport is assigned to the variable myViewport.The origin and the size of the viewport assume the default va

32、lues.odbPath=viewer_tutorial.odbThis statement creates a path to the tutorial output database.myOdb=session.openOdb(path=odbPath)This statement uses the path variable odbPath to open the output database and to assign it to the variable myOdb.myViewport.setValues(displayedObject=myOdb)This statement

33、displays the default plot of the output database in the viewport.firstStep=myOdb.stepsStep-1secondStep=myOdb.steps5 Step-25These statements assign the first and second steps in the output database to the variables firstStep and secondStep.frame1=firstStep.frames-1frame2=secondStep.frames-1These stat

34、ements assign the last frame of the first and second steps to the variables frame1 and frame2.In Python an index of 0 refers to the first item in a sequence.An index of-1 refers to the last item in a sequence.displacement!=framel.fieldOutputsUdisplacement?二 frame2.fieldOutputsU,These statements assi

35、gn the displacement field output in the last frame of the first and second steps to the variables displacement!and displacement2.stressl=framel.fieldOutputsSstress2=frame2.fieldOutputsSSimilarly,these statements assign the stress field output in the last frame of the first and second steps to the va

36、riables stressl and stress2.deltaDisplacement=displacement2-displacement1This statement subtracts the displacement field output from the last frame of the two steps and puts the resulting field output into a new variable deltaDisplacement.deltaStress=stress2-stresslSimilarly,this statement subtracts

37、 the stress field output and puts the result in the variable deltaStress.myViewport.odbDisplay.setDeformedVariable(deltaDisplacement)This statement uses deltaDisplacement,the displacement field output variable that we created earlier,to set the deformed variable.This is the variable that Abaqus will

38、 use to display the shape of the deformed model.myViewport.odbDisplay.setPrimaryVariable(field=deltaStress,outputPosition=INTEGRATION_POINT,refinement=(INVARIANT,Mises)This statement uses deltaStress,our stress field output variable,to set the primary variable.This is the variable that Abaqus will d

39、isplay in a contour or symbol plot.myViewport.odbDisplay.display.setValues(plotState=(C0NT0URS_0N_DEF,)The final statement sets the plot state to display a contour plot on the deformed model shape.3.3 SummaryThe examples illustrate how a script can operate on a model in a model database or on the da

40、ta stored in an output database.The details of the commands in the examples are described in later sections;however,you should note the following:You can run a script from the Abaqus/CAE startup screen when you start a session.After a session has started,you can run a script from the FileRun Script

41、menu or from the command line interface.A script is a sequence of commands stored in ASCII format and can be edited with a standard text editor.A set of example scripts are provided with Abaqus.Use the abaqus fetch command to retrieve a script and any associated files.You must use the import stateme

42、nt to make the required set of Abaqus Scripting Interface commands available.For example,the statement import part provides the commands that create and operate on parts.A command that creates something(an“object”in object-oriented programming terms)is called a constructor and starts with an upperca

43、se character.For example,the fol lowing statement uses the Model constructor to create a model object.myModel=mdb.Model(name=Model A)The model object created ismdb.models 5 Model A You can use a variable to refer to an object.Variables make your scripts easier to read and understand.myModel refers t

44、o a model object in the previous example.A Python script can include a loop.The start and end of a loop is controlled by indentation in the script.Python includes a set of built-in functions.For example,the len()function returns the length of a sequence.You can use commands to replicate any operation that can be performed interactively when you are working with Abaqus/CAE;for example,creating a viewport,displaying a contour plot,and setting the step and the frame to display.

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 通信科技 > 开发语言

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服