Skip to content

Commit

Permalink
Add method for setting voltage angles in states (#191)
Browse files Browse the repository at this point in the history
* set bus voltage angle

* change order of tests to avoid numerical errors
  • Loading branch information
antonplietzsch authored Jun 17, 2022
1 parent ac3cbf0 commit 64b83da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/common/States.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ Base.setindex!(s::State, v, n, ::Type{Val{:v}}) = begin
u = s[n, :u]
s[n, :u] = v.*u./abs.(u)
end
Base.setindex!(s::State, v, n, ::Type{Val{:φ}}) = begin
u = s[n, :u]
s[n, :u] = abs.(u).*exp.(im.*v)
end
Base.setindex!(s::State, v, n, ::Type{Val{:var}}, i) = begin
s[internalindex(s, n, i)] = v
end
Expand Down
11 changes: 11 additions & 0 deletions test/common/States.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ s_2 = state_from_dict["bus2", :u] * conj(i_2)
@test state_from_dict[:, :p] == real(state[:, :u] .* conj.([i_1, i_2, i_3]))
@test state_from_dict[:, :q] == imag(state[:, :u] .* conj.([i_1, i_2, i_3]))

# exchange phi
state[2, ] = φ_Sw2
@test state[2:3, ] [φ_Sw2, φ_Sw2]
state[2:3, ] = [φ_Sw1, φ_Sw2]
@test state[2:3, ] [φ_Sw1, φ_Sw2]

state_from_dict["bus2", ] = φ_Sw2
@test state_from_dict[["bus2","bus3"], ] [φ_Sw2, φ_Sw2]
state_from_dict[["bus2","bus3"], ] = [φ_Sw1, φ_Sw2]
@test state_from_dict[["bus2","bus3"], ] [φ_Sw1, φ_Sw2]

## binary operations ##
s1 = State(grid, ones(systemsize(grid)))
s2 = State(grid, ones(systemsize(grid)))
Expand Down

2 comments on commit 64b83da

@antonplietzsch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/62503

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.0.2 -m "<description of version>" 64b83da7b8ec5324e93035e923cbb50a3193417f
git push origin v3.0.2

Please sign in to comment.