Skip to content

Commit

Permalink
Merge branch '__p__'
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Feb 6, 2024
2 parents bbdba08 + 0be7218 commit e05e1f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions cases/0-hello-world/master/mm_julia/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ function mm_init_func_(__constants__)
P * default_comp,
],
Float64[
__constants__...,
default_comp,
__constants__...
]
)
end

### calculate RHS of ODE
function mm_ode_func_(__du__, __u__, __p__, t)
__constants__ = __p__[1:2]
(default_comp,) = __p__[3:3]
(default_comp,) = __p__[1:1]
__constants__ = __p__[2:3]
(S_,P_,) = __u__

# Heta rules
P = P_ / default_comp
S = S_ / default_comp
r1 = __constants__[1] * S / (__constants__[2] + S) * default_comp

#__p__[3:3] .= [default_comp,]
#__p__[1:1] .= [default_comp,]
__du__ .= [
-r1, # dS_/dt
r1, # dP_/dt
Expand All @@ -85,8 +85,8 @@ function mm_saving_generator_(__outputIds__::Vector{Symbol})
end

function saving_(__u__, t, __integrator__)
__constants__ = __integrator__.p[1:2]
(default_comp,) = __integrator__.p[3:3]
(default_comp,) = __integrator__.p[1:1]
__constants__ = __integrator__.p[2:3]
(S_,P_,) = __u__

# Heta rules
Expand Down
30 changes: 15 additions & 15 deletions src/templates/julia-model.jl.njk
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,21 @@ function {{ id }}_init_func_(__constants__)
[ 0.0 ], # init for fake variable
{%- endif %}
Float64[
__constants__...,
{%- for record in img.staticRecords %}
{{ record.id }}{{ '*' + record.compartment if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}
__constants__...
]
)
end
{% set constantMaxIndex = img.constants | length %}
{%- set staticMaxIndex = img.staticRecords | length %}
### calculate RHS of ODE
function {{ id }}_ode_func_(__du__, __u__, __p__, t)
__constants__ = __p__[1:{{ constantMaxIndex }}]
({% for record in img.staticRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __p__[{{ constantMaxIndex + 1 }}:{{ constantMaxIndex + staticMaxIndex }}]
{%- endfor %}) = __p__[1:{{ staticMaxIndex }}]
__constants__ = __p__[{{ staticMaxIndex + 1 }}:{{ staticMaxIndex + constantMaxIndex }}]
({% for record in img.dynamicRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __u__ {# TODO: replace by __u__[index] #}
Expand All @@ -131,7 +131,7 @@ function {{ id }}_ode_func_(__du__, __u__, __p__, t)
{{ record.id }} = {{ record.id }}_ / {{ record.compartment }}
{% endif -%}
{% endfor %}
#__p__[{{ constantMaxIndex + 1 }}:{{ constantMaxIndex + staticMaxIndex }}] .= [{% for record in img.staticRecords -%}
#__p__[1:{{ staticMaxIndex }}] .= [{% for record in img.staticRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}]
{%- if img.dynamicRecords | length > 0 %}
Expand Down Expand Up @@ -163,10 +163,10 @@ function {{ id }}_saving_generator_(__outputIds__::Vector{Symbol})
end

function saving_(__u__, t, __integrator__)
__constants__ = __integrator__.p[1:{{ img.constants | length }}]
({% for record in img.staticRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __integrator__.p[{{ constantMaxIndex + 1 }}:{{ constantMaxIndex + staticMaxIndex }}]
{%- endfor %}) = __integrator__.p[1:{{ staticMaxIndex }}]
__constants__ = __integrator__.p[{{ staticMaxIndex + 1 }}:{{ staticMaxIndex + constantMaxIndex }}]
({% for record in img.dynamicRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __u__{# TODO: replace by __u__[index] #}
Expand Down Expand Up @@ -219,10 +219,10 @@ end

{%- for event in img.events | filter2('switcher.className', 'DSwitcher') %}
function {{ id }}_{{ event.switcher.id }}_condition_func_(__u__, t, __integrator__)
__constants__ = __integrator__.p[1:{{ img.constants | length }}]
({% for record in img.staticRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __integrator__.p[{{ constantMaxIndex + 1 }}:{{ constantMaxIndex + staticMaxIndex }}]
{%- endfor %}) = __integrator__.p[1:{{ staticMaxIndex }}]
__constants__ = __integrator__.p[{{ staticMaxIndex + 1 }}:{{ staticMaxIndex + constantMaxIndex }}]
({% for record in img.dynamicRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __u__
Expand All @@ -245,10 +245,10 @@ end

{%- for event in img.events | filter2('switcher.className', 'CSwitcher') %}
function {{ id }}_{{ event.switcher.id }}_condition_func_(__u__, t, __integrator__)
__constants__ = __integrator__.p[1:{{ img.constants | length }}]
({% for record in img.staticRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __integrator__.p[{{ constantMaxIndex + 1 }}:{{ constantMaxIndex + staticMaxIndex }}]
{%- endfor %}) = __integrator__.p[1:{{ staticMaxIndex }}]
__constants__ = __integrator__.p[{{ staticMaxIndex + 1}}:{{ staticMaxIndex + constantMaxIndex }}]
({% for record in img.dynamicRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __u__
Expand All @@ -273,10 +273,10 @@ end

{%- for event in img.events | filter2('switcher.className', 'StopSwitcher') %}
function {{ id }}_{{ event.switcher.id }}_condition_func_(__u__, t, __integrator__)
__constants__ = __integrator__.p[1:{{ img.constants | length }}]
({% for record in img.staticRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __integrator__.p[{{ constantMaxIndex + 1 }}:{{ constantMaxIndex + staticMaxIndex }}]
{%- endfor %}) = __integrator__.p[1:{{ staticMaxIndex }}]
__constants__ = __integrator__.p[{{ staticMaxIndex + 1 }}:{{ staticMaxIndex + constantMaxIndex }}]
({% for record in img.dynamicRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __u__
Expand All @@ -301,10 +301,10 @@ end
{% for event in img.events | exclude2('switcher.className', 'StopSwitcher') -%}
function {{ id }}_{{ event.switcher.id }}_affect_func_(__integrator__)
t = __integrator__.t
__constants__ = __integrator__.p[1:{{ img.constants | length }}]
({% for record in img.staticRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __integrator__.p[{{ constantMaxIndex + 1 }}:{{ constantMaxIndex + staticMaxIndex }}]
{%- endfor %}) = __integrator__.p[1:{{ staticMaxIndex }}]
__constants__ = __integrator__.p[{{ staticMaxIndex + 1 }}:{{ staticMaxIndex + constantMaxIndex }}]
({% for record in img.dynamicRecords -%}
{{ record.id }}{{ '_' if record.instanceOf('Species') and not record.isAmount }},
{%- endfor %}) = __integrator__.u
Expand Down Expand Up @@ -349,7 +349,7 @@ function {{ id }}_{{ event.switcher.id }}_affect_func_(__integrator__)
{%- endif %}
__integrator__.p[[
{%- for record in img.staticRecords -%}
{{ loop.index + constantMaxIndex + ',' if record.getAssignment(event.switcher.id) is defined }}
{{ loop.index + ',' if record.getAssignment(event.switcher.id) is defined }}
{%- endfor -%}
]] = [
{%- for record in img.staticRecords | exclude2('assignments.' + event.switcher.id, undefined) %}
Expand Down

0 comments on commit e05e1f0

Please sign in to comment.