Skip to content

Commit

Permalink
Update for GeometricEquations v0.6 and GeometricSolutions v0.4 and fi…
Browse files Browse the repository at this point in the history
…x some docstrings.
  • Loading branch information
michakraus committed Sep 23, 2022
1 parent f8d1649 commit dfead7b
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 49 deletions.
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.3.0"

[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GeometricBase = "9a0b12b7-583b-4f04-aa1f-d8551b6addc9"
GeometricEquations = "c85262ba-a08a-430a-b926-d29770767bf2"
GeometricSolutions = "7843afe4-64f4-4df4-9231-049495c56661"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Expand All @@ -19,8 +20,9 @@ Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"

[compat]
Documenter = "0.25, 0.26, 0.27"
GeometricEquations = "0.4"
GeometricSolutions = "0.1"
GeometricBase = "0.4"
GeometricEquations = "0.5, 0.6"
GeometricSolutions = "0.3"
LaTeXStrings = "1"
Measures = "0.3"
ModelingToolkit = "6, 7"
Expand Down
65 changes: 26 additions & 39 deletions src/diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module Diagnostics
export compute_one_form, compute_invariant, compute_invariant_error, compute_momentum_error, compute_error_drift

"""
Takes a 1d DataSeries holding an invariant and computes the relative error `(inv(t)-inv(0))/inv(0)`.
Takes a ScalarDataSeries holding an invariant and computes the relative error `(inv(t)-inv(0))/inv(0)`.
Returns a 1d DataSeries similar to the argument holding the time series of the relativ errors.
Returns a ScalarDataSeries similar to the argument holding the time series of the relativ errors.
"""
function compute_relative_error(invds::AbstractDataSeries{T,1}) where {T}
function compute_relative_error(invds::ScalarDataSeries{T}) where {T}
errds = similar(invds)
for i in eachindex(errds, invds)
errds[i] = (invds[i] - invds[0]) / invds[0]
Expand All @@ -20,14 +20,14 @@ module Diagnostics
"""
Compute the one-form (symplectic potential) for the solution of a Lagrangian system.
Arguments: `(t::TimeSeries, q::AbstractDataSeries, one_form::Function)`
Arguments: `(t::TimeSeries, q::DataSeries, one_form::Function)`
The `one_form` function needs to take three arguments `(t,q,k)` where `k` is the index
of the one-form component.
Returns a DataSeries similar to `q` holding the time series of the one-form.
"""
function compute_one_form(t::TimeSeries, q::AbstractDataSeries, one_form::Function)
function compute_one_form(t::TimeSeries, q::DataSeries, one_form::Function)
ϑ = similar(q)
try
for i in axes(p,2)
Expand All @@ -48,15 +48,15 @@ module Diagnostics
"""
Compute an invariant for the solution of an ODE or DAE system.
Arguments: `(t::TimeSeries, q::AbstractDataSeries{T}, invariant::Function)`
Arguments: `(t::TimeSeries, q::DataSeries{T}, invariant::Function)`
The `invariant` functions needs to take two arguments `(t,q)` and return the
corresponding value of the invariant.
Returns a 1d DataSeries holding the time series of the invariant.
Returns a ScalarDataSeries holding the time series of the invariant.
"""
function compute_invariant(t::TimeSeries, q::AbstractDataSeries{<:AbstractArray{T}}, invariant::Function) where {T}
invds = DataSeries(T, ntime(q))
function compute_invariant(t::TimeSeries, q::DataSeries{<:AbstractArray{T}}, invariant::Function) where {T}
invds = ScalarDataSeries(T, ntime(q))
try
for i in eachindex(invds)
invds[i] = invariant(t[i], q[i])
Expand All @@ -74,15 +74,15 @@ module Diagnostics
"""
Compute an invariant for the solution of a partitioned ODE or DAE system.
Arguments: `(t::TimeSeries, q::AbstractDataSeries{T}, p::AbstractDataSeries{T}, invariant::Function)`
Arguments: `(t::TimeSeries, q::DataSeries{T}, p::DataSeries{T}, invariant::Function)`
The `invariant` functions needs to take three arguments `(t,q,p)` and return the
corresponding value of the invariant.
Returns a 1d DataSeries holding the time series of the invariant.
Returns a ScalarDataSeries holding the time series of the invariant.
"""
function compute_invariant(t::TimeSeries, q::AbstractDataSeries{<:AbstractArray{T}}, p::AbstractDataSeries{<:AbstractArray{T}}, invariant::Function) where {T}
invds = DataSeries(T, ntime(q))
function compute_invariant(t::TimeSeries, q::DataSeries{<:AbstractArray{T}}, p::DataSeries{<:AbstractArray{T}}, invariant::Function) where {T}
invds = ScalarDataSeries(T, ntime(q))
try
for i in eachindex(invds)
invds[i] = invariant(t[i], q[i], p[i])
Expand All @@ -100,14 +100,14 @@ module Diagnostics
"""
Compute the relative error of an invariant for the solution of an ODE or DAE system.
Arguments: `(t::TimeSeries, q::AbstractDataSeries{T}, invariant::Function)`
Arguments: `(t::TimeSeries, q::DataSeries{T}, invariant::Function)`
The `invariant` functions needs to take two arguments `(t,q)` and return the
corresponding value of the invariant.
Returns a tuple of two 1d DataSeries holding the time series of the invariant and the relativ error, respectively.
"""
function compute_invariant_error(t::TimeSeries, q::AbstractDataSeries{T}, invariant::Function) where {T}
function compute_invariant_error(t::TimeSeries, q::DataSeries{T}, invariant::Function) where {T}
invds = compute_invariant(t, q, invariant)
errds = compute_relative_error(invds)
(invds, errds)
Expand All @@ -116,14 +116,14 @@ module Diagnostics
"""
Compute the relative error of an invariant for the solution of a partitioned ODE or DAE system.
Arguments: `(t::TimeSeries, q::AbstractDataSeries{T}, p::AbstractDataSeries{T}, invariant::Function)`
Arguments: `(t::TimeSeries, q::DataSeries{T}, p::DataSeries{T}, invariant::Function)`
The `invariant` functions needs to take three arguments `(t,q,p)` and return the
corresponding value of the invariant.
Returns a tuple of two 1d DataSeries holding the time series of the invariant and the relativ error, respectively.
Returns a tuple of two ScalarDataSeries holding the time series of the invariant and the relativ error, respectively.
"""
function compute_invariant_error(t::TimeSeries, q::AbstractDataSeries{T}, p::AbstractDataSeries{T}, invariant::Function) where {T}
function compute_invariant_error(t::TimeSeries, q::DataSeries{T}, p::DataSeries{T}, invariant::Function) where {T}
invds = compute_invariant(t, q, p, invariant)
errds = compute_relative_error(invds)
(invds, errds)
Expand All @@ -132,28 +132,15 @@ module Diagnostics
"""
Computes the difference of the momentum and the one-form of an implicit ODE or DAE system.
Arguments: `(t::TimeSeries, q::AbstractDataSeries{T}, p::AbstractDataSeries{T}, one_form::Function)`
Arguments: `(t::TimeSeries, q::DataSeries{T}, p::DataSeries{T}, one_form::Function)`
The `one_form` function needs to take three arguments `(t,q,k)` where `k` is the index
of the one-form component.
Returns a DataSeries similar to `p` holding the time series of the difference between the momentum and the one-form.
"""
function compute_momentum_error(t::TimeSeries, q::AbstractDataSeries{T}, p::AbstractDataSeries{T,2}, one_form::Function) where {T}
e = similar(p)

for i in axes(p,2)
for n in axes(p,1)
for k in eachindex(p[n,i])
e[n,i][k] = p[n,i][k] - one_form(t[n], q[n,i], k)
end
end
end

return e
end

function compute_momentum_error(t::TimeSeries, q::AbstractDataSeries{T}, p::AbstractDataSeries{T,1}, one_form::Function) where {T}
function compute_momentum_error(t::TimeSeries, q::DataSeries{T}, p::DataSeries{T}, one_form::Function) where {T}
e = similar(p)

for n in axes(p,1)
Expand All @@ -168,11 +155,11 @@ module Diagnostics
"""
Computes the difference of the momentum and the one-form of an implicit ODE or DAE system.
Arguments: `(p::AbstractDataSeries{DT}, ϑ::AbstractDataSeries{DT})`
Arguments: `(p::DataSeries{DT}, ϑ::DataSeries{DT})`
Returns a DataSeries similar to `p` holding the time series of the difference between `p` and `ϑ`.
"""
function compute_momentum_error(p::AbstractDataSeries{DT}, ϑ::AbstractDataSeries{DT}) where {DT}
function compute_momentum_error(p::DataSeries{DT}, ϑ::DataSeries{DT}) where {DT}
@assert axes(p) == axes(ϑ)

e = similar(p)
Expand All @@ -184,23 +171,23 @@ module Diagnostics
"""
Computes the drift in an invariant error.
Arguments: `(t::TimeSeries, invariant_error::AbstractDataSeries{T,1}, interval_length=100)`
Arguments: `(t::TimeSeries, invariant_error::DataSeries{T,1}, interval_length=100)`
The time series of the solution is split into intervals of `interval_length` time steps.
In each interval, the maximum of the absolute value of the invariant error is determined.
Returns a tuple of a TimeSeries that holds the centers of all intervals and a 1d DataSeries
Returns a tuple of a TimeSeries that holds the centers of all intervals and a ScalarDataSeries
that holds the maxima.
This is useful to detect drifts in invariants that are not preserved exactly but whose error
is oscillating such as the energy error of Hamiltonian systems with symplectic integrators.
"""
function compute_error_drift(t::TimeSeries, invariant_error::AbstractDataSeries{T,1}, interval_length=100) where {T}
function compute_error_drift(t::TimeSeries, invariant_error::ScalarDataSeries{T}, interval_length=100) where {T}
@assert ntime(t) == ntime(invariant_error)
@assert mod(t.n, interval_length) == 0

nint = div(ntime(invariant_error), interval_length)
Tdrift = TimeSeries(nint, (t[end] - t[begin]) / nint)
Idrift = DataSeries(T, nint)
Idrift = ScalarDataSeries(T, nint)

Tdrift[0] = t[0]

Expand Down
2 changes: 1 addition & 1 deletion src/harmonic_oscillator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ module HarmonicOscillator
end


function compute_energy_error(t, q::AbstractDataSeries{T}, params) where {T}
function compute_energy_error(t, q::DataSeries{T}, params) where {T}
h = DataSeries(T, q.nt)
e = DataSeries(T, q.nt)

Expand Down
5 changes: 3 additions & 2 deletions src/lotka_volterra_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ References:
"""
module LotkaVolterra3d

using GeometricBase
using GeometricEquations
using GeometricSolutions
using Parameters
Expand Down Expand Up @@ -105,7 +106,7 @@ module LotkaVolterra3d
end


function compute_energy_error(t, q::AbstractDataSeries{<:AbstractVector{T}}, params) where {T}
function compute_energy_error(t::TimeSeries, q::DataSeries{T}, params) where {T}
h = DataSeries(T, ntime(q))
e = DataSeries(T, ntime(q))

Expand All @@ -117,7 +118,7 @@ module LotkaVolterra3d
(h, e)
end

function compute_casimir_error(t, q::AbstractDataSeries{<:AbstractVector{T}}, params) where {T}
function compute_casimir_error(t::TimeSeries, q::DataSeries{T}, params) where {T}
c = DataSeries(T, ntime(q))
e = DataSeries(T, ntime(q))

Expand Down
4 changes: 2 additions & 2 deletions src/point_vortices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ module PointVortices
end


function compute_energy_error(t, q::AbstractDataSeries{T}, params) where {T}
function compute_energy_error(t, q::DataSeries{T}, params) where {T}
h = DataSeries(T, q.nt)
e = DataSeries(T, q.nt)

Expand All @@ -352,7 +352,7 @@ module PointVortices
(h, e)
end

function compute_angular_momentum_error(t, q::AbstractDataSeries{T}, params) where {T}
function compute_angular_momentum_error(t, q::DataSeries{T}, params) where {T}
m = DataSeries(T, q.nt)
e = DataSeries(T, q.nt)

Expand Down
1 change: 0 additions & 1 deletion test/harmonic_oscillator_tests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using SimpleSolvers
using Test
using GeometricEquations
using GeometricIntegrators
using GeometricIntegrators.Integrators.VPRK
using GeometricIntegrators.Utils
Expand Down
1 change: 0 additions & 1 deletion test/kubo_oscillator_tests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using GeometricEquations
using GeometricIntegrators
using GeometricProblems.KuboOscillator
using Test
Expand Down
1 change: 0 additions & 1 deletion test/lotka_volterra_2d_tests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using SimpleSolvers
using Test
using GeometricEquations
using GeometricIntegrators
using GeometricIntegrators.Integrators.VPRK
using GeometricIntegrators.Utils
Expand Down

2 comments on commit dfead7b

@michakraus
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
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/68841

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 v0.3.0 -m "<description of version>" dfead7be9aa0ed93988fa25893cc520223474e68
git push origin v0.3.0

Please sign in to comment.