Skip to content

Commit

Permalink
updated ODE library models
Browse files Browse the repository at this point in the history
  • Loading branch information
tnguyenh committed May 8, 2022
1 parent 2954818 commit 0a9c772
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 108 deletions.
Expand Up @@ -241,11 +241,11 @@ experiment simulation type: gui autorun: true {

output {
layout value: horizontal([0::50,vertical([1::50,2::50])::50]) tabs:true;
display action_button name:"Interaction matrix" {
display action_button name:"Interaction matrix" toolbar: false{
species button aspect:modern ;
event mouse_down action:activate_act;
}
display LV name: "Time series" refresh: every(1#cycle) type: java2D {
display LV name: "Time series" refresh: every(1#cycle) type: java2D toolbar: false{
chart "Population size" type: series background: rgb('white') x_range: 200 x_tick_line_visible: false{
loop i from: 0 to: max_species-1{
data "Species "+i value: first(solver_and_scheduler).pop[i] color: (species_list[i] != nil)?color_list[i]:rgb(0,0,0,0) marker: false;
Expand Down
Expand Up @@ -43,16 +43,16 @@ species agent_with_SIR_dynamic {
experiment Simulation type: gui {
float minimum_cycle_duration <- 0.1#s;
output {
layout #vertical;
display display_charts {
chart "Time series" type: series background: #white {
layout #vertical tabs: false;
display display_charts toolbar: false {
chart "Time series" type: series background: rgb(47,47,47) color: #white {
data 'S' value: first(agent_with_SIR_dynamic).S color: rgb(46,204,113) ;
data 'I' value: first(agent_with_SIR_dynamic).I color: rgb(231,76,60) ;
data 'R' value: first(agent_with_SIR_dynamic).R color: rgb(52,152,219) ;
}
}
display display_phase_portrait {
chart "Phase portrait" type: xy background: #white x_label:"S" y_label:"Y" x_range: {0,1600} y_range: {0,700}{
display display_phase_portrait toolbar: false {
chart "Phase portrait" type: xy background: rgb(47,47,47) color: #white x_label:"S" y_label:"Y" x_range: {0,1600} y_range: {0,700}{
data 'I vs S' value: [first(agent_with_SIR_dynamic).S,first(agent_with_SIR_dynamic).I] color: rgb(243,156,18) ;
}
}
Expand Down
Expand Up @@ -43,28 +43,28 @@ species LV_model {
experiment Displays type: gui {
float minimum_cycle_duration <- 0.1#s;
output {
layout #split;
display D1 synchronized:false {
chart 'Time series' type: series background: #white y_label:"pop" x_tick_line_visible: false{
layout #split tabs: false;
display D1 synchronized:false toolbar: false{
chart 'Time series' type: series background: rgb(47,47,47) color: #white y_label:"pop" x_tick_line_visible: false{
data "x" value: first(LV_model).x color: rgb(52,152,219);
data "y" value: first(LV_model).y color: rgb(41,128,185);
}
}
display D2 synchronized:false {
chart 'Time series - continuous display' type: series background: #white y_label:"pop" x_tick_line_visible: false{
display D2 synchronized:false toolbar: false{
chart 'Time series - continuous display' type: series background: rgb(47,47,47) color: #white y_label:"pop" x_tick_line_visible: false{
// chart 'Time series - continuous display' type: series x_serie: first(LV_model).t[] background: #white y_label:"pop"{
data "x" value: first(LV_model).x[] color: rgb(52,152,219) marker: false;
data "y" value: first(LV_model).y[] color: rgb(41,128,185) marker: false;
}
}
display D3 name: "Phase Portrait " synchronized:false {
chart 'Phase Portrait' type: xy background: #white x_label: "x" y_label:"y"{
display D3 name: "Phase Portrait " synchronized:false toolbar: false{
chart 'Phase Portrait' type: xy background: rgb(47,47,47) color: #white x_label: "x" y_label:"y"{
// Continuous display requires to pass a list of two values x and y
data "y(x(t))" value: [first(LV_model).x,first(LV_model).y] color: rgb(243,156,18);
}
}
display D4 name: "Phase Portrait - continuous display" synchronized:false {
chart 'Phase Portrait - continuous display' type: xy background: #white x_label: "x" y_label:"y"{
display D4 name: "Phase Portrait - continuous display" synchronized:false toolbar: false{
chart 'Phase Portrait - continuous display' type: xy background: rgb(47,47,47) color: #white x_label: "x" y_label:"y"{
// Continuous display requires to pass a list of two values x and y
data "y(x(t))" value: rows_list(matrix(first(LV_model).x[],first(LV_model).y[])) color: rgb(243,156,18) marker: false;
}
Expand Down
Expand Up @@ -112,9 +112,9 @@ experiment Simulation type: gui {
parameter 'Delta (I->R)' type: float var: _delta <- 0.2 category: "Parameters";

output {
layout #split;
display chart_3system_eq {
chart 'Split system' type: series background: #white x_tick_line_visible: false{
layout #split tabs: false;
display chart_3system_eq name: "Split system" toolbar: false{
chart 'Split system' type: series background: rgb(47,47,47) color: #white x_tick_line_visible: false{
data 'susceptible' value: first(S_agt).Ssize color: rgb(46,204,113) marker_shape: marker_circle;
data 'infected 1' value: first(I_agt).beta * first(I_agt).Isize color: rgb(231,76,60)+120 marker_shape: marker_diamond;
data 'infected 2' value: last(I_agt).beta * last(I_agt).Isize color: rgb(231,76,60)+100 marker_shape: marker_diamond;
Expand All @@ -124,8 +124,8 @@ experiment Simulation type: gui {

}

display chart_1system_eq {
chart 'unified system' type: series background: #white x_tick_line_visible: false{
display chart_1system_eq name: "Unified system" toolbar: false {
chart 'Unified system' type: series background: rgb(47,47,47) color: #white x_tick_line_visible: false{
data 'susceptible (maths)' value: first(my_SIR_maths).Sm color: rgb(46,204,113) marker_shape: marker_circle;
data 'infected (maths)' value: first(my_SIR_maths).Im color: rgb(231,76,60) marker_shape: marker_circle;
data 'recovered (maths)' value: first(my_SIR_maths).Rm color: rgb(52,152,219) marker_shape: marker_circle;
Expand Down
Expand Up @@ -2,9 +2,17 @@
* Name: Influence of the integration step
* Author: Tri, Nghi, Benoit
* Description: The aim is to show the influence of the integration method on the result precision.
* Note: an integration step of 0.1 is considered as not accurate enough. It is used here to highlight clearly the impact of the integration method.
* Note: an integration step of 0.1 is considered as not accurate enough. It is used here
* to highlight the impact of the integration method.
*
* About the expected dynamics: Lotka-Volterra model solutions are known to be periodic. With
* a step of 0.1, the numerical solution provided by the Runge-Kutta 4 method for Lotka-Volterra
* model looks periodic (see the phase portrait), while for the Euler the solution is unbounded (which
* is wrong). See as time increases how errors accumulate, leading to negative and unbounded values.
*
* Tags: equation, math
***/

model LVInfluenceoftheIntegrationMethod

global {
Expand All @@ -24,7 +32,7 @@ species LVRK4 {
float beta <- 0.3;
float gamma <- 0.2;
float delta <- 0.85;

equation eqLV {
diff(x, t) = x * (alpha - beta * y);
diff(y, t) = -y * (delta - gamma * x);
Expand All @@ -33,7 +41,6 @@ species LVRK4 {
reflex solving {
solve eqLV method: #rk4 step_size: h;
}

}


Expand All @@ -56,6 +63,8 @@ species LVEuler {
solve eqLV method: #Euler step_size: h;
}



reflex end_simulation when: cycle > 126{
ask world{do pause;}
}
Expand All @@ -65,10 +74,22 @@ species LVEuler {
experiment examples type: gui {
float minimum_cycle_duration <- 0.1#s;
output {
display LV synchronized:false {
chart 'Comparison Euler - RK4 (RK4 is more accurate)' type: xy x_serie:first(LVRK4).t[] background: #white {
data "RK4" value: [first(LVRK4).x,first(LVRK4).y] color: #blue marker: false;
data "Euler" value: [first(LVEuler).x,first(LVEuler).y] color: #red marker: false;
layout #split tabs: false;
display LV_series name: "Time series" synchronized:false toolbar: false {
chart 'Comparison Euler - RK4 (RK4 is more accurate)' type: series
x_serie: first(LVRK4).t[] y_label: "pop" background: rgb(47,47,47) color: #white x_tick_line_visible: false {
data "x (rk4)" value: first(LVRK4).x[] color: rgb(52,152,219) marker: false thickness: 2;
data "y (rk4)" value: first(LVRK4).y[] color: rgb(41,128,185) marker: false thickness: 2;
data "x (Euler)" value: first(LVEuler).x[] color: rgb(243,156,18) marker: false thickness: 2;
data "y (Euler)" value: first(LVEuler).y[] color: rgb(230,126,34) marker: false thickness: 2;
}

}
display LV_phase_portrait name: "Phase portrait" synchronized:false toolbar: false{
chart 'Comparison Euler - RK4 (RK4 is more accurate)' type: xy
background: rgb(47,47,47) color: #white x_label: "x" y_label: "y" x_tick_line_visible: false y_tick_line_visible: false{
data "y(x(t)) rk4" value: rows_list(matrix(first(LVRK4).x[],first(LVRK4).y[])) color: rgb(52,152,219) marker: false thickness: 2;
data "y(x(t)) Euler" value: rows_list(matrix(first(LVEuler).x[],first(LVEuler).y[])) color: rgb(243,156,18) marker: false thickness: 2;
}

}
Expand Down
@@ -1,8 +1,10 @@
/***
* Name: Influence of the integration step
* Author: Tri, Nghi, Benoit
* Description: The aim is to show the influence of the integration step on the result precision.
* Notice that a step of value 1.0 is not realistic, but this value is necessary with the RK4 method to show the influence of the integration step.
* Description: The aim is to show the influence of the integration step on the result precision.
* The solutions of the Lotka-Volterra are periodic. When the integration step is not
* small enough, this periodicity is lost, as illustrated with h=1.
*
* Tags: equation, math
***/

Expand Down Expand Up @@ -36,14 +38,36 @@ species userLV {
}

experiment examples type: gui {
output {
display LV {
chart 'examplesUserLV' type: series background: #lightgray {
data "x" value: first(userLV).x color: #yellow;
data "y" value: first(userLV).y color: #blue;
data "x1" value: last(userLV).x color: #red;
data "y1" value: last(userLV).y color: #green;
float minimum_cycle_duration <- 0.05#s;
output {
layout horizontal([vertical([0::100,1::100])::100,2::100]) tabs: false;
display "h=0.01" toolbar: false{
chart 'Lotka-Voltera dynamics (time series)' type: series
background: rgb(47,47,47) color: #white
y_label: "pop" x_tick_line_visible: false{
data "x (h=0.01)" value: first(userLV).x[] color: rgb(52,152,219) marker: false thickness: 2;
data "y (h=0.01)" value: first(userLV).y[] color: rgb(41,128,185) marker: false thickness: 2;
// data "x (h=1)" value: last(userLV).x color: rgb(243,156,18) marker: false thickness: 2;
// data "y (h=1)" value: last(userLV).y color: rgb(230,126,34) marker: false thickness: 2;
}
}
display "h=1" toolbar: false{
chart 'Lotka-Voltera dynamics (time series)' type: series
background: rgb(47,47,47) color: #white
y_label: "pop" x_tick_line_visible: false{
// data "x (h=0.01)" value: first(userLV).x color: rgb(52,152,219) marker: false thickness: 2;
// data "y (h=0.01)" value: first(userLV).y color: rgb(41,128,185) marker: false thickness: 2;
data "x (h=1)" value: last(userLV).x[] color: rgb(243,156,18) marker: false thickness: 2;
data "y (h=1)" value: last(userLV).y[] color: rgb(230,126,34) marker: false thickness: 2;
}
}
display "Phase Portrait" toolbar: false {
chart 'Lotka-Voltera dynamics (phase portrait)' type: xy
background: rgb(47,47,47) color: #white y_label: "y" x_label: "x"
x_range: {0,8} y_range: {0,5.3}{
data "h=0.01" value: [first(userLV).x,first(userLV).y] color: rgb(52,152,219) marker: false;
data "h=1" value: [last(userLV).x,last(userLV).y] color: rgb(243,156,18) marker: false;
}
}
}
}
Expand Up @@ -8,9 +8,11 @@

model SIRInfluenceofSimulationStep

global {
global {
string step_string;
init {
write name + "" + step;
step_string <- string(step)+"s";
create userSIR with: [h::0.1,N::500,I::1.0];
}

Expand Down Expand Up @@ -43,19 +45,29 @@ species userSIR {


experiment examples type: gui {
float minimum_cycle_duration <- 0.1#s;

init {
action _init_ {
create simulation with: [step::2#s,name::"s2s"] ;
create simulation with: [step::10#s,name::"s10s"] ;
}

output {
display SIR {
chart 'examplesUserSIR' type: series background: #lightgray {
data "S" value: first(userSIR).S color: #green;
data "I" value: first(userSIR).I color: #red;
data "R" value: first(userSIR).R color: #blue;
output {
layout #split tabs: false;
display SIR toolbar: false {
chart 'Time Teries ('+step_string+' per cycle)' type: series
background: rgb(47,47,47) color: #white y_label: "pop" x_tick_line_visible: false{
data "S" value: first(userSIR).S[] color: rgb(46,204,113) marker: false thickness: 2;
data "I" value: first(userSIR).I[] color: rgb(231,76,60) marker: false thickness: 2;
data "R" value: first(userSIR).R[] color: rgb(52,152,219) marker: false thickness: 2;
}
}
}
display "Phase Portrait" toolbar: false {
chart 'Phase Portrait ('+step_string+' per cycle)' type: xy
background: rgb(47,47,47) color: #white y_label: "y" x_label: "x"
x_range: {0,500} y_range: {0,450}{
data "I vs S" value: rows_list(matrix(first(userSIR).S[],first(userSIR).I[])) color: rgb(52,152,219) marker: false;
}
}
}
}

This file was deleted.

0 comments on commit 0a9c772

Please sign in to comment.