4. Scripting

The automatization suite of Mechanical also supports the scripting of the ACCS extension. The examples below show how the ACCS extension and module can be loaded into the scripting environment. Once loaded, the ACCS module can be used to activate the curing simulation, control the properties, add a support remover, add results plots etc.

_images/menu_scripting.png

Fig. 4.1 Mechanical’s Automation tab.

An alternative is to use the recording to generate the script automatically.

_images/recording_script.png

Fig. 4.2 Recording button translates the GUI actions into a script.

4.1. Documentation

This section presents the embedded help of the scripting module.

4.1.1. Project class

class ACCS_scripting.Project[source]

Project class

Class to use to script ACCS from Workbench

Note

It is important to create the instance after loading the project

CheckMaterial()[source]

Checks all materials in the project to see if they have not been imported from an earlier release.

HomogeneizeMaterial()[source]

Adds homogeneized properties for all materials which were defined via the fibre/matrix formulation.

UpgradeMaterial()[source]

Upgrades all materials that were imported from an earlier release.

4.1.2. Mechanical class

class ACCS_scripting.Mechanical(API)[source]

Mechanical class

Class to use to script ACCS from Mechanical

AddACCS(analysis)[source]

Adds the ACCS module to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultAlpha(analysis)[source]

Adds the ACCS Degree of Cure/Crystallisation result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultEpsElXX(analysis)[source]

Adds the elastic strain XX result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultEpsElXY(analysis)[source]

Adds the elastic strain XY result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultEpsElXZ(analysis)[source]

Adds the elastic strain XZ result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultEpsElYY(analysis)[source]

Adds the elastic strain YY result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultEpsElYZ(analysis)[source]

Adds the elastic strain YZ result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultEpsElZZ(analysis)[source]

Adds the elastic strain ZZ result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultEpsShXX(analysis)[source]

Adds the ACCS Cure Shrinkage XX result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultEpsShYY(analysis)[source]

Adds the ACCS Cure Shrinkage YY result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultEpsShZZ(analysis)[source]

Adds the ACCS Cure Shrinkage ZZ result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultHeat(analysis)[source]

Adds the ACCS Generated Heat result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultState(analysis)[source]

Adds the ACCS Material State result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddResultTg(analysis)[source]

Adds the ACCS Glass transition temperature/reference result to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddSupportRemover(analysis)[source]

Adds the ACCS module to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

AddSurfaceExporter(analysis)[source]

Adds the ACCS Surface Exporter module to the input analysis.

Parameters

analysis (Ansys.ACT.Automation.Mechanical.Analysis) – The analysis to which it should be added

CopyAnalysisSettings(AnalysisFrom, AnalysisTo)[source]

Copies analysis settings between two simulations.

Parameters
  • AnalysisFrom (Ansys.ACT.Automation.Mechanical.Analysis) – The source analysis

  • AnalysisTo (Ansys.ACT.Automation.Mechanical.) – The destination analysis

4.1.3. ACCSload class

class ACCS_scripting.ACCSload(load)[source]

ACCS load class

Class to use to script the ACCS load from Mechanical

setAnalysisType(t)[source]

Sets the ACCS Analysis Type.

Parameters

t (str) – The analysis type either ‘Full’ or ‘Fast’

setMRCC(steps)[source]

Sets the ACCS Cure cycle for the mechanical FAST approach.

Parameters

MRCC (list[step]) – The cure cycle shall be defined with a list of steps. A step can be defined as a Heating/Cooling step with [‘Heating Rate’, X, Y] defines a Heating/Cooling step at a rate of X C/min until reaching Y C or [‘Fixed temperature’, Z]: defines a Fixed temperature step with a duration of Z minutes.

setTvst(Tprof)[source]

Sets the ACCS Cure cycle for the mechanical FAST approach.

Parameters

Tprof (list[point]) – The cure cycle shall be defined with a list of points. [10, 120] defines a point at 10 seconds and 120 C

setViscoElasticity(v)[source]

Activates or deactivate the viscoelasticity.

Parameters

v (bool) – The viscoelasticity will be activated if True

Note

The corresponding properties do need to have been defined in Engineering Data.

4.1.4. ACCSsuprem class

class ACCS_scripting.ACCSsuprem(load)[source]

ACCS support remover class

Class to use to script the ACCS support remover from Mechanical

setStep(step)[source]

Defines when will the support remover will be active.

Parameters

step (scalar) – The step number

setSurfacesByGeoSelection(selection)[source]

Sets the surfaces where it applies via Geometry Selection.

Parameters

selection (SelectionInfo) – The selected surfaces

setSurfacesByNamedSelection(selection)[source]

Sets the surfaces where it applies via Named Selection.

Parameters

selection (NamedSelection or NamedSelection ID) – Instance or ID reference to the named selection containing the surfaces

4.1.5. ACCSsurexp class

class ACCS_scripting.ACCSsurexp(result)[source]

ACCS support remover class

Class to use to script the ACCS support remover from Mechanical

setExportPath(filepath)[source]

Sets the path to the exported path.

Parameters

filepath (string) – The full path or relative path defining where the file will be saved

setSurfacesByGeoSelection(selection)[source]

Sets the surfaces where it applies via Geometry Selection.

Parameters

selection (SelectionInfo) – The selected surfaces

setSurfacesByNamedSelection(selection)[source]

Sets the surfaces where it applies via Named Selection.

Parameters

selection (NamedSelection or NamedSelection ID) – Instance or ID reference to the named selection containing the surfaces

4.1.6. Interactive help

The user can also get help by running the help function on the different classes or the methods of the classes as illustrated in the following code.

1# Importing the scripting module
2import ACCS_scripting
3
4# Printing help for the Project class
5help(ACCS_scripting.Project)
6
7# Printing help for the AddACCS method of the Mechanical class
8help(ACCS_scripting.Mechanical.AddACCS)

4.2. Examples

The following examples are available at the following location:

%ProgramFiles%/LMAT/ACCS/v2.8_WB23.2/ScriptingDemo/

4.2.1. Full cure simulation

This example shows how a full cure simulation with a transient thermal and structural analysis can be defined via scripting. The first script (wbjn) adds the material to the WB project and the analysis systems, the second script (Python) is for Mechanical to add, configure, run, and post-process the cure simulation within Mechanical.

Download files here

Workbench journal script

**Show/Hide Code**
 1# encoding: utf-8
 2
 3Reset()
 4
 5import os
 6import re
 7
 8directory = os.path.dirname(os.path.abspath(__file__))
 9cdb = os.path.join(directory,"C-shape.cdb")
10script = os.path.join(directory,"test_scripting_full.py")
11
12
13import ACCS_scripting
14
15
16# Instantiating the project interface
17ACCS_proj = ACCS_scripting.Project()
18
19
20
21EngD_sys = GetTemplate(TemplateName="EngData").CreateSystem()
22EngD_EngD = EngD_sys.GetContainer(ComponentName="Engineering Data")
23for m in EngD_EngD.GetMaterials():
24   m.Delete()
25EngD_fav = EngData.LoadFavoriteItems()
26EngD_lib = EngData.OpenLibrary(Name="Cure Simulation",Source="ACCS_Library.xml")
27AS4 = EngD_EngD.ImportMaterial(Name="UD epoxy prepreg",Source="ACCS_Library.xml")
28AS4.SetAsDefaultSolidForModel()
29AS4.SetAsDefaultFluidForModel()
30EngD_engd = EngD_sys.GetComponent(Name="Engineering Data")
31
32
33FEM_sys = GetTemplate(TemplateName="External Model").CreateSystem(Position="Below",RelativeTo=EngD_sys)
34FEM_sys.GetContainer(ComponentName="Setup").AddDataFile(FilePath=cdb)
35FEM_setup = FEM_sys.GetComponent(Name="Setup")
36FEM_setup.Update(AllDependencies=True)
37
38
39
40MaterialReleases = ACCS_proj.CheckMaterial()
41if MaterialReleases!=None:
42   print("Materials need to be updated")
43   ACCS_proj.UpgradeMaterial()
44
45
46ACCS_proj.HomogeneizeMaterial()
47
48
49
50Th_tpl = GetTemplate(TemplateName="Transient Thermal",Solver="ANSYS")
51Full_Th_sys = Th_tpl.CreateSystem(Position="Right",RelativeTo=FEM_sys)
52Full_Th_sys.DisplayText = "Full - Transient Thermal"
53Full_Th_engd = Full_Th_sys.GetComponent(Name="Engineering Data")
54Full_Th_model = Full_Th_sys.GetComponent(Name="Model")
55Full_Th_setup = Full_Th_sys.GetContainer(ComponentName="Setup")
56Full_Th_solution = Full_Th_sys.GetComponent(Name="Solution")
57
58Full_Th_engd.ReplaceWithShare(TargetSystem=Full_Th_sys,ComponentToShare=EngD_engd,SourceSystem=EngD_sys)
59FEM_setup.TransferData(TargetComponent=Full_Th_model)
60
61
62Transfer_tpl = GetComponentTemplate(Name="SimulationSetupCellTemplate_StructuralStaticANSYS")
63St_tpl = GetTemplate(TemplateName="Static Structural",Solver="ANSYS")
64Full_St_sys = St_tpl.CreateSystem(
65   ComponentsToShare=[Full_Th_engd, Full_Th_model],
66   DataTransferFrom=[Set(FromComponent=Full_Th_solution, TransferName=None, ToComponentTemplate=Transfer_tpl)],
67   Position="Right",
68   RelativeTo=Full_Th_sys)
69Full_St_sys.DisplayText = "Full - Static Structural"
70Full_St_setup = Full_Th_sys.GetContainer(ComponentName="Setup")
71
72
73Full_Th_model.Update(AllDependencies=True)
74
75
76Full_St_setup.Edit()
77Full_St_setup.SendCommand(Command="WB.AppletList.Applet('DSApplet').App.Script.doToolsRunMacro(\""+re.escape(script)+"\")")

Mechanical journal script

**Show/Hide Code**
  1# encoding: utf-8
  2
  3import os
  4
  5directory = os.path.dirname(os.path.abspath(__file__))
  6RSO = os.path.join(directory,"C-shape.rso")
  7
  8
  9import ACCS_scripting
 10
 11
 12# Instantiating the mechanical interface
 13ACCS_mech = ACCS_scripting.Mechanical(ExtAPI)
 14
 15
 16LoadSteps = [15600, 20400, 20640]
 17CureCycle = [  [    0., 20.],
 18               [ 3000.,120.],
 19               [ 6600.,120.],
 20               [ 8400.,180.],
 21               [15600.,180.],
 22               [20400., 20.],
 23               [23000., 20.]]
 24
 25
 26part = Model.Geometry.Children[0]
 27body = part.Children[0]
 28geoBody = body.GetGeoBody()
 29
 30
 31#Adding Named Selection: Body
 32NS_body = Model.AddNamedSelection()
 33NS_body.Name = r"Body"
 34NS_body.ScopingMethod = GeometryDefineByType.Worksheet
 35NS_body.GenerationCriteria.Add(None)
 36NS_body.GenerationCriteria[0].Action = SelectionActionType.Add
 37NS_body.GenerationCriteria[0].EntityType = SelectionType.GeoBody
 38NS_body.GenerationCriteria[0].Criterion = SelectionCriterionType.Size
 39NS_body.GenerationCriteria[0].Operator = SelectionOperatorType.Largest
 40NS_body.Generate()
 41
 42#Adding Named Selection: Outer
 43NS_outer = Model.AddNamedSelection()
 44NS_outer.Name = r"Outer"
 45NS_outer.ScopingMethod = GeometryDefineByType.Worksheet
 46NS_outer.GenerationCriteria.Add(None)
 47NS_outer.GenerationCriteria[0].Action = SelectionActionType.Add
 48NS_outer.GenerationCriteria[0].EntityType = SelectionType.GeoFace
 49NS_outer.GenerationCriteria[0].Criterion = SelectionCriterionType.Size
 50NS_outer.GenerationCriteria[0].Operator = SelectionOperatorType.Largest
 51NS_outer.Generate()
 52
 53#Adding Named Selection: Inner
 54NS_inner = Model.AddNamedSelection()
 55NS_inner.Name = r"Inner"
 56NS_inner.ScopingMethod = GeometryDefineByType.Worksheet
 57NS_inner.GenerationCriteria.Add(None)
 58NS_inner.GenerationCriteria[0].Action = SelectionActionType.Add
 59NS_inner.GenerationCriteria[0].EntityType = SelectionType.GeoFace
 60NS_inner.GenerationCriteria[0].Criterion = SelectionCriterionType.Size
 61NS_inner.GenerationCriteria[0].Operator = SelectionOperatorType.RangeInclude
 62NS_inner.GenerationCriteria[0].LowerBound = Quantity(0.001, 'm m')
 63NS_inner.GenerationCriteria[0].UpperBound = Quantity(0.0015, 'm m')
 64NS_inner.Generate()
 65
 66#Adding Named Selection: Edge
 67NS_edge = Model.AddNamedSelection()
 68NS_edge.Name = r"Edge"
 69NS_edge.ScopingMethod = GeometryDefineByType.Worksheet
 70NS_edge.GenerationCriteria.Add(None)
 71NS_edge.GenerationCriteria[0].Action = SelectionActionType.Add
 72NS_edge.GenerationCriteria[0].EntityType = SelectionType.GeoEdge
 73NS_edge.GenerationCriteria[0].Criterion = SelectionCriterionType.LocationZ
 74NS_edge.GenerationCriteria[0].Operator = SelectionOperatorType.LessThan
 75NS_edge.GenerationCriteria[0].Value = Quantity(0.001, 'm')
 76NS_edge.GenerationCriteria.Add(None)
 77NS_edge.GenerationCriteria[1].Action = SelectionActionType.Filter
 78NS_edge.GenerationCriteria[1].EntityType = SelectionType.GeoEdge
 79NS_edge.GenerationCriteria[1].Criterion = SelectionCriterionType.Size
 80NS_edge.GenerationCriteria[1].Operator = SelectionOperatorType.RangeInclude
 81NS_edge.GenerationCriteria[1].LowerBound = Quantity(0.05, 'm')
 82NS_edge.GenerationCriteria[1].UpperBound = Quantity(0.06, 'm')
 83NS_edge.Generate()
 84
 85#Adding Named Selection: DX
 86NS_DX = Model.AddNamedSelection()
 87NS_DX.Name = r"DX"
 88NS_DX.ScopingMethod = GeometryDefineByType.Worksheet
 89NS_DX.GenerationCriteria.Add(None)
 90NS_DX.GenerationCriteria[0].Action = SelectionActionType.Add
 91NS_DX.GenerationCriteria[0].EntityType = SelectionType.GeoVertex
 92NS_DX.GenerationCriteria[0].Criterion = SelectionCriterionType.LocationX
 93NS_DX.GenerationCriteria[0].Operator = SelectionOperatorType.Smallest
 94NS_DX.GenerationCriteria.Add(None)
 95NS_DX.GenerationCriteria[1].Action = SelectionActionType.Filter
 96NS_DX.GenerationCriteria[1].EntityType = SelectionType.GeoVertex
 97NS_DX.GenerationCriteria[1].Criterion = SelectionCriterionType.LocationZ
 98NS_DX.GenerationCriteria[1].Operator = SelectionOperatorType.Smallest
 99NS_DX.Generate()
100
101#Adding Named Selection: DY
102NS_DY = Model.AddNamedSelection()
103NS_DY.Name = r"DY"
104NS_DY.ScopingMethod = GeometryDefineByType.Worksheet
105NS_DY.GenerationCriteria.Add(None)
106NS_DY.GenerationCriteria[0].Action = SelectionActionType.Add
107NS_DY.GenerationCriteria[0].EntityType = SelectionType.GeoFace
108NS_DY.GenerationCriteria[0].Criterion = SelectionCriterionType.Size
109NS_DY.GenerationCriteria[0].Operator = SelectionOperatorType.Smallest
110NS_DY.GenerationCriteria.Add(None)
111NS_DY.GenerationCriteria[1].Action = SelectionActionType.Filter
112NS_DY.GenerationCriteria[1].EntityType = SelectionType.GeoFace
113NS_DY.GenerationCriteria[1].Criterion = SelectionCriterionType.LocationX
114NS_DY.GenerationCriteria[1].Operator = SelectionOperatorType.LessThan
115NS_DY.GenerationCriteria[1].Value = Quantity(0.005, 'm')
116NS_DY.Generate()
117
118#Adding Named Selection: DZ
119NS_DZ = Model.AddNamedSelection()
120NS_DZ.Name = r"DZ"
121NS_DZ.ScopingMethod = GeometryDefineByType.Worksheet
122NS_DZ.GenerationCriteria.Add(None)
123NS_DZ.GenerationCriteria[0].Action = SelectionActionType.Add
124NS_DZ.GenerationCriteria[0].EntityType = SelectionType.GeoFace
125NS_DZ.GenerationCriteria[0].Criterion = SelectionCriterionType.LocationZ
126NS_DZ.GenerationCriteria[0].Operator = SelectionOperatorType.Smallest
127NS_DZ.Generate()
128
129
130#Adding element orientation
131EO = Model.Geometry.AddElementOrientation()
132EO.BodyLocation = NS_body
133EO.SurfaceLocation = NS_inner
134EO.EdgeLocation = NS_edge
135EO.AxisEdgeOrientation = EO.AxisEdgeOrientation.NegativeXAxis
136
137
138
139
140###############################################################
141#
142#              THERMAL ANALYSIS
143#
144###############################################################
145
146TH_analysis = Model.Analyses[0]
147TH_solution = TH_analysis.Solution
148
149
150TH_analysis.InitialConditions[0].InitialTemperatureValue = Quantity(20,'C')
151
152
153AS = TH_analysis.AnalysisSettings
154AS.NumberOfSteps = len(LoadSteps)
155for CSN in range(len(LoadSteps),0,-1):
156   AS.SetStepEndTime(CSN, Quantity(LoadSteps[CSN-1], "sec"))
157   AS.SetAutomaticTimeStepping(CSN, AutomaticTimeStepping.On)
158   AS.SetCarryOverTimeStep(CSN, AutomaticTimeStepping.On)
159   AS.SetInitialTimeStep(CSN, Quantity(120, "sec"))
160   AS.SetMinimumTimeStep(CSN, Quantity( 60, "sec"))
161   AS.SetMaximumTimeStep(CSN, Quantity(240, "sec"))
162
163
164conv = TH_analysis.AddConvection()
165conv.Location = NS_inner
166conv.FilmCoefficient.Output.DiscreteValues = [Quantity(10, "W m^-1 m^-1 C^-1")]
167conv.AmbientTemperature.Inputs[0].DiscreteValues = [Quantity(t[0], "s") for t in CureCycle]
168conv.AmbientTemperature.Output.DiscreteValues = [Quantity(t[1], "C") for t in CureCycle]
169
170
171TH_ACCS_ld = ACCS_mech.AddACCS(TH_analysis)
172
173
174TH_temp = TH_solution.AddTemperature()
175
176TH_ACCS_res_state = ACCS_mech.AddResultState(TH_analysis)
177TH_ACCS_res_alpha = ACCS_mech.AddResultAlpha(TH_analysis)
178TH_ACCS_res_Tg = ACCS_mech.AddResultTg(TH_analysis)
179TH_ACCS_res_qdot = ACCS_mech.AddResultHeat(TH_analysis)
180
181
182TH_solution.Solve(True)
183
184
185
186
187###############################################################
188#
189#              STRUCTURAL ANALYSIS
190#
191###############################################################
192
193ST_analysis = Model.Analyses[1]
194ST_solution = ST_analysis.Solution
195
196
197ACCS_mech.CopyAnalysisSettings(TH_analysis, ST_analysis)
198
199
200ST_importedload = ST_analysis.GetChildren(DataModelObjectCategory.ImportedBodyTemperature, True)[0]
201ST_importedload.PropertyByName('PROPID_AnalysisTimeDefinition').InternalValue = 0
202
203
204ST_frictionless = ST_analysis.AddFrictionlessSupport()
205ST_frictionless.Location = NS_inner
206
207ST_DX = ST_analysis.AddDisplacement()
208ST_DX.Location = NS_DX
209ST_DX.PropertyByName('ComponentX').InternalValue = 0
210for CSN in range(0,len(LoadSteps)-1,+1):
211   ST_DX.SetActivateAtLoadStep(CSN+1,False)
212for CSN in range(len(LoadSteps)-1,len(LoadSteps),+1):
213   ST_DX.SetActivateAtLoadStep(CSN+1,True)
214ST_DX.Name = NS_DX.Name
215
216
217ST_DY = ST_analysis.AddDisplacement()
218ST_DY.Location = NS_DY
219ST_DY.PropertyByName('ComponentY').InternalValue = 0
220ST_DY.Name = NS_DY.Name
221
222ST_DZ = ST_analysis.AddDisplacement()
223ST_DZ.Location = NS_DZ
224ST_DZ.PropertyByName('ComponentZ').InternalValue = 0
225ST_DZ.Name = NS_DZ.Name
226
227
228ST_ACCS_ld = ACCS_mech.AddACCS(ST_analysis)
229ST_ACCS_ld.setAnalysisType('Full')
230ST_ACCS_ld.setViscoElasticity('Disabled')
231
232
233ST_ACCS_suprem = ACCS_mech.AddSupportRemover(ST_analysis)
234ST_ACCS_suprem.setSurfacesByNamedSelection(NS_inner)
235ST_ACCS_suprem.setStep(str(len(LoadSteps)))
236
237
238ST_ACCS_surexp = ACCS_mech.AddSurfaceExporter(ST_analysis)
239ST_ACCS_surexp.setSurfacesByNamedSelection(NS_outer)
240ST_ACCS_surexp.setExportPath(RSO)
241
242
243ST_TOTDEF = ST_solution.AddTotalDeformation()
244
245ST_EPTHXX = ST_solution.AddThermalStrain()
246ST_EPTHXX.NormalOrientation = NormalOrientationType.XAxis
247ST_EPTHXX.Name = 'EPTHXX'
248
249ST_EPTHYY = ST_solution.AddThermalStrain()
250ST_EPTHYY.NormalOrientation = NormalOrientationType.YAxis
251ST_EPTHYY.Name = 'EPTHYY'
252
253ST_EPTHZZ = ST_solution.AddThermalStrain()
254ST_EPTHZZ.NormalOrientation = NormalOrientationType.ZAxis
255ST_EPTHZZ.Name = 'EPTHZZ'
256
257ST_ACCS_res_state = ACCS_mech.AddResultState(ST_analysis)
258ST_ACCS_res_alpha = ACCS_mech.AddResultAlpha(ST_analysis)
259ST_ACCS_res_Tg = ACCS_mech.AddResultTg(ST_analysis)
260ST_ACCS_res_qdot = ACCS_mech.AddResultHeat(ST_analysis)
261
262ST_ACCS_res_EpsShXX = ACCS_mech.AddResultEpsShXX(ST_analysis)
263ST_ACCS_res_EpsShYY = ACCS_mech.AddResultEpsShYY(ST_analysis)
264ST_ACCS_res_EpsShZZ = ACCS_mech.AddResultEpsShZZ(ST_analysis)
265
266ST_ACCS_res_EpsElXX = ACCS_mech.AddResultEpsElXX(ST_analysis)
267ST_ACCS_res_EpsElYY = ACCS_mech.AddResultEpsElYY(ST_analysis)
268ST_ACCS_res_EpsElZZ = ACCS_mech.AddResultEpsElZZ(ST_analysis)
269ST_ACCS_res_EpsElXY = ACCS_mech.AddResultEpsElXY(ST_analysis)
270ST_ACCS_res_EpsElYZ = ACCS_mech.AddResultEpsElYZ(ST_analysis)
271ST_ACCS_res_EpsElXZ = ACCS_mech.AddResultEpsElXZ(ST_analysis)
272
273
274ST_solution.Solve(wait=True)
275

4.2.2. Fast cure simulation via MRCC

This example shows how a fast cure simulation with a three-step structural analysis can be defined via scripting. The first script (wbjn) adds the material to the WB project and the analysis system, the second script (Python) is for Mechanical to add, configure, run, and post-process the cure simulation within Mechanical. The cure cycle is defined by the manufacturer recommended cure-cycle (heat rate, and dwell times).

Download files here

Workbench journal script

**Show/Hide Code**
 1# encoding: utf-8
 2
 3Reset()
 4
 5import os
 6import re
 7
 8directory = os.path.dirname(os.path.abspath(__file__))
 9cdb = os.path.join(directory,"C-shape.cdb")
10script = os.path.join(directory,"test_scripting_fast_MRCC.py")
11
12
13import ACCS_scripting
14
15
16# Instantiating the project interface
17ACCS_proj = ACCS_scripting.Project()
18
19
20
21EngD_sys = GetTemplate(TemplateName="EngData").CreateSystem()
22EngD_EngD = EngD_sys.GetContainer(ComponentName="Engineering Data")
23for m in EngD_EngD.GetMaterials():
24   m.Delete()
25EngD_fav = EngData.LoadFavoriteItems()
26EngD_lib = EngData.OpenLibrary(Name="Cure Simulation",Source="ACCS_Library.xml")
27AS4 = EngD_EngD.ImportMaterial(Name="UD epoxy prepreg",Source="ACCS_Library.xml")
28AS4.SetAsDefaultSolidForModel()
29AS4.SetAsDefaultFluidForModel()
30EngD_engd = EngD_sys.GetComponent(Name="Engineering Data")
31
32
33FEM_sys = GetTemplate(TemplateName="External Model").CreateSystem(Position="Below",RelativeTo=EngD_sys)
34FEM_sys.GetContainer(ComponentName="Setup").AddDataFile(FilePath=cdb)
35FEM_setup = FEM_sys.GetComponent(Name="Setup")
36FEM_setup.Update(AllDependencies=True)
37
38
39
40MaterialReleases = ACCS_proj.CheckMaterial()
41if MaterialReleases!=None:
42   print("Materials need to be updated")
43   ACCS_proj.UpgradeMaterial()
44
45
46ACCS_proj.HomogeneizeMaterial()
47
48
49
50St_tpl = GetTemplate(TemplateName="Static Structural",Solver="ANSYS")
51Fast_MRCC_sys = St_tpl.CreateSystem(Position="Right",RelativeTo=FEM_sys)
52Fast_MRCC_sys.DisplayText = "Fast MRCC - Static Structural"
53Fast_MRCC_engd = Fast_MRCC_sys.GetComponent(Name="Engineering Data")
54Fast_MRCC_model = Fast_MRCC_sys.GetComponent(Name="Model")
55Fast_MRCC_setup = Fast_MRCC_sys.GetContainer(ComponentName="Setup")
56
57Fast_MRCC_engd.ReplaceWithShare(TargetSystem=Fast_MRCC_sys,ComponentToShare=EngD_engd,SourceSystem=EngD_sys)
58FEM_setup.TransferData(TargetComponent=Fast_MRCC_model)
59
60
61Fast_MRCC_model.Update(AllDependencies=True)
62
63
64Fast_MRCC_setup.Edit()
65Fast_MRCC_setup.SendCommand(Command="WB.AppletList.Applet('DSApplet').App.Script.doToolsRunMacro(\""+re.escape(script)+"\")")

Mechanical journal script

**Show/Hide Code**
 1# encoding: utf-8
 2
 3Reset()
 4
 5import os
 6import re
 7
 8directory = os.path.dirname(os.path.abspath(__file__))
 9cdb = os.path.join(directory,"C-shape.cdb")
10script = os.path.join(directory,"test_scripting_fast_MRCC.py")
11
12
13import ACCS_scripting
14
15
16# Instantiating the project interface
17ACCS_proj = ACCS_scripting.Project()
18
19
20
21EngD_sys = GetTemplate(TemplateName="EngData").CreateSystem()
22EngD_EngD = EngD_sys.GetContainer(ComponentName="Engineering Data")
23for m in EngD_EngD.GetMaterials():
24   m.Delete()
25EngD_fav = EngData.LoadFavoriteItems()
26EngD_lib = EngData.OpenLibrary(Name="Cure Simulation",Source="ACCS_Library.xml")
27AS4 = EngD_EngD.ImportMaterial(Name="UD epoxy prepreg",Source="ACCS_Library.xml")
28AS4.SetAsDefaultSolidForModel()
29AS4.SetAsDefaultFluidForModel()
30EngD_engd = EngD_sys.GetComponent(Name="Engineering Data")
31
32
33FEM_sys = GetTemplate(TemplateName="External Model").CreateSystem(Position="Below",RelativeTo=EngD_sys)
34FEM_sys.GetContainer(ComponentName="Setup").AddDataFile(FilePath=cdb)
35FEM_setup = FEM_sys.GetComponent(Name="Setup")
36FEM_setup.Update(AllDependencies=True)
37
38
39
40MaterialReleases = ACCS_proj.CheckMaterial()
41if MaterialReleases!=None:
42   print("Materials need to be updated")
43   ACCS_proj.UpgradeMaterial()
44
45
46ACCS_proj.HomogeneizeMaterial()
47
48
49
50St_tpl = GetTemplate(TemplateName="Static Structural",Solver="ANSYS")
51Fast_MRCC_sys = St_tpl.CreateSystem(Position="Right",RelativeTo=FEM_sys)
52Fast_MRCC_sys.DisplayText = "Fast MRCC - Static Structural"
53Fast_MRCC_engd = Fast_MRCC_sys.GetComponent(Name="Engineering Data")
54Fast_MRCC_model = Fast_MRCC_sys.GetComponent(Name="Model")
55Fast_MRCC_setup = Fast_MRCC_sys.GetContainer(ComponentName="Setup")
56
57Fast_MRCC_engd.ReplaceWithShare(TargetSystem=Fast_MRCC_sys,ComponentToShare=EngD_engd,SourceSystem=EngD_sys)
58FEM_setup.TransferData(TargetComponent=Fast_MRCC_model)
59
60
61Fast_MRCC_model.Update(AllDependencies=True)
62
63
64Fast_MRCC_setup.Edit()
65Fast_MRCC_setup.SendCommand(Command="WB.AppletList.Applet('DSApplet').App.Script.doToolsRunMacro(\""+re.escape(script)+"\")")

4.2.3. Fast cure simulation via T vs t

This example shows how a fast cure simulation with a three-step structural analysis can be defined via scripting. The first script (wbjn) adds the material to the WB project and the analysis system, the second script (Python) is for Mechanical to add, configure, run, and post-process the cure simulation within Mechanical. The cure cycle is defined by the temperature versus time curve.

Download files here

Workbench journal script

**Show/Hide Code**
 1# encoding: utf-8
 2
 3Reset()
 4
 5import os
 6import re
 7
 8directory = os.path.dirname(os.path.abspath(__file__))
 9cdb = os.path.join(directory,"C-shape.cdb")
10script = os.path.join(directory,"test_scripting_fast_Tvst.py")
11
12
13import ACCS_scripting
14
15
16# Instantiating the project interface
17ACCS_proj = ACCS_scripting.Project()
18
19
20
21EngD_sys = GetTemplate(TemplateName="EngData").CreateSystem()
22EngD_EngD = EngD_sys.GetContainer(ComponentName="Engineering Data")
23for m in EngD_EngD.GetMaterials():
24   m.Delete()
25EngD_fav = EngData.LoadFavoriteItems()
26EngD_lib = EngData.OpenLibrary(Name="Cure Simulation",Source="ACCS_Library.xml")
27AS4 = EngD_EngD.ImportMaterial(Name="UD epoxy prepreg",Source="ACCS_Library.xml")
28AS4.SetAsDefaultSolidForModel()
29AS4.SetAsDefaultFluidForModel()
30EngD_engd = EngD_sys.GetComponent(Name="Engineering Data")
31
32
33FEM_sys = GetTemplate(TemplateName="External Model").CreateSystem(Position="Below",RelativeTo=EngD_sys)
34FEM_sys.GetContainer(ComponentName="Setup").AddDataFile(FilePath=cdb)
35FEM_setup = FEM_sys.GetComponent(Name="Setup")
36FEM_setup.Update(AllDependencies=True)
37
38
39
40MaterialReleases = ACCS_proj.CheckMaterial()
41if MaterialReleases!=None:
42   print("Materials need to be updated")
43   ACCS_proj.UpgradeMaterial()
44
45
46ACCS_proj.HomogeneizeMaterial()
47
48
49
50St_tpl = GetTemplate(TemplateName="Static Structural",Solver="ANSYS")
51Fast_Tvst_sys = St_tpl.CreateSystem(Position="Right",RelativeTo=FEM_sys)
52Fast_Tvst_sys.DisplayText = "Fast T vs t - Static Structural"
53Fast_Tvst_engd = Fast_Tvst_sys.GetComponent(Name="Engineering Data")
54Fast_Tvst_model = Fast_Tvst_sys.GetComponent(Name="Model")
55Fast_Tvst_setup = Fast_Tvst_sys.GetContainer(ComponentName="Setup")
56
57Fast_Tvst_engd.ReplaceWithShare(TargetSystem=Fast_Tvst_sys,ComponentToShare=EngD_engd,SourceSystem=EngD_sys)
58FEM_setup.TransferData(TargetComponent=Fast_Tvst_model)
59
60
61Fast_Tvst_model.Update(AllDependencies=True)
62
63
64Fast_Tvst_setup.Edit()
65Fast_Tvst_setup.SendCommand(Command="WB.AppletList.Applet('DSApplet').App.Script.doToolsRunMacro(\""+re.escape(script)+"\")")

Mechanical journal script

**Show/Hide Code**
 1# encoding: utf-8
 2
 3Reset()
 4
 5import os
 6import re
 7
 8directory = os.path.dirname(os.path.abspath(__file__))
 9cdb = os.path.join(directory,"C-shape.cdb")
10script = os.path.join(directory,"test_scripting_fast_Tvst.py")
11
12
13import ACCS_scripting
14
15
16# Instantiating the project interface
17ACCS_proj = ACCS_scripting.Project()
18
19
20
21EngD_sys = GetTemplate(TemplateName="EngData").CreateSystem()
22EngD_EngD = EngD_sys.GetContainer(ComponentName="Engineering Data")
23for m in EngD_EngD.GetMaterials():
24   m.Delete()
25EngD_fav = EngData.LoadFavoriteItems()
26EngD_lib = EngData.OpenLibrary(Name="Cure Simulation",Source="ACCS_Library.xml")
27AS4 = EngD_EngD.ImportMaterial(Name="UD epoxy prepreg",Source="ACCS_Library.xml")
28AS4.SetAsDefaultSolidForModel()
29AS4.SetAsDefaultFluidForModel()
30EngD_engd = EngD_sys.GetComponent(Name="Engineering Data")
31
32
33FEM_sys = GetTemplate(TemplateName="External Model").CreateSystem(Position="Below",RelativeTo=EngD_sys)
34FEM_sys.GetContainer(ComponentName="Setup").AddDataFile(FilePath=cdb)
35FEM_setup = FEM_sys.GetComponent(Name="Setup")
36FEM_setup.Update(AllDependencies=True)
37
38
39
40MaterialReleases = ACCS_proj.CheckMaterial()
41if MaterialReleases!=None:
42   print("Materials need to be updated")
43   ACCS_proj.UpgradeMaterial()
44
45
46ACCS_proj.HomogeneizeMaterial()
47
48
49
50St_tpl = GetTemplate(TemplateName="Static Structural",Solver="ANSYS")
51Fast_Tvst_sys = St_tpl.CreateSystem(Position="Right",RelativeTo=FEM_sys)
52Fast_Tvst_sys.DisplayText = "Fast T vs t - Static Structural"
53Fast_Tvst_engd = Fast_Tvst_sys.GetComponent(Name="Engineering Data")
54Fast_Tvst_model = Fast_Tvst_sys.GetComponent(Name="Model")
55Fast_Tvst_setup = Fast_Tvst_sys.GetContainer(ComponentName="Setup")
56
57Fast_Tvst_engd.ReplaceWithShare(TargetSystem=Fast_Tvst_sys,ComponentToShare=EngD_engd,SourceSystem=EngD_sys)
58FEM_setup.TransferData(TargetComponent=Fast_Tvst_model)
59
60
61Fast_Tvst_model.Update(AllDependencies=True)
62
63
64Fast_Tvst_setup.Edit()
65Fast_Tvst_setup.SendCommand(Command="WB.AppletList.Applet('DSApplet').App.Script.doToolsRunMacro(\""+re.escape(script)+"\")")

4.3. Running the solver

It is also possible to run directly an input file generated by Mechanical using the ACCS integration in the ANSYS solver. To do so, one should use the cbatch files stored in the following directory:

On Windows: > %ProgramFiles%\LMAT\ACCS\v2.8_WB23.2\UPFs\

Two scripts are available:

RunACCS_FULL.bat

Run the input file using the FULL approach

RunACCS_FAST.bat

Run the input file using the FAST approach

They both accept every options the ANSYS solver accepts. Please refer to the ANSYS manual for more information regarding how to run the ANSYS solver.

On Windows, a complete example for the FULL approach wih would be the following:

1"%ProgramFiles%\LMAT\ACCS\v2.8_WB23.2\UPFs\RunACCS_FULL.bat" ^
2   -p ansys -s noread -l en-us -t -d win32 -b nolist ^
3   -smp -np4 ^
4   -dir "%CD%" ^
5   -j "jobname" ^
6   -i "%CD%\inputfile.inp" ^
7   -o "%CD%\logfile.out"