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

PoC / Paraview integration for mesh_doctor #16

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jafranc
Copy link

@jafranc jafranc commented Mar 27, 2024

This PR transfer from discussion on GEOS' PR #2790

This is a test to leverage mesh_doctor in Paraview either as a Python Programmable Filter or a python plugin
A example is given for element_volumes check.
It is run over the unstructured version of spe11a join here.

screenshot-PVMeshDoctor

spe11a_mesh_.zip

As a programmable filter

mesh_doctor has to be deploy in the Paraview python hierarchy so it is able to get the import path

As a python plugin

As exemplified here, going through the loading procedure allow load and access to Mesh Doctor(GEOS) as a new filter (for now only volume check is available).

Note that as stated in documentation, the test packaged mesh_doctor version has been modified so that elementVolumes.check takes a vtk mesh as input (instead of a file name) as Paraview is in charge of loading meshes here. This reduce to using the __check function included in elementVolumes.

@jafranc
Copy link
Author

jafranc commented Mar 27, 2024

Unfortunately @untereiner, PV_PLUGIN_PATH is not an option to help Paraview resolve the dependencies path. IIUC it helps with the location of the actual plugin.

Therefore, there is still a need to install from a source the packaged though it can be as a usual package and not in the Paraview python version (unlike I initially thought)

Copy link
Contributor

@TotoGaz TotoGaz left a comment

Choose a reason for hiding this comment

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

Thx!

Comment on lines 1 to 2
from paraview.util.vtkAlgorithm import *
from paraview.selection import *
Copy link
Contributor

Choose a reason for hiding this comment

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

If possible, please be specific about what you include (i.e. no *)

Comment on lines 31 to 32
from paraview.vtk import vtkIdTypeArray, vtkSelectionNode, vtkSelection, vtkCollection
from vtk import vtkExtractSelection
Copy link
Contributor

Choose a reason for hiding this comment

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

We usually try to put all the includes at the top of the file, not nested in functions.

BTW, I'm surprised you have to gather vtkExtractSelection from vtk while everything else is available from praview.vtk? I've seen a vtkPVExtractSelection available. Do you think that could make it?

Copy link
Author

Choose a reason for hiding this comment

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

Indeed I was also suprised that it is missing and TBF jumped right to the closest working version from what I already had.

I will try with vtkPVExtractSelection which should wrap the same functions as originally vtkExtractSelection

extracted.SetInputDataObject(0, mesh)
extracted.SetInputData(1, selection)
extracted.Update()
print("There are {} cells under {} m3 vol".format(extracted.GetOutput().GetNumberOfCells(), self.opt))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use a logger instead.
Maybe use f-strings as well?
Are you sure about the unit?

Copy link
Author

Choose a reason for hiding this comment

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

I will discard text printing as it is more of a debug tool for now

print("There are {} cells under {} m3 vol".format(extracted.GetOutput().GetNumberOfCells(), self.opt))
print("There are {} arrays of cell data".format(extracted.GetOutput().GetCellData().GetNumberOfArrays(), self.opt))

return extracted
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to return the extracted of some kind of extracted.GetOuput()?

Copy link
Author

Choose a reason for hiding this comment

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

I indeed only need to return a vtkUnstructuredMesh

print("1> There are {} cells under {} m3 vol".format(outData.GetNumberOfCells(), self.opt))
return 1

def _Process(self,mesh):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add type hints to your functions (if there's no problem with some python compatibility)?

Copy link
Author

Choose a reason for hiding this comment

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

Done

@jafranc
Copy link
Author

jafranc commented Apr 2, 2024

Exploring paraview ressources regarding extraction of cells, it is unclear to me what should be used or not. I didn't found any path leading to a python binding to vtkPVExtractSelection.

However, reading through sources, it seems that a self-contained path would be to flag cells that violate threshold (instead of extracting them), which is denoted as Preserve Topology here IIUC.

It can be further down extracted later through paraview | Find Cells interface.

@TotoGaz
Copy link
Contributor

TotoGaz commented Apr 2, 2024

Well that makes sense @jafranc But does that imply some refactoring in mesh_doctor then?

@jafranc
Copy link
Author

jafranc commented Apr 3, 2024

Yes it would require for the two demonstrated here element_volumes and non_conformal that their __check private be made public and rename to avoid clashes.

The other functionality would require to return iterable list of cells to flag, though with not too much effort it could be a point/node set for collocated_nodes.

self_intersecting_element would need some extra care though it is repetition of same mechanic.

@TotoGaz
Copy link
Contributor

TotoGaz commented Apr 3, 2024

Yes it would require for the two demonstrated here element_volumes and non_conformal that their __check private be made public and rename to avoid clashes.

Yes, we can handle this that's OK I think.

The other functionality would require to return iterable list of cells to flag, though with not too much effort it could be a point/node set for collocated_nodes.

Yes, in mesh_doctor we more or less always return a new mesh (IIRC).
That would have to change then (not that it's crazy complicated, but still...)

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.

2 participants