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 mesh_stats checks and field_operations features #51

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

Conversation

alexbenedicto
Copy link
Contributor

@alexbenedicto alexbenedicto commented Dec 18, 2024

Closes #50

Followed the previous work on PR #19 and closes #19.

Two features added:

  • field_operations: provides a tool to copy and create new fields on a .vtu file using a VTK file as input that contains PointData or CellData. This VTK file can either be a .vtu, .vtm or .pvd file as long as the complete geometry corresponds to the one of the .vtu file that will receive this data.
  • mesh_stats: provides a summary of mesh statistics on geometry, topology and properties painting. This is a starting point for this feature that will be enhanced to check later mesh quality.

ryar9534 and others added 30 commits July 10, 2024 17:58
…rrays available in the source data + better error handling
from dataclasses import dataclass
from geos.mesh.doctor.checks.vtk_utils import ( VtkOutput, get_points_coords_from_vtk, get_cell_centers_array,
get_vtm_filepath_from_pvd, get_vtu_filepaths_from_vtm,
get_all_array_names, read_mesh, write_mesh )
Copy link

Choose a reason for hiding this comment

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

I would move the "local" imports at the end

class Options:
support: str # choice between 'cell' and 'point' to operate on fields
source: str # file from where the data is collected
operations: list[ tuple[ str ] ] # [ ( function0, new_name0 ), ... ]
Copy link

Choose a reason for hiding this comment

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

From the comment, it seems like we expect exactly 2 str in the tuple. Would something like list[ tuple[ str, str ] ] work?


Returns:
array: [ distance0, distance1, ..., distanceN ] with N being the number of support elements.
"""
Copy link

Choose a reason for hiding this comment

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

Looks like a great opportunity to use your support_construction defined at L30.

Returns:
array: Array of size N being the number of support elements.
"""
if support == __SUPPORT_CHOICES[ 0 ]:
Copy link

Choose a reason for hiding this comment

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

It's tempting to have a seperate function that would return the number of elements, especially if the support_choices list is intended to grow in the future.
That would avoid changing the code everywhere it is repeated, like L209.



def get_random_field( mesh: vtkUnstructuredGrid, support: str ) -> array:
f"""For a specific support type {__SUPPORT_CHOICES}, an array with samples from a uniform distribution over [0, 1).
Copy link

Choose a reason for hiding this comment

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

In the doc string, "returns an array..."

Comment on lines +74 to +75
for i in range( result.number_cell_types ):
logging.info( f"\t{result.cell_types[ i ]}\t\t({result.cell_type_counts[ i ]} cells)" )
Copy link

Choose a reason for hiding this comment

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

For readability and as you did L80, we could do:

Suggested change
for i in range( result.number_cell_types ):
logging.info( f"\t{result.cell_types[ i ]}\t\t({result.cell_type_counts[ i ]} cells)" )
for cell_type, type_count in zip(result.number_cell_types, result.cell_type_counts ):
logging.info( f"\t{cell_type}\t\t({type_count} cells)" )

Comment on lines +144 to +146
for field_name, validity_range in data.items():
is_valid: bool = validity_range[ 0 ]
min_max: tuple[ float ] = validity_range[ 1 ]
Copy link

Choose a reason for hiding this comment

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

Suggested change
for field_name, validity_range in data.items():
is_valid: bool = validity_range[ 0 ]
min_max: tuple[ float ] = validity_range[ 1 ]
for field_name, (is_valid, min_max) in data.items():

Comment on lines +150 to +151
if options.write_stats:
if is_valid_to_write_folder( options.output_folder ):
Copy link

Choose a reason for hiding this comment

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

Suggested change
if options.write_stats:
if is_valid_to_write_folder( options.output_folder ):
if options.write_stats and is_valid_to_write_folder( options.output_folder ):

Comment on lines +110 to +111
for i, sub_grid in enumerate( sub_grids ):
for name, value in sub_grids_values[ i ].items():
Copy link

Choose a reason for hiding this comment

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

Suggested change
for i, sub_grid in enumerate( sub_grids ):
for name, value in sub_grids_values[ i ].items():
for sub_grid, sub_grid_value in zip(sub_grids, sub_grids_values):
for name, value in sub_grid_value.items():

}


def get_vtu_filepaths( options: Options ) -> tuple[ str ]:
Copy link

Choose a reason for hiding this comment

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

At some point, could maybe be moved to the vtk utils ?

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

Successfully merging this pull request may close these issues.

Add mesh_stats and field_operations
3 participants