-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from JuliaGNI/rigid_body
Rigid body
- Loading branch information
Showing
12 changed files
with
153 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# The rigid body | ||
|
||
```@example | ||
using GeometricProblems.RigidBody: odeensemble | ||
using GeometricIntegrators: integrate, ImplicitMidpoint | ||
using GeometricEquations: EnsembleProblem | ||
using GeometricSolutions: GeometricSolution | ||
using CairoMakie | ||
ics = [ | ||
[sin(1.1), 0., cos(1.1)], | ||
[sin(2.1), 0., cos(2.1)], | ||
[sin(2.2), 0., cos(2.2)], | ||
[0., sin(1.1), cos(1.1)], | ||
[0., sin(1.5), cos(1.5)], | ||
[0., sin(1.6), cos(1.6)] | ||
] | ||
ensemble_problem = odeensemble(ics) | ||
ensemble_solution = integrate(ensemble_problem, ImplicitMidpoint()) | ||
function plot_geometric_solution!(p, solution::GeometricSolution; kwargs...) | ||
lines!(p, solution.q[:, 1].parent, solution.q[:, 2].parent, solution.q[:, 3].parent; kwargs...) | ||
end | ||
function sphere(r, C) # r: radius; C: center [cx,cy,cz] | ||
n = 100 | ||
u = range(-π, π; length = n) | ||
v = range(0, π; length = n) | ||
x = C[1] .+ r * cos.(u) * sin.(v)' | ||
y = C[2] .+ r * sin.(u) * sin.(v)' | ||
z = C[3] .+ r * ones(n) * cos.(v)' | ||
return x, y, z | ||
end | ||
fig, ax, plt = surface(sphere(1., [0., 0., 0.])..., alpha = .6) | ||
for (i, solution) in zip(1:length(ensemble_solution), ensemble_solution.s) | ||
plot_geometric_solution!(ax, solution; label = "trajectory "*string(i), linewidth=2) | ||
end | ||
fig | ||
``` | ||
|
||
|
||
## Library functions | ||
|
||
```@docs | ||
GeometricProblems.RigidBody | ||
``` | ||
|
||
```@autodocs | ||
Modules = [GeometricProblems.RigidBody] | ||
Order = [:constant, :type, :macro, :function] | ||
``` | ||
|
||
```@bibliography | ||
Pages = [] | ||
bajars2023locally | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
@doc raw""" | ||
# Rigid body | ||
```math | ||
\begin{aligned} | ||
\dot{x} = Ayz \\ | ||
\dot{y} = Bxz \\ | ||
\dot{z} = Cxy | ||
\end{aligned}, | ||
``` | ||
where ``A = (I_2 - I_3)/(I_2I_3)``, ``B = (I_3 - I_1)/(I_3I_1)`` and ``C = (I_1 - I_2)/(I_1I_2)``; ``I_{\cdot}`` are the *principal components of inertia*. | ||
The initial condition and the default parameters are taken from [bajars2023locally](@cite). | ||
""" | ||
module RigidBody | ||
|
||
using GeometricEquations | ||
using GeometricSolutions | ||
using Parameters | ||
|
||
export odeproblem, odeensemble | ||
|
||
const tspan = (0.0, 100.0) | ||
const tstep = 0.1 | ||
|
||
const default_parameters = ( | ||
I₁ = 2., | ||
I₂ = 1., | ||
I₃ = 2. / 3. | ||
) | ||
|
||
const q₀ = [cos(1.1), 0., sin(1.1)] | ||
const q₁ = [cos(2.1), 0., sin(2.1)] | ||
const q₂ = [cos(2.2), 0., sin(2.2)] | ||
|
||
function rigid_body_v(v, t, q, params) | ||
@unpack I₁, I₂, I₃ = params | ||
A = (I₂ - I₃) / (I₂ * I₃) | ||
B = (I₃ - I₁) / (I₃ * I₁) | ||
C = (I₁ - I₂) / (I₁ * I₂) | ||
v[1] = A * q[2] * q[3] | ||
v[2] = B * q[1] * q[3] | ||
v[3] = C * q[1] * q[2] | ||
|
||
nothing | ||
end | ||
|
||
function odeproblem(q₀ = q₀; tspan = tspan, tstep = tstep, parameters = default_parameters) | ||
ODEProblem(rigid_body_v, tspan, tstep, q₀; parameters = parameters) | ||
end | ||
|
||
function odeensemble(samples = [q₀, q₁, q₂]; parameters = default_parameters, tspan = tspan, tstep = tstep) | ||
ODEEnsemble(rigid_body_v, tspan, tstep, samples; parameters = parameters) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using GeometricProblems.RigidBody | ||
using Test | ||
|
||
@test_nowarn odeproblem() | ||
@test_nowarn odeensemble() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters