tmain.c - simple_DEM - a simple 2D Discrete Element Method code for educational purposes
 (HTM) git clone git://src.adamsgaard.dk/simple_DEM
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tmain.c (1726B)
       ---
            1 #include <stdio.h>
            2 #include <math.h>
            3 
            4 /* Structure declarations and function prototypes */
            5 #include "header.h"
            6 
            7 /* Global and constant simulation properties */
            8 #include "global_properties.h"
            9 
           10 
           11 int main(int argc, char* argv[])
           12 {
           13 
           14   printf("\n## simple_DEM ##\n");
           15   printf("Particles: %d\n", np);
           16   printf("maxStep: %d\n", maxStep);
           17 
           18 
           19   double time = 0.0;        /* Time at simulation start */
           20 
           21   /* Allocate memory */
           22   grain g[np];                /* Grain structure */
           23 
           24   /* Compute simulation domain dimensions */
           25   double wleft  = 0.0;                        /* Left wall */
           26   double wright = (npw+1)*2*rmax;         /* Right wall */
           27   double wdown  = 0.0;                        /* Lower wall */
           28   double wup        = (np/npw+1)*2*rmax;        /* Upper wall */
           29 
           30   /* Variables for pressures on walls */
           31   double wp_up, wp_down, wp_left, wp_right;
           32 
           33   /* Initiailze grains inside the simulation domain */
           34   triangular_grid(g);
           35 
           36 
           37   /* Main time loop */
           38   int step;
           39   for (step = 0; step < maxStep; ++step) {
           40 
           41     time += dt;        /* Update current time */
           42 
           43     /* Predict new kinematics */
           44     prediction(g);
           45 
           46     /* Calculate contact forces between grains */
           47     interact_grains(g);
           48 
           49     /* Calculate contact forces between grains and walls */
           50     interact_walls(g, wleft, wright, wup, wdown, &wp_up, &wp_down, &wp_left, &wp_right);
           51 
           52     /* Update acceleration from forces */
           53     update_acc(g);
           54 
           55     /* Correct velocities */
           56     correction(g);
           57 
           58     /* Write output files if the fileInterval is reached */
           59     if (step % fileInterval == 0) {
           60       (void)vtk_export_grains(g, step);
           61       (void)vtk_export_forces(g, step);
           62     }
           63 
           64   } /* End of main time loop */
           65 
           66   /* Free dynamically allocated memory */
           67   /*free(g);*/
           68 
           69   printf("\nSimulation ended without errors.\n");
           70   return 0;        /* Terminate successfully */
           71 }
           72