Skip to content

Commit 0877464

Browse files
committed
Merge branch 'feature_tutorials_fea'
2 parents 6803f41 + 9f2d5fc commit 0877464

File tree

2 files changed

+66
-66
lines changed

2 files changed

+66
-66
lines changed

_tutorials/multiphysics/Adjoint_FSI_Python.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ userguide: Build-SU2-Linux-MacOS
1515
---
1616

1717
This tutorial uses SU2's python wrapper and its native adjoint solvers for incompressible flow and solid mechanics to solve a steady-state, **adjoint** Fluid-Structure Interaction problem. This document will cover:
18-
- Operating with the ad version of the pysu2 library
18+
- Operating with the AD version of the pysu2 library
1919
- Extracting the adjoints of the flow loads and structural displacements from two different python instances of SU2
2020
- Exchanging adjoint information between the two instances
2121

@@ -172,9 +172,9 @@ and the ```flow_filename``` variable previously defined. Next, identifyin the FS
172172
Now, the major differences with respect to the primal case are presented. First, we need to initialize the cross dependency that is applied as a source term into the flow domain to 0, using
173173

174174
```
175-
fea_sensitivities=[]
176-
for iVertex in range(nVertex_Marker_Flow):
177-
fea_sensitivities.append([0.0, 0.0, 0.0])
175+
fea_sens=[]
176+
for j in range(nVertex_Marker_Flow):
177+
fea_sens.append([0.0, 0.0, 0.0])
178178
```
179179

180180
We start the FSI loop and limit it to 15 iterations
@@ -186,73 +186,73 @@ for i in range(15):
186186
and the source term corresponding to the flow load adjoint is applied to the fluid domain. In the first iteration, this will be a zero-vector, but that will not be the case for subsequent iterations.
187187

188188
```
189-
FlowDriver.SetFlowLoad_Adjoint(FlowMarkerID, 0, fea_sensitivities[1][0], fea_sensitivities[1][1], fea_sensitivities[1][2])
190-
FlowDriver.SetFlowLoad_Adjoint(FlowMarkerID, 1, fea_sensitivities[0][0], fea_sensitivities[0][1], fea_sensitivities[0][2])
191-
for iVertex in range(2, nVertex_Marker_Flow):
192-
FlowDriver.SetFlowLoad_Adjoint(FlowMarkerID,iVertex,fea_sensitivities[iVertex][0],fea_sensitivities[iVertex][1],fea_sensitivities[iVertex][2])
189+
FlowDriver.SetFlowLoad_Adjoint(FlowMarkerID,0,fea_sens[1][0],fea_sens[1][1],0)
190+
FlowDriver.SetFlowLoad_Adjoint(FlowMarkerID,1,fea_sens[0][0],fea_sens[0][1],0)
191+
for j in range(2, nVertex_Marker_Flow):
192+
FlowDriver.SetFlowLoad_Adjoint(FlowMarkerID,j,fea_sens[j][0],fea_sens[j][1],0)
193193
```
194194

195195
The flow adjoint iteration is run now using
196196

197197
```
198-
FlowDriver.ResetConvergence()
199-
FlowDriver.Preprocess(0)
200-
FlowDriver.Run()
201-
FlowDriver.Postprocess()
202-
FlowDriver.Update()
203-
stopCalc = FlowDriver.Monitor(0)
198+
FlowDriver.ResetConvergence()
199+
FlowDriver.Preprocess(0)
200+
FlowDriver.Run()
201+
FlowDriver.Postprocess()
202+
FlowDriver.Update()
203+
stopCalc = FlowDriver.Monitor(0)
204204
```
205205

206206
We need to recover the flow loads and apply them to the structural simulation in order to run the primal iteration for the recording,
207207

208208
```
209-
flow_loads=[]
210-
for iVertex in range(nVertex_Marker_Flow):
211-
vertexLoad = FlowDriver.GetFlowLoad(FlowMarkerID, iVertex)
212-
flow_loads.append(vertexLoad)
209+
flow_loads=[]
210+
for j in range(nVertex_Marker_Flow):
211+
vertexLoad = FlowDriver.GetFlowLoad(FlowMarkerID, j)
212+
flow_loads.append(vertexLoad)
213213
214-
FEADriver.SetFEA_Loads(FEAMarkerID, 0, flow_loads[1][0], flow_loads[1][1], flow_loads[1][2])
215-
FEADriver.SetFEA_Loads(FEAMarkerID, 1, flow_loads[0][0], flow_loads[0][1], flow_loads[0][2])
216-
for iVertex in range(2, nVertex_Marker_FEA):
217-
FEADriver.SetFEA_Loads(FEAMarkerID, iVertex, flow_loads[iVertex][0], flow_loads[iVertex][1], flow_loads[iVertex][2])
214+
FEADriver.SetFEA_Loads(FEAMarkerID, 0, flow_loads[1][0], flow_loads[1][1], 0)
215+
FEADriver.SetFEA_Loads(FEAMarkerID, 1, flow_loads[0][0], flow_loads[0][1], 0)
216+
for j in range(2, nVertex_Marker_FEA):
217+
FEADriver.SetFEA_Loads(FEAMarkerID, j, flow_loads[j][0], flow_loads[j][1], 0)
218218
```
219219

220220
and also, we need to extract the cross dependency on the mesh displacements
221221

222222
```
223-
flow_sensitivities=[]
224-
for iVertex in range(nVertex_Marker_Flow):
225-
sensX, sensY, sensZ = FlowDriver.GetMeshDisp_Sensitivity(FlowMarkerID, iVertex)
226-
flow_sensitivities.append([sensX, sensY, sensZ])
223+
flow_sens=[]
224+
for iVertex in range(nVertex_Marker_Flow):
225+
sensX, sensY, sensZ = FlowDriver.GetMeshDisp_Sensitivity(FlowMarkerID, iVertex)
226+
flow_sens.append([sensX, sensY, sensZ])
227227
```
228228

229229
that will be used as a source term into the structural domain
230230

231231
```
232-
FEADriver.SetSourceTerm_DispAdjoint(FEAMarkerID,0,flow_sensitivities[1][0],flow_sensitivities[1][1],flow_sensitivities[1][2])
233-
FEADriver.SetSourceTerm_DispAdjoint(FEAMarkerID,1,flow_sensitivities[0][0],flow_sensitivities[0][1],flow_sensitivities[0][2])
234-
for iVertex in range(nVertex_Marker_FEA):
235-
FEADriver.SetSourceTerm_DispAdjoint(FEAMarkerID,iVertex,flow_sensitivities[iVertex][0],flow_sensitivities[iVertex][1],flow_sensitivities[iVertex][2])
232+
FEADriver.SetSourceTerm_DispAdjoint(FEAMarkerID,0,flow_sens[1][0],flow_sens[1][1],0)
233+
FEADriver.SetSourceTerm_DispAdjoint(FEAMarkerID,1,flow_sens[0][0],flow_sens[0][1],0)
234+
for j in range(nVertex_Marker_FEA):
235+
FEADriver.SetSourceTerm_DispAdjoint(FEAMarkerID,j,flow_sens[j][0],flow_sens[j][1],0)
236236
```
237237
238238
Next, the structural adjoint simulation is run with
239239

240240
```
241-
FEADriver.ResetConvergence()
242-
FEADriver.Preprocess(0)
243-
FEADriver.Run()
244-
FEADriver.Postprocess()
245-
FEADriver.Update()
246-
stopCalc = FEADriver.Monitor(0)
241+
FEADriver.ResetConvergence()
242+
FEADriver.Preprocess(0)
243+
FEADriver.Run()
244+
FEADriver.Postprocess()
245+
FEADriver.Update()
246+
stopCalc = FEADriver.Monitor(0)
247247
```
248248

249249
and the crossed sensitivities with respect to the flow load are retrieved using
250250

251251
```
252-
fea_sensitivities=[]
253-
for iVertex in range(nVertex_Marker_FEA):
254-
sensX, sensY, sensZ = FEADriver.GetFlowLoad_Sensitivity(FEAMarkerID, iVertex)
255-
fea_sensitivities.append([sensX, sensY, sensZ])
252+
fea_sens=[]
253+
for j in range(nVertex_Marker_FEA):
254+
sensX, sensY, sensZ = FEADriver.GetFlowLoad_Sensitivity(FEAMarkerID, j)
255+
fea_sens.append([sensX, sensY, sensZ])
256256
```
257257

258258
Finally, these boundary displacements are imposed to the flow domain in the next iteration. Once the loop is completed, it only remains to write the solution of each domain to file using

_tutorials/multiphysics/Static_FSI_Python.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -162,59 +162,59 @@ for i in range(17):
162162
First, the flow solution is run
163163

164164
```
165-
FlowDriver.ResetConvergence()
166-
FlowDriver.Preprocess(0)
167-
FlowDriver.Run()
168-
FlowDriver.Postprocess()
169-
stopCalc = FlowDriver.Monitor(0)
165+
FlowDriver.ResetConvergence()
166+
FlowDriver.Preprocess(0)
167+
FlowDriver.Run()
168+
FlowDriver.Postprocess()
169+
stopCalc = FlowDriver.Monitor(0)
170170
```
171171

172172
and the flow loads are recovered using
173173

174174
```
175-
flow_loads=[]
176-
for iVertex in range(nVertex_Marker_Flow):
177-
vertexLoad = FlowDriver.GetFlowLoad(FlowMarkerID, iVertex)
178-
flow_loads.append(vertexLoad)
175+
flow_loads=[]
176+
for j in range(nVertex_Marker_Flow):
177+
vertexLoad = FlowDriver.GetFlowLoad(FlowMarkerID, j)
178+
flow_loads.append(vertexLoad)
179179
```
180180

181181
The ```flow_loads``` array now contains the loads in all the vertices of the flow FSI interface. Now, we need to set the flow loads to the FEA nodes. By construction for this case, the vertex IDs are matching for both meshes except for vertex 0 and 1, which are inverted. Therefore, we set the flow loads on the structural domain using
182182

183183
```
184-
FEADriver.SetFEA_Loads(FEAMarkerID, 0, flow_loads[1][0], flow_loads[1][1], flow_loads[1][2])
185-
FEADriver.SetFEA_Loads(FEAMarkerID, 1, flow_loads[0][0], flow_loads[0][1], flow_loads[0][2])
186-
for iVertex in range(2, nVertex_Marker_FEA):
187-
FEADriver.SetFEA_Loads(FEAMarkerID, iVertex, flow_loads[iVertex][0], flow_loads[iVertex][1], flow_loads[iVertex][2])
184+
FEADriver.SetFEA_Loads(FEAMarkerID,0,flow_loads[1][0],flow_loads[1][1],0)
185+
FEADriver.SetFEA_Loads(FEAMarkerID,1,flow_loads[0][0],flow_loads[0][1],0)
186+
for j in range(2, nVertex_Marker_FEA):
187+
FEADriver.SetFEA_Loads(FEAMarkerID,j,flow_loads[j][0],flow_loads[j][1],0)
188188
```
189189

190190
You can ensure the vertices are coincidental by the coordinates of the nodes using ```FlowDriver.GetVertexCoordX(FlowMarkerID, iVertex)``` and ```FlowDriver.GetVertexCoordY(FlowMarkerID, iVertex)``` for the flow domain, and ```FEADriver.GetVertexCoordX(FEAMarkerID, iVertex)``` and ```FEADriver.GetVertexCoordY(FEAMarkerID, iVertex)``` for the structural domain.
191191

192192
Next, the structural simulation is run with
193193

194194
```
195-
FEADriver.ResetConvergence()
196-
FEADriver.Preprocess(0)
197-
FEADriver.Run()
198-
FEADriver.Postprocess()
199-
stopCalc = FEADriver.Monitor(0)
195+
FEADriver.ResetConvergence()
196+
FEADriver.Preprocess(0)
197+
FEADriver.Run()
198+
FEADriver.Postprocess()
199+
stopCalc = FEADriver.Monitor(0)
200200
```
201201

202202
and the structural displacements at the ```feabound``` interface are retrieved using
203203

204204
```
205-
fea_disp=[]
206-
for iVertex in range(nVertex_Marker_FEA):
207-
vertexDisp = FEADriver.GetFEA_Displacements(FEAMarkerID, iVertex)
208-
fea_disp.append(vertexDisp)
205+
fea_disp=[]
206+
for j in range(nVertex_Marker_FEA):
207+
vertexDisp = FEADriver.GetFEA_Displacements(FEAMarkerID, j)
208+
fea_disp.append(vertexDisp)
209209
```
210210

211211
Finally, these boundary displacements are imposed to the flow mesh
212212

213213
```
214-
FlowDriver.SetMeshDisplacement(FlowMarkerID, 0, fea_disp[1][0], fea_disp[1][1], fea_disp[1][2])
215-
FlowDriver.SetMeshDisplacement(FlowMarkerID, 1, fea_disp[0][0], fea_disp[0][1], fea_disp[0][2])
216-
for iVertex in range(2, nVertex_Marker_FEA):
217-
FlowDriver.SetMeshDisplacement(FlowMarkerID, iVertex, fea_disp[iVertex][0], fea_disp[iVertex][1], fea_disp[iVertex][2])
214+
FlowDriver.SetMeshDisplacement(FlowMarkerID,0,fea_disp[1][0],fea_disp[1][1],0)
215+
FlowDriver.SetMeshDisplacement(FlowMarkerID,1,fea_disp[0][0],fea_disp[0][1],0)
216+
for j in range(2, nVertex_Marker_FEA):
217+
FlowDriver.SetMeshDisplacement(FlowMarkerID,j,fea_disp[j][0],fea_disp[j][1],0)
218218
```
219219

220220
Once the loop is completed, it only remains to write the solution of each domain to file using

0 commit comments

Comments
 (0)