loliverhennigh / Computational-Fluid-Dynamics-Machine-Learning-Examples

This repo contains some tutorial type programs showing some basic ways machine learning can be applied to CFD.
273 stars 90 forks source link

img_data.Update() not working because of update in VTK 6 #1

Open vishwesh5 opened 6 years ago

vishwesh5 commented 6 years ago

Hi

According to the update made in VTK 6, the Update() function can be called only on objects which have been derived from the vtkAlgorithm class. Thus, img_data.Update() in train/vtm_data.py is giving errors. Can this be fixed?

mechamind commented 3 years ago

Using the two functions will help resolve this problem.

Regards

def readMultiBlockGeometry(filename):
    reader = vtk.vtkXMLMultiBlockDataReader()
    reader.SetFileName(filename)
    reader.Update()
    mb = reader.GetOutput()
    data_iterator = mb.NewIterator()
    img_data = data_iterator.GetCurrentDataObject()
    img_shape = img_data.GetExtent()
    point_data = img_data.GetPointData()   
    array_data = point_data.GetArray(0)
    np_array = vtk_to_numpy(array_data)
    np_shape = [img_shape[3] - img_shape[2] + 1, img_shape[1] - img_shape[0] + 1, 1]
    img_array = np_array.reshape(np_shape)
    return img_array

def readMultiBlockVelocityAndPressure(filename):
    reader = vtk.vtkXMLMultiBlockDataReader()
    reader.SetFileName(filename)
    reader.Update()
    mb = reader.GetOutput()
    data_iterator = mb.NewIterator()
    img_data = data_iterator.GetCurrentDataObject()
    img_shape = img_data.GetExtent()
    img_shape = img_data.GetExtent()
    velocity_np_shape = [img_shape[3] - img_shape[2] + 1, img_shape[1] - img_shape[0] + 1, 2]
    pressure_np_shape = [img_shape[3] - img_shape[2] + 1, img_shape[1] - img_shape[0] + 1, 1]    
    point_data = img_data.GetPointData()
    velocity_array_data = point_data.GetArray(0)
    pressure_array_data = point_data.GetArray(1)
    velocity_np_array = vtk_to_numpy(velocity_array_data)
    pressure_np_array = vtk_to_numpy(pressure_array_data)
    velocity_np_array = velocity_np_array.reshape(velocity_np_shape)
    pressure_np_array = pressure_np_array.reshape(pressure_np_shape)
    steady_flow_array = np.concatenate([velocity_np_array, pressure_np_array], axis=2)
    return steady_flow_array

geometry_array = readMultiBlockGeometry(geometry_file)
if np.isnan(geometry_array).any():
    continue

steady_flow_array = readMultiBlockVelocityAndPressure(steady_flow_file)
if np.isnan(steady_flow_array).any():
    continue
IT-five commented 2 years ago

使用这两个函数将有助于解决这个问题。

问候

def readMultiBlockGeometry(filename):
    reader = vtk.vtkXMLMultiBlockDataReader()
    reader.SetFileName(filename)
    reader.Update()
    mb = reader.GetOutput()
    data_iterator = mb.NewIterator()
    img_data = data_iterator.GetCurrentDataObject()
    img_shape = img_data.GetExtent()
    point_data = img_data.GetPointData()   
    array_data = point_data.GetArray(0)
    np_array = vtk_to_numpy(array_data)
    np_shape = [img_shape[3] - img_shape[2] + 1, img_shape[1] - img_shape[0] + 1, 1]
    img_array = np_array.reshape(np_shape)
    return img_array

def readMultiBlockVelocityAndPressure(filename):
    reader = vtk.vtkXMLMultiBlockDataReader()
    reader.SetFileName(filename)
    reader.Update()
    mb = reader.GetOutput()
    data_iterator = mb.NewIterator()
    img_data = data_iterator.GetCurrentDataObject()
    img_shape = img_data.GetExtent()
    img_shape = img_data.GetExtent()
    velocity_np_shape = [img_shape[3] - img_shape[2] + 1, img_shape[1] - img_shape[0] + 1, 2]
    pressure_np_shape = [img_shape[3] - img_shape[2] + 1, img_shape[1] - img_shape[0] + 1, 1]    
    point_data = img_data.GetPointData()
    velocity_array_data = point_data.GetArray(0)
    pressure_array_data = point_data.GetArray(1)
    velocity_np_array = vtk_to_numpy(velocity_array_data)
    pressure_np_array = vtk_to_numpy(pressure_array_data)
    velocity_np_array = velocity_np_array.reshape(velocity_np_shape)
    pressure_np_array = pressure_np_array.reshape(pressure_np_shape)
    steady_flow_array = np.concatenate([velocity_np_array, pressure_np_array], axis=2)
    return steady_flow_array

geometry_array = readMultiBlockGeometry(geometry_file)
if np.isnan(geometry_array).any():
  continue

steady_flow_array = readMultiBlockVelocityAndPressure(steady_flow_file)
if np.isnan(steady_flow_array).any():
  continue

Hello, I want to train a network in predicting the steady state flow velocity vector field and pressure field ,so i run keras_steady_flow_predictor.py,in that I found that len(train_geometries) = 0, so there should be a problem with my data set path, and everything else succeeded. If you see it, please take a look at it. Thank you very much. I will put the error picture Link below,Thank you! https://stshoueducn-my.sharepoint.com/:f:/g/personal/m210911561_st_shou_edu_cn/EiB_9KBrt99Cjms93It_h7ABbd4ZxsubKE86TQSo0B4e3w?e=fhfGRH

IT-five commented 2 years ago

你好

根据 VTK 6 的更新, Update()只能在派生自对象的对象上调用函数 vtkAlgorithm班级。 因此, img_data.Update()train/vtm_data.py 中出现错误。 这可以解决吗?

Did you finally solve this problem? What should I do?