krafiq commited on
Commit
21ef528
·
1 Parent(s): a7f788f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -6,7 +6,6 @@ import numpy as np
6
  import matplotlib.pyplot as plt
7
  import gradio as gr
8
 
9
- # Creating a numpy array of shape (8, 16, 1)
10
  flow_field = np.ones((128,256), dtype = np.uint8)
11
 
12
  # Changing the left input side
@@ -18,6 +17,14 @@ flow_field[0,:] = 2
18
  # Changing the bottom layer
19
  flow_field[-1,:] = 2
20
 
 
 
 
 
 
 
 
 
21
  def nvs_loss(y_pred, rho=10, nu=0.0001): #arbitary rho and nu(Later use values of air)
22
  u,v,p = tf.split(y_pred, 3, axis=3)
23
 
@@ -172,7 +179,6 @@ def fill_shape_with_pixels(img): #img is taken by gradio as uint8
172
  test_img = patch_stiching(flooded_image, h, w, x0, y0)
173
 
174
  # Loading and Compiling the Model
175
- #model_path = "/content/drive/MyDrive/Pinns_Loss_file.h5"
176
  model_path = "Pinns_Loss_file.h5"
177
  model = load_model(model_path, compile = False)
178
  model.compile(loss=custom_loss, optimizer=tf.keras.optimizers.AdamW(learning_rate = 0.0001), metrics=['mae', 'cosine_proximity'])
@@ -181,6 +187,11 @@ def fill_shape_with_pixels(img): #img is taken by gradio as uint8
181
  prediction = model.predict(test_img) # (prediction.shape = (1, 128, 256, 3))
182
  u_pred, v_pred, p_pred = np.split(prediction, 3, axis=3) # shape of u_pred, v_pred, p_pred = (1, 128, 256, 1)
183
 
 
 
 
 
 
184
  # Making test_img in shape required by zero_pixel_location
185
  req_img = squeeze_function(test_img)
186
 
@@ -192,7 +203,10 @@ def fill_shape_with_pixels(img): #img is taken by gradio as uint8
192
  u_profile = u_pred[0][:,:,0] # shape of u profile to compatible shape (H, W) = (128, 256)
193
  v_profile = v_pred[0][:,:,0]
194
  p_profile = p_pred[0][:,:,0]
195
- p_profile[p_profile>1.6] = 1.6
 
 
 
196
 
197
  # Creating a copy of the above profiles-
198
  u_profile_dash = np.copy(u_profile)
@@ -217,7 +231,7 @@ def fill_shape_with_pixels(img): #img is taken by gradio as uint8
217
  velocity = np.sqrt(u_profile_dash_1**2 + v_profile_dash_1**2)
218
  ax = plt.subplot()
219
  ax.imshow(velocity, cmap = 'gray', extent = (0,256, 0,128))
220
- q = ax.quiver(X[5::7,5::7], Y[5::7,5::7], u_profile_dash[5::7,5::7], v_profile_dash[5::7,5::7], pivot = 'middle', color = 'red')
221
  ax.quiverkey(q, X=0.9, Y=1.07, U=2,
222
  label='m/s', labelpos='E')
223
  plt.title("Velocity distribution", fontsize = 11)
@@ -226,7 +240,7 @@ def fill_shape_with_pixels(img): #img is taken by gradio as uint8
226
 
227
  # StreamLine Plot
228
  streamline_plot = plt.figure(figsize = (14,6), edgecolor = "gray")
229
- plt.streamplot(X, Y, u_profile_dash, v_profile_dash, density = 3.5)
230
  plt.axis('scaled')
231
  plt.title("Streamline Plot", fontsize = 11)
232
  plt.xlabel("Length of Channel", fontsize = 11)
@@ -248,9 +262,10 @@ def fill_shape_with_pixels(img): #img is taken by gradio as uint8
248
  with gr.Blocks(theme="Taithrah/Minimal") as demo:
249
  gr.Markdown(
250
  """
251
- # Physics Constrained DNN for Predicting Mean Turbulent Flows
252
  The App solves 2-D incompressible steady state NS equations for any given 2-D closed geometry. Geometry needs to be drawn around the center of the patch.\n
253
  It predicts the streamlines,horizontal & vertical velocity profiles and the pressure profiles using a hybrid loss function.\n
 
254
  """)
255
  with gr.Row():
256
  with gr.Column():
 
6
  import matplotlib.pyplot as plt
7
  import gradio as gr
8
 
 
9
  flow_field = np.ones((128,256), dtype = np.uint8)
10
 
11
  # Changing the left input side
 
17
  # Changing the bottom layer
18
  flow_field[-1,:] = 2
19
 
20
+ mean_u = 0.075003795
21
+ mean_v = -0.000036
22
+ mean_p = 0.004301
23
+
24
+ std_dev_u = 0.04605
25
+ std_dev_v = 0.013812
26
+ std_dev_p = 0.007917
27
+
28
  def nvs_loss(y_pred, rho=10, nu=0.0001): #arbitary rho and nu(Later use values of air)
29
  u,v,p = tf.split(y_pred, 3, axis=3)
30
 
 
179
  test_img = patch_stiching(flooded_image, h, w, x0, y0)
180
 
181
  # Loading and Compiling the Model
 
182
  model_path = "Pinns_Loss_file.h5"
183
  model = load_model(model_path, compile = False)
184
  model.compile(loss=custom_loss, optimizer=tf.keras.optimizers.AdamW(learning_rate = 0.0001), metrics=['mae', 'cosine_proximity'])
 
187
  prediction = model.predict(test_img) # (prediction.shape = (1, 128, 256, 3))
188
  u_pred, v_pred, p_pred = np.split(prediction, 3, axis=3) # shape of u_pred, v_pred, p_pred = (1, 128, 256, 1)
189
 
190
+ # De-Normalizing teh Data:
191
+ u_pred = ((u_pred*std_dev_u) + mean_u)
192
+ v_pred = ((v_pred*std_dev_v) + mean_v)
193
+ p_pred = ((p_pred*std_dev_p) + mean_p)
194
+
195
  # Making test_img in shape required by zero_pixel_location
196
  req_img = squeeze_function(test_img)
197
 
 
203
  u_profile = u_pred[0][:,:,0] # shape of u profile to compatible shape (H, W) = (128, 256)
204
  v_profile = v_pred[0][:,:,0]
205
  p_profile = p_pred[0][:,:,0]
206
+ p_profile[p_profile>0.02] = 0.02
207
+ hist, bins = np.histogram(p_profile, bins=20)
208
+ print(hist)
209
+ print(bins)
210
 
211
  # Creating a copy of the above profiles-
212
  u_profile_dash = np.copy(u_profile)
 
231
  velocity = np.sqrt(u_profile_dash_1**2 + v_profile_dash_1**2)
232
  ax = plt.subplot()
233
  ax.imshow(velocity, cmap = 'gray', extent = (0,256, 0,128))
234
+ q = ax.quiver(X[5::5,5::5], Y[5::5,5::5], u_profile_dash[5::5,5::5], v_profile_dash[5::5,5::5], pivot = 'middle', color = 'red')
235
  ax.quiverkey(q, X=0.9, Y=1.07, U=2,
236
  label='m/s', labelpos='E')
237
  plt.title("Velocity distribution", fontsize = 11)
 
240
 
241
  # StreamLine Plot
242
  streamline_plot = plt.figure(figsize = (14,6), edgecolor = "gray")
243
+ plt.streamplot(X, Y, u_profile_dash, v_profile_dash, density = 4)
244
  plt.axis('scaled')
245
  plt.title("Streamline Plot", fontsize = 11)
246
  plt.xlabel("Length of Channel", fontsize = 11)
 
262
  with gr.Blocks(theme="Taithrah/Minimal") as demo:
263
  gr.Markdown(
264
  """
265
+ # Channel Flow - Physics Constrained DNN for Predicting Mean Turbulent Flows
266
  The App solves 2-D incompressible steady state NS equations for any given 2-D closed geometry. Geometry needs to be drawn around the center of the patch.\n
267
  It predicts the streamlines,horizontal & vertical velocity profiles and the pressure profiles using a hybrid loss function.\n
268
+ Model Parameters (In SI Units) - Kinematic Viscosity = 0.0001, Input horizontal velocity = 0.075, Input vertical velocity = 0
269
  """)
270
  with gr.Row():
271
  with gr.Column():