Skip to content

Commit

Permalink
Allows for flexibility in data mode for fractures
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbenedicto committed Nov 4, 2024
1 parent 6f5840b commit 9861c0b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 45 deletions.
2 changes: 2 additions & 0 deletions docs/geos-mesh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ The ``generate_fractures`` module will split the mesh and generate the multi-blo
[string]: For ".vtu" output format, the data mode can be binary or ascii. Defaults to binary.
--fractures_output_dir FRACTURES_OUTPUT_DIR
[string]: The output directory for the fractures meshes that will be generated from the mesh.
--fractures_data_mode FRACTURES_DATA_MODE
[string]: For ".vtu" output format, the data mode can be binary or ascii. Defaults to binary.
``generate_global_ids``
"""""""""""""""""""""""
Expand Down
37 changes: 0 additions & 37 deletions geos-mesh/src/geos/mesh/doctor/checks/generate_fractures.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,43 +234,6 @@ def __call__( self, index: int ) -> int:
return result


def combined_and_fracture_mappings( all_mappings: list[ Mapping[ int, IDMapping ] ] ):
shortened_mappings: list[ Mapping[ int, IDMapping ] ] = all_mappings.copy()
for fracture in shortened_mappings:
toRemoveCellId: list[ int ] = list()
for cell_id, node_conversion in fracture.items():
toRemoveNode: list[ int ] = list()
for node_init, node_final in node_conversion.items():
if node_init == node_final:
toRemoveNode.append( node_init )
for node_value in toRemoveNode:
del node_conversion[ node_value ]
if len( node_conversion ) == 0:
toRemoveCellId.append( cell_id )
for cell_id_value in toRemoveCellId:
del fracture[ cell_id_value ]

combined_mapping: Mapping[ int, IDMapping ] = dict()
for fracture in shortened_mappings:
for cell_id, node_conversion in fracture.items():
if cell_id not in combined_mapping.keys():
combined_mapping[ cell_id ] = dict()
for node_init, node_final in node_conversion.items():
if node_init not in combined_mapping[ cell_id ].keys():
combined_mapping[ cell_id ][ node_init ] = node_final
elif node_final < combined_mapping[ cell_id ][ node_init ]:
combined_mapping[ cell_id ][ node_init ] = node_final

new_fracture_mappings: list[ Mapping[ int, IDMapping ] ] = list()
for fracture in all_mappings:
fracture_mapping: Mapping[ int, IDMapping ] = dict()
for cell_id in fracture.keys():
fracture_mapping[ cell_id ] = combined_mapping[ cell_id ]
new_fracture_mappings.append( fracture_mapping )

return ( combined_mapping, new_fracture_mappings )


def truncated_coordinates_with_id( mesh: vtkUnstructuredGrid, decimals: int = 3 ) -> dict[ Coordinates3D, int ]:
"""Creates a mapping of truncated points coordinates with the their point id for every point of a mesh.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
__FIELD_VALUES = "values"

__FRACTURES_OUTPUT_DIR = "fractures_output_dir"
__FRACTURES_DATA_MODE = "fractures_data_mode"


def convert_to_fracture_policy( s: str ) -> FracturePolicy:
Expand Down Expand Up @@ -58,6 +59,10 @@ def fill_subparser( subparsers ) -> None:
'--' + __FRACTURES_OUTPUT_DIR,
type=str,
help=f"[string]: The output directory for the fractures meshes that will be generated from the mesh." )
p.add_argument(
'--' + __FRACTURES_DATA_MODE,
type=str,
help=f'[string]: For ".vtu" output format, the data mode can be binary or ascii. Defaults to binary.' )


def convert( parsed_options ) -> Options:
Expand All @@ -71,21 +76,22 @@ def convert( parsed_options ) -> Options:
)
all_values_no_separator: str = all_values.replace( ":", "," )
field_values_combined: frozenset[ int ] = frozenset( map( int, all_values_no_separator.split( "," ) ) )
vtk_output = vtk_output_parsing.convert( parsed_options )
mesh_vtk_output = vtk_output_parsing.convert( parsed_options )
# create the different fractures
per_fracture: list[ str ] = all_values.split( ":" )
field_values_per_fracture: list[ frozenset[ int ] ] = [
frozenset( map( int, fracture.split( "," ) ) ) for fracture in per_fracture
]
fracture_names: list[ str ] = [ "fracture_" + frac.replace( ",", "_" ) + ".vtu" for frac in per_fracture ]
fracture_output_dir: str = parsed_options[ __FRACTURES_OUTPUT_DIR ]
all_fractures_VtkOutput: list[ VtkOutput ] = build_all_fractures_VtkOutput( fracture_output_dir, vtk_output,
fracture_names )
fractures_output_dir: str = parsed_options[ __FRACTURES_OUTPUT_DIR ]
fractures_data_mode: str = parsed_options[ __FRACTURES_DATA_MODE ]
all_fractures_VtkOutput: list[ VtkOutput ] = build_all_fractures_VtkOutput( fractures_output_dir, fractures_data_mode,
mesh_vtk_output, fracture_names )
return Options( policy=policy,
field=field,
field_values_combined=field_values_combined,
field_values_per_fracture=field_values_per_fracture,
mesh_VtkOutput=vtk_output,
mesh_VtkOutput=mesh_vtk_output,
all_fractures_VtkOutput=all_fractures_VtkOutput )


Expand All @@ -103,19 +109,21 @@ def are_values_parsable( values: str ) -> bool:
return True


def build_all_fractures_VtkOutput( fracture_output_dir: str, vtk_output: VtkOutput,
def build_all_fractures_VtkOutput( fracture_output_dir: str,
fractures_data_mode: str,
mesh_vtk_output: VtkOutput,
fracture_names: list[ str ] ) -> list[ VtkOutput ]:
if not os.path.exists( fracture_output_dir ):
raise ValueError( f"The --{__FRACTURES_OUTPUT_DIR} given directory does not exist." )

if not os.access( fracture_output_dir, os.W_OK ):
raise ValueError( f"The --{__FRACTURES_OUTPUT_DIR} given directory is not writable." )

output_name = os.path.basename( vtk_output.output )
output_name = os.path.basename( mesh_vtk_output.output )
splitted_name_without_expension: list[ str ] = output_name.split( "." )[ :-1 ]
name_without_extension: str = '_'.join( splitted_name_without_expension ) + "_"
all_fractures_VtkOuput: list[ VtkOutput ] = list()
for fracture_name in fracture_names:
fracture_path = os.path.join( fracture_output_dir, name_without_extension + fracture_name )
all_fractures_VtkOuput.append( VtkOutput( fracture_path, vtk_output.is_data_mode_binary ) )
all_fractures_VtkOuput.append( VtkOutput( fracture_path, fractures_data_mode ) )
return all_fractures_VtkOuput

0 comments on commit 9861c0b

Please sign in to comment.