MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
seeds.cc
Go to the documentation of this file.
1 
7 #include "globals.hh"
8 #include <stdlib.h>
9 #include <stdio.h>
10 using namespace globals;
13  int &ncell ,\
14  int *center_x ,\
15  int *center_y ,\
16  int *center_z ,\
17  bool report )
18 {
19  // Creates seeds for Voronoi tessellation at centers of cells at cubic or
20  // hexagonal grids. Seed positions are store in `center_x`, `center_y` and
21  // `center_z`. Updates `ncell`.
22  const int GRID_CUBIC=1,GRID_HEXAG_AB=2,GRID_HEXAG_ABC=3;
23  int i,j,k,m;
24  int ttt;
25  if (report) {
26  if (grid == GRID_CUBIC ) {
27  printf("Cubic grid.\n");
28  } else if (grid == GRID_HEXAG_AB ) {
29  printf("Hexagonal grid ABABAB...\n");
30  } else if (grid == GRID_HEXAG_ABC ) {
31  printf("Hexagonal grid ABCABCABC...\n");
32  }
33  printf("Matrix of %d x %d x %d voxels.\n", nx, ny, nz);
34  printf("Spacing of the grid is %d, %d, %d\n", sx, sy, sz);
35  printf("Maximum number of cells, ncell = %d\n", ncell);
36  }
37  if (grid == GRID_CUBIC ) {
38  m = 0;
39  for (i = 0; i < nx; i++)
40  for (j = 0; j < ny; j++)
41  for (k = 0; k < nz; k++)
42  if ((i % sx == 0) && (j % sy == 0) && \
43  (k % sz == 0)) {
44  center_x[m] = i;
45  center_y[m] = j;
46  center_z[m] = k;
47  m++;
48  }
49  } else if (grid == GRID_HEXAG_AB ) {
50  m = 0;
51  for (i = 0; i < nx; i++)
52  for (j = 0; j < ny; j++)
53  for (k = 0; k < nz; k++)
54  if ((i % sx == 0) &&
55  (j % (2*sy) == 0) &&
56  (k % (2*sz) == 0) ) {
57  center_x[m] = i;
58  center_y[m] = j;
59  center_z[m] = k;
60  m++;
61  } else if ((i % sx == (sx/2)) &&
62  (j % (2*sy) == sy ) &&
63  (k % (2*sz) == 0 ) ) {
64  center_x[m] = i;
65  center_y[m] = j;
66  center_z[m] = k;
67  m++;
68  } else if ((i % sx == (sx/2) ) &&
69  (j % (2*sy) == 1 + sy/3) &&
70  (k % (2*sz) == sz ) ) {
71  center_x[m] = i;
72  center_y[m] = j;
73  center_z[m] = k;
74  m++;
75  } else if ((i % sx == 0 ) &&
76  (j % (2*sy) == sy + 1 + sy/3) &&
77  (k % (2*sz) == sz ) ) {
78  center_x[m] = i;
79  center_y[m] = j;
80  center_z[m] = k;
81  m++;
82  }
83  } else if (grid == GRID_HEXAG_ABC ) {
84  m = 0;
85  for (i = 0; i < nx; i++)
86  for (j = 0; j < ny; j++)
87  for (k = 0; k < nz; k++)
88  if ((i % sx == 0) &&
89  (j % (2*sy) == 0) &&
90  (k % (3*sz) == 0) ) {
91  center_x[m] = i;
92  center_y[m] = j;
93  center_z[m] = k;
94  m++;
95  } else if ((i % sx == (sx/2)) &&
96  (j % (2*sy) == sy ) &&
97  (k % (3*sz) == 0 ) ) {
98  center_x[m] = i;
99  center_y[m] = j;
100  center_z[m] = k;
101  m++;
102  } else if ((i % sx == (sx/2) ) &&
103  (j % (2*sy) == 1 + sy/3) &&
104  (k % (3*sz) == sz ) ) {
105  center_x[m] = i;
106  center_y[m] = j;
107  center_z[m] = k;
108  m++;
109  } else if ((i % sx == 0 ) &&
110  (j % (2*sy) == sy + 1 + sy/3) &&
111  (k % (3*sz) == sz ) ) {
112  center_x[m] = i;
113  center_y[m] = j;
114  center_z[m] = k;
115  m++;
116  } else if ((i % sx == 0 ) &&
117  (j % (2*sy) == 1 + (2*sy)/3) &&
118  (k % (3*sz) == (2*sz) ) ) {
119  center_x[m] = i;
120  center_y[m] = j;
121  center_z[m] = k;
122  m++;
123  } else if ((i % sx == (sx/2) ) &&
124  (j % (2*sy) == sy + 1 + (2*sy)/3) &&
125  (k % (3*sz) == (2*sz) ) ) {
126  center_x[m] = i;
127  center_y[m] = j;
128  center_z[m] = k;
129  m++;
130  }
131  }
132  if (report) {
133  printf("Number of initialized centers of cells = %d\n", m);
134  }
135  ncell = m;
136 
137  /*
138  * Random perturbations of the grid.
139  */
140  for (m = 0; m < ncell; m++) {
141 
142  /*
143  * center_x[m]
144  */
145  ttt = rand();
146  if (ttt < RAND_MAX/2) {
147  center_x[m] += (int)(RANDOM *
148  (double)ttt / (double)RAND_MAX *
149  (double)sx);
150  } else {
151  ttt = ttt - RAND_MAX/2;
152  center_x[m] -= (int)(RANDOM *
153  (double)ttt / (double)RAND_MAX *
154  (double)sx);
155  }
156  center_x[m] = CONFINEX( center_x[m] );
157 
158  /*
159  * center_y[m]
160  */
161  ttt = rand();
162  if (ttt < RAND_MAX/2) {
163  center_y[m] += (int)(RANDOM *
164  (double)ttt / (double)RAND_MAX *
165  (double)sy);
166  } else {
167  ttt = ttt - RAND_MAX/2;
168  center_y[m] -= (int)(RANDOM *
169  (double)ttt / (double)RAND_MAX *
170  (double)sy);
171  }
172  center_y[m] = CONFINEY( center_y[m] );
173 
174  /*
175  * center_z[m]
176  */
177  ttt = rand();
178  if (ttt < RAND_MAX/2) {
179  center_z[m] += (int)(RANDOM *
180  (double)ttt / (double)RAND_MAX *
181  (double)sz);
182  } else {
183  ttt = ttt - RAND_MAX/2;
184  center_z[m] -= (int)(RANDOM *
185  (double)ttt / (double)RAND_MAX *
186  (double)sz);
187  }
188  center_z[m] = CONFINEZ( center_z[m] );
189 
190  }
191 }
int grid
Definition: globals.cc:17
int nz
domain size in Z
Definition: globals.cc:21
int sy
size of cells in Y
Definition: globals.cc:23
int sz
size of cells in Z
Definition: globals.cc:24
int sx
size of cells in X
Definition: globals.cc:22
Defines global variables, macros, templates and namespace.
double RANDOM
Definition: globals.cc:15
m
Bubble Growth Application Recipe.
Definition: bubbleGrowth.py:59
int nx
domain size in X
Definition: globals.cc:19
#define CONFINEZ(x)
Periodic boundary conditions in z.
Definition: globals.hh:17
integer ncell
number of cells
Definition: globals.f90:15
#define CONFINEY(x)
Periodic boundary conditions in y.
Definition: globals.hh:15
namespace with global variables
Definition: globals.f90:8
#define CONFINEX(x)
Periodic boundary conditions in x.
Definition: globals.hh:13
void createSeeds(int &ncell, int *center_x, int *center_y, int *center_z, bool report)
Initialization of seeds. Stores positions of seeds.
Definition: seeds.cc:12
int ny
domain size in Y
Definition: globals.cc:20