Skip to content

Commit

Permalink
Fix storing the new value of the continuous state vector
Browse files Browse the repository at this point in the history
  • Loading branch information
stewid committed Jan 27, 2020
1 parent 07d1f42 commit 3665ce8
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/solvers/SimInf_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright (C) 2015 Pavol Bauer
* Copyright (C) 2017 -- 2019 Robin Eriksson
* Copyright (C) 2015 -- 2019 Stefan Engblom
* Copyright (C) 2015 -- 2019 Stefan Widgren
* Copyright (C) 2015 -- 2020 Stefan Widgren
*
* SimInf is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -640,7 +640,7 @@ void SimInf_store_solution_sparse(SimInf_compartment_model *model)
/* Copy continuous state to V_sparse */
for (j = model[0].jcV[model[0].V_it];
j < model[0].jcV[model[0].V_it + 1]; j++)
model[0].prV[j] = model[0].v[model[0].irV[j]];
model[0].prV[j] = model[0].v_new[model[0].irV[j]];
model[0].V_it++;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/solvers/aem/SimInf_solver_aem.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright (C) 2015 Pavol Bauer
* Copyright (C) 2017 -- 2019 Robin Eriksson
* Copyright (C) 2015 -- 2019 Stefan Engblom
* Copyright (C) 2015 -- 2019 Stefan Widgren
* Copyright (C) 2015 -- 2020 Stefan Widgren
*
* SimInf is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -337,7 +337,7 @@ static int SimInf_solver_aem(
/* Copy continuous state to V */
while (sa.V && sa.V_it < sa.tlen && sa.tt > sa.tspan[sa.V_it])
memcpy(&sa.V[sa.Nd * ((sa.Ntot * sa.V_it++) + sa.Ni)],
sa.v, sa.Nn * sa.Nd * sizeof(double));
sa.v_new, sa.Nn * sa.Nd * sizeof(double));

*&model[i] = sa;
*&method[i] = ma;
Expand Down
4 changes: 2 additions & 2 deletions src/solvers/ssm/SimInf_solver_ssm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright (C) 2015 Pavol Bauer
* Copyright (C) 2017 -- 2019 Robin Eriksson
* Copyright (C) 2015 -- 2019 Stefan Engblom
* Copyright (C) 2015 -- 2019 Stefan Widgren
* Copyright (C) 2015 -- 2020 Stefan Widgren
*
* SimInf is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -257,7 +257,7 @@ static int SimInf_solver_ssm(
/* Copy continuous state to V */
while (m.V && m.V_it < m.tlen && m.tt > m.tspan[m.V_it])
memcpy(&m.V[m.Nd * ((m.Ntot * m.V_it++) + m.Ni)],
m.v, m.Nn * m.Nd * sizeof(double));
m.v_new, m.Nn * m.Nd * sizeof(double));

*&model[i] = m;
}
Expand Down
110 changes: 64 additions & 46 deletions tests/phi.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Copyright (C) 2015 Pavol Bauer
## Copyright (C) 2017 -- 2019 Robin Eriksson
## Copyright (C) 2015 -- 2019 Stefan Engblom
## Copyright (C) 2015 -- 2019 Stefan Widgren
## Copyright (C) 2015 -- 2020 Stefan Widgren
##
## SimInf is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
Expand All @@ -31,39 +31,56 @@ sessionInfo()
tol <- 1e-8

## Expected phi
phi_exp <- c(1, 0.228812574827662, 0.0523896281322291, 0.0120297167737883,
0.00279666361731157, 0.000684437209448165, 0.000201227557942374,
9.06846888450544e-05, 6.53960261079013e-05, 5.96107912188877e-05,
5.82873150402961e-05, 5.79845461417288e-05, 5.79152823291854e-05,
6.39789936374658e-05, 9.42765209017355e-05, 0.000110545295549532,
0.000119281091914435, 0.000123971926951566, 0.000126490750928962,
0.000127843276476948, 0.000128569538166677, 0.000128959516783166,
0.000129168922460856, 0.00012928136641546, 0.000129341745117061,
0.000129374166491958, 0.000130685472705078, 0.000137406872101236,
0.000141301373209865, 0.000143557918014179, 0.000144865401132516,
0.000145622980641447, 0.000146061935993378, 0.000146316274711252,
0.00014646364319218, 0.000146549031171458, 0.000146598506520319,
0.000146627173437672, 0.000146643783571192, 0.000130521651183348,
7.64318047731465e-05, 6.35130989329827e-05, 6.04276222370606e-05,
5.96906934332883e-05, 5.95146868983672e-05, 5.94726498655136e-05,
5.94626098284665e-05, 5.94602118870071e-05, 5.9459639167682e-05,
5.94595023805956e-05, 5.94594697106539e-05, 5.94594619078333e-05,
5.94594600442239e-05, 5.82526953215486e-05, 5.79766262605224e-05,
5.79134705143992e-05, 5.78990225054351e-05, 5.78957172644106e-05,
5.78949611312813e-05, 5.78947881522746e-05, 5.78947485802262e-05,
5.78947395274109e-05, 5.78947374564171e-05, 5.78947369826401e-05,
5.78947368742551e-05, 5.78947368494601e-05, 9.10094753200943e-05,
0.000108790999633954, 0.000118339092764896, 0.000123466104421938,
0.000126219140883875, 0.000127697430825022, 0.000128491223853306,
0.000128917464575247, 0.000129146341809699, 0.000129269241349217,
0.000129335234355685, 0.000129370670427455, 0.000129389698431324,
0.000136656076909902, 0.000140866348814994, 0.000143305856964351,
0.000144719352373896, 0.000145538357333289, 0.000146012903708877,
0.00014628786451345, 0.000146447181806639, 0.000146539493145154,
0.00014659298001433, 0.000146623971279545, 0.000146641928182509,
0.000146652332738819, 8.02844230341808e-05, 6.44332502244339e-05,
6.06473892479069e-05, 5.97431821267293e-05, 5.95272231881794e-05,
5.94756440067648e-05, 5.94633249429036e-05, 5.94603826834443e-05)
phi_exp <- c(0.810011, 0.185349185610407, 0.0424465987871056,
0.00975507058676853, 0.00227629753002237,
0.000565394139653014, 0.000173994321933323,
8.44545979644941e-05, 6.39707811474e-05,
5.9284740887299e-05, 5.82127251826398e-05,
5.79674823748003e-05, 5.79113786866402e-05,
6.95407791782812e-05, 9.7263016625088e-05,
0.000112148945427821, 0.000120142199101708,
0.000124434313160683, 0.0001267390371,
0.000127976597976407, 0.00012864112742251,
0.000128997957856597, 0.000129189564051683,
0.000129292450270145, 0.000129347696782111,
0.000129377362340141, 0.000131884062252197,
0.000138101356693643, 0.000141703770219126,
0.000143791074163116, 0.000145000496047577,
0.000145701257093339, 0.000146107290793875,
0.000146342554107908, 0.000146478869952767,
0.000146557853833598, 0.000146603618531295,
0.000146630135429847, 0.000146645499803353,
0.000117375145714429, 7.32919208901144e-05,
6.27631756303809e-05, 6.02485121232044e-05,
5.964791514813e-05, 5.95044698221693e-05,
5.94702096403935e-05, 5.94620270102002e-05,
5.94600726879108e-05, 5.94596059216608e-05,
5.94594944401854e-05, 5.94594678141829e-05,
5.94594614548841e-05, 5.91621626358214e-05,
5.81846832104543e-05, 5.79610672710232e-05,
5.79099111166633e-05, 5.78982082294025e-05,
5.78955309841726e-05, 5.78949185163378e-05,
5.78947784033424e-05, 5.78947463499832e-05,
5.78947390172028e-05, 5.78947373396978e-05,
5.78947369559385e-05, 5.78947368681467e-05,
6.3973684217256e-05, 9.42736699178863e-05,
0.000110543764665068, 0.00011928026987988,
0.000123971485546074, 0.000126490513908745,
0.000127843149204895, 0.000128569469825775,
0.000128959480086351, 0.000129168902755875,
0.000129281355834533, 0.000129341739435452,
0.000129374163441121, 0.000130685471048975,
0.000137406871141659, 0.00014130137265387,
0.000143557917692025, 0.000144865400945854,
0.000145622980533292, 0.000146061935930711,
0.000146316274674941, 0.000146463643171141,
0.000146549031159267, 0.000146598506513255,
0.000146627173433579, 0.000146643783568821,
0.000130521651182138, 7.64318047728573e-05,
6.35130989329136e-05, 6.04276222370442e-05,
5.96906934332844e-05, 5.95146868983662e-05,
5.94726498655133e-05, 5.94626098284664e-05,
5.94602118870071e-05)

## Check phi from the SISe model
sis_e <- SISe(u0 = data.frame(S = 100, I = 0),
Expand Down Expand Up @@ -160,18 +177,19 @@ if (SimInf:::have_openmp()) {
}

## Check decay of phi for various configurations of the intervals.
## [1, 2) 1*0.97
## [2, 3) 1*0.97*0.97
## [3, 4) 1*0.97*0.97*0.95
## [4, 5) 1*0.97*0.97*0.95*0.95
## [5, 6) 1*0.97*0.97*0.95*0.95*0.93
## [6, 7) 1*0.97*0.97*0.95*0.95*0.93*0.93
## [7, 8) 1*0.97*0.97*0.95*0.95*0.93*0.93*0.91
## [8, 9) 1*0.97*0.97*0.95*0.95*0.93*0.93*0.91*0.91
## [9, 10) 1*0.97*0.97*0.95*0.95*0.93*0.93*0.91*0.91*0.97
phi <- c(1, 0.97, 0.9409, 0.893855, 0.84916225,
0.7897208925, 0.734440430025, 0.66834079132275,
0.608190120103702, 0.589944416500591)
## [1, 2) 1*0.97
## [2, 3) 1*0.97*0.97
## [3, 4) 1*0.97*0.97*0.95
## [4, 5) 1*0.97*0.97*0.95*0.95
## [5, 6) 1*0.97*0.97*0.95*0.95*0.93
## [6, 7) 1*0.97*0.97*0.95*0.95*0.93*0.93
## [7, 8) 1*0.97*0.97*0.95*0.95*0.93*0.93*0.91
## [8, 9) 1*0.97*0.97*0.95*0.95*0.93*0.93*0.91*0.91
## [9, 10) 1*0.97*0.97*0.95*0.95*0.93*0.93*0.91*0.91*0.97
## [10, 11) 1*0.97*0.97*0.95*0.95*0.93*0.93*0.91*0.91*0.97*0.97
phi <- c(0.97, 0.9409, 0.893855, 0.84916225, 0.7897208925,
0.734440430025, 0.66834079132275, 0.608190120103702,
0.589944416500591, 0.572246084005574)

model <- SISe(u0 = data.frame(S = 1, I = 0),
tspan = 1:10,
Expand Down

0 comments on commit 3665ce8

Please sign in to comment.