cffview 0.2.4__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cffview
3
- Version: 0.2.4
3
+ Version: 0.3.0
4
4
  Summary: A Python CLI tool to inspect Ansys Fluent .cas.h5/.msh.h5 files without opening Fluent
5
5
  Author-email: preamer <1524477126@qq.com>
6
6
  License-Expression: BSD-3-Clause
@@ -57,6 +57,9 @@ pip install .
57
57
 
58
58
  ## Usage
59
59
 
60
+ > [!IMPORTANT]
61
+ > Only tested with Ansys Fluent 25R2!
62
+
60
63
  ```
61
64
  cffview <file> [options]
62
65
  ```
@@ -69,13 +72,14 @@ cffview <file> [options]
69
72
  | `--extract` | Dump raw Scheme settings to `general.scm` and `boundary.scm` |
70
73
  | `--showmesh` | Visualise the mesh interactively with PyVista |
71
74
  | `--solver` | Solver type, time, dimension, precision, turbulence model, energy, radiation, gravity |
72
- | `--mat` | Material properties |
73
- | `--bd` | Boundary condition settings |
74
- | `--ne` | Named expressions |
75
+ | `--mat`, `--materials` | Material properties |
76
+ | `--bd`, `--boundary` | Boundary condition settings |
77
+ | `--ne`, `--named-expressions` | Named expressions |
75
78
  | `--disc` | Discretisation schemes and relaxation factors |
76
- | `--rd` | Report definitions |
79
+ | `--rd`, `--report-definitions` | Report definitions |
77
80
  | `--plotsets` | Plot sets |
78
81
  | `--monitorsets` | Monitor sets |
82
+ | `--residuals` | Residual settings |
79
83
  | `--iter` | Iteration / time-step settings |
80
84
  | `--contours` | Graphics contours settings |
81
85
  | `--vectors` | Graphics vectors settings |
@@ -103,6 +107,10 @@ cffview case.cas.h5 --version
103
107
  cffview case.cas.h5 --extract
104
108
  ```
105
109
 
110
+ ### Demo
111
+
112
+ [demo.webm](https://github.com/user-attachments/assets/9047a354-b5cb-475e-b030-97609e2a1274)
113
+
106
114
  ---
107
115
 
108
116
  ## License
@@ -33,6 +33,9 @@ pip install .
33
33
 
34
34
  ## Usage
35
35
 
36
+ > [!IMPORTANT]
37
+ > Only tested with Ansys Fluent 25R2!
38
+
36
39
  ```
37
40
  cffview <file> [options]
38
41
  ```
@@ -45,13 +48,14 @@ cffview <file> [options]
45
48
  | `--extract` | Dump raw Scheme settings to `general.scm` and `boundary.scm` |
46
49
  | `--showmesh` | Visualise the mesh interactively with PyVista |
47
50
  | `--solver` | Solver type, time, dimension, precision, turbulence model, energy, radiation, gravity |
48
- | `--mat` | Material properties |
49
- | `--bd` | Boundary condition settings |
50
- | `--ne` | Named expressions |
51
+ | `--mat`, `--materials` | Material properties |
52
+ | `--bd`, `--boundary` | Boundary condition settings |
53
+ | `--ne`, `--named-expressions` | Named expressions |
51
54
  | `--disc` | Discretisation schemes and relaxation factors |
52
- | `--rd` | Report definitions |
55
+ | `--rd`, `--report-definitions` | Report definitions |
53
56
  | `--plotsets` | Plot sets |
54
57
  | `--monitorsets` | Monitor sets |
58
+ | `--residuals` | Residual settings |
55
59
  | `--iter` | Iteration / time-step settings |
56
60
  | `--contours` | Graphics contours settings |
57
61
  | `--vectors` | Graphics vectors settings |
@@ -79,6 +83,10 @@ cffview case.cas.h5 --version
79
83
  cffview case.cas.h5 --extract
80
84
  ```
81
85
 
86
+ ### Demo
87
+
88
+ [demo.webm](https://github.com/user-attachments/assets/9047a354-b5cb-475e-b030-97609e2a1274)
89
+
82
90
  ---
83
91
 
84
92
  ## License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cffview"
7
- version = "0.2.4"
7
+ version = "0.3.0"
8
8
  description = "A Python CLI tool to inspect Ansys Fluent .cas.h5/.msh.h5 files without opening Fluent"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -24,6 +24,7 @@ class Fluid:
24
24
  id_: str
25
25
  material: str = ''
26
26
  sources: str = ''
27
+ sources_terms: str = ''
27
28
  fixed: str = ''
28
29
  mrf_motion: str = ''
29
30
  mgrid_motion: str = ''
@@ -32,6 +33,14 @@ class Fluid:
32
33
  porous: str = ''
33
34
  fanzone: str = ''
34
35
 
36
+ def to_dict(self) -> dict[str, str]:
37
+ data = self.__dict__.copy()
38
+
39
+ if data['sources'] == '#f':
40
+ data.pop('sources_terms', None)
41
+
42
+ return data
43
+
35
44
 
36
45
  @dataclass
37
46
  @BoundaryFactory.register('solid')
@@ -40,6 +49,17 @@ class Solid:
40
49
  id_: str
41
50
  material: str = ''
42
51
  sources: str = ''
52
+ sources_terms: str = ''
53
+ fixed: str = ''
54
+ solid_motion: str = ''
55
+
56
+ def to_dict(self) -> dict[str, str]:
57
+ data = self.__dict__.copy()
58
+
59
+ if data['sources'] == '#f':
60
+ data.pop('sources_terms', None)
61
+
62
+ return data
43
63
 
44
64
 
45
65
  @dataclass
@@ -210,6 +230,13 @@ class PressureOutlet:
210
230
  return data
211
231
 
212
232
 
233
+ @dataclass
234
+ @BoundaryFactory.register('outflow')
235
+ class Outflow:
236
+ name: str
237
+ id_: str
238
+
239
+
213
240
  @dataclass
214
241
  @BoundaryFactory.register('wall')
215
242
  class Wall:
@@ -300,6 +327,13 @@ class Symmetry:
300
327
  id_: str
301
328
 
302
329
 
330
+ @dataclass
331
+ @BoundaryFactory.register('axis')
332
+ class Axis:
333
+ name: str
334
+ id_: str
335
+
336
+
303
337
  @dataclass
304
338
  class NotImplementedBoundary:
305
339
  name: str
@@ -21,8 +21,11 @@ def print_version(file_path: str) -> str:
21
21
 
22
22
 
23
23
  def read_case(file_path: str, **kwargs) -> dict[
24
- Literal['solver', 'materials', 'boundary', 'named-expressions',
25
- 'disc-scheme', 'report-definitions', 'plotsets', 'monitorsets', 'iter'],
24
+ Literal[
25
+ 'solver', 'materials', 'boundary', 'named-expressions',
26
+ 'disc-scheme', 'report-definitions', 'plotsets', 'monitorsets',
27
+ 'residuals', 'iter', 'contours', 'vectors'
28
+ ],
26
29
  dict[str]
27
30
  ]:
28
31
  """Read the cas.h5 file
@@ -185,10 +188,11 @@ def read_case(file_path: str, **kwargs) -> dict[
185
188
  for property_ in boundary_info[2]:
186
189
  property_name = str(property_[0]).replace('-', '_').replace('?', '').replace('/', '_')
187
190
  if hasattr(new_boundary, property_name):
188
- if property_[1] == sexpdata.Symbol('.'):
189
- setattr(new_boundary, property_name, str(property_[2]))
190
- elif isinstance(property_[1], list):
191
- setattr(new_boundary, property_name, f'{property_[1][0]}/{property_[1][2]}')
191
+ if len(property_) > 1:
192
+ if property_[1] == sexpdata.Symbol('.'):
193
+ setattr(new_boundary, property_name, str(property_[2]))
194
+ elif isinstance(property_[1], list):
195
+ setattr(new_boundary, property_name, f'{property_[1][0]}/{property_[1][2]}')
192
196
 
193
197
  b_list.append(new_boundary.to_dict() if hasattr(new_boundary, 'to_dict') else new_boundary.__dict__)
194
198
  data['boundary'][type_] = b_list
@@ -311,6 +315,49 @@ def read_case(file_path: str, **kwargs) -> dict[
311
315
  monitorset_dict['report-defs'] = monitorset[-4][1:]
312
316
  data['monitorsets'][monitorset_dict['name']] = monitorset_dict
313
317
 
318
+ if kwargs['residuals']:
319
+ import sexpdata
320
+
321
+ data['residuals'] = {}
322
+
323
+ for setting in [
324
+ r'advanced-options\?', r'normalize\?', r'compute-local\?',
325
+ r'scale\?', 'convergence-criterion-type', 'n-display',
326
+ 'n-save', r'plot\?', r'print\?', 'n-maximize-norms',
327
+ ]:
328
+ value = re.search(
329
+ fr'\(residuals/{setting}\s+(#[tf]|[\d.]+)\)',
330
+ general_info,
331
+ ).group(1)
332
+ data['residuals'][setting.removesuffix(r'\?')] = value
333
+ cct = data['residuals']['convergence-criterion-type']
334
+ data['residuals']['convergence-criterion-type'] = 'absolute' if cct == '0' else 'none'
335
+
336
+ if not (solver_time := data.get('solver', {}).get('time', None)):
337
+ case_config = re.search(
338
+ r'^\(case-config.*',
339
+ general_info,
340
+ re.M
341
+ ).group()
342
+ is_unsteady = re.search(
343
+ r"\(rp-unsteady\?\s+\.\s+([^()\s]+)\)",
344
+ case_config
345
+ ).group(1)
346
+ solver_time = "transient" if is_unsteady == "#t" else "steady"
347
+ residuals = 'residuals/settings-transient' if solver_time == 'transient' else 'residuals/settings'
348
+ res = re.search(
349
+ fr'(\({residuals}.*)',
350
+ general_info,
351
+ re.M
352
+ ).group(1)
353
+ res: list = sexpdata.loads(res, true=None)[1]
354
+ for eq in res:
355
+ data['residuals'][str(eq[0])] = {
356
+ 'monitor': str(eq[1]),
357
+ 'check-convergence': str(eq[3]),
358
+ 'absolute-criteria': str(eq[4]),
359
+ }
360
+
314
361
  if kwargs['iter']:
315
362
  data['iter'] = {}
316
363
 
@@ -449,14 +496,7 @@ def show_mesh(file_path: str) -> None:
449
496
  """
450
497
  import pyvista as pv
451
498
  if file_path.endswith('cas.h5'):
452
- pv.plot(
453
- pv.read(file_path),
454
- show_edges=True,
455
- show_axes=True,
456
- anti_aliasing='ssaa',
457
- smooth_shading=True,
458
- split_sharp_edges=True,
459
- )
499
+ mesh = pv.read(file_path)
460
500
  elif file_path.endswith('msh.h5'):
461
501
  import numpy as np
462
502
  from h5py import File, Group, Dataset
@@ -502,21 +542,79 @@ def show_mesh(file_path: str) -> None:
502
542
  faces=pv_faces if dimension == 3 else None,
503
543
  lines=pv_faces if dimension == 2 else None
504
544
  )
505
- plotter = pv.Plotter()
506
- plotter.enable_anti_aliasing()
507
- plotter.add_mesh(
508
- mesh,
509
- show_edges=True,
510
- )
511
- plotter.add_axes()
512
- plotter.show()
545
+
546
+ pl = pv.Plotter()
547
+ pl.enable_anti_aliasing()
548
+
549
+ mesh = mesh.combine() if mesh.n_blocks > 1 else mesh
550
+ mesh_actor = pl.add_mesh(mesh, show_edges=True)
551
+
552
+ def toggle_opacity(value):
553
+ mesh_actor.prop.opacity = value
554
+
555
+ opacity_slider_widget = pl.add_slider_widget(
556
+ toggle_opacity,
557
+ rng=(0.1, 1.0),
558
+ value=1.0,
559
+ title="Opacity",
560
+ style="modern",
561
+ )
562
+
563
+ # Monkey patch to fix clip plane error
564
+ if isinstance(mesh, pv.UnstructuredGrid):
565
+ from pyvista import _vtk
566
+ _vtk._CORE_MODULES['vtkFiltersGeneral'] = (*_vtk._CORE_MODULES['vtkFiltersGeneral'], 'vtkClipDataSet')
567
+ _vtk._VTK_CLASS_TO_MODULE = {
568
+ cls: module
569
+ for module, classes in (_vtk._CORE_MODULES | _vtk._PLOTTING_MODULES | _vtk._OPENGL_MODULES).items()
570
+ for cls in classes
571
+ }
572
+ _vtk.vtkTableBasedClipDataSet = _vtk.vtkClipDataSet
573
+
574
+ mesh_clip_plane_actor = pl.add_mesh_clip_plane(mesh, show_edges=True)
575
+ mesh_clip_plane_actor.visibility = False
576
+ clip_plane = pl.widgets.plane_widgets[-1]
577
+ clip_plane.Off()
578
+
579
+ def toggle_slice(state):
580
+ if state:
581
+ mesh_actor.visibility = False
582
+ opacity_slider_widget.Off()
583
+ mesh_clip_plane_actor.visibility = True
584
+ clip_plane.On()
585
+ else:
586
+ mesh_actor.visibility = True
587
+ opacity_slider_widget.On()
588
+ mesh_clip_plane_actor.visibility = False
589
+ clip_plane.Off()
590
+
591
+ pl.add_checkbox_button_widget(
592
+ callback=toggle_slice,
593
+ value=False,
594
+ )
595
+
596
+ pl.add_axes()
597
+ pl.show()
513
598
 
514
599
 
515
600
  def main() -> None:
516
601
  import argparse
517
602
 
518
- desc = "A Python CLI tool to inspect Ansys Fluent .cas.h5/.msh.h5 files without opening Fluent"
519
- parser = argparse.ArgumentParser(description=desc)
603
+ BANNER = r"""
604
+ ________ _
605
+ _____/ __/ __/ __(_)__ _ __
606
+ / ___/ /_/ /_| | / / / _ \ | /| / /
607
+ / /__/ __/ __/| |/ / / __/ |/ |/ /
608
+ \___/_/ /_/ |___/_/\___/|__/|__/
609
+
610
+ A Python CLI tool to inspect Ansys Fluent .cas.h5/.msh.h5 files without opening Fluent
611
+ """
612
+
613
+ parser = argparse.ArgumentParser(
614
+ prog='cffview',
615
+ description=BANNER,
616
+ formatter_class=argparse.RawDescriptionHelpFormatter,
617
+ )
520
618
 
521
619
  parser.add_argument(
522
620
  "file_path",
@@ -535,6 +633,7 @@ def main() -> None:
535
633
  (("--rd", "--report-definitions"), "show report-definitions settings"),
536
634
  (("--plotsets",), "show report-definitions plotsets settings"),
537
635
  (("--monitorsets",), "show report-definitions monitorsets settings"),
636
+ (("--residuals",), "show residuals settings"),
538
637
  (("--iter",), "show iteration settings"),
539
638
  (("--contours",), "show graphics contours settings"),
540
639
  (("--vectors",), "show graphics vectors settings"),
@@ -558,19 +657,11 @@ def main() -> None:
558
657
  show_mesh(args.file_path)
559
658
  else:
560
659
  from .utils import print_colored_dict
561
- kwargs = {
562
- 'solver': args.solver,
563
- 'mat': args.mat,
564
- 'bd': args.bd,
565
- 'ne': args.ne,
566
- 'disc': args.disc,
567
- 'rd': args.rd,
568
- 'plotsets': args.plotsets,
569
- 'monitorsets': args.monitorsets,
570
- 'contours': args.contours,
571
- 'vectors': args.vectors,
572
- 'iter': args.iter
573
- }
660
+ keys = [
661
+ 'solver', 'mat', 'bd', 'ne', 'disc', 'rd',
662
+ 'plotsets', 'monitorsets', 'residuals', 'iter', 'contours', 'vectors',
663
+ ]
664
+ kwargs = {k: getattr(args, k) for k in keys}
574
665
  output = read_case(args.file_path, **kwargs)
575
666
  print_colored_dict(output)
576
667
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cffview
3
- Version: 0.2.4
3
+ Version: 0.3.0
4
4
  Summary: A Python CLI tool to inspect Ansys Fluent .cas.h5/.msh.h5 files without opening Fluent
5
5
  Author-email: preamer <1524477126@qq.com>
6
6
  License-Expression: BSD-3-Clause
@@ -57,6 +57,9 @@ pip install .
57
57
 
58
58
  ## Usage
59
59
 
60
+ > [!IMPORTANT]
61
+ > Only tested with Ansys Fluent 25R2!
62
+
60
63
  ```
61
64
  cffview <file> [options]
62
65
  ```
@@ -69,13 +72,14 @@ cffview <file> [options]
69
72
  | `--extract` | Dump raw Scheme settings to `general.scm` and `boundary.scm` |
70
73
  | `--showmesh` | Visualise the mesh interactively with PyVista |
71
74
  | `--solver` | Solver type, time, dimension, precision, turbulence model, energy, radiation, gravity |
72
- | `--mat` | Material properties |
73
- | `--bd` | Boundary condition settings |
74
- | `--ne` | Named expressions |
75
+ | `--mat`, `--materials` | Material properties |
76
+ | `--bd`, `--boundary` | Boundary condition settings |
77
+ | `--ne`, `--named-expressions` | Named expressions |
75
78
  | `--disc` | Discretisation schemes and relaxation factors |
76
- | `--rd` | Report definitions |
79
+ | `--rd`, `--report-definitions` | Report definitions |
77
80
  | `--plotsets` | Plot sets |
78
81
  | `--monitorsets` | Monitor sets |
82
+ | `--residuals` | Residual settings |
79
83
  | `--iter` | Iteration / time-step settings |
80
84
  | `--contours` | Graphics contours settings |
81
85
  | `--vectors` | Graphics vectors settings |
@@ -103,6 +107,10 @@ cffview case.cas.h5 --version
103
107
  cffview case.cas.h5 --extract
104
108
  ```
105
109
 
110
+ ### Demo
111
+
112
+ [demo.webm](https://github.com/user-attachments/assets/9047a354-b5cb-475e-b030-97609e2a1274)
113
+
106
114
  ---
107
115
 
108
116
  ## License
File without changes
File without changes
File without changes