Skip to content

Commit 609e362

Browse files
committed
fix FEA examples
1 parent 7776bef commit 609e362

6 files changed

Lines changed: 30 additions & 21 deletions

File tree

SU2_CFD/src/output/CElasticityOutput.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,15 @@ void CElasticityOutput::SetHistoryOutputFields(CConfig *config){
169169
AddHistoryOutput("LOAD_INCREMENT", "Load[%]", ScreenOutputFormat::PERCENT, "", "LOAD_INCREMENT");
170170
AddHistoryOutput("LOAD_RAMP", "Load_Ramp",ScreenOutputFormat::FIXED, "", "LOAD_RAMP");
171171

172-
AddHistoryOutput("REFERENCE_GEOMETRY", "RefGeom", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
173-
AddHistoryOutput("REFERENCE_NODE", "RefNode", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
174-
AddHistoryOutput("VOLUME_FRACTION", "VolFrac", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
175-
AddHistoryOutput("TOPOL_DISCRETENESS", "TopDisc", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
176-
AddHistoryOutput("TOPOL_COMPLIANCE", "TopComp", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
177-
172+
AddHistoryOutput("REFERENCE_NODE", "RefNode", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
173+
AddHistoryOutput("TOPOL_COMPLIANCE", "TopComp", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
174+
if (config->GetRefGeom()) {
175+
AddHistoryOutput("REFERENCE_GEOMETRY", "RefGeom", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
176+
}
177+
if (config->GetTopology_Optimization()) {
178+
AddHistoryOutput("VOLUME_FRACTION", "VolFrac", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
179+
AddHistoryOutput("TOPOL_DISCRETENESS", "TopDisc", ScreenOutputFormat::SCIENTIFIC, "STRUCT_COEFF", "", HistoryFieldType::COEFFICIENT);
180+
}
178181
}
179182

180183
void CElasticityOutput::LoadVolumeData(CConfig *config, CGeometry *geometry, CSolver **solver, unsigned long iPoint){

SU2_PY/topology_optimization.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ def obj_val(self,x):
122122

123123
try:
124124
sp.call(self._objValCommand,shell=True)
125-
fid = open(self._objValFile,"r"); val = float(fid.readlines()[1]); fid.close()
125+
with open(self._objValFile,"r") as fid:
126+
lines = fid.readlines()
127+
for col,name in enumerate(lines[0].split(",")):
128+
if "TopComp" in name:
129+
val = float(lines[1].split(",")[col])
130+
break
126131
# the return code of mpirun is useless, we test the value of the function
127132
self._assert_isfinite(val)
128133
except:
@@ -161,15 +166,13 @@ def obj_der(self,x):
161166
def con_val(self,x):
162167
# inputs written in obj_val_driver
163168

164-
# clear previous output and run solver
165-
try: os.remove(self._conValFile)
166-
except: pass
167-
try: os.remove(self._conDerFile)
168-
except: pass
169-
170169
try:
171-
sp.call(self._conDerCommand,shell=True)
172-
fid = open(self._conValFile,"r"); val = float(fid.readlines()[1]); fid.close()
170+
with open(self._conValFile,"r") as fid:
171+
lines = fid.readlines()
172+
for col,name in enumerate(lines[0].split(",")):
173+
if "VolFrac" in name:
174+
val = float(lines[1].split(",")[col])
175+
break
173176
self._assert_isfinite(val)
174177
except:
175178
raise RuntimeError("Constraint function evaluation failed")
@@ -181,12 +184,16 @@ def con_val(self,x):
181184
def con_der(self,x):
182185
# inputs written in obj_val_driver
183186

184-
# adjoint solver already ran
187+
# clear previous output and run solver
188+
try: os.remove(self._conDerFile)
189+
except: pass
185190
N = x.shape[0]
186191
y = np.ndarray((N,))
187192

188193
# read result
189194
try:
195+
sp.call(self._conDerCommand,shell=True)
196+
190197
fid = open(self._conDerFile,"r"); lines = fid.readlines(); fid.close()
191198
for i in range(N):
192199
val = float(lines[i][0:-1])

TestCases/fea_fsi/MixElemsKnowles/config.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
% Case description: Tip-loaded 3D cantilever beam, mix of element types, %
55
% nonlinear elasticity with Knowles material model. %
66
% Institution: Imperial College London %
7-
% File Version 7.0.8 "Blackbird" %
7+
% File Version 7.0.8 "Blackbird" %
88
% %
99
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1010
%
@@ -51,4 +51,5 @@ TABULAR_FORMAT= CSV
5151
RESTART_SOL= YES
5252
SOLUTION_FILENAME= solution_structure.dat
5353

54-
SCREEN_OUTPUT=(INNER_ITER, RMS_UTOL, RMS_RTOL, RMS_ETOL, COMBO, VMS)
54+
HISTORY_OUTPUT= (ITER, RMS_RES, STRUCT_COEFF)
55+
SCREEN_OUTPUT=(INNER_ITER, RMS_UTOL, RMS_RTOL, RMS_ETOL, REFERENCE_NODE, VMS)

TestCases/fea_topology/quick_start/settings.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ TABULAR_FORMAT= CSV
4646
SOLUTION_FILENAME= direct.dat
4747
RESTART_FILENAME= direct.dat
4848
OUTPUT_FILES= RESTART, PARAVIEW
49-
HISTORY_OUTPUT= COMBO
49+
HISTORY_OUTPUT= STRUCT_COEFF

TestCases/fea_topology/quick_start/settings_compliance.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,4 @@ TABULAR_FORMAT= CSV
4848
SOLUTION_FILENAME= direct.dat
4949
RESTART_FILENAME= direct.dat
5050
OUTPUT_FILES= PARAVIEW
51-
HISTORY_OUTPUT= COMBO
5251

TestCases/fea_topology/quick_start/settings_volfrac.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,4 @@ TABULAR_FORMAT= CSV
4848
SOLUTION_FILENAME= direct.dat
4949
RESTART_FILENAME= direct.dat
5050
OUTPUT_FILES= PARAVIEW
51-
HISTORY_OUTPUT= COMBO
5251

0 commit comments

Comments
 (0)