12
12
import cbit .vcell .messaging .server .SimulationTask ;
13
13
import cbit .vcell .mongodb .VCMongoMessage ;
14
14
import cbit .vcell .parser .ExpressionException ;
15
+ import cbit .vcell .simdata .SimulationData ;
15
16
import cbit .vcell .solver .*;
16
17
import cbit .vcell .xml .XMLSource ;
17
18
import cbit .vcell .xml .XmlHelper ;
30
31
import java .io .ByteArrayInputStream ;
31
32
import java .io .File ;
32
33
import java .io .InputStream ;
34
+ import java .math .BigDecimal ;
33
35
import java .util .ArrayList ;
34
36
import java .util .List ;
35
37
@@ -49,24 +51,57 @@ public static void vcmlToFiniteVolumeInput(String vcml_content, String simulatio
49
51
if (sim == null ) {
50
52
throw new IllegalArgumentException ("Simulation not found: " + simulation_name );
51
53
}
52
- FieldDataIdentifierSpec [] fdiSpecs = getFieldDataIdentifierSpecs (sim , parentDir );
54
+ FieldDataIdentifierSpec [] fdiSpecs = getFieldDataIdentifierSpecs (sim , outputDir , parentDir );
53
55
54
56
TempSimulation tempSimulation = new TempSimulation (sim , false );
55
57
tempSimulation .setSimulationOwner (sim .getSimulationOwner ());
56
58
SimulationJob tempSimulationJob = new SimulationJob (tempSimulation , 0 , fdiSpecs );
59
+
60
+ renameExistingFieldDataFiles (tempSimulation .getKey (), tempSimulationJob .getJobIndex (), outputDir );
61
+
57
62
SimulationTask simTask = new SimulationTask (tempSimulationJob , 0 );
58
63
LocalFVSolverStandalone solver = new LocalFVSolverStandalone (simTask , outputDir );
59
64
solver .initialize ();
60
65
}
61
66
62
- private static FieldDataIdentifierSpec [] getFieldDataIdentifierSpecs (Simulation sim , File parentDir ) throws MathException , ExpressionException {
67
+ private static void renameExistingFieldDataFiles (KeyValue tempSimKey , int jobId , File outputDir ) {
68
+ File [] files = outputDir .listFiles ();
69
+ if (files != null ) {
70
+ for (File file : files ) {
71
+ if (file .getName ().startsWith ("SimID_SIMULATIONKEY_JOBINDEX_" )) {
72
+ String newName = file .getName ().replace ("SIMULATIONKEY" ,tempSimKey .toString ()).replace ("JOBINDEX" ,String .valueOf (jobId ));
73
+ File newFile = new File (outputDir , newName );
74
+ if (!file .renameTo (newFile )){
75
+ throw new RuntimeException ("Could not rename " + file .getName () + " to " + newFile .getAbsolutePath ());
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
81
+
82
+ private static FieldDataIdentifierSpec [] getFieldDataIdentifierSpecs (Simulation sim , File outputDir , File parentDir ) throws MathException , ExpressionException {
63
83
FieldDataIdentifierSpec [] fdiSpecs = null ;
64
84
FieldFunctionArguments [] fieldFuncArgs = FieldUtilities .getFieldFunctionArguments (sim .getMathDescription ());
65
85
if (fieldFuncArgs != null ) {
66
86
List <FieldDataIdentifierSpec > fdiSpecList = new ArrayList <>();
67
87
for (FieldFunctionArguments fieldFuncArg : fieldFuncArgs ) {
68
88
if (fieldFuncArg != null ) {
69
89
String name = fieldFuncArg .getFieldName ();
90
+ //
91
+ // First, check if the resampled field data files are already present (e.g. if pyvcell wrote the files directly from image data)
92
+ //
93
+ ExternalDataIdentifier fakeExtDataId = new ExternalDataIdentifier (sim .getKey (), User .tempUser , name );
94
+ String fieldDataFileName = SimulationData .createCanonicalResampleFileName (fakeExtDataId , fieldFuncArg );
95
+ fieldDataFileName = fieldDataFileName .replace ("SimID_" + sim .getKey ().toString () + "_0_" , "SimID_SIMULATIONKEY_JOBINDEX_" );
96
+ File preexistingFieldDataFile = new File (outputDir , fieldDataFileName );
97
+ if (preexistingFieldDataFile .exists ()) {
98
+ fdiSpecList .add (new FieldDataIdentifierSpec (fieldFuncArg , fakeExtDataId ));
99
+ continue ;
100
+ }
101
+
102
+ //
103
+ // If not, check if the field data directory exists as a subdirectory of the parentDir - holding simulation results.
104
+ //
70
105
File fieldDataDir = new File (parentDir , name );
71
106
if (!fieldDataDir .exists ()) {
72
107
throw new IllegalArgumentException ("Field data directory does not exist: " + fieldDataDir .getAbsolutePath ());
0 commit comments