# Help code to obtain the wall velocity

Hi guys, all right? I would like to know if someone can help me with the following problem. I am starting to use python and I am trying to find a second order polynomial fit to find the value of the velocity on the wall, i.e. the value of the velocity at a value of r/D=0.5 and r/D=-0.5 . My code allows me to obtain the second order polynomial (P1 in the photo) and I can calculate the value of the speed r/D 0.5 (side of positive values) (see photo), but I cannot evaluate the data with my polynomial on the side of negative values, that is, when r/D= -0.5 (negative side)

Could you help me get the side

Python code

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

import os

class fluido_NN:
def init(self):
sep=“\s+”,
)
sep=“\s+”,
)
sep=“\s+”,
)

``````    self.df1 = df1.rename(columns={0: "velocity", 1: "diameter"})
self.df2 = df2.rename(columns={0: "velocity", 1: "diameter"})
self.df3 = df3.rename(columns={0: "velocity", 1: "diameter"})

def get_value_closest_to(self, wall):
# print(min(df1["diameter"] - 0.5))
val_closest_to_zero_df1 = min((abs(x), x) for x in self.df1["diameter"] - wall)[
1
]
idx_1 = self.df1.index[self.df1["diameter"] == val_closest_to_zero_df1 + wall]
idx_closest_to_zero_df1 = idx_1.to_list()
idx_closest_to_zero_df1 = [str(item) for item in idx_closest_to_zero_df1]
idx_closest_to_zero_df1 = "".join(idx_closest_to_zero_df1)
self.idx_closest_to_zero_df1 = int(idx_closest_to_zero_df1)

val_closest_to_zero_df2 = min((abs(x), x) for x in self.df2["diameter"] - wall)[
1
]
idx_2 = self.df2.index[self.df2["diameter"] == val_closest_to_zero_df2 + wall]
idx_closest_to_zero_df2 = idx_2.to_list()
idx_closest_to_zero_df2 = [str(item) for item in idx_closest_to_zero_df2]
idx_closest_to_zero_df2 = "".join(idx_closest_to_zero_df2)
self.idx_closest_to_zero_df2 = int(idx_closest_to_zero_df2)

val_closest_to_zero_df3 = min((abs(x), x) for x in self.df3["diameter"] - wall)[
1
]
idx_3 = self.df3.index[self.df3["diameter"] == val_closest_to_zero_df3 + wall]
idx_closest_to_zero_df3 = idx_3.to_list()
idx_closest_to_zero_df3 = [str(item) for item in idx_closest_to_zero_df3]
idx_closest_to_zero_df3 = "".join(idx_closest_to_zero_df3)
self.idx_closest_to_zero_df3 = int(idx_closest_to_zero_df3)

return (
self.idx_closest_to_zero_df1,
self.idx_closest_to_zero_df2,
self.idx_closest_to_zero_df3,
)

def plot_closest_to_wall(self):

# Dataset 1
y1 = self.df1["velocity"].iloc[
self.idx_closest_to_zero_df1 - 3 : self.idx_closest_to_zero_df1
]
``````

# x1 = np.arange(1, len(y1) + 1)

``````    x1 = self.df1["diameter"].iloc[
self.idx_closest_to_zero_df1 - 3 : self.idx_closest_to_zero_df1
]
print(x1.iloc[:])
print(y1)

model1 = np.poly1d(np.polyfit(x1, y1, 2))
print(f"\nModel1: {model1}")
print("Model1 at x = 0.5 : ", model1(0.5))

line1 = np.linspace(x1.iloc[0], x1.iloc[-1], 100)
print(line1)

plt.subplot(1, 3, 1)
plt.scatter(x1, y1)
plt.plot(line1, model1(line1))

# Dataset 2
y2 = self.df2["velocity"].iloc[
self.idx_closest_to_zero_df2 - 3 : self.idx_closest_to_zero_df2
]
``````

# x2 = np.arange(1, len(y2) + 1)

``````    x2 = self.df2["diameter"].iloc[
self.idx_closest_to_zero_df2 - 3 : self.idx_closest_to_zero_df2
]

model2 = np.poly1d(np.polyfit(x2, y2, 2))
print(f"\nModel2: {model2}")
print("Model2 at x = 0.5 : ", model2(0.5))
``````

# line2 = np.linspace(0, 4, 100)

``````    line2 = np.linspace(x2.iloc[0], x2.iloc[-1], 100)

plt.subplot(1, 3, 2)
plt.scatter(x2, y2)
plt.plot(line2, model2(line2))

# Dataset 3
y3 = self.df3["velocity"].iloc[
self.idx_closest_to_zero_df3 - 3 : self.idx_closest_to_zero_df3
]
``````

# x3 = np.arange(1, len(y3) + 1)

``````    x3 = self.df3["diameter"].iloc[
self.idx_closest_to_zero_df3 - 3 : self.idx_closest_to_zero_df3
]

model3 = np.poly1d(np.polyfit(x3, y3, 2))
print(f"\nModel3: {model3}")
print("Model3 at x = 0.5 : ", model3(0.5))
``````

# line3 = np.linspace(0, 4, 100)

``````    line3 = np.linspace(x3.iloc[0], x3.iloc[-1], 100)

plt.subplot(1, 3, 3)
plt.scatter(x3, y3)
plt.plot(line3, model3(line3))
plt.show()

def calcular_PIV(
self,
NUM_PIXELS=1,
DISTANCIA_METROS=0.000027,
TEMPO_ENTRE_PULSES=0.2,
CONSTANTE_ERRO=0.1,
):
self.PIV = (CONSTANTE_ERRO * DISTANCIA_METROS / NUM_PIXELS) / TEMPO_ENTRE_PULSES
print(self.PIV)
return self.PIV

def calcular_erro_geral(self, salvar_csv=False):
Mean_velocity=0.2846
df_dict = {}
df_dict["velocity_mean_df1"] = self.df1["velocity"]
df_dict["std_mean_df1"] = self.df1["velocity"]

df_dict["velocity_mean_df2"] = self.df2["velocity"]
df_dict["std_mean_df2"] = self.df2["velocity"]

df_dict["velocity_mean_df3"] = self.df3["velocity"]
df_dict["std_mean_df3"] = self.df3["velocity"]

df = pd.DataFrame.from_dict(df_dict)

cols_mean = ["velocity_mean_df1", "velocity_mean_df2", "velocity_mean_df3"]

df["overall_velocity_mean"] = df[cols_mean].mean(axis=1, skipna=True)

cols_std = ["std_mean_df1", "std_mean_df2", "std_mean_df3"]
df["overall_velocity_std"] = df[cols_std].std(axis=1, skipna=True)

df["PIV"] = self.PIV
df["erro_geral"] = df["PIV"] ** 2 + df["overall_velocity_std"] ** 2

print(df)
if salvar_csv:
df.to_csv("df.csv",decimal=",")
``````

calculo_fluido = fluido_NN()
calculo_fluido.get_value_closest_to(0.5)
calculo_fluido.plot_closest_to_wall()
calculo_fluido.calcular_PIV()
calculo_fluido.calcular_erro_geral(salvar_csv=True)

Sorry, your code is not formatted correctly and is all but unreadable, especially for those of use who do not understand the problem domain.

Please put your code within code fences. If you are using the rich text widget on the Discuss website, use the `</>` button. Otherwise put three backticks on a line of their own at the start and end of your code:

``````code goes here
``````

I’m afraid you are going to need to either explain the problem domain in more detail (what do you mean, “find the velocity on the wall”???) or simplify the problem, and hence your code, a lot for me to understand it.

You say that

What happens when you try? Do you get an error or something?

Please copy and paste both the code you used to evaluate the polynomial with negative values, and whatever output you get. Again, put it between code fences (three backticks), not a photo.