Skip to content

Commit

Permalink
Revise Component Macros.
Browse files Browse the repository at this point in the history
Fixes #39
  • Loading branch information
zekeriya.sari committed Aug 24, 2020
1 parent 48c2b19 commit 6a5796d
Show file tree
Hide file tree
Showing 56 changed files with 4,946 additions and 10,496 deletions.
4 changes: 2 additions & 2 deletions docs/build/assets/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions docs/build/assets/themes/documenter-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -7277,8 +7277,6 @@ html.theme--documenter-dark {
opacity: 0.2; }
html.theme--documenter-dark .docstring > section:hover a.docs-sourcelink {
opacity: 1; }
html.theme--documenter-dark .documenter-example-output {
background-color: #1f2424; }
html.theme--documenter-dark .content pre {
border: 1px solid #5e6d6f; }
html.theme--documenter-dark .content code {
Expand Down Expand Up @@ -7381,7 +7379,6 @@ html.theme--documenter-dark {
margin-bottom: 0.4em; }
html.theme--documenter-dark #documenter .docs-main .docs-footer {
display: flex;
flex-wrap: wrap;
margin-left: 0;
margin-right: 0;
border-top: 1px solid #5e6d6f;
Expand All @@ -7395,13 +7392,6 @@ html.theme--documenter-dark {
flex-grow: 1; }
html.theme--documenter-dark #documenter .docs-main .docs-footer .docs-footer-nextpage {
text-align: right; }
html.theme--documenter-dark #documenter .docs-main .docs-footer .flexbox-break {
flex-basis: 100%;
height: 0; }
html.theme--documenter-dark #documenter .docs-main .docs-footer .footer-message {
font-size: 0.8em;
margin: 0.5em auto 0 auto;
text-align: center; }
html.theme--documenter-dark #documenter .docs-sidebar {
display: flex;
flex-direction: column;
Expand Down
11 changes: 0 additions & 11 deletions docs/build/assets/themes/documenter-light.css
Original file line number Diff line number Diff line change
Expand Up @@ -7239,9 +7239,6 @@ h1:hover .docs-heading-anchor-permalink, h2:hover .docs-heading-anchor-permalink
.docstring > section:hover a.docs-sourcelink {
opacity: 1; }

.documenter-example-output {
background-color: white; }

.content pre {
border: 1px solid #dbdbdb; }

Expand Down Expand Up @@ -7363,7 +7360,6 @@ html {

#documenter .docs-main .docs-footer {
display: flex;
flex-wrap: wrap;
margin-left: 0;
margin-right: 0;
border-top: 1px solid #dbdbdb;
Expand All @@ -7377,13 +7373,6 @@ html {
flex-grow: 1; }
#documenter .docs-main .docs-footer .docs-footer-nextpage {
text-align: right; }
#documenter .docs-main .docs-footer .flexbox-break {
flex-basis: 100%;
height: 0; }
#documenter .docs-main .docs-footer .footer-message {
font-size: 0.8em;
margin: 0.5em auto 0 auto;
text-align: center; }

#documenter .docs-sidebar {
display: flex;
Expand Down
6 changes: 1 addition & 5 deletions docs/build/index.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions docs/build/manual/components/sinks/printer/index.html

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions docs/build/manual/components/sinks/scope/index.html

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions docs/build/manual/components/sinks/sinks/index.html

Large diffs are not rendered by default.

62 changes: 13 additions & 49 deletions docs/build/manual/components/sinks/writer/index.html

Large diffs are not rendered by default.

90 changes: 29 additions & 61 deletions docs/build/manual/components/sources/clock/index.html

Large diffs are not rendered by default.

36 changes: 6 additions & 30 deletions docs/build/manual/components/sources/generators/index.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

60 changes: 12 additions & 48 deletions docs/build/manual/connections/link/index.html

Large diffs are not rendered by default.

59 changes: 16 additions & 43 deletions docs/build/manual/connections/pin/index.html

Large diffs are not rendered by default.

44 changes: 12 additions & 32 deletions docs/build/manual/connections/port/index.html

Large diffs are not rendered by default.

37 changes: 8 additions & 29 deletions docs/build/manual/models/model/index.html

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions docs/build/manual/models/simulation/index.html

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions docs/build/manual/models/taskmanager/index.html

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions docs/build/manual/plugins/plugins/index.html

Large diffs are not rendered by default.

172 changes: 64 additions & 108 deletions docs/build/manual/utilities/buffers/index.html

Large diffs are not rendered by default.

18 changes: 3 additions & 15 deletions docs/build/manual/utilities/callback/index.html

Large diffs are not rendered by default.

20 changes: 4 additions & 16 deletions docs/build/modeling_and_simulation/modeling/index.html

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions docs/build/modeling_and_simulation/simulation/index.html

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions docs/build/search/index.html

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions docs/build/search_index.js

Large diffs are not rendered by default.

141 changes: 28 additions & 113 deletions docs/build/tutorials/algebraic_loops/index.html

Large diffs are not rendered by default.

994 changes: 269 additions & 725 deletions docs/build/tutorials/breaking_algebraic_loops_plot1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,016 changes: 269 additions & 747 deletions docs/build/tutorials/breaking_algebraic_loops_with_memory_incorrect_plot1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
994 changes: 269 additions & 725 deletions docs/build/tutorials/breaking_algebraic_loops_with_memory_plot1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 10 additions & 40 deletions docs/build/tutorials/coupled_systems/index.html

Large diffs are not rendered by default.

9,792 changes: 3,307 additions & 6,485 deletions docs/build/tutorials/coupled_systems_plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 18 additions & 55 deletions docs/build/tutorials/defining_new_components/index.html

Large diffs are not rendered by default.

367 changes: 144 additions & 223 deletions docs/build/tutorials/larger_model_plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 5 additions & 17 deletions docs/build/tutorials/model_construction/index.html

Large diffs are not rendered by default.

146 changes: 32 additions & 114 deletions docs/build/tutorials/model_simulation/index.html

Large diffs are not rendered by default.

466 changes: 206 additions & 260 deletions docs/build/tutorials/simple_model_plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/Causal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export readtime!,
drive!,
approve!

include("components/constants.jl")

include("components/sources/clock.jl")
export Clock,
isrunning,
Expand All @@ -125,7 +127,6 @@ export @def_source,
ExponentialGenerator,
DampedExponentialGenerator


include("components/systems/staticsystems/staticsystems.jl")
export @def_static_system,
StaticSystem,
Expand Down
48 changes: 48 additions & 0 deletions src/components/constants.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This file includes the type symbols of the fields to be added to the user defined components.

# NOTE: This is one-time defines to avoid name name conflicts with the user defined type names.

# `trigger` field type symbol. Common to all AbstractComponent
const TRIGGER_TYPE_SYMBOL = gensym()

# `handshake` field type symbol. Commona to all AbstractComponent.
const HANDSHAKE_TYPE_SYMBOL = gensym()

# `callbacks` field type symbol. Commone to all AbstractComponent
const CALLBACKS_TYPE_SYMBOL = gensym()

# `id` field type symbol. Common to all AbstractComponent.
const ID_TYPE_SYMBOL = gensym()

# `modelargs` field type symbol. Common to all AbstractDynamicalSystem
const MODEL_ARGS_TYPE_SYMBOL = gensym()

# `modelkwargs` field type symbol. Common to all AbstractDynamicalSystem
const MODEL_KWARGS_TYPE_SYMBOL = gensym()

# `solverargs` field type symbol. Common to all AbstractDynamicalSystem
const SOLVER_ARGS_TYPE_SYMBOL = gensym()

# `solverkwargs` field type symbol. Common to all AbstractDynamicalSystem
const SOLVER_KWARGS_TYPE_SYMBOL = gensym()

# `alg` field type symbol. Common to all AbstractDynamicalSystem
const ALG_TYPE_SYMBOL = gensym()

# `integrator` field type symbol. Common to all AbstractDynamicalSystem
const INTEGRATOR_TYPE_SYMBOL = gensym()

# `input` field type symbol. Common to all AbstractSink
const INPUT_TYPE_SYMBOL = gensym()

# `plugin` field type symbol. Common to all AbstractSink
const PLUGIN_TYPE_SYMBOL = gensym()

# `timebuf` field type symbol. Common to all AbstractSink
const TIMEBUF_TYPE_SYMBOL = gensym()

# `databuf` field type symbol. Common to all AbstractSink
const DATABUF_TYPE_SYMBOL = gensym()

# `sinkcallback` field type symbol. Common to all AbstractSink
const SINK_CALLBACK_TYPE_SYMBOL = gensym()
22 changes: 11 additions & 11 deletions src/components/sinks/sinks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ macro def_sink(ex)
=#
ex.args[2].head == :(<:) && ex.args[2].args[2] == :AbstractSink ||
error("Invalid usage. The type should be a subtype of AbstractSink.\n$ex")
TR, HS, CB, ID, IP, PL, TB, DB, SCB = [gensym() for i in 1 : 9]
# TR, HS, CB, ID, IP, PL, TB, DB, SCB = [gensym() for i in 1 : 9]
fields = quote
trigger::$(TR) = Inpin()
handshake::$(HS) = Outpin{Bool}()
callbacks::$(CB) = nothing
trigger::$(TRIGGER_TYPE_SYMBOL) = Inpin()
handshake::$(HANDSHAKE_TYPE_SYMBOL) = Outpin{Bool}()
callbacks::$(CALLBACKS_TYPE_SYMBOL) = nothing
name::Symbol = Symbol()
id::$(ID) = Causal.uuid4()
input::$(IP) = Inport()
id::$(ID_TYPE_SYMBOL) = Causal.uuid4()
input::$(INPUT_TYPE_SYMBOL) = Inport()
buflen::Int = 64
plugin::$(PL) = nothing
timebuf::$(TB) = Buffer(buflen)
databuf::$(DB) = length(input) == 1 ? Buffer(buflen) : Buffer(length(input), buflen)
sinkcallback::$(SCB) = plugin === nothing ?
plugin::$(PLUGIN_TYPE_SYMBOL) = nothing
timebuf::$(TIMEBUF_TYPE_SYMBOL) = Buffer(buflen)
databuf::$(DATABUF_TYPE_SYMBOL) = length(input) == 1 ? Buffer(buflen) : Buffer(length(input), buflen)
sinkcallback::$(SINK_CALLBACK_TYPE_SYMBOL) = plugin === nothing ?
Callback(sink->ishit(databuf), sink->action(sink, outbuf(timebuf), outbuf(databuf)), true, id) :
Callback(sink->ishit(databuf), sink->action(sink, outbuf(timebuf), plugin.process(outbuf(databuf))), true, id)
end, [TR, HS, CB, ID, IP, PL, TB, DB, SCB]
end, [TRIGGER_TYPE_SYMBOL, HANDSHAKE_TYPE_SYMBOL, CALLBACKS_TYPE_SYMBOL, ID_TYPE_SYMBOL, INPUT_TYPE_SYMBOL, PLUGIN_TYPE_SYMBOL, TIMEBUF_TYPE_SYMBOL, DATABUF_TYPE_SYMBOL, SINK_CALLBACK_TYPE_SYMBOL]
_append_common_fields!(ex, fields...)
deftype(ex)
end
Expand Down
23 changes: 5 additions & 18 deletions src/components/sources/generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,15 @@ julia> gen.output
```
"""
macro def_source(ex)
#= NOTE:
Generate the parameter names TR, HS, CB, ID of types of trigger, handshake, callbacks, id by using
`gensym` to avoid duplicate type parameter names so that the users can parametrizde their types as
@def_source struct Mygen{RO, TR} <: AbstractSource
readout::RO = t -> sin(t)
output::TR = Outport()
end
Note that the parameter name of output is TR. But, since the parameter name TR of trigger of the compnent
is generated by `gensym`, we get rid of duplicate parameter names.
=#
ex.args[2].head == :(<:) && ex.args[2].args[2] == :AbstractSource ||
error("Invalid usage. The type should be a subtype of AbstractSource.\n$ex")
TR, HS, CB, ID = [gensym() for i in 1 : 4]
fields = quote
trigger::$(TR) = Inpin()
handshake::$(HS) = Outpin{Bool}()
callbacks::$(CB) = nothing
trigger::$(TRIGGER_TYPE_SYMBOL) = Inpin()
handshake::$(HANDSHAKE_TYPE_SYMBOL) = Outpin{Bool}()
callbacks::$(CALLBACKS_TYPE_SYMBOL) = nothing
name::Symbol = Symbol()
id::$(ID) = Causal.uuid4()
end, [TR, HS, CB, ID]
id::$(ID_TYPE_SYMBOL) = Causal.uuid4()
end, [TRIGGER_TYPE_SYMBOL, HANDSHAKE_TYPE_SYMBOL, CALLBACKS_TYPE_SYMBOL, ID_TYPE_SYMBOL]
_append_common_fields!(ex, fields...)
deftype(ex)
end
Expand Down
23 changes: 11 additions & 12 deletions src/components/systems/dynamicalsystems/daesystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,23 @@ macro def_dae_system(ex)
is generated by `gensym`, we get rid of duplicate parameter names.
=#
checksyntax(ex, :AbstractDAESystem)
TR, HS, CB, ID, MA, MK, SA, SK, AL, IT = [gensym() for i in 1 : 10]
fields = quote
trigger::$(TR) = Inpin()
handshake::$(HS) = Outpin{Bool}()
callbacks::$(CB) = nothing
trigger::$(TRIGGER_TYPE_SYMBOL) = Inpin()
handshake::$(HANDSHAKE_TYPE_SYMBOL) = Outpin{Bool}()
callbacks::$(CALLBACKS_TYPE_SYMBOL) = nothing
name::Symbol = Symbol()
id::$(ID) = Causal.uuid4()
id::$(ID_TYPE_SYMBOL) = Causal.uuid4()
t::Float64 = 0.
modelargs::$(MA) = ()
modelkwargs::$(MK) = NamedTuple()
solverargs::$(SA) = ()
solverkwargs::$(SK) = NamedTuple()
alg::$(AL) = Causal.IDA()
integrator::$(IT) = Causal.construct_integrator(Causal.DAEProblem, input, righthandside, state, t, modelargs,
modelargs::$(MODEL_ARGS_TYPE_SYMBOL) = ()
modelkwargs::$(MODEL_KWARGS_TYPE_SYMBOL) = NamedTuple()
solverargs::$(SOLVER_ARGS_TYPE_SYMBOL) = ()
solverkwargs::$(SOLVER_KWARGS_TYPE_SYMBOL) = NamedTuple()
alg::$(ALG_TYPE_SYMBOL) = Causal.IDA()
integrator::$(INTEGRATOR_TYPE_SYMBOL) = Causal.construct_integrator(Causal.DAEProblem, input, righthandside, state, t, modelargs,
solverargs; alg=alg, stateder=stateder, modelkwargs=(;
zip((keys(modelkwargs)..., :differential_vars), (values(modelkwargs)..., diffvars))...),
solverkwargs=solverkwargs, numtaps=3)
end, [TR, HS, CB, ID, MA, MK, SA, SK, AL, IT]
end, [TRIGGER_TYPE_SYMBOL, HANDSHAKE_TYPE_SYMBOL, CALLBACKS_TYPE_SYMBOL, ID_TYPE_SYMBOL, MODEL_ARGS_TYPE_SYMBOL, MODEL_KWARGS_TYPE_SYMBOL, SOLVER_ARGS_TYPE_SYMBOL, SOLVER_KWARGS_TYPE_SYMBOL, ALG_TYPE_SYMBOL, INTEGRATOR_TYPE_SYMBOL]
_append_common_fields!(ex, fields...)
deftype(ex)
end
Expand Down
42 changes: 11 additions & 31 deletions src/components/systems/dynamicalsystems/ddesystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,48 +82,28 @@ julia> ds = MyDDESystem();
```
"""
macro def_dde_system(ex)
#= NOTE:
Generate the parameter names TR, HS, CB, ID, MA, MK, SA, SK, AL, IT of types of trigger, handshake, callbacks,
id, modelargs, modelkwargs, solverargs, solverkwargs, alg, integrator by using `gensym` to avoid duplicate type
parameter names so that the users can parametrizde their types as
@def_dde_system mutable struct MyDDESystem{CL, DL, RH, HST, RO, ST, IP, TR} <: AbstractDDESystem
constlags::CL
depslags::DL
righthandside::RH
history::HST
readout::RO
state::ST
input::IP
output::TR
end
Note that the parameter name of output is TR. But, since the parameter name TR of trigger of the compnent
is generated by `gensym`, we get rid of duplicate parameter names.
=#
checksyntax(ex, :AbstractDDESystem)
TR, HS, CB, ID, MA, MK, SA, SK, AL, IT = [gensym() for i in 1 : 10]
fields = quote
trigger::$(TR) = Inpin()
handshake::$(HS) = Outpin{Bool}()
callbacks::$(CB) = nothing
trigger::$(TRIGGER_TYPE_SYMBOL) = Inpin()
handshake::$(HANDSHAKE_TYPE_SYMBOL) = Outpin{Bool}()
callbacks::$(CALLBACKS_TYPE_SYMBOL) = nothing
name::Symbol = Symbol()
id::$(ID) = Causal.uuid4()
id::$(ID_TYPE_SYMBOL) = Causal.uuid4()
t::Float64 = 0.
modelargs::$(MA) = ()
modelkwargs::$(MK) = NamedTuple()
solverargs::$(SA) = ()
solverkwargs::$(SK) = NamedTuple()
alg::$(AL) = Causal.MethodOfSteps(Causal.Tsit5())
integrator::$(IT) = Causal.construct_integrator(
modelargs::$(MODEL_ARGS_TYPE_SYMBOL) = ()
modelkwargs::$(MODEL_KWARGS_TYPE_SYMBOL) = NamedTuple()
solverargs::$(SOLVER_ARGS_TYPE_SYMBOL) = ()
solverkwargs::$(SOLVER_KWARGS_TYPE_SYMBOL) = NamedTuple()
alg::$(ALG_TYPE_SYMBOL) = Causal.MethodOfSteps(Causal.Tsit5())
integrator::$(INTEGRATOR_TYPE_SYMBOL) = Causal.construct_integrator(
Causal.DDEProblem, input, (righthandside, history), state, t, modelargs, solverargs;
alg=alg, modelkwargs=(;
zip(
(keys(modelkwargs)..., :constant_lags, :dependent_lags),
(values(modelkwargs)..., constlags, depslags))...
),
solverkwargs=solverkwargs, numtaps=3)
end, [TR, HS, CB, ID, MA, MK, SA, SK, AL, IT]
end, [TRIGGER_TYPE_SYMBOL, HANDSHAKE_TYPE_SYMBOL, CALLBACKS_TYPE_SYMBOL, ID_TYPE_SYMBOL, MODEL_ARGS_TYPE_SYMBOL, MODEL_KWARGS_TYPE_SYMBOL, SOLVER_ARGS_TYPE_SYMBOL, SOLVER_KWARGS_TYPE_SYMBOL, ALG_TYPE_SYMBOL, INTEGRATOR_TYPE_SYMBOL]
_append_common_fields!(ex, fields...)
deftype(ex)
end
Expand Down
24 changes: 12 additions & 12 deletions src/components/systems/dynamicalsystems/discretesystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ macro def_discrete_system(ex)
is generated by `gensym`, we get rid of duplicate parameter names.
=#
checksyntax(ex, :AbstractDiscreteSystem)
TR, HS, CB, ID, MA, MK, SA, SK, AL, IT = [gensym() for i in 1 : 10]
# TR, HS, CB, ID, MA, MK, SA, SK, AL, IT = [gensym() for i in 1 : 10]
fields = quote
trigger::$(TR) = Inpin()
handshake::$(HS) = Outpin{Bool}()
callbacks::$(CB) = nothing
trigger::$(TRIGGER_TYPE_SYMBOL) = Inpin()
handshake::$(HANDSHAKE_TYPE_SYMBOL) = Outpin{Bool}()
callbacks::$(CALLBACKS_TYPE_SYMBOL) = nothing
name::Symbol = Symbol()
id::$(ID )= Causal.uuid4()
id::$(ID_TYPE_SYMBOL)= Causal.uuid4()
t::Float64 = 0.
modelargs::$(MA) = ()
modelkwargs::$(MK) = NamedTuple()
solverargs::$(SA) = ()
solverkwargs::$(SK) = NamedTuple()
alg::$(AL) = Causal.FunctionMap()
integrator::$(IT) = Causal.construct_integrator(Causal.DiscreteProblem, input, righthandside, state, t,
modelargs::$(MODEL_ARGS_TYPE_SYMBOL) = ()
modelkwargs::$(MODEL_KWARGS_TYPE_SYMBOL) = NamedTuple()
solverargs::$(SOLVER_ARGS_TYPE_SYMBOL) = ()
solverkwargs::$(SOLVER_KWARGS_TYPE_SYMBOL) = NamedTuple()
alg::$(ALG_TYPE_SYMBOL) = Causal.FunctionMap()
integrator::$(INTEGRATOR_TYPE_SYMBOL) = Causal.construct_integrator(Causal.DiscreteProblem, input, righthandside, state, t,
modelargs, solverargs; alg=alg, modelkwargs=modelkwargs, solverkwargs=solverkwargs, numtaps=3)
end, [TR, HS, CB, ID, MA, MK, SA, SK, AL, IT]
end, [TRIGGER_TYPE_SYMBOL, HANDSHAKE_TYPE_SYMBOL, CALLBACKS_TYPE_SYMBOL, ID_TYPE_SYMBOL, MODEL_ARGS_TYPE_SYMBOL, MODEL_KWARGS_TYPE_SYMBOL, SOLVER_ARGS_TYPE_SYMBOL, SOLVER_KWARGS_TYPE_SYMBOL, ALG_TYPE_SYMBOL, INTEGRATOR_TYPE_SYMBOL]
_append_common_fields!(ex, fields...)
deftype(ex)
end
Expand Down
39 changes: 11 additions & 28 deletions src/components/systems/dynamicalsystems/odesystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,39 +65,22 @@ julia> ds.input
```
"""
macro def_ode_system(ex)
#= NOTE:
Generate the parameter names TR, HS, CB, ID, MA, MK, SA, SK, AL, IT of types of trigger, handshake, callbacks,
id, modelargs, modelkwargs, solverargs, solverkwargs, alg, integrator by using `gensym` to avoid duplicate type
parameter names so that the users can parametrizde their types as
@def_discrete_system mutablestruct MyODESystem{RH, RO, ST, IP, TR} <: AbstractODESystem
righthandside::RH
readout::RO
state::ST
input::IP
output::TR
end
Note that the parameter name of output is TR. But, since the parameter name TR of trigger of the compnent
is generated by `gensym`, we get rid of duplicate parameter names.
=#
checksyntax(ex, :AbstractODESystem)
TR, HS, CB, ID, MA, MK, SA, SK, AL, IT = [gensym() for i in 1 : 10]
fields = quote
trigger::$(TR) = Inpin()
handshake::$(HS) = Outpin{Bool}()
callbacks::$(CB) = nothing
trigger::$(TRIGGER_TYPE_SYMBOL) = Inpin()
handshake::$(HANDSHAKE_TYPE_SYMBOL) = Outpin{Bool}()
callbacks::$(CALLBACKS_TYPE_SYMBOL) = nothing
name::Symbol = Symbol()
id::$(ID) = Causal.uuid4()
id::$(ID_TYPE_SYMBOL) = Causal.uuid4()
t::Float64 = 0.
modelargs::$(MA) = ()
modelkwargs::$(MK) = NamedTuple()
solverargs::$(SA) = ()
solverkwargs::$(SK) = NamedTuple()
alg::$(AL) = Causal.Tsit5()
integrator::$(IT) = Causal.construct_integrator(Causal.ODEProblem, input, righthandside, state, t, modelargs,
modelargs::$(MODEL_ARGS_TYPE_SYMBOL) = ()
modelkwargs::$(MODEL_KWARGS_TYPE_SYMBOL) = NamedTuple()
solverargs::$(SOLVER_ARGS_TYPE_SYMBOL) = ()
solverkwargs::$(SOLVER_KWARGS_TYPE_SYMBOL) = NamedTuple()
alg::$(ALG_TYPE_SYMBOL) = Causal.Tsit5()
integrator::$(INTEGRATOR_TYPE_SYMBOL) = Causal.construct_integrator(Causal.ODEProblem, input, righthandside, state, t, modelargs,
solverargs; alg=alg, modelkwargs=modelkwargs, solverkwargs=solverkwargs, numtaps=3)
end, [TR, HS, CB, ID, MA, MK, SA, SK, AL, IT]
end, [TRIGGER_TYPE_SYMBOL, HANDSHAKE_TYPE_SYMBOL, CALLBACKS_TYPE_SYMBOL, ID_TYPE_SYMBOL, MODEL_ARGS_TYPE_SYMBOL, MODEL_KWARGS_TYPE_SYMBOL, SOLVER_ARGS_TYPE_SYMBOL, SOLVER_KWARGS_TYPE_SYMBOL, ALG_TYPE_SYMBOL, INTEGRATOR_TYPE_SYMBOL]
_append_common_fields!(ex, fields...)
deftype(ex)
end
Expand Down
Loading

0 comments on commit 6a5796d

Please sign in to comment.