Skip to content
Merged
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"
110 changes: 49 additions & 61 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,64 +1,52 @@
using Documenter, ModelingToolkit

makedocs(
sitename="ModelingToolkit.jl",
authors="Chris Rackauckas",
modules=[ModelingToolkit],
clean=true,doctest=false,
strict=[
:doctest,
:linkcheck,
:parse_error,
:example_block,
# Other available options are
# :autodocs_block, :cross_references, :docs_block, :eval_block, :example_block, :footnote, :meta_block, :missing_docs, :setup_block
],
format=Documenter.HTML(analytics = "UA-90474609-3",
assets=["assets/favicon.ico"],
canonical="https://mtk.sciml.ai/stable/"),
pages=[
"Home" => "index.md",
"Symbolic Modeling Tutorials" => Any[
"tutorials/ode_modeling.md",
"tutorials/spring_mass.md",
"tutorials/acausal_components.md",
"tutorials/higher_order.md",
"tutorials/tearing_parallelism.md",
"tutorials/nonlinear.md",
"tutorials/optimization.md",
"tutorials/stochastic_diffeq.md",
"tutorials/nonlinear_optimal_control.md",
"tutorials/parameter_identifiability.md"
],
"ModelingToolkitize Tutorials" => Any[
"mtkitize_tutorials/modelingtoolkitize.md",
"mtkitize_tutorials/modelingtoolkitize_index_reduction.md",
"mtkitize_tutorials/sparse_jacobians.md",
],
"Basics" => Any[
"basics/AbstractSystem.md",
"basics/ContextualVariables.md",
"basics/Variable_metadata.md",
"basics/Composition.md",
"basics/Validation.md",
"basics/DependencyGraphs.md",
"basics/FAQ.md"
],
"System Types" => Any[
"systems/ODESystem.md",
"systems/SDESystem.md",
"systems/JumpSystem.md",
"systems/NonlinearSystem.md",
"systems/OptimizationSystem.md",
"systems/ControlSystem.md",
"systems/PDESystem.md",
],
"comparison.md",
"internals.md",
]
)
makedocs(sitename = "ModelingToolkit.jl",
authors = "Chris Rackauckas",
modules = [ModelingToolkit],
clean = true, doctest = false,
strict = [
:doctest,
:linkcheck,
:parse_error,
:example_block,
# Other available options are
# :autodocs_block, :cross_references, :docs_block, :eval_block, :example_block, :footnote, :meta_block, :missing_docs, :setup_block
],
format = Documenter.HTML(analytics = "UA-90474609-3",
assets = ["assets/favicon.ico"],
canonical = "https://mtk.sciml.ai/stable/"),
pages = [
"Home" => "index.md",
"Symbolic Modeling Tutorials" => Any["tutorials/ode_modeling.md",
"tutorials/spring_mass.md",
"tutorials/acausal_components.md",
"tutorials/higher_order.md",
"tutorials/tearing_parallelism.md",
"tutorials/nonlinear.md",
"tutorials/optimization.md",
"tutorials/stochastic_diffeq.md",
"tutorials/nonlinear_optimal_control.md",
"tutorials/parameter_identifiability.md"],
"ModelingToolkitize Tutorials" => Any["mtkitize_tutorials/modelingtoolkitize.md",
"mtkitize_tutorials/modelingtoolkitize_index_reduction.md",
"mtkitize_tutorials/sparse_jacobians.md"],
"Basics" => Any["basics/AbstractSystem.md",
"basics/ContextualVariables.md",
"basics/Variable_metadata.md",
"basics/Composition.md",
"basics/Validation.md",
"basics/DependencyGraphs.md",
"basics/FAQ.md"],
"System Types" => Any["systems/ODESystem.md",
"systems/SDESystem.md",
"systems/JumpSystem.md",
"systems/NonlinearSystem.md",
"systems/OptimizationSystem.md",
"systems/ControlSystem.md",
"systems/PDESystem.md"],
"comparison.md",
"internals.md",
])

deploydocs(
repo="github.com/SciML/ModelingToolkit.jl.git";
push_preview=true
)
deploydocs(repo = "github.com/SciML/ModelingToolkit.jl.git";
push_preview = true)
88 changes: 40 additions & 48 deletions examples/electrical_components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,97 @@ using Test
using ModelingToolkit, OrdinaryDiffEq

@isdefined(t) || @parameters t
@connector function Pin(;name)
@connector function Pin(; name)
sts = @variables v(t)=1.0 i(t)=1.0 [connect = Flow]
ODESystem(Equation[], t, sts, []; name=name)
ODESystem(Equation[], t, sts, []; name = name)
end

function Ground(;name)
function Ground(; name)
@named g = Pin()
eqs = [g.v ~ 0]
compose(ODESystem(eqs, t, [], []; name=name), g)
compose(ODESystem(eqs, t, [], []; name = name), g)
end

function OnePort(;name)
function OnePort(; name)
@named p = Pin()
@named n = Pin()
sts = @variables v(t)=1.0 i(t)=1.0
eqs = [
v ~ p.v - n.v
eqs = [v ~ p.v - n.v
0 ~ p.i + n.i
i ~ p.i
]
compose(ODESystem(eqs, t, sts, []; name=name), p, n)
i ~ p.i]
compose(ODESystem(eqs, t, sts, []; name = name), p, n)
end

function Resistor(;name, R = 1.0)
function Resistor(; name, R = 1.0)
@named oneport = OnePort()
@unpack v, i = oneport
ps = @parameters R=R
ps = @parameters R = R
eqs = [
v ~ i * R
]
extend(ODESystem(eqs, t, [], ps; name=name), oneport)
v ~ i * R,
]
extend(ODESystem(eqs, t, [], ps; name = name), oneport)
end

function Capacitor(;name, C = 1.0)
function Capacitor(; name, C = 1.0)
@named oneport = OnePort()
@unpack v, i = oneport
ps = @parameters C=C
ps = @parameters C = C
D = Differential(t)
eqs = [
D(v) ~ i / C
]
extend(ODESystem(eqs, t, [], ps; name=name), oneport)
D(v) ~ i / C,
]
extend(ODESystem(eqs, t, [], ps; name = name), oneport)
end

function ConstantVoltage(;name, V = 1.0)
function ConstantVoltage(; name, V = 1.0)
@named oneport = OnePort()
@unpack v = oneport
ps = @parameters V=V
ps = @parameters V = V
eqs = [
V ~ v
]
extend(ODESystem(eqs, t, [], ps; name=name), oneport)
V ~ v,
]
extend(ODESystem(eqs, t, [], ps; name = name), oneport)
end

function Inductor(; name, L = 1.0)
@named oneport = OnePort()
@unpack v, i = oneport
ps = @parameters L=L
ps = @parameters L = L
D = Differential(t)
eqs = [
D(i) ~ v / L
]
extend(ODESystem(eqs, t, [], ps; name=name), oneport)
D(i) ~ v / L,
]
extend(ODESystem(eqs, t, [], ps; name = name), oneport)
end

@connector function HeatPort(;name)
@connector function HeatPort(; name)
@variables T(t)=293.15 Q_flow(t)=0.0 [connect = Flow]
ODESystem(Equation[], t, [T, Q_flow], [], name=name)
ODESystem(Equation[], t, [T, Q_flow], [], name = name)
end

function HeatingResistor(;name, R=1.0, TAmbient=293.15, alpha=1.0)
function HeatingResistor(; name, R = 1.0, TAmbient = 293.15, alpha = 1.0)
@named p = Pin()
@named n = Pin()
@named h = HeatPort()
@variables v(t) RTherm(t)
@parameters R=R TAmbient=TAmbient alpha=alpha
eqs = [
RTherm ~ R*(1 + alpha*(h.T - TAmbient))
eqs = [RTherm ~ R * (1 + alpha * (h.T - TAmbient))
v ~ p.i * RTherm
h.Q_flow ~ -v * p.i # -LossPower
v ~ p.v - n.v
0 ~ p.i + n.i
]
compose(ODESystem(
eqs, t, [v, RTherm], [R, TAmbient, alpha],
name=name,
), p, n, h)
0 ~ p.i + n.i]
compose(ODESystem(eqs, t, [v, RTherm], [R, TAmbient, alpha],
name = name), p, n, h)
end

function HeatCapacitor(;name, rho=8050, V=1, cp=460, TAmbient=293.15)
function HeatCapacitor(; name, rho = 8050, V = 1, cp = 460, TAmbient = 293.15)
@parameters rho=rho V=V cp=cp
C = rho*V*cp
C = rho * V * cp
@named h = HeatPort()
D = Differential(t)
eqs = [
D(h.T) ~ h.Q_flow / C
]
compose(ODESystem(
eqs, t, [], [rho, V, cp],
name=name,
), h)
D(h.T) ~ h.Q_flow / C,
]
compose(ODESystem(eqs, t, [], [rho, V, cp],
name = name), h)
end
12 changes: 5 additions & 7 deletions examples/rc_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ include("electrical_components.jl")
R = 1.0
C = 1.0
V = 1.0
@named resistor = Resistor(R=R)
@named capacitor = Capacitor(C=C)
@named source = ConstantVoltage(V=V)
@named resistor = Resistor(R = R)
@named capacitor = Capacitor(C = C)
@named source = ConstantVoltage(V = V)
@named ground = Ground()

rc_eqs = [
connect(source.p, resistor.p)
rc_eqs = [connect(source.p, resistor.p)
connect(resistor.n, capacitor.p)
connect(capacitor.n, source.n)
connect(capacitor.n, ground.g)
]
connect(capacitor.n, ground.g)]

@named rc_model = ODESystem(rc_eqs, t)
rc_model = compose(rc_model, [resistor, capacitor, source, ground])
14 changes: 6 additions & 8 deletions examples/serial_inductor.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
include("electrical_components.jl")

@named source = ConstantVoltage(V=10.0)
@named resistor = Resistor(R=1.0)
@named inductor1 = Inductor(L=1.0e-2)
@named inductor2 = Inductor(L=2.0e-2)
@named source = ConstantVoltage(V = 10.0)
@named resistor = Resistor(R = 1.0)
@named inductor1 = Inductor(L = 1.0e-2)
@named inductor2 = Inductor(L = 2.0e-2)
@named ground = Ground()

eqs = [
connect(source.p, resistor.p)
eqs = [connect(source.p, resistor.p)
connect(resistor.n, inductor1.p)
connect(inductor1.n, inductor2.p)
connect(source.n, inductor2.n)
connect(inductor2.n, ground.g)
]
connect(inductor2.n, ground.g)]

@named ll_model = ODESystem(eqs, t)
ll_model = compose(ll_model, [source, resistor, inductor1, inductor2, ground])
12 changes: 7 additions & 5 deletions src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ for fun in [:toexpr]
Expr(:(=), $fun(eq.lhs; kw...), $fun(eq.rhs; kw...))
end

$fun(eqs::AbstractArray; kw...) = map(eq->$fun(eq; kw...), eqs)
$fun(eqs::AbstractArray; kw...) = map(eq -> $fun(eq; kw...), eqs)
$fun(x::Integer; kw...) = x
$fun(x::AbstractFloat; kw...) = x
end
Expand Down Expand Up @@ -158,7 +158,8 @@ for S in subtypes(ModelingToolkit.AbstractSystem)
@eval convert_system(::Type{<:$S}, sys::$S) = sys
end

export AbstractTimeDependentSystem, AbstractTimeIndependentSystem, AbstractMultivariateSystem
export AbstractTimeDependentSystem, AbstractTimeIndependentSystem,
AbstractMultivariateSystem
export ODESystem, ODEFunction, ODEFunctionExpr, ODEProblemExpr, convert_system
export DAEFunctionExpr, DAEProblemExpr
export SDESystem, SDEFunction, SDEFunctionExpr, SDESystemExpr
Expand All @@ -174,15 +175,17 @@ export NonlinearSystem, OptimizationSystem
export ControlSystem
export alias_elimination, flatten
export connect, @connector, Connection, Flow, Stream, instream
export isinput, isoutput, getbounds, hasbounds, isdisturbance, istunable, getdist, hasdist, tunable_parameters
export isinput, isoutput, getbounds, hasbounds, isdisturbance, istunable, getdist, hasdist,
tunable_parameters
export ode_order_lowering, dae_order_lowering, liouville_transform
export runge_kutta_discretize
export PDESystem
export Differential, expand_derivatives, @derivatives
export Equation, ConstrainedEquation
export Term, Sym
export SymScope, LocalScope, ParentScope, GlobalScope
export independent_variables, independent_variable, states, parameters, equations, controls, observed, structure, full_equations
export independent_variables, independent_variable, states, parameters, equations, controls,
observed, structure, full_equations
export structural_simplify, expand_connections
export DiscreteSystem, DiscreteProblem

Expand All @@ -208,5 +211,4 @@ export modelingtoolkitize
export @variables, @parameters
export @named, @nonamespace, @namespace, extend, compose


end # module
Loading