Charging Sim

Module contents

Submodules

Battery module

Battery Aging Sim module

This module contains the BatteryAging class. The battery aging objects enact on the battery object and update the battery capacity and resistance at each simulation time-step.

class charging_sim.batteryAgingSim.BatteryAging(datetime, num_steps, res=15)

Bases: object

Current aging model is for LiNiMnCoO2 (NMC) battery cells. More aging models will be added in the future.

Link to Paper: https://www.sciencedirect.com/science/article/pii/S0378775314001876

Default Params from paper:
  • beta_cap: capacity fade aging factor for cycle aging

  • alpha_cap capacity fade aging factor for calendar aging

  • beta_res: resistance growth aging factor for cycle aging

  • alpha_res: resistance growth aging factor for calendar aging

Assumptions:
  • Homogenous battery with dynamics modelled.

  • Uniform aging across all cells.

  • Constant temperature profile in vicinity of battery.

static LFP_cal_aging()
static LFP_cyc_aging()
static NMC_cal_aging()
static NMC_cyc_aging()
get_aging_value(battery)

Returns the total capacity fade and resistance growth of the battery object.

Parameters:

battery – The battery (pack) object.

Returns:

List of total capacity fade and resistance growth of the battery.

get_calendar_aging(battery)

Returns the calendar aging of the battery object.

Parameters:

battery – The battery object.

Returns:

A tuple of capacity fade and resistance growth due to calendar aging.

get_cyc_aging(battery)

Calculates the resistance growth and capacity fade from cycle aging.

Parameters:

battery – THe batt

Returns:

get_total_aging(battery: object)

Returns the total capacity fade of the battery object. This includes both cycle and calendar aging.

Parameters:

battery (object) – The battery (pack) object.

Returns:

Total calendar + cycle aging of the battery.

run(battery)

Runs the aging model for the battery object.

Parameters:

battery – The battery (pack) object.

Returns:

None. Updates the battery object.

update_capacity(battery)

Updates the capacity of the battery based on the aging model adopted from Schmalsteig Et. Al.

Parameters:

battery – Battery object.

Returns:

None. Updates the battery object capacity.

update_resistance(battery)

Updates the resistance of the battery based on the aging model adopted from Schmalsteig Et. Al.

Parameters:

battery – Battery object.

Returns:

None. Updates the battery object resistance.

Battery pack module

Capacitor module

This file hosts the class for capacitors. Future work

class charging_sim.capacitor.Capacitor(config)

Bases: object

Charging Station module

Clock module

This module defines the clock class. This allows ease of temporal understanding of different timescales within the simulation.

class charging_sim.clock.Clock(config)

Bases: object

This class defines the clock for the simulation. It allows ease of temporal understanding of different timescales.

Parameters:

config (dict) – Configuration dictionary.

Derived attributes:

pf_dt: Powerflow timestep in seconds.

trans_dt: Transformer timestep in seconds.

battery_dt: Battery timestep in seconds.

dt: Clock timestep in seconds.

it: Iteration number (usually starts at 0).

reset()

Reset the clock.

update()

Update the clock.

Controller module

Electricity prices module

Overview This module contains the class that loads the electricity price data and structure used for sampling prices during simulation.

Details

Based on the prices.json config file, this module will load the desired price TOU rate file that will be used in optimization problem. The default is the PGE_BEV2_S rate file, which is valid for California, however users can load their own TOU rate file. The prices are loaded into a numpy array and can be sampled from during simulation. The prices are sampled based on the month of the year and the hour of the day.

class charging_sim.electricityPrices.PriceLoader(config, path_prefix=None)

Bases: object

This class pre-loads prices and is used to sample prices that are used for optimization of EVSE profits/costs during charging simulation.

Parameters:
  • config (dict) – Configuration dictionary for the price loader.

  • path_prefix – This string path prefix is obtained first based on your repository location to set the

correct path for obtaining the data.

downscale(input_res, output_res)

Downscales the price data into a finer resolution, similar to the downscaling method in Pandas. Typically only used once.

Parameters:
  • input_res – Resolution of the input data.

  • output_res – Resolution of the output data.

Returns:

None. Saves output data to a csv file.

get_prices(start_idx, num_steps, month=7)

Returns time-of-use (TOU) rate prices from data. This assumes TOU rates do not change day-to-day.

Parameters:
  • start_idx (int) – Starting index from which to price vector will start.

  • num_steps (int) – Cardinality of the price vector being returned.

  • month (int) – Month for which the price vector will be obtained (for example, 1 - Jan, 12 - December).

Return price_vector:

The TOU price vector, which is a numpy array.

set_month_data(month)

Sets the month for which the prices will be obtained.

Parameters:

month – Month to set the data to.

Returns:

None.

Node module

class charging_sim.node.Node(name, idx, storage, solar, controller=None, others=None, children=None, parent=None)

Bases: object

Node object class for defining relevant node_name for co-simulation. It helps organize centralized DER assets within their respective grid locations. This is only used for centralized DER simulations and it is not used for collocated EVSE and DER simulations.

For example, within the centralized simulation, if there are multiple secondary feeders connected to a single primary feeder, then the primary feeder would be a node_name and the secondary feeders would be children of that node_name. Thus, when power injections at each time step are calculated through optimization, the controller and orchestrator knows the load at each child node, which is then aggregated to control the DER assets at the parent node.

Parameters:
  • name – Name of the node_name.

  • idx – Index of the node_name.

  • storage – Storage object.

  • solar – Solar object.

  • controller – Controller object.

  • children – List of children nodes.

  • parent – Parent node.

add_child(node: object)

Adds a child node_name to the current node_name.

Parameters:

node – Node object.

Returns:

None.

get_current_load()

Returns the current load of the charging station.

Returns:

Current load (kW) of the charging station.

save_sim_data(save_prefix: str)

Saves all relevant simulation data to csv files.

Parameters:

save_prefix – Path string to save the data from simulation.

Returns:

None.

set_current_load(load)

Sets the current load of the charging station.

Parameters:

load – Load in kW.

Returns:

None.

update_load(net_grid_load, ev_load)

Updates the node_name loads, including DER assets. MPC mode.

Parameters:
  • net_grid_load – Net load charging station pulls from the grid.

  • ev_load – Sum of all electric vehicle charging demand within that primary feeder node_name.

Optimization module

Contains the Optimization class, which is used by controller to solve the optimization problem.

class charging_sim.optimization.Optimization(objective_type, objective, controller, power_demand, time_res, transformer, battery, time=0, name=None, solar=None, solver='GUROBI')

Bases: object

Constructor for the overall optimization problem solved by the optimization-based controller.

  • Designed to include future cost functions such as transformer degradation and battery aging.

  • Limited to convex and Mixed Integer programs, depending on the selected solver.

  • Note, each desired solver must be installed separately on user’s PC for a successful run.

Parameters:
  • objective_type – Type of objective problem being optimized.

  • objective – CVXPY objective function object.

  • controller – Controller object.

  • power_demand – Power demand at the Charging Station.

  • time_res – Time resolution of problem data.

  • transformer – Transformer object (optional, not implemented yet).

  • battery – Battery object.

  • time – Time Counter.

  • name – Optimization identifier.

  • solar – Solar Object.

  • solver (str) – Available backend solver to invoke (ECOS, MOSEK, GUROBI, etc.).

add_demand_charge(charge)

Including demand charge in the objective function (Deprecated).

Parameters:

charge – Demand charge ($/kW).

Returns:

aggregate_constraints()

Aggregates all the constraints into one constraint list within the object.

Returns:

None.

build_battery_cost()

Build battery cost (to be implemented in future version).

Returns:

build_emissions_cost()

Builds emission cost to be included in the objective function (future work).

Returns:

build_transformer_cost()

Build Transformer cost (to be implemented in future version).

Returns:

get_battery_constraint()

Returns the list of battery constraints within the controller.

Returns:

Battery constraints.

get_constraints()

Returns the constraints list.

Returns:

List of all constraints within the problem.

run()

Runs an instance of the optimization problem.

Return float:

Optimal objective value.

Orchestrator module

Simulate module

Solar module

This module contains the Solar class. The solar class is used to simulate the solar power generation at a given site by sampling Global Horizontal Irradiance (GHI) data from the dataset of the desired location.

class charging_sim.solar.Solar(config, path_prefix=None, controller=None, num_steps=None)

Bases: object

This class is used to simulate the solar power generation at a given site by sampling Global Horizontal Irradiance and estimating the solar generation, given the solar nameplate capacity that can be modified it its configuration file solar.json. It also contains the optimization variables for the solar system.

The solar power generation is estimated using the following equation:

\[P_{solar} = \min(P_{rated}, \eta * A * GHI).\]

Where \(P_{solar}\) is the solar power generation, \(\eta\) is the efficiency of the solar system, \(P_{rated}\) is the solar nameplate capacity, \(A\) is the area of the solar panels, and \(GHI\) is the Global Horizontal Irradiance.

Parameters:
  • config – Solar configuration dictionary.

  • path_prefix – This string path prefix is obtained first based on your repository location to set the right path.

  • controller – Controller object for making decisions on flow of power from energy devices.

  • num_steps – Number of steps in the simulation.

downscale(input_res, output_res)

This is used only to initially downscale data to desired resolution

get_constraints()
get_power(start_idx, num_steps, desired_shape=(96, 1), month=None)
get_solar_output()
modify_res(new_res)
update_history()
charging_sim.solar.main()

THis is mainly to testing or generating new data purposes

Transformer module

Module for the transformer class. This module contains classes for simulating the thermal dynamics of transformers.

class charging_sim.transformer.OilTypeTransformer(config, global_clock=None, temperature_data=None)

Bases: object

plot_states()

Plot the transformer thermal states.

Returns:

None.

thermal_dynamics(power: float)

Propagate transformer state from previous timestep to current timestep (currently it is a minute resolution data simulated in 10 seconds increment). Nonlinear model from Swift et. Al (2001).

Returns:

None.

Utils

Stores general configurations and general functions

charging_sim.utils.PGE_BEV2_S()

Price schedule/TOU rate for PGE EVSE doc can be found here:

charging_sim.utils.add_power_profile_to_object(battery, index, battery_power_profile)
charging_sim.utils.build_cost_PGE_BEV2S(controller, load, energy_prices_TOU, penalize_max_power=True, max_power_pen=1000)

This will need to use a heuristic and take the average conservative estimate for gamma

charging_sim.utils.build_electricity_cost(controller, load, energy_prices_TOU, demand_charge=False)

Need to update from home load right now; maybe this can be useful in future opt.

charging_sim.utils.build_objective(mode, electricity_cost, battery_degradation_cost, emissions_cost=0, transformer_cost=0)

Builds the objective function that we will minimize.

charging_sim.utils.load_prices(time_intervals, price, price_vector)