From 3ef6c4873eeeffa00ce678c9f6c739f481b76052 Mon Sep 17 00:00:00 2001
From: acrovato <a.crovato@uliege.be>
Date: Mon, 1 Jul 2024 10:50:29 +0200
Subject: [PATCH] Add z coordinate to slices

---
 sdpm/utils.py | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/sdpm/utils.py b/sdpm/utils.py
index 7e432f6..dd7da0d 100644
--- a/sdpm/utils.py
+++ b/sdpm/utils.py
@@ -91,9 +91,12 @@ def create_slices(body, sol, fname, ys):
     for i in range(len(ys)):
         # get data on cut section
         coords, connct, cvalues = extract_data(cut_grid(grid, [0., ys[i], 0.]), snames)
-        # normalize x-coordinate by local chord
-        xc = np.zeros((coords.shape[0], 1))
-        xc[:,0] = (coords[:,0] - min(coords[:,0])) / (max(coords[:,0]) - min(coords[:,0]))
+        # normalize x and z-coordinates by local chord
+        xc = np.zeros((coords.shape[0], 2))
+        ile = np.argmin(coords[:,0]) # LE index
+        crd = max(coords[:,0]) - min(coords[:,0]) # chord
+        xc[:,0] = (coords[:,0] - coords[ile,0]) / crd
+        xc[:,1] = (coords[:,2] - coords[ile,2]) / crd
         # average value at points from values at cell center
         nvalues = np.zeros((coords.shape[0], len(sol.keys())))
         for j in range(connct.shape[0]):
@@ -101,16 +104,16 @@ def create_slices(body, sol, fname, ys):
             for k in range(len(pids)):
                 for l in range(len(sol.keys())):
                     nvalues[connct[j][k], l] += cvalues[snames[l]][j] / len(pids)
-        # create dataset holding x-coordinates and values and sort it
+        # create dataset holding coordinates and values and sort it
         xc_vals = np.hstack((xc, nvalues))
         sort(connct, xc_vals)
         xc_vals = np.vstack((xc_vals, xc_vals[0,:]))
         # write to file
-        hdr = 'x/c'
+        hdr = f'y = {ys[i]}, c = {crd}\n'
+        hdr += '{:>9s}, {:>10s}'.format('x/c', 'z/c')
         for name in snames:
-            hdr += f', {name}'
-        hdr += f'\ny = {ys[i]}'
-        np.savetxt(fname+f'_slice_{i}.dat', xc_vals, fmt='%1.5e', delimiter=',', header=hdr)
+            hdr += ', {:>10s}'.format(name)
+        np.savetxt(fname+f'_slice_{i}.dat', xc_vals, fmt='%+1.4e', delimiter=',', header=hdr)
 
 def interpolate_modes(fname, surf_nodes, flat=True):
     """Read modal displacements and interpolate them on surface grid
-- 
GitLab