@@ -35,11 +35,13 @@ class OpenFoamSimu(object):
3535 If simu=None, it will lists all existing simulation names in path
3636 and ask you to choose.\n
3737 timeStep: str, timeStep to load. If None, load the last time step\n
38- structured: bool, true if the mesh is structured
38+ structured: bool, true if the mesh is structured\n
39+ dataToLoad: list of str, list containing the name of the varaibles
40+ to read and load. If None, read and load all saved variables.
3941 """
4042
4143 def __init__ (self , path = None , simu = None , timeStep = None , structured = False ,
42- precision = 10 , order = 'F' ):
44+ dataToLoad = None , precision = 10 , order = 'F' ):
4345
4446 if path == None and simu == None :
4547 # If nothing if given, consider the current directory as the
@@ -63,8 +65,9 @@ def __init__(self, path=None, simu=None, timeStep=None, structured=False,
6365
6466 self .readmesh (structured = structured , precision = precision ,
6567 order = order )
66- self .readopenfoam (timeStep = timeStep , structured = structured ,
67- precision = precision , order = order )
68+ self .readopenfoam (timeStep = timeStep , structured = structured ,
69+ dataToLoad = dataToLoad , precision = precision ,
70+ order = order )
6871
6972 def readmesh (self , structured = False , precision = 10 , order = 'F' ):
7073
@@ -80,7 +83,8 @@ def readmesh(self, structured=False, precision=10, order='F'):
8083 self .ind = np .array (range (nx * ny * nz ))
8184 self .shape = (nx , ny , nz )
8285
83- def readopenfoam (self , timeStep = None , structured = False , precision = 10 , order = 'F' ):
86+ def readopenfoam (self , timeStep = None , structured = False , dataToLoad = None ,
87+ precision = 10 , order = 'F' ):
8488 """
8589 Reading SedFoam results
8690 Load the last time step saved of the simulation
@@ -111,15 +115,18 @@ def readopenfoam(self, timeStep=None, structured=False, precision=10, order='F')
111115
112116 #List all variables saved at the required time step removing potential
113117 #directory that cannot be loaded
114- self .variables = []
115- basepath = self .directory + self .timeStep + '/'
116- for fname in os .listdir (basepath ):
117- path = os .path .join (basepath , fname )
118- if os .path .isdir (path ):
119- # skip directories
120- continue
121- else :
122- self .variables .append (fname )
118+ if dataToLoad is None :
119+ self .variables = []
120+ basepath = self .directory + self .timeStep + '/'
121+ for fname in os .listdir (basepath ):
122+ path = os .path .join (basepath , fname )
123+ if os .path .isdir (path ):
124+ # skip directories
125+ continue
126+ else :
127+ self .variables .append (fname )
128+ else :
129+ self .variables = dataToLoad
123130
124131 for var in self .variables :
125132 #Load all variables and assign them as a variable of the object
0 commit comments