Skip to content

Commit 4bac4ab

Browse files
committed
20250826 Backup
1 parent faf6a94 commit 4bac4ab

30 files changed

Lines changed: 2140 additions & 535 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python Debugger: Current File",
9+
"type": "debugpy",
10+
"request": "launch",
11+
"program": "${file}",
12+
"console": "integratedTerminal"
13+
}
14+
]
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"python-envs.defaultEnvManager": "ms-python.python:conda",
3+
"python-envs.defaultPackageManager": "ms-python.python:conda",
4+
"python-envs.pythonProjects": []
5+
}

samples/CSP/sco2_analysis_python_V2/G3P3_analysis/sco2_baseline_sim_w_IP bauxite.py renamed to samples/CSP/sco2_analysis_python_V2/G3P3_analysis/archive/sco2_baseline_sim_OPTVARS.py

Lines changed: 111 additions & 68 deletions
Large diffs are not rendered by default.

samples/CSP/sco2_analysis_python_V2/G3P3_analysis/sco2_baseline_sim_FINAL.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,13 @@ def run_G3P3_partial_sweep(n_par, run_folder = ''):
337337
time_string = design_pt.get_time_string()
338338
for i in range(N_batches):
339339
run_index_current = i * N_per_batch
340-
solve_collection = design_pt.run_opt_parallel_solve_dict(dict_list_batches[i], default_par, global_var_dict["Nproc"], N_run_total=N_cases, N_run_curr=run_index_current)
340+
solve_collection = design_pt.run_opt_parallel_solve_dict(dict_list_batches[i], default_par,
341+
global_var_dict["Nproc"], N_run_total=N_cases,
342+
N_run_curr=run_index_current)
341343

342344
file_name = "partial_G3P3_collection"
343-
combined_name = global_var_dict['folder_location'] + run_folder + file_name + '_' + str(n_par) + '_' + time_string + '_' + str(i).zfill(3) + ".csv"
345+
combined_name = (global_var_dict['folder_location'] + run_folder + file_name
346+
+ '_' + str(n_par) + '_' + time_string + '_' + str(i).zfill(3) + ".csv")
344347
solve_collection.write_to_csv(combined_name)
345348

346349
finished = ""
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import sys
4+
import os
5+
import json
6+
7+
parentDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
8+
sys.path.append(parentDir)
9+
simsharedFolder = os.path.join(parentDir, 'sco2_sim_shared')
10+
sys.path.append(simsharedFolder)
11+
12+
import sco2_baseline_parameters as sco2_pars
13+
import sco2_sim_core
14+
15+
16+
# Global variables
17+
eta_cutoff = 0.2
18+
N_per_batch = 50000
19+
20+
def initialize_global_var():
21+
local_var_dict = {}
22+
23+
json_file_path = os.path.join(parentDir, 'local_var.json')
24+
if os.path.exists(json_file_path):
25+
with open(json_file_path, 'r') as json_file:
26+
local_var_dict = json.load(json_file)
27+
28+
return local_var_dict
29+
30+
# Methods to run all sweeps
31+
32+
def run_case():
33+
34+
global_var_dict = initialize_global_var()
35+
36+
default_par = sco2_pars.get_sco2_G3P3()
37+
design_var_dict = sco2_pars.get_design_vars_opt()
38+
n_par = 10
39+
run_name = "baseline_OPT"
40+
run_g3p3 = True
41+
sco2_sim_core.run_all_sweeps(n_par, run_name, default_par, design_var_dict,
42+
global_var_dict, run_g3p3)
43+
44+
# Main function
45+
46+
if __name__ == "__main__":
47+
48+
run_case()
49+

samples/CSP/sco2_analysis_python_V2/G3P3_analysis/sco2_sandbox.py

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import numpy as np
44
import math
55
from tkinter.filedialog import asksaveasfilename
6+
from tkinter.filedialog import askopenfilename
7+
import pickle
8+
import multiprocessing
69

710
parentDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
811
sys.path.append(parentDir)
@@ -529,6 +532,80 @@ def test_tsf_inflation():
529532
else:
530533
print("tsf inflation looks good")
531534

535+
def run_sco2_case_from_GUI():
536+
537+
filename = askopenfilename(filetypes =[
538+
('All supported', '*.pkl *.txt *.tsv'),
539+
('Pickle files', '*.pkl'),
540+
('Text files', '*.txt'),
541+
('Tab-separated', '*.tsv')],
542+
title="Open htrbp pkl file")
543+
_, ext = os.path.splitext(filename)
544+
545+
result_dict = {}
546+
547+
match ext:
548+
case ".txt" | ".tsv":
549+
result_dict = design_tools.get_dict_from_file_w_STRING(filename)
550+
case ".pkl":
551+
with open(filename, 'rb') as f:
552+
result_dict = pickle.load(f)
553+
554+
# Get default par
555+
sim_dict = design_pt.get_sco2_G3P3()
556+
557+
# Overwrite all keys in sim_dict
558+
for key in sim_dict:
559+
if key in result_dict:
560+
sim_dict[key] = result_dict[key][0]
561+
else:
562+
trouble = 0
563+
564+
# Add missing keys
565+
sim_dict['T_bypass_target'] = 0
566+
sim_dict['deltaT_bypass'] = 0
567+
568+
# Make Cycle class
569+
c_sco2 = sco2_solve.C_sco2_sim(result_dict['cycle_config'][0])
570+
571+
# Overwrite Variables
572+
c_sco2.overwrite_default_design_parameters(sim_dict)
573+
574+
# Solve
575+
c_sco2.solve_sco2_case()
576+
solve_dict = c_sco2.m_solve_dict
577+
578+
if c_sco2.m_solve_success == False:
579+
return
580+
581+
# Add cmod success var
582+
solve_dict['cmod_success'] = True
583+
solve_dict['id'] = 0
584+
solve_dict['filename'] = os.path.basename(filename)
585+
586+
# Run G3P3
587+
sys.path.append(r"C:\Users\tbrown2\OneDrive - NREL\sCO2-CSP 10302.41.01.40\Notes\G3P3\Design Point\G3P3_python_design_point")
588+
import g3p3_design_sim
589+
590+
manager = multiprocessing.Manager()
591+
solve_dict_queue = manager.Queue()
592+
593+
g3p3_design_sim.run_once_solve_dict(solve_dict, solve_dict_queue)
594+
g3p3_solve_dict = solve_dict_queue.get()
595+
596+
# Make mega g3p3 dict
597+
mega_dict = {}
598+
for sco2_key in solve_dict:
599+
mega_dict[sco2_key] = solve_dict[sco2_key]
600+
for g3p3_key in g3p3_solve_dict:
601+
mega_dict[g3p3_key] = g3p3_solve_dict[g3p3_key]
602+
603+
# Save
604+
save_filename = asksaveasfilename(filetypes =[('Text file', '*.txt')], title="Select save file")
605+
design_tools.write_dict(save_filename, mega_dict, '\t')
606+
607+
608+
532609

533610
if __name__ == "__main__":
534611
#run_bad_partial()
@@ -538,9 +615,10 @@ def test_tsf_inflation():
538615
#test_recomp()
539616
#test_partial_no_recomp()
540617
#test_simple_cost_htr()
541-
test_recomp_inflation()
542-
test_partial_inflation()
543-
test_htrbp_inflation()
544-
test_tsf_inflation()
618+
run_sco2_case_from_GUI()
619+
#test_recomp_inflation()
620+
#test_partial_inflation()
621+
#test_htrbp_inflation()
622+
#test_tsf_inflation()
545623
#get_IP_pressure_range()
546624
#run_bad_partial()

0 commit comments

Comments
 (0)