Skip to content

Instantly share code, notes, and snippets.

View jd-lara's full-sized avatar
🔨

Jose Daniel Lara jd-lara

🔨
  • National Renewable Energy Laboratory
  • Denver, Colorado
  • 20:37 (UTC -06:00)
View GitHub Profile
@jd-lara
jd-lara / Ybus_example.jl
Last active April 29, 2019 17:57
Ybus Calculations with PowerSystems.jl
using PowerSystems
const PSY = PowerSystems;
# Getting data for the YBus
pm_dict = PowerSystems.parse_file(joinpath(MATPOWER_DIR, "case5.m"));
ps_dict = PowerSystems.pm2ps_dict(pm_dict);
Buses, Generators, Storages, Branches, Loads, Shunts, Services = PowerSystems.ps_dict2ps_struct(ps_dict);
# Getting PTDF calculated
Ybus = PSY.build_ybus(length(Buses), Branches)
@jd-lara
jd-lara / 2statemachine.jl
Last active May 7, 2019 00:39
2-state model of a synchronous machine example
"""
Example of modeling a 2-state synchronous machine in Julia with DifferentialEquations.jl
Uses a simple statement inside of the function to make the step change, this can be improved with callbacks
Refer to Power System Modelling and Scripting for the equations
"""
using DifferentialEquations
using NLsolve
using Plots
###### Machine Parameter Struct ######
@jd-lara
jd-lara / bridges_diff.jl
Last active May 18, 2019 17:41
Ipopt_bridges
using JuMP
using Ipopt
using Random
ipopt_optimizer = with_optimizer(Ipopt.Optimizer, print_level = 5)
lb_noise = rand(10);
ub_noise = rand(10);
lb = -2 .- lb_noise
ub = 2 .+ ub_noise
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
using JuMP
using Gurobi
using Random
Gurobi_optimizer = with_optimizer(Gurobi.Optimizer)
# Generate Data
data_ub = rand(100) .+ 1
data_lb = rand(100) .- 1
;
##########Function Defs###################
function obtain_raw_data(base_dir::String, sha::String)
data_path = joinpath(base_dir,"raw_input_data")
ispath(data_path) && rm(data_path, recursive = true)
mkpath(data_path)
if Sys.iswindows()
POWERSYSTEMSTESTDATA_URL = "https://github.com/GridMod/RTS-GMLC/archive/$(sha).zip"
else
POWERSYSTEMSTESTDATA_URL = "https://github.com/GridMod/RTS-GMLC/archive/$(sha).tar.gz"
using JuMP
using Ipopt
m = Model(Ipopt.Optimizer);
# Indexes
I = 1:2
J = 1:2
#Variables
@variable(m, x[i in I] >= 0)
# Parameters
@jd-lara
jd-lara / stackoverflow.log
Created May 9, 2020 22:45
Error Stackoverflow GG.jl
Internal error: encountered unexpected error in runtime:
StackOverflowError()
intersect at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:0
intersect_invariant at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2742
intersect at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:3002
intersect_tuple at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2642 [inlined]
intersect at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2958
intersect_unionall_ at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2491
intersect_unionall at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:2539
intersect at /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c:0
@jd-lara
jd-lara / market_sim.jl
Last active November 23, 2020 18:22
Run UC - ED simulation with RH and lmp exports
using PowerSystems
const PSY = PowerSystems
using PowerSystems: UtilsData
using PowerSimulations
const PSI = PowerSimulations
using Dates
using TimeSeries
using Random
using Cbc
using GLPK