@@ -70,7 +70,15 @@ private enum LoaderState
70
70
private boolean useGui ;
71
71
private Comets c ;
72
72
private int lineCount ;
73
-
73
+ private boolean substrate = false ;
74
+ private boolean modelDiffusion = false ;
75
+ private boolean specific = false ;
76
+ private boolean friction = false ;
77
+ private double [][] substrateDiffConsts ;
78
+ private double [][] modelDiffConsts ;
79
+ private int [][] substrateLayout ;
80
+ private double [][] specificMedia ;
81
+ private double [][] substrateFrictionConsts ;
74
82
private static final String MODEL_FILE = "model_file" ,
75
83
MODEL_WORLD = "model_world" ,
76
84
GRID_SIZE = "grid_size" ,
@@ -87,7 +95,12 @@ private enum LoaderState
87
95
BARRIER = "barrier" ,
88
96
MEDIA = "media" ,
89
97
PARAMETERS = "parameters" ,
90
- DIFFUSION_CONST = "diffusion_constants" ;
98
+ DIFFUSION_CONST = "diffusion_constants" ,
99
+ SUBSTRATE_DIFFUSIVITY = "substrate_diffusivity" ,
100
+ SUBSTRATE_FRICTION = "substrate_friction" ,
101
+ MODEL_DIFFUSIVITY = "model_diffusivity" ,
102
+ SUBSTRATE_LAYOUT = "substrate_layout" ,
103
+ SPECIFIC_MEDIA = "specific_media" ;
91
104
/**
92
105
* Returns the recently loaded World2D.
93
106
*/
@@ -202,7 +215,7 @@ public int loadLayoutFile(String filename, Comets c, boolean useGui) throws IOEx
202
215
/*
203
216
* makes and stores internally: an FBAWorld, an array of FBAModels, an
204
217
* ArrayList of FBACells
205
- */
218
+ */
206
219
try
207
220
{
208
221
BufferedReader reader = new BufferedReader (new FileReader (filename ));
@@ -270,7 +283,6 @@ public int loadLayoutFile(String filename, Comets c, boolean useGui) throws IOEx
270
283
if (state == LoaderState .CANCELED )
271
284
throw new LayoutFileException ("Layout file loading canceled" , lineCount );
272
285
}
273
-
274
286
else if (parsed [0 ].equalsIgnoreCase (MODEL_WORLD ))
275
287
{
276
288
Map <String , Point2D .Double > media = new HashMap <String , Point2D .Double >();
@@ -363,10 +375,10 @@ else if (worldParsed[0].equalsIgnoreCase(GRID_SIZE))
363
375
else if (worldParsed .length == 3 )
364
376
c .getParameters ().setNumLayers (Integer .valueOf (1 ));
365
377
366
- if (Integer .valueOf (worldParsed [3 ])==1 )
367
- {
368
- throw new IOException ("In a 3D simulation the number of layers along the 3rd coordinate must be larger than 1." );
369
- }
378
+ // if (Integer.valueOf(worldParsed[3])==1)
379
+ // {
380
+ // throw new IOException("In a 3D simulation the number of layers along the 3rd coordinate must be larger than 1.");
381
+ // }
370
382
}
371
383
372
384
/****************** BARRIER *************************/
@@ -396,6 +408,47 @@ else if (worldParsed[0].equalsIgnoreCase(DIFFUSION_CONST))
396
408
List <String > lines = collectLayoutFileBlock (reader );
397
409
state = parseMediaDiffusionConstantsBlock (lines , diffConsts );
398
410
}
411
+ /****************** DIFFUSION CONSTANTS BY SUBSTRATE ********************/
412
+
413
+ else if (worldParsed [0 ].equalsIgnoreCase (SUBSTRATE_DIFFUSIVITY ))
414
+ {
415
+ substrate = true ;
416
+ List <String > lines = collectLayoutFileBlock (reader );
417
+ state = parseSubstrateDiffusionConstantsBlock (lines ,numMedia );
418
+ }
419
+ /****************** FRICTION CONSTANTS BY SUBSTRATE ********************/
420
+
421
+ else if (worldParsed [0 ].equalsIgnoreCase (SUBSTRATE_FRICTION ))
422
+ {
423
+ friction = true ;
424
+ List <String > lines = collectLayoutFileBlock (reader );
425
+ state = parseSubstrateFrictionConstantsBlock (lines );
426
+ }
427
+ /****************** DIFFUSION CONSTANTS BY MODEL ********************/
428
+
429
+ else if (worldParsed [0 ].equalsIgnoreCase (MODEL_DIFFUSIVITY ))
430
+ {
431
+ modelDiffusion = true ;
432
+ List <String > lines = collectLayoutFileBlock (reader );
433
+ state = parseModelDiffusionConstantsBlock (lines ,numMedia );
434
+ }
435
+
436
+ /****************** SUBSTRATE LAYOUT ********************/
437
+
438
+ else if (worldParsed [0 ].equalsIgnoreCase (SUBSTRATE_LAYOUT ))
439
+ {
440
+ List <String > lines = collectLayoutFileBlock (reader );
441
+ state = parseSubstrateLayoutBlock (lines ,c .getParameters ().getNumCols (),c .getParameters ().getNumRows ());
442
+ }
443
+
444
+ /****************** SPECIFIC MEDIA ********************/
445
+
446
+ else if (worldParsed [0 ].equalsIgnoreCase (SPECIFIC_MEDIA ))
447
+ {
448
+ specific = true ;
449
+ List <String > lines = collectLayoutFileBlock (reader );
450
+ state = parseSpecificMediaBlock (lines );
451
+ }
399
452
400
453
/****************** MEDIA ***********************/
401
454
@@ -634,7 +687,6 @@ else if (worldParsed[0].equalsIgnoreCase("prevent_media_in"))
634
687
}
635
688
}
636
689
}
637
-
638
690
/* Set diffusion constants */
639
691
double [] diffusionConsts = new double [numMedia ];
640
692
double defaultDiffConst = pParams .getDefaultDiffusionConstant ();
@@ -649,6 +701,22 @@ else if (worldParsed[0].equalsIgnoreCase("prevent_media_in"))
649
701
}
650
702
}
651
703
world .setDiffusionConstants (diffusionConsts );
704
+ if (substrate )
705
+ {
706
+ world .setSubstrateDiffusion (substrateDiffConsts );
707
+ world .setSubstrateLayout (substrateLayout );
708
+ }
709
+ if (modelDiffusion ){
710
+ world .setModelDiffusivity (modelDiffConsts );
711
+ }
712
+ if (specific )
713
+ {
714
+ world .setSpecificMedia (specificMedia );
715
+ }
716
+ if (friction )
717
+ {
718
+ world .setSubstrateFriction (substrateFrictionConsts );
719
+ }
652
720
System .out .println ("Done!" );
653
721
}
654
722
else if (c .getParameters ().getNumLayers ()>1 )
@@ -1109,6 +1177,184 @@ private LoaderState parseMediaDiffusionConstantsBlock(List<String> lines, Map<In
1109
1177
1110
1178
}
1111
1179
1180
+ private LoaderState parseSubstrateDiffusionConstantsBlock (List <String > lines , int numMedia ) throws LayoutFileException ,
1181
+ NumberFormatException
1182
+ {
1183
+ /* the 'diffusion_constants' block is taken from the way of doing it in the Model files, so it looks like this:
1184
+ *
1185
+ * diffusion_constants <default>
1186
+ * <medium number> <diff_const>
1187
+ * <medium number> <diff_const>
1188
+ * //
1189
+ */
1190
+ Integer i = 0 ;
1191
+ substrateDiffConsts = new double [lines .size ()][numMedia ];
1192
+ for (String line : lines )
1193
+ {
1194
+ lineCount ++;
1195
+ if (line .length () == 0 )
1196
+ continue ;
1197
+
1198
+ String [] diffConstParsed = line .split ("\\ s+" );
1199
+ if (diffConstParsed .length != numMedia )
1200
+ throw new LayoutFileException ("Each line of the 'diffusion_constants' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant." , lineCount );
1201
+
1202
+ else
1203
+ {
1204
+ for (int j = 0 ;j <numMedia ;j ++)
1205
+ {
1206
+ substrateDiffConsts [i ][j ] = Double .parseDouble (diffConstParsed [j ]);
1207
+ }
1208
+ i ++;
1209
+ }
1210
+ }
1211
+ return LoaderState .OK ;
1212
+
1213
+ }
1214
+
1215
+ private LoaderState parseSubstrateFrictionConstantsBlock (List <String > lines ) throws LayoutFileException ,
1216
+ NumberFormatException
1217
+ {
1218
+ /* the 'diffusion_constants' block is taken from the way of doing it in the Model files, so it looks like this:
1219
+ *
1220
+ * diffusion_constants <default>
1221
+ * <medium number> <diff_const>
1222
+ * <medium number> <diff_const>
1223
+ * //
1224
+ */
1225
+ Integer i = 0 ;
1226
+ substrateFrictionConsts = new double [lines .size ()][models .length ];
1227
+ for (String line : lines )
1228
+ {
1229
+ lineCount ++;
1230
+ if (line .length () == 0 )
1231
+ continue ;
1232
+
1233
+ String [] diffConstParsed = line .split ("\\ s+" );
1234
+ if (diffConstParsed .length != models .length )
1235
+ throw new LayoutFileException ("Each line of the 'diffusion_constants' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant." , lineCount );
1236
+
1237
+ else
1238
+ {
1239
+ for (int j = 0 ;j <models .length ;j ++)
1240
+ {
1241
+ substrateFrictionConsts [i ][j ] = Double .parseDouble (diffConstParsed [j ]);
1242
+ }
1243
+ i ++;
1244
+ }
1245
+ }
1246
+ return LoaderState .OK ;
1247
+
1248
+ }
1249
+ private LoaderState parseModelDiffusionConstantsBlock (List <String > lines , int numMedia ) throws LayoutFileException ,
1250
+ NumberFormatException
1251
+ {
1252
+ /* the 'diffusion_constants' block is taken from the way of doing it in the Model files, so it looks like this:
1253
+ *
1254
+ * diffusion_constants <default>
1255
+ * <medium number> <diff_const>
1256
+ * <medium number> <diff_const>
1257
+ * //
1258
+ */
1259
+ Integer i = 0 ;
1260
+ modelDiffConsts = new double [lines .size ()][numMedia ];
1261
+ for (String line : lines )
1262
+ {
1263
+ lineCount ++;
1264
+ if (line .length () == 0 )
1265
+ continue ;
1266
+
1267
+ String [] diffConstParsed = line .split ("\\ s+" );
1268
+ if (diffConstParsed .length != numMedia )
1269
+ throw new LayoutFileException ("Each line of the 'diffusion_constants' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant." , lineCount );
1270
+
1271
+ else
1272
+ {
1273
+ for (int j = 0 ;j <numMedia ;j ++)
1274
+ {
1275
+ modelDiffConsts [i ][j ] = Double .parseDouble (diffConstParsed [j ]);
1276
+ }
1277
+ i ++;
1278
+ }
1279
+ }
1280
+ return LoaderState .OK ;
1281
+
1282
+ }
1283
+
1284
+ private LoaderState parseSubstrateLayoutBlock (List <String > lines ,int cols ,int rows ) throws LayoutFileException ,
1285
+ NumberFormatException
1286
+ {
1287
+ /* the 'diffusion_constants' block is taken from the way of doing it in the Model files, so it looks like this:
1288
+ *
1289
+ * diffusion_constants <default>
1290
+ * <medium number> <diff_const>
1291
+ * <medium number> <diff_const>
1292
+ * //
1293
+ */
1294
+ if (lines .size () != rows )
1295
+ throw new LayoutFileException ("Each line of the 'diffusion_constants' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant." , lineCount );
1296
+ else
1297
+ {
1298
+ Integer i = 0 ;
1299
+ substrateLayout = new int [cols ][rows ];
1300
+ for (String line : lines )
1301
+ {
1302
+ lineCount ++;
1303
+ if (line .length () == 0 )
1304
+ continue ;
1305
+
1306
+ String [] layoutParsed = line .split ("\\ s+" );
1307
+ if (layoutParsed .length != cols )
1308
+ throw new LayoutFileException ("Each line of the 'diffusion_constants' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant." , lineCount );
1309
+
1310
+ else
1311
+ {
1312
+ for (int j = 0 ;j <cols ;j ++)
1313
+ {
1314
+ substrateLayout [j ][i ] = Integer .parseInt (layoutParsed [j ]);
1315
+ }
1316
+ i ++;
1317
+ }
1318
+ }
1319
+ }
1320
+ return LoaderState .OK ;
1321
+
1322
+ }
1323
+
1324
+ private LoaderState parseSpecificMediaBlock (List <String > lines ) throws LayoutFileException ,
1325
+ NumberFormatException
1326
+ {
1327
+ /* the 'diffusion_constants' block is taken from the way of doing it in the Model files, so it looks like this:
1328
+ *
1329
+ * diffusion_constants <default>
1330
+ * <medium number> <diff_const>
1331
+ * <medium number> <diff_const>
1332
+ * //
1333
+ */
1334
+ Integer i = 0 ;
1335
+ specificMedia = new double [4 ][lines .size ()];
1336
+ for (String line : lines )
1337
+ {
1338
+ lineCount ++;
1339
+ if (line .length () == 0 )
1340
+ continue ;
1341
+
1342
+ String [] sMediaParsed = line .split ("\\ s+" );
1343
+ if (sMediaParsed .length != 4 )
1344
+ throw new LayoutFileException ("Each line of the 'specific_media' block should have two tokens.\n The first should be the index of the medium component, followed by its (non-default) diffusion constant." , lineCount );
1345
+
1346
+ else
1347
+ {
1348
+ for (int j = 0 ;j <4 ;j ++)
1349
+ {
1350
+ specificMedia [j ][i ] = Double .parseDouble (sMediaParsed [j ]);
1351
+ }
1352
+ i ++;
1353
+ }
1354
+ }
1355
+ return LoaderState .OK ;
1356
+ }
1357
+
1112
1358
private LoaderState parseInitialPopBlock (String [] header , List <String > lines ) throws LayoutFileException ,
1113
1359
NumberFormatException
1114
1360
{
0 commit comments