Skip to content

Commit

Permalink
fix initial reassignment in dbsolve
Browse files Browse the repository at this point in the history
  • Loading branch information
metelkin committed Jun 30, 2020
1 parent d5ac040 commit cf1509f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/dbsolve-export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DBSolveExport extends _Export{
// create and sort expressions for RHS (rules)
image.ruleRecords = this.namespace
.sortExpressionsByContext('ode_', true)
.filter((x) => x.instanceOf('Species') || x.isRule );
.filter((x) => x.isDynamic || x.isRule );

// create TimeEvents
image.events = [];
Expand Down
25 changes: 12 additions & 13 deletions src/templates/model.slv.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
{%- set freeConstants = population.selectByClassName('Const') | selectattr('free') %}
{%- set constants = population.selectByClassName('Const') %}
{%- set species = population.selectByInstanceOf('Species') %}
{%- set speciesInConc = species | exclude2('isAmount', true) -%}

DBSolve Optimum (new parser) 1 Jul 2006
SLV25.00*
Expand Down Expand Up @@ -275,7 +274,7 @@ FIT Title for Y Axes
{% endfor -%}
>Compound Names
{% for compound in dynamicRecords -%}
#{{ compound.id }}{{ '_' if compound.instanceOf('Species') and not compound.isAmount }}
#{{ compound.id }}_
{% endfor -%}
>Mechanism Rate Low expression -Kinetic or Elementary constants
#0 0
Expand Down Expand Up @@ -434,17 +433,17 @@ if(t==0){
{%- endif %}
{%- endfor %}
// calculate initial amounts
{%- for spec in speciesInConc %}
{{ spec.id }}_start__ = {{ spec.id }} * {{ spec.compartment }};
{%- for dynamic in dynamicRecords %}
{{ dynamic.id }}_start__ = {{ dynamic.id }}{{ ' * ' + dynamic.compartment if dynamic.instanceOf('Species') and not dynamic.isAmount }};
{%- endfor %}
}else{

//! Calculation of ode_ part, count: {{ ruleRecords|length }}
{%- for record in ruleRecords %}
{% if record.isRule -%}
{{ record.id }} = {{ record.getAssignment('ode_').toSLVString(powTransform) }};
{%- elif record.instanceOf('Species') and not record.isAmount -%}
{{ record.id }} = {{ record.id }}_ / {{ record.compartment }};
{%- elif record.isDynamic -%}
{{ record.id }} = {{ record.id }}_{{ ' / '+ record.compartment if record.instanceOf('Species') and not record.isAmount}};
{%- endif -%}
{%- endfor %}

Expand Down Expand Up @@ -489,9 +488,9 @@ F[{{ loop.index }}] = {{ diff(dynamic.backReferences) }};
{{ con.id }} = {{ con.num }}; // @{{ con.className }} {{ "'" + con.title + "'" if con.title is defined }} {units: {{ con.units|default('?') }}};
{%- endfor %}

//! Species recalculated to amounts
{%- for dynamic in speciesInConc %}
{{ dynamic.id }}_ = 0; // {{ dynamic.id }} { isAmount: false };
//! Auxilary variables
{%- for dynamic in dynamicRecords %}
{{ dynamic.id }}_ = 0; // {{ dynamic.id }};
{%- endfor %}

{% set switchers = population.selectByClassName('TimeSwitcher') %}
Expand Down Expand Up @@ -784,11 +783,11 @@ k1
1000000
{{ 0 if eventsOff else 1 }}
{% block events -%}
{{ speciesInConc.length + eventCounter }}
{%- for spec in speciesInConc %}{# init events #}
{{ spec.id }}_
{{ dynamicRecords.length + eventCounter }}
{%- for dynamic in dynamicRecords %}{# init events #}
{{ dynamic.id }}_
0
{{ spec.id }}_start__
{{ dynamic.id }}_start__
0
0
1
Expand Down

0 comments on commit cf1509f

Please sign in to comment.