2. Scripting¶
2.1. Documentation¶
For code documentation see Scripting.
2.2. Examples¶
The following RTM specific 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 infusion simulation with a transient thermal and ACCS RTM Solver analysis can be defined via scripting.
Workbench journal script¶
**Show/Hide Code**
1# encoding: utf-8
2
3Reset()
4
5
6import os
7import re
8import json
9
10fpath = os.path.abspath(__file__)
11
12cdb = fpath.replace(".wbjn", ".cdb")
13wbpyTH = fpath.replace(".wbjn", "_th.py")
14wbpyRTM = fpath.replace(".wbjn", "_rtm.py")
15
16
17# Importing the scripting module
18import ACCS_scripting
19
20
21# Instantiating the project interface
22ACCS_proj = ACCS_scripting.Project()
23
24
25EngD_sys = GetTemplate(TemplateName="EngData").CreateSystem()
26EngD_EngD = EngD_sys.GetContainer(ComponentName="Engineering Data")
27for m in EngD_EngD.GetMaterials():
28 m.Delete()
29EngD_lib = EngData.OpenLibrary(Name="Cure Simulation", Source="ACCS_Library.xml")
30matname = [c.Name for c in EngD_lib.GetMaterials() if c.Name in ["RTM Fabric"]]
31RTMFab = EngD_EngD.ImportMaterial(Name=matname[0], Source="ACCS_Library.xml")
32RTMFab.SetAsDefaultSolidForModel()
33RTMFab.SetAsDefaultFluidForModel()
34matname = [
35 c.Name
36 for c in EngD_lib.GetMaterials()
37 if c.Name in ["RTM Resin with cure dependent viscosity"]
38]
39RTMRes = EngD_EngD.ImportMaterial(Name=matname[0], Source="ACCS_Library.xml")
40EngD_engd = EngD_sys.GetComponent(Name="Engineering Data")
41
42
43FEM_sys = GetTemplate(TemplateName="External Model").CreateSystem(
44 Position="Below", RelativeTo=EngD_sys
45)
46FEM_sys.GetContainer(ComponentName="Setup").AddDataFile(FilePath=cdb)
47FEM_setup = FEM_sys.GetComponent(Name="Setup")
48FEM_setup.Update(AllDependencies=True)
49
50
51Thermal_tpl = GetTemplate(TemplateName="Transient Thermal", Solver="ANSYS")
52Thermal_sys = Thermal_tpl.CreateSystem(Position="Right", RelativeTo=FEM_sys)
53Thermal_engd = Thermal_sys.GetComponent(Name="Engineering Data")
54Thermal_model = Thermal_sys.GetComponent(Name="Model")
55Thermal_setup = Thermal_sys.GetContainer(ComponentName="Setup")
56Thermal_solution = Thermal_sys.GetComponent(Name="Solution")
57
58Thermal_engd.ReplaceWithShare(
59 TargetSystem=Thermal_sys, ComponentToShare=EngD_engd, SourceSystem=EngD_sys
60)
61FEM_setup.TransferData(TargetComponent=Thermal_model)
62
63
64ACCSRTM_sys = ACCS_proj.CreateRTMSystem(
65 GetAllVisibleTemplates, Position="Right", RelativeTo=Thermal_sys
66)
67ACCSRTM_engd = ACCSRTM_sys.GetComponent(Name="Engineering Data")
68ACCSRTM_model = ACCSRTM_sys.GetComponent(Name="Model")
69ACCSRTM_setup = ACCSRTM_sys.GetContainer(ComponentName="Setup")
70ACCSRTM_solution = ACCSRTM_sys.GetComponent(Name="Solution")
71
72Thermal_model.TransferData(TargetComponent=ACCSRTM_model)
73
74
75Thermal_model.Update(AllDependencies=True)
76ACCSRTM_model.Update(AllDependencies=True)
77
78
79Thermal_setup.Edit()
80Thermal_setup.SendCommand(
81 Command="WB.AppletList.Applet('DSApplet').App.Script.doToolsRunMacro("
82 + json.dumps(wbpyTH)
83 + ")"
84)
85Thermal_setup.Exit()
86
87
88ACCSRTM_setup.Edit()
89ACCSRTM_setup.SendCommand(
90 Command="WB.AppletList.Applet('DSApplet').App.Script.doToolsRunMacro("
91 + json.dumps(wbpyRTM)
92 + ")"
93)
Thermal Mechanical journal script¶
**Show/Hide Code**
1# encoding: utf-8
2
3Graphics.Camera.SetFit()
4Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso)
5
6
7import ACCS_scripting
8
9# Instantiating the mechanical interface
10ACCS_mech = ACCS_scripting.Mechanical(ExtAPI)
11
12
13LoadSteps = [100]
14CureCycle = [
15 [0.0, 22.0],
16 [20.0, 100.0],
17 [100.0, 120.0],
18]
19
20
21part = Model.Geometry.Children[0]
22body = part.Children[0]
23geoBody = body.GetGeoBody()
24
25
26sortedareas = [
27 i[0]
28 for i in sorted(
29 enumerate([t.Centroid[2] for t in geoBody.Faces]), key=lambda x: x[1]
30 )
31]
32
33
34# Selection: Body
35S_body = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
36S_body.Ids = [geoBody.Id]
37
38# Selection: top
39S_top = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
40S_top.Ids = [geoBody.Faces[sortedareas[-1]].Id]
41
42# Selection: Edge
43S_edge = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
44S_edge.Ids = [
45 t.Id for t in geoBody.Edges if (t.Centroid[2] < 0.001) and (t.Centroid[1] < 0.001)
46]
47
48
49# Adding element orientation
50# EO = Model.Geometry.AddElementOrientation()
51# EO.BodyLocation = S_body
52# EO.SurfaceLocation = S_top
53# EO.EdgeLocation = S_edge
54# EO.AxisEdgeOrientation = EO.AxisEdgeOrientation.NegativeXAxis
55
56
57###############################################################
58#
59# THERMAL ANALYSIS
60#
61###############################################################
62
63TH_analysis = None
64for a in Model.Analyses:
65 if a.PhysicsType.ToString() == "Thermal":
66 TH_analysis = a
67 break
68TH_solution = TH_analysis.Solution
69
70
71TH_analysis.InitialConditions[0].InitialTemperatureValue = Quantity(
72 CureCycle[0][1], "C"
73)
74
75
76AS = TH_analysis.AnalysisSettings
77AS.NumberOfSteps = len(LoadSteps)
78for CSN in range(len(LoadSteps), 0, -1):
79 AS.SetStepEndTime(CSN, Quantity(LoadSteps[CSN - 1], "sec"))
80 AS.SetAutomaticTimeStepping(CSN, AutomaticTimeStepping.On)
81 AS.SetCarryOverTimeStep(CSN, True)
82 AS.SetDefineBy(CSN, TimeStepDefineByType.Time)
83 AS.SetInitialTimeStep(CSN, Quantity(1, "sec"))
84 AS.SetMinimumTimeStep(CSN, Quantity(1.0e-3, "sec"))
85 AS.SetMaximumTimeStep(CSN, Quantity(1, "sec"))
86
87
88temp = TH_analysis.AddTemperature()
89temp.Location = S_top
90temp.Magnitude.Inputs[0].DiscreteValues = [Quantity(t[0], "s") for t in CureCycle]
91temp.Magnitude.Output.DiscreteValues = [Quantity(t[1], "C") for t in CureCycle]
92
93
94TH_temp = TH_solution.AddTemperature()
95
96
97TH_solution.Solve(True)
RTM Mechanical journal script¶
**Show/Hide Code**
1# encoding: utf-8
2import os
3import shutil
4
5fpath = os.path.abspath(__file__)
6directory = os.path.dirname(fpath)
7
8Graphics.Camera.SetFit()
9Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso)
10
11
12import ACCS_scripting
13
14# Instantiating the mechanical interface
15ACCS_mech = ACCS_scripting.Mechanical(ExtAPI)
16
17
18LoadSteps = [100]
19CureCycle = [
20 [0.0, 22.0],
21 [20.0, 100.0],
22 [100.0, 120.0],
23]
24
25
26part = Model.Geometry.Children[0]
27body = part.Children[0]
28geoBody = body.GetGeoBody()
29
30
31sortedareas = [
32 i[0]
33 for i in sorted(
34 enumerate([t.Centroid[2] for t in geoBody.Faces]), key=lambda x: x[1]
35 )
36]
37
38
39# Selection: Body
40S_body = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
41S_body.Ids = [geoBody.Id]
42
43# Selection: Edge X0
44S_Inlet = ExtAPI.SelectionManager.CreateSelectionInfo(
45 SelectionTypeEnum.GeometryEntities
46)
47S_Inlet.Ids = [
48 t.Id for t in geoBody.Vertices if (t.X < 0.001) and (t.Y < 0.001) and (t.Z < 0.001)
49]
50
51# Selection: Edge X1
52S_Outlet = ExtAPI.SelectionManager.CreateSelectionInfo(
53 SelectionTypeEnum.GeometryEntities
54)
55S_Outlet.Ids = [
56 t.Id for t in geoBody.Vertices if (0.099 < t.X) and (0.019 < t.Y) and (0.0049 < t.Z)
57]
58
59
60###############################################################
61#
62# RTM ANALYSIS
63#
64###############################################################
65
66ST_analysis = None
67for a in Model.Analyses:
68 if a.PhysicsType.ToString() == "Mechanical":
69 ST_analysis = a
70 break
71ST_solution = ST_analysis.Solution
72current_directory = ST_analysis.WorkingDir
73
74
75ACCS_mech.changeRTMSolverSetting(
76 ST_analysis,
77 property_name="Resin",
78 property_value="RTM Resin with cure dependent viscosity",
79)
80
81
82therm_import = ACCS_mech.AddRTMThermalImport(ST_analysis)
83therm_import.setSurfacesByGeoSelection(S_body)
84
85
86arr = [[0.0, 1.0], [60.0, 2.0]]
87flow = ACCS_mech.AddRTMFlowRateInlet(ST_analysis)
88flow.setSurfacesByGeoSelection(S_Inlet)
89flow.setTimeConditionOnFill(arr)
90flow.suppress()
91
92
93pres = ACCS_mech.AddRTMPressureInlet(ST_analysis)
94pres.setSurfacesByGeoSelection(S_Inlet)
95pres.setConstant(1013.0)
96
97
98outlet = ACCS_mech.AddRTMOutlet(ST_analysis)
99outlet.setSurfacesByGeoSelection(S_Outlet)
100
101
102# results
103ACCS_mech.AddRTMResultFill(ST_analysis)
104ACCS_mech.AddRTMResultBC(ST_analysis)
105ACCS_mech.AddRTMResultDegreeOfCure(ST_analysis)
106ACCS_mech.AddRTMResultEntrapment(ST_analysis)
107ACCS_mech.AddRTMResultGateOpenTime(ST_analysis)
108ACCS_mech.AddRTMResultInfusionTime(ST_analysis)
109ACCS_mech.AddRTMResultPressure(ST_analysis)
110ACCS_mech.AddRTMResultTempBC(ST_analysis)
111ACCS_mech.AddRTMResultTemperature(ST_analysis)
112ACCS_mech.AddRTMResultViscosity(ST_analysis)
113ACCS_mech.AddRTMResultVelocity(ST_analysis)
114
115
116ST_solution.Solve(True)
117
118
119result_fp = os.path.join(directory, "model.h5")
120shutil.copy(os.path.join(ST_analysis.WorkingDir, "model.h5"), result_fp)
121
122
123ACCS_mech.changeRTMSolverSetting(ST_analysis, result_only=True)
124result_imp = ACCS_mech.AddRTMResultImport(ST_analysis)
125result_imp.set_result_filepath(result_fp)
126therm_import.suppress()
127pres.suppress()
128outlet.suppress()
129
130
131ST_solution.Solve(True)