2. 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. 2.1 Mechanical’s Automation tab.

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

_images/recording_script.png

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

2.1. Documentation

This section presents the embedded help of the scripting module.

2.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.

2.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

AddInistateImporter(analysis)[source]

Adds the ACCS Inistate Importer module to the input analysis.

Parameters:

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

AddRTMFlowRateInlet(analysis)[source]

Adds the ACCS RTM Flow Rate Inlet Load to the input analysis.

Parameters:

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

AddRTMOutlet(analysis)[source]

Adds the ACCS RTM Pressure Inlet Load to the input analysis.

Parameters:

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

AddRTMPressureInlet(analysis)[source]

Adds the ACCS RTM Pressure Inlet Load to the input analysis.

Parameters:

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

AddRTMResultBC(analysis)[source]

Adds the RTM BC result to the input analysis.

Parameters:

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

AddRTMResultDegreeOfCure(analysis)[source]

Adds the RTM Degree Of Cure result to the input analysis.

Parameters:

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

AddRTMResultEntrapment(analysis)[source]

Adds the RTM Entrapment result to the input analysis.

Parameters:

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

AddRTMResultExport(analysis)[source]

Adds the RTM Result Export result to the input analysis.

Parameters:

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

AddRTMResultFill(analysis)[source]

Adds the RTM Fill result to the input analysis.

Parameters:

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

AddRTMResultFlowRate(analysis)[source]

Adds the RTM Flow Rate result to the input analysis.

Parameters:

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

AddRTMResultGateOpenTime(analysis)[source]

Adds the RTM Gate Open Time result to the input analysis.

Parameters:

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

AddRTMResultImport(analysis)[source]

Adds the ACCS RTM Result Import Load to the input analysis.

Parameters:

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

AddRTMResultInfusionTime(analysis)[source]

Adds the RTM Infusion Time result to the input analysis.

Parameters:

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

AddRTMResultPressure(analysis)[source]

Adds the RTM Pressure result to the input analysis.

Parameters:

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

AddRTMResultResinState(analysis)[source]

Adds the RTM Resin State result to the input analysis.

Parameters:

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

AddRTMResultTG(analysis)[source]

Adds the RTM TG result to the input analysis.

Parameters:

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

AddRTMResultTempBC(analysis)[source]

Adds the RTM Temp BC result to the input analysis.

Parameters:

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

AddRTMResultTemperature(analysis)[source]

Adds the RTM Temperature result to the input analysis.

Parameters:

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

AddRTMResultVelocity(analysis)[source]

Adds the RTM Velocity result to the input analysis.

Parameters:

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

AddRTMResultVelocityX(analysis)[source]

Adds the RTM Velocity X result to the input analysis.

Parameters:

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

AddRTMResultVelocityY(analysis)[source]

Adds the RTM Velocity Y result to the input analysis.

Parameters:

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

AddRTMResultVelocityZ(analysis)[source]

Adds the RTM Velocity Z result to the input analysis.

Parameters:

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

AddRTMResultViscosity(analysis)[source]

Adds the RTM Viscosity result to the input analysis.

Parameters:

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

AddRTMResultdV_Cure(analysis)[source]

Adds the RTM Cure Shrinkage result to the input analysis.

Parameters:

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

AddRTMResultdV_Thermal(analysis)[source]

Adds the RTM Thermal Expansion result to the input analysis.

Parameters:

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

AddRTMResultdV_Total(analysis)[source]

Adds the RTM Total Volume Change result to the input analysis.

Parameters:

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

AddRTMThermalImport(analysis)[source]

Adds the ACCS RTM Thermal Import Load 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.Analysis) – The destination analysis

changeRTMSolverSetting(analysis, property_name=None, property_value=None, result_only=False)[source]

Copies analysis settings between two simulations.

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

  • property_name (String) – Name of the solver property that is to be changed.

  • property_value (String) – The new value of the selected solver property.

  • result_only (Boolean) – Defines if the solver is result only.

2.1.3. ACCSload class

class ACCS_scripting.ACCSload(uObj, tObj)[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.

2.1.4. ACCSsuprem class

class ACCS_scripting.ACCSsuprem(uObj, tObj)[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

2.1.5. ACCSsurexp class

class ACCS_scripting.ACCSsurexp(uObj, tObj)[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

2.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)

2.2. Examples

The following examples are available at the following location:

%ProgramFiles%/LMAT/ACCS/v3.2hf1_WB25.2/ScriptingDemo/

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

Mechanical journal script

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

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

Mechanical journal script

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

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

Mechanical journal script

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

2.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\v3.2hf1_WB25.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\v3.2hf1_WB25.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"