Skip to content
This repository was archived by the owner on Sep 4, 2024. It is now read-only.

Commit f4789c6

Browse files
authored
updating the docs (#8)
* updated docs and added doc test to ci * fixing ci
1 parent 2902089 commit f4789c6

File tree

10 files changed

+135
-27
lines changed

10 files changed

+135
-27
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ matrix:
2727
# apt: # apt-get for linux
2828
# packages:
2929
# - gfortran
30-
#before_script: # homebrew for mac
30+
before_script: # homebrew for mac
3131
# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi
32+
- julia -e 'using Pkg; Pkg.add(PackageSpec(name="Documenter", version="0.19"))'
3233

3334
## uncomment the following lines to override the default test script
34-
#script:
35-
# - julia -e 'Pkg.clone(pwd()); Pkg.build("DPSABase"); Pkg.test("DPSABase"; coverage=true)'
35+
script:
36+
# - julia -e 'Pkg.clone(pwd()); Pkg.build("DPSABase"); Pkg.test("DPSABase"; coverage=true)'
37+
- julia --check-bounds=yes --color=yes -e "using Pkg; Pkg.test(coverage=true)"
38+
- julia docs/make.jl
3639
after_success:
3740
# push coverage results to Coveralls
3841
# - julia -e 'cd(Pkg.dir("DPSABase")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ makedocs(
77
# html options
88
format = :html,
99
sitename = "PowerDynBase.jl",
10-
pages = ["index.md"])
10+
pages = ["index.md"],
11+
strict=true)

src/DEVariables.jl

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,33 @@ using MacroTools
77
issymbol(::Symbol) = true
88
issymbol(::Any) = false
99

10-
"Abstract super type for all variables that AbstractNodeDynamics sub types can be called with."
10+
"""
11+
abstract type AbstractDEVariable end
12+
13+
Abstract super type for all variables that [PowerDynBase.AbstractNetworkFunction`] sub-types can be called with.
14+
15+
DEVariable stands for Differential Equation Variable.
16+
17+
The basic idea of a DEVariable is to combine (the arrays of) all necessary variables for a sub-type of [`PowerDynBase.GridDynamics`].
18+
E.g. for a [`PowerDynBase.OrdinaryGridDynamics`] one needs only the state variable (here called `val` for value) and the derivative
19+
(here called `ddt`). Hence, the definition for the corresponding [`PowerDynBase.ODEVariable`] is:
20+
21+
@DEVariable struct ODEVariable{Tval, Tddt} <: AbstractODEVariable
22+
val::AbstractVector{Tval}
23+
ddt::AbstractVector{Tddt}
24+
end ddt
25+
26+
The final `ddt` statement is part of the [`PowerDynBase.@DEVariable`] macro stating that the output variable of this kind of DEVariable
27+
is `ddt`. Further, the [`PowerDynBase.@DEVariable`] macro generates all the necessary constructors. Check its docs for more details.
28+
"""
1129
abstract type AbstractDEVariable end
1230

1331
"""
1432
function mapfields(f, s, args...)
1533
1634
Applies `f` to all fields of (the struct) `s` giving `args...` as additional arguments.
35+
36+
It's written as a `@generated` function in order to ensure that the compiler can infer the types.
1737
"""
1838
@generated function mapfields(f, s, args...)
1939
Expr(:call, nameof(s), [:(f(s.$field, args...)) for field in fieldnames(s) ]...)
@@ -24,7 +44,7 @@ function view(var::AbstractDEVariable, range)
2444
mapfields(view, var, range)
2545
end
2646

27-
"Extend complexview from arrays to subtypes of [`AbstractDEVariable`](#ref)."
47+
"Extend [`PowerDynBase.complexview`] from arrays to subtypes of [`AbstractDEVariable`](#ref)."
2848
function complexview(var::AbstractDEVariable, i0, num)
2949
mapfields(complexview, var, i0, num)
3050
end
@@ -39,8 +59,8 @@ excomparison(exs) = Expr(:comparison, _excomparison(exs...)...)
3959
"""
4060
Basically, this macro generates all the constructors (internal and external) for a subtype of AbstracDEVariable.
4161
42-
If you really want to understand this macro, uncomment the `println(ex)` statement at the end and check the resulting
43-
generated expression.
62+
If you want to understand what this macro does, call [`PowerDynBase.showdefinition`](#ref) with a type that was generated by this macro, e.g.
63+
`showdefinition(ODEVariable)`. It will output the full defintion that the macro actually creates.
4464
"""
4565
function create_DEVariable(structdef, outputfield::Symbol)
4666
structdef = deepcopy(structdef)
@@ -80,6 +100,19 @@ function create_DEVariable(structdef, outputfield::Symbol)
80100
ex
81101
end
82102

103+
"""
104+
@DEVariable struct DEVariableName{Type1, Type2, ...} <: AbstractODEVariable
105+
...
106+
end outputVariableName
107+
108+
Basically, this macro generates all the constructors (internal and external) for a subtype of AbstracDEVariable.
109+
In particular, it creates an external constructor that automatically chooses the type for the `outputVariableName` and instantiates this variable.
110+
111+
If you want to understand what this macro does, call [`PowerDynBase.showdefinition`](#ref) with a type that was generated by this macro, e.g.
112+
`showdefinition(ODEVariable)`. It will output the full defintion that the macro actually creates.
113+
114+
Furthermore, the macro is just the interface for the [`PowerDynBase.create_DEVariable`] function.
115+
"""
83116
macro DEVariable(structdef, outputfield)
84117
mainex = create_DEVariable(structdef, outputfield)
85118
@capture(structdef, struct name_{__} <: _

src/DynamicNodeMacro.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function getinternalvars(::Type{Val{T}}, args...;kwargs...) where {T}
8484
throw(NodeDynamicsError("unknown node dynamics type $T"))
8585
end
8686

87-
"""See [`DPSABase.@DynamicNode`](#ref)."""
87+
"""See [`PowerDynBase.@DynamicNode`](#ref)."""
8888
function DynamicNode(typedef, prep, internalsdef, func_body)
8989
@capture(typedef, name_(parameters__) <: dynamicscall_)
9090
dynamicstype = dynamicscall.args[1]
@@ -172,5 +172,6 @@ macro DynamicNode(typedef, prep, internals, func_body)
172172
return esc(mainex)
173173
end
174174

175-
"Show the definition generated by [`DPSABase.@DynamicNode`](#ref) for a subtype of [`AbstractNodeParameters`](#ref)."
175+
"Show the definition generated by a macro of PowerDynamics.jl,
176+
e.g. the macro [`PowerDynBase.@DynamicNode`](#ref) creting a subtype of [`PowerDynBase.AbstractNodeParameters`](#ref)."
176177
showdefinition(x) = showdefinition(stdout, x)

src/GridDynamics.jl

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,58 @@ abstract type AbstractAlgebraicGridDynamics <: GridDynamics end
1414

1515
NetworkRHS(g::GridDynamics) = g.rhs
1616

17-
"TBD"
17+
"""
18+
struct OrdinaryGridDynamics <: AbstractOrdinaryGridDynamics
19+
rhs::NetworkRHS
20+
end
21+
22+
The data structure that contains all the information necessary for a power grid model that can be described
23+
as an ordinary differential equation. In this case, only the [`PowerDynBase.NetworkRHS`] is necessary.
24+
"""
1825
@with_kw struct OrdinaryGridDynamics <: AbstractOrdinaryGridDynamics
1926
rhs::NetworkRHS
2027
end
2128
(dyn::OrdinaryGridDynamics)(dx_dt::AbstractVector, x_in::AbstractVector, p, t) = dyn.rhs(ODEVariable(x_in, dx_dt), t)
2229

23-
"TBD"
30+
"""
31+
struct OrdinaryGridDynamicsWithMass <: AbstractAlgebraicGridDynamics
32+
rhs::NetworkRHS
33+
masses::AbstractVector{Bool} # diagonal part of the mass matrix, off-diagonal is assumed to be 0 anyway
34+
end
35+
36+
The data structure that contains all the information necessary for a power grid model that can be described
37+
as an ordinary differential equation with masses, i.e. a semi-explicit differential algebraic equation.
38+
`rhs` is the [`PowerDynBase.NetworkRHS`]. `masses` is a 1-dimensional array representing the diagonal entries
39+
of the mass matrix. The off-diagonal entries are assumed to be 0. `masses` can only contain boolean values
40+
representing: `true` the equation is treated as a ordinary differential eqation and `false` the equation is
41+
treated as an algebraic constraint on the state variables.
42+
"""
2443
@with_kw struct OrdinaryGridDynamicsWithMass <: AbstractAlgebraicGridDynamics
2544
rhs::NetworkRHS
2645
masses::AbstractVector{Bool} # diagonal part of the mass matrix, off-diagonal is assumed to be 0 anyway
2746
end
2847
(dyn::OrdinaryGridDynamicsWithMass)(dx_dt::AbstractVector, x_in::AbstractVector, p, t) = dyn.rhs(ODEVariable(x_in, dx_dt), t)
2948

30-
"TBD"
49+
"""
50+
struct AlgebraicGridDynamics <: AbstractAlgebraicGridDynamics
51+
rhs::NetworkRHS
52+
differentials::AbstractVector{Bool} # boolean values whether there a variable is a differential
53+
end
54+
55+
The data structure that contains all the information necessary for a power grid model that can be described
56+
as an differential algebraic equation.
57+
`rhs` is the [`PowerDynBase.NetworkRHS`]. `differentials` is a 1-dimensional array of boolean values.
58+
A `true` entry means the corresponding variable is dynamic and has a derivative variable.
59+
A `false` entry means the corresponding variable is defined by an algebraic constraint only.
60+
"""
3161
@with_kw struct AlgebraicGridDynamics <: AbstractAlgebraicGridDynamics
3262
rhs::NetworkRHS
3363
differentials::AbstractVector{Bool} # boolean values whether there a variable is a differential
3464
end
3565
(dyn::AlgebraicGridDynamics)(x_out::AbstractVector, dx_dt::AbstractVector, x_in::AbstractVector, p, t) = dyn.root(DAEVariable(val=x_in, ddt=dx_dt, out=x_out), t)
3666

3767

38-
"Create for each subtype of [`DPSABase.AbstractNodeDynamics`](#ref) the corresponding subtype of [`DPSABase.GridDynamics`](#ref)."
68+
"Create for each subtype of [`PowerDynBase.AbstractNodeDynamics`](#ref) the corresponding subtype of [`PowerDynBase.GridDynamics`](#ref)."
3969
_GridDynamics(nodes::AbstractVector{<:OrdinaryNodeDynamics}, LY::AbstractMatrix) =
4070
OrdinaryGridDynamics(NetworkRHS(nodes, LY))
4171

@@ -63,9 +93,9 @@ end
6393
skip_LY_check=false,
6494
kwargs...)
6595
66-
Bring all sutypes of [`DPSABase.AbstractNodeDynamics`](#ref) on one level and then
67-
create for each subtype of [`DPSABase.AbstractNodeDynamics`](#ref) the corresponding subtype of [`DPSABase.GridDynamics`](#ref) by using
68-
[`DPSABase._GridDynamics`](#ref).
96+
Bring all sutypes of [`PowerDynBase.AbstractNodeDynamics`](#ref) on one level and then
97+
create for each subtype of [`PowerDynBase.AbstractNodeDynamics`](#ref) the corresponding subtype of [`PowerDynBase.GridDynamics`](#ref) by using
98+
[`PowerDynBase._GridDynamics`](#ref).
6999
"""
70100
function GridDynamics(
71101
nodes::AbstractArray{<:AbstractNodeDynamics},
@@ -84,16 +114,17 @@ end
84114
"""
85115
function GridDynamics(nodes::AbstractVector{<:AbstractNodeParameters}, args...; kwargs...)
86116
87-
Convert all subtypes of [`DPSABase.AbstractNodeParameters`](#ref) to the corresponding
88-
subtypes of [`DPSABase.AbstractNodeDynamics`](#ref) and then call [`DPSABase.GridDynamics`](#ref)
117+
Convert all subtypes of [`PowerDynBase.AbstractNodeParameters`](#ref) to the corresponding
118+
subtypes of [`PowerDynBase.AbstractNodeDynamics`](#ref) and then call [`PowerDynBase.GridDynamics`](#ref)
89119
again.
90120
"""
91121
function GridDynamics(nodes::AbstractVector{<:AbstractNodeParameters}, args...; kwargs...)
92122
GridDynamics(map(construct_node_dynamics, nodes), args...; kwargs...)
93123
end
94124

95-
125+
"Return the 1-dimensional differentials array (see [`PowerDynBase.AlgebraicGridDynamics`]) for the internal variables for each node."
96126
int_differentials(node::AbstractAlgebraicNodeDynamics, nodes::AbstractAlgebraicNodeDynamics...) = [int_differentials(node); int_differentials(nodes...)]
127+
"Return the 1-dimensional differentials array (see [`PowerDynBase.AlgebraicGridDynamics`]) for the voltagee variables for each node."
97128
u_differentials(node::AbstractAlgebraicNodeDynamics, nodes::AbstractAlgebraicNodeDynamics...) = [u_differentials(node); u_differentials(nodes...)]
98129
u_differentials(node::OrdinaryNodeDynamicsWithMass) = repeat([node.m_u], inner=2) # 1 Complex number is 2 Real numbers
99130
int_differentials(node::OrdinaryNodeDynamicsWithMass) = node.m_int

src/NetwirkRHSs.jl

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ abstract type AbstractNetworkFunction{T<:AbstractNodeDynamics, M<:AbstractMatrix
3434
systemsize
3535
intrange # unitrange telling me where I find the internal dynamic variables
3636
nodalintranges # unit ranges to find the internal variables for each node in the full length of internal variables
37-
rhsinterface::Function
3837
end
3938
4039
Representing the full dynamics of the power grid.
41-
42-
From [DPSABase.`AbstractNetworkFunction`](#ref) it inherits the conditions that `T<:AbstractNodeDynamics` and `M<:AbstractMatrix}`.
4340
"""
4441
@with_kw struct NetworkRHS{T, M} <: AbstractNetworkFunction{T, M}
4542
nodes::AbstractVector{T}
@@ -49,12 +46,22 @@ From [DPSABase.`AbstractNetworkFunction`](#ref) it inherits the conditions that
4946
intrange # unitrange telling me where I find the internal dynamic variables
5047
nodalintranges # unit ranges to find the internal variables for each node in the full length of internal variables
5148
end
49+
"""
50+
(rhs::NetworkRHS)(x::AbstractDEVariable, t)
51+
52+
Evalate the network right-hand-side function.
53+
"""
5254
function (rhs::NetworkRHS)(x::AbstractDEVariable, t)
5355
# distribute the values of the of the DEVariables over all
5456
nodeiterator(rhs, x, t)
5557
nothing
5658
end
5759
# external constructor
60+
"""
61+
NetworkRHS(nodes::AbstractVector{T}, LY::M) where {T<:AbstractNodeDynamics, M<:AbstractMatrix}
62+
63+
Create an [`PowerDynBase.NetworkRHS`](#ref) object from a node list and the nodal admittance matrix.
64+
"""
5865
function NetworkRHS(nodes::AbstractVector{T}, LY::M) where {T<:AbstractNodeDynamics, M<:AbstractMatrix}
5966
numnodes = length(nodes)
6067
@assert size(LY) == (numnodes, numnodes)
@@ -68,14 +75,35 @@ function NetworkRHS(nodes::AbstractVector{T}, LY::M) where {T<:AbstractNodeDynam
6875
nodalintranges = internal_unitranges(nodes)
6976
)
7077
end
78+
7179
Nodes(rhs::NetworkRHS) = rhs.nodes
7280
SystemSize(rhs::NetworkRHS) = rhs.systemsize
7381
AdmittanceLaplacian(rhs::NetworkRHS) = rhs.LY
7482

7583
# fall-back: only GridDynamics(x) needs to be defined, the rest is automatically via this line and the following
84+
"""
85+
NetworkRHS(x)
86+
87+
Return the struct of type [`PowerDynBase.NetworkRHS`](#ref) for `x`.
88+
"""
7689
NetworkRHS(x) = x |> GridDynamics |> NetworkRHS
90+
"""
91+
SystemSize(x)
92+
93+
Return the full system size, i.e. number of independent, dynamic, real-valued variables, for `x`.
94+
"""
7795
SystemSize(x) = x |> NetworkRHS |> SystemSize
96+
"""
97+
Nodes(x)
98+
99+
Return the array of nodes for `x`.
100+
"""
78101
Nodes(x) = x |> NetworkRHS |> Nodes
102+
"""
103+
AdmittanceLaplacian(x)
104+
105+
Return the nodal admittance matrix of the system.
106+
"""
79107
AdmittanceLaplacian(x) = x |> NetworkRHS |> AdmittanceLaplacian
80108

81109
"""

src/NodeDynamicsBase.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ getDEVariableType(::Type{Val{OrdinaryNodeDynamics}}) = ODEVariable
7373
"Get number of internal arguments of the node."
7474
nint(dyn::OrdinaryNodeDynamics) = dyn.n_int
7575

76+
"Get the symbols data structure for the node."
7677
symbolsof(n::OrdinaryNodeDynamics) = n.symbols
7778

79+
"Get the parameters struct for the node."
7880
parametersof(n::OrdinaryNodeDynamics) = n.parameters
7981

8082
################################################################################

src/NodeParametersBase.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ struct ODENodeSymbols <: AbstractNodeSymbols
2020
vars::AbstractVector{Symbol}
2121
dvars::AbstractVector{Symbol}
2222
end
23+
"Get the symbols representing the internal variables of the node."
2324
internalsymbolsof(s::ODENodeSymbols) = s.vars
2425
internalsymbolsof(s::AbstractNodeSymbols) = s |> ODENodeSymbols |> internalsymbolsof
2526
internalsymbolsof(s) = s |> symbolsof |> internalsymbolsof
27+
"Get the symbols representing the derivative of the internal variables of the node."
2628
internaldsymbolsof(s::ODENodeSymbols) = s.dvars
2729
internaldsymbolsof(s::AbstractNodeSymbols) = s |> ODENodeSymbols |> internaldsymbolsof
2830
internaldsymbolsof(s) = s |> symbolsof |> internaldsymbolsof
@@ -33,6 +35,7 @@ struct DAENodeSymbols <: AbstractNodeSymbols
3335
DAENodeSymbols(vars, dvars, outvars) = new(ODENodeSymbols(vars, dvars), outvars)
3436
end
3537
ODENodeSymbols(s::DAENodeSymbols) = s.odesymbols
38+
"Get the symbols representing the output of the internal variables of the node."
3639
internaloutsymbolsof(s::DAENodeSymbols) = s.outvars
3740
internaloutsymbolsof(s::AbstractNodeSymbols) = s |> DAENodeSymbols |> internaloutsymbolsof
3841
internaloutsymbolsof(s) = s |> symbolsof |> internaloutsymbolsof

src/States.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Encode a state vector and the corresponding rhs information.
2525
# Indexing
2626
2727
In an instance `b` of of a `BaseState` behaves like an
28-
[`Array`](@ref), i.e. you can access the ``j``-th element
28+
array, i.e. you can access the ``j``-th element
2929
of the state vector (and set it to a value ``ξ``) by calling `b[j] ( = ξ )`.
3030
3131
"""
@@ -67,9 +67,9 @@ Encode the information on the value of a state vector at a particular time point
6767
# Indexing
6868
6969
Concerning the indexing, a `State` object ``s`` basically behaves like a
70-
an [`Array`](@ref).
70+
an array.
7171
There are plenty of convenient ways to access its contents at a node ``j``
72-
by using a particular [`Symbol`](@ref):
72+
by using a particular symbol:
7373
7474
* `s[j, :u]`: complex voltage
7575
* `s[j, :v]`: voltage magnitude

src/complexview.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# (C) 2018 Potsdam Institute for Climate Impact Research, authors and contributors (see AUTHORS file)
22
# Licensed under GNU GPL v3 (see LICENSE file)
33

4-
"Interpret (part of) an array of real values as an array with complex values."
4+
"""
5+
complexview(vec::AbstractArray, i0, n)
6+
7+
Interpret (part of) an array of real values as an array with complex values.
8+
`i0` is the index where to start.
9+
`n` is the number of complex values that should be extracted.
10+
"""
511
function complexview(vec::AbstractArray{T}, i0, n) where T
612
vec_view = view(vec, i0:i0 + 2*n -1)
713
reinterpret(Complex{T}, vec_view)

0 commit comments

Comments
 (0)