From 0be7218573b32bc08f9e5cbe69fa56c68548f21e Mon Sep 17 00:00:00 2001 From: Evgeny Metelkin Date: Tue, 6 Feb 2024 12:37:52 +0200 Subject: [PATCH] exchange static and constants in Julia export --- cases/0-hello-world/master/mm_julia/model.jl | 12 ++++---- src/templates/julia-model.jl.njk | 30 ++++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cases/0-hello-world/master/mm_julia/model.jl b/cases/0-hello-world/master/mm_julia/model.jl index b0727ac7..3a5ec0e2 100644 --- a/cases/0-hello-world/master/mm_julia/model.jl +++ b/cases/0-hello-world/master/mm_julia/model.jl @@ -49,16 +49,16 @@ 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 @@ -66,7 +66,7 @@ function mm_ode_func_(__du__, __u__, __p__, t) 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 @@ -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 diff --git a/src/templates/julia-model.jl.njk b/src/templates/julia-model.jl.njk index 108fe5dc..fea5581d 100644 --- a/src/templates/julia-model.jl.njk +++ b/src/templates/julia-model.jl.njk @@ -101,10 +101,10 @@ 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 @@ -112,10 +112,10 @@ end {%- 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] #} @@ -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 %} @@ -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] #} @@ -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__ @@ -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__ @@ -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__ @@ -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 @@ -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) %}