123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #include "CP_core_IPS.h"
- // Initialize the lattice
- void initialize_IPS(IPSmodel *s)
- {
- int r=5;
- //Start with en empty lattice
- int x,y;
- for (x = 0; x < X_SIZE; x++)
- for (y = 0; y < Y_SIZE; y++)
- {
- s->lattice_configuration[x][y]=0;
- }
- s->occupancy = 0;
- // then add some r-size cluster with particles
- for (x = 128-r; x < 128+r; x++)
- for (y = 128-r; y < 128+r; y++)
- {
- s->lattice_configuration[x][y]= 1;
- s->occupancy ++;
- }
- s->initialized = TRUE;
- s->generation_time = 0;
- }
- // Update function
- void update_IPS(IPSmodel *s)
- {
- int random_neighbor_state, tape_symbol;
- long random_neighboor;
- int sites = 0;
- int random_x_coor, random_y_coor;
- // The Monte Carlo step (MC) is 4x the number of sites in the Lattice
- for (sites; sites < (int)(Y_SIZE*X_SIZE)*4; sites++)
- {
- //pick a random focal site
- random_x_coor = (int) floor(genrand64_real3()*X_SIZE);
- random_y_coor = (int) floor(genrand64_real3()*Y_SIZE);
- switch(s->lattice_configuration[random_x_coor][random_y_coor])
- {
- case 0: // if the site is empty
- // chose a random neighboor from the 4 posible ones
- random_neighboor = 1 + (long) floor(genrand64_real3()*4);
- switch(random_neighboor)
- {
- case 1: // North
- random_neighbor_state = s->lattice_configuration[random_x_coor][(int)(((int)Y_SIZE + random_y_coor-1) % (int)Y_SIZE)];
- break;
- case 2: // West
- random_neighbor_state = s->lattice_configuration[(int)((X_SIZE + random_x_coor-1)%X_SIZE)][random_y_coor];
- break;
- case 3: // South
- random_neighbor_state = s->lattice_configuration[random_x_coor][(int)((Y_SIZE + random_y_coor+1) % Y_SIZE)];
- break;
- case 4: // East
- random_neighbor_state = s->lattice_configuration[(int)((X_SIZE + random_x_coor+1)%X_SIZE)][random_y_coor];
- break;
- }
- // if its random neighbor is occupied: put a copy at the focal site state.
- // Note that when all 4 newighboors are occupied
- // colonization of the focal site happens with probability 1.0.
- if(random_neighbor_state != 0)
- {
- s->lattice_configuration[random_x_coor][random_y_coor] = random_neighbor_state;
- s->occupancy ++;
- }
- break;
- case 1: // if the site is occupied and points North (N)
- // if a particle is present at the focal site,
- //it can die with probability dead_rate* dt
- if (genrand64_real2() < s->dead_rate)
- {
- s->lattice_configuration[random_x_coor][random_y_coor]= 0;
- s->occupancy --;
- }
- break;
- }
- }
- s->generation_time ++;
- }
- void prepare_IPS(IPSmodel *s)
- {
- // we initialize the mt algorithm for random number genration
- unsigned long long seed = (unsigned int)time(NULL);
- init_genrand64(seed);
- //define default parameters of the simulation
- s->dead_rate = (float) MORTALITY;
- s->running = FALSE;
- s->initialized = FALSE; // SET SIMULATION FLAGS
- }
- // Dialog Box
- // For info at a website:
- //lab wiki on the contact process
- void show_about(GtkWidget *widget, gpointer data)
- {
- GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file("kimero_LAB_transparent.tiff", NULL);
- GtkWidget *dialog = gtk_about_dialog_new();
- gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),
- "IPS Process App");
- gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog), "v 1.0, 2024");
- gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog),"Open Source Code");
- gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog),
- "The Contact process, a stochastic process, is a model of spatial competition. Particles die and spread in a 2D lattice");
- gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog),
- "https://github.com/jekeymer/Contact-Process/wiki");
- gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(dialog), pixbuf);
- g_object_unref(pixbuf), pixbuf = NULL;
- gtk_dialog_run(GTK_DIALOG (dialog));
- gtk_widget_destroy(dialog);
- }
|