OSCR

Diversity in emergent cell locomotion from the coupling cytosolic and cortical Marangoni flows with reaction-diffusion dynamics.

Code ↔ Paper

The paper beside its authors' code: matches between them have not been computed for this paper yet.

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

C · 1,327 lines · 56 KB · MIT

  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Project: CellRDA-LS (Mechanochemical cell motility simulations)
  4. * File: main.c
  5. * Brief: Program entry point; parses JSON parameters and runs batch simulations.
  6. *
  7. * Author: Blaž Ivšić
  8. * Contact: [email hidden]
  9. * Copyright: (c) 2023–2025 Blaž Ivšić
  10. *
  11. * License: MIT — see LICENSE in the repository root.
  12. *
  13. * How to cite:
  14. * Article: Diversity in emergent cell locomotion from the coupling cytosolic and cortical Marangoni flows with reaction–diffusion dynamics, <Journal or preprint>, <Year>. DOI: <paper DOI>
  15. * Software: Cite this release via CITATION.cff (and Zenodo DOI if minted).
  16. *
  17. * Reproducibility:
  18. * - Language/Std: C11
  19. * - Compiler: gcc >= 12 and/or clang >= 16 (tested)
  20. * - Dependencies: NetCDF >= 4.9 (with HDF5), cJSON (vendored), -lm
  21. * - Optional: OpenMP, AVX2 (guard with feature flags)
  22. * - Inputs: SimulationParameters_X.json, InitialConditions_X.nc
  23. * - Outputs: <files>.nc/.bin/.txt (see README)
  24. * - Determinism: set Seed=<int> to reproduce stochastic runs
  25. *
  26. * Version: v1.0.0 | Commit: <git short SHA> | Date: <YYYY-MM-DD>
  27. * Build (ex): gcc -O3 -std=c11 -fopenmp -Ithird_party/cJSON \
  28. * src/*.c third_party/cJSON/cJSON.c \
  29. * -lnetcdf -lhdf5 -lm -o program
  30. */
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <netcdf.h>
  34. #include <string.h>
  35. #include <math.h>
  36. #include <time.h>
  37. #include "cJSON.h"
  38. #include "simulation.h"
  39. #define chcJSONitem(item, name) \
  40. if ((item) == NULL) { \
  41. printf("Error: Missing or invalid value for key: %s\n", name); \
  42. return 11; \
  43. }
  44. #define ALLOC_ARRAY(name, type, rows, cols) \
  45. type *name = (type *)calloc((rows) * (cols), sizeof(type)); \
  46. if (name == NULL) \
  47. { \
  48. printf("Memory allocation failed for " #name "\n"); \
  49. \
  50. exit(EXIT_FAILURE); \
  51. }
  52. char *readJSON(const char *filename)
  53. {
  54. //Function for loading JSON file
  55. FILE *file = fopen(filename, "r");
  56. if(!file)
  57. {
  58. printf("Error: Failed to open the file\n");
  59. return NULL;
  60. }
  61. // Determining length of the file
  62. fseek(file, 0, SEEK_END);
  63. long length = ftell(file);
  64. fseek(file, 0, SEEK_SET);
  65. // Memory allocation
  66. char *content = (char *)malloc(length + 1); // While this makes the cast explicit, it's not required in C, and omitting the cast is typically the preferred approach in modern C programming.
  67. // ChatGPT: This was common in older versions of C or when using C++ compilers, which are stricter about type conversions. However, in modern C compilers, the cast is generally not necessary because malloc returns a void *, which can be assigned to any pointer type without a cast.
  68. fread(content, 1, length, file);
  69. fclose(file);
  70. content[length] = '\0';
  71. return content;
  72. }
  73. cJSON* loadJSON(const char* filename)
  74. {
  75. // Function for loading the JSON data
  76. char *JSONcontent = readJSON(filename);
  77. if (!JSONcontent)
  78. {
  79. printf("Error: Failed to read the file\n");
  80. return NULL;
  81. }
  82. // Parsing file content
  83. cJSON *json = cJSON_Parse(JSONcontent);
  84. free(JSONcontent);
  85. if (json == NULL) {
  86. printf("Error: Failed to parse JSON\n");
  87. return NULL;
  88. }
  89. return json;
  90. }
  91. int validateArray(cJSON *array, int expectedSize, const char *keyName) {
  92. if (array == NULL || array->type != cJSON_Array || cJSON_GetArraySize(array) != expectedSize) {
  93. printf("Error: Missing or invalid array for key: %s (expected size: %d)\n", keyName, expectedSize);
  94. return 11; // Error code for missing or invalid array
  95. }
  96. for (int i = 0; i < expectedSize; i++) {
  97. cJSON *item = cJSON_GetArrayItem(array, i);
  98. if (item == NULL || item->type != cJSON_Number) {
  99. printf("Error: Invalid value at index %d in array for key: %s\n", i, keyName);
  100. return 12; // Error code for invalid array value
  101. }
  102. }
  103. return 0; // Validation successful
  104. }
  105. int validateParameters(cJSON *json) {
  106. // Function for checking JSON keys
  107. // File parameters
  108. cJSON *FileParameters = cJSON_GetObjectItem(json, "FileParameters");
  109. chcJSONitem(FileParameters, "FileParameters");
  110. chcJSONitem(cJSON_GetObjectItem(FileParameters, "InitialFile"), "InitialFile");
  111. chcJSONitem(cJSON_GetObjectItem(FileParameters, "SaveFile"), "SaveFile");
  112. chcJSONitem(cJSON_GetObjectItem(FileParameters, "TracerFolder"), "TracerFolder");
  113. chcJSONitem(cJSON_GetObjectItem(FileParameters, "TracerPrefix"), "TracerPrefix");
  114. // Simulation parameters
  115. cJSON *SimulationParameters = cJSON_GetObjectItem(json, "SimulationParameters");
  116. chcJSONitem(SimulationParameters, "SimulationParameters");
  117. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "Cluster"), "Cluster");
  118. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "Seed"), "Seed");
  119. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "NumberOfTracersBulk"), "NumberOfTracersBulk");
  120. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "NumberOfTracersOut"), "NumberOfTracersOut");
  121. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "NumberOfSaveCycles"), "NumberOfSaveCycles");
  122. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "NumberOfDoubleStep"), "NumberOfDoubleStep");
  123. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "NumberOfPointsX"), "NumberOfPointsX");
  124. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "NumberOfPointsY"), "NumberOfPointsY");
  125. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "GridSpacingX"), "GridSpacingX");
  126. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "GridSpacingY"), "GridSpacingY");
  127. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "TimeStepSpacing"), "TimeStepSpacing");
  128. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "CutOff"), "CutOff");
  129. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "PotentialCutOffBulk"), "PotentialCutOffBulk");
  130. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "PotentialCutOffSurface"), "PotentialCutOffSurface");
  131. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "MaxIterations"), "MaxIterations");
  132. chcJSONitem(cJSON_GetObjectItem(SimulationParameters, "PressTol"), "PressTol");
  133. // Model Parameters
  134. cJSON *ModelParameters = cJSON_GetObjectItem(json, "ModelParameters");
  135. chcJSONitem(ModelParameters, "ModelParameters");
  136. chcJSONitem(cJSON_GetObjectItem(ModelParameters, "Epsilon"), "Epsilon");
  137. chcJSONitem(cJSON_GetObjectItem(ModelParameters, "Viscosity"), "Viscosity");
  138. chcJSONitem(cJSON_GetObjectItem(ModelParameters, "Gamma"), "Gamma");
  139. chcJSONitem(cJSON_GetObjectItem(ModelParameters, "SurfaceTension"), "SurfaceTension");
  140. chcJSONitem(cJSON_GetObjectItem(ModelParameters, "SurfaceTensionCoefficient"), "SurfaceTensionCoefficient");
  141. chcJSONitem(cJSON_GetObjectItem(ModelParameters, "SubstrateForceCoefficient"), "SubstrateForceCoefficient");
  142. chcJSONitem(cJSON_GetObjectItem(ModelParameters, "Dissipation"), "Dissipation");
  143. chcJSONitem(cJSON_GetObjectItem(ModelParameters, "AreaConstraint"), "AreaConstraint");
  144. chcJSONitem(cJSON_GetObjectItem(ModelParameters, "Rac1Max"), "Rac1Max");
  145. cJSON *DiffusionArray = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "Diffusion"), "value");
  146. cJSON *ReactionsArray = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "Reactions"), "value");
  147. int chcDiff = validateArray(DiffusionArray, 4, "Diffusion");
  148. if (chcDiff != 0) {return chcDiff;}
  149. int chcReac = validateArray(ReactionsArray, 5, "Reactions");
  150. if (chcReac != 0) {return chcReac;}
  151. return 0; // Validation successful
  152. }
  153. int loadParameters(cJSON *json,
  154. char *InitialConditionsFile, char *SaveFileName, char *TracerFolder, char * TracerPrefix,
  155. int *Seed, int *Cluster, int *nTracersB, int *nTracersO, int *NumberOfSaveCycles, int *NumberOfDoubleStep,
  156. size_t *I, size_t *J,
  157. double *dx, double *dy, double *dt, double *CO, double *vBB, double *vBS, int *MaxIter, double *PTol,
  158. double *eps, double *nu, double *cG, double *Si0, double *kSi, double *kC, double *Beta, double *Alpha,
  159. double *DRD, double *DRT, double *DG, double *DGc,
  160. double *k1, double *k2, double *k3, double *k11, double *k12, double *R_Max)
  161. {
  162. // Function for loading parameters from .json content
  163. // The Parameters are split into groups depending on the type of data
  164. // If new parameters are added the type of parameter to be loaded needs to be specified accordingly even dough the type is specified in .json file.
  165. // Checking the compatibility of JOSN file
  166. int chcVAL = validateParameters(json);
  167. if (chcVAL != 0) {return chcVAL;}
  168. // Loading JSON fields
  169. cJSON *FileParameters = cJSON_GetObjectItem(json, "FileParameters");
  170. cJSON *SimulationParameters = cJSON_GetObjectItem(json, "SimulationParameters");
  171. cJSON *ModelParameters = cJSON_GetObjectItem(json, "ModelParameters");
  172. // File parameters
  173. strcpy(InitialConditionsFile, cJSON_GetObjectItem(cJSON_GetObjectItem(FileParameters, "InitialFile"), "value")->valuestring);
  174. strcpy(SaveFileName, cJSON_GetObjectItem(cJSON_GetObjectItem(FileParameters, "SaveFile"), "value")->valuestring);
  175. strcpy(TracerFolder, cJSON_GetObjectItem(cJSON_GetObjectItem(FileParameters, "TracerFolder"), "value")->valuestring);
  176. strcpy(TracerPrefix, cJSON_GetObjectItem(cJSON_GetObjectItem(FileParameters, "TracerPrefix"), "value")->valuestring);
  177. // Simulation parameters
  178. *Cluster = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "Cluster"), "value")->valueint;
  179. *Seed = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "Seed"), "value")->valueint;
  180. *nTracersB = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "NumberOfTracersBulk"), "value")->valueint;
  181. *nTracersO = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "NumberOfTracersOut"), "value")->valueint;
  182. *NumberOfSaveCycles = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "NumberOfSaveCycles"), "value")->valueint;
  183. *NumberOfDoubleStep = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "NumberOfDoubleStep"), "value")->valueint;
  184. *I = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "NumberOfPointsX"), "value")->valueint;
  185. *J = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "NumberOfPointsY"), "value")->valueint;
  186. *dx = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "GridSpacingX"), "value")->valuedouble;
  187. *dy = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "GridSpacingY"), "value")->valuedouble;
  188. *dt = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "TimeStepSpacing"), "value")->valuedouble;
  189. *CO = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "CutOff"), "value")->valuedouble;
  190. *vBB = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "PotentialCutOffBulk"), "value")->valuedouble;
  191. *vBS = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "PotentialCutOffSurface"), "value")->valuedouble;
  192. *MaxIter = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "MaxIterations"), "value")->valueint;
  193. *PTol = cJSON_GetObjectItem(cJSON_GetObjectItem(SimulationParameters, "PressTol"), "value")->valuedouble;
  194. // Model Parameters
  195. *eps = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "Epsilon"), "value")->valuedouble;
  196. *nu = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "Viscosity"), "value")->valuedouble;
  197. *cG = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "Gamma"), "value")->valuedouble;
  198. *Si0 = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "SurfaceTension"), "value")->valuedouble;
  199. *kSi = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "SurfaceTensionCoefficient"), "value")->valuedouble;
  200. *kC = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "SubstrateForceCoefficient"), "value")->valuedouble;
  201. *Beta = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "Dissipation"), "value")->valuedouble;
  202. *Alpha = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "AreaConstraint"), "value")->valuedouble;
  203. cJSON *diffusion = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "Diffusion"), "value");
  204. double Diffusion[4];
  205. for (int i = 0; i < 4; i++) {
  206. Diffusion[i] = cJSON_GetArrayItem(diffusion, i)->valuedouble;
  207. }
  208. *DRD = Diffusion[0];
  209. *DRT = Diffusion[1];
  210. *DG = Diffusion[2];
  211. *DGc = Diffusion[3];
  212. cJSON *reactions = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "Reactions"), "value");
  213. double Reactions[5];
  214. for (int i = 0; i < 5; i++) {
  215. Reactions[i] = cJSON_GetArrayItem(reactions, i)->valuedouble;
  216. }
  217. *k1 = Reactions[0];
  218. *k2 = Reactions[1];
  219. *k3 = Reactions[2];
  220. *k11 = Reactions[3];
  221. *k12 = Reactions[4];
  222. *R_Max = cJSON_GetObjectItem(cJSON_GetObjectItem(ModelParameters, "Rac1Max"), "value")->valuedouble;
  223. return 0;
  224. }
  225. int checkSolutionFile(const char* SaveFileName)
  226. {
  227. // Function for checking if the solution exists and where has simulation terminated.
  228. int ncID, timeVarID;
  229. int RetVAL;
  230. size_t Len;
  231. // Try to open the solutions file
  232. RetVAL = nc_open(SaveFileName, NC_NOWRITE, &ncID);
  233. if (RetVAL == 2)
  234. {
  235. return -1; //The code that signals there is no Solution file
  236. }
  237. else if (RetVAL != NC_NOERR)
  238. {
  239. printf("Error opening file: %s\n", nc_strerror(RetVAL));
  240. return -30;
  241. }
  242. // Get the ID of the "Time" variable
  243. if (nc_inq_varid(ncID, "Time", &timeVarID) != NC_NOERR)
  244. {
  245. nc_close(ncID);
  246. return -31; // Time variable not found
  247. }
  248. // Get the length of the "Time" variable
  249. RetVAL = nc_inq_dimlen(ncID, timeVarID, &Len);
  250. if (RetVAL != NC_NOERR)
  251. {
  252. printf("Error: Time dimension not found in the file. %s\n", nc_strerror(RetVAL));
  253. nc_close(ncID);
  254. return -32; // Can't fetch the length of "Time" variable
  255. }
  256. // Allocate memory to hold the "Time" values
  257. double *TimeValues = (double *)malloc(Len * sizeof(double));
  258. if (TimeValues == NULL)
  259. {
  260. nc_close(ncID);
  261. return -98;
  262. }
  263. // Read the "Time" values
  264. if (nc_get_var_double(ncID, timeVarID, TimeValues) != NC_NOERR)
  265. {
  266. printf("Error reading Time vector: %s\n", nc_strerror(RetVAL));
  267. free(TimeValues);
  268. nc_close(ncID);
  269. return -33;
  270. }
  271. // Find the last index where the value is below the threshold
  272. int LastIndex = -1;
  273. for (size_t i = 0; i < Len; i++)
  274. {
  275. if (TimeValues[i] < 1e10)
  276. {
  277. LastIndex = i;
  278. }
  279. else
  280. {
  281. break;
  282. }
  283. }
  284. // Clean up
  285. free(TimeValues);
  286. nc_close(ncID);
  287. return LastIndex;
  288. }
  289. int readICNetCDF(const char *InitialConditionsFile)
  290. {
  291. // Function for opening NetCDF File
  292. int ncID, RetVAL;
  293. // Open the NetCDF file and assign the result to RetVAL
  294. RetVAL = nc_open(InitialConditionsFile, NC_NOWRITE, &ncID);
  295. if (RetVAL != NC_NOERR) // Check if an error occurred
  296. {
  297. printf("Error opening file: %s\n", nc_strerror(RetVAL));
  298. return -30;
  299. }
  300. // Return the NetCDF ID if successful
  301. return ncID;
  302. }
  303. int loadICNetCDF(int ncID, int *varID_Vx, int *varID_Vy, int *varID_Phi, int *varID_C_RD, int *varID_C_RT, int *varID_C_G, int *varID_C_Gc, int *varID_X, int *varID_Y)
  304. {
  305. // Function for loading NetCDF files for initial condition.
  306. // This function will return variable IDs and check if the needed initial condition matrices are included in the file.
  307. int RetVAL;
  308. RetVAL = nc_inq_varid(ncID, "Vx", varID_Vx);
  309. if (RetVAL != NC_NOERR)
  310. {
  311. printf("Error: Vx matrix not found in the file. %s\n", nc_strerror(RetVAL));
  312. return -31;
  313. }
  314. RetVAL = nc_inq_varid(ncID, "Vy", varID_Vy);
  315. if (RetVAL != NC_NOERR)
  316. {
  317. printf("Error: Vy matrix not found in the file. %s\n", nc_strerror(RetVAL));
  318. return -31;
  319. }
  320. RetVAL = nc_inq_varid(ncID, "Phi", varID_Phi);
  321. if (RetVAL != NC_NOERR)
  322. {
  323. printf("Error: Phi matrix not found in the file. %s\n", nc_strerror(RetVAL));
  324. return -31;
  325. }
  326. RetVAL = nc_inq_varid(ncID, "RD", varID_C_RD);
  327. if (RetVAL != NC_NOERR)
  328. {
  329. printf("Error: C_RD matrix not found in the file. %s\n", nc_strerror(RetVAL));
  330. return -31;
  331. }
  332. RetVAL = nc_inq_varid(ncID, "RT", varID_C_RT);
  333. if (RetVAL != NC_NOERR)
  334. {
  335. printf("Error: C_RT matrix not found in the file. %s\n", nc_strerror(RetVAL));
  336. return -31;
  337. }
  338. RetVAL = nc_inq_varid(ncID, "G", varID_C_G);
  339. if (RetVAL != NC_NOERR)
  340. {
  341. printf("Error: C_G matrix not found in the file. %s\n", nc_strerror(RetVAL));
  342. return -31;
  343. }
  344. RetVAL = nc_inq_varid(ncID, "Gc", varID_C_Gc);
  345. if (RetVAL != NC_NOERR)
  346. {
  347. printf("Error: C_Gc matrix not found in the file. %s\n", nc_strerror(RetVAL));
  348. return -31;
  349. }
  350. RetVAL = nc_inq_varid(ncID, "X", varID_X);
  351. if (RetVAL != NC_NOERR)
  352. {
  353. printf("Error: X vector not found in the file. %s\n", nc_strerror(RetVAL));
  354. return -31;
  355. }
  356. RetVAL = nc_inq_varid(ncID, "Y", varID_Y);
  357. if (RetVAL != NC_NOERR)
  358. {
  359. printf("Error: Y vector not found in the file. %s\n", nc_strerror(RetVAL));
  360. return -31;
  361. }
  362. return 0;
  363. }
  364. int checkICDimensions(int ncID, size_t I, size_t J)
  365. {
  366. // This function checks if the dimensions of initial conditions and ones specified in the parameters .json file are compatible
  367. int RetVAL;
  368. size_t FileI, FileJ;
  369. int xDim, yDim;
  370. RetVAL = nc_inq_dimid(ncID, "xDim", &xDim);
  371. if (RetVAL != NC_NOERR)
  372. {
  373. printf("Error: xDim dimenison not found in the file. %s\n", nc_strerror(RetVAL));
  374. return -32;
  375. }
  376. RetVAL = nc_inq_dimid(ncID, "yDim", &yDim);
  377. if (RetVAL != NC_NOERR)
  378. {
  379. printf("Error: yDim dimension not found in the file. %s\n", nc_strerror(RetVAL));
  380. return -32;
  381. }
  382. RetVAL = nc_inq_dimlen(ncID, xDim, &FileI);
  383. if (RetVAL != NC_NOERR)
  384. {
  385. printf("Error: Failed to obtain xDim %s\n", nc_strerror(RetVAL));
  386. return -32;
  387. }
  388. RetVAL = nc_inq_dimlen(ncID, yDim, &FileJ);
  389. if (RetVAL != NC_NOERR)
  390. {
  391. printf("Error: Failed to obtain yDim %s\n", nc_strerror(RetVAL));
  392. return -32;
  393. }
  394. if(I != FileI || J != FileJ)
  395. {
  396. printf("Error: Initial Conditions File dimensions not compatible with Parameters File.\n");
  397. return -97;
  398. }
  399. return 0;
  400. }
  401. int loadInitialConditions(const char *InitialConditionsFile, size_t I, size_t J,
  402. double *Vx, double *Vy, double *Phi, double *C_RD, double *C_RT, double *C_G, double *C_Gc,
  403. double *X, double *Y)
  404. {
  405. // Function for loading initial conditions.
  406. int varID_Vx, varID_Vy, varID_Phi, varID_C_RD, varID_C_RT, varID_C_G, varID_C_Gc, varID_X, varID_Y;
  407. int ncID, RetVAL;
  408. // Retrieving initial conditions file ID
  409. ncID = readICNetCDF(InitialConditionsFile);
  410. if (ncID == -30) { return -30; }
  411. // Retrieving variable IDs from initial conditions file
  412. RetVAL = loadICNetCDF(ncID, &varID_Vx, &varID_Vy, &varID_Phi, &varID_C_RD, &varID_C_RT, &varID_C_G, &varID_C_Gc, &varID_X, &varID_Y);
  413. if (RetVAL != 0) { nc_close(ncID); return RetVAL;}
  414. // Checking if dimensions in initial conditions file match those in parameters file
  415. RetVAL = checkICDimensions(ncID,I,J);
  416. if (RetVAL != 0) { nc_close(ncID); return RetVAL; }
  417. // Loading initial conditions matrices
  418. RetVAL = nc_get_var_double(ncID, varID_Vx, Vx);
  419. if (RetVAL != NC_NOERR)
  420. {
  421. printf("Error reading Vx matrix: %s\n", nc_strerror(RetVAL));
  422. nc_close(ncID);
  423. return -33;
  424. }
  425. RetVAL = nc_get_var_double(ncID, varID_Vy, Vy);
  426. if (RetVAL != NC_NOERR)
  427. {
  428. printf("Error reading Vy matrix: %s\n", nc_strerror(RetVAL));
  429. nc_close(ncID);
  430. return -33;
  431. }
  432. RetVAL = nc_get_var_double(ncID, varID_Phi, Phi);
  433. if (RetVAL != NC_NOERR)
  434. {
  435. printf("Error reading Phi matrix: %s\n", nc_strerror(RetVAL));
  436. nc_close(ncID);
  437. return -33;
  438. }
  439. RetVAL = nc_get_var_double(ncID, varID_C_RD, C_RD);
  440. if (RetVAL != NC_NOERR)
  441. {
  442. printf("Error reading C_RD matrix: %s\n", nc_strerror(RetVAL));
  443. nc_close(ncID);
  444. return -33;
  445. }
  446. RetVAL = nc_get_var_double(ncID, varID_C_RT, C_RT);
  447. if (RetVAL != NC_NOERR)
  448. {
  449. printf("Error reading C_RT matrix: %s\n", nc_strerror(RetVAL));
  450. nc_close(ncID);
  451. return -33;
  452. }
  453. RetVAL = nc_get_var_double(ncID, varID_C_G, C_G);
  454. if (RetVAL != NC_NOERR)
  455. {
  456. printf("Error reading C_G matrix: %s\n", nc_strerror(RetVAL));
  457. nc_close(ncID);
  458. return -33;
  459. }
  460. RetVAL = nc_get_var_double(ncID, varID_C_Gc, C_Gc);
  461. if (RetVAL != NC_NOERR)
  462. {
  463. printf("Error reading C_Gc matrix: %s\n", nc_strerror(RetVAL));
  464. nc_close(ncID);
  465. return -33;
  466. }
  467. RetVAL = nc_get_var_double(ncID, varID_X, X);
  468. if (RetVAL != NC_NOERR)
  469. {
  470. printf("Error reading X vector: %s\n", nc_strerror(RetVAL));
  471. nc_close(ncID);
  472. return -33;
  473. }
  474. RetVAL = nc_get_var_double(ncID, varID_Y, Y);
  475. if (RetVAL != NC_NOERR)
  476. {
  477. printf("Error reading Y vector: %s\n", nc_strerror(RetVAL));
  478. nc_close(ncID);
  479. return -33;
  480. }
  481. // Closing the file
  482. RetVAL = nc_close(ncID);
  483. if (RetVAL != NC_NOERR)
  484. {
  485. printf("Error closing file: %s\n", nc_strerror(RetVAL));
  486. return -38;
  487. }
  488. return 0;
  489. }
  490. int loadSolutionNetCDF(int ncID, int *varID_Vx, int *varID_Vy, int *varID_Phi, int *varID_C_RD, int *varID_C_RT, int *varID_C_G, int *varID_C_Gc)
  491. {
  492. // Function for loading NetCDF files for initial condition.
  493. // This function will return variable IDs and check if the needed initial condition matrices are included in the file.
  494. int RetVAL;
  495. RetVAL = nc_inq_varid(ncID, "VsX", varID_Vx);
  496. if (RetVAL != NC_NOERR)
  497. {
  498. printf("Error: Vx matrix not found in the file. %s\n", nc_strerror(RetVAL));
  499. return -31;
  500. }
  501. RetVAL = nc_inq_varid(ncID, "VsY", varID_Vy);
  502. if (RetVAL != NC_NOERR)
  503. {
  504. printf("Error: Vy matrix not found in the file. %s\n", nc_strerror(RetVAL));
  505. return -31;
  506. }
  507. RetVAL = nc_inq_varid(ncID, "Phi", varID_Phi);
  508. if (RetVAL != NC_NOERR)
  509. {
  510. printf("Error: Phi matrix not found in the file. %s\n", nc_strerror(RetVAL));
  511. return -31;
  512. }
  513. RetVAL = nc_inq_varid(ncID, "RD", varID_C_RD);
  514. if (RetVAL != NC_NOERR)
  515. {
  516. printf("Error: C_RD matrix not found in the file. %s\n", nc_strerror(RetVAL));
  517. return -31;
  518. }
  519. RetVAL = nc_inq_varid(ncID, "RT", varID_C_RT);
  520. if (RetVAL != NC_NOERR)
  521. {
  522. printf("Error: C_RT matrix not found in the file. %s\n", nc_strerror(RetVAL));
  523. return -31;
  524. }
  525. RetVAL = nc_inq_varid(ncID, "G", varID_C_G);
  526. if (RetVAL != NC_NOERR)
  527. {
  528. printf("Error: C_G matrix not found in the file. %s\n", nc_strerror(RetVAL));
  529. return -31;
  530. }
  531. RetVAL = nc_inq_varid(ncID, "Gc", varID_C_Gc);
  532. if (RetVAL != NC_NOERR)
  533. {
  534. printf("Error: C_Gc matrix not found in the file. %s\n", nc_strerror(RetVAL));
  535. return -31;
  536. }
  537. return 0;
  538. }
  539. int loadInitialConditionsFromSolution(const char *InitialConditionsFile, const char *SaveFileName, int SolutionIdx,
  540. size_t I, size_t J, double *X, double *Y,
  541. double *Vx, double *Vy, double *Phi, double *C_RD, double *C_RT, double *C_G, double *C_Gc, double *P,
  542. double *Time)
  543. {
  544. // Function for loading initial conditions for solution file.
  545. // In case the simulation was already run and terminated before finish.
  546. // Loading X and Y arrays
  547. int varID_Vx, varID_Vy, varID_Phi, varID_C_RD, varID_C_RT, varID_C_G, varID_C_Gc, varID_X, varID_Y;
  548. int ncID, RetVAL;
  549. // Retrieving initial conditions file ID
  550. ncID = readICNetCDF(InitialConditionsFile);
  551. if (ncID == -30) { return -30; }
  552. // Retrieving variable IDs from initial conditions file
  553. RetVAL = loadICNetCDF(ncID, &varID_Vx, &varID_Vy, &varID_Phi, &varID_C_RD, &varID_C_RT, &varID_C_G, &varID_C_Gc, &varID_X, &varID_Y);
  554. if (RetVAL != 0) { nc_close(ncID); return RetVAL;}
  555. RetVAL = nc_get_var_double(ncID, varID_X, X);
  556. if (RetVAL != NC_NOERR)
  557. {
  558. printf("Error reading X vector: %s\n", nc_strerror(RetVAL));
  559. nc_close(ncID);
  560. return -33;
  561. }
  562. RetVAL = nc_get_var_double(ncID, varID_Y, Y);
  563. if (RetVAL != NC_NOERR)
  564. {
  565. printf("Error reading Y vector: %s\n", nc_strerror(RetVAL));
  566. nc_close(ncID);
  567. return -33;
  568. }
  569. // Closing the file
  570. RetVAL = nc_close(ncID);
  571. if (RetVAL != NC_NOERR)
  572. {
  573. printf("Error closing Initial Conditions file: %s\n", nc_strerror(RetVAL));
  574. return -38;
  575. }
  576. // Clearing variables
  577. ncID, RetVAL = 0;
  578. varID_Vx, varID_Vy, varID_Phi, varID_C_RD, varID_C_RT, varID_C_G, varID_C_Gc = 0;
  579. int varID_Time, varID_P;
  580. // Loading initial conditions from Solution file.
  581. ncID = readICNetCDF(SaveFileName);
  582. // Retrieving variable IDs from Solution file.
  583. RetVAL = loadSolutionNetCDF(ncID, &varID_Vx, &varID_Vy, &varID_Phi, &varID_C_RD, &varID_C_RT, &varID_C_G, &varID_C_Gc);
  584. if (RetVAL != 0) { nc_close(ncID); return RetVAL;}
  585. // Open the solution file
  586. RetVAL = nc_open(SaveFileName, NC_NOWRITE, &ncID);
  587. if (RetVAL != NC_NOERR) {
  588. printf("Error opening solution file: %s\n", nc_strerror(RetVAL));
  589. return -30;
  590. }
  591. // Get variable IDs for required variables
  592. if ((RetVAL = nc_inq_varid(ncID, "VsX", &varID_Vx)) != NC_NOERR ||
  593. (RetVAL = nc_inq_varid(ncID, "VsY", &varID_Vy)) != NC_NOERR ||
  594. (RetVAL = nc_inq_varid(ncID, "Time", &varID_Time)) != NC_NOERR ||
  595. (RetVAL = nc_inq_varid(ncID, "Phi", &varID_Phi)) != NC_NOERR ||
  596. (RetVAL = nc_inq_varid(ncID, "RD", &varID_C_RD)) != NC_NOERR ||
  597. (RetVAL = nc_inq_varid(ncID, "RT", &varID_C_RT)) != NC_NOERR ||
  598. (RetVAL = nc_inq_varid(ncID, "G", &varID_C_G)) != NC_NOERR ||
  599. (RetVAL = nc_inq_varid(ncID, "Gc", &varID_C_Gc)) != NC_NOERR ||
  600. (RetVAL = nc_inq_varid(ncID, "P", &varID_P)) != NC_NOERR) {
  601. printf("Error: Required variable not found in file: %s\n", nc_strerror(RetVAL));
  602. nc_close(ncID);
  603. return -31;
  604. }
  605. // Define start and count for slicing data
  606. size_t start3D[3] = {SolutionIdx, 0, 0};
  607. size_t count3D_VsX[3] = {1, I - 1, J}; // For VsX
  608. size_t count3D_VsY[3] = {1, I, J - 1}; // For VsY
  609. size_t count3D[3] = {1, I, J}; // For 3D variables (Phi, RD, RT, G, Gc, P)
  610. size_t start1D[1] = {SolutionIdx};
  611. size_t count1D[1] = {1};
  612. // Read the variables
  613. if ((RetVAL = nc_get_vara_double(ncID, varID_Vx, start3D, count3D_VsX, Vx)) != NC_NOERR ||
  614. (RetVAL = nc_get_vara_double(ncID, varID_Vy, start3D, count3D_VsY, Vy)) != NC_NOERR ||
  615. (RetVAL = nc_get_vara_double(ncID, varID_Phi, start3D, count3D, Phi)) != NC_NOERR ||
  616. (RetVAL = nc_get_vara_double(ncID, varID_C_RD, start3D, count3D, C_RD)) != NC_NOERR ||
  617. (RetVAL = nc_get_vara_double(ncID, varID_C_RT, start3D, count3D, C_RT)) != NC_NOERR ||
  618. (RetVAL = nc_get_vara_double(ncID, varID_C_G, start3D, count3D, C_G)) != NC_NOERR ||
  619. (RetVAL = nc_get_vara_double(ncID, varID_C_Gc, start3D, count3D, C_Gc)) != NC_NOERR ||
  620. (RetVAL = nc_get_vara_double(ncID, varID_P, start3D, count3D, P)) != NC_NOERR) {
  621. printf("Error reading variable data: %s\n", nc_strerror(RetVAL));
  622. nc_close(ncID);
  623. return -33;
  624. }
  625. // Read the Time variable
  626. if ((RetVAL = nc_get_vara_double(ncID, varID_Time, start1D, count1D, Time)) != NC_NOERR) {
  627. printf("Error reading Time data: %s\n", nc_strerror(RetVAL));
  628. nc_close(ncID);
  629. return -33;
  630. }
  631. // Close the file
  632. if ((RetVAL = nc_close(ncID)) != NC_NOERR) {
  633. printf("Error closing file: %s\n", nc_strerror(RetVAL));
  634. return -38;
  635. }
  636. return 0;
  637. }
  638. int CreateSolutionsFile(const char *SaveFileName, size_t I, size_t J, int MaxTimeSteps)
  639. {
  640. // Function for creating solutions file.
  641. // Space needed is allocated before the start of simulation.
  642. // The empty matrix values are stored as biggest double value and not zero.
  643. int ncID, RetVAL;
  644. // Creating Solutions file
  645. int timeDimID, xDimID, yDimID, xDimVsXID, yDimVsYID, varID_Time, varID_VnsX, varID_VnsY, varID_VsX, varID_VsY, varID_VsX_1, varID_VsY_1, varID_Phi, varID_Phi_1, varID_RD, varID_RT, varID_G, varID_Gc, varID_P, varID_SimTime;
  646. RetVAL = nc_create(SaveFileName, NC_NETCDF4 | NC_CLOBBER, &ncID);
  647. if (RetVAL != NC_NOERR)
  648. {
  649. printf("Error creating file: %s\n", nc_strerror(RetVAL));
  650. return 34;
  651. }
  652. // Define dimensions
  653. RetVAL = nc_def_dim(ncID, "time", MaxTimeSteps, &timeDimID);
  654. if (RetVAL != NC_NOERR)
  655. {
  656. printf("Error defining time dimension: %s\n", nc_strerror(RetVAL));
  657. return 35;
  658. }
  659. RetVAL = nc_def_dim(ncID, "xDim", I, &xDimID);
  660. if (RetVAL != NC_NOERR)
  661. {
  662. printf("Error defining x dimension: %s\n", nc_strerror(RetVAL));
  663. return 35;
  664. }
  665. RetVAL = nc_def_dim(ncID, "yDim", J, &yDimID);
  666. if (RetVAL != NC_NOERR)
  667. {
  668. printf("Error defining y dimension: %s\n", nc_strerror(RetVAL));
  669. return 35;
  670. }
  671. // Define additional dimensions for VsX and VsY
  672. RetVAL = nc_def_dim(ncID, "xDimS", I - 1, &xDimVsXID);
  673. if (RetVAL != NC_NOERR)
  674. {
  675. printf("Error defining xDimS dimension: %s\n", nc_strerror(RetVAL));
  676. return 35;
  677. }
  678. RetVAL = nc_def_dim(ncID, "yDimS", J - 1, &yDimVsYID);
  679. if (RetVAL != NC_NOERR)
  680. {
  681. printf("Error defining yDimS dimension: %s\n", nc_strerror(RetVAL));
  682. return 35;
  683. }
  684. // Define variables
  685. int dims3D[3] = {timeDimID, xDimID, yDimID};
  686. int dimsTime[1] = {timeDimID};
  687. int dims2D[2] = {timeDimID, 1};
  688. // Time variable
  689. RetVAL = nc_def_var(ncID, "Time", NC_DOUBLE, 1, dimsTime, &varID_Time);
  690. if (RetVAL != NC_NOERR)
  691. {
  692. printf("Error defining Time variable: %s\n", nc_strerror(RetVAL));
  693. return 36;
  694. }
  695. // Simulation Time variable
  696. RetVAL = nc_def_var(ncID, "SimulationTime", NC_DOUBLE, 2, dims2D, &varID_SimTime);
  697. if (RetVAL != NC_NOERR)
  698. {
  699. printf("Error defining SimulationTime variable: %s\n", nc_strerror(RetVAL));
  700. return 36;
  701. }
  702. // Solution matrices
  703. RetVAL = nc_def_var(ncID, "VnsX", NC_DOUBLE, 3, dims3D, &varID_VnsX);
  704. if (RetVAL != NC_NOERR)
  705. {
  706. printf("Error defining VnsX variable: %s\n", nc_strerror(RetVAL));
  707. return 36;
  708. }
  709. RetVAL = nc_def_var(ncID, "VnsY", NC_DOUBLE, 3, dims3D, &varID_VnsY);
  710. if (RetVAL != NC_NOERR)
  711. {
  712. printf("Error defining VnsY variable: %s\n", nc_strerror(RetVAL));
  713. return 36;
  714. }
  715. // Redefine the dimensions for VsX (3D array with I-1 rows)
  716. dims3D[1] = xDimVsXID;
  717. RetVAL = nc_def_var(ncID, "VsX", NC_DOUBLE, 3, dims3D, &varID_VsX);
  718. if (RetVAL != NC_NOERR)
  719. {
  720. printf("Error defining VsX variable: %s\n", nc_strerror(RetVAL));
  721. return 36;
  722. }
  723. RetVAL = nc_def_var(ncID, "VsX_1", NC_DOUBLE, 3, dims3D, &varID_VsX_1);
  724. if (RetVAL != NC_NOERR)
  725. {
  726. printf("Error defining VsX_1 variable: %s\n", nc_strerror(RetVAL));
  727. return 36;
  728. }
  729. // Redefine the dimensions for VsY (3D array with J-1 columns)
  730. dims3D[1] = xDimID; // Reset to xDim for VsY
  731. dims3D[2] = yDimVsYID;
  732. RetVAL = nc_def_var(ncID, "VsY", NC_DOUBLE, 3, dims3D, &varID_VsY);
  733. if (RetVAL != NC_NOERR)
  734. {
  735. printf("Error defining VsY variable: %s\n", nc_strerror(RetVAL));
  736. return 36;
  737. }
  738. RetVAL = nc_def_var(ncID, "VsY_1", NC_DOUBLE, 3, dims3D, &varID_VsY_1);
  739. if (RetVAL != NC_NOERR)
  740. {
  741. printf("Error defining VsY_1 variable: %s\n", nc_strerror(RetVAL));
  742. return 36;
  743. }
  744. // Reset to original xDim and yDim for remaining matrices
  745. dims3D[1] = xDimID;
  746. dims3D[2] = yDimID;
  747. RetVAL = nc_def_var(ncID, "Phi", NC_DOUBLE, 3, dims3D, &varID_Phi);
  748. if (RetVAL != NC_NOERR)
  749. {
  750. printf("Error defining Phi variable: %s\n", nc_strerror(RetVAL));
  751. return 36;
  752. }
  753. RetVAL = nc_def_var(ncID, "Phi_1", NC_DOUBLE, 3, dims3D, &varID_Phi_1);
  754. if (RetVAL != NC_NOERR)
  755. {
  756. printf("Error defining Phi_1 variable: %s\n", nc_strerror(RetVAL));
  757. return 36;
  758. }
  759. RetVAL = nc_def_var(ncID, "RD", NC_DOUBLE, 3, dims3D, &varID_RD);
  760. if (RetVAL != NC_NOERR)
  761. {
  762. printf("Error defining RD variable: %s\n", nc_strerror(RetVAL));
  763. return 36;
  764. }
  765. RetVAL = nc_def_var(ncID, "RT", NC_DOUBLE, 3, dims3D, &varID_RT);
  766. if (RetVAL != NC_NOERR)
  767. {
  768. printf("Error defining RT variable: %s\n", nc_strerror(RetVAL));
  769. return 36;
  770. }
  771. RetVAL = nc_def_var(ncID, "G", NC_DOUBLE, 3, dims3D, &varID_G);
  772. if (RetVAL != NC_NOERR)
  773. {
  774. printf("Error defining G variable: %s\n", nc_strerror(RetVAL));
  775. return 36;
  776. }
  777. RetVAL = nc_def_var(ncID, "Gc", NC_DOUBLE, 3, dims3D, &varID_Gc);
  778. if (RetVAL != NC_NOERR)
  779. {
  780. printf("Error defining Gc variable: %s\n", nc_strerror(RetVAL));
  781. return 36;
  782. }
  783. RetVAL = nc_def_var(ncID, "P", NC_DOUBLE, 3, dims3D, &varID_P);
  784. if (RetVAL != NC_NOERR)
  785. {
  786. printf("Error defining P variable: %s\n", nc_strerror(RetVAL));
  787. return 36;
  788. }
  789. // End definitions and leave define mode
  790. RetVAL = nc_enddef(ncID);
  791. if (RetVAL != NC_NOERR)
  792. {
  793. printf("Error leaving define mode: %s\n", nc_strerror(RetVAL));
  794. return 37;
  795. }
  796. // Close the file (it will be reopened for writing during the simulation)
  797. RetVAL = nc_close(ncID);
  798. if (RetVAL != NC_NOERR)
  799. {
  800. printf("Error closing file: %s\n", nc_strerror(RetVAL));
  801. return 38;
  802. }
  803. return 0;
  804. }
  805. void GenerateTracerPosition(int Cluster, int Seed, int NumPoints, double Rmin, double Rmax, double DomainLength, double *VecX, double *VecY)
  806. {
  807. // Function for generating initial positions of Tracers.
  808. // Rmin and Rmax parameters define the minimum and maximum radius the point can have with respect to the domain center.
  809. double x,y,r,phi;
  810. // The seed is defined in Parameters file.
  811. srand(Seed);
  812. for (int i = 0; i < NumPoints; i++)
  813. {
  814. double u = (double)rand() / RAND_MAX;
  815. // the radius is proportional to sqrt(u) so that we get homogeneous distribution in x and y dimensions.
  816. r = (Rmax - Rmin) * sqrt(u) + Rmin;
  817. phi = 2 * M_PI * ((double)rand() / RAND_MAX);
  818. x = DomainLength/2 + r * cos(phi);
  819. y = DomainLength/2 + r * sin(phi);
  820. if(Cluster==0 || NumPoints != 0)
  821. {
  822. printf("x:%lf\ty:%lf\n",x,y);
  823. }
  824. VecX[i]=x;
  825. VecY[i]=y;
  826. }
  827. }
  828. int CrateTracerFiles(char *TracerFolder, int TracerNBulk, int TracerNOut,
  829. double *TracerPositionBx, double *TracerPositionBy, double *TracerPositionOx, double *TracerPositionOy,
  830. char TracersBulkFileNames[][100], char TracersOutFileNames[][100])
  831. {
  832. // Function for creating binary files tracer positions will be stored in.
  833. double time_stamp = 0.0;
  834. // Bulk Tracer Files
  835. for (int i = 0; i < TracerNBulk; i++)
  836. {
  837. snprintf(TracersBulkFileNames[i], 100, "%sBulkTracer_%d.bin", TracerFolder, i+1);
  838. FILE *file = fopen(TracersBulkFileNames[i], "wb");
  839. if (!file)
  840. {
  841. printf("Error opening file");
  842. return 40;
  843. }
  844. fwrite(&time_stamp, sizeof(double), 1, file); // This is time stamp equal to 0 for initial position.
  845. fwrite(&TracerPositionBx[i], sizeof(double), 1, file);
  846. fwrite(&TracerPositionBy[i], sizeof(double), 1, file);
  847. fclose(file);
  848. }
  849. // Tracers Out Files
  850. for (int i = 0; i < TracerNOut; i++)
  851. {
  852. snprintf(TracersOutFileNames[i], 100, "%sOutTracer_%d.bin", TracerFolder, i+1);
  853. FILE *file = fopen(TracersOutFileNames[i], "wb");
  854. if (!file)
  855. {
  856. printf("Error opening file");
  857. return 40;
  858. }
  859. fwrite(&time_stamp, sizeof(double), 1, file);
  860. fwrite(&TracerPositionOx[i], sizeof(double), 1, file);
  861. fwrite(&TracerPositionOy[i], sizeof(double), 1, file);
  862. fclose(file);
  863. }
  864. return 0;
  865. }
  866. void printParameters(const char *InitialConditionsFile, const char *SaveFileName,
  867. int nTracersB, int nTracersO,
  868. int NumberOfSaveCycles, int NumberOfDoubleStep, int MaxIter,
  869. size_t I, size_t J,
  870. double dx, double dy, double dt, double CO, double vBB, double vBS,
  871. double PTol, double eps, double nu, double cG, double Si0, double kSi, double kC, double Beta, double Alpha,
  872. double DRD, double DRT, double DG, double DGc, double k1, double k2, double k3, double k11, double k12, double R_Max)
  873. {
  874. // Function for displaying loaded Parameters
  875. printf("Original Initial conditions File is: '%s'.\n", InitialConditionsFile);
  876. printf("File for saving data with the name: '%s', will be created.\n\n", SaveFileName);
  877. printf("Solution Matrices will be saved every: %d steps, which is equivalent to saving every %2.3lf s.\n\n", 2*NumberOfDoubleStep, 2*NumberOfDoubleStep*dt);
  878. printf("Domain is split onto: %zu Points in x and %zu Points in y direction,\n", I, J);
  879. printf("With Grid spacing of: %1.3lf in x and %1.3lf in y direction,\n", dx, dy);
  880. printf("Which gives: %2.3lf by %2.3lf Domain.\n\n", dx*(I-1), dy*(J-1));
  881. printf("Time Step length is: %lf.\n\n", dt);
  882. printf("Gradient CutOff is: %1.1e, while Potential Saturation values are: %2.1lf for Bulk and %2.1lf for Surface.\n\n", CO, vBB, vBS);
  883. printf("Pressure Tolerance at which iterative process is stopped: %1.1e.\n\n", PTol);
  884. printf("Viscosity of the fluid is: %2.3lf, while dissipation coefficient is %2.3lf.\n\n", nu, Beta);
  885. printf("Level-Set Parameters are:\n \t Epsilon: %2.3lf,\n \t Gamma: %2.3lf. \n \t Alpha: %2.3lf.\n\n", eps, cG, Alpha);
  886. printf("Parameters for Force on the membrane:\n \t Surface tension Sigma: %2.3lf,\n \t Surface tension change rate: %2.3lf,\n \t Force from interaction with the substrate coefficient: %2.3lf.\n\n", Si0, kSi, kC);
  887. printf("Diffusion constants are:\n \t D_RD: %2.3lf,\n \t D_RT: %2.3lf,\n \t D_G: %2.3lf,\n \t D_Gc: %2.3lf.\n\n", DRD, DRT, DG, DGc);
  888. printf("Reaction constants are:\n \t k1: %2.3lf,\n \t k2: %2.3lf,\n \t k3: %2.3lf,\n \t k11: %2.3lf,\n \t k12: %2.3lf.\n", k1, k2, k3, k11, k12);
  889. printf("Concentration of binding spaces for Rac1T is: %3.1lf\n\n", R_Max);
  890. printf("Number of tracers inside cell: %d\n", nTracersB);
  891. printf("Number of tracers outside cell: %d\n\n", nTracersO);
  892. }
  893. // Error codes
  894. // 10 - Failed to load or parse the JSON file. (Check input file names and LoadJSON function)
  895. // 11 - Failed to find key in .json file
  896. // 12 - Array size in .json file is missing values or has extra values.
  897. // 20 - Cluster variable not set properly. Can't determine if the simulation is to be run on cluster without inputs or on personal computer with input and print options.
  898. // 30 - Failed to open .nc file
  899. // 31 - Variable not found in .nc file
  900. // 32 - Failed to get the dimension of variable
  901. // 33 - Failed to read the variable
  902. // 34 - Failed to create .nc file
  903. // 35 - Failed to define dimensions in .nc file
  904. // 36 - Failed to define variable in .nc file
  905. // 37 - Failed to exit variable definition mode
  906. // 38 - Failed to close .nc file
  907. // 40 - Failed to open Tracer files
  908. // 95 - Simulation aborted by the user
  909. // 96 - Error occurred during simulation.
  910. // 97 - Initial Conditions File and Parameters File dimensions are not compatible
  911. // 98 - Memory allocation failed.
  912. // 99 - The y/n question input is neither "y" nor "n"
  913. int main(int argc, char *argv[])
  914. {
  915. // Main function for simulating cell locomotion
  916. // Error code
  917. int ERROR;
  918. // y/n input
  919. char InputYN[3];
  920. // Simulation Parameters allocation
  921. char ParametersFile[100];
  922. // File
  923. char InitialConditionsFile[100], SaveFileName[100], TracerFolder[100], TracerPrefix[100];
  924. // Simulation
  925. int Seed, Cluster, nTracersB, nTracersO, NumberOfSaveCycles, NumberOfDoubleStep, MaxIter;
  926. size_t I, J;
  927. double dx, dy, dt, CO, vBB, vBS, PTol;
  928. // Model
  929. double eps, nu, cG, Si0, kSi, kC, Beta, Alpha;
  930. double DRD, DRT, DG, DGc;
  931. double k1, k2, k3, k11, k12;
  932. double R_Max;
  933. // Loading Parameters from .json file
  934. if (argc>=3) // If Parameters file and initial conditions file were provided
  935. {
  936. // Copying provided file names
  937. strcpy(ParametersFile, argv[1]);
  938. strcpy(InitialConditionsFile, argv[2]);
  939. // Loading parameters file
  940. cJSON *JSONFile = loadJSON(ParametersFile);
  941. if (!JSONFile)
  942. {
  943. printf("Error: Failed to load or parse the JSON file\n");
  944. cJSON_Delete(JSONFile); // Clean up cJSON object
  945. return 10;
  946. }
  947. // Loading parameters form .json
  948. ERROR = loadParameters(JSONFile,
  949. InitialConditionsFile, SaveFileName, TracerFolder, TracerPrefix,
  950. &Seed, &Cluster, &nTracersB, &nTracersO, &NumberOfSaveCycles, &NumberOfDoubleStep,
  951. &I, &J,
  952. &dx, &dy, &dt, &CO, &vBB, &vBS, &MaxIter, &PTol,
  953. &eps, &nu, &cG, &Si0, &kSi, &kC, &Beta, &Alpha,
  954. &DRD, &DRT, &DG, &DGc,
  955. &k1, &k2, &k3, &k11, &k12, &R_Max);
  956. if (ERROR != 0)
  957. {
  958. printf("Error: Failed to save parameter values from the JSON file\n");
  959. cJSON_Delete(JSONFile); // Clean up cJSON object
  960. return ERROR;
  961. }
  962. cJSON_Delete(JSONFile); // Clean up cJSON object
  963. }
  964. else // If Parameters file and initial conditions file were both NOT provided
  965. {
  966. // Declaration of variables
  967. char InitialConditionsFileInput[100];
  968. // Starting simulation preparation
  969. printf("Cell Locomotion Simulation\n\n");
  970. // Asking to provide the parameters file name
  971. printf("Please enter the Parameters File Name: ");
  972. fgets(ParametersFile, sizeof(ParametersFile), stdin);
  973. ParametersFile[strcspn(ParametersFile, "\n")] = 0;
  974. // Loading parameters file
  975. cJSON *JSONFile = loadJSON(ParametersFile);
  976. if (!JSONFile)
  977. {
  978. printf("Error: Failed to load or parse the JSON file\n");
  979. cJSON_Delete(JSONFile); // Clean up cJSON object
  980. return 10;
  981. }
  982. // Loading parameters form .json
  983. ERROR = loadParameters(JSONFile,
  984. InitialConditionsFile, SaveFileName, TracerFolder, TracerPrefix,
  985. &Seed, &Cluster, &nTracersB, &nTracersO, &NumberOfSaveCycles, &NumberOfDoubleStep,
  986. &I, &J,
  987. &dx, &dy, &dt, &CO, &vBB, &vBS, &MaxIter, &PTol,
  988. &eps, &nu, &cG, &Si0, &kSi, &kC, &Beta, &Alpha,
  989. &DRD, &DRT, &DG, &DGc,
  990. &k1, &k2, &k3, &k11, &k12, &R_Max);
  991. if (ERROR != 0)
  992. {
  993. printf("Error: Failed to load parameter values from the JSON file\n");
  994. cJSON_Delete(JSONFile); // Clean up cJSON object
  995. return ERROR;
  996. }
  997. cJSON_Delete(JSONFile); // Clean up cJSON object
  998. // Asking to provide the initial conditions file name
  999. printf("Do you want to use original Initial Conditions from Parameters File?: (y/n) \n");
  1000. fgets(InputYN, sizeof(InputYN), stdin);
  1001. InputYN[strcspn(InputYN, "\n")] = 0;
  1002. if(strcmp(InputYN,"n")==0)
  1003. {
  1004. // Asking to provide the initial conditions file name
  1005. printf("\nPlease provide the new Initial Conditions file in the same folder as the program before continuing!");
  1006. printf("\nPlease enter the Initial Conditions File Name: \n");
  1007. fgets(InitialConditionsFileInput, sizeof(InitialConditionsFileInput), stdin);
  1008. InitialConditionsFileInput[strcspn(InitialConditionsFileInput, "\n")] = 0;
  1009. // Copying initial conditions file name
  1010. for(size_t i=0; i<100; i++)
  1011. {
  1012. InitialConditionsFile[i]=InitialConditionsFileInput[i];
  1013. }
  1014. }
  1015. else if(strcmp(InputYN,"y")==0)
  1016. {
  1017. // Initial conditions file name was loaded from parameters file and not overwritten
  1018. printf("\nOriginal Initial Conditions will be loaded\n");
  1019. }
  1020. else
  1021. {
  1022. printf("\nError: Please enter y for YES and n for NO.\n");
  1023. return 99;
  1024. }
  1025. }
  1026. // Memory allocation for initial conditions arrays
  1027. ALLOC_ARRAY(Vx,double,I-1,J);
  1028. ALLOC_ARRAY(Vy,double,I,J-1);
  1029. ALLOC_ARRAY(Phi,double,I,J);
  1030. ALLOC_ARRAY(C_RD,double,I,J);
  1031. ALLOC_ARRAY(C_RT,double,I,J);
  1032. ALLOC_ARRAY(C_G,double,I,J);
  1033. ALLOC_ARRAY(C_Gc,double,I,J);
  1034. ALLOC_ARRAY(X,double,I,1);
  1035. ALLOC_ARRAY(Y,double,1,J);
  1036. ALLOC_ARRAY(P,double,I,J);
  1037. if (Vx == NULL) {printf("Error: Memory allocation failed for Vx\n"); return 98;}
  1038. if (Vy == NULL) {printf("Error: Memory allocation failed for Vy\n"); return 98;}
  1039. if (Phi == NULL) {printf("Error: Memory allocation failed for Phi\n"); return 98;}
  1040. if (C_RD == NULL) {printf("Error: Memory allocation failed for C_RD\n"); return 98;}
  1041. if (C_RT == NULL) {printf("Error: Memory allocation failed for C_RT\n"); return 98;}
  1042. if (C_G == NULL) {printf("Error: Memory allocation failed for C_G\n"); return 98;}
  1043. if (C_Gc == NULL) {printf("Error: Memory allocation failed for C_Gc\n"); return 98;}
  1044. if (X == NULL) {printf("Error: Memory allocation failed for X\n"); return 98;}
  1045. if (Y == NULL) {printf("Error: Memory allocation failed for Y\n"); return 98;}
  1046. if (P == NULL) {printf("Error: Memory allocation failed for P\n"); return 98;}
  1047. double Time = 0;
  1048. // Returning error value for loading initial conditions
  1049. int RetVAL;
  1050. // Memory allocation for tracers
  1051. double TracerPositionBx[nTracersB];
  1052. double TracerPositionBy[nTracersB];
  1053. double TracerPositionOx[nTracersO];
  1054. double TracerPositionOy[nTracersO];
  1055. char TracersBulkFileNames[nTracersB][100];
  1056. char TracersOutFileNames[nTracersO][100];
  1057. // Memory allocation for pressuer iteration number array
  1058. ALLOC_ARRAY(nIterStepVec, int, NumberOfSaveCycles*NumberOfDoubleStep*2+1, 1);
  1059. // Initiating something
  1060. double SimulationTime = 0;
  1061. double PrctSave=2;
  1062. // Forking for cluster or personal computer simulation setup
  1063. if(Cluster==1)
  1064. {
  1065. // Checking if the solution file already exists which signals the simulation has been terminated before
  1066. int SolutionIdx = checkSolutionFile(SaveFileName);
  1067. if (SolutionIdx < -1)
  1068. {
  1069. printf("Error: Failed to access Solutions file!\n");
  1070. if (Vx) free(Vx);
  1071. if (Vy) free(Vy);
  1072. if (Phi) free(Phi);
  1073. if (C_RD) free(C_RD);
  1074. if (C_RT) free(C_RT);
  1075. if (C_G) free(C_G);
  1076. if (C_Gc) free(C_Gc);
  1077. if (X) free(X);
  1078. if (Y) free(Y);
  1079. if (P) free(P);
  1080. if (nIterStepVec) free(nIterStepVec);
  1081. return -SolutionIdx;
  1082. }
  1083. else if (SolutionIdx == -1)
  1084. {
  1085. // Solution file does not exist
  1086. RetVAL = loadInitialConditions(InitialConditionsFile,I,J,Vx,Vy,Phi,C_RD,C_RT,C_G,C_Gc,X,Y);
  1087. if (RetVAL < 0)
  1088. {
  1089. return -RetVAL;
  1090. }
  1091. CreateSolutionsFile(SaveFileName,I,J,NumberOfSaveCycles+1);
  1092. }
  1093. else
  1094. {
  1095. // Solution file exists
  1096. loadInitialConditionsFromSolution(InitialConditionsFile,SaveFileName,SolutionIdx,
  1097. I,J,X,Y,
  1098. Vx,Vy,Phi,C_RD,C_RT,C_G,C_Gc,P,
  1099. &Time);
  1100. }
  1101. GenerateTracerPosition(Cluster,Seed,nTracersB,0,6.21,X[I-1],TracerPositionBx,TracerPositionBy);
  1102. GenerateTracerPosition(Cluster,Seed,nTracersO,6.5,11.2,X[I-1],TracerPositionOx,TracerPositionOy);
  1103. RetVAL = CrateTracerFiles(TracerPrefix,nTracersB,nTracersO,TracerPositionBx,TracerPositionBy,TracerPositionOx,TracerPositionOy,TracersBulkFileNames,TracersOutFileNames);
  1104. if (RetVAL != 0)
  1105. {
  1106. printf("Error: Failed to create Tracer files!\n");
  1107. if (Vx) free(Vx);
  1108. if (Vy) free(Vy);
  1109. if (Phi) free(Phi);
  1110. if (C_RD) free(C_RD);
  1111. if (C_RT) free(C_RT);
  1112. if (C_G) free(C_G);
  1113. if (C_Gc) free(C_Gc);
  1114. if (X) free(X);
  1115. if (Y) free(Y);
  1116. if (P) free(P);
  1117. if (nIterStepVec) free(nIterStepVec);
  1118. return RetVAL;
  1119. }
  1120. SimulationTime = simulation(SolutionIdx,Time,Cluster,SaveFileName,NumberOfSaveCycles,NumberOfDoubleStep,PrctSave,
  1121. nTracersB,nTracersO,TracerPositionBx,TracerPositionBy,TracerPositionOx,TracerPositionOy,TracersBulkFileNames,TracersOutFileNames,
  1122. I,J,dx,dy,dt,eps,nu,cG,
  1123. CO,vBB,vBS,MaxIter,PTol,nIterStepVec,
  1124. Si0,kSi,kC,Beta,Alpha,
  1125. DRD,DRT,DG,DGc,k1,k2,k3,k11,k12,R_Max,
  1126. P,Vx,Vy,Phi,C_RT,C_RD,C_G,C_Gc,X,Y);
  1127. if(SimulationTime==-1)
  1128. {
  1129. printf("Error occurred closing tracer files.\n");
  1130. if (Vx) free(Vx);
  1131. if (Vy) free(Vy);
  1132. if (Phi) free(Phi);
  1133. if (C_RD) free(C_RD);
  1134. if (C_RT) free(C_RT);
  1135. if (C_G) free(C_G);
  1136. if (C_Gc) free(C_Gc);
  1137. if (X) free(X);
  1138. if (Y) free(Y);
  1139. if (nIterStepVec) free(nIterStepVec);
  1140. return 96;
  1141. }
  1142. }
  1143. else if(Cluster==0)
  1144. {
  1145. printf("Parameters file loaded!\n\n");
  1146. printParameters(InitialConditionsFile,SaveFileName,
  1147. nTracersB,nTracersO,
  1148. NumberOfSaveCycles,NumberOfDoubleStep,MaxIter,
  1149. I, J,
  1150. dx,dy,dt,CO,vBB,vBS,
  1151. PTol,eps,nu,cG,Si0,kSi,kC,Beta, Alpha,
  1152. DRD,DRT,DG,DGc,
  1153. k1,k2,k3,k11,k12,R_Max);
  1154. printf("Checking existence of Solutions file!\n");
  1155. int SolutionIdx = checkSolutionFile(SaveFileName);
  1156. if (SolutionIdx < -1)
  1157. {
  1158. printf("Error: Failed to access Solutions file!\n");
  1159. if (Vx) free(Vx);
  1160. if (Vy) free(Vy);
  1161. if (Phi) free(Phi);
  1162. if (C_RD) free(C_RD);
  1163. if (C_RT) free(C_RT);
  1164. if (C_G) free(C_G);
  1165. if (C_Gc) free(C_Gc);
  1166. if (X) free(X);
  1167. if (Y) free(Y);
  1168. if (P) free(P);
  1169. if (nIterStepVec) free(nIterStepVec);
  1170. return -SolutionIdx;
  1171. }
  1172. else if (SolutionIdx == -1)
  1173. {
  1174. // Solution file does not exist
  1175. printf("Solution file does not exist!\n");
  1176. printf("Initial conditions will be loaded from Initial Conditions file!\n");
  1177. RetVAL = loadInitialConditions(InitialConditionsFile,I,J,Vx,Vy,Phi,C_RD,C_RT,C_G,C_Gc,X,Y);
  1178. if (RetVAL < 0)
  1179. {
  1180. return -RetVAL;
  1181. }
  1182. printf("Solutions file will be created\n");
  1183. CreateSolutionsFile(SaveFileName,I,J,NumberOfSaveCycles+1);
  1184. }
  1185. else
  1186. {
  1187. // Solution file exists
  1188. printf("Solution file exists!\n");
  1189. printf("Would you like to load initial conditions from Solutions File and continue the simulation?: (y/n) \n");
  1190. fgets(InputYN, sizeof(InputYN), stdin);
  1191. InputYN[strcspn(InputYN, "\n")] = 0;
  1192. if(strcmp(InputYN,"n")==0)
  1193. {
  1194. printf("Initial conditions will be loaded from Initial Conditions file!\n");
  1195. RetVAL = loadInitialConditions(InitialConditionsFile,I,J,Vx,Vy,Phi,C_RD,C_RT,C_G,C_Gc,X,Y);
  1196. if (RetVAL < 0)
  1197. {
  1198. return -RetVAL;
  1199. }
  1200. printf("Solutions file will be created\n");
  1201. CreateSolutionsFile(SaveFileName,I,J,NumberOfSaveCycles+1);
  1202. }
  1203. else if(strcmp(InputYN,"y")==0)
  1204. {
  1205. printf("Initial conditions will be loaded from Solutions file!\n");
  1206. printf("Solution index is = %d\n",SolutionIdx);
  1207. loadInitialConditionsFromSolution(InitialConditionsFile,SaveFileName,SolutionIdx,
  1208. I,J,X,Y,
  1209. Vx,Vy,Phi,C_RD,C_RT,C_G,C_Gc,P,
  1210. &Time);
  1211. }
  1212. else
  1213. {
  1214. printf("\nError: Please enter y for YES and n for NO.\n");
  1215. return 99;
  1216. }
  1217. }
  1218. if (nTracersB != 0) {printf("Tracer Positions in the Bulk:\n");}
  1219. GenerateTracerPosition(Cluster,Seed,nTracersB,0,6.21,X[I-1],TracerPositionBx,TracerPositionBy);
  1220. if (nTracersO != 0) {printf("Tracer Positions Outside the cell:\n");}
  1221. GenerateTracerPosition(Cluster,Seed,nTracersO,6.5,11.2,X[I-1],TracerPositionOx,TracerPositionOy);
  1222. if (nTracersO != 0 || nTracersB != 0) {printf("\nTracer Files will be created in: %s\n",TracerFolder);}
  1223. CrateTracerFiles(TracerFolder,nTracersB,nTracersO,TracerPositionBx,TracerPositionBy,TracerPositionOx,TracerPositionOy,TracersBulkFileNames,TracersOutFileNames);
  1224. printf("\n\nStart simulation? ((y/n))\n");
  1225. fgets(InputYN, sizeof(InputYN), stdin);
  1226. InputYN[strcspn(InputYN, "\n")] = 0;
  1227. if(strcmp(InputYN,"n")==0)
  1228. {
  1229. printf("Simulation aborted...\n");
  1230. if (Vx) free(Vx);
  1231. if (Vy) free(Vy);
  1232. if (Phi) free(Phi);
  1233. if (C_RD) free(C_RD);
  1234. if (C_RT) free(C_RT);
  1235. if (C_G) free(C_G);
  1236. if (C_Gc) free(C_Gc);
  1237. if (X) free(X);
  1238. if (Y) free(Y);
  1239. if (P) free(P);
  1240. if (nIterStepVec) free(nIterStepVec);
  1241. return 95;
  1242. }
  1243. else if(strcmp(InputYN,"y")==0)
  1244. {
  1245. SimulationTime = simulation(SolutionIdx,Time,Cluster,SaveFileName,NumberOfSaveCycles,NumberOfDoubleStep,PrctSave,
  1246. nTracersB,nTracersO,TracerPositionBx,TracerPositionBy,TracerPositionOx,TracerPositionOy,TracersBulkFileNames,TracersOutFileNames,
  1247. I,J,dx,dy,dt,eps,nu,cG,
  1248. CO,vBB,vBS,MaxIter,PTol,nIterStepVec,
  1249. Si0,kSi,kC,Beta,Alpha,
  1250. DRD,DRT,DG,DGc,k1,k2,k3,k11,k12,R_Max,
  1251. P,Vx,Vy,Phi,C_RT,C_RD,C_G,C_Gc,X,Y);
  1252. if(SimulationTime==-1)
  1253. {
  1254. printf("Error occurred closing tracer files.\n");
  1255. if (Vx) free(Vx);
  1256. if (Vy) free(Vy);
  1257. if (Phi) free(Phi);
  1258. if (C_RD) free(C_RD);
  1259. if (C_RT) free(C_RT);
  1260. if (C_G) free(C_G);
  1261. if (C_Gc) free(C_Gc);
  1262. if (X) free(X);
  1263. if (Y) free(Y);
  1264. if (P) free(P);
  1265. if (nIterStepVec) free(nIterStepVec);
  1266. return 96;
  1267. }
  1268. printf("Simulation took %lf s.", SimulationTime);
  1269. char ch;
  1270. scanf(" %c", &ch); // Not to close the window. When running on Windows from cmd.
  1271. }
  1272. else
  1273. {
  1274. printf("\nError: Please enter y for YES and n for NO.\n");
  1275. return 99;
  1276. }
  1277. }
  1278. else
  1279. {
  1280. printf("\nError: Value of \"Cluster\" variable neither 0 nor 1. Please check the parameters file!\n");
  1281. return 20;
  1282. }
  1283. if (Vx) free(Vx);
  1284. if (Vy) free(Vy);
  1285. if (Phi) free(Phi);
  1286. if (C_RD) free(C_RD);
  1287. if (C_RT) free(C_RT);
  1288. if (C_G) free(C_G);
  1289. if (C_Gc) free(C_Gc);
  1290. if (X) free(X);
  1291. if (Y) free(Y);
  1292. if (P) free(P);
  1293. if (nIterStepVec) free(nIterStepVec);
  1294. return 0;
  1295. }

main.c at commit c76d59f, under MIT · at the source

Overview

Authors: Blaž Ivšić1,2, Dorijan Vulić1, Igor Weber3, Piotr Nowakowski1, Ana-Sunčana Smith1,4,5
  1. Division of Physical Chemistry, Ruđer Bošković Institute, Zagreb, Croatia
  2. Centre for Advanced Laser Techniques, Institute of Physics, Zagreb, Croatia
  3. Division of Molecular Biology, Ruđer Bošković Institute, Zagreb, Croatia
  4. Department of Physics, Faculty of Sciences, Friedrich-Alexander-Universität, Erlangen, Bavaria, Germany
  5. Competence Center Engineering of Advanced Materials, Friedrich-Alexander-Universität, Erlangen, Bavaria, Germany
Journal: PLoS computational biology, volume 22, issue 4, article e1014216
Dates: received 21 November 2025; accepted 9 April 2026; published online 27 April 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1371/journal.pcbi.1014216 · PMID 42044154 · PMCID PMC13148778 · OpenAlex W4415938307
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: computational modeling (no new data) (modality), none (in silico) (organism), cellular / molecular (subfield)
MeSH: Cell Movement*, Cytosol*, Models, Biological*, Animals, Cell Polarity, Computational Biology, Cytoskeleton, Diffusion, Hydrodynamics, rho GTP-Binding Proteins, Signal Transduction (* major topic)
Journal subjects: Biology and Life Sciences, Cell Biology, Cell Motility, Physical Sciences, Physics, Classical Mechanics, Continuum Mechanics, Fluid Mechanics, Surface Tension, Fluid Dynamics, Fluid Flow, Cell Physiology, Cell Polarity, Biochemistry, Biochemical Simulations, Computational Biology, Cytosol, Chemistry, Physical Chemistry, Reaction Dynamics, Motion, Velocity
Topic: Cellular Mechanics and Interactions (Cell Biology, Biochemistry, Genetics and Molecular Biology), according to OpenAlex
Funding: Hrvatska Zaklada za Znanost (HRZZ-IP-2024-05-6331, HRZZ-IP-2025-02-3976); Deutsche Forschungsgemeinschaft (SM 289/10-1, SM 289/11-1)
Citations: not cited yet (Europe PMC); 126 references in the paper

Abstract

Cell migration is a fundamental process underlying the survival and function of both unicellular and multicellular organisms. Crawling motility in eukaryotic cells arises from cyclic protrusion and retraction driven by the cytoskeleton, whose organization is regulated by reaction–diffusion (RD) dynamics of Rho GTPases between the cytosol and the cortex. These dynamics generate spatial membrane patterning and establish front–rear polarity through the coupling of biochemical signalling and mechanical feedback. We develop a cross-scale mean-field framework that integrates RD signalling with cytosolic and cortical hydrodynamics to capture the evolution of cell shapes and emergent cellular locomotion. Our model reproduces diverse experimentally observed shape and motility phenotypes with small parameter changes, indicating that these behaviours correspond to self-organized limit cycles. Phase-space analysis reveals that coupling to both cytosolic flow and spatially varying surface tension is essential to recover the full spectrum of motility modes, providing a theoretical foundation for understanding amoeboid migration.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above.

blejzara/CellRDA-LS

License: MIT
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Commit: c76d59f3ca568c1f6dedfc59c38473e5571f0987, 30 October 2025
Languages: C (3), C/C++ (2)
Size: 14 files, 5 scripts
Software Heritage: not archived
Found in: “Data Availability”
Holds: README, license file, CITATION.cff
Not found: environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 30 September 2026: the link answers
  • 30 September 2026: the link answers
7 files

Zenodo 18824137

License: CC-BY-4.0
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Size: 10 files
Software Heritage: not checked
Found in: “Data Availability”
Holds: README
Not found: license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 30 September 2026: the link answers (HTTP 200)
  • 30 September 2026: the link answers (HTTP 200)
1 file
At the source:

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 5 scripts, each with its path and the digest of its content;
  • no match between paragraphs and code yet;
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data Availability

All data used to produce the figures presented in this manuscript are available at: DOI:10.5281/zenodo.18824137. Code used in simulations that provided presented results is available at: https://github.com/blejzara/CellRDA-LS.

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 30 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 5 authors, 11 MeSH terms, 2 funders, 118 references.

Cite

This paper

Ivšić, B., Vulić, D., Weber, I., Nowakowski, P., & Smith, A.-S. (2026). Diversity in emergent cell locomotion from the coupling cytosolic and cortical Marangoni flows with reaction-diffusion dynamics. PLoS computational biology, 22(4), e1014216. https://doi.org/10.1371/journal.pcbi.1014216

BibTeX

@article{ivsic2026diversity,
author = {Ivšić, Blaž and Vulić, Dorijan and Weber, Igor and Nowakowski, Piotr and Smith, Ana-Sunčana},
title = {{Diversity in emergent cell locomotion from the coupling cytosolic and cortical Marangoni flows with reaction-diffusion dynamics}},
journal = {PLoS computational biology},
year = {2026},
month = apr,
volume = {22},
number = {4},
pages = {e1014216},
publisher = {PLOS},
issn = {1553-734X},
doi = {10.1371/journal.pcbi.1014216},
url = {https://doi.org/10.1371/journal.pcbi.1014216},
pmid = {42044154},
pmcid = {PMC13148778}
}

RIS

TY - JOUR
AU - Ivšić, Blaž
AU - Vulić, Dorijan
AU - Weber, Igor
AU - Nowakowski, Piotr
AU - Smith, Ana-Sunčana
TI - Diversity in emergent cell locomotion from the coupling cytosolic and cortical Marangoni flows with reaction-diffusion dynamics
T2 - PLoS computational biology
J2 - PLoS Comput Biol
PY - 2026
DA - 2026/04/27
VL - 22
IS - 4
SP - e1014216
SN - 1553-734X
PB - PLOS
DO - 10.1371/journal.pcbi.1014216
UR - https://doi.org/10.1371/journal.pcbi.1014216
LA - en
ER -

CSL-JSON

{
"id": "10.1371/journal.pcbi.1014216",
"type": "article-journal",
"title": "Diversity in emergent cell locomotion from the coupling cytosolic and cortical Marangoni flows with reaction-diffusion dynamics",
"container-title": "PLoS computational biology",
"author": [
{
"family": "Ivšić",
"given": "Blaž"
},
{
"family": "Vulić",
"given": "Dorijan"
},
{
"family": "Weber",
"given": "Igor"
},
{
"family": "Nowakowski",
"given": "Piotr"
},
{
"family": "Smith",
"given": "Ana-Sunčana"
}
],
"container-title-short": "PLoS Comput Biol",
"volume": "22",
"issue": "4",
"page": "e1014216",
"DOI": "10.1371/journal.pcbi.1014216",
"PMID": "42044154",
"PMCID": "PMC13148778",
"ISSN": "1553-734X",
"publisher": "PLOS",
"URL": "https://doi.org/10.1371/journal.pcbi.1014216",
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
27
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41556-026-01965-1 [code]
Long-range mutual activation establishes Rho and Rac polarity during cell migration.
Journal: Nature cell biology
In common: cellular / molecular, 5 references
[2] doi:10.1038/s41467-026-72845-3 [code]
The membrane-to-cortex distance regulates mDia1 activity to control cortical mechanics.
Journal: Nature communications
In common: cellular / molecular, 4 references
[3] doi:10.1126/sciadv.aec7705 [code]
Mitotic Cdc42 waves encode PI(3,4)P&lt;sub&gt;2&lt;/sub&gt; signaling and Golgi morphological state to control spindle scaling.
Journal: Science advances
In common: cellular / molecular, 4 references
[4] doi:10.1002/advs.77115
RNA Promotes Synapsin Condensates That Organize Synaptic Vesicles in Live Neurons and Enable Localized Translation in Reconstituted System.
Journal: Advanced science (Weinheim, Baden-Wurttemberg, Germany)
In common: cellular / molecular, 2 references
[5] doi:10.1186/s12860-026-00584-w
A role for PaxB in regulating blebbing: experimental insights and theoretical perspectives from Dictyostelium discoideum.
Journal: BMC molecular and cell biology
In common: none (in silico), 1 reference
[6] doi:10.1126/sciadv.aeb3209 [code]
The actomyosin cortex controls t-tubule remodeling in skeletal muscle.
Journal: Science advances
In common: cellular / molecular, 2 references
[7] doi:10.1085/jgp.202513926
Characterization of an open-channel structure and lateral conduction pathway in the cation-selective pentameric ligand-gated ion channel, ELIC.
Journal: The Journal of general physiology
In common: none (in silico), computational modeling (no new data), cellular / molecular
[8] doi:10.1016/j.celrep.2026.117793 [code]
Clustered inputs engage dendritic nonlinearities and calcium signaling to support efficient place-field formation in CA1 pyramidal neurons.
Journal: Cell reports
In common: none (in silico), computational modeling (no new data), cellular / molecular
[9] doi:10.1038/s41586-026-10670-w [code]
Zero-shot design of drug-binding proteins via neural iterative selection-expansion.
Journal: Nature
In common: none (in silico), computational modeling (no new data), cellular / molecular
[10] doi:10.1038/s41598-026-55218-0
Amorphous metal-oxide semiconductor thin-film neuron, synapse, and neuromorphic system.
Journal: Scientific reports
In common: none (in silico), computational modeling (no new data), cellular / molecular

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.