Timothy  0.9
Tissue Modelling Framework
 All Data Structures Files Functions Variables Typedefs Macros
init.c
Go to the documentation of this file.
1 /* **************************************************************************
2  * This file is part of Timothy
3  *
4  * Copyright (c) 2014/15 Maciej Cytowski
5  * Copyright (c) 2014/15 ICM, University of Warsaw, Poland
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  * *************************************************************************/
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <math.h>
27 
28 #include "global.h"
29 #include "inline.h"
30 
39 {
40  rst = 0;
41  rstReset = 0;
42  nhs = -1;
43  tgs = 0;
44 
45  statOutStep = 1;
46  rstOutStep = 1;
47  vtkOutStep = 1;
48 
49  povout = 0;
50  vtkout = 0;
51  vnfout = 0;
52 
53  csizeInUnits = 10.0; /* eukaryotic cell size is usually between 10-30 micrometers */
54  cellVolume = (4.0 / 3.0) * M_PI * pow(csizeInUnits * 0.0001, 3.0);
55 
56 }
57 
62 {
63  /* under construction */
64  if (strcmp(cOutType, "VTK") && strcmp(cOutType, "POV")
65  && strcmp(cOutType, "NON"))
66  stopRun(116, "COUTTYPE", __FILE__, __LINE__);
67  if (strcmp(fOutType, "VNF") && strcmp(fOutType, "NON"))
68  stopRun(116, "FOUTTYPE", __FILE__, __LINE__);
69 }
70 
74 void simulationInit(int argc, char **argv)
75 {
76  int i;
77  int periods[3];
78  int reorder;
79 
80  /* print basic informations */
82 
83  /* check necessary arguments */
84  //if( (argc<3 || (strcmp(argv[1],"-p"))) || (argc<2 || (strcmp(argv[1],"-h"))) )
85  // stopRun(102,NULL,__FILE__,__LINE__);
86 
87  if (argc < 2)
88  stopRun(102, NULL, __FILE__, __LINE__);
89  else if ((argc < 3 && strcmp(argv[1], "-p") == 0)
90  || (strcmp(argv[1], "-p") && strcmp(argv[1], "-h")))
91  stopRun(102, NULL, __FILE__, __LINE__);
92 
93  initParams();
94 
95  if (strcmp(argv[1], "-h") == 0)
96  printHelp();
97 
98  /* check number of processes */
99  if (!POWER_OF_TWO(MPIsize))
100  stopRun(101, NULL, __FILE__, __LINE__);
101 
102  /* checking system and runtime configuration */
103  checkEndiannes();
106 
107  /* print execution informations */
108  printExecInfo();
109 
110  /* set default values */
111  defaultValues();
112 
113  /* initialize random number generator */
115 
116  /* read parameters file and restart file (if present) */
117  readParams(argc, argv);
118 
119  /* generate random cells if not a restart simulation */
120  if (!rst) {
121  simStart = 0;
122  /* calculating number of cells per process */
123  lnc = nc / MPIsize;
124  if (MPIrank < nc % MPIsize)
125  lnc++;
126  /* allocating tables */
127  cellsAllocate();
128  /* total number of cells - initialization */
129  for (i = 0; i < MPIsize; i++)
130  tlnc[i] = lnc; //ZLE!!!!!
131  /* cell cycle init */
132  cellsCycleInit();
133  /* random cell placement */
134  cellsRandomInit();
135  /* decomposition - initialization */
136  decompositionInit(argc, argv, MPI_COMM_WORLD);
137  }
138 
139  /* maximum distance cell can travel in 1 sec */
140  maxSpeedInUnits = (maxSpeed * csize) / (24.0 * 60.0 * 60.0);
141  /* at least one global fields iteration per step */
143  /* global fields iterations per step */
144  gfIterPerStep = (int) (secondsPerStep / gfDt);
145 
146  /* density critical levels (very important parameters) */
147  if (sdim == 3) {
148  densityCriticalLevel1 = 6 * h3 * sph_kernel(1.5 * csize); //1.8 //1.4 //1.75
149  densityCriticalLevel2 = 6 * h3 * sph_kernel(1.1 * csize); //1.1 //1.4
150  }
151  if (sdim == 2) {
152  densityCriticalLevel1 = 4 * h2 * sph_kernel(1.4 * csize); //1.4 //1.75
153  densityCriticalLevel2 = 4 * h2 * sph_kernel(1.15 * csize); //1.1 //1.4
154  }
155 
156  /* checking the consistency */
157  checkParameters();
158 
159  if (!strcmp(cOutType, "POV"))
160  povout = 1;
161  if (!strcmp(cOutType, "VTK"))
162  vtkout = 1;
163  if (!strcmp(fOutType, "VNF"))
164  vnfout = 1;
165 
166  /* organizing processes in a Cartesian grid for global fields computations */
167  MPI_Dims_create(MPIsize, sdim, MPIdim);
168  periods[0] = 0;
169  periods[1] = 0;
170  periods[2] = 0;
171  reorder = 0;
172  MPI_Cart_create(MPI_COMM_WORLD, sdim, MPIdim, periods, reorder,
173  &MPI_CART_COMM);
174  MPIcoords = (int **) malloc(MPIsize * sizeof(int *));
175  for (i = 0; i < MPIsize; i++) {
176  MPIcoords[i] = (int *) malloc(3 * sizeof(int));
177  MPI_Cart_coords(MPI_CART_COMM, i, sdim, MPIcoords[i]);
178  }
179  /* compute grid size */
180  computeGridSize();
181 
182  /* allocate grid data */
183  allocateGrid();
184  /* initialize global fields (might take some time) */
185  fieldsInit();
186 
187  /* define colormaps for PovRay outputs */
188  defineColormaps();
189 
190  /* define vessels - TBD */
191  //initVessel();
192 }
void defaultValues()
Definition: init.c:38
int statOutStep
Definition: global.h:214
int MPINodeRank
Definition: global.h:139
float secondsPerStep
Definition: global.h:247
int64_t * tlnc
Definition: global.h:111
void getLocalRankAndSize(int rank, int size, int32_t *lrank, int32_t *lsize)
Definition: utils.c:193
int MPIdim[3]
Definition: global.h:136
double csizeInUnits
Definition: global.h:198
int MPIrank
Definition: global.h:134
#define lnc
Definition: global.h:102
void printExecInfo()
Definition: io.c:62
int povout
Definition: global.h:181
int memPerProc
Definition: global.h:141
char fOutType[3]
Definition: global.h:179
int simStart
Definition: global.h:172
int tgs
Definition: global.h:220
int64_t nhs
Definition: global.h:218
int vtkOutStep
Definition: global.h:216
int MPIsize
Definition: global.h:135
contains various Timothy inline functions
int rst
Definition: global.h:211
char cOutType[3]
Definition: global.h:178
size_t getMemoryPerProcess(int32_t lsize)
Definition: utils.c:167
void defineColormaps()
Definition: io.c:1813
float maxSpeed
Definition: global.h:176
double h3
Definition: global.h:202
contains the most important global variables, arrays and defines
void allocateGrid()
Definition: grid.c:81
void decompositionInit(int argc, char **argv, MPI_Comm Comm)
Definition: domdec.c:191
#define POWER_OF_TWO(x)
Definition: global.h:31
int sdim
Definition: global.h:160
int cellsRandomInit()
Definition: cells.c:132
int rstOutStep
Definition: global.h:215
int vtkout
Definition: global.h:180
void computeGridSize()
Definition: grid.c:38
int rstReset
Definition: global.h:212
void randomStreamInit()
Definition: random.c:35
double csize
Definition: global.h:197
int MPINodeSize
Definition: global.h:140
int checkEndiannes()
Definition: utils.c:45
void cellsCycleInit()
Definition: cells.c:107
void checkParameters()
Definition: init.c:61
double densityCriticalLevel1
Definition: global.h:208
int gfIterPerStep
Definition: global.h:253
float gfDt
Definition: global.h:249
void readParams(int argc, char **argv)
Definition: io.c:600
void fieldsInit()
Definition: fields.c:45
double h2
Definition: global.h:201
int vnfout
Definition: global.h:182
double densityCriticalLevel2
Definition: global.h:209
#define nc
Definition: global.h:93
void cellsAllocate()
Definition: cells.c:66
int ** MPIcoords
Definition: global.h:144
void printHelp()
Definition: io.c:87
void simulationInit(int argc, char **argv)
Definition: init.c:74
double cellVolume
Definition: global.h:199
void printBasicInfo()
Definition: io.c:48
void stopRun(int ierr, char *name, char *file, int line)
Definition: utils.c:72
void initParams(int argc, char **argv)
Definition: io.c:102
float maxSpeedInUnits
Definition: global.h:177
MPI_Comm MPI_CART_COMM
Definition: global.h:143