Skip to content

Commit

Permalink
qua 30 ago 2023 16:58:33 -03
Browse files Browse the repository at this point in the history
  • Loading branch information
RenatoBrittoAraujo committed Aug 30, 2023
1 parent 3b2007f commit 849ba99
Show file tree
Hide file tree
Showing 73 changed files with 154 additions and 10,438 deletions.
106 changes: 56 additions & 50 deletions avl_optmizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def get_thread_result_blocking(self, thread_label: str):
if tid in self.results:
result = self.results[tid]
del self.results[tid]
if tid not in self.running_threads:
if tid not in self.running_threads and tid in self.label_map:
del self.label_map[tid]
return result

Expand Down Expand Up @@ -409,16 +409,26 @@ def check_running_threads(self):
class Input:
key: str
index: int
interval: list[float]
min_variation: float
max_variation: float
interval_max: float
interval_min: float
curr: float
step: float

def __init__(self, key: str, curr: float, value: dict):
self.key = key
self.interval = value.get("interval")
self.min_variation = value.get("min_variation") or value.get("step")
self.max_variation = value.get("max_variation") or value.get("step")

if not value.get("step"):
raise Exception("step not found or not a number")

interval = value.get("interval")
# if not interval or len(interval) != 2 or not interval[0].is:
# raise Exception("variation interval not found or not parseable")

print(value)

self.interval_max = max(value.get("interval"))
self.interval_min = min(value.get("interval"))
self.step = value.get("step")
self.curr = curr

global INPUT_INDEX
Expand All @@ -428,10 +438,13 @@ def __init__(self, key: str, curr: float, value: dict):
INPUT_INDEX += 1

def get_interval(self) -> tuple[float, float]:
return max(*self.interval), min(self.interval)
return max(self.interval), min(self.interval)

def get_interval_amplitude(self) -> float:
return max(*self.interval) - min(self.interval)
return max(self.interval) - min(self.interval)

def get_variation(self) -> tuple[float, float]:
return self.get_interval_amplitude() / self.step


class Output:
Expand Down Expand Up @@ -602,13 +615,6 @@ def __init__(
def optimize(self, in_fp: AVLFileParser) -> tuple[AVLFileParser, AVLResultParser]:
iter_count = 0

step_sizes = []
for inp in self.inputs:
if inp.min_variation:
step_sizes.append(inp.min_variation)
else:
step_sizes.append(inp.get_interval_amplitude() / self.interval_steps)

x_next = [float(in_fp.get_value(inp.key)) for inp in self.inputs]

print("[main] Getting initial out file...")
Expand All @@ -624,7 +630,6 @@ def optimize(self, in_fp: AVLFileParser) -> tuple[AVLFileParser, AVLResultParser
if iter_count > self.max_iter_count:
return x_next
iter_count += 1
x_new = x_next.copy()
x_out_changes = False
x_inp_changes = False

Expand All @@ -633,15 +638,23 @@ def optimize(self, in_fp: AVLFileParser) -> tuple[AVLFileParser, AVLResultParser
for inp in self.inputs:
indx = self.inputs.index(inp)

if not last_out_fp:
new_in_fp = self.get_first_variation(inp.index, in_fp)
else:
new_in_fp = self.get_subsequent_variation(inp.index, x_next)

self.thread_queue.add_new_thread_blocking(
self.avl.analyse_for_thread,
(in_fp,),
(new_in_fp,),
label=int(indx),
)

self.thread_queue.wait_all_threads()

for i in range(len(x_new)):
for i in range(len(x_next)):



if x_next[i] != x_new[i]:
print(
f"Changed the input {self.inputs[i].key} in x_next versus x_new from {x_next[i]} to {x_new[i]}"
Expand Down Expand Up @@ -674,38 +687,31 @@ def optimize(self, in_fp: AVLFileParser) -> tuple[AVLFileParser, AVLResultParser

return self.get_in_fp_from_vals(x_next), last_out_fp

def get_new_variations(
self,
indx: int,
inp: list[float],
variation: float,
) -> tuple[float, bool]:
# # increase so that a convergance is eventually forced
# if iter_count > self.limit_iter_count:
# step_sizes[indx] = step_sizes[indx] * self.limit_variation_factor

in_fp = self.get_in_fp_from_vals(inp)
out_fp = self.avl.analyse_from_fp(in_fp)
fx, errors, out_fp = self.get_score_from_scorer(in_fp, out_fp)

if errors is not None:
print("ERROS!\n", errors)

# d = f(x) / (x1 - x2)
d = fx / -variation

# if math.fabs(d*step_sizes[indx]) < min_variation[indx]:
# continue
# el
print(f"d = {d}")
if d > 0:
nv = inp[indx] + variation * d
inp[indx] = nv
else:
nv = inp[indx] - variation * d
inp[indx] = nv
def get_first_variation(
self, indx: int, in_fp: AVLFileParser
) -> list[AVLFileParser]:
key = self.inputs[indx].key
curr = in_fp.get_value(key)
variation = self.inputs[indx].get_variation()
res_a = AVLFileParser(structure=in_fp)
res_a.set_value(key, curr + variation)
res_b = AVLFileParser(structure=in_fp)
res_b.set_value(key, curr - variation)
return [res_a, res_b]

def get_subsequent_variation(
self, indx: int, inp: list[float] | None
) -> list[AVLFileParser]:

# estamos em uma árvore para variar o atual
# vamos ver pra qual direção essa mudança dá melhor resultado
# temos o valor x atual e score atual
# vamos recalcular quando x + d ou x - d
# é melhor x+d ou x-d ou x do jeito que tá?




return out_fp

def get_score_from_scorer(
self,
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"avl_env_path": "env/",
"avl_input_file": "in.avl",
"avl_output_file": "baseline_out.txt",
"avl_output_file": "baseline_out_3.txt",
"base_input_file": "geometria.avl",
"final_input_file": "otimizado.avl",
"final_output_file": "output.txt",
"templates_folder": "templates/",
"max_threads": 9,
"max_threads": 4,
"max_iter_count": 200,
"limit_iter_count": 100,
"limit_variation_factor": 0.95,
Expand Down
4 changes: 2 additions & 2 deletions dev_files/commands_sent.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
LOAD in_12.avl
LOAD in_0.avl
OPER
X
ST
out_12.txt
out_0.txt
188 changes: 9 additions & 179 deletions dev_files/stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
NAME s Specify new configuration name

AVL c>
Reading file: in_12.avl ...
Reading file: in_0.avl ...

Configuration: WING_2022

Expand All @@ -46,188 +46,18 @@
Building duplicate image-surface: Right_Wing (YDUP)

Building surface: emp_horizontal
Reading airfoil from file: eh_NACA3312_inv.dat
Reading airfoil from file: eh_NACA3312_inv.dat

Building duplicate image-surface: emp_horizontal (YDUP)

Building surface: emp_vertical
Reading airfoil from file: ev_BELL540.dat
Reading airfoil from file: ev_BELL540.dat

Building surface: Fuselage H

Building duplicate image-surface: Fuselage H (YDUP)

Building surface: Fuselage V

Mach = 0.0000 (default)

0 Bodies
8 Solid surfaces
103 Strips
2060 Vortices

3 Control variables
0 Design parameters

Initializing run cases...
** Read error on line 65 ...
<__main__.Input object at 0x7fb8180e79d0> 0.0 <__main__.Input object at 0x7fb8180e7a30> <__main__.Input object at 0x7fb8180e7a90> <__main__.Input object at 0x7fb8180e7af0>
** File not processed. Current geometry may be corrupted.

AVL c>
Operation of run case 1/1: -unnamed-
==========================================================
* Configuration not defined

variable constraint
------------ ------------------------
A lpha -> alpha = 0.000
B eta -> beta = 0.000
R oll rate -> pb/2V = 0.000
P itch rate -> qc/2V = 0.000
Y aw rate -> rb/2V = 0.000
D1 aileron -> aileron = 0.000
D2 elevator -> elevator = 0.000
D3 rudder -> rudder = 0.000
------------ ------------------------

C1 set level or banked horizontal flight constraints
C2 set steady pitch rate (looping) flight constraints
M odify parameters

"#" select run case L ist defined run cases
+ add new run case S ave run cases to file
- delete run case F etch run cases from file
N ame current run case W rite forces to file

eX ecute run case I nitialize variables

G eometry plot T refftz Plane plot

ST stability derivatives FT total forces
SB body-axis derivatives FN surface forces
RE reference quantities FS strip forces
DE design changes FE element forces
O ptions FB body forces
HM hinge moments
VM strip shear,moment
MRF machine-readable format CPOM OML surface pressures

.OPER (case 1/1) c> Building normalwash AIC matrix...
Factoring normalwash AIC matrix...
Building source+doublet strength AIC matrix...
Building source+doublet velocity AIC matrix...
Building bound-vortex velocity matrix...

iter d(alpha) d(beta) d(pb/2V) d(qc/2V) d(rb/2V) aileron elevator rudder
1 -0.000E+00 -0.000E+00 0.000E+00 -0.000E+00 0.000E+00 -0.000E+00 -0.000E+00 -0.000E+00
---------------------------------------------------------------
Vortex Lattice Output -- Total Forces

Configuration: WING_2022
# Surfaces = 8
# Strips = 103
# Vortices =2060
AVL c> X command not recognized. Type a "?" for list

Sref = 0.39000 Cref = 0.23200 Bref = 1.6700
Xref = 0.0000 Yref = 0.0000 Zref = 0.0000
AVL c> ST command not recognized. Type a "?" for list

Standard axis orientation, X fwd, Z down

Run case: -unnamed-

Alpha = 0.00000 pb/2V = -0.00000 p'b/2V = -0.00000
Beta = 0.00000 qc/2V = 0.00000
Mach = 0.000 rb/2V = -0.00000 r'b/2V = -0.00000

CXtot = -0.00304 Cltot = 0.00000 Cl'tot = 0.00000
CYtot = 0.00000 Cmtot = 0.26191
CZtot = 0.08174 Cntot = -0.00000 Cn'tot = -0.00000

CLtot = -0.08174
CDtot = 0.00304
CDvis = 0.00000 CDind = 0.0030421
CLff = -0.08174 CDff = 0.0030431 | Trefftz
CYff = 0.00000 e = 0.0977 | Plane

aileron = 0.00000
elevator = 0.00000
rudder = 0.00000

---------------------------------------------------------------

Operation of run case 1/1: -unnamed-
==========================================================

variable constraint
------------ ------------------------
A lpha -> alpha = 0.000
B eta -> beta = 0.000
R oll rate -> pb/2V = 0.000
P itch rate -> qc/2V = 0.000
Y aw rate -> rb/2V = 0.000
D1 aileron -> aileron = 0.000
D2 elevator -> elevator = 0.000
D3 rudder -> rudder = 0.000
------------ ------------------------

C1 set level or banked horizontal flight constraints
C2 set steady pitch rate (looping) flight constraints
M odify parameters

"#" select run case L ist defined run cases
+ add new run case S ave run cases to file
- delete run case F etch run cases from file
N ame current run case W rite forces to file

eX ecute run case I nitialize variables

G eometry plot T refftz Plane plot

ST stability derivatives FT total forces
SB body-axis derivatives FN surface forces
RE reference quantities FS strip forces
DE design changes FE element forces
O ptions FB body forces
HM hinge moments
VM strip shear,moment
MRF machine-readable format CPOM OML surface pressures

.OPER (case 1/1) c>
Enter filename, or <return> for screen output s>
Operation of run case 1/1: -unnamed-
==========================================================
AVL c> OUT_ command not recognized. Type a "?" for list

variable constraint
------------ ------------------------
A lpha -> alpha = 0.000
B eta -> beta = 0.000
R oll rate -> pb/2V = 0.000
P itch rate -> qc/2V = 0.000
Y aw rate -> rb/2V = 0.000
D1 aileron -> aileron = 0.000
D2 elevator -> elevator = 0.000
D3 rudder -> rudder = 0.000
------------ ------------------------

C1 set level or banked horizontal flight constraints
C2 set steady pitch rate (looping) flight constraints
M odify parameters

"#" select run case L ist defined run cases
+ add new run case S ave run cases to file
- delete run case F etch run cases from file
N ame current run case W rite forces to file

eX ecute run case I nitialize variables

G eometry plot T refftz Plane plot

ST stability derivatives FT total forces
SB body-axis derivatives FN surface forces
RE reference quantities FS strip forces
DE design changes FE element forces
O ptions FB body forces
HM hinge moments
VM strip shear,moment
MRF machine-readable format CPOM OML surface pressures

.OPER (case 1/1) c>
AVL c>
Loading

0 comments on commit 849ba99

Please sign in to comment.