Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cache_plane_variables.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/vlm.old/VLM_method.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.3"
"version": "3.13.7"
}
},
"nbformat": 4,
Expand Down
37 changes: 31 additions & 6 deletions src/vlm/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from functools import wraps
from pathlib import Path
from typing import Any, Dict, Optional
from datetime import datetime

# Third-party imports kept together; optional/possibly heavy imports guarded for clearer errors
try:
Expand Down Expand Up @@ -275,8 +276,9 @@ def _vlm_create_and_save(plane: dict, u: float, rho: float, alpha: float, beta:
vlm = VLM(plane, u, rho, alpha, beta, n, m)
# operación que depende de VLM
vlm.save_and_load_plane_variables(filename=str(BASE_DIR / 'data' / 'cache_plane_variables.txt'), option='save_and_load')
state_path = SAVED_STATES / f"{session_id}.pkl"
vlm.save_state(str(state_path))
#timestamp = datetime.now().strftime("%d%m%y%H%M%S")
#state_path = SAVED_STATES / f"{session_id}_{timestamp}.pkl"
#vlm.save_state(str(state_path))
with vlm_sessions_lock:
vlm_sessions[session_id] = vlm
return {"status": "success", "message": "Wing design computed."}
Expand Down Expand Up @@ -473,6 +475,10 @@ def compute(vlm: VLM):
if vlm.results is None:
future = thread_pool.submit(compute, vlm)
vlm = future.result()
#save state after computation
timestamp = datetime.now().strftime("%d%m%y%H%M%S")
state_path = SAVED_STATES / f"{"results"}_{timestamp}.pkl"
vlm.save_state(str(state_path))

wing_lift_total = np.sum(vlm.lift_sum.get('lift_wing', [])) if hasattr(vlm, 'lift_sum') else None
hs_lift_total = np.sum(vlm.lift_sum.get('lift_hs', [])) if hasattr(vlm, 'lift_sum') else None
Expand Down Expand Up @@ -576,14 +582,33 @@ def load_airfoil():
def load_vlm_state():
try:
session_id = session.get("session_id")
state_file = SAVED_STATES / f"{session_id}.pkl"
if not state_file.exists():
return jsonify({"status": "error", "message": "No saved state found"}), 404
if 'state_file' not in request.files:
return jsonify({"status": "error", "message": "No state_file provided"}), 400
file = request.files['state_file']
if file.filename == '':
return jsonify({"status": "error", "message": "No file selected"}), 400

# Path to load the state file
path = SAVED_STATES / file.filename

with vlm_sessions_lock:
if session_id not in vlm_sessions:
return jsonify({"status": "error", "message": "No active VLM session"}), 400
vlm_sessions[session_id].load_state(str(state_file))
vlm_sessions[session_id].load_state(str(path))
vlm = vlm_sessions[session_id]
#update vlm session
wing_lift_total = np.sum(vlm.lift_sum.get('lift_wing', [])) if hasattr(vlm, 'lift_sum') else None
hs_lift_total = np.sum(vlm.lift_sum.get('lift_hs', [])) if hasattr(vlm, 'lift_sum') else None
vs_lift_total = np.sum(vlm.lift_sum.get('lift_vs', [])) if hasattr(vlm, 'lift_sum') else None

cl = f"{vlm.CL:.4f}" if getattr(vlm, 'CL', None) is not None else "--"
cd = f"{vlm.CD:.4f}" if getattr(vlm, 'CD', None) is not None else "--"
total_lift = f"{vlm.lift:.2f}" if getattr(vlm, 'lift', None) is not None else "--"
total_drag = f"{vlm.drag:.2f}" if getattr(vlm, 'drag', None) is not None else "--"
wing_lift = f"{wing_lift_total:.2f}" if wing_lift_total is not None else "--"
hs_lift = f"{hs_lift_total:.2f}" if hs_lift_total is not None else "--"
vs_lift = f"{vs_lift_total:.2f}" if vs_lift_total is not None else "--"

return jsonify({"status": "success", "message": "VLM state loaded successfully"}), 200
except Exception as e:
logger.exception("Error in /load_vlm_state")
Expand Down
4 changes: 3 additions & 1 deletion src/vlm/data/cache_plane_variables.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
wing_sections: [{'chord_root': 1.0, 'chord_tip': 0.8, 'span_fraction': 8.0, 'sweep': np.float64(0.5235987755982988), 'alpha': np.float64(0.05235987755982989), 'dihedral': np.float64(0.06981317007977318), 'NACA_root': '3215', 'NACA_tip': '1310'}]
wing_sections: [{'chord_root': 1.0, 'chord_tip': 1.0, 'span_fraction': 8.0, 'sweep': np.float64(0.5235987755982988), 'alpha': np.float64(0.0523598775598299), 'dihedral': np.float64(0.06981317007977318), 'NACA_root': '3215', 'NACA_tip': '1310'}]
horizontal_stabilizer: {'x_translate': 2.0, 'z_translate': 0.0, 'NACA_root': '3215', 'NACA_tip': '3215', 'chord_root': 0.5, 'chord_tip': 0.5, 'span_fraction': 2.0, 'sweep': np.float64(0.5235987755982988), 'alpha': np.float64(0.0), 'dihedral': np.float64(0.0)}
vertical_stabilizer: {'x_translate': 2.0, 'z_translate': 0.0, 'NACA_root': '3215', 'NACA_tip': '3215', 'chord_root': 0.5, 'chord_tip': 0.5, 'span_fraction': 0.5, 'sweep': np.float64(0.5235987755982988), 'alpha': np.float64(0.0), 'dihedral': np.float64(1.5707963267948966)}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading