Skip to content

Postprocess and visualize CHT flow over plate results #199

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

Merged
merged 9 commits into from
Apr 13, 2021

Conversation

BenjaminRodenberg
Copy link
Member

@BenjaminRodenberg BenjaminRodenberg commented Apr 13, 2021

Similar to #196, just for a different case. In the end we want to plot the temperature across the coupling interface.

What kind of plot?

image

In the end we want a plot similar to the one above taken from Fig3c from this paper, but automatically generated from the preCICE output data. Note that this will restrict us to the coupling interface, i.e. the interval x = [0,1] and not the whole bottom of the channel x = [-0.5,3].

What we get with this PR:

tutorials-flow-over-heated-plate-results-comparison

@BenjaminRodenberg BenjaminRodenberg self-assigned this Apr 13, 2021
@BenjaminRodenberg BenjaminRodenberg changed the base branch from master to develop April 13, 2021 12:55
@BenjaminRodenberg
Copy link
Member Author

@oguzziya knows a different approach to this problem. Maybe worth switching to it?

@oguzziya
Copy link

oguzziya commented Apr 13, 2021

If the script is that long, it might not worth the hassle. However, if we gonna have different kinds of VTK files, such as unstructured, structured, etc. It might be a good approach. PyVista is pretty handy to manipulate the data. For example, the following snippet is a code that I use in general to obtain a contour plot. The good thing is, you can obtain pretty flexible plots combining with matplotlib, especially good for papers (LaTeX, pdf output, etc.) I have also scripts to plot data along an axis and comparing it with an experimental data but the approach is basically the same.

def contour_plot(self, file_path, field_name, save_name=None, cmap="bone"):
     mesh = pv.read(file_path) 
    midplane = mesh.ctp().slice(normal=self.axis[self.directions["tangential"]], generate_triangles=True)
   
    midplane.active_scalars_name = field_name

    x = midplane.points
    tri = midplane.faces.reshape((-1,4))[:, 1:]
    data = midplane.active_scalars

    data_max = round(float(np.max(data)) / 10) * 10
    data_min = int(float(np.min(data)) / 10) * 10

# Rest is matplotlib
    fig = plt.figure(figsize=(20, 5))
    ax = fig.add_subplot(1,1,1)
    cont = ax.tricontourf(x[:, self.directions["axial"]], x[:, self.directions["radial"]], tri, data, levels=np.linspace(data_min, data_max, 39), cmap=cmap)
    cbar = fig.colorbar(cont, ax=ax)
    cbar.set_ticks(np.linspace(data_min, data_max, 5, endpoint=True))
    ax.set_yticklabels([])
    ax.set_yticks([])
    ax.set_label(field_name)
    cbar.set_label(field_name, fontsize=20)
    if save_name is not None:
      fig.savefig(save_name + ".png", dpi=300)

@BenjaminRodenberg
Copy link
Member Author

@oguzziya Never heard about PyVista. This looks so much more reasonable than plain vtk code (which is a nightmare). Thanks for the hint!

@BenjaminRodenberg BenjaminRodenberg marked this pull request as ready for review April 13, 2021 16:08
Copy link
Member

@uekerman uekerman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 👌 Works like a charm.
Small comments:

  • Please add the dependency vtk in the README (and how to get it normally from PyPI). matplotlib as well?
  • example.vtk can be deleted, right?

and see below.
Please merge after fixing these.

@BenjaminRodenberg BenjaminRodenberg merged commit bd447d7 into develop Apr 13, 2021
@BenjaminRodenberg BenjaminRodenberg deleted the cht_vtk_postproc branch April 13, 2021 17:43
BenjaminRodenberg added a commit that referenced this pull request Apr 13, 2021
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

Successfully merging this pull request may close these issues.

3 participants