Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vector data as Point data in mesh #448

Open
davidcortesortuno opened this issue Jun 23, 2021 · 4 comments
Open

Add vector data as Point data in mesh #448

davidcortesortuno opened this issue Jun 23, 2021 · 4 comments

Comments

@davidcortesortuno
Copy link

Description

Hi, I'm loading data from a tecplot file which is read successfully. This data is shown as
image

Is there a way to add a new Data Array as Point data? I tried using add_field

mesh.add_field_array(np.column_stack((mesh.get_array('Mx'),
                                      mesh.get_array('My'),
                                      mesh.get_array('Mz'))),
                     name='M_vec')

but this creates a Fields and not a Points field:

image

I finally tried

mesh.vectors = np.column_stack((mesh.get_array('Mx'),
                                      mesh.get_array('My'),
                                      mesh.get_array('Mz')))

which produces what I was expecting,

image

However I cannot set a name to the data with this method. Is this the way to do it or is there a better function/method to do this?

@MatthewFlamm
Copy link

MatthewFlamm commented Jun 23, 2021

You can try:

mesh["my_vector_name"] = np.column_stack((mesh.get_array('Mx'),
                                          mesh.get_array('My'),
                                          mesh.get_array('Mz'))
mesh.set_active_vectors("my_vector_name")  # not strictly neccessary, but it will replicate the mesh.vectors usage.

See here:

https://github.com/pyvista/pyvista/blob/274261f684aad2d9f2ce5dcf9c864a7cf2ca2c5a/pyvista/core/dataset.py#L247-L258

@davidcortesortuno
Copy link
Author

Thanks, I just realised I can also do

mesh.point_arrays.update(dict(M_vec=np.column_stack((mesh.get_array('Mx'),
                                                     mesh.get_array('My'),
                                                     mesh.get_array('Mz')))))

@MatthewFlamm
Copy link

Your method is basically the same as mine above, when doing mesh["M_vec"] = vector_data, but your usage will only work for point_data, whereas this usage will work for both point and cell data.

To summarize, you can add data with:

mesh.point_arrays.update(dict(name=point_data))
mesh.cell_arrays.update(dict(name=cell_data))
mesh["name"] = point_data
mesh["name"] = cell_data

mesh.vectors = point_data
mesh.vectors = cell_data

I tend to use the mesh["name"] = data method as it is the most flexible. I find the mesh.vectors usage to be confusing. There should be a limited number of ways to add data.

@MatthewFlamm
Copy link

I was incorrect, mesh.vectors = cell_data will not work since it adds to mesh.point_arrays. This is a bug, although I'd prefer this whole functionality to be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants