Skip to content

Commit

Permalink
Fixing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cadojo committed Dec 8, 2024
1 parent cf5beb2 commit 815065b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
22 changes: 9 additions & 13 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

First, let's use everyone's favorite toy potential: the Plummer potential.

```@repl example
```@example example
using GalacticPotentials
field = PlummerPotential()
Expand All @@ -19,15 +19,15 @@ gradient of the scalar field $\Phi$ with respect to the state variables $x$,
$y$, and $z$ to find the force (per unit mass) applied to the particle at all
points in space.

```@repl example
```@example example
system = PlummerPotential(gradient=true)
```

Note there are 10 equations! Most of these equations are observables, i.e.
they can be reconstructed lazily from the solution. We can reduce the system
to 6 unknowns and 6 equations by calling `ModelingToolkit.structural_simplify`.

```@repl example
```@example example
using ModelingToolkit
system = structural_simplify(system)
```
Expand All @@ -51,18 +51,18 @@ The `ModelingToolkit.jl` `AbstractSystem` interface methods are defined for
all potential fields within `GalacticPotentials.jl` because they are all
`ModelingToolkit.ODESystem` instances!

```@repl example
```@example example
J = ModelingToolkit.calculate_jacobian(system)
```

```@repl example
```@example example
f = ModelingToolkit.generate_function(system)
```

As with any `ModelingToolkit.ODESystem`, we can construct a numerical problem
by passing the system to an `ODEProblem` constructor.

```@repl example
```@example example
using OrdinaryDiffEq
problem = let
Expand All @@ -78,7 +78,7 @@ It's generally safer to use _variable maps_ to provide initial conditions for
your `ODEProblem`. Variable maps allow for an arbitrary state vector order; the
`ODEProblem` call above assumes the parameter and state vector orders!

```@repl example
```@example example
problem = let model = system
p = @nonamespace Dict(
Expand All @@ -105,23 +105,19 @@ end
With the `ODEProblem` defined, you can use `OrdinaryDiffEq.jl` or
`DifferentialEquations.jl` to numerically integrate the orbit.

```@repl example
```@example example
trajectory = solve(problem; abstol=1e-14, reltol=1e-14)
```

Finally, you can use `Plots.jl` to show the result! For more information,
consult the `SciML` [documentation](https://docs.sciml.ai), or the
`GalacticPotentials.jl` [Getting Started](index.md) page.

```@repl example
```@example example
using Plots
figure = plot(
trajectory, idxs=(:x, :y),
label=:none, title="Orbit in the Plummer Potential",
)
```

```@example example
figure # hide
```
9 changes: 4 additions & 5 deletions gen/gala.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# GalacticPotentials.jl. Thank you Gala!
#

if haskey(ENV, "CLEAN")
if haskey(ENV, "CLEAN") || !isdir("venv")
run(`rm -rf $(joinpath(@__DIR__, "venv"))`)
run(`python3 -m venv $(joinpath(@__DIR__, "venv"))`)
end
Expand All @@ -22,14 +22,15 @@ using PyCall, SymPy, LaTeXStrings

gala = pyimport("gala.potential")

expressions = Dict{String,LaTeXString}()
expressions = Dict{String, LaTeXString}()

latex!(collection::AbstractDict, name::AbstractString) =
function latex!(collection::AbstractDict, name::AbstractString)
try
collection[name] = getproperty(gala.potential, name).to_latex()
catch
@warn "Unable to get expression for $name."
end
end

for potential in gala.potential.__dir__()
if occursin("Potential", potential)
Expand All @@ -54,7 +55,6 @@ open(joinpath(@__DIR__, "..", "src", "gen", "expressions.jl"), "w") do file
end

write(file, ")\n")

end

open(joinpath(@__DIR__, "..", "test", "gen", "potentials.jl"), "w") do file
Expand All @@ -75,5 +75,4 @@ open(joinpath(@__DIR__, "..", "test", "gen", "potentials.jl"), "w") do file
end

write(file, ")\n")

end

0 comments on commit 815065b

Please sign in to comment.