From 687bd4a78f3164db3e31c7396047d41584557600 Mon Sep 17 00:00:00 2001
From: elemel <elise.lemeledo@math.uzh.ch>
Date: Mon, 28 Sep 2020 09:27:35 +0200
Subject: [PATCH] fastned post processing with global mesh import

---
 .../PredefinedSettings/TestSettings.txt       |  2 +-
 RunPostProcess.py                             |  2 +-
 SourceCode/PostProcess.py                     | 33 +++++++++++----
 SourceCode/PostProcessing/Exports.py          | 41 +++++++++++--------
 4 files changed, 52 insertions(+), 26 deletions(-)

diff --git a/PredefinedTests/PredefinedSettings/TestSettings.txt b/PredefinedTests/PredefinedSettings/TestSettings.txt
index 548f7a4..48d8fd9 100644
--- a/PredefinedTests/PredefinedSettings/TestSettings.txt
+++ b/PredefinedTests/PredefinedSettings/TestSettings.txt
@@ -18,4 +18,4 @@ Limiter_1		    	# Additives list Index of limiter (0=None). For properties (e.g.
 # Export properties
 m			  # Verbose mode (n=none, m=minimal, d=debug)
 0.005		# Time export intervals
-1			  # 1: MeshFree light export, 0: Full export with mesh structure
+0			  # 1: MeshFree light export, 0: Full export with mesh structure
diff --git a/RunPostProcess.py b/RunPostProcess.py
index c02f9c9..9a54603 100644
--- a/RunPostProcess.py
+++ b/RunPostProcess.py
@@ -77,7 +77,7 @@ if __name__ == '__main__':
     MeshResolution    = 20
 
     # Conversion tasks
-    #PostProcess.Results_ConvertToVTK(ProblemDefinition, SettingsChoice, "all", MeshResolution)
+    PostProcess.Results_ConvertToVTK(ProblemDefinition, SettingsChoice, "all", MeshResolution)
 
     # Post - processing tasks
 	#PostProcess.Plot_DebugMatplotlib(ProblemDefinition, SettingsChoice, [0.0], MeshResolution)
diff --git a/SourceCode/PostProcess.py b/SourceCode/PostProcess.py
index 6a0f433..c7e5768 100644
--- a/SourceCode/PostProcess.py
+++ b/SourceCode/PostProcess.py
@@ -92,10 +92,13 @@ def Results_ConvertToVTK(*argv):
 	LightExport = int(re.split(" |\t", Settings.readlines()[20])[0])
 	Settings.close()
 
+	# Load the mesh once for all
+	if len(times)>0: Mesh, ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], times[0], 1)
+
 	# Loop on the wished times
 	for t in times:
 		# Load the solution
-		Mesh, ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], t)
+		ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], t, 0)
 
 		# Convert the solution
 		for VariableId in range(Problem.GoverningEquations.NbVariables):
@@ -116,7 +119,7 @@ def Plots_StaticSchlieren(*argv):
 		Settings     (string):                      name of the settings file specifying the scheme, time options etc to use for the study, stored in the "PredefinedSettings" folder
 		time         (float array-like or string):  time points for which to process the plot, or "all"
 		Resolution   (integer):                     mesh resolution
-
+		
 	Returns:
 		None: The solution's matplotlib plots for each time step given in :code:`time`.
 
@@ -125,6 +128,10 @@ def Plots_StaticSchlieren(*argv):
 	The automatically exported plots (called plotting routines) for this function are for the selected variable:
 
 		-	| Compute2DSchlierenImages
+		
+	.. note::
+	
+		For speedup, we assume that the mesh is the same for every time point. Change line 174 to be as 169 if wished otherwise
 	"""
 
 	# ---------------------- Checking the user input -------------------------------------
@@ -161,10 +168,13 @@ def Plots_StaticSchlieren(*argv):
 	LightExport = int(re.split(" |\t", Settings.readlines()[20])[0])
 	Settings.close()
 
+	# Load the mesh once for all
+	if len(times)>0: Mesh, ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], times[0], 1)
+
 	# Loop on the wished times
 	for t in times:
 		# Load the solution
-		Mesh, ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], t)
+		ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], t, 0)
 
 		# Export the schlieren images
 		for VariableId in range(Problem.GoverningEquations.NbVariables):
@@ -238,11 +248,14 @@ def Plots_StaticMatplotlib(*argv):
 	Settings    = open(os.path.join(Pathes.SolutionPath, ParametersId, "Res"+str(argv[3]).replace(".","_"), "RawResults","UsedSettings.txt"), "r")
 	LightExport = int(re.split(" |\t", Settings.readlines()[20])[0])
 	Settings.close()
-
+	
+	# Load the mesh once for all
+	if len(times)>0: Mesh, ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], times[0], 1)
+	
 	# Loop on the wished times
 	for t in times:
 		# Load the solution
-		Mesh, ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], t)
+		ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], t, 0)
 
 		# Batch the plotting routines
 		for VariableId in range(Problem.GoverningEquations.NbVariables):
@@ -321,10 +334,13 @@ def Plot_DebugMatplotlib(*argv):
 	LightExport = int(re.split(" |\t", Settings.readlines()[20])[0])
 	Settings.close()
 
+	# Load the mesh once for all
+	if len(times)>0: Mesh, ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], times[0], 1)
+
 	# Loop on the wished times
 	for t in times:
 		# Load the solution
-		Mesh, ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], t)
+		ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], t, 0)
 
 		# Batch the plotting routines
 		PMP.PlotFlags(Problem, Mesh, Solution,  ParametersId)
@@ -398,10 +414,13 @@ def Plots_StaticPlotly(*argv):
 	LightExport = int(re.split(" |\t", Settings.readlines()[20])[0])
 	Settings.close()
 
+	# Load the mesh once for all
+	if len(times)>0: Mesh, ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], times[0], 1)
+
 	# Loop on the wished times
 	for t in times:
 		# Load the solution
-		Mesh, ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], t)
+		ProblemData, Problem, Solution = EX.LoadSolution(LightExport, ParametersId, argv[3], t, 0)
 
 		# Generating the batch plots
 		PLP.PlotEachLevelSet(Mesh, Solution, ParametersId)
diff --git a/SourceCode/PostProcessing/Exports.py b/SourceCode/PostProcessing/Exports.py
index 2e0736f..c576fa8 100644
--- a/SourceCode/PostProcessing/Exports.py
+++ b/SourceCode/PostProcessing/Exports.py
@@ -62,7 +62,7 @@ def ExportSolution(LightExport, TestCase, Mesh, ProblemData, Problem, Solution):
     else:                    ExportSolutionMeshFree (TestCase, Mesh, ProblemData, Problem, Solution)
 
 #### Load the file that has been exported in binary pickle format #####
-def LoadSolution(LightExport, TestCase, Resolution, t):
+def LoadSolution(LightExport, TestCase, Resolution, t, ReturnMesh=0):
     """ Load the file that has been exported in binary pickle format, , paying attention if the user wants to export the mesh inside the
     binary file or not.
 
@@ -71,6 +71,7 @@ def LoadSolution(LightExport, TestCase, Resolution, t):
         TestCase     (string):     name of the folder in which the solutions are stored
         Resolution   (integer):    resolution of the associated mesh
         t            (float):      time for which to load the solution
+        ReturnMesh   (integer):    (optional, default 0) in case of a light export, give the possibility to load the mesh along with the solution (1) or not (0).
 
     Returns:
         Mesh          (MeshStructure instance):           mesh on which the solution has been computed
@@ -83,8 +84,8 @@ def LoadSolution(LightExport, TestCase, Resolution, t):
         This routine loads a binary file that has been generated by pickles. To work, the used structures should already be known by the programm by the loading time.
     """
 
-    if     LightExport == 0: return(LoadSolutionPlainMesh(TestCase, Resolution, t))
-    else:                    return(LoadSolutionMeshFree (TestCase, Resolution, t))
+    if     LightExport == 0: return(LoadSolutionPlainMesh(TestCase, Resolution, t, ReturnMesh))
+    else:                    return(LoadSolutionMeshFree (TestCase, Resolution, t, ReturnMesh))
 
 
 
@@ -169,13 +170,14 @@ def ExportUsedMesh(TestCase, Mesh):
 # ==============================================================================
 
 #### Load the file that has been exported in binary pickle format #####
-def LoadSolutionPlainMesh(TestCase, Resolution, t):
+def LoadSolutionPlainMesh(TestCase, Resolution, t, ReturnMesh=1):
     """ Load the file that has been exported in binary pickle format
 
     Args:
         TestCase     (string):    name of the folder in which the solutions are stored
         Resolution   (integer):   resolution of the associated mesh
         t            (float):     time for which to load the solution
+        ReturnMesh   (integer):   selects if the mesh has to be collected (1) or not (0)
 
     Returns:
         Mesh          (MeshStructure instance):           mesh on which the solution has been computed
@@ -196,7 +198,8 @@ def LoadSolutionPlainMesh(TestCase, Resolution, t):
     Mesh, ProblemData, Problem, Solution = np.load(FileName, allow_pickle=True)
 
     # Returning all the instances in a list
-    return([Mesh, ProblemData, Problem, Solution])
+    if ReturnMesh: return([Mesh, ProblemData, Problem, Solution])
+    else:          return([ProblemData, Problem, Solution])
 
 #### Export the solution in a binary pickle format #####
 def ExportSolutionPlainMesh(TestCase, Mesh, ProblemData, Problem, Solution):
@@ -231,13 +234,14 @@ def ExportSolutionPlainMesh(TestCase, Mesh, ProblemData, Problem, Solution):
     ToWrite.close()
 
 #### Load the file that has been exported in binary pickle format #####
-def LoadSolutionMeshFree(TestCase, Resolution, t):
+def LoadSolutionMeshFree(TestCase, Resolution, t, ReturnMesh=0):
     """ Load the file that has been exported in binary pickle format without the mesh in the structure
 
     Args:
         TestCase     (string):    name of the folder in which the solutions are stored
         Resolution   (integer):   resolution of the associated mesh
         t            (float):     time for which to load the solution
+        ReturnMesh   (integer):   selects if the mesh has to be collected (1) or not (0)
 
     Returns:
         Mesh          (MeshStructure instance):           mesh on which the solution has been computed
@@ -258,17 +262,20 @@ def LoadSolutionMeshFree(TestCase, Resolution, t):
     MeshInfo, ProblemData, Problem, Solution = np.load(FileName, allow_pickle=True)
 
     # Retrieving the mesh by first looking in the solution folder, in the mesh folder then
-    try:     Mesh = Meshing.Meshing_DualMesh.DualMesh(os.path.join(Folder,"UsedMesh.pyMsh")).Mesh
-    except:
-        print("User WARNING: No binary mesh found in the solution folder. Loading the corresponding one in the mesh folder.")
-        Mesh = Meshing.Meshing_DualMesh.DualMesh(*MeshInfo).Mesh
-
-    # Checking that the mesh is the one considered
-    if not (MeshInfo[0] == Mesh.MeshName and Mesh.MeshOrder == MeshInfo[1] and Mesh.MeshDofsType == MeshInfo[2] and Mesh.MeshResolution == MeshInfo[3]):
-        raise(RunTimeError("The mesh stored in the solution folder does not correspond to the mesh the solution has been obtained on. Abortion"))
-
-    # Returning all the instances in a list
-    return([Mesh, ProblemData, Problem, Solution])
+    if ReturnMesh:
+        try:     Mesh = Meshing.Meshing_DualMesh.DualMesh(os.path.join(Folder,"UsedMesh.pyMsh")).Mesh
+        except:
+            print("User WARNING: No binary mesh found in the solution folder. Loading the corresponding one in the mesh folder.")
+            Mesh = Meshing.Meshing_DualMesh.DualMesh(*MeshInfo).Mesh
+
+        # Checking that the mesh is the one considered
+        if not (MeshInfo[0] == Mesh.MeshName and Mesh.MeshOrder == MeshInfo[1] and Mesh.MeshDofsType == MeshInfo[2] and Mesh.MeshResolution == MeshInfo[3]):
+            raise(RunTimeError("The mesh stored in the solution folder does not correspond to the mesh the solution has been obtained on. Abortion"))
+
+        # Returning all the instances in a list
+        return([Mesh, ProblemData, Problem, Solution])
+    
+    else: return([ProblemData, Problem, Solution])
 
 #### Export the solution in a binary pickle format #####
 def ExportSolutionMeshFree(TestCase, Mesh, ProblemData, Problem, Solution):
-- 
GitLab