icplot 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.
Files changed (95) hide show
  1. {icplot-0.2.4/src/icplot.egg-info → icplot-0.3.0}/PKG-INFO +66 -18
  2. icplot-0.3.0/README.md +103 -0
  3. {icplot-0.2.4 → icplot-0.3.0}/pyproject.toml +14 -7
  4. icplot-0.3.0/setup.cfg +4 -0
  5. {icplot-0.2.4/src/icplot/gantt → icplot-0.3.0/src/icplot/charts}/gantt.py +2 -3
  6. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/charts}/tree.py +2 -3
  7. icplot-0.3.0/src/icplot/converter/__init__.py +3 -0
  8. icplot-0.3.0/src/icplot/converter/cli.py +27 -0
  9. icplot-0.3.0/src/icplot/converter/convert.py +32 -0
  10. icplot-0.2.4/src/icplot/image_utils.py → icplot-0.3.0/src/icplot/converter/image.py +5 -9
  11. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/geometry/base.py +6 -0
  12. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/edge.py +1 -1
  13. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/mesh.py +30 -4
  14. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/openfoam/blockmesh.py +2 -3
  15. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/openfoam/polymesh.py +4 -6
  16. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/shapes.py +87 -7
  17. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/vertex.py +16 -1
  18. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/geometry/shapes.py +29 -0
  19. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/geometry/transform.py +2 -2
  20. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/graph/__init__.py +3 -4
  21. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/graph/plot.py +2 -53
  22. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/graph/series.py +3 -4
  23. icplot-0.3.0/src/icplot/main_cli.py +39 -0
  24. icplot-0.3.0/src/icplot/renderer/__init__.py +1 -0
  25. icplot-0.3.0/src/icplot/renderer/charts/pgfgantt.py +71 -0
  26. icplot-0.2.4/src/icplot/gantt/gantt_renderer.py → icplot-0.3.0/src/icplot/renderer/charts/svggantt.py +8 -6
  27. icplot-0.3.0/src/icplot/renderer/cli.py +58 -0
  28. icplot-0.3.0/src/icplot/renderer/config.py +41 -0
  29. icplot-0.3.0/src/icplot/renderer/formats/__init__.py +1 -0
  30. icplot-0.3.0/src/icplot/renderer/formats/mermaid.py +41 -0
  31. icplot-0.3.0/src/icplot/renderer/formats/plantuml.py +37 -0
  32. icplot-0.3.0/src/icplot/renderer/formats/tex.py +117 -0
  33. icplot-0.3.0/src/icplot/renderer/graph/__init__.py +3 -0
  34. icplot-0.3.0/src/icplot/renderer/graph/color.py +17 -0
  35. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/renderer}/graph/matplotlib.py +15 -7
  36. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/renderer}/graph/mpl.py +8 -8
  37. icplot-0.2.4/src/icplot/graph/generator.py → icplot-0.3.0/src/icplot/renderer/graph/renderer.py +43 -8
  38. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/renderer}/graph/vtk.py +2 -3
  39. icplot-0.3.0/src/icplot/renderer/render.py +140 -0
  40. icplot-0.2.4/src/icplot/cairo_interface.py → icplot-0.3.0/src/icplot/renderer/scene/cairo.py +5 -5
  41. {icplot-0.2.4/src/icplot/graph → icplot-0.3.0/src/icplot/renderer}/video.py +2 -3
  42. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/scene.py +1 -1
  43. icplot-0.3.0/src/icplot/theme/__init__.py +0 -0
  44. icplot-0.3.0/src/icplot/theme/cli.py +50 -0
  45. icplot-0.3.0/src/icplot/theme/color.py +97 -0
  46. icplot-0.3.0/src/icplot/theme/templates/puml.j2 +91 -0
  47. icplot-0.3.0/src/icplot/theme/templates/tikz.j2 +100 -0
  48. icplot-0.3.0/src/icplot/theme/theme.json +81 -0
  49. icplot-0.3.0/src/icplot/theme/theme.py +117 -0
  50. icplot-0.3.0/src/icplot/theme/theme_generator.py +119 -0
  51. {icplot-0.2.4 → icplot-0.3.0/src/icplot.egg-info}/PKG-INFO +66 -18
  52. icplot-0.3.0/src/icplot.egg-info/SOURCES.txt +80 -0
  53. {icplot-0.2.4 → icplot-0.3.0}/src/icplot.egg-info/requires.txt +2 -0
  54. icplot-0.2.4/test/test_cairo_interface.py → icplot-0.3.0/test/test_cairo.py +5 -5
  55. {icplot-0.2.4 → icplot-0.3.0}/test/test_gantt_chart.py +1 -3
  56. {icplot-0.2.4 → icplot-0.3.0}/test/test_geometry.py +1 -1
  57. icplot-0.2.4/test/test_image_utils.py → icplot-0.3.0/test/test_image.py +1 -1
  58. {icplot-0.2.4 → icplot-0.3.0}/test/test_line_plots.py +2 -2
  59. icplot-0.3.0/test/test_mermaid.py +36 -0
  60. {icplot-0.2.4 → icplot-0.3.0}/test/test_meshing.py +50 -12
  61. {icplot-0.2.4 → icplot-0.3.0}/test/test_openfoam.py +2 -2
  62. {icplot-0.2.4 → icplot-0.3.0}/test/test_plot_group.py +3 -2
  63. {icplot-0.2.4 → icplot-0.3.0}/test/test_polymesh.py +24 -16
  64. icplot-0.3.0/test/test_tex.py +26 -0
  65. {icplot-0.2.4 → icplot-0.3.0}/test/test_tree.py +2 -2
  66. icplot-0.2.4/README.md +0 -57
  67. icplot-0.2.4/setup.cfg +0 -9
  68. icplot-0.2.4/src/icplot/color.py +0 -50
  69. icplot-0.2.4/src/icplot/convert.py +0 -51
  70. icplot-0.2.4/src/icplot/gantt/__init__.py +0 -1
  71. icplot-0.2.4/src/icplot/gantt/pgfgantt.py +0 -15
  72. icplot-0.2.4/src/icplot/main_cli.py +0 -88
  73. icplot-0.2.4/src/icplot/mermaid.py +0 -39
  74. icplot-0.2.4/src/icplot/tex.py +0 -78
  75. icplot-0.2.4/src/icplot/trace/__init__.py +0 -1
  76. icplot-0.2.4/src/icplot.egg-info/SOURCES.txt +0 -66
  77. icplot-0.2.4/test/test_mermaid.py +0 -24
  78. icplot-0.2.4/test/test_tex.py +0 -23
  79. {icplot-0.2.4 → icplot-0.3.0}/LICENSE +0 -0
  80. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/__init__.py +0 -0
  81. icplot-0.2.4/src/icplot/py.typed → icplot-0.3.0/src/icplot/charts/__init__.py +0 -0
  82. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/geometry/__init__.py +0 -0
  83. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/__init__.py +1 -1
  84. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/cell.py +0 -0
  85. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/openfoam/__init__.py +1 -1
  86. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/openfoam/foamfile.py +0 -0
  87. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/operations.py +1 -1
  88. {icplot-0.2.4/src/icplot → icplot-0.3.0/src/icplot/geometry}/mesh/vtk.py +2 -2
  89. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/geometry/operations.py +0 -0
  90. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/graph/axis.py +0 -0
  91. {icplot-0.2.4 → icplot-0.3.0}/src/icplot/graph/plot_group.py +1 -1
  92. /icplot-0.2.4/src/icplot/trace/trace.py → /icplot-0.3.0/src/icplot/py.typed +0 -0
  93. {icplot-0.2.4 → icplot-0.3.0}/src/icplot.egg-info/dependency_links.txt +0 -0
  94. {icplot-0.2.4 → icplot-0.3.0}/src/icplot.egg-info/entry_points.txt +0 -0
  95. {icplot-0.2.4 → icplot-0.3.0}/src/icplot.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: icplot
3
- Version: 0.2.4
3
+ Version: 0.3.0
4
4
  Summary: Utilities for generating plots and graphics for technical reports.
5
5
  Author-email: "James Grogan, Irish Centre for High End Computing" <james.grogan@ichec.ie>
6
6
  Project-URL: Repository, https://git.ichec.ie/performance/toolshed/icplot
@@ -21,11 +21,13 @@ Requires-Dist: moviepy
21
21
  Requires-Dist: scipy
22
22
  Requires-Dist: iccore==0.2.3
23
23
  Requires-Dist: graphviz
24
+ Requires-Dist: Jinja2
24
25
  Provides-Extra: test
25
26
  Requires-Dist: pytest; extra == "test"
26
27
  Requires-Dist: pytest-cov; extra == "test"
27
28
  Requires-Dist: pytest-sugar; extra == "test"
28
29
  Requires-Dist: black; extra == "test"
30
+ Requires-Dist: isort; extra == "test"
29
31
  Requires-Dist: mypy; extra == "test"
30
32
  Requires-Dist: flake8; extra == "test"
31
33
  Requires-Dist: pylint; extra == "test"
@@ -36,16 +38,18 @@ Dynamic: license-file
36
38
 
37
39
  # icplot
38
40
 
39
- This is a library used at [The Irish Centre for High End Computing (ICHEC)](https://www.ichec.ie) for generating plots and graphics for technical documents.
41
+ This is a library used at [The Irish Centre for High End Computing (ICHEC)](https://www.ichec.ie) for generating plots, diagrams and other graphics for technical documents.
40
42
 
41
43
  # Features #
42
44
 
43
- The project has support for:
45
+ The project has three primary modules:
44
46
 
45
- * Coverting image formats between pdf, svg and png
46
- * Building pdf and png output from tex files, including tikz.
47
- * Generating plots based on a serializable data model to support reproducible research
48
- * Generating mermaid plots
47
+ `converter`: Converts between image formats, such as pdf, svg and png
48
+ `renderer`: Render text based inputs as svg, pdf or png images or videos
49
+ `theme`: Generate and apply themes from a design system
50
+
51
+
52
+ ## Converter ##
49
53
 
50
54
  To covert between image formats you can do:
51
55
 
@@ -53,24 +57,68 @@ To covert between image formats you can do:
53
57
  icplot convert --source my_image.svg --target my_image.png
54
58
  ```
55
59
 
56
- To render a Tex tikz image as pdf and png you can do:
60
+ Supported conversions are:
57
61
 
58
- ``` shell
59
- icplot convert --source my_tikz.tex
60
- ```
62
+ * svg -> png
63
+ * svg -> pdf
64
+ * pdf -> png
61
65
 
62
- To render a Mermaid plot as png you can do:
63
-
64
- ``` shell
65
- icplot convert --source my_mermaid.mmd
66
- ```
66
+ ## Renderer ##
67
67
 
68
- To generate a plot or collection of plots from a yaml description you can do:
68
+ Render a range of text based formats to images or videos. For example,
69
69
 
70
70
  ``` shell
71
- icplot plot --config my_plot.yml
71
+ icplot render --file uml_diagram.puml
72
72
  ```
73
73
 
74
+ renders the PlantUML file to png and svg.
75
+
76
+ Supported render inputs and targets are:
77
+
78
+ * PlantUml
79
+ * SVG
80
+ * PNG
81
+ * Latex/Tikz
82
+ * PDF
83
+ * SVG
84
+ * PNG
85
+ * Mermaid
86
+ * SVG
87
+ * PNG
88
+ * Custom JSON
89
+ * Graph
90
+ * Backends:
91
+ * Matplotlib
92
+ * VTK
93
+ * Output formats:
94
+ * SVG
95
+ * PNG
96
+ * MP4
97
+ * Tree
98
+ * Backends:
99
+ * Graphviz
100
+ * Output formats:
101
+ * SVG
102
+ * PNG
103
+ * Gantt
104
+ * Backends:
105
+ * Cairo
106
+ * PgfGantt
107
+ * Output formats:
108
+ * SVG
109
+ * PNG
110
+ * Scene
111
+ * Backends:
112
+ * Cairo
113
+ * VTK
114
+ * Output formats:
115
+ * SVG
116
+ * VTK
117
+
118
+ ## Themes ##
119
+
120
+ The library supports themeing with an Angular Material 3 motivated design system. Plots can be themed by adapting a version of `theme.json` included in this module's source. Currently Tikz and PlantUML support themeing.
121
+
74
122
  # Installation #
75
123
 
76
124
  The package is available on PyPI. For a minimal installation you can do:
icplot-0.3.0/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # icplot
2
+
3
+ This is a library used at [The Irish Centre for High End Computing (ICHEC)](https://www.ichec.ie) for generating plots, diagrams and other graphics for technical documents.
4
+
5
+ # Features #
6
+
7
+ The project has three primary modules:
8
+
9
+ `converter`: Converts between image formats, such as pdf, svg and png
10
+ `renderer`: Render text based inputs as svg, pdf or png images or videos
11
+ `theme`: Generate and apply themes from a design system
12
+
13
+
14
+ ## Converter ##
15
+
16
+ To covert between image formats you can do:
17
+
18
+ ``` shell
19
+ icplot convert --source my_image.svg --target my_image.png
20
+ ```
21
+
22
+ Supported conversions are:
23
+
24
+ * svg -> png
25
+ * svg -> pdf
26
+ * pdf -> png
27
+
28
+ ## Renderer ##
29
+
30
+ Render a range of text based formats to images or videos. For example,
31
+
32
+ ``` shell
33
+ icplot render --file uml_diagram.puml
34
+ ```
35
+
36
+ renders the PlantUML file to png and svg.
37
+
38
+ Supported render inputs and targets are:
39
+
40
+ * PlantUml
41
+ * SVG
42
+ * PNG
43
+ * Latex/Tikz
44
+ * PDF
45
+ * SVG
46
+ * PNG
47
+ * Mermaid
48
+ * SVG
49
+ * PNG
50
+ * Custom JSON
51
+ * Graph
52
+ * Backends:
53
+ * Matplotlib
54
+ * VTK
55
+ * Output formats:
56
+ * SVG
57
+ * PNG
58
+ * MP4
59
+ * Tree
60
+ * Backends:
61
+ * Graphviz
62
+ * Output formats:
63
+ * SVG
64
+ * PNG
65
+ * Gantt
66
+ * Backends:
67
+ * Cairo
68
+ * PgfGantt
69
+ * Output formats:
70
+ * SVG
71
+ * PNG
72
+ * Scene
73
+ * Backends:
74
+ * Cairo
75
+ * VTK
76
+ * Output formats:
77
+ * SVG
78
+ * VTK
79
+
80
+ ## Themes ##
81
+
82
+ The library supports themeing with an Angular Material 3 motivated design system. Plots can be themed by adapting a version of `theme.json` included in this module's source. Currently Tikz and PlantUML support themeing.
83
+
84
+ # Installation #
85
+
86
+ The package is available on PyPI. For a minimal installation you can do:
87
+
88
+ ``` shell
89
+ pip install icplot
90
+ ```
91
+
92
+ For full functionality, particularly conversion of image formats, `imagemagick` and `cairo` are required. On Mac you can install them with:
93
+
94
+ ``` shell
95
+ brew install imagemagick cairo
96
+ ```
97
+
98
+ # Copyright #
99
+
100
+ Copyright 2024 Irish Centre for High End Computing
101
+
102
+ The software in this repository can be used under the conditions of the GPLv3+ license, which is available for reading in the accompanying LICENSE file.
103
+
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "icplot"
3
- version = "0.2.4"
3
+ version = "0.3.0"
4
4
  authors = [
5
5
  { name="James Grogan, Irish Centre for High End Computing", email="james.grogan@ichec.ie" },
6
6
  ]
@@ -22,7 +22,8 @@ dependencies = ["wand",
22
22
  "moviepy",
23
23
  "scipy",
24
24
  "iccore==0.2.3",
25
- "graphviz"]
25
+ "graphviz",
26
+ "Jinja2"]
26
27
 
27
28
  [project.urls]
28
29
  Repository = "https://git.ichec.ie/performance/toolshed/icplot"
@@ -34,6 +35,7 @@ test = [
34
35
  "pytest-cov",
35
36
  "pytest-sugar",
36
37
  "black",
38
+ "isort",
37
39
  "mypy",
38
40
  "flake8",
39
41
  "pylint"
@@ -52,7 +54,7 @@ build-backend = "setuptools.build_meta"
52
54
  icplot = "icplot.main_cli:main_cli"
53
55
 
54
56
  [tool.setuptools.package-data]
55
- "icplot" = ["py.typed", "controlDict"]
57
+ "icplot" = ["py.typed", "controlDict", "theme/theme.json", "theme/templates/*.j2"]
56
58
 
57
59
  [tool.setuptools.packages.find]
58
60
  where = ["src"]
@@ -122,16 +124,21 @@ commands = [["pytest", "test"]]
122
124
  [tool.tox.env.format_apply]
123
125
  description = "Run Format Apply"
124
126
  skip_install = true
125
- deps = ["black"]
126
- commands = [["black", "src"], ["black", "test"]]
127
+ deps = ["black", "isort"]
128
+ commands = [["black", "src"], ["black", "test"], ["isort", "src"], ["isort", "test"]]
127
129
 
128
130
  [tool.tox.env.format_check]
129
131
  description = "Run Format Check"
130
132
  skip_install = true
131
- deps = ["black"]
133
+ deps = ["black", "isort"]
132
134
  commands = [
133
135
  ["black", "--check", "--diff", "src"],
134
- ["black", "--check", "--diff", "test"]]
136
+ ["black", "--check", "--diff", "test"],
137
+ ["isort", "--check", "--diff", "src"],
138
+ ["isort", "--check", "--diff", "test"]]
139
+
140
+ [tool.isort]
141
+ profile = "black"
135
142
 
136
143
  [tool.tox.env.lint]
137
144
  description = "Run Linter"
icplot-0.3.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -4,11 +4,10 @@ This module represents a gantt chard
4
4
 
5
5
  from datetime import datetime
6
6
 
7
- from pydantic import BaseModel
8
-
9
7
  from iccore.project import Milestone
8
+ from pydantic import BaseModel
10
9
 
11
- from icplot.color import Color
10
+ from icplot.theme.color import Color
12
11
 
13
12
 
14
13
  class GanttChart(BaseModel, frozen=True):
@@ -1,13 +1,12 @@
1
+ import logging
1
2
  import os
2
3
  import shutil
3
- import logging
4
4
  from dataclasses import dataclass
5
- from typing import Callable
6
5
  from pathlib import Path
6
+ from typing import Callable
7
7
 
8
8
  import graphviz
9
9
 
10
-
11
10
  logger = logging.getLogger(__name__)
12
11
 
13
12
 
@@ -0,0 +1,3 @@
1
+ from .image import pdf_to_png, svg_to_pdf, svg_to_png
2
+
3
+ __all__ = ["pdf_to_png", "svg_to_pdf", "svg_to_png"]
@@ -0,0 +1,27 @@
1
+ from pathlib import Path
2
+
3
+ from .convert import convert
4
+
5
+
6
+ def convert_cli(args):
7
+
8
+ source = args.source.resolve()
9
+ target = Path(args.target).resolve() if args.target else None
10
+ convert(source, target)
11
+
12
+
13
+ def register_parser(subparsers):
14
+
15
+ convert_parser = subparsers.add_parser("convert")
16
+ convert_parser.add_argument(
17
+ "source",
18
+ type=Path,
19
+ help="Path to file to be converted from",
20
+ )
21
+ convert_parser.add_argument(
22
+ "--target",
23
+ type=str,
24
+ default="",
25
+ help="Path to file to be converted to",
26
+ )
27
+ convert_parser.set_defaults(func=convert_cli)
@@ -0,0 +1,32 @@
1
+ """
2
+ Module supporting conversion between image formats
3
+ """
4
+
5
+ import logging
6
+ from pathlib import Path
7
+
8
+ from .image import pdf_to_png, svg_to_pdf, svg_to_png
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+
13
+ def convert(source: Path, target: Path | None = None):
14
+ """
15
+ Convert between image formats using the source and target
16
+ file extensions as format hints.
17
+ """
18
+
19
+ logger.info("Converting %s", source)
20
+
21
+ if source.suffix == ".pdf":
22
+ pdf_to_png(source, target)
23
+ elif source.suffix == ".svg":
24
+ if target:
25
+ if target.suffix == ".png":
26
+ svg_to_png(source, target)
27
+ elif target.suffix == ".pdf":
28
+ svg_to_pdf(source, target)
29
+ else:
30
+ svg_to_png(source)
31
+
32
+ logger.info("Finished conversion")
@@ -7,27 +7,23 @@ import logging
7
7
  import os
8
8
  from pathlib import Path
9
9
 
10
+ logger = logging.getLogger(__name__)
11
+
10
12
  _HAS_WAND = True
11
13
  try:
12
- from wand.image import Image
13
14
  from wand.color import Color
15
+ from wand.image import Image
14
16
  except ImportError as e:
15
- logging.getLogger(__name__).warning(
16
- "Disabling Wand stupport. Failed to load with: %s", e
17
- )
17
+ logger.debug("wand not available: %s", e)
18
18
  _HAS_WAND = False
19
19
 
20
20
  _HAS_CAIRO_SVG = True
21
21
  try:
22
22
  import cairosvg
23
23
  except ImportError as e:
24
- logging.getLogger(__name__).warning(
25
- "Disabling CairoSVG stupport. Failed to load with: %s", e
26
- )
24
+ logger.debug("cairosvg not available: %s", e)
27
25
  _HAS_CAIRO_SVG = False
28
26
 
29
- logger = logging.getLogger(__name__)
30
-
31
27
 
32
28
  def has_wand() -> bool:
33
29
  return _HAS_WAND
@@ -1,8 +1,11 @@
1
1
  from __future__ import annotations
2
+
2
3
  from dataclasses import dataclass
3
4
 
4
5
  import numpy as np
5
6
 
7
+ from .operations import get_point_distance
8
+
6
9
 
7
10
  @dataclass(frozen=True)
8
11
  class Vector:
@@ -47,6 +50,9 @@ class Point:
47
50
  def subtract(self, v: Vector) -> Vector:
48
51
  return Vector(self.x - v.x, self.y - v.y, self.z - v.z)
49
52
 
53
+ def get_distance(self, p: Point) -> float:
54
+ return get_point_distance(p.as_array(), self.as_array())
55
+
50
56
 
51
57
  @dataclass(frozen=True)
52
58
  class Bounds:
@@ -1,6 +1,6 @@
1
1
  from dataclasses import dataclass
2
2
 
3
- from icplot.geometry import Point, segment_contains_point, get_segment_distance
3
+ from icplot.geometry import Point, get_segment_distance, segment_contains_point
4
4
 
5
5
  from .vertex import Vertex
6
6
 
@@ -4,13 +4,14 @@ over performance. Consider something else for high performance meshing.
4
4
  """
5
5
 
6
6
  from __future__ import annotations
7
+
7
8
  from dataclasses import dataclass
8
9
 
9
- from icplot.geometry import Point, Vector, Transform, Bounds
10
+ from icplot.geometry import Bounds, Point, Shape, Transform, Vector
10
11
 
11
- from .vertex import Vertex, find_closest_vertex
12
12
  from .cell import Cell, flip_normals
13
13
  from .edge import Edge, contains_point, get_distance
14
+ from .vertex import Vertex, find_closest_vertex
14
15
 
15
16
 
16
17
  @dataclass(frozen=True)
@@ -49,7 +50,7 @@ class Mesh:
49
50
  ymin = min(ymin, v.y)
50
51
  ymax = max(ymax, v.y)
51
52
  zmin = min(zmin, v.z)
52
- zmax = min(zmax, v.z)
53
+ zmax = max(zmax, v.z)
53
54
  return Bounds(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax)
54
55
 
55
56
  def flip_normals(self) -> Mesh:
@@ -67,8 +68,28 @@ class Mesh:
67
68
  vertices=tuple(v.translate(delta) for v in self.vertices), cells=self.cells
68
69
  )
69
70
 
70
- def move_by(self, x: float, y: float, z: float) -> Mesh:
71
+ def scale_by(self, factor: float) -> Mesh:
72
+ return Mesh(
73
+ vertices=tuple(v.scale(factor) for v in self.vertices), cells=self.cells
74
+ )
75
+
76
+ def rotate_to(self, vec: Vector) -> Mesh:
77
+ return Mesh(
78
+ vertices=tuple(v.rotate_to(vec) for v in self.vertices), cells=self.cells
79
+ )
80
+
81
+ def move_by(
82
+ self, x: float, y: float, z: float, selection: list[int] | None = None
83
+ ) -> Mesh:
71
84
  delta = Vector(x, y, z)
85
+ if selection:
86
+ return Mesh(
87
+ vertices=tuple(
88
+ v.translate(delta) if v.id in selection else v.copy()
89
+ for v in self.vertices
90
+ ),
91
+ cells=self.cells,
92
+ )
72
93
  return Mesh(
73
94
  vertices=tuple(v.translate(delta) for v in self.vertices), cells=self.cells
74
95
  )
@@ -105,3 +126,8 @@ class Mesh:
105
126
  vertices=tuple(Vertex(v.x, v.y, v.z, v.id) for v in self.vertices),
106
127
  cells=tuple(Cell(c.vertices, c.type) for c in self.cells),
107
128
  )
129
+
130
+ def select_region(self, region: Shape) -> list[int]:
131
+ return [
132
+ v.id for v in self.vertices if region.contains_point(Point(v.x, v.y, v.z))
133
+ ]
@@ -2,14 +2,13 @@
2
2
  Meshing utilities for use in openfoam
3
3
  """
4
4
 
5
+ import os
5
6
  import shutil
6
7
  import subprocess
7
- import os
8
8
  from pathlib import Path
9
9
  from typing import cast
10
10
 
11
-
12
- from icplot.mesh import Edge, HexCell, Mesh, Patch
11
+ from icplot.geometry.mesh import Edge, HexCell, Mesh, Patch
13
12
 
14
13
  from .foamfile import FoamFile, write_header
15
14
 
@@ -1,11 +1,11 @@
1
1
  from dataclasses import dataclass
2
- from pathlib import Path
3
2
  from functools import cmp_to_key
3
+ from pathlib import Path
4
4
 
5
5
  from icplot.geometry import Point
6
- from icplot.mesh import Vertex, Mesh, get_hex_faces
6
+ from icplot.geometry.mesh import Mesh, Vertex, get_hex_faces
7
7
 
8
- from .foamfile import read_foamfile, FoamFile, write_header
8
+ from .foamfile import FoamFile, read_foamfile, write_header
9
9
 
10
10
 
11
11
  @dataclass(frozen=True)
@@ -65,10 +65,8 @@ class PolymeshPatch:
65
65
 
66
66
  def read_polymesh(path: Path) -> Polymesh:
67
67
 
68
- points_file = read_foamfile(path / "points")
68
+ _ = read_foamfile(path / "points")
69
69
  # faces_file = read_foamfile(path / "faces")
70
- print(points_file)
71
- # print(faces_file)
72
70
  return Polymesh((), (), ())
73
71
 
74
72
 
@@ -1,21 +1,21 @@
1
1
  import numpy as np
2
2
 
3
3
  from icplot.geometry import (
4
- Point,
5
- Quad,
6
4
  Annulus,
7
- Transform,
8
5
  Circle,
9
6
  Cuboid,
10
- Vector,
11
7
  Cylinder,
8
+ Point,
9
+ Quad,
10
+ Shape,
11
+ Transform,
12
+ Vector,
12
13
  )
13
14
 
15
+ from .cell import Cell, HexCell
14
16
  from .mesh import Mesh
17
+ from .operations import close_mesh, map_radial, merge_meshes, mesh_extrude
15
18
  from .vertex import Vertex, find_closest
16
- from .cell import Cell, HexCell
17
-
18
- from .operations import map_radial, close_mesh, merge_meshes, mesh_extrude
19
19
 
20
20
 
21
21
  def mesh_rectangle(rect: Quad, num_width: int = 10, num_height: int = 10) -> Mesh:
@@ -187,6 +187,73 @@ def mesh_cylinder_basic(
187
187
  )
188
188
 
189
189
 
190
+ """
191
+ def _mesh_cylinder_block(radius,
192
+ top_loc,
193
+ bottom_loc,
194
+ boundary_fraction,
195
+ num_radial,
196
+ num_circumferential,
197
+ cell_height,
198
+ top_hole: Hole | None = None,
199
+ bottom_hole: Hole | None = None) -> Mesh:
200
+ length = height - hole_loc.z
201
+ num_cells_in_block = int(num_height*length/height) + 1
202
+ block = mesh_cylinder_basic(Cylinder(diameter=radius*2, length=length),
203
+ boundary_fraction,
204
+ num_radial,
205
+ num_circumferential,
206
+ num_cells_in_block)
207
+ block = block.move_by(0.0, 0.0, hole_loc.z)
208
+ selection = block.select_region(holes[0])
209
+ block = block.move_by(0.0, 0.0, (length/num_cells_in_block)/8.0, selection)
210
+ """
211
+
212
+
213
+ def _mesh_compound_cylinder_with_holes(
214
+ inlet_radius,
215
+ inlet_height,
216
+ radius,
217
+ height,
218
+ boundary_fraction,
219
+ num_circumferential,
220
+ num_radial,
221
+ num_height,
222
+ holes: list[Shape],
223
+ ) -> Mesh:
224
+
225
+ # Mesh the core cylinder in blocks at the hole locations
226
+ hole_loc = holes[0].transform.location
227
+
228
+ length = height - hole_loc.z
229
+ num_cells_in_block = int(num_height * length / height) + 1
230
+ block = mesh_cylinder_basic(
231
+ Cylinder(diameter=radius * 2, length=length),
232
+ boundary_fraction,
233
+ num_radial,
234
+ num_circumferential,
235
+ num_cells_in_block,
236
+ )
237
+ block = block.move_by(0.0, 0.0, hole_loc.z)
238
+ selection = block.select_region(holes[0])
239
+ block = block.move_by(0.0, 0.0, (length / num_cells_in_block) / 8.0, selection)
240
+
241
+ length = hole_loc.z
242
+ num_cells_in_block = int(num_height * length / height) + 1
243
+ block = mesh_cylinder_basic(
244
+ Cylinder(diameter=radius * 2, length=length),
245
+ boundary_fraction,
246
+ num_radial,
247
+ num_circumferential,
248
+ num_cells_in_block,
249
+ )
250
+ block = block.move_by(0.0, 0.0, 0.0)
251
+ selection = block.select_region(holes[0])
252
+ block = block.move_by(0.0, 0.0, -(length / num_cells_in_block) / 8.0, selection)
253
+
254
+ return merge_meshes(block, block)
255
+
256
+
190
257
  def mesh_compound_cylinder(
191
258
  inlet_radius,
192
259
  inlet_height,
@@ -196,8 +263,21 @@ def mesh_compound_cylinder(
196
263
  num_circumferential,
197
264
  num_radial,
198
265
  num_height,
266
+ holes: list[Shape] | None = None,
199
267
  ) -> Mesh:
200
268
 
269
+ if holes:
270
+ return _mesh_compound_cylinder_with_holes(
271
+ inlet_radius,
272
+ inlet_height,
273
+ radius,
274
+ height,
275
+ boundary_fraction,
276
+ num_circumferential,
277
+ num_radial,
278
+ num_height,
279
+ holes,
280
+ )
201
281
  inner = mesh_cylinder_basic(
202
282
  Cylinder(diameter=inlet_radius * 2, length=2 * inlet_height + height),
203
283
  boundary_fraction,