Benjamin Mewes
unread,Feb 26, 2019, 7:26:46 AM2/26/19Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to gama-p...@googlegroups.com
Dear all,
I do some experiments with the physics engine. If I create all necessary agents at the init, my model works (limited to 1.000 agents). If I add them at runtime, they are created but the physics are not calculated anymore. Any ideas?
Update: I got it working for some cycles, then it crashes with an OutOfIndex error for the world.
Here is the new code:
/**
* Name: geometrie
* Author: Mewes
* */
model geometrie
global {
//Variables
float globalWaterTransport <- 0.3; // mm³
int dimension <- 100;
//Physics engine
physic_world world2;
init {
create ground {
location <- { dimension / 2, dimension / 2, 0 };
collisionBound <- ["shape"::"floor", "x"::dimension / 2, "y"::dimension / 2, "z"::0];
shape <- rectangle({ dimension, dimension });
mass <- 0.0;
}
create Tube number: 1 {
shape <- rectangle({ 100, 25 });
mass <- 0.0;
location <- {50,50,0};
collisionBound <- ["shape"::"floor","x"::100, "y":: 25/2, "z"::10];
}
create WaterAgent number: 10 {
location <- {rnd(dimension),rnd(dimension),50};
collisionBound <- ["shape"::"sphere", "radius"::waterTransportPerAgent];
mass <- waterTransportPerAgent;
color <- #yellow;
}
create physic_world {
world2 <- self;
ask world2 {
agents <- (WaterAgent as list)+(Tube as list)+(ground as list);
}
world2.gravity <- true;
}
}
reflex createWatAgents {
if (cycle > 100){
ask world2 {
create WaterAgent number: 2 {
location <- {rnd(dimension),rnd(dimension),50};
collisionBound <- ["shape"::"sphere", "radius"::waterTransportPerAgent];
mass <- waterTransportPerAgent;
color <- #red;
}
}
ask world2 {
agents <- nil;
agents <- (WaterAgent as list)+(Tube as list)+(ground as list);
}
}
}
reflex getPressureHeight {
ask Environment {do WaterInside;}
}
reflex computeForces {
ask world2 {
do compute_forces step: 1;
}
}
}
species Tube skills: [physics] {
aspect cube {
draw shape depth: 10 color:#blue ;
}
}
species ground skills: [physics] {
aspect default {
draw shape color: rgb(100, 20, 20);
}
}
species WaterAgent skills: [physics] {
float waterTransportPerAgent <- globalWaterTransport;
rgb color;
reflex checkifdead {
if (location.z < -1) {
do die;
}
if (location.x < -1) {
do die;
}
if (location.x > 101) {
do die;
}
}
aspect sphere{
draw sphere(waterTransportPerAgent) color: color ;
}
}
species physic_world parent: physical_world ;
grid Environment height: 100 width: 100 neighbors: 8 {
float pressureHeigth;
int countWaterAgents;
action WaterInside {
countWaterAgents <- 0;
ask WaterAgent inside self {
myself.countWaterAgents <- myself.countWaterAgents + 1;
}
pressureHeigth <-float(countWaterAgents) * globalWaterTransport;
}
}
experiment Init type: gui {
output {
display cells type:opengl draw_env: true {
species ground;
species Tube aspect:cube;
species WaterAgent aspect:sphere;
}
}
}