Skip to content

Commit c4b24f4

Browse files
committed
adding feature to retreive figure handles when calling plotOptimization function in LineDesign.
1 parent 447b3c0 commit c4b24f4

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

famodel/design/LineDesign.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ def negativeObjectiveFun(**kwargs):
13021302

13031303
if plot:
13041304
self.plotOptimization()
1305-
1305+
13061306
return X, self.cost #, infodict
13071307

13081308

@@ -1313,7 +1313,7 @@ def getCons4PSO(self, X):
13131313
return conList
13141314

13151315

1316-
def plotOptimization(self, layout="tall"):
1316+
def plotOptimization(self, layout="tall", return_fig=False):
13171317
'''Plot the optimization trajectory, including design variables, constraints and cost.
13181318
13191319
Parameters
@@ -1346,7 +1346,7 @@ def plotOptimization(self, layout="tall"):
13461346
for i in range(n_dv):
13471347
ax = axes[i, 0]
13481348
ax.plot(Xs[:, i], color='blue')
1349-
ax.set_ylabel(f"d.v.{i+1} ({self.X0Units[i]})", rotation=0, labelpad=20,fontsize=10, ha='right', va='center')
1349+
ax.set_ylabel(f"d.v.{i+1} ({self.X0Units[i]})", rotation=90, fontsize=10, va='center')
13501350

13511351
# --- Column 2 / stacked: Constraints ---
13521352
for i, con in enumerate(self.constraints):
@@ -1356,10 +1356,13 @@ def plotOptimization(self, layout="tall"):
13561356
tol = 0.005 * (max(Gs[:, i])-min(Gs[:, i]))
13571357
color = 'green' if Gs[-1, i] >= -tol else 'red'
13581358
ax.plot(Gs[:, i], color=color)
1359-
ax.set_ylabel(f"{con['name']} ({con['unit']})",
1360-
rotation=0, labelpad=20,
1361-
ha='right', va='center',
1362-
fontsize=10)
1359+
if con['name']=='tension_safety_factor':
1360+
con_name = 'SF'
1361+
else:
1362+
con_name = con['name']
1363+
ax.set_ylabel(f"{con_name} ({con['unit']})",
1364+
rotation=90,
1365+
va='center', fontsize=10)
13631366
# Show threshold value inside plot
13641367
ax.text(0.98, 0.90, f"{con['threshold']}",
13651368
transform=ax.transAxes,
@@ -1371,8 +1374,8 @@ def plotOptimization(self, layout="tall"):
13711374
else:
13721375
ax_cost = axes[-1, 0]
13731376
ax_cost.plot(Fs/1e6, color='black')
1374-
ax_cost.set_ylabel('cost (M$)', rotation=0, labelpad=20, ha='right', va='center', fontsize=10)
1375-
1377+
ax_cost.set_ylabel('cost (M$)', rotation=90, va='center', fontsize=10)
1378+
13761379
# remove unused axes if layout='grid'
13771380
if layout=="grid":
13781381
for i in range(n_dv, n_rows):
@@ -1381,7 +1384,7 @@ def plotOptimization(self, layout="tall"):
13811384
for i in range(n_con, n_rows):
13821385
axes[i, 1].axis('off')
13831386

1384-
for i in range(1, n_rows):
1387+
for i in range(2, n_rows):
13851388
axes[i, 2].axis('off')
13861389

13871390
# --- X labels only on bottom subplots ---
@@ -1402,6 +1405,9 @@ def plotOptimization(self, layout="tall"):
14021405

14031406
plt.tight_layout()
14041407

1408+
if return_fig:
1409+
return fig, axes
1410+
14051411
def plotGA(self):
14061412
'''A function dedicated to plotting relevant GA outputs'''
14071413

@@ -2100,7 +2106,7 @@ def dump(self):
21002106
info['design']['X' ] = self.Xlast.tolist() # design variables
21012107
#info['design']['Gdict' ] = self.evaluateConstraints([])[1] # dict of constraint names and values of evaluated constraint functions
21022108
info['design']['Ls' ] = [float(line.L ) for line in self.ss.lineList] # length of each segment
2103-
info['design']['Ds' ] = [float(line.type['input_d']) for line in self.ss.lineList] # *input* diameter of each segment
2109+
info['design']['Ds' ] = [float(line.type['d_nom']) for line in self.ss.lineList] # *input* diameter of each segment
21042110
info['design']['lineTypes' ] = [str(line.type['material']) for line in self.ss.lineList] # line type of each segment (may be redundant with what's in arrangement)
21052111
info['design']['anchorType'] = self.anchorType # (may be redundant with what's in arrangement)
21062112
info['design']['span' ] = float(self.span) # platform-platform of platfom-anchor horizontal span just in case it's changed

0 commit comments

Comments
 (0)