Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CST version check #169

Draft
wants to merge 101 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
4625282
create permian dir
kurbansitterley Oct 23, 2024
ae55393
create oxidation unit
kurbansitterley Oct 23, 2024
9359b26
add electrocoagulation
kurbansitterley Oct 24, 2024
2bd557f
clean up
kurbansitterley Oct 24, 2024
117db50
stash costing changes
kurbansitterley Oct 24, 2024
5b7ffb6
add cart filt
kurbansitterley Oct 25, 2024
2b6b6c1
updates to costing
kurbansitterley Oct 25, 2024
9b66784
add generic path for permian case study file
kurbansitterley Oct 25, 2024
09024b7
add cart filt yaml; checkpoint
kurbansitterley Oct 25, 2024
e826fe0
black
kurbansitterley Oct 25, 2024
6b08702
add case study yaml to component files
kurbansitterley Oct 25, 2024
dcd05c3
fix permian EC
kurbansitterley Oct 25, 2024
f6e13aa
fix KBHDP ec
kurbansitterley Oct 25, 2024
999da5f
add ec yaml; add kbhdp case study yaml
kurbansitterley Oct 25, 2024
34e9bef
similar structure
kurbansitterley Oct 25, 2024
05be75e
add mvc
kurbansitterley Oct 27, 2024
0cd1790
make importable; clean up
kurbansitterley Oct 27, 2024
e0a726a
draft permian SOA started
kurbansitterley Oct 27, 2024
201315b
blackify
kurbansitterley Oct 27, 2024
76b4bf1
add DWI component file
kurbansitterley Oct 28, 2024
132e30b
add translators; make importable
kurbansitterley Oct 28, 2024
7de1e99
permian SOA case study checkpoint
kurbansitterley Oct 28, 2024
9ef94db
conductivity via constr
kurbansitterley Oct 28, 2024
df0c8b1
set unit operating conditions
kurbansitterley Oct 28, 2024
a4ece11
add flowsheet_costing_block arg
kurbansitterley Oct 28, 2024
c2ed31a
add costing for SOA
kurbansitterley Oct 28, 2024
95e2341
import init func
kurbansitterley Oct 29, 2024
b974416
passing fs not unit
kurbansitterley Oct 29, 2024
1e235d0
black
kurbansitterley Nov 1, 2024
905c024
sw to water tb
kurbansitterley Nov 2, 2024
8b993ba
improve MVC build
kurbansitterley Nov 3, 2024
0882bf2
MVC working optimization and design
kurbansitterley Nov 3, 2024
a5672f7
MVC design/operating functions
kurbansitterley Nov 3, 2024
6e1ef5e
use generic MVC
kurbansitterley Nov 10, 2024
2be7008
SOA initializing
kurbansitterley Nov 10, 2024
22b4c5a
0 TDS removal for EC
kurbansitterley Nov 11, 2024
5996ac5
permian SOA checkpoint
kurbansitterley Nov 11, 2024
f2d215f
Merge branch 'main' of https://github.com/kurbansitterley/watertap-se…
kurbansitterley Nov 15, 2024
9a84483
update data yamls for permian
kurbansitterley Nov 18, 2024
16ef25e
add pretreatment flowsheet
kurbansitterley Nov 18, 2024
a649a63
permian pretreatment flowsheet mod
kurbansitterley Nov 19, 2024
2c81da5
blackify
kurbansitterley Nov 19, 2024
0b0c274
Merge branch 'main' into permian_case_study
kurbansitterley Nov 21, 2024
13704cf
Merge branch 'main' into permian_case_study
kurbansitterley Nov 22, 2024
c003357
add kwargs
kurbansitterley Nov 22, 2024
651fd91
add SOA temp
kurbansitterley Nov 22, 2024
3ca4251
add EC TDS removal frac, base currency = 2023 to yamls
kurbansitterley Dec 4, 2024
d388765
Merge branch 'main' into permian_case_study
kurbansitterley Dec 7, 2024
29316c3
Merge branch 'main' of https://github.com/kurbansitterley/watertap-se…
kurbansitterley Dec 9, 2024
c6e4725
Merge branch 'permian_case_study' of https://github.com/kurbansitterl…
kurbansitterley Dec 16, 2024
f701e5a
Merge branch 'main' of https://github.com/kurbansitterley/watertap-se…
kurbansitterley Dec 16, 2024
48c8730
black of course
kurbansitterley Dec 16, 2024
0c8cc93
remove conductivity constraint
kurbansitterley Dec 16, 2024
c3c66c2
Merge branch 'main' of https://github.com/kurbansitterley/watertap-re…
kurbansitterley Dec 19, 2024
f28606e
update gitignore
kurbansitterley Dec 23, 2024
da6536c
create data dir; add carlsbad NM weather for permian case study
kurbansitterley Dec 23, 2024
2c9c079
pretreatment changes
MuktaHardikar Dec 30, 2024
c7e9e32
update ec yaml and add costing back to pretreatment
MuktaHardikar Dec 30, 2024
e9e193b
pretreatment solving with DOF = 1
MuktaHardikar Dec 30, 2024
b02a560
pretreatment solving with DOF=0. Need to verify values
MuktaHardikar Dec 30, 2024
a1e301c
updated rho_water density
MuktaHardikar Dec 30, 2024
00bc7a1
Fixing the disposal_SW_mixer.mixed_state temperature after initializa…
MuktaHardikar Dec 30, 2024
214a256
improve EC scaling
kurbansitterley Dec 31, 2024
0976822
improve CF scaling
kurbansitterley Dec 31, 2024
cb23edb
add chem addition scaling
kurbansitterley Dec 31, 2024
90c1aaa
unify pretreatment scaling
kurbansitterley Dec 31, 2024
252fb06
HX split fraction is always 0.5; update scaling part 1
kurbansitterley Dec 31, 2024
7422b9e
add constant to prop_out tds mass flow to fix conc issue
kurbansitterley Dec 31, 2024
d7e15bc
move constant
kurbansitterley Dec 31, 2024
142f975
correct system recovery calc
kurbansitterley Dec 31, 2024
179e690
dwi use lcow costing method
kurbansitterley Jan 3, 2025
0935a4b
add build_and_run to permian pretreatment
kurbansitterley Jan 3, 2025
75d3c7a
MVC working mostly
kurbansitterley Jan 3, 2025
0632ae8
keeping old permian SOA file for now
kurbansitterley Jan 3, 2025
d84caa2
hacky way to run permian SOA
kurbansitterley Jan 3, 2025
2891741
Permian Subtheme 1 MD flowsheet added and black
MuktaHardikar Jan 3, 2025
af77e2b
matching density in ZO and SW packages
MuktaHardikar Jan 3, 2025
7a175b3
fix pressure ratio in solve func
kurbansitterley Jan 3, 2025
cc38977
update __all__
kurbansitterley Jan 3, 2025
e6abce3
Merge branch 'permian' of https://github.com/watertap-org/watertap-re…
kurbansitterley Jan 3, 2025
d2b55e4
change feed_to_mvc tds source
kurbansitterley Jan 3, 2025
8ddf606
rever TDS calc
kurbansitterley Jan 3, 2025
72ec29b
fix zo_to_sw translator block, black
MuktaHardikar Jan 3, 2025
1084081
pretreatment checkpoint before attempt at sweep
kurbansitterley Jan 4, 2025
c62b689
SOA checkpoint
kurbansitterley Jan 6, 2025
f27d226
Merge branch 'main' of https://github.com/kurbansitterley/watertap-re…
kurbansitterley Jan 7, 2025
06d221a
Merge branch 'mec_modift' of https://github.com/kurbansitterley/water…
kurbansitterley Jan 7, 2025
42253be
kbhdp md component fix, permian st1 md fix
MuktaHardikar Jan 9, 2025
061aee4
CST updates with permian pkl and json heat 1-50
MuktaHardikar Jan 10, 2025
b3731d1
update filepaths in pysam_run_permian trough
MuktaHardikar Jan 10, 2025
306004e
Adding trough surrogate files
MuktaHardikar Jan 13, 2025
6042e3a
Add trough pkl
MuktaHardikar Jan 13, 2025
eee1a13
adding mec files and updates to permian
MuktaHardikar Jan 29, 2025
63b88c4
working ST2 MD without CST
MuktaHardikar Feb 10, 2025
c965fcc
fixed hours of storage pkl
MuktaHardikar Feb 10, 2025
c0e9e81
trough 1-100 fixed storage pkl
MuktaHardikar Feb 10, 2025
95cba60
CST model updated for pySAM version 6.0.0
MuktaHardikar Feb 12, 2025
713fa45
updated file name and ran black
MuktaHardikar Feb 12, 2025
8ad1097
updates to permian and kbhdp branchs and. Adding json and pkl
MuktaHardikar Feb 13, 2025
350dc67
added number of points to the pysam_run_trough, fix cost package unit…
MuktaHardikar Feb 13, 2025
eea3746
add kbhdp pkl
MuktaHardikar Feb 13, 2025
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: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"watertap==1.0.0rc0",
"idaes-pse==2.5.0",
"pyomo==6.7.3",
"nrel-pysam == 5.1.0",
"nrel-pysam == 6.0.0",
],
extras_require={
"dev": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Block,
Constraint,
SolverFactory,
Param,
)
import os

Expand All @@ -30,6 +31,8 @@
EnergyCosting,
)

import pickle

__all__ = [
"build_cst",
"init_cst",
Expand Down Expand Up @@ -58,67 +61,101 @@ def build_cst(blk, __file__=None):

if __file__ == None:
cwd = os.getcwd()
__file__ = cwd + r"\src\watertap_contrib\reflo\solar_models\surrogate\trough\\"
__file__ = (
cwd + "/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/data/cst/"
)

dataset_filename = os.path.join(
os.path.dirname(__file__), r"data\test_trough_data.pkl"
os.path.dirname(__file__),
r"trough_kbhdp_heat_load_1_50_hours_storage_24_T_loop_out_300.pkl",
)

# Updating pickle file output column names
with open(dataset_filename, "rb") as f:
df = pickle.load(f)

# Rename the columns
df.rename(columns={"annual_energy": "heat_annual"}, inplace=True)
df.rename(columns={"electrical_load": "electricity_annual"}, inplace=True)

# Save the modified DataFrame back as a pickle
with open(dataset_filename, "wb") as f:
pickle.dump(df, f)

surrogate_filename = os.path.join(
os.path.dirname(__file__),
r"data\test_trough_data_heat_load_100_500_hours_storage_0_26.json",
r"trough_kbhdp_heat_load_1_50_hours_storage_24_T_loop_out_300.json",
)

input_bounds = dict(heat_load=[100, 500], hours_storage=[0, 26])
input_units = dict(heat_load="MW", hours_storage="hour")
input_bounds = dict(heat_load=[1, 50]) # , hours_storage=[23, 24])
input_units = dict(heat_load="MW") # , hours_storage="hour")
input_variables = {
"labels": ["heat_load", "hours_storage"],
"labels": ["heat_load"], # "hours_storage"],
"bounds": input_bounds,
"units": input_units,
}

output_units = dict(heat_annual_scaled="kWh", electricity_annual_scaled="kWh")
output_units = dict(
heat_annual_scaled="kWh",
electricity_annual_scaled="kWh",
total_aperture_area_scaled="m**2",
)
output_variables = {
"labels": ["heat_annual_scaled", "electricity_annual_scaled"],
"labels": [
"heat_annual_scaled",
"electricity_annual_scaled",
"total_aperture_area_scaled",
],
"units": output_units,
}

blk.unit = TroughSurrogate(
surrogate_model_file=surrogate_filename,
# surrogate_model_file=surrogate_filename,
surrogate_filename_save=surrogate_filename,
dataset_filename=dataset_filename,
input_variables=input_variables,
output_variables=output_variables,
scale_training_data=True,
)

if hasattr(blk.unit, "hours_storage"):
print("Hours of storage is already any input parameter")
else:
print("Creating hours of storage parameter")
blk.unit.hours_storage = Param(initialize=24, units=pyunits.h, mutable=True)


def init_cst(blk):
# Fix input variables for initialization
blk.unit.hours_storage.fix()
blk.unit.heat_load.fix()
blk.unit.initialize()

blk.unit.heat_load.unfix()


def set_system_op_conditions(m):
m.fs.system_capacity.fix()


def set_cst_op_conditions(blk, hours_storage=6):
blk.unit.hours_storage.fix(hours_storage)
def set_cst_op_conditions(blk, heat_load=10, hours_storage=6):

if isinstance(m.fs.cst.unit.hours_storage, pyo.Param):
blk.unit.hours_storage.set_value(hours_storage)

if isinstance(m.fs.cst.unit.hours_storage, pyo.Var):
blk.unit.hours_storage.fix(hours_storage)
blk.unit.heat_load.fix(heat_load)


def add_cst_costing(blk, costing_block):
blk.unit.costing = UnitModelCostingBlock(flowsheet_costing_block=costing_block)


def calc_costing(m, blk):
blk.costing.heat_cost.set_value(0)
blk.costing.cost_process()
# Updated to be 0 because this factor is not included in SAM
blk.costing.maintenance_labor_chemical_factor.fix(0)
blk.costing.initialize()

# TODO: Connect to the treatment volume
blk.costing.add_LCOW(m.fs.system_capacity)
# blk.costing.add_LCOW(m.fs.system_capacity)


def report_cst(m, blk):
Expand Down Expand Up @@ -149,9 +186,9 @@ def report_cst_costing(m, blk):
print(f"\n\n-------------------- CST Costing Report --------------------\n")
print("\n")

print(
f'{"LCOW":<30s}{value(blk.costing.LCOW):<20,.2f}{pyunits.get_units(blk.costing.LCOW)}'
)
# print(
# f'{"LCOW":<30s}{value(blk.costing.LCOW):<20,.2f}{pyunits.get_units(blk.costing.LCOW)}'
# )

print(
f'{"Capital Cost":<30s}{value(blk.costing.total_capital_cost):<20,.2f}{pyunits.get_units(blk.costing.total_capital_cost)}'
Expand Down Expand Up @@ -181,14 +218,6 @@ def report_cst_costing(m, blk):
# f'{"Heat Cost":<30s}{value(blk.costing.aggregate_flow_costs["heat"]):<20,.2f}{pyunits.get_units(blk.costing.aggregate_flow_costs["heat"])}'
# )

# print(
# f'{"Elec Flow":<30s}{value(blk.costing.aggregate_flow_electricity):<20,.2f}{pyunits.get_units(blk.costing.aggregate_flow_electricity)}'
# )

# print(
# f'{"Elec Cost":<30s}{value(blk.costing.aggregate_flow_costs["electricity"]):<20,.2f}{pyunits.get_units(blk.costing.aggregate_flow_costs["electricity"])}'
# )


if __name__ == "__main__":

Expand All @@ -199,17 +228,47 @@ def report_cst_costing(m, blk):

build_cst(m.fs.cst)

set_cst_op_conditions(m.fs.cst, heat_load=50, hours_storage=24)
init_cst(m.fs.cst)

set_cst_op_conditions(m.fs.cst)

add_cst_costing(m.fs.cst, costing_block=m.fs.costing)
calc_costing(m, m.fs)
m.fs.costing.aggregate_flow_heat.fix(-70000)
results = solver.solve(m)

print(degrees_of_freedom(m))
report_cst(m, m.fs.cst.unit)
report_cst_costing(m, m.fs)

# m.fs.costing.used_flows.display()
print(
f'{"Elec Flow":<30s}{value(m.fs.costing.aggregate_flow_electricity):<20,.2f}{pyunits.get_units(m.fs.costing.aggregate_flow_electricity)}'
)

print(
f'{"Elec Cost":<30s}{value(m.fs.costing.aggregate_flow_costs["electricity"]):<20,.2f}{pyunits.get_units(m.fs.costing.aggregate_flow_costs["electricity"])}'
)

m.fs.costing.add_LCOH()
print("LCOH:", m.fs.costing.LCOH())
print("Hours of storage:", m.fs.cst.unit.hours_storage())
print("Aperture area:", m.fs.cst.unit.total_aperture_area())

print("CST fixed cost:", m.fs.cst.unit.costing.fixed_operating_cost())

# Calcualating LCOH like SAM
cost = m.fs.costing
lcoh = (
cost.total_capital_cost * cost.capital_recovery_factor
+ cost.total_operating_cost
) / m.fs.cst.unit.heat_annual

print("\nManual LCOH check\n")
print("CRF:", cost.capital_recovery_factor())
print(
"Numerator:",
(
cost.total_capital_cost * cost.capital_recovery_factor
+ cost.total_operating_cost
)(),
)
print("Denominator:", m.fs.cst.unit.heat_annual())
print("Calculated LCOH:", lcoh())
Original file line number Diff line number Diff line change
Expand Up @@ -225,27 +225,31 @@ def init_md(blk, verbose=True, solver=None):
# Build connection to permeate state junction
blk.permeate.properties[0]._flow_vol_phase

@blk.Constraint(
doc="Assign the permeate flow rate to its respective state junction"
)
def get_permeate_flow(b):
num_modules = b.mp.get_active_process_blocks()[-1].fs.vagmd.num_modules
# num_modules = b.unit.mp.get_active_process_blocks()[-1].fs.vagmd.num_modules

return (
b.permeate.properties[0].flow_vol_phase["Liq"]
==
# pyunits.convert(
pyunits.convert(
(
num_modules
* b.mp.get_active_process_blocks()[-1].fs.acc_distillate_volume
/ (
b.mp.get_active_process_blocks()[-1].fs.dt
* (blk.n_time_points - 1)
)
),
to_units=pyunits.m**3 / pyunits.s,
vagmd = b.unit.mp.get_active_process_blocks()[-1].fs.vagmd
num_modules = pyunits.convert(
vagmd.system_capacity
/ sum(
b.unit.mp.get_active_process_blocks()[i].fs.vagmd.permeate_flux
for i in range(blk.n_time_points)
)
* blk.n_time_points
/ b.unit.mp.get_active_process_blocks()[0].fs.vagmd.module_area,
to_units=pyunits.dimensionless,
)

return b.permeate.properties[0].flow_vol_phase["Liq"] == pyunits.convert(
(
num_modules
* b.unit.mp.get_active_process_blocks()[-1].fs.acc_distillate_volume
/ (
b.unit.mp.get_active_process_blocks()[-1].fs.dt
* (blk.n_time_points - 1)
)
),
to_units=pyunits.m**3 / pyunits.s,
)

blk.permeate.properties[0].flow_mass_phase_comp["Liq", "TDS"].fix(0)
Expand All @@ -261,15 +265,18 @@ def get_permeate_flow(b):
doc="Assign the concentrate flow rate to its respective state junction"
)
def get_concentrate_flow(b):
num_modules = b.mp.get_active_process_blocks()[-1].fs.vagmd.num_modules
num_modules = b.unit.mp.get_active_process_blocks()[-1].fs.vagmd.num_modules

return b.concentrate.properties[0].flow_vol_phase["Liq"] == pyunits.convert(
(
num_modules
* blk.model_options["initial_batch_volume"]
* pyunits.L
* (1 - b.mp.get_active_process_blocks()[-1].fs.acc_recovery_ratio)
/ (b.mp.get_active_process_blocks()[-1].fs.dt * (blk.n_time_points - 1))
b.unit.mp.get_active_process_blocks()[-1].fs.vagmd.system_capacity
* (1 - m.water_recovery)
/ m.water_recovery
# num_modules
# * blk.model_input["initial_batch_volume"]
# * pyunits.L
# * (1 - b.unit.mp.get_active_process_blocks()[-1].fs.acc_recovery_ratio)
# / (b.unit.mp.get_active_process_blocks()[-1].fs.dt * (blk.n_time_points - 1))
),
to_units=pyunits.m**3 / pyunits.s,
)
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Loading