问题描述
我正在尝试计算多相流设置(固体浸入流体中)中3D速度场的发散度。如果我们假设u
,v
,w
是三个3D numpy数组的速度分量(每个n x n x n
),这是我计算散度的函数: / p>
def calc_divergence_velocity(df,h=0.025):
"""
@param df: A dataframe with the entire vector field with columns [x,y,z,u,v,w] with
x,z indicating the 3D coordinates of each point in the field and u,w
the velocities in the x,z directions respectively.
@param h: This is the dimension of a single side of the 3D (uniform) grid. Used
as input to numpy.gradient() function.
"""
"""
Reshape dataframe columns to get 3D numpy arrays (dim = 80) so each u,w is a
80x80x80 ndarray.
"""
u = df['u'].values.reshape((dim,dim,dim))
v = df['v'].values.reshape((dim,dim))
w = df['w'].values.reshape((dim,dim))
#Supply x,z coordinates appropriately.
#Note: Only a scalar `h` has been supplied to np.gradient because
#the type of grid we are dealing with is a uniform grid with each
#grid cell having the same dimensions in x,z directions.
u_grad = np.gradient(u,h,axis=0) #central diff. du_dx
v_grad = np.gradient(v,axis=1) #central diff. dv_dy
w_grad = np.gradient(w,axis=2) #central diff. dw_dz
"""
The `mask` column in the dataframe is a binary column indicating the locations
in the field where we are interested in measuring divergence.
The problem I am looking at is multi-phase flow with solid particles and a fluid
hence we are only interested in the fluid locations.
"""
sdf = df['mask'].values.reshape((dim,dim))
div = (u_grad*sdf) + (v_grad*sdf) + (w_grad*sdf)
return div
我遇到的问题是我看到的差异值太高。 例如,下面的图片展示了一个值在[-350,350]之间的分布,而在我的情况下,大多数值在技术上应该接近零,并且在[20,-20]之间。这告诉我我不正确地计算了偏差,并且我希望获得一些有关如何更正上述函数以正确计算偏差的指标。据我所知(如果我错了,请纠正我),我认为所做的工作类似于this赞成SO响应。预先感谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)