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

format SciML Style #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "sciml"
42 changes: 42 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: format-check

on:
push:
branches:
- 'master'
- 'release-'
tags: '*'
pull_request:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1]
julia-arch: [x86]
os: [ubuntu-latest]
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}

- uses: actions/checkout@v1
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'
18 changes: 9 additions & 9 deletions examples/User_Type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,37 @@ using Compat

const DataFloat = Float64
mutable struct Vec2
a::DataFloat
b::DataFloat
a::DataFloat
b::DataFloat
end

# This is the minimal set of function required on the type inorder to work with
# the ODE module
Base.:/(x::Vec2, y::Real) = Vec2(x.a/y, x.b/y)
Base.:/(x::Vec2, y::Real) = Vec2(x.a / y, x.b / y)
Base.:*(y::Real, x::Vec2) = Vec2(y * x.a, y * x.b)
Base.:*(x::Vec2, y::Real) = y*x
Base.:.*(y::Real, x::Vec2) = y*x
Base.:*(x::Vec2, y::Real) = y * x
Base.:.*(y::Real, x::Vec2) = y * x
Base.:+(x::Vec2, y::Vec2) = Vec2(x.a + y.a, x.b + y.b)
Base.:-(x::Vec2, y::Vec2) = Vec2(x.a - y.a, x.b - y.b)
Base.norm(x::Vec2) = sqrt(x.a^2 + x.b^2)
Base.zero(x::Type{Vec2}) = Vec2(zero(DataFloat), zero(DataFloat))
ODE.isoutofdomain(x::Vec2) = isnan(x.a) || isnan(x.b)

# RHS function
f(t,y) = Vec2(-y.b, y.a)
f(t, y) = Vec2(-y.b, y.a)

# Initial condtions
start = Vec2(0.0, 0.1)

# Time vector going from 0 to 2*PI in 0.01 increments
time = 0:0.1:4*pi
time = 0:0.1:(4 * pi)

# Solve the ODE
t, y = ode45(f, start, time)

# Plot the solution
a = map(y -> y.a, y)
b = map(y -> y.b, y)
plot(t, a, label="a(t)")
plot(t, b, label="b(t)")
plot(t, a, label = "a(t)")
plot(t, b, label = "b(t)")
legend()
Loading