Skip to content
Snippets Groups Projects

Update cyclus_input.py to shorten variable input lists

Merged maxschalz requested to merge (removed):pakistan into pakistan
1 file
+ 28
22
Compare changes
  • Side-by-side
  • Inline
@@ -8,6 +8,7 @@ script placed in this repository under
import argparse
import json
import math
import pandas
import sys
from nrx_spent_fuel_composition import SpentFuelCalculator
@@ -338,13 +339,15 @@ def feed_throughput_per_swu():
max_feed = max_feed * GLOBAL_PARAMS["dt"] / SECONDS_PER_YEAR
return max_feed
def yearly_rates_to_sim_steps(var, var_name, t_init=0):
def yearly_rates_to_sim_steps(var, time, var_name):
"""Convert yearly rates in `var` into simulation timestep rates.
Parameters
----------
var : array-like
Array to be converted. Must contain *yearly* rates.
time : array-like
Corresponding years.
var_name : str
Name of the variable. Only relevant for error messages.
t_init : int
@@ -353,22 +356,24 @@ def yearly_rates_to_sim_steps(var, var_name, t_init=0):
Returns
-------
converted_var : list
Contains the rates in units of simulation timesteps with as many
entries as timesteps in the simulation.
Has as many entries as `var` but in units of simulation timestep rates.
converted_time : list
Years from `time` converted to simulation timesteps.
"""
if len(var) != len(time):
raise RuntimeError("'var' and 'time' must have the same dimension.")
if isinstance(time, pandas.core.series.Series):
t0 = time.iloc[0]
else:
t0 = time[0]
sim_steps_per_year = SECONDS_PER_YEAR // GLOBAL_PARAMS["dt"]
converted_var = [v * GLOBAL_PARAMS["dt"] / SECONDS_PER_YEAR
for v in var for _ in range(int(sim_steps_per_year))]
for v in var]
converted_time = [int((t-t0) * sim_steps_per_year) for t in time]
if GLOBAL_PARAMS["duration"] is None:
control()
if len(converted_var) < GLOBAL_PARAMS["duration"] - t_init:
raise RuntimeError(f"{var_name} does not cover the the whole duration "
"of the simulation.")
elif len(converted_var) > GLOBAL_PARAMS["duration"]:
converted_var = converted_var[:GLOBAL_PARAMS["duration"]]
return converted_var
return converted_var, converted_time
def simulation_duration(startyear):
"""Get the duration of the simulation in units of simulation timesteps.
@@ -569,11 +574,12 @@ def facilities():
* SECONDS_PER_YEAR / GLOBAL_PARAMS["dt"])
# Convert data into appropriate rates.
mine_throughput = yearly_rates_to_sim_steps(mine_production["mass"],
'mine_production["mass"]')
swu_capacity = yearly_rates_to_sim_steps(
swu_capacity["swu"], 'swu_capacity["swu"]', t_init=enrichment_entry_ts
)
mine_throughput_vals, mine_throughput_times= yearly_rates_to_sim_steps(
mine_production["mass"], mine_production["year"],
'mine_production["mass"]')
swu_capacity_vals, swu_capacity_times = yearly_rates_to_sim_steps(
swu_capacity["swu"], swu_capacity["year"], 'swu_capacity["swu"]')
leu_storage_data, wgu_sink_data = generate_leu_data(simulation_startyear)
facilities_dict = {"facility": [
@@ -584,8 +590,8 @@ def facilities():
"out_commod": "MinedU",
"out_recipe": "NaturalURecipe",
"inventory_size": 1e299,
"throughput_times": {"val": [-1]},
"throughput_vals": {"val": mine_throughput},
"throughput_times": {"val": mine_throughput_times},
"throughput_vals": {"val": mine_throughput_vals},
}
}
}, {
@@ -603,8 +609,8 @@ def facilities():
"enrichment_max_feed_inv"],
"max_enrich": 1.,
"order_prefs": False,
"swu_capacity_times": {"val": [-1]},
"swu_capacity_vals": {"val": swu_capacity}
"swu_capacity_times": {"val": swu_capacity_times},
"swu_capacity_vals": {"val": swu_capacity_vals}
}
}
}, {
Loading