Timothy  0.9
Tissue Modelling Framework
 All Data Structures Files Functions Variables Typedefs Macros
io.c File Reference

contains I/O functions More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
#include <inttypes.h>
#include <float.h>
#include <math.h>
#include <fcntl.h>
#include "global.h"
#include "io.h"
#include "fields.h"
Include dependency graph for io.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

void readRstFile (int argc, char **argv)
 
void printBasicInfo ()
 
void printExecInfo ()
 
void printHelp ()
 
void initParams (int argc, char **argv)
 
void readParams (int argc, char **argv)
 
void ioDefineOutputFields ()
 
void ioWriteStepVTK (int step)
 
void printStepNum ()
 
void ioDefineRstGlobalParams ()
 
void saveRstFile ()
 
void ioDefineOutputGlobalFields ()
 
void ioWriteFields (int step)
 
void switchStdOut (const char *newStream)
 
void revertStdOut ()
 
void defineColormaps ()
 
void ioWriteStepPovRay (int step, int type)
 

Detailed Description

contains I/O functions

Definition in file io.c.

Macro Definition Documentation

#define _GNU_SOURCE

Definition at line 31 of file io.c.

Function Documentation

void defineColormaps ( )

This function defines colormaps for PovRay output.

Definition at line 1813 of file io.c.

References colormapPoint_t::b, beta, cmaps, colormap_t::cp, colormapPoint_t::g, colormap_t::ncp, colormapPoint_t::position, and colormapPoint_t::r.

1814 {
1815  int i, j;
1816  int numberOfColormaps;
1817 
1818  /* on the ocassion - initialize the rotation angle */
1819  beta = 0.0;
1820 
1821  numberOfColormaps = 6;
1822  cmaps = (colormap *) malloc(numberOfColormaps * sizeof(colormap));
1823 
1824  /* medical colormap i=0 */
1825  strcpy(cmaps[0].name, "medical");
1826  cmaps[0].ncp = 4;
1827  cmaps[0].cp =
1828  (colormapPoint *) malloc(cmaps[0].ncp * sizeof(colormapPoint));
1829  cmaps[0].cp[0].position = 0.0;
1830  cmaps[0].cp[0].r = 0.0;
1831  cmaps[0].cp[0].g = 0.0;
1832  cmaps[0].cp[0].b = 0.0;
1833  cmaps[0].cp[1].position = 0.33;
1834  cmaps[0].cp[1].r = 122.0;
1835  cmaps[0].cp[1].g = 32.0;
1836  cmaps[0].cp[1].b = 32.0;
1837  cmaps[0].cp[2].position = 0.66;
1838  cmaps[0].cp[2].r = 255.0;
1839  cmaps[0].cp[2].g = 179.0;
1840  cmaps[0].cp[2].b = 77.0;
1841  cmaps[0].cp[3].position = 1.0;
1842  cmaps[0].cp[3].r = 255.0;
1843  cmaps[0].cp[3].g = 255.0;
1844  cmaps[0].cp[3].b = 255.0;
1845 
1846  /* rainbow colormap i=1 */
1847  strcpy(cmaps[1].name, "rainbow");
1848  cmaps[1].ncp = 5;
1849  cmaps[1].cp =
1850  (colormapPoint *) malloc(cmaps[1].ncp * sizeof(colormapPoint));
1851  cmaps[1].cp[0].position = 0.0;
1852  cmaps[1].cp[0].r = 0.0;
1853  cmaps[1].cp[0].g = 0.0;
1854  cmaps[1].cp[0].b = 255.0;
1855  cmaps[1].cp[1].position = 0.25;
1856  cmaps[1].cp[1].r = 0.0;
1857  cmaps[1].cp[1].g = 255.0;
1858  cmaps[1].cp[1].b = 255.0;
1859  cmaps[1].cp[2].position = 0.5;
1860  cmaps[1].cp[2].r = 0.0;
1861  cmaps[1].cp[2].g = 255.0;
1862  cmaps[1].cp[2].b = 0.0;
1863  cmaps[1].cp[3].position = 0.75;
1864  cmaps[1].cp[3].r = 255.0;
1865  cmaps[1].cp[3].g = 255.0;
1866  cmaps[1].cp[3].b = 0.0;
1867  cmaps[1].cp[4].position = 1.0;
1868  cmaps[1].cp[4].r = 255.0;
1869  cmaps[1].cp[4].g = 0.0;
1870  cmaps[1].cp[4].b = 0.0;
1871 
1872  /* blue red yellow */
1873  strcpy(cmaps[2].name, "bry");
1874  cmaps[2].ncp = 4;
1875  cmaps[2].cp =
1876  (colormapPoint *) malloc(cmaps[2].ncp * sizeof(colormapPoint));
1877  cmaps[2].cp[0].position = 0.0;
1878  cmaps[2].cp[0].r = 0.0;
1879  cmaps[2].cp[0].g = 0.0;
1880  cmaps[2].cp[0].b = 255.0;
1881  cmaps[2].cp[1].position = 0.33;
1882  cmaps[2].cp[1].r = 255.0;
1883  cmaps[2].cp[1].g = 0.0;
1884  cmaps[2].cp[1].b = 255.0;
1885  cmaps[2].cp[2].position = 0.67;
1886  cmaps[2].cp[2].r = 255.0;
1887  cmaps[2].cp[2].g = 0.0;
1888  cmaps[2].cp[2].b = 0.0;
1889  cmaps[2].cp[3].position = 1.0;
1890  cmaps[2].cp[3].r = 255.0;
1891  cmaps[2].cp[3].g = 255.0;
1892  cmaps[2].cp[3].b = 0.0;
1893 
1894  /* hot */
1895  strcpy(cmaps[3].name, "hot");
1896  cmaps[3].ncp = 5;
1897  cmaps[3].cp =
1898  (colormapPoint *) malloc(cmaps[3].ncp * sizeof(colormapPoint));
1899  cmaps[3].cp[0].position = 0.0;
1900  cmaps[3].cp[0].r = 107.0;
1901  cmaps[3].cp[0].g = 0.0;
1902  cmaps[3].cp[0].b = 0.0;
1903  cmaps[3].cp[1].position = 0.35;
1904  cmaps[3].cp[1].r = 255.0;
1905  cmaps[3].cp[1].g = 102.0;
1906  cmaps[3].cp[1].b = 28.0;
1907  cmaps[3].cp[2].position = 0.57;
1908  cmaps[3].cp[2].r = 250.0;
1909  cmaps[3].cp[2].g = 235.0;
1910  cmaps[3].cp[2].b = 128.0;
1911  cmaps[3].cp[3].position = 0.76;
1912  cmaps[3].cp[3].r = 232.0;
1913  cmaps[3].cp[3].g = 230.0;
1914  cmaps[3].cp[3].b = 230.0;
1915  cmaps[3].cp[4].position = 1.0;
1916  cmaps[3].cp[4].r = 156.0;
1917  cmaps[3].cp[4].g = 161.0;
1918  cmaps[3].cp[4].b = 255.0;
1919 
1920  /* hot1 */
1921  strcpy(cmaps[4].name, "hot1");
1922  cmaps[4].ncp = 5;
1923  cmaps[4].cp =
1924  (colormapPoint *) malloc(cmaps[4].ncp * sizeof(colormapPoint));
1925  cmaps[4].cp[0].position = 0.0;
1926  cmaps[4].cp[0].r = 128.0;
1927  cmaps[4].cp[0].g = 0.0;
1928  cmaps[4].cp[0].b = 0.0;
1929  cmaps[4].cp[1].position = 0.2;
1930  cmaps[4].cp[1].r = 255.0;
1931  cmaps[4].cp[1].g = 0.0;
1932  cmaps[4].cp[1].b = 0.0;
1933  cmaps[4].cp[2].position = 0.4;
1934  cmaps[4].cp[2].r = 255.0;
1935  cmaps[4].cp[2].g = 255.0;
1936  cmaps[4].cp[2].b = 0.0;
1937  cmaps[4].cp[3].position = 0.7;
1938  cmaps[4].cp[3].r = 255.0;
1939  cmaps[4].cp[3].g = 255.0;
1940  cmaps[4].cp[3].b = 255.0;
1941  cmaps[4].cp[4].position = 1.0;
1942  cmaps[4].cp[4].r = 128.0;
1943  cmaps[4].cp[4].g = 128.0;
1944  cmaps[4].cp[4].b = 255.0;
1945 
1946  /* my */
1947  strcpy(cmaps[5].name, "my");
1948  cmaps[5].ncp = 5;
1949  cmaps[5].cp =
1950  (colormapPoint *) malloc(cmaps[5].ncp * sizeof(colormapPoint));
1951  cmaps[5].cp[0].position = 0.0;
1952  cmaps[5].cp[0].r = 107.0;
1953  cmaps[5].cp[0].g = 0.0;
1954  cmaps[5].cp[0].b = 0.0;
1955  cmaps[5].cp[1].position = 0.35;
1956  cmaps[5].cp[1].r = 0.0;
1957  cmaps[5].cp[1].g = 100.0;
1958  cmaps[5].cp[1].b = 255.0;
1959  cmaps[5].cp[2].position = 0.57;
1960  cmaps[5].cp[2].r = 250.0;
1961  cmaps[5].cp[2].g = 235.0;
1962  cmaps[5].cp[2].b = 128.0;
1963  cmaps[5].cp[3].position = 0.76;
1964  cmaps[5].cp[3].r = 232.0;
1965  cmaps[5].cp[3].g = 230.0;
1966  cmaps[5].cp[3].b = 230.0;
1967  cmaps[5].cp[4].position = 1.0;
1968  cmaps[5].cp[4].r = 156.0;
1969  cmaps[5].cp[4].g = 161.0;
1970  cmaps[5].cp[4].b = 255.0;
1971 
1972 }
float g
Definition: io.h:92
float beta
Definition: io.h:103
float b
Definition: io.h:93
colormap * cmaps
Definition: io.h:102
colormapPoint * cp
Definition: io.h:99
float r
Definition: io.h:91
float position
Definition: io.h:90
int ncp
Definition: io.h:98
Definition: io.h:96

Here is the caller graph for this function:

void initParams ( int  argc,
char **  argv 
)

This function initializes all parameters.

Definition at line 102 of file io.c.

References addr, cg1, cg2, cm, cOutType, cs, desc, DOUBLE, fieldBC, fieldConsumption, fieldCriticalLevel1, fieldCriticalLevel2, fieldDiffCoef, fieldICMean, fieldICVar, fieldLambda, fieldProduction, fOutType, g1, g2, gfDt, gfH, gfields, GLUC, glucose, h, HYDR, hydrogenIon, INT, logdir, LONG, m, maxCells, maxSpeed, mitrand, nc, nhs, nsteps, nx, ny, nz, outdir, OXYG, oxygen, params, rd, REAL, req, rng, rstFileName, rstOutStep, rstReset, s, sdim, secondsPerStep, statOutStep, STRING, temperature, tgs, type, v, and vtkOutStep.

103 {
104 
105  int nr;
106  /* initialize all parameters */
107 
108  nr = 0;
109 
110  strcpy(params[nr], "SIZEX");
111  strcpy(desc[nr], "box size (X coordinate)");
112  req[nr] = 1;
113  addr[nr] = &nx;
114  type[nr] = INT;
115  nr++;
116 
117  strcpy(params[nr], "SIZEY");
118  strcpy(desc[nr], "box size (Y coordinate)");
119  req[nr] = 1;
120  addr[nr] = &ny;
121  type[nr] = INT;
122  nr++;
123 
124  strcpy(params[nr], "SIZEZ");
125  strcpy(desc[nr], "box size (Z coordinate)");
126  req[nr] = 1;
127  addr[nr] = &nz;
128  type[nr] = INT;
129  nr++;
130 
131  strcpy(params[nr], "RSTFILE");
132  strcpy(desc[nr], "restart file name");
133  req[nr] = 0;
134  addr[nr] = rstFileName;
135  type[nr] = STRING;
136  nr++;
137 
138  strcpy(params[nr], "NC");
139  strcpy(desc[nr], "number of cells");
140  req[nr] = 1;
141  addr[nr] = &nc;
142  type[nr] = LONG;
143  nr++;
144 
145  strcpy(params[nr], "RNG");
146  strcpy(desc[nr], "random number generator type");
147  req[nr] = 1;
148  addr[nr] = rng;
149  type[nr] = STRING;
150  nr++;
151 
152  strcpy(params[nr], "H");
153  strcpy(desc[nr], "SPH kernel function diameter");
154  req[nr] = 0;
155  addr[nr] = &h;
156  type[nr] = REAL;
157  nr++;
158 
159  strcpy(params[nr], "NSTEPS");
160  strcpy(desc[nr], "number of simulation steps");
161  req[nr] = 1;
162  addr[nr] = &nsteps;
163  type[nr] = INT;
164  nr++;
165 
166  strcpy(params[nr], "OUTDIR");
167  strcpy(desc[nr], "output directory");
168  req[nr] = 0;
169  addr[nr] = &outdir;
170  type[nr] = STRING;
171  nr++;
172 
173  strcpy(params[nr], "G1");
174  strcpy(desc[nr],
175  "mean duration of G1 phase (in hours) - healthy tissue");
176  req[nr] = 1;
177  addr[nr] = &g1;
178  type[nr] = REAL;
179  nr++;
180 
181  strcpy(params[nr], "S");
182  strcpy(desc[nr], "mean duration of S phase (in hours) - healthy tissue");
183  req[nr] = 1;
184  addr[nr] = &s;
185  type[nr] = REAL;
186  nr++;
187 
188  strcpy(params[nr], "G2");
189  strcpy(desc[nr],
190  "mean duration of G2 phase (in hours) - healthy tissue");
191  req[nr] = 1;
192  addr[nr] = &g2;
193  type[nr] = REAL;
194  nr++;
195 
196  strcpy(params[nr], "M");
197  strcpy(desc[nr], "mean duration of M phase (in hours) - healthy tissue");
198  req[nr] = 1;
199  addr[nr] = &m;
200  type[nr] = REAL;
201  nr++;
202 
203  strcpy(params[nr], "SECPERSTEP");
204  strcpy(desc[nr], "time step");
205  req[nr] = 1;
206  addr[nr] = &secondsPerStep;
207  type[nr] = REAL;
208  nr++;
209 
210  strcpy(params[nr], "DIM");
211  strcpy(desc[nr], "dimensionality of the system (2D/3D)");
212  req[nr] = 1;
213  addr[nr] = &sdim;
214  type[nr] = INT;
215  nr++;
216 
217  strcpy(params[nr], "MITRAND");
218  strcpy(desc[nr], "mitosis random direction (1/0)");
219  req[nr] = 1;
220  addr[nr] = &mitrand;
221  type[nr] = INT;
222  nr++;
223 
224  strcpy(params[nr], "V");
225  strcpy(desc[nr], "variability of duration of cell cycles, 0<V<1");
226  req[nr] = 1;
227  addr[nr] = &v;
228  type[nr] = REAL;
229  nr++;
230 
231  strcpy(params[nr], "RD");
232  strcpy(desc[nr],
233  "radnom death - probability (for each cell) of being marked for dying. 0.0<=RD<1.0");
234  req[nr] = 1;
235  addr[nr] = &rd;
236  type[nr] = REAL;
237  nr++;
238 
239  strcpy(params[nr], "RSTRESET");
240  strcpy(desc[nr], "reset simulation parameters of restart file");
241  req[nr] = 1;
242  addr[nr] = &rstReset;
243  type[nr] = INT;
244  nr++;
245 
246  strcpy(params[nr], "NHS");
247  strcpy(desc[nr],
248  "number of cells needed to activate random dying (for homeostasis)");
249  req[nr] = 0;
250  addr[nr] = &nhs;
251  type[nr] = LONG;
252  nr++;
253 
254  strcpy(params[nr], "TGS");
255  strcpy(desc[nr], "switches on tumor growth simulation");
256  req[nr] = 1;
257  addr[nr] = &tgs;
258  type[nr] = INT;
259  nr++;
260 
261  strcpy(params[nr], "STATOUTSTEP");
262  strcpy(desc[nr], "every how many steps statistics are printed");
263  req[nr] = 1;
264  addr[nr] = &statOutStep;
265  type[nr] = INT;
266  nr++;
267 
268  strcpy(params[nr], "RSTOUTSTEP");
269  strcpy(desc[nr], "every how many steps restart file is printed");
270  req[nr] = 1;
271  addr[nr] = &rstOutStep;
272  type[nr] = INT;
273  nr++;
274 
275  strcpy(params[nr], "VISOUTSTEP");
276  strcpy(desc[nr], "every how many steps VTK file is printed");
277  req[nr] = 1;
278  addr[nr] = &vtkOutStep;
279  type[nr] = INT;
280  nr++;
281 
282  strcpy(params[nr], "CG1");
283  strcpy(desc[nr], "mean duration of G1 phase (in hours) - cancer cells");
284  req[nr] = 1;
285  addr[nr] = &cg1;
286  type[nr] = REAL;
287  nr++;
288 
289  strcpy(params[nr], "CS");
290  strcpy(desc[nr], "mean duration of S phase (in hours) - cancer cells");
291  req[nr] = 1;
292  addr[nr] = &cs;
293  type[nr] = REAL;
294  nr++;
295 
296  strcpy(params[nr], "CG2");
297  strcpy(desc[nr], "mean duration of G2 phase (in hours) - cancer cells");
298  req[nr] = 1;
299  addr[nr] = &cg2;
300  type[nr] = REAL;
301  nr++;
302 
303  strcpy(params[nr], "CM");
304  strcpy(desc[nr], "mean duration of M phase (in hours) - cancer cells");
305  req[nr] = 1;
306  addr[nr] = &cm;
307  type[nr] = REAL;
308  nr++;
309 
310  strcpy(params[nr], "MAXSPEED");
311  strcpy(desc[nr],
312  "maximal displacement of cells in one time step (0.0<MAXMOVE<1.0)");
313  req[nr] = 1;
314  addr[nr] = &maxSpeed;
315  type[nr] = REAL;
316  nr++;
317 
318  strcpy(params[nr], "GFLOGDIR");
319  strcpy(desc[nr], "log directory");
320  req[nr] = 0;
321  addr[nr] = &logdir;
322  type[nr] = STRING;
323  nr++;
324 
325  strcpy(params[nr], "GFDT");
326  strcpy(desc[nr],
327  "the length of time step for solving global fields (unit: seconds)");
328  req[nr] = 1;
329  addr[nr] = &gfDt;
330  type[nr] = REAL;
331  nr++;
332 
333  strcpy(params[nr], "GFH");
334  strcpy(desc[nr],
335  "grid resolution for solving global fields (unit: cell size)");
336  req[nr] = 1;
337  addr[nr] = &gfH;
338  type[nr] = REAL;
339  nr++;
340 
341  strcpy(params[nr], "GFIELDS");
342  strcpy(desc[nr],
343  "do we use global fields in the simulation? (0 - no, 1 - yes)");
344  req[nr] = 1;
345  addr[nr] = &gfields;
346  type[nr] = INT;
347  nr++;
348 
349  strcpy(params[nr], "OXYGEN");
350  strcpy(desc[nr],
351  "do we use oxygen field in the simulation? (0 - no, 1 - yes)");
352  req[nr] = 0;
353  addr[nr] = &oxygen;
354  type[nr] = INT;
355  nr++;
356 
357  strcpy(params[nr], "OXYGENDC");
358  strcpy(desc[nr], "oxygen field diffusion coefficient");
359  req[nr] = 0;
360  addr[nr] = &fieldDiffCoef[OXYG];
361  type[nr] = DOUBLE;
362  nr++;
363 
364  strcpy(params[nr], "OXYGENBC");
365  strcpy(desc[nr],
366  "oxygen field boundary condition (Dirichlet), mol/cm^3");
367  req[nr] = 0;
368  addr[nr] = &fieldBC[OXYG];
369  type[nr] = DOUBLE;
370  nr++;
371 
372  strcpy(params[nr], "OXYGENICMEAN");
373  strcpy(desc[nr], "oxygen field initial condition mean, mol/cm^3");
374  req[nr] = 0;
375  addr[nr] = &fieldICMean[OXYG];
376  type[nr] = DOUBLE;
377  nr++;
378 
379  strcpy(params[nr], "OXYGENICVAR");
380  strcpy(desc[nr], "oxygen field initial condition variance, mol/cm^3");
381  req[nr] = 0;
382  addr[nr] = &fieldICVar[OXYG];
383  type[nr] = DOUBLE;
384  nr++;
385 
386  strcpy(params[nr], "OXYGENCONS");
387  strcpy(desc[nr], "oxygen field consumption, mol/(cell s)");
388  req[nr] = 0;
389  addr[nr] = &fieldConsumption[OXYG];
390  type[nr] = DOUBLE;
391  nr++;
392 
393  strcpy(params[nr], "OXYGENPROD");
394  strcpy(desc[nr], "oxygen field production, mol/(cell s)");
395  req[nr] = 0;
396  addr[nr] = &fieldProduction[OXYG];
397  type[nr] = DOUBLE;
398  nr++;
399 
400  strcpy(params[nr], "OXYGENLAMBDA");
401  strcpy(desc[nr], "oxygen field lambda");
402  req[nr] = 0;
403  addr[nr] = &fieldLambda[OXYG];
404  type[nr] = DOUBLE;
405  nr++;
406 
407  strcpy(params[nr], "OXYGENCL1");
408  strcpy(desc[nr], "oxygen field critical level 1, mol/cm^3");
409  req[nr] = 0;
410  addr[nr] = &fieldCriticalLevel1[OXYG];
411  type[nr] = DOUBLE;
412  nr++;
413 
414  strcpy(params[nr], "OXYGENCL2");
415  strcpy(desc[nr], "oxygen field critical level 2, mol/cm^3");
416  req[nr] = 0;
417  addr[nr] = &fieldCriticalLevel2[OXYG];
418  type[nr] = DOUBLE;
419  nr++;
420 
421  strcpy(params[nr], "GLUCOSE");
422  strcpy(desc[nr],
423  "do we use glucose field in the simulation? (0 - no, 1 - yes)");
424  req[nr] = 0;
425  addr[nr] = &glucose;
426  type[nr] = INT;
427  nr++;
428 
429  strcpy(params[nr], "GLUCOSEDC");
430  strcpy(desc[nr], "glucose field diffusion coefficient");
431  req[nr] = 0;
432  addr[nr] = &fieldDiffCoef[GLUC];
433  type[nr] = DOUBLE;
434  nr++;
435 
436  strcpy(params[nr], "GLUCOSEBC");
437  strcpy(desc[nr],
438  "glucose field boundary condition (Dirichlet), mol/cm^3");
439  req[nr] = 0;
440  addr[nr] = &fieldBC[GLUC];
441  type[nr] = DOUBLE;
442  nr++;
443 
444  strcpy(params[nr], "GLUCOSEICMEAN");
445  strcpy(desc[nr], "glucose field initial condition mean, mol/cm^3");
446  req[nr] = 0;
447  addr[nr] = &fieldICMean[GLUC];
448  type[nr] = DOUBLE;
449  nr++;
450 
451  strcpy(params[nr], "GLUCOSEICVAR");
452  strcpy(desc[nr], "glucose field initial condition variance, mol/cm^3");
453  req[nr] = 0;
454  addr[nr] = &fieldICVar[GLUC];
455  type[nr] = DOUBLE;
456  nr++;
457 
458  strcpy(params[nr], "GLUCOSECONS");
459  strcpy(desc[nr], "glucose field consumption, mol/(cell s)");
460  req[nr] = 0;
461  addr[nr] = &fieldConsumption[GLUC];
462  type[nr] = DOUBLE;
463  nr++;
464 
465  strcpy(params[nr], "GLUCOSEPROD");
466  strcpy(desc[nr], "glucose field production, mol/(cell s)");
467  req[nr] = 0;
468  addr[nr] = &fieldProduction[GLUC];
469  type[nr] = DOUBLE;
470  nr++;
471 
472  strcpy(params[nr], "GLUCOSELAMBDA");
473  strcpy(desc[nr], "glucose field lambda");
474  req[nr] = 0;
475  addr[nr] = &fieldLambda[GLUC];
476  type[nr] = DOUBLE;
477  nr++;
478 
479  strcpy(params[nr], "GLUCOSECL1");
480  strcpy(desc[nr], "glucose field critical level 1, mol/cm^3");
481  req[nr] = 0;
482  addr[nr] = &fieldCriticalLevel1[GLUC];
483  type[nr] = DOUBLE;
484  nr++;
485 
486  strcpy(params[nr], "GLUCOSECL2");
487  strcpy(desc[nr], "glucose field critical level 2, mol/cm^3");
488  req[nr] = 0;
489  addr[nr] = &fieldCriticalLevel2[GLUC];
490  type[nr] = DOUBLE;
491  nr++;
492 
493  strcpy(params[nr], "HYDROGENION");
494  strcpy(desc[nr],
495  "do we use hydrogen ion field in the simulation? (0 - no, 1 - yes)");
496  req[nr] = 0;
497  addr[nr] = &hydrogenIon;
498  type[nr] = INT;
499  nr++;
500 
501  strcpy(params[nr], "HYDROGENIONDC");
502  strcpy(desc[nr], "hydrogen ion field diffusion coefficient");
503  req[nr] = 0;
504  addr[nr] = &fieldDiffCoef[HYDR];
505  type[nr] = DOUBLE;
506  nr++;
507 
508  strcpy(params[nr], "HYDROGENIONBC");
509  strcpy(desc[nr],
510  "hydrogen ion field boundary condition (Dirichlet), mol/cm^3");
511  req[nr] = 0;
512  addr[nr] = &fieldBC[HYDR];
513  type[nr] = DOUBLE;
514  nr++;
515 
516  strcpy(params[nr], "HYDROGENIONICMEAN");
517  strcpy(desc[nr], "hydrogen ion field initial condition mean, mol/cm^3");
518  req[nr] = 0;
519  addr[nr] = &fieldICMean[HYDR];
520  type[nr] = DOUBLE;
521  nr++;
522 
523  strcpy(params[nr], "HYDROGENIONICVAR");
524  strcpy(desc[nr],
525  "hydrogen ion field initial condition variance, mol/cm^3");
526  req[nr] = 0;
527  addr[nr] = &fieldICVar[HYDR];
528  type[nr] = DOUBLE;
529  nr++;
530 
531  strcpy(params[nr], "HYDROGENIONCONS");
532  strcpy(desc[nr], "hydrogen ion field consumption, mol/(cell s)");
533  req[nr] = 0;
534  addr[nr] = &fieldConsumption[HYDR];
535  type[nr] = DOUBLE;
536  nr++;
537 
538  strcpy(params[nr], "HYDROGENIONPROD");
539  strcpy(desc[nr], "hydrogen ion field production, mol/(cell s)");
540  req[nr] = 0;
541  addr[nr] = &fieldProduction[HYDR];
542  type[nr] = DOUBLE;
543  nr++;
544 
545  strcpy(params[nr], "HYDROGENIONLAMBDA");
546  strcpy(desc[nr], "hydrogen ion field lambda");
547  req[nr] = 0;
548  addr[nr] = &fieldLambda[HYDR];
549  type[nr] = DOUBLE;
550  nr++;
551 
552  strcpy(params[nr], "HYDROGENIONCL1");
553  strcpy(desc[nr], "hydrogen ion field critical level 1, mol/cm^3");
554  req[nr] = 0;
555  addr[nr] = &fieldCriticalLevel1[HYDR];
556  type[nr] = DOUBLE;
557  nr++;
558 
559  strcpy(params[nr], "HYDROGENIONCL2");
560  strcpy(desc[nr], "hydrogen ion field critical level 2, mol/cm^3");
561  req[nr] = 0;
562  addr[nr] = &fieldCriticalLevel2[HYDR];
563  type[nr] = DOUBLE;
564  nr++;
565 
566  strcpy(params[nr], "TEMPERATURE");
567  strcpy(desc[nr],
568  "do we use temperature field in the simulation? (0 - no, 1 - yes)");
569  req[nr] = 0;
570  addr[nr] = &temperature;
571  type[nr] = INT;
572  nr++;
573 
574  strcpy(params[nr], "MAXCELLS");
575  strcpy(desc[nr], "maximum number of cells in the simulation");
576  req[nr] = 1;
577  addr[nr] = &maxCells;
578  type[nr] = LONG;
579  nr++;
580 
581  strcpy(params[nr], "COUTTYPE");
582  strcpy(desc[nr], "type of cellular data output (VTK or POV)");
583  req[nr] = 1;
584  addr[nr] = cOutType;
585  type[nr] = STRING;
586  nr++;
587 
588  strcpy(params[nr], "FOUTTYPE");
589  strcpy(desc[nr], "type of fields data output (VNF)");
590  req[nr] = 1;
591  addr[nr] = fOutType;
592  type[nr] = STRING;
593  nr++;
594 
595 }
int statOutStep
Definition: global.h:214
#define GLUC
Definition: fields.h:84
float secondsPerStep
Definition: global.h:247
float s
Definition: global.h:186
float g1
Definition: global.h:185
char params[NPAR][64]
Definition: io.h:79
char fOutType[3]
Definition: global.h:179
int tgs
Definition: global.h:220
int mitrand
Definition: global.h:161
int64_t nhs
Definition: global.h:218
int vtkOutStep
Definition: global.h:216
double fieldDiffCoef[NFIELDS]
Definition: fields.h:55
char cOutType[3]
Definition: global.h:178
int nsteps
Definition: global.h:169
float cm
Definition: global.h:195
float maxSpeed
Definition: global.h:176
float gfH
Definition: global.h:250
double fieldICVar[NFIELDS]
Definition: fields.h:59
float m
Definition: global.h:188
int sdim
Definition: global.h:160
int rstOutStep
Definition: global.h:215
int hydrogenIon
Definition: fields.h:36
char rstFileName[128]
Definition: global.h:165
int64_t maxCells
Definition: global.h:87
char logdir[128]
Definition: global.h:167
double fieldBC[NFIELDS]
Definition: fields.h:57
#define STRING
Definition: io.h:30
int rstReset
Definition: global.h:212
char rng[3]
Definition: global.h:168
int glucose
Definition: fields.h:35
double fieldCriticalLevel2[NFIELDS]
Definition: fields.h:70
int type[NPAR]
Definition: io.h:84
double fieldCriticalLevel1[NFIELDS]
Definition: fields.h:69
double fieldICMean[NFIELDS]
Definition: fields.h:58
float g2
Definition: global.h:187
float v
Definition: global.h:189
int temperature
Definition: fields.h:37
#define DOUBLE
Definition: io.h:34
float gfDt
Definition: global.h:249
#define HYDR
Definition: fields.h:85
#define LONG
Definition: io.h:32
#define OXYG
Definition: fields.h:83
double fieldConsumption[NFIELDS]
Definition: fields.h:64
int nz
Definition: global.h:164
#define INT
Definition: io.h:31
int req[NPAR]
Definition: io.h:82
float rd
Definition: global.h:190
void * addr[NPAR]
Definition: io.h:81
#define nc
Definition: global.h:93
float cs
Definition: global.h:193
char desc[NPAR][512]
Definition: io.h:80
double fieldProduction[NFIELDS]
Definition: fields.h:65
#define REAL
Definition: io.h:29
float cg1
Definition: global.h:192
int oxygen
Definition: fields.h:34
int ny
Definition: global.h:163
double fieldLambda[NFIELDS]
Definition: fields.h:56
int nx
Definition: global.h:162
char outdir[128]
Definition: global.h:166
float cg2
Definition: global.h:194
double h
Definition: global.h:200
int gfields
Definition: fields.h:33

Here is the caller graph for this function:

void ioDefineOutputFields ( )

This function defines output fields. Edit this part in order to introduce new output fields.

Definition at line 885 of file io.c.

References addrOut, cellData::age, cells, cellData::density, dimOut, cellData::halo, INT, jumpOut, lnc, MPIrank, nameOut, nfOut, cellData::phase, REAL, SCALAR, cellData::scalarField, cellData::size, cellData::tumor, typeOut, VECTOR, and velocity.

886 {
887 
888  nfOut = 0;
889 
890  if (lnc > 0) {
891 
892  strcpy(nameOut[nfOut], "density");
893  dimOut[nfOut] = SCALAR;
894  typeOut[nfOut] = REAL;
895  addrOut[nfOut] = &cells[0].density;
896  if (lnc > 1)
897  jumpOut[nfOut] =
898  (int64_t) & cells[1].density - (int64_t) & cells[0].density;
899  else
900  jumpOut[nfOut] = 0;
901 
902  nfOut++;
903 
904  strcpy(nameOut[nfOut], "size");
905  dimOut[nfOut] = SCALAR;
906  typeOut[nfOut] = REAL;
907  addrOut[nfOut] = &cells[0].size;
908  if (lnc > 1)
909  jumpOut[nfOut] =
910  (int64_t) & cells[1].size - (int64_t) & cells[0].size;
911  else
912  jumpOut[nfOut] = 0;
913 
914  nfOut++;
915 
916  strcpy(nameOut[nfOut], "rank");
917  dimOut[nfOut] = SCALAR;
918  typeOut[nfOut] = INT;
919  addrOut[nfOut] = &MPIrank;
920  jumpOut[nfOut] = 0;
921 
922  nfOut++;
923 
924  strcpy(nameOut[nfOut], "phase");
925  dimOut[nfOut] = SCALAR;
926  typeOut[nfOut] = INT;
927  addrOut[nfOut] = &cells[0].phase;
928  if (lnc > 1)
929  jumpOut[nfOut] =
930  (int64_t) & cells[1].phase - (int64_t) & cells[0].phase;
931  else
932  jumpOut[nfOut] = 0;
933 
934  nfOut++;
935 
936  strcpy(nameOut[nfOut], "tumor");
937  dimOut[nfOut] = SCALAR;
938  typeOut[nfOut] = INT;
939  addrOut[nfOut] = &cells[0].tumor;
940  if (lnc > 1)
941  jumpOut[nfOut] =
942  (int64_t) & cells[1].tumor - (int64_t) & cells[0].tumor;
943  else
944  jumpOut[nfOut] = 0;
945 
946  nfOut++;
947 
948  strcpy(nameOut[nfOut], "halo");
949  dimOut[nfOut] = SCALAR;
950  typeOut[nfOut] = INT;
951  addrOut[nfOut] = &cells[0].halo;
952  if (lnc > 1)
953  jumpOut[nfOut] =
954  (int64_t) & cells[1].halo - (int64_t) & cells[0].halo;
955  else
956  jumpOut[nfOut] = 0;
957 
958  nfOut++;
959 
960  strcpy(nameOut[nfOut], "velocity");
961  dimOut[nfOut] = VECTOR;
962  typeOut[nfOut] = REAL;
963  addrOut[nfOut] = &velocity[0];
964  if (lnc > 1)
965  jumpOut[nfOut] = (int64_t) & velocity[1] - (int64_t) & velocity[0];
966  else
967  jumpOut[nfOut] = 0;
968 
969  nfOut++;
970 
971  strcpy(nameOut[nfOut], "age");
972  dimOut[nfOut] = SCALAR;
973  typeOut[nfOut] = INT;
974  addrOut[nfOut] = &cells[0].age;
975  if (lnc > 1)
976  jumpOut[nfOut] = (int64_t) & cells[1].age - (int64_t) & cells[0].age;
977  else
978  jumpOut[nfOut] = 0;
979 
980  nfOut++;
981 
982  strcpy(nameOut[nfOut], "scalarField");
983  dimOut[nfOut] = SCALAR;
984  typeOut[nfOut] = REAL;
986  if (lnc > 1)
987  jumpOut[nfOut] =
988  (int64_t) & cells[1].scalarField -
989  (int64_t) & cells[0].scalarField;
990  else
991  jumpOut[nfOut] = 0;
992 
993  nfOut++;
994 
995  }
996 }
double density
Definition: global.h:75
int dimOut[NOUT]
Definition: io.h:46
int MPIrank
Definition: global.h:134
#define lnc
Definition: global.h:102
double scalarField
Definition: global.h:76
unsigned char tumor
Definition: global.h:77
int typeOut[NOUT]
Definition: io.h:44
double size
Definition: global.h:72
#define VECTOR
Definition: io.h:40
struct doubleVector3d * velocity
Definition: global.h:84
#define SCALAR
Definition: io.h:39
char nameOut[NOUT][128]
Definition: io.h:45
int phase
Definition: global.h:58
struct cellData * cells
Definition: global.h:82
int64_t jumpOut[NOUT]
Definition: io.h:48
#define INT
Definition: io.h:31
int age
Definition: global.h:59
int nfOut
Definition: io.h:49
void * addrOut[NOUT]
Definition: io.h:47
#define REAL
Definition: io.h:29
int halo
Definition: global.h:61

Here is the caller graph for this function:

void ioDefineOutputGlobalFields ( )

This function defines output for global fields.

Definition at line 1656 of file io.c.

References addrOut, dimOut, fieldAddr, fieldName, jumpOut, nameOut, NFIELDS, REAL, SCALAR, and typeOut.

1657 {
1658  int f;
1659  for (f = 0; f < NFIELDS; f++) {
1660  strcpy(nameOut[f], fieldName[f]);
1661  dimOut[f] = SCALAR;
1662  typeOut[f] = REAL;
1663  addrOut[f] = &fieldAddr[f];
1664  jumpOut[f] = sizeof(double);
1665  }
1666 }
int dimOut[NOUT]
Definition: io.h:46
#define NFIELDS
Definition: fields.h:27
int typeOut[NOUT]
Definition: io.h:44
char fieldName[NFIELDS][128]
Definition: fields.h:51
#define SCALAR
Definition: io.h:39
char nameOut[NOUT][128]
Definition: io.h:45
int64_t jumpOut[NOUT]
Definition: io.h:48
double * fieldAddr[NFIELDS]
Definition: fields.h:52
void * addrOut[NOUT]
Definition: io.h:47
#define REAL
Definition: io.h:29

Here is the caller graph for this function:

void ioDefineRstGlobalParams ( )

This function defines global parametes for the restart file. Defined parameters are used during reading and writing of the restart file. Edit this function in order to introduce new restart file parameters.

Definition at line 1235 of file io.c.

References addrRst, cg1, cg2, CHAR, cm, cs, csize, DOUBLE, dummy, g1, g2, h, INT, INT64_T, m, nc, nRst, nx, ny, nz, one, outdir, rd, REAL, rng, s, sdim, secondsPerStep, simStart, simTime, sizeRst, typeRst, and v.

1236 {
1237 
1238  nRst = 0;
1239 
1240  /* endiannnes */
1241  typeRst[nRst] = INT;
1242  sizeRst[nRst] = 1;
1243  addrRst[nRst] = &one;
1244  nRst++;
1245  /* system dimensions */
1246  typeRst[nRst] = INT;
1247  sizeRst[nRst] = 1;
1248  addrRst[nRst] = &sdim;
1249  nRst++;
1250  /* box sizes */
1251  typeRst[nRst] = INT;
1252  sizeRst[nRst] = 1;
1253  addrRst[nRst] = &nx;
1254  nRst++;
1255  typeRst[nRst] = INT;
1256  sizeRst[nRst] = 1;
1257  addrRst[nRst] = &ny;
1258  nRst++;
1259  typeRst[nRst] = INT;
1260  sizeRst[nRst] = 1;
1261  addrRst[nRst] = &nz;
1262  nRst++;
1263  /* output directory */
1264  typeRst[nRst] = CHAR;
1265  sizeRst[nRst] = 128;
1266  addrRst[nRst] = outdir;
1267  nRst++;
1268  /* RNG type */
1269  typeRst[nRst] = CHAR;
1270  sizeRst[nRst] = 3;
1271  addrRst[nRst] = rng;
1272  nRst++;
1273  /* number of cells */
1274  typeRst[nRst] = INT64_T;
1275  sizeRst[nRst] = 1;
1276  addrRst[nRst] = &nc;
1277  nRst++;
1278  /* "Simulation started" flag */
1279  typeRst[nRst] = INT;
1280  sizeRst[nRst] = 1;
1281  addrRst[nRst] = &simStart;
1282  nRst++;
1283  /* simulation time step */
1284  typeRst[nRst] = REAL;
1285  sizeRst[nRst] = 1;
1287  nRst++;
1288  /* simulation time */
1289  typeRst[nRst] = REAL;
1290  sizeRst[nRst] = 1;
1291  addrRst[nRst] = &simTime;
1292  nRst++;
1293  /* fraction */
1294  typeRst[nRst] = REAL;
1295  sizeRst[nRst] = 1;
1296  addrRst[nRst] = &dummy;
1297  nRst++;
1298  /* cell cycle phases duration - healthy tissue */
1299  typeRst[nRst] = REAL;
1300  sizeRst[nRst] = 1;
1301  addrRst[nRst] = &g1;
1302  nRst++;
1303  typeRst[nRst] = REAL;
1304  sizeRst[nRst] = 1;
1305  addrRst[nRst] = &s;
1306  nRst++;
1307  typeRst[nRst] = REAL;
1308  sizeRst[nRst] = 1;
1309  addrRst[nRst] = &g2;
1310  nRst++;
1311  typeRst[nRst] = REAL;
1312  sizeRst[nRst] = 1;
1313  addrRst[nRst] = &m;
1314  nRst++;
1315  /* cell cycle variability */
1316  typeRst[nRst] = REAL;
1317  sizeRst[nRst] = 1;
1318  addrRst[nRst] = &v;
1319  nRst++;
1320  /* random death probability */
1321  typeRst[nRst] = REAL;
1322  sizeRst[nRst] = 1;
1323  addrRst[nRst] = &rd;
1324  nRst++;
1325  /* neighborhood h parameter */
1326  typeRst[nRst] = DOUBLE;
1327  sizeRst[nRst] = 1;
1328  addrRst[nRst] = &h;
1329  nRst++;
1330  /* cell size */
1331  typeRst[nRst] = DOUBLE;
1332  sizeRst[nRst] = 1;
1333  addrRst[nRst] = &csize;
1334  nRst++;
1335  /* cell cycle phases duration - cancer cells */
1336  typeRst[nRst] = REAL;
1337  sizeRst[nRst] = 1;
1338  addrRst[nRst] = &cg1;
1339  nRst++;
1340  typeRst[nRst] = REAL;
1341  sizeRst[nRst] = 1;
1342  addrRst[nRst] = &cs;
1343  nRst++;
1344  typeRst[nRst] = REAL;
1345  sizeRst[nRst] = 1;
1346  addrRst[nRst] = &cg2;
1347  nRst++;
1348  typeRst[nRst] = REAL;
1349  sizeRst[nRst] = 1;
1350  addrRst[nRst] = &cm;
1351  nRst++;
1352 
1353 }
float secondsPerStep
Definition: global.h:247
#define CHAR
Definition: io.h:35
float s
Definition: global.h:186
float g1
Definition: global.h:185
int simStart
Definition: global.h:172
float dummy
Definition: global.h:242
float cm
Definition: global.h:195
void * addrRst[NRSTPARAMS]
Definition: io.h:53
float m
Definition: global.h:188
int sdim
Definition: global.h:160
char rng[3]
Definition: global.h:168
double csize
Definition: global.h:197
int one
Definition: io.h:77
float g2
Definition: global.h:187
#define INT64_T
Definition: io.h:33
float v
Definition: global.h:189
#define DOUBLE
Definition: io.h:34
int nz
Definition: global.h:164
#define INT
Definition: io.h:31
int nRst
Definition: io.h:54
float simTime
Definition: global.h:175
int sizeRst[NRSTPARAMS]
Definition: io.h:52
float rd
Definition: global.h:190
#define nc
Definition: global.h:93
float cs
Definition: global.h:193
#define REAL
Definition: io.h:29
float cg1
Definition: global.h:192
int typeRst[NRSTPARAMS]
Definition: io.h:51
int ny
Definition: global.h:163
int nx
Definition: global.h:162
char outdir[128]
Definition: global.h:166
float cg2
Definition: global.h:194
double h
Definition: global.h:200

Here is the caller graph for this function:

void ioWriteFields ( int  step)

This function prints global fields data in VisNow data format http://visnow.icm.edu.pl

Definition at line 1672 of file io.c.

References endian, fieldAddr, gfields, gridBuffer, gridI, gridJ, gridK, gridSize, gridStartIdx, ioDefineOutputGlobalFields(), m, MPIrank, nameOut, NFIELDS, outdir, swap_Nbyte(), x, int64Vector3d::x, floatVector3d::x, int64Vector3d::y, floatVector3d::y, int64Vector3d::z, and floatVector3d::z.

1673 {
1674  int i, j, k, f;
1675  MPI_File fh1, fh2;
1676  struct floatVector3d *floatVectorField;
1677  float *floatScalarField;
1678  int *integerScalarField;
1679  int64_t nprev = 0;
1680  int64_t size;
1681  int m = 0;
1682  int bdim;
1683  int gsize[3];
1684  int bsize[3]; /* box size */
1685  int bstart[3]; /* box start */
1686  MPI_Offset offset, goffset;
1687  MPI_Datatype subarray1_t, subarray2_t, float3_t;
1688 
1689  if (!gfields)
1690  return;
1691 
1693 
1694  bdim = 3;
1695  gsize[0] = gridI;
1696  gsize[1] = gridJ;
1697  gsize[2] = gridK;
1698  bsize[0] = gridSize.x;
1699  bsize[1] = gridSize.y;
1700  bsize[2] = gridSize.z;
1701  bstart[0] = gridStartIdx[MPIrank].x;
1702  bstart[1] = gridStartIdx[MPIrank].y;
1703  bstart[2] = gridStartIdx[MPIrank].z;
1704 
1705  MPI_Type_vector(1, 3, 0, MPI_FLOAT, &float3_t);
1706  MPI_Type_commit(&float3_t);
1707 
1708  MPI_Type_create_subarray(bdim, gsize, bsize, bstart, MPI_ORDER_C,
1709  float3_t, &subarray1_t);
1710  MPI_Type_commit(&subarray1_t);
1711 
1712  gsize[0] = gridI;
1713  gsize[1] = gridJ;
1714  gsize[2] = gridK;
1715  bsize[0] = gridSize.x;
1716  bsize[1] = gridSize.y;
1717  bsize[2] = gridSize.z;
1718  bstart[0] = gridStartIdx[MPIrank].x;
1719  bstart[1] = gridStartIdx[MPIrank].y;
1720  bstart[2] = gridStartIdx[MPIrank].z;
1721 
1722  MPI_Type_create_subarray(bdim, gsize, bsize, bstart, MPI_ORDER_C,
1723  MPI_FLOAT, &subarray2_t);
1724  MPI_Type_commit(&subarray2_t);
1725 
1726  for (f = 0; f < NFIELDS; f++) {
1727 
1728  char fstname1[256];
1729  char fstname2[256];
1730 
1731  size = gridSize.x * gridSize.y * gridSize.z;
1732 
1733  floatVectorField =
1734  (struct floatVector3d *) malloc(size *
1735  sizeof(struct floatVector3d));
1736  floatScalarField = (float *) malloc(size * sizeof(float));
1737  integerScalarField = (int *) malloc(size * sizeof(int));
1738 
1739  sprintf(fstname1, "%s/%s%08dcoords.bin", outdir, nameOut[f], step);
1740  sprintf(fstname2, "%s/%s%08dvalues.bin", outdir, nameOut[f], step);
1741 
1742  goffset = 0;
1743  MPI_File_open(MPI_COMM_WORLD, fstname1,
1744  MPI_MODE_WRONLY | MPI_MODE_CREATE, MPI_INFO_NULL, &fh1);
1745  MPI_File_set_view(fh1, 0, MPI_FLOAT, subarray1_t, "native",
1746  MPI_INFO_NULL);
1747  /* truncate the first file */
1748  MPI_File_set_size(fh1, 0);
1749 
1750  for (j = 0; j < size; j++) {
1751  floatVectorField[j].x = (float) (gridBuffer[j].x);
1752  floatVectorField[j].y = (float) (gridBuffer[j].y);
1753  floatVectorField[j].z = (float) (gridBuffer[j].z);
1754  }
1755  if (!endian)
1756  swap_Nbyte((char *) floatVectorField, size * 3, sizeof(float));
1757  MPI_File_write(fh1, floatVectorField, 3 * size, MPI_FLOAT,
1758  MPI_STATUS_IGNORE);
1759  MPI_File_close(&fh1);
1760 
1761  goffset = 0;
1762  MPI_File_open(MPI_COMM_WORLD, fstname2,
1763  MPI_MODE_WRONLY | MPI_MODE_CREATE, MPI_INFO_NULL, &fh2);
1764  MPI_File_set_view(fh2, 0, MPI_FLOAT, subarray2_t, "native",
1765  MPI_INFO_NULL);
1766  /* truncate the second file */
1767  MPI_File_set_size(fh2, 0);
1768 
1769  for (j = 0; j < size; j++)
1770  floatScalarField[j] = fieldAddr[f][j];
1771  if (!endian)
1772  swap_Nbyte((char *) floatScalarField, size, sizeof(float));
1773  MPI_File_write(fh2, floatScalarField, size, MPI_FLOAT,
1774  MPI_STATUS_IGNORE);
1775 
1776  MPI_File_close(&fh2);
1777 
1778  free(floatVectorField);
1779  free(floatScalarField);
1780  free(integerScalarField);
1781 
1782  }
1783  MPI_Type_free(&subarray1_t);
1784  MPI_Type_free(&subarray2_t);
1785 }
int64_t x
Definition: global.h:229
int MPIrank
Definition: global.h:134
float z
Definition: global.h:237
HYPRE_SStructVector x
Definition: tempf.c:41
int64_t gridK
Definition: fields.h:40
#define NFIELDS
Definition: fields.h:27
struct doubleVector3d * gridBuffer
Definition: fields.h:43
void ioDefineOutputGlobalFields()
Definition: io.c:1656
int64_t z
Definition: global.h:231
float m
Definition: global.h:188
int step
Definition: global.h:173
struct int64Vector3d gridSize
Definition: fields.h:41
char nameOut[NOUT][128]
Definition: io.h:45
struct int64Vector3d * gridStartIdx
Definition: fields.h:42
float x
Definition: global.h:235
float y
Definition: global.h:236
double * fieldAddr[NFIELDS]
Definition: fields.h:52
int64_t y
Definition: global.h:230
int endian
Definition: global.h:157
void swap_Nbyte(char *data, int n, int m)
Definition: utils.c:57
int64_t gridI
Definition: fields.h:40
int64_t gridJ
Definition: fields.h:40
char outdir[128]
Definition: global.h:166
int gfields
Definition: fields.h:33

Here is the call graph for this function:

Here is the caller graph for this function:

void ioWriteStepPovRay ( int  step,
int  type 
)

This function prints PovRay output with cellular data.

Definition at line 1978 of file io.c.

References colormapPoint_t::b, beta, cellFields, cells, cm, cmaps, colormap_t::cp, csize, cellData::density, densityCriticalLevel2, fieldMax, fieldMin, colormapPoint_t::g, lnc, MPIrank, MPIsize, colormap_t::ncp, outdir, OXYG, colormapPoint_t::position, colormapPoint_t::r, cellData::size, stopRun(), x, cellData::x, cellData::y, floatVector3d::y, cellData::z, and floatVector3d::z.

1979 {
1980  int c;
1981  int i;
1982  char fstname[256];
1983  MPI_File fh;
1984  MPI_Status status;
1985  MPI_Offset disp, offset;
1986  MPI_Datatype subarray_t;
1987  float cr, cg, cb;
1988  char *const fmt =
1989  "sphere{ <%10.4f,%10.4f,%10.4f>,%10.4f texture { pigment { color rgb <%6.4f,%6.4f,%6.4f> } finish { phong 0.2 ambient .1 }}} \n";
1990  char testBuffer[512];
1991  char *txtData;
1992  char *txtData_p;
1993  char *txtHeaderData;
1994  int numCharsPerCell;
1995  int headerLen;
1996  int headerSize;
1997  int headerSizeTmp;
1998  int error;
1999  int gdims;
2000  int gsize[1];
2001  int istart[1];
2002  int isize[1];
2003  int64_t printed = 0;
2004  int64_t tPrinted[MPIsize];
2005  double fmin, fmax, fepsilon;
2006  int cm;
2007  int cmReverse = 0;
2008  int cmShift = 0;
2009  double cmPad;
2010  double minCorner[3], maxCorner[3];
2011  double gMinCorner[3], gMaxCorner[3];
2012 
2013  double middlePointLocal[3];
2014  double middlePointGlobal[3];
2015  double lmass, gmass;
2016 
2017  /* type: 0 - denisty, 1 - oxygen, 2 - phases, 3 - slice & phases */
2018 
2019  minCorner[0] = DBL_MAX;
2020  minCorner[1] = DBL_MAX;
2021  minCorner[2] = DBL_MAX;
2022  maxCorner[0] = -DBL_MAX;
2023  maxCorner[1] = -DBL_MAX;
2024  maxCorner[2] = -DBL_MAX;
2025 
2026  for (i = 0; i < lnc; i++) {
2027  minCorner[0] =
2028  (cells[i].x - cells[i].size <
2029  minCorner[0] ? cells[i].x - cells[i].size : minCorner[0]);
2030  maxCorner[0] =
2031  (cells[i].x + cells[i].size >
2032  maxCorner[0] ? cells[i].x + cells[i].size : maxCorner[0]);
2033  minCorner[1] =
2034  (cells[i].y - cells[i].size <
2035  minCorner[1] ? cells[i].y - cells[i].size : minCorner[1]);
2036  maxCorner[1] =
2037  (cells[i].y + cells[i].size >
2038  maxCorner[1] ? cells[i].y + cells[i].size : maxCorner[1]);
2039  minCorner[2] =
2040  (cells[i].z - cells[i].size <
2041  minCorner[2] ? cells[i].z - cells[i].size : minCorner[2]);
2042  maxCorner[2] =
2043  (cells[i].z + cells[i].size >
2044  maxCorner[2] ? cells[i].z + cells[i].size : maxCorner[2]);
2045  }
2046  MPI_Allreduce(minCorner, gMinCorner, 3, MPI_DOUBLE, MPI_MIN,
2047  MPI_COMM_WORLD);
2048  MPI_Allreduce(maxCorner, gMaxCorner, 3, MPI_DOUBLE, MPI_MAX,
2049  MPI_COMM_WORLD);
2050 
2051  middlePointLocal[0] = 0.0;
2052  middlePointLocal[1] = 0.0;
2053  middlePointLocal[2] = 0.0;
2054  lmass = 0.0;
2055  gmass = 0.0;
2056 
2057  for (c = 0; c < lnc; c++) {
2058  middlePointLocal[0] += cells[c].size * cells[c].x;
2059  middlePointLocal[1] += cells[c].size * cells[c].y;
2060  middlePointLocal[2] += cells[c].size * cells[c].z;
2061  lmass += cells[c].size;
2062  }
2063 
2064  MPI_Allreduce(middlePointLocal, middlePointGlobal, 3, MPI_DOUBLE,
2065  MPI_SUM, MPI_COMM_WORLD);
2066  MPI_Allreduce(&lmass, &gmass, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
2067  middlePointGlobal[0] /= gmass;
2068  middlePointGlobal[1] /= gmass;
2069  middlePointGlobal[2] /= gmass;
2070 
2071  middlePointGlobal[0] =
2072  gMinCorner[0] + (gMaxCorner[0] - gMinCorner[0]) / 2;
2073  middlePointGlobal[1] =
2074  gMinCorner[1] + (gMaxCorner[1] - gMinCorner[1]) / 2;
2075  middlePointGlobal[2] =
2076  gMinCorner[2] + (gMaxCorner[2] - gMinCorner[2]) / 2;
2077 
2078  /* write data to test buffer */
2079  cr = 0.0;
2080  cg = 0.0;
2081  cb = 0.0;
2082  cm = 0;
2083  numCharsPerCell =
2084  sprintf(testBuffer, fmt, cells[0].x, cells[0].y, cells[0].z,
2085  cells[0].size, cr, cg, cb);
2086  if (!
2087  (txtData =
2088  (char *) malloc(numCharsPerCell * (lnc + 16) * sizeof(char))))
2089  stopRun(106, "txtData", __FILE__, __LINE__);
2090  txtData_p = txtData;
2091 
2092  for (i = 0; i < MPIsize; i++)
2093  tPrinted[i] = 0;
2094 
2095  switch (type) {
2096  case 0:
2097  sprintf(fstname, "%s/step%08ddensity.pov", outdir, step);
2098  cm = 5;
2099  cmReverse = 1;
2100  break;
2101  case 1:
2102  sprintf(fstname, "%s/step%08doxygen.pov", outdir, step);
2103  MPI_Allreduce(&fieldMin[OXYG], &fmin, 1, MPI_DOUBLE, MPI_MIN,
2104  MPI_COMM_WORLD);
2105  MPI_Allreduce(&fieldMax[OXYG], &fmax, 1, MPI_DOUBLE, MPI_MAX,
2106  MPI_COMM_WORLD);
2107  fepsilon = (fmax - fmin) * 0.1;
2108  fmin -= fepsilon;
2109  fmax += fepsilon;
2110  cm = 0;
2111  break;
2112  case 2:
2113  sprintf(fstname, "%s/step%08dphases.pov", outdir, step);
2114  cm = 1;
2115  break;
2116  case 3:
2117  sprintf(fstname, "%s/step%08dslice.pov", outdir, step);
2118  cm = 1;
2119  break;
2120  case 4:
2121  sprintf(fstname, "%s/step%08doutside.pov", outdir, step);
2122  cm = 0;
2123  cmReverse = 1;
2124  cmShift = 1;
2125  cmPad = 0.15;
2126  break;
2127  }
2128 
2129  /* open file */
2130  error =
2131  MPI_File_open(MPI_COMM_WORLD, fstname,
2132  MPI_MODE_WRONLY | MPI_MODE_CREATE, MPI_INFO_NULL, &fh);
2133  if (error != MPI_SUCCESS)
2134  if (MPIrank == 0)
2135  stopRun(113, NULL, __FILE__, __LINE__);
2136 
2137  MPI_File_set_size(fh, 0);
2138 
2139  /* write header */
2140  if (MPIrank == 0) {
2141 
2142  float cameraLocation[3];
2143  float lookAt[3];
2144  float lightSource1[3];
2145  float lightSource2[3];
2146  float a1, a2, a3, b1, b2, b3, dist;
2147  float ss, cc;
2148  float corner;
2149 
2150  a1 = (gMaxCorner[0] - gMinCorner[0]) / 2;
2151  a2 = (gMaxCorner[1] - gMinCorner[1]) / 2;
2152  a3 = (gMaxCorner[2] - gMinCorner[2]) / 2;
2153 
2154  b1 = a1 / (tan(30.0 * M_PI / 180.0));
2155  b2 = a2 / (tan(30.0 * M_PI / 180.0));
2156  b3 = a3 / (tan(30.0 * M_PI / 180.0));
2157 
2158  dist = (b1 >= b2 ? b1 : b2);
2159  dist = (dist >= b3 ? dist : b3);
2160 
2161  ss = sin(beta * M_PI / 180.0);
2162  cc = cos(beta * M_PI / 180.0);
2163 
2164  corner = sqrt(pow(a1, 2) + pow(a3, 2));
2165 
2166  cameraLocation[0] =
2167  -(middlePointGlobal[2] - corner - dist -
2168  middlePointGlobal[2]) * ss + middlePointGlobal[0];
2169  cameraLocation[1] = middlePointGlobal[1];
2170  cameraLocation[2] =
2171  (middlePointGlobal[2] - corner - dist -
2172  middlePointGlobal[2]) * cc + middlePointGlobal[2];
2173 
2174  lookAt[0] = middlePointGlobal[0];
2175  lookAt[1] = middlePointGlobal[1];
2176  lookAt[2] = middlePointGlobal[2];
2177 
2178  lightSource1[0] = cameraLocation[0];
2179  lightSource1[1] = cameraLocation[1];
2180  lightSource1[2] = cameraLocation[2];
2181 
2182  lightSource2[0] = lightSource1[0];
2183  lightSource2[1] = lightSource1[1];
2184  lightSource2[2] = lightSource1[2];
2185 
2186  txtHeaderData = (char *) malloc(1024 * sizeof(char));
2187 
2188  headerLen =
2189  sprintf(txtHeaderData,
2190  "#include \"colors.inc\"\ncamera { location <%f,%f,%f> look_at <%f,%f,%f> angle 60}\nlight_source { <%f,%f,%f> color White }\nlight_source { <%f,%f,%f> color White }\nbackground { color White }\n",
2191  cameraLocation[0], cameraLocation[1], cameraLocation[2],
2192  lookAt[0], lookAt[1], lookAt[2], lightSource1[0],
2193  lightSource1[1], lightSource1[2], lightSource2[0],
2194  lightSource2[1], lightSource2[2]);
2195 
2196  headerSize = headerLen * sizeof(char);
2197 
2198  MPI_File_write(fh, txtHeaderData, headerLen, MPI_CHAR, &status);
2199 
2200  free(txtHeaderData);
2201  }
2202 
2203  MPI_Bcast(&headerSize, 1, MPI_INT, 0, MPI_COMM_WORLD);
2204 
2205  for (c = 0; c < lnc; c++) {
2206  float color = 0.0;
2207  int jump;
2208  if (beta == 360.0
2209  && (cells[c].z > middlePointGlobal[2] + 4.0 * csize
2210  || cells[c].z < middlePointGlobal[2] - 4.0 * csize))
2211  continue;
2212  if (type == 0) {
2213  color = ((cells[c].density) / (densityCriticalLevel2));
2214  if (cells[c].tumor)
2215  color = 0.0;
2216  } //2.5);
2217  if (type == 1)
2218  color = ((cellFields[OXYG][c] - fmin) / (fmax - fmin));
2219  if (type == 2 || type == 3 || type == 4)
2220  color = (((float) cells[c].phase) / 5.0);
2221  if (type == 2)
2222  color = (((float) MPIrank) / 512.0);
2223 
2224  if (type == 0)
2225  color = color / 4 + 0.75;
2226 
2227  if (cmReverse)
2228  color = 1.0 - color;
2229  if (cmShift) {
2230  color = color * (1 - cmPad);
2231  if (color == 1 - cmPad)
2232  color = 1.0;
2233  }
2234 
2235  for (i = 1; i < cmaps[cm].ncp; i++) {
2236  float d, dr, dg, db;
2237  d = cmaps[cm].cp[i].position - cmaps[cm].cp[i - 1].position;
2238  dr = cmaps[cm].cp[i].r - cmaps[cm].cp[i - 1].r;
2239  dg = cmaps[cm].cp[i].g - cmaps[cm].cp[i - 1].g;
2240  db = cmaps[cm].cp[i].b - cmaps[cm].cp[i - 1].b;
2241  if (color <= cmaps[cm].cp[i].position) {
2242  cr = cmaps[cm].cp[i - 1].r +
2243  ((color - cmaps[cm].cp[i - 1].position) / d) * dr;
2244  cg = cmaps[cm].cp[i - 1].g +
2245  ((color - cmaps[cm].cp[i - 1].position) / d) * dg;
2246  cb = cmaps[cm].cp[i - 1].b +
2247  ((color - cmaps[cm].cp[i - 1].position) / d) * db;
2248  break;
2249  }
2250 
2251  }
2252 
2253  cr /= 255.0;
2254  cg /= 255.0;
2255  cb /= 255.0;
2256 
2257  jump =
2258  sprintf(txtData_p, fmt, cells[c].x, cells[c].y, cells[c].z,
2259  cells[c].size, cr, cg, cb);
2260  txtData_p += jump;
2261  printed += 1;
2262  }
2263 
2264  if (printed == 0) {
2265  float coords[3];
2266  float size = 0.0;
2267  float color[3];
2268  int jump;
2269  /* artificial cell far away from the scene */
2270  coords[0] = -512.0;
2271  coords[1] = -512.0;
2272  coords[2] = -512.0;
2273  color[0] = 0.0;
2274  color[1] = 0.0;
2275  color[2] = 0.0;
2276 
2277  printed = 1;
2278 
2279  jump =
2280  sprintf(txtData_p, fmt, coords[0], coords[1], coords[2], size,
2281  color[0], color[1], color[2]);
2282  txtData_p += jump;
2283  }
2284 
2285  gdims = 1;
2286  tPrinted[MPIrank] = printed;
2287  MPI_Allgather(&printed, 1, MPI_INT64_T, tPrinted, 1, MPI_INT64_T,
2288  MPI_COMM_WORLD);
2289 
2290  gsize[0] = 0;
2291  istart[0] = 0;
2292  isize[0] = printed * numCharsPerCell;
2293  for (i = 0; i < MPIrank; i++)
2294  istart[0] += tPrinted[i] * numCharsPerCell;
2295 
2296  for (i = 0; i < MPIsize; i++)
2297  gsize[0] += tPrinted[i] * numCharsPerCell;
2298 
2299  MPI_Type_create_subarray(gdims, gsize, isize, istart, MPI_ORDER_C,
2300  MPI_CHAR, &subarray_t);
2301  MPI_Type_commit(&subarray_t);
2302 
2303  MPI_File_set_view(fh, headerSize, MPI_CHAR, subarray_t, "native",
2304  MPI_INFO_NULL);
2305 
2306  MPI_File_write(fh, txtData, isize[0], MPI_CHAR, &status);
2307 
2308  free(txtData);
2309 
2310  MPI_File_close(&fh);
2311  MPI_Type_free(&subarray_t);
2312 
2313  if (beta < 360.0)
2314  beta += 1.0;
2315  else
2316  beta = 360.0;
2317 
2318 }
double density
Definition: global.h:75
int MPIrank
Definition: global.h:134
#define lnc
Definition: global.h:102
float z
Definition: global.h:237
HYPRE_SStructVector x
Definition: tempf.c:41
double fieldMin[NFIELDS]
Definition: fields.h:72
int MPIsize
Definition: global.h:135
float cm
Definition: global.h:195
double size
Definition: global.h:72
float g
Definition: io.h:92
double fieldMax[NFIELDS]
Definition: fields.h:73
int step
Definition: global.h:173
float beta
Definition: io.h:103
float b
Definition: io.h:93
double x
Definition: global.h:69
colormap * cmaps
Definition: io.h:102
double csize
Definition: global.h:197
int type[NPAR]
Definition: io.h:84
colormapPoint * cp
Definition: io.h:99
struct cellData * cells
Definition: global.h:82
#define OXYG
Definition: fields.h:83
float y
Definition: global.h:236
double z
Definition: global.h:71
float r
Definition: io.h:91
float position
Definition: io.h:90
double y
Definition: global.h:70
double densityCriticalLevel2
Definition: global.h:209
double ** cellFields
Definition: global.h:83
void stopRun(int ierr, char *name, char *file, int line)
Definition: utils.c:72
char outdir[128]
Definition: global.h:166
int ncp
Definition: io.h:98

Here is the call graph for this function:

Here is the caller graph for this function:

void ioWriteStepVTK ( int  step)

This function writes a VTK file with all cells for a given step.

Definition at line 1001 of file io.c.

References addrOut, cells, dimOut, endian, INT, ioDefineOutputFields(), jumpOut, lnc, MPIrank, nameOut, nc, nfOut, outdir, REAL, SCALAR, swap_Nbyte(), tlnc, typeOut, VECTOR, and x.

1002 {
1003 
1004  int i, j, k;
1005  MPI_File fh;
1006  float *floatVectorField;
1007  float *floatScalarField;
1008  int *integerScalarField;
1009  int64_t nprev = 0;
1010  char fstname[256];
1011  char header[256];
1012  MPI_Offset offset, goffset;
1013 
1015 
1016  floatVectorField = (float *) calloc(lnc * 3, sizeof(float));
1017  floatScalarField = (float *) calloc(lnc, sizeof(float));
1018  integerScalarField = (int *) calloc(lnc, sizeof(int));
1019 
1020  sprintf(fstname, "%s/step%08d.vtk", outdir, step);
1021 
1022  goffset = 0;
1023  MPI_File_open(MPI_COMM_WORLD, fstname, MPI_MODE_WRONLY | MPI_MODE_CREATE,
1024  MPI_INFO_NULL, &fh);
1025  /* truncate the file */
1026  MPI_File_set_size(fh, 0);
1027 
1028  sprintf(header,
1029  "# vtk DataFile Version 2.0\nTimothy output\nBINARY\nDATASET UNSTRUCTURED_GRID\n");
1030 
1031  /* gather number of cells from each process */
1032  MPI_Allgather(&lnc, 1, MPI_LONG_LONG, tlnc, 1, MPI_LONG_LONG,
1033  MPI_COMM_WORLD);
1034  for (i = 0; i < MPIrank; i++)
1035  nprev += tlnc[i];
1036 
1037 
1038  /* write the VTK header */
1039  if (MPIrank == 0)
1040  MPI_File_write(fh, &header, strlen(header), MPI_BYTE,
1041  MPI_STATUS_IGNORE);
1042  goffset += strlen(header);
1043  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1044 
1045  /* adding positions */
1046  memset(header, 0, 256);
1047  sprintf(header, "\nPOINTS %" PRId64 " float\n", nc);
1048  if (MPIrank == 0)
1049  MPI_File_write(fh, &header, strlen(header), MPI_BYTE,
1050  MPI_STATUS_IGNORE);
1051  goffset += strlen(header);
1052  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1053 
1054  offset = nprev * sizeof(float) * 3;
1055  MPI_File_seek(fh, offset, MPI_SEEK_CUR);
1056  for (j = 0; j < lnc; j++) {
1057  floatVectorField[3 * j] = (float) (cells[j].x);
1058  floatVectorField[3 * j + 1] = (float) (cells[j].y);
1059  floatVectorField[3 * j + 2] = (float) (cells[j].z);
1060  }
1061  if (endian)
1062  swap_Nbyte((char *) floatVectorField, lnc * 3, sizeof(float));
1063  MPI_File_write(fh, floatVectorField, 3 * lnc, MPI_FLOAT,
1064  MPI_STATUS_IGNORE);
1065  goffset += nc * sizeof(float) * 3;
1066  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1067 
1068  /* adding cell types */
1069  memset(header, 0, 256);
1070  sprintf(header, "\nCELL_TYPES %" PRId64 "\n", nc);
1071  if (MPIrank == 0)
1072  MPI_File_write(fh, &header, strlen(header), MPI_BYTE,
1073  MPI_STATUS_IGNORE);
1074  goffset += strlen(header);
1075  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1076  offset = nprev * sizeof(int);
1077  MPI_File_seek(fh, offset, MPI_SEEK_CUR);
1078  for (j = 0; j < lnc; j++)
1079  integerScalarField[j] = 1;
1080  if (endian)
1081  swap_Nbyte((char *) integerScalarField, lnc, sizeof(int));
1082  MPI_File_write(fh, integerScalarField, lnc, MPI_INT, MPI_STATUS_IGNORE);
1083  goffset += nc * sizeof(int);
1084  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1085 
1086  /* point data */
1087  memset(header, 0, 256);
1088  sprintf(header, "\nPOINT_DATA %" PRId64, nc);
1089  if (MPIrank == 0)
1090  MPI_File_write(fh, &header, strlen(header), MPI_BYTE,
1091  MPI_STATUS_IGNORE);
1092  goffset += strlen(header);
1093  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1094 
1095  /* adding fields */
1096  for (i = 0; i < nfOut; i++) {
1097  memset(header, 0, 256);
1098  if (dimOut[i] == SCALAR) {
1099  switch (typeOut[i]) {
1100  case REAL:
1101  sprintf(header, "\nSCALARS %s float 1\nLOOKUP_TABLE default\n",
1102  nameOut[i]);
1103  if (MPIrank == 0)
1104  MPI_File_write(fh, &header, strlen(header), MPI_BYTE,
1105  MPI_STATUS_IGNORE);
1106  goffset += strlen(header);
1107  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1108  for (j = 0; j < lnc; j++)
1109  floatScalarField[j] =
1110  (float) (*((double *) (addrOut[i] + j * jumpOut[i])));
1111  offset = nprev * sizeof(float);
1112  MPI_File_seek(fh, offset, MPI_SEEK_CUR);
1113  if (endian)
1114  swap_Nbyte((char *) floatScalarField, lnc, sizeof(float));
1115  MPI_File_write(fh, floatScalarField, lnc, MPI_FLOAT,
1116  MPI_STATUS_IGNORE);
1117  goffset += nc * sizeof(float);
1118  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1119  break;
1120  case INT:
1121  sprintf(header, "\nSCALARS %s integer 1\nLOOKUP_TABLE default\n",
1122  nameOut[i]);
1123  if (MPIrank == 0)
1124  MPI_File_write(fh, &header, strlen(header), MPI_BYTE,
1125  MPI_STATUS_IGNORE);
1126  goffset += strlen(header);
1127  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1128  for (j = 0; j < lnc; j++)
1129  integerScalarField[j] = *((int *) (addrOut[i] + j * jumpOut[i]));
1130  offset = nprev * sizeof(int);
1131  MPI_File_seek(fh, offset, MPI_SEEK_CUR);
1132  if (endian)
1133  swap_Nbyte((char *) integerScalarField, lnc, sizeof(int));
1134  MPI_File_write(fh, integerScalarField, lnc, MPI_INT,
1135  MPI_STATUS_IGNORE);
1136  goffset += nc * sizeof(int);
1137  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1138  break;
1139  }
1140  }
1141  if (dimOut[i] == VECTOR) {
1142  switch (typeOut[i]) {
1143  case REAL:
1144  sprintf(header, "\nVECTORS %s float\n", nameOut[i]);
1145  if (MPIrank == 0)
1146  MPI_File_write(fh, &header, strlen(header), MPI_BYTE,
1147  MPI_STATUS_IGNORE);
1148  goffset += strlen(header);
1149  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1150  for (j = 0; j < lnc; j++) {
1151  floatVectorField[3 * j] =
1152  (float) (*((double *) (addrOut[i] + j * jumpOut[i])));
1153  floatVectorField[3 * j + 1] =
1154  (float) (*
1155  ((double *) (addrOut[i] + 1 * sizeof(double) +
1156  j * jumpOut[i])));
1157  floatVectorField[3 * j + 2] =
1158  (float) (*
1159  ((double *) (addrOut[i] + 2 * sizeof(double) +
1160  j * jumpOut[i])));
1161  }
1162  offset = nprev * sizeof(float) * 3;
1163  MPI_File_seek(fh, offset, MPI_SEEK_CUR);
1164  if (endian)
1165  swap_Nbyte((char *) floatVectorField, lnc * 3, sizeof(float));
1166  MPI_File_write(fh, floatVectorField, lnc * 3, MPI_FLOAT,
1167  MPI_STATUS_IGNORE);
1168  goffset += nc * 3 * sizeof(float);
1169  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1170  break;
1171  case INT:
1172  /* note: INTs are converted to FLOATs */
1173  printf(header, "\nVECTORS %s float\n", nameOut[i]);
1174  if (MPIrank == 0)
1175  MPI_File_write(fh, &header, strlen(header), MPI_BYTE,
1176  MPI_STATUS_IGNORE);
1177  goffset += strlen(header);
1178  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1179  for (j = 0; j < lnc; j++) {
1180  floatVectorField[3 * j] =
1181  (*((float *) (addrOut[i] + j * jumpOut[i])));
1182  floatVectorField[3 * j + 1] =
1183  (*
1184  ((float *) (addrOut[i] + 1 * sizeof(int) +
1185  j * jumpOut[i])));
1186  floatVectorField[3 * j + 2] =
1187  (*
1188  ((float *) (addrOut[i] + 2 * sizeof(int) +
1189  j * jumpOut[i])));
1190  }
1191  offset = nprev * sizeof(float) * 3;
1192  MPI_File_seek(fh, offset, MPI_SEEK_CUR);
1193  if (endian)
1194  swap_Nbyte((char *) floatVectorField, lnc * 3, sizeof(float));
1195  MPI_File_write(fh, floatVectorField, lnc * 3, MPI_FLOAT,
1196  MPI_STATUS_IGNORE);
1197  goffset += nc * 3 * sizeof(float);
1198  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1199  break;
1200  }
1201  }
1202  }
1203 
1204  free(floatVectorField);
1205  free(floatScalarField);
1206  free(integerScalarField);
1207 
1208  MPI_File_close(&fh);
1209 }
int dimOut[NOUT]
Definition: io.h:46
int64_t * tlnc
Definition: global.h:111
int MPIrank
Definition: global.h:134
#define lnc
Definition: global.h:102
float z
Definition: global.h:237
HYPRE_SStructVector x
Definition: tempf.c:41
int typeOut[NOUT]
Definition: io.h:44
#define VECTOR
Definition: io.h:40
int step
Definition: global.h:173
#define SCALAR
Definition: io.h:39
char nameOut[NOUT][128]
Definition: io.h:45
struct cellData * cells
Definition: global.h:82
int64_t jumpOut[NOUT]
Definition: io.h:48
void ioDefineOutputFields()
Definition: io.c:885
float y
Definition: global.h:236
#define INT
Definition: io.h:31
int nfOut
Definition: io.h:49
#define nc
Definition: global.h:93
int endian
Definition: global.h:157
void * addrOut[NOUT]
Definition: io.h:47
#define REAL
Definition: io.h:29
void swap_Nbyte(char *data, int n, int m)
Definition: utils.c:57
char outdir[128]
Definition: global.h:166

Here is the call graph for this function:

Here is the caller graph for this function:

void printBasicInfo ( )

This function prints Timothy's basic information.

Definition at line 48 of file io.c.

References MPIrank, and VERSION.

49 {
50  if (MPIrank == 0) {
51  printf("\nTimothy v.%s - Tissue Modelling Framework\n", VERSION);
52  printf(" M.Cytowski, Z.Szymanska\n");
53  printf(" ICM, University of Warsaw\n");
54  printf(" http://timothy.icm.edu.pl\n\n");
55  fflush(stdout);
56  }
57 }
int MPIrank
Definition: global.h:134
#define VERSION
Definition: global.h:29

Here is the caller graph for this function:

void printExecInfo ( )

This function prints the execution info.

Definition at line 62 of file io.c.

References endian, memPerProc, MPINodeSize, MPIrank, MPIsize, and OMPthreads.

63 {
64  if (MPIrank == 0) {
65  printf("Exec.info: %d ", MPIsize);
66  if (MPIsize > 1)
67  printf("processes ");
68  else
69  printf("process ");
70  printf("x %d OpenMP ", OMPthreads);
71  if (OMPthreads > 1)
72  printf("threads,\n");
73  else
74  printf("thread,\n");
75  printf(" %d proc./node, %dMB/proc.\n\n", MPINodeSize,
76  memPerProc);
77  printf("Sys.info: ");
78  if (endian)
79  printf("%s, little endian\n", CPUARCH);
80  else
81  printf("%s, big endian\n", CPUARCH);
82  printf("\n");
83  fflush(stdout);
84  }
85 }
int MPIrank
Definition: global.h:134
int memPerProc
Definition: global.h:141
int MPIsize
Definition: global.h:135
int OMPthreads
Definition: global.h:137
int MPINodeSize
Definition: global.h:140
int endian
Definition: global.h:157

Here is the caller graph for this function:

void printHelp ( )

Definition at line 87 of file io.c.

References desc, MPIrank, NPAR, params, and stopRun().

88 {
89  int i;
90  if (MPIrank == 0) {
91  printf
92  ("This help prints all Timothy parameters and their meaning.\n\n");
93  for (i = 0; i < NPAR; i++)
94  printf("%s: %s\n", params[i], desc[i]);
95  }
96  stopRun(999, NULL, __FILE__, __LINE__);
97 }
int MPIrank
Definition: global.h:134
char params[NPAR][64]
Definition: io.h:79
char desc[NPAR][512]
Definition: io.h:80
#define NPAR
Definition: io.h:28
void stopRun(int ierr, char *name, char *file, int line)
Definition: utils.c:72

Here is the call graph for this function:

Here is the caller graph for this function:

void printStepNum ( )

This function prints the actual step number and total number of cells in the system.

Definition at line 1215 of file io.c.

References MPIrank, nc, secondsPerStep, simTime, and step.

1216 {
1217  if (MPIrank == 0) {
1218  char ESC = 27;
1219  printf
1220  ("\n-------------------------------------------------------------------------\n");
1221  printf(" Step %8d,%15s%8.4f%20s%14" PRId64 " ", step, "Time step = ",
1222  secondsPerStep, "Number of cells = ", nc);
1223  fflush(stdout);
1224  printf
1225  ("\n-------------------------------------------------------------------------\n\n");
1226  printf(" Time: %8.4f\n\n", simTime);
1227  }
1228 }
float secondsPerStep
Definition: global.h:247
int MPIrank
Definition: global.h:134
int step
Definition: global.h:173
float simTime
Definition: global.h:175
#define nc
Definition: global.h:93

Here is the caller graph for this function:

void readParams ( int  argc,
char **  argv 
)

This function reads the parameter file.

Definition at line 600 of file io.c.

References addr, desc, DOUBLE, FNLEN, gfields, glucose, hydrogenIon, INT, logdir, LONG, MPIrank, nhs, NPAR, nx, ny, nz, outdir, oxygen, params, POWER_OF_TWO, readRstFile(), REAL, req, rst, set, stopRun(), STRING, tgs, and type.

601 {
602 
603  char paramFileName[FNLEN];
604  char buf[400], buf1[100], buf2[100], buf3[100];
605  FILE *fhandle;
606  int i;
607  int nr;
608 
609  strcpy(outdir, "results");
610 
611  if (strlen(argv[2]) >= FNLEN) {
612  fprintf(stderr, "\nERROR File name too long (>%d characters).\n",
613  FNLEN);
614  stopRun(0, NULL, __FILE__, __LINE__);
615  }
616  sprintf(paramFileName, "%s", argv[2]);
617 
618  if (MPIrank == 0)
619  printf("Reading parameters file: %s\n", paramFileName);
620 
621  fhandle = fopen(paramFileName, "r");
622  if (fhandle == NULL) {
623  if (MPIrank == 0)
624  fprintf(stderr, "\nERROR while opening parameter file.\n\n");
625  stopRun(0, NULL, __FILE__, __LINE__);
626  }
627  /* look for parameters in the file */
628  while (!feof(fhandle)) {
629 
630  char *ret;
631  ret = fgets(buf, 200, fhandle);
632 
633  if (sscanf(buf, "%s%s%s", buf1, buf2, buf3) < 2)
634  continue;
635 
636  if (feof(fhandle))
637  break;
638 
639  if (buf1[0] == '#')
640  continue;
641 
642  for (i = 0; i < NPAR; i++) {
643  if (strcmp(buf1, params[i]) == 0
644  && strcmp(params[i], "RSTFILE") == 0) {
645  strcpy((char *) addr[i], buf2);
646  set[i] = 1;
647  rst = 1;
648  }
649  if (strcmp(buf1, params[i]) == 0
650  && strcmp(params[i], "MAXCELLS") == 0) {
651  *((int64_t *) addr[i]) = atol(buf2);
652  }
653  }
654  }
655 
656  /* read restart file if given */
657  if (rst == 1)
658  readRstFile(argc, argv);
659 
660  /* rewind the file */
661  rewind(fhandle);
662 
663  /* convert some of the parameters to data */
664  while (!feof(fhandle)) {
665 
666  char *ret;
667  ret = fgets(buf, 200, fhandle);
668 
669  if (sscanf(buf, "%s%s%s", buf1, buf2, buf3) < 2)
670  continue;
671 
672  if (feof(fhandle))
673  break;
674 
675  if (buf1[0] == '#')
676  continue;
677 
678  for (i = 0; i < NPAR; i++) {
679  /* in the case of the restart simulation we do not allow to change the number of cells */
680  if (rst == 1 && strcmp(params[i], "NC") == 0
681  && strcmp(params[i], buf1) == 0) {
682  if (MPIrank == 0)
683  printf
684  ("NC value from the parameter file will be ignored. This is a restart simulation\n");
685  continue;
686  }
687  if (strcmp(buf1, params[i]) == 0) {
688  switch (type[i]) {
689  case REAL:
690  *((float *) addr[i]) = atof(buf2);
691 #ifdef DEBUG
692  if (MPIrank == 0) {
693  printf("READ %s = %f\n", params[i], *((float *) addr[i]));
694  fflush(stdout);
695  }
696 #endif
697  break;
698  case DOUBLE:
699  *((double *) addr[i]) = atof(buf2);
700 #ifdef DEBUG
701  if (MPIrank == 0) {
702  printf("READ %s = %f\n", params[i], *((double *) addr[i]));
703  fflush(stdout);
704  }
705 #endif
706  break;
707  case STRING:
708  strcpy((char *) addr[i], buf2);
709 #ifdef DEBUG
710  if (MPIrank == 0) {
711  printf("READ %s = %s\n", params[i], buf2);
712  fflush(stdout);
713  }
714 #endif
715  break;
716  case INT:
717  *((int *) addr[i]) = atoi(buf2);
718 #ifdef DEBUG
719  if (MPIrank == 0) {
720  printf("READ %s = %d\n", params[i], *((int *) addr[i]));
721  fflush(stdout);
722  }
723 #endif
724  break;
725  case LONG:
726  *((int64_t *) addr[i]) = atol(buf2);
727 #ifdef DEBUG
728  if (MPIrank == 0) {
729  printf("READ %s = %lld\n", params[i], *((int64_t *) addr[i]));
730  fflush(stdout);
731  }
732 #endif
733  break;
734  }
735  set[i] = 1;
736  break;
737  }
738  }
739  }
740 
741  /* check parameters for correctness */
742 
743  if (gfields == 1) {
744  for (i = 0; i < NPAR; i++) {
745  if (oxygen == 1) {
746  if (strcmp(params[i], "OXYGENDC") == 0 && set[i] == 0)
747  stopRun(114, "OXYGENDC", __FILE__, __LINE__);
748  if (strcmp(params[i], "OXYGENBC") == 0 && set[i] == 0)
749  stopRun(114, "OXYGENBC", __FILE__, __LINE__);
750  if (strcmp(params[i], "OXYGENICMEAN") == 0 && set[i] == 0)
751  stopRun(114, "OXYGENICMEAN", __FILE__, __LINE__);
752  if (strcmp(params[i], "OXYGENICVAR") == 0 && set[i] == 0)
753  stopRun(114, "OXYGENICVAR", __FILE__, __LINE__);
754  if (strcmp(params[i], "OXYGENCONS") == 0 && set[i] == 0)
755  stopRun(114, "OXYGENCONS", __FILE__, __LINE__);
756  if (strcmp(params[i], "OXYGENPROD") == 0 && set[i] == 0)
757  stopRun(114, "OXYGENPROD", __FILE__, __LINE__);
758  if (strcmp(params[i], "OXYGENLAMBDA") == 0 && set[i] == 0)
759  stopRun(114, "OXYGENLAMBDA", __FILE__, __LINE__);
760  if (strcmp(params[i], "OXYGENCL1") == 0 && set[i] == 0)
761  stopRun(114, "OXYGENCL1", __FILE__, __LINE__);
762  if (strcmp(params[i], "OXYGENCL2") == 0 && set[i] == 0)
763  stopRun(114, "OXYGENCL2", __FILE__, __LINE__);
764  }
765  if (glucose == 1) {
766  if (strcmp(params[i], "GLUCOSEDC") == 0 && set[i] == 0)
767  stopRun(114, "GLUCOSEDC", __FILE__, __LINE__);
768  if (strcmp(params[i], "GLUCOSEBC") == 0 && set[i] == 0)
769  stopRun(114, "GLUCOSEBC", __FILE__, __LINE__);
770  if (strcmp(params[i], "GLUCOSEICMEAN") == 0 && set[i] == 0)
771  stopRun(114, "GLUCOSEICMEAN", __FILE__, __LINE__);
772  if (strcmp(params[i], "GLUCOSEICVAR") == 0 && set[i] == 0)
773  stopRun(114, "GLUCOSEICVAR", __FILE__, __LINE__);
774  if (strcmp(params[i], "GLUCOSECONS") == 0 && set[i] == 0)
775  stopRun(114, "GLUCOSECONS", __FILE__, __LINE__);
776  if (strcmp(params[i], "GLUCOSEPROD") == 0 && set[i] == 0)
777  stopRun(114, "GLUCOSEPROD", __FILE__, __LINE__);
778  if (strcmp(params[i], "GLUCOSELAMBDA") == 0 && set[i] == 0)
779  stopRun(114, "GLUCOSELAMBDA", __FILE__, __LINE__);
780  if (strcmp(params[i], "GLUCOSECL1") == 0 && set[i] == 0)
781  stopRun(114, "GLUCOSECL1", __FILE__, __LINE__);
782  if (strcmp(params[i], "GLUCOSECL2") == 0 && set[i] == 0)
783  stopRun(114, "GLUCOSECL2", __FILE__, __LINE__);
784  }
785  if (hydrogenIon == 1) {
786  if (strcmp(params[i], "HYDROGENIONDC") == 0 && set[i] == 0)
787  stopRun(114, "HYDROGENIONDC", __FILE__, __LINE__);
788  if (strcmp(params[i], "HYDROGENIONBC") == 0 && set[i] == 0)
789  stopRun(114, "HYDROGENIONBC", __FILE__, __LINE__);
790  if (strcmp(params[i], "HYDROGENIONICMEAN") == 0 && set[i] == 0)
791  stopRun(114, "HYDROGENIONICMEAN", __FILE__, __LINE__);
792  if (strcmp(params[i], "HYDROGENIONICVAR") == 0 && set[i] == 0)
793  stopRun(114, "HYDROGENIONICVAR", __FILE__, __LINE__);
794  if (strcmp(params[i], "HYDROGENIONCONS") == 0 && set[i] == 0)
795  stopRun(114, "HYDROGENIONCONS", __FILE__, __LINE__);
796  if (strcmp(params[i], "HYDROGENIONPROD") == 0 && set[i] == 0)
797  stopRun(114, "HYDROGENIONPROD", __FILE__, __LINE__);
798  if (strcmp(params[i], "HYDROGENIONLAMBDA") == 0 && set[i] == 0)
799  stopRun(114, "HYDROGENIONLAMBDA", __FILE__, __LINE__);
800  if (strcmp(params[i], "HYDROGENIONCL1") == 0 && set[i] == 0)
801  stopRun(114, "HYDROGENIONCL1", __FILE__, __LINE__);
802  if (strcmp(params[i], "HYDROGENIONCL2") == 0 && set[i] == 0)
803  stopRun(114, "HYDROGENIONCL2", __FILE__, __LINE__);
804  }
805  }
806  }
807  if (!rst && nhs == -1 && tgs == 1) {
808  if (MPIrank == 0) {
809  fprintf(stderr,
810  "This is a tumor growth simulation. NHS is undefined. Define NHS in parameter file\n");
811  fflush(stdout);
812  }
813  stopRun(0, NULL, __FILE__, __LINE__);
814  }
815 
816  if (!rst) {
817  for (i = 0; i < NPAR; i++)
818  if (req[i] == 1 && set[i] == 0) {
819  if (MPIrank == 0) {
820  fprintf(stderr, "Missing parameter: %s - %s.\nProgram Abort.\n",
821  params[i], desc[i]);
822  fflush(stdout);
823  }
824  stopRun(0, NULL, __FILE__, __LINE__);
825  }
826  }
827 
828  if (maxSpeed <= 0.0 || maxSpeed >= 4.0)
829  stopRun(111, NULL, __FILE__, __LINE__);
830 
831  if (!POWER_OF_TWO(nx)) {
832  if (MPIrank == 0)
833  printf("SIZEX = %d. Must be a power of two.\n\n", nx);
834  stopRun(100, "X", __FILE__, __LINE__);
835  }
836  if (!POWER_OF_TWO(ny)) {
837  if (MPIrank == 0)
838  printf("SIZEY = %d. Must be a power of two.\n\n", ny);
839  stopRun(100, "Y", __FILE__, __LINE__);
840  }
841  if (!POWER_OF_TWO(nz)) {
842  if (MPIrank == 0)
843  printf("SIZEZ = %d. Must be a power of two.\n\n", nz);
844  stopRun(100, "Z", __FILE__, __LINE__);
845  }
846  if (MPIrank == 0)
847  printf("Box size: %dx%dx%d\n", nx, ny, nz);
848 
849  if (MPIrank == 0) {
850  struct stat s;
851  int err;
852  printf("Output directory: %s\n", outdir);
853 
854  err = stat(outdir, &s);
855  if (err == -1) {
856  printf("%s/ directory does not exist.\nCreating directory %s/.\n",
857  outdir, outdir);
858  mkdir(outdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
859  } else {
860  rmdir(outdir);
861  mkdir(outdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
862  }
863 
864  printf("Log directory: %s\n\n", logdir);
865 
866  err = stat(logdir, &s);
867  if (err == -1) {
868  printf("%s/ directory does not exist.\nCreating directory %s/.\n",
869  logdir, logdir);
870  mkdir(logdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
871  } else {
872  rmdir(logdir);
873  mkdir(logdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
874  }
875 
876  }
877 
878  fclose(fhandle);
879 }
#define FNLEN
Definition: io.h:42
int MPIrank
Definition: global.h:134
float s
Definition: global.h:186
char params[NPAR][64]
Definition: io.h:79
void readRstFile(int argc, char **argv)
Definition: io.c:1437
int tgs
Definition: global.h:220
int64_t nhs
Definition: global.h:218
int rst
Definition: global.h:211
#define POWER_OF_TWO(x)
Definition: global.h:31
int hydrogenIon
Definition: fields.h:36
char logdir[128]
Definition: global.h:167
#define STRING
Definition: io.h:30
int glucose
Definition: fields.h:35
int type[NPAR]
Definition: io.h:84
#define DOUBLE
Definition: io.h:34
#define LONG
Definition: io.h:32
int nz
Definition: global.h:164
#define INT
Definition: io.h:31
int req[NPAR]
Definition: io.h:82
void * addr[NPAR]
Definition: io.h:81
char desc[NPAR][512]
Definition: io.h:80
#define NPAR
Definition: io.h:28
#define REAL
Definition: io.h:29
int oxygen
Definition: fields.h:34
int ny
Definition: global.h:163
int nx
Definition: global.h:162
void stopRun(int ierr, char *name, char *file, int line)
Definition: utils.c:72
int set[NPAR]
Definition: io.h:83
char outdir[128]
Definition: global.h:166
int gfields
Definition: fields.h:33

Here is the call graph for this function:

Here is the caller graph for this function:

void readRstFile ( int  argc,
char **  argv 
)

This function reads the restart file.

Definition at line 1437 of file io.c.

References addrRst, cellData::age, cancer, cells, cellsAllocate(), CHAR, csize, cellData::death, decompositionInit(), cellData::density, DOUBLE, endian, g1, g2, cellData::gid, h, h2, h3, h4, cellData::halo, INT, INT64_T, ioDefineRstGlobalParams(), lcnc, lg0nc, lg1nc, lg2nc, cellData::lifetime, lmnc, lnc, lnnc, localCellCount, localID, lsnc, m, maxCells, maxCellsPerProc, MPIrank, MPIsize, nc, nRst, nsteps, numberOfCounts, one, cellData::phase, cellData::phasetime, randomStreamInit(), REAL, rstFileName, s, cellData::scalarField, cellData::size, sizeRst, stopRun(), swap_Nbyte(), tlnc, totalCellCount, cellData::tumor, typeRst, v, x, cellData::y, cellData::young, and cellData::z.

1438 {
1439 
1440  int i;
1441  MPI_File fh;
1442  MPI_Offset goffset;
1443  MPI_Offset offset;
1444  int len;
1445  int error;
1446  int64_t nk, nr;
1447  int64_t nprev = 0;
1448  int swap;
1449  int lcancer = 0;
1450 
1451  if (MPIrank == 0)
1452  printf("Reading restart file: %s\n", rstFileName);
1453 
1454  goffset = 0;
1455 
1456  /* open restart file */
1457  MPI_File_open(MPI_COMM_WORLD, rstFileName, MPI_MODE_RDONLY,
1458  MPI_INFO_NULL, &fh);
1459 
1460  /* each process defines global parameters to be read from restart file */
1462 
1463  goffset = 0;
1464 
1465  for (i = 0; i < nRst; i++) {
1466  switch (typeRst[i]) {
1467  case REAL:
1468  MPI_File_read(fh, addrRst[i], sizeRst[i], MPI_FLOAT,
1469  MPI_STATUS_IGNORE);
1470  goffset += sizeRst[i] * sizeof(float);
1471  break;
1472  case INT:
1473  MPI_File_read(fh, addrRst[i], sizeRst[i], MPI_INT,
1474  MPI_STATUS_IGNORE);
1475  goffset += sizeRst[i] * sizeof(int);
1476  break;
1477  case CHAR:
1478  MPI_File_read(fh, addrRst[i], sizeRst[i], MPI_CHAR,
1479  MPI_STATUS_IGNORE);
1480  goffset += sizeRst[i] * sizeof(char);
1481  break;
1482  case DOUBLE:
1483  MPI_File_read(fh, addrRst[i], sizeRst[i], MPI_DOUBLE,
1484  MPI_STATUS_IGNORE);
1485  goffset += sizeRst[i] * sizeof(double);
1486  break;
1487  case INT64_T:
1488  MPI_File_read(fh, addrRst[i], sizeRst[i], MPI_INT64_T,
1489  MPI_STATUS_IGNORE);
1490  goffset += sizeRst[i] * sizeof(int64_t);
1491  break;
1492  }
1493  }
1494 
1495  /* check endian */
1496  char *p = (char *) &one;
1497  swap = 0;
1498  if (p[0] == 1) {
1499  if (MPIrank == 0)
1500  printf("Restart file in little endian format.\n");
1501  if (endian == 0) {
1502  if (MPIrank == 0)
1503  printf("Conversion to big endian.\n");
1504  swap = 1;
1505  }
1506  } else {
1507  if (MPIrank == 0)
1508  printf("Restart file in big endian format.\n");
1509  if (endian == 1) {
1510  if (MPIrank == 0)
1511  printf("Conversion to little endian.\n");
1512  swap = 1;
1513  }
1514  }
1515 
1516  if (swap) {
1517  for (i = 0; i < nRst; i++) {
1518  switch (typeRst[i]) {
1519  case REAL:
1520  swap_Nbyte((char *) addrRst[i], sizeRst[i], sizeof(float));
1521  break;
1522  case INT:
1523  swap_Nbyte((char *) addrRst[i], sizeRst[i], sizeof(int));
1524  break;
1525  case CHAR:
1526  swap_Nbyte((char *) addrRst[i], sizeRst[i], sizeof(char));
1527  break;
1528  case DOUBLE:
1529  swap_Nbyte((char *) addrRst[i], sizeRst[i], sizeof(double));
1530  break;
1531  case INT64_T:
1532  swap_Nbyte((char *) addrRst[i], sizeRst[i], sizeof(int64_t));
1533  break;
1534  }
1535  }
1536  }
1537 
1538  /* set local number of cells to be read by each process */
1539  nk = nc / MPIsize;
1540  nr = nc % MPIsize;
1541  lnc = (MPIrank < nr ? nk + 1 : nk);
1542 
1543  if (nc > maxCells)
1544  stopRun(115, NULL, __FILE__, __LINE__);
1545 
1546  h = 2.5 * csize;
1547 
1548  h2 = h * h;
1549  h3 = h2 * h;
1550  h4 = h3 * h;
1551 
1552  cellsAllocate();
1553 
1554  /* gather number of cells from each process */
1555  MPI_Allgather(&lnc, 1, MPI_INT64_T, tlnc, 1, MPI_INT64_T,
1556  MPI_COMM_WORLD);
1557  for (i = 0; i < MPIrank; i++)
1558  nprev += tlnc[i];
1559 
1560  goffset += nprev * sizeof(struct cellData);
1561 
1562  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1563  /* read cells data */
1564  MPI_File_read(fh, cells, lnc * sizeof(struct cellData), MPI_BYTE,
1565  MPI_STATUS_IGNORE);
1566 
1567  if (swap) {
1568  for (i = 0; i < lnc; i++) {
1569  swap_Nbyte((char *) (&cells[i].gid), 1, sizeof(ZOLTAN_ID_TYPE));
1570  swap_Nbyte((char *) (&cells[i].lifetime), 1, sizeof(int));
1571  swap_Nbyte((char *) (&cells[i].phase), 1, sizeof(int));
1572  swap_Nbyte((char *) (&cells[i].phasetime), 1, sizeof(float));
1573  swap_Nbyte((char *) (&cells[i].g1), 1, sizeof(float));
1574  swap_Nbyte((char *) (&cells[i].s), 1, sizeof(float));
1575  swap_Nbyte((char *) (&cells[i].g2), 1, sizeof(float));
1576  swap_Nbyte((char *) (&cells[i].m), 1, sizeof(float));
1577  swap_Nbyte((char *) (&cells[i].x), 1, sizeof(double));
1578  swap_Nbyte((char *) (&cells[i].y), 1, sizeof(double));
1579  swap_Nbyte((char *) (&cells[i].z), 1, sizeof(double));
1580  swap_Nbyte((char *) (&cells[i].size), 1, sizeof(double));
1581  swap_Nbyte((char *) (&cells[i].h), 1, sizeof(double));
1582  swap_Nbyte((char *) (&cells[i].v), 1, sizeof(double));
1583  swap_Nbyte((char *) (&cells[i].density), 1, sizeof(double));
1584  swap_Nbyte((char *) (&cells[i].age), 1, sizeof(int));
1585  swap_Nbyte((char *) (&cells[i].death), 1, sizeof(int));
1586  swap_Nbyte((char *) (&cells[i].young), 1, sizeof(float));
1587  swap_Nbyte((char *) (&cells[i].tumor), 1, sizeof(unsigned char));
1588  swap_Nbyte((char *) (&cells[i].scalarField), 1, sizeof(double));
1589  swap_Nbyte((char *) (&cells[i].halo), 1, sizeof(int));
1590  }
1591  }
1592 
1593  lg0nc = 0;
1594  lg1nc = 0;
1595  lsnc = 0;
1596  lg2nc = 0;
1597  lmnc = 0;
1598  lcnc = 0;
1599  lnnc = 0;
1600  cancer = 0;
1601 
1602  for (i = 0; i < lnc; i++) {
1603 
1604  cells[i].gid =
1605  (unsigned long long int) MPIrank *(unsigned long long int)
1606  maxCellsPerProc + (unsigned long long int) i;
1607 
1608  switch (cells[i].phase) {
1609  case 0: /* G0 phase */
1610  lg0nc++;
1611  break;
1612  case 1: /* G1 phase */
1613  lg1nc++;
1614  break;
1615  case 2: /* S phase */
1616  lsnc++;
1617  break;
1618  case 3: /* G2 phase */
1619  lg2nc++;
1620  break;
1621  case 4: /* M phase */
1622  lmnc++;
1623  break;
1624  case 5: /* Necrotic cells */
1625  lnnc++;
1626  break;
1627  }
1628 
1629  if (cells[i].tumor == 1) {
1630  lcnc++;
1631  lcancer = 1;
1632  }
1633  }
1634 
1635  localID = lnc;
1636 
1637  randomStreamInit();
1638 
1640  MPI_INT64_T, MPI_SUM, MPI_COMM_WORLD);
1641  MPI_Allreduce(&lcancer, &cancer, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
1642 
1643  nsteps = 512; /* set by default in the case of the restart simulation */
1644 
1645  /* close file */
1646  MPI_File_close(&fh);
1647 
1648  MPI_Barrier(MPI_COMM_WORLD);
1649  decompositionInit(argc, argv, MPI_COMM_WORLD);
1650 
1651 }
double density
Definition: global.h:75
int64_t * tlnc
Definition: global.h:111
#define CHAR
Definition: io.h:35
int MPIrank
Definition: global.h:134
#define lnc
Definition: global.h:102
float s
Definition: global.h:186
HYPRE_SStructVector x
Definition: tempf.c:41
float g1
Definition: global.h:185
int64_t localID
Definition: global.h:240
float young
Definition: global.h:67
double scalarField
Definition: global.h:76
#define lnnc
Definition: global.h:109
unsigned char tumor
Definition: global.h:77
int MPIsize
Definition: global.h:135
int nsteps
Definition: global.h:169
#define numberOfCounts
Definition: global.h:88
double h4
Definition: global.h:203
int cancer
Definition: global.h:205
float phasetime
Definition: global.h:62
double size
Definition: global.h:72
double h3
Definition: global.h:202
ZOLTAN_ID_TYPE gid
Definition: global.h:68
void * addrRst[NRSTPARAMS]
Definition: io.h:53
void decompositionInit(int argc, char **argv, MPI_Comm Comm)
Definition: domdec.c:191
int death
Definition: global.h:60
float m
Definition: global.h:188
#define lcnc
Definition: global.h:108
void ioDefineRstGlobalParams()
Definition: io.c:1235
char rstFileName[128]
Definition: global.h:165
int64_t totalCellCount[numberOfCounts]
Definition: global.h:91
int64_t maxCells
Definition: global.h:87
#define lg0nc
Definition: global.h:103
int maxCellsPerProc
Definition: global.h:132
void randomStreamInit()
Definition: random.c:35
double csize
Definition: global.h:197
#define lsnc
Definition: global.h:105
int one
Definition: io.h:77
int phase
Definition: global.h:58
struct cellData * cells
Definition: global.h:82
float g2
Definition: global.h:187
#define INT64_T
Definition: io.h:33
float v
Definition: global.h:189
#define DOUBLE
Definition: io.h:34
#define INT
Definition: io.h:31
double z
Definition: global.h:71
int age
Definition: global.h:59
int nRst
Definition: io.h:54
int lifetime
Definition: global.h:57
int sizeRst[NRSTPARAMS]
Definition: io.h:52
#define lg1nc
Definition: global.h:104
double h2
Definition: global.h:201
double y
Definition: global.h:70
int64_t localCellCount[numberOfCounts]
Definition: global.h:90
#define nc
Definition: global.h:93
int endian
Definition: global.h:157
void cellsAllocate()
Definition: cells.c:66
#define REAL
Definition: io.h:29
void swap_Nbyte(char *data, int n, int m)
Definition: utils.c:57
int typeRst[NRSTPARAMS]
Definition: io.h:51
int halo
Definition: global.h:61
#define lg2nc
Definition: global.h:106
void stopRun(int ierr, char *name, char *file, int line)
Definition: utils.c:72
#define lmnc
Definition: global.h:107
double h
Definition: global.h:200

Here is the call graph for this function:

Here is the caller graph for this function:

void revertStdOut ( )

This function brings back the stdout.

Definition at line 1803 of file io.c.

References fdSave.

1804 {
1805  fflush(stdout);
1806  dup2(fdSave, fileno(stdout));
1807  close(fdSave);
1808 }
int fdSave
Definition: io.h:86

Here is the caller graph for this function:

void saveRstFile ( )

This function saves a restart file of the simulation.

Definition at line 1358 of file io.c.

References addrRst, cells, CHAR, DOUBLE, INT, INT64_T, ioDefineRstGlobalParams(), lnc, MPIrank, nRst, outdir, REAL, sizeRst, step, tlnc, and typeRst.

1359 {
1360 
1361  int i, j, k;
1362  MPI_File fh;
1363  int64_t nprev = 0;
1364  char fstname[256];
1365  char header[256];
1366  MPI_Offset goffset;
1367  MPI_Offset offset;
1368 
1369  sprintf(fstname, "%s/step%08d.rst", outdir, step);
1370 
1371  goffset = 0;
1372  MPI_File_open(MPI_COMM_WORLD, fstname, MPI_MODE_WRONLY | MPI_MODE_CREATE,
1373  MPI_INFO_NULL, &fh);
1374  /* truncate the file */
1375  MPI_File_set_size(fh, 0);
1376 
1377  /* gather number of cells from each process */
1378  MPI_Allgather(&lnc, 1, MPI_INT64_T, tlnc, 1, MPI_INT64_T,
1379  MPI_COMM_WORLD);
1380  for (i = 0; i < MPIrank; i++)
1381  nprev += tlnc[i];
1382 
1383  /* write out the simulation global variables and parameters (single process) */
1384  if (MPIrank == 0) {
1385 
1387  offset = 0;
1388 
1389  /* write out to rst file */
1390  for (i = 0; i < nRst; i++) {
1391  switch (typeRst[i]) {
1392  case REAL:
1393  MPI_File_write(fh, addrRst[i], sizeRst[i], MPI_FLOAT,
1394  MPI_STATUS_IGNORE);
1395  offset += sizeRst[i] * sizeof(float);
1396  break;
1397  case INT:
1398  MPI_File_write(fh, addrRst[i], sizeRst[i], MPI_INT,
1399  MPI_STATUS_IGNORE);
1400  offset += sizeRst[i] * sizeof(int);
1401  break;
1402  case CHAR:
1403  MPI_File_write(fh, addrRst[i], sizeRst[i], MPI_CHAR,
1404  MPI_STATUS_IGNORE);
1405  offset += sizeRst[i] * sizeof(char);
1406  break;
1407  case DOUBLE:
1408  MPI_File_write(fh, addrRst[i], sizeRst[i], MPI_DOUBLE,
1409  MPI_STATUS_IGNORE);
1410  offset += sizeRst[i] * sizeof(double);
1411  break;
1412  case INT64_T:
1413  MPI_File_write(fh, addrRst[i], sizeRst[i], MPI_INT64_T,
1414  MPI_STATUS_IGNORE);
1415  offset += sizeRst[i] * sizeof(int64_t);
1416  break;
1417  }
1418  }
1419  }
1420 
1421  /* distribute information on global offset in the rst file */
1422  MPI_Bcast(&offset, 1, MPI_OFFSET, 0, MPI_COMM_WORLD);
1423  /* move the global file offset */
1424  goffset = offset + nprev * sizeof(struct cellData);
1425 
1426  MPI_File_seek(fh, goffset, MPI_SEEK_SET);
1427  /* write out cells' data */
1428  MPI_File_write(fh, cells, lnc * sizeof(struct cellData), MPI_BYTE,
1429  MPI_STATUS_IGNORE);
1430  /* close file */
1431  MPI_File_close(&fh);
1432 }
int64_t * tlnc
Definition: global.h:111
#define CHAR
Definition: io.h:35
int MPIrank
Definition: global.h:134
#define lnc
Definition: global.h:102
void * addrRst[NRSTPARAMS]
Definition: io.h:53
void ioDefineRstGlobalParams()
Definition: io.c:1235
int step
Definition: global.h:173
struct cellData * cells
Definition: global.h:82
#define INT64_T
Definition: io.h:33
#define DOUBLE
Definition: io.h:34
#define INT
Definition: io.h:31
int nRst
Definition: io.h:54
int sizeRst[NRSTPARAMS]
Definition: io.h:52
#define REAL
Definition: io.h:29
int typeRst[NRSTPARAMS]
Definition: io.h:51
char outdir[128]
Definition: global.h:166

Here is the call graph for this function:

Here is the caller graph for this function:

void switchStdOut ( const char *  newStream)

This function redirects stdout to a given file.

Definition at line 1790 of file io.c.

References fdNew, and fdSave.

1791 {
1792  fflush(stdout);
1793  dup2(fileno(stdout), fdSave);
1794  fflush(stdout);
1795  fdNew = open(newStream, O_WRONLY | O_CREAT | O_TRUNC, 0644);
1796  dup2(fdNew, fileno(stdout));
1797  close(fdNew);
1798 }
int fdNew
Definition: io.h:87
int fdSave
Definition: io.h:86

Here is the caller graph for this function: