Skip to content

Commit

Permalink
mtk models added
Browse files Browse the repository at this point in the history
  • Loading branch information
ivborissov committed Jul 26, 2024
1 parent c304ba4 commit f6489ac
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 0 deletions.
112 changes: 112 additions & 0 deletions cases/mtk/events/nameless.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#=
This code was generated by heta-compiler
=#

function get_MTKmodel()

### Define independent and dependent variables ###

@variables t
__ruleVariables__ = @variables a0(t) s1(t) s2(t) vabs(t) vel(t)
__dynamicVariables__ = @variables _a0_(t) _s1_(t)

### Define potential algebraic variables ###

### Define parameters (constants and statics) ###
__constParameters__ = @parameters kabs kel sw2_start
__staticParameters__ = @parameters _s2_ comp0 comp1

### Define an operator for the differentiation w.r.t. time
__D__ = Differential(t)

### ODE Equations ###
__eqs__ = [
# extended rules
a0 ~ _a0_,
s1 ~ _s1_/ comp1,
s2 ~ _s2_/ comp1,
vabs ~ kabs * a0,
vel ~ kel * s1 * comp1,

# ODEs
__D__(_a0_) ~ -vabs, # da0/dt
__D__(_s1_) ~ vabs-vel, # ds1/dt
]

### TIME EVENTS ###
#=
function __sw0_tstops__(__constants__, __times__)
return [40.0]
end
function __sw1_tstops__(__constants__, __times__)
return 12.0 > 0.0 ? collect(range(0.0, 60.0; step=12.0)) : [0.0]
end
function __sw2_tstops__(__constants__, __times__)
return 24.0 > 0.0 ? collect(range(__constants__[3], __times__[2]; step=24.0)) : [__constants__[3]]
end
=#
__sw0_tstops__ = (t == [40.])
__sw1_tstops__ = (t in collect(range(0.0, 60.0; step=12.0)))
__sw2_tstops__ = (t in collect(range(sw2_start, 100.; step=24.0)))



### C EVENTS ###

### STOP EVENTS ###

### EVENTS ASSIGNMENTS ###
__sw0_affect__ = [
]
__sw1_affect__ = [
_a0_ ~ (a0 + 1e+1),
comp1 ~ 6e+0,
]
__sw2_affect__ = [
_s1_ ~ (s1 + 2e+0) * comp1,
_s2_ ~ (s2 + 2e+0) * comp1,
]


### Initialization ###

__constValues__ = [
kabs => 0.01,
kel => 0.01,
sw2_start => 5,
]

__init__ = [
a0 => 0e+0,
s1 => 0e+0,
s2 => 0e+0,
comp0 => 1e+0,
comp1 => 5.2,
vabs => kabs * a0,
vel => kel * s1 * comp1,
]

__amountsInit__ = [
_a0_ => a0,
_s1_ => s1 * comp1,
_s2_ => s2 * comp1,
]

### ODESystem definition ###
__sys__ = ODESystem(__eqs__, t, [__dynamicVariables__; __ruleVariables__], [__constParameters__; __staticParameters__],
name = :nameless,
discrete_events = [__sw0_tstops__=>__sw0_affect__, __sw1_tstops__=>__sw1_affect__, __sw2_tstops__=>__sw2_affect__],
defaults = [__constValues__; __init__; __amountsInit__]
)

return (
structural_simplify(__sys__),
__amountsInit__,
__constValues__
)

end # function __get_nameless_model__

__model__ = get_MTKmodel()
106 changes: 106 additions & 0 deletions cases/mtk/events/nameless2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#=
This code was generated by heta-compiler
=#

function __get_nameless_model__()

### Define independent and dependent variables ###

@variables t
__ruleVariables__ = @variables x1(t) x2(t) r1(t) x3(t) cond1(t)
__dynamicVariables__ = @variables _x1_(t) _x2_(t)

### Define potential algebraic variables ###

### Define parameters (constants and statics) ###
__constParameters__ = @parameters k1
__staticParameters__ = @parameters comp1 p1 _x3_

### Define an operator for the differentiation w.r.t. time
__D__ = Differential(t)

### ODE Equations ###
__eqs__ = [
# extended rules
x1 ~ _x1_/ comp1,
x2 ~ _x2_/ comp1,
r1 ~ k1 * x1 * comp1,
x3 ~ _x3_/ comp1,
cond1 ~ 6e+0 - x1,

# ODEs
__D__(_x1_) ~ -r1, # dx1/dt
__D__(_x2_) ~ r1, # dx2/dt
]

### TIME EVENTS ###

### C EVENTS ###
__sw1_condition__ = [cond1 ~ 0.0]

### STOP EVENTS ###

### EVENTS ASSIGNMENTS ###
function _sw1_affect_func_(__integrator__)
t = __integrator__.t
(comp1,p1,x3_,) = __integrator__.p[1:]
__constants__ = __integrator__.p[NaN:NaN]
(x1_,x2_,) = __integrator__.u

# Heta rules
x2 = x2_ / comp1
x1 = x1_ / comp1

# recalculated values
(x1,p1,) = (x1 + 1e+1,x1 * 2e+0,)

# save results
__integrator__.u[[1,]] = [
x1*comp1,
]
__integrator__.p[[2,]] = [
p1,
]
end


### Initialization ###

__constValues__ = [
k1 => 0.01,
]

__init__ = [
comp1 => 1e+0,
x1 => 1e+1,
x2 => 0e+0,
r1 => k1 * x1 * comp1,
p1 => 1e+1,
x3 => 12.12,
cond1 => 6e+0 - x1,
]

__amountsInit__ = [
_x1_ => x1 * comp1,
_x2_ => x2 * comp1,
_x3_ => x3 * comp1,
]

### ODESystem definition ###
__sys__ = ODESystem(__eqs__, t, [__dynamicVariables__; __ruleVariables__], [__constParameters__; __staticParameters__],
name = :nameless,
discrete_events = [],
defaults = [__constValues__; __init__; __amountsInit__]
)

return (
structural_simplify(__sys__),
[__constValues__; __init__; __amountsInit__],
NamedTuple{()}([]),
NamedTuple{(:sw1, )}([(__sw1_condition__, __sw1_affect__, false), ]),
NamedTuple{()}([]),
)

end # function __get_nameless_model__

__model__ = __get_nameless_model__()
Empty file.
6 changes: 6 additions & 0 deletions cases/mtk/events/run_nameless2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using HetaSimulator, Plots
using DiffEqCallbacks

m = load_mtkmodel("$HetaSimulatorDir/cases/mtk/events/nameless2.jl")
observed(m.sys)
equations(m.sys)

0 comments on commit f6489ac

Please sign in to comment.