cardiac-geometriesx 0.0.3__py3-none-any.whl → 0.1.0__py3-none-any.whl

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.

Potentially problematic release.


This version of cardiac-geometriesx might be problematic. Click here for more details.

@@ -1,8 +1,4 @@
1
- from . import fibers
2
- from . import geometry
1
+ from . import cli, fibers, geometry, mesh, utils
3
2
  from .geometry import Geometry
4
- from . import mesh
5
- from . import utils
6
- from . import cli
7
3
 
8
4
  __all__ = ["mesh", "fibers", "geometry", "Geometry", "utils", "cli"]
cardiac_geometries/cli.py CHANGED
@@ -6,7 +6,6 @@ import rich_click as click
6
6
 
7
7
  from . import mesh
8
8
 
9
-
10
9
  meta = metadata("cardiac-geometriesx")
11
10
  __version__ = meta["Version"]
12
11
  __author__ = meta["Author"]
@@ -1,6 +1,4 @@
1
- from . import lv_ellipsoid, slab
2
- from . import utils
3
-
1
+ from . import lv_ellipsoid, slab, utils
4
2
  from .utils import Microstructure
5
3
 
6
4
  __all__ = ["lv_ellipsoid", "slab", "utils", "Microstructure"]
@@ -1,8 +1,8 @@
1
1
  from pathlib import Path
2
+
3
+ import basix
2
4
  import dolfinx
3
5
  import numpy as np
4
- import basix
5
-
6
6
 
7
7
  from . import utils
8
8
 
@@ -1,8 +1,8 @@
1
1
  from pathlib import Path
2
2
 
3
+ import basix
3
4
  import dolfinx
4
5
  import numpy as np
5
- import basix
6
6
 
7
7
  from . import utils
8
8
 
@@ -1,11 +1,11 @@
1
- from typing import NamedTuple
2
1
  from pathlib import Path
2
+ from typing import NamedTuple, Sequence
3
3
 
4
+ import adios4dolfinx
4
5
  import dolfinx
5
- from dolfinx.fem.petsc import LinearProblem
6
- import ufl
7
6
  import numpy as np
8
- import adios4dolfinx
7
+ import ufl
8
+ from dolfinx.fem.petsc import LinearProblem
9
9
 
10
10
 
11
11
  class Microstructure(NamedTuple):
@@ -15,28 +15,27 @@ class Microstructure(NamedTuple):
15
15
 
16
16
 
17
17
  def save_microstructure(
18
- mesh: dolfinx.mesh.Mesh, system: Microstructure, outdir: str | Path
18
+ mesh: dolfinx.mesh.Mesh, functions: Sequence[dolfinx.fem.Function], outdir: str | Path
19
19
  ) -> None:
20
20
  from ..utils import element2array
21
21
 
22
22
  # Save for paraview visualization
23
23
  with dolfinx.io.XDMFFile(mesh.comm, Path(outdir) / "microstructure.xdmf", "w") as file:
24
24
  file.write_mesh(mesh)
25
- file.write_function(system.f0)
26
- file.write_function(system.s0)
27
- file.write_function(system.n0)
25
+ for f in functions:
26
+ file.write_function(f)
28
27
 
29
28
  # Save with proper function space
30
29
  filename = Path(outdir) / "microstructure.bp"
31
- adios4dolfinx.write_function(u=system.f0, filename=filename)
32
- adios4dolfinx.write_function(u=system.s0, filename=filename)
33
- adios4dolfinx.write_function(u=system.n0, filename=filename)
34
- arr = element2array(system.f0.ufl_element().basix_element)
30
+ for function in functions:
31
+ adios4dolfinx.write_function(u=function, filename=filename)
32
+
33
+ attributes = {f.name: element2array(f.ufl_element().basix_element) for f in functions}
35
34
  adios4dolfinx.write_attributes(
36
35
  comm=mesh.comm,
37
36
  filename=filename,
38
37
  name="function_space",
39
- attributes={k: arr for k in ("f0", "s0", "n0")},
38
+ attributes=attributes,
40
39
  )
41
40
 
42
41
 
@@ -1,10 +1,12 @@
1
- from dataclasses import dataclass, field
2
1
  import json
2
+ import shutil
3
+ from dataclasses import dataclass, field
3
4
  from pathlib import Path
4
- import dolfinx
5
+
5
6
  from mpi4py import MPI
6
- import shutil
7
+
7
8
  import adios4dolfinx
9
+ import dolfinx
8
10
  import numpy as np
9
11
 
10
12
  from . import utils
@@ -85,16 +87,10 @@ class Geometry:
85
87
 
86
88
  # Read mesh
87
89
  if (folder / "mesh.xdmf").exists():
88
- mesh, cfun = utils.read_mesh(comm=comm, filename=folder / "mesh.xdmf")
90
+ mesh, cfun, ffun = utils.read_mesh(comm=comm, filename=folder / "mesh.xdmf")
89
91
  else:
90
92
  raise ValueError("No mesh file found")
91
93
 
92
- # Read meshtags
93
- if (folder / "triangle_mesh.xdmf").exists():
94
- ffun = utils.read_ffun(mesh=mesh, filename=folder / "triangle_mesh.xdmf")
95
- else:
96
- ffun = None
97
-
98
94
  # Read markers
99
95
  if (folder / "markers.json").exists():
100
96
  if comm.rank == 0:
@@ -1,12 +1,13 @@
1
- from pathlib import Path
2
- import math
3
- import json
4
1
  import datetime
2
+ import json
3
+ import math
5
4
  from importlib.metadata import metadata
6
- from structlog import get_logger
5
+ from pathlib import Path
7
6
 
8
7
  from mpi4py import MPI
8
+
9
9
  import cardiac_geometries_core as cgc
10
+ from structlog import get_logger
10
11
 
11
12
  from . import utils
12
13
  from .geometry import Geometry
@@ -42,6 +43,7 @@ def biv_ellipsoid(
42
43
  fiber_angle_endo: float = -60,
43
44
  fiber_angle_epi: float = +60,
44
45
  fiber_space: str = "P_1",
46
+ verbose: bool = False,
45
47
  ) -> Geometry:
46
48
  """Create BiV ellipsoidal geometry
47
49
 
@@ -95,6 +97,8 @@ def biv_ellipsoid(
95
97
  Angle for the epicardium, by default +60
96
98
  fiber_space : str, optional
97
99
  Function space for fibers of the form family_degree, by default "P_1"
100
+ verbose : bool, optional
101
+ If True print information from gmsh, by default False
98
102
 
99
103
  Returns
100
104
  -------
@@ -164,6 +168,7 @@ def biv_ellipsoid(
164
168
  a_epi_rv=a_epi_rv,
165
169
  b_epi_rv=b_epi_rv,
166
170
  c_epi_rv=c_epi_rv,
171
+ verbose=verbose,
167
172
  )
168
173
  comm.barrier()
169
174
  geometry = utils.gmsh2dolfin(comm=comm, msh_file=mesh_name)
@@ -220,6 +225,7 @@ def biv_ellipsoid_torso(
220
225
  fiber_angle_endo: float = -60,
221
226
  fiber_angle_epi: float = +60,
222
227
  fiber_space: str = "P_1",
228
+ verbose: bool = False,
223
229
  ) -> Geometry:
224
230
  """Create BiV ellipsoidal geometry
225
231
 
@@ -285,6 +291,8 @@ def biv_ellipsoid_torso(
285
291
  Angle for the epicardium, by default +60
286
292
  fiber_space : str, optional
287
293
  Function space for fibers of the form family_degree, by default "P_1"
294
+ verbose : bool, optional
295
+ If True print information from gmsh, by default False
288
296
 
289
297
  Returns
290
298
  -------
@@ -364,6 +372,7 @@ def biv_ellipsoid_torso(
364
372
  a_epi_rv=a_epi_rv,
365
373
  b_epi_rv=b_epi_rv,
366
374
  c_epi_rv=c_epi_rv,
375
+ verbose=verbose,
367
376
  )
368
377
  comm.barrier()
369
378
 
@@ -412,6 +421,7 @@ def lv_ellipsoid(
412
421
  fiber_angle_epi: float = +60,
413
422
  fiber_space: str = "P_1",
414
423
  aha: bool = True,
424
+ verbose: bool = False,
415
425
  ) -> Geometry:
416
426
  """Create an LV ellipsoidal geometry
417
427
 
@@ -447,6 +457,8 @@ def lv_ellipsoid(
447
457
  Function space for fibers of the form family_degree, by default "P_1"
448
458
  aha : bool, optional
449
459
  If True create 17-segment AHA regions
460
+ verbose : bool, optional
461
+ If True print information from gmsh, by default False
450
462
 
451
463
  Returns
452
464
  -------
@@ -497,6 +509,7 @@ def lv_ellipsoid(
497
509
  mu_apex_endo=mu_apex_endo,
498
510
  mu_apex_epi=mu_apex_epi,
499
511
  psize_ref=psize_ref,
512
+ verbose=verbose,
500
513
  )
501
514
  comm.barrier()
502
515
 
@@ -559,6 +572,7 @@ def slab(
559
572
  fiber_angle_endo: float = -60,
560
573
  fiber_angle_epi: float = +60,
561
574
  fiber_space: str = "P_1",
575
+ verbose: bool = False,
562
576
  ) -> Geometry:
563
577
  """Create slab geometry
564
578
 
@@ -582,6 +596,8 @@ def slab(
582
596
  Angle for the epicardium, by default +60
583
597
  fiber_space : str, optional
584
598
  Function space for fibers of the form family_degree, by default "P_1"
599
+ verbose : bool, optional
600
+ If True print information from gmsh, by default False
585
601
 
586
602
  Returns
587
603
  -------
@@ -615,7 +631,14 @@ def slab(
615
631
  default=utils.json_serial,
616
632
  )
617
633
 
618
- cgc.slab(mesh_name=mesh_name.as_posix(), lx=lx, ly=ly, lz=lz, dx=dx)
634
+ cgc.slab(
635
+ mesh_name=mesh_name.as_posix(),
636
+ lx=lx,
637
+ ly=ly,
638
+ lz=lz,
639
+ dx=dx,
640
+ verbose=verbose,
641
+ )
619
642
  comm.barrier()
620
643
 
621
644
  geometry = utils.gmsh2dolfin(comm=comm, msh_file=mesh_name)
@@ -651,6 +674,7 @@ def slab_in_bath(
651
674
  by: float = 0.0,
652
675
  bz: float = 0.1,
653
676
  dx: float = 0.001,
677
+ verbose: bool = False,
654
678
  ) -> Geometry:
655
679
  """Create slab geometry
656
680
 
@@ -672,6 +696,8 @@ def slab_in_bath(
672
696
  Thickness of bath the z-direction, by default 0.1
673
697
  dx : float, optional
674
698
  Element size, by default 0.001
699
+ verbose : bool, optional
700
+ If True print information from gmsh, by default False
675
701
 
676
702
  Returns
677
703
  -------
@@ -714,6 +740,7 @@ def slab_in_bath(
714
740
  by=by,
715
741
  bz=bz,
716
742
  dx=dx,
743
+ verbose=verbose,
717
744
  )
718
745
 
719
746
  geometry = utils.gmsh2dolfin(comm=comm, msh_file=mesh_name)
@@ -1,14 +1,14 @@
1
- from pathlib import Path
2
1
  import tempfile
3
- from typing import NamedTuple, Iterable
4
2
  from enum import Enum
3
+ from pathlib import Path
4
+ from typing import Iterable, NamedTuple
5
5
 
6
- import numpy as np
7
6
  from mpi4py import MPI
8
- from structlog import get_logger
7
+
9
8
  import basix
10
9
  import dolfinx
11
-
10
+ import numpy as np
11
+ from structlog import get_logger
12
12
 
13
13
  logger = get_logger()
14
14
 
@@ -67,19 +67,15 @@ class GMshGeometry(NamedTuple):
67
67
  markers: dict[str, tuple[int, int]]
68
68
 
69
69
 
70
- def read_ffun(mesh, filename: str | Path) -> dolfinx.mesh.MeshTags | None:
71
- mesh.topology.create_connectivity(mesh.topology.dim - 1, mesh.topology.dim)
72
- with dolfinx.io.XDMFFile(mesh.comm, filename, "r") as xdmf:
73
- ffun = xdmf.read_meshtags(mesh, name="Facet tags")
74
-
75
- return ffun
76
-
77
-
78
- def read_mesh(comm, filename: str | Path) -> tuple[dolfinx.mesh.Mesh, dolfinx.mesh.MeshTags | None]:
70
+ def read_mesh(
71
+ comm, filename: str | Path
72
+ ) -> tuple[dolfinx.mesh.Mesh, dolfinx.mesh.MeshTags | None, dolfinx.mesh.MeshTags | None]:
79
73
  with dolfinx.io.XDMFFile(comm, filename, "r") as xdmf:
80
74
  mesh = xdmf.read_mesh(name="Mesh")
81
75
  cfun = xdmf.read_meshtags(mesh, name="Cell tags")
82
- return mesh, cfun
76
+ mesh.topology.create_connectivity(2, 3)
77
+ ffun = xdmf.read_meshtags(mesh, name="Facet tags")
78
+ return mesh, cfun, ffun
83
79
 
84
80
 
85
81
  def gmsh2dolfin(comm: MPI.Intracomm, msh_file, rank: int = 0) -> GMshGeometry:
@@ -95,7 +91,10 @@ def gmsh2dolfin(comm: MPI.Intracomm, msh_file, rank: int = 0) -> GMshGeometry:
95
91
  gmsh.model.add("Mesh from file")
96
92
  gmsh.merge(str(msh_file))
97
93
  mesh, ct, ft = dolfinx.io.gmshio.model_to_mesh(gmsh.model, comm, 0)
98
- markers = {gmsh.model.getPhysicalName(*v): v for v in gmsh.model.getPhysicalGroups()}
94
+ markers = {
95
+ gmsh.model.getPhysicalName(*v): tuple(reversed(v))
96
+ for v in gmsh.model.getPhysicalGroups()
97
+ }
99
98
  gmsh.finalize()
100
99
  else:
101
100
  mesh, ct, ft = dolfinx.io.gmshio.model_to_mesh(gmsh.model, comm, 0)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cardiac-geometriesx
3
- Version: 0.0.3
3
+ Version: 0.1.0
4
4
  Summary: A python library for cardiac geometries
5
5
  Author-email: Henrik Finsberg <henriknf@simula.no>
6
6
  License: MIT
@@ -29,13 +29,14 @@ Requires-Dist: pre-commit ; extra == 'test'
29
29
  Requires-Dist: pytest ; extra == 'test'
30
30
  Requires-Dist: pytest-cov ; extra == 'test'
31
31
 
32
+
32
33
  # Cardiac geometries
33
34
 
34
35
  Cardiac geometries for `dolfinx` (targeting v0.8).
35
36
 
36
37
  Install
37
38
  ```
38
- python3 -m pip install git+https://github.com/ComputationalPhysiology/cardiac-geometriesx
39
+ python3 -m pip install cardiac-geometriesx
39
40
  ```
40
41
 
41
42
  Example usage
@@ -0,0 +1,14 @@
1
+ cardiac_geometries/__init__.py,sha256=2W_ywAeLjyRk5MqSPAodHa4UN2lOnW1h8tmGLQ3gaJ0,150
2
+ cardiac_geometries/cli.py,sha256=2-99xmcBltdotzxp4aDZLrh46gyA5U_PZc6lHen7LIM,19323
3
+ cardiac_geometries/geometry.py,sha256=XRacH519WbrLK0V_Ec6rbxAZFK-n39fUsEzdK3ulbJg,4655
4
+ cardiac_geometries/mesh.py,sha256=cJAcwdDaYmO8MlfocaxvV6pkBcfEWybMSBAaycr6q3s,25987
5
+ cardiac_geometries/utils.py,sha256=-fH13vimCYrirDZubQdxRpX-7I9iCFsOJ8Xo1NL5Nvc,3596
6
+ cardiac_geometries/fibers/__init__.py,sha256=WpRrn9Iakl-3m8IGtFkqP0LXGjw5EZHZ8Eg9JCnCdrg,137
7
+ cardiac_geometries/fibers/lv_ellipsoid.py,sha256=zcCTcst08-xcG5c2j8rPLFp0cgNjXt1Q0mVGhs5r5Ps,3695
8
+ cardiac_geometries/fibers/slab.py,sha256=-EWG4cHjtFYo4VyoFfVnsbHhfdf8qKWphYimJ1jB56o,3867
9
+ cardiac_geometries/fibers/utils.py,sha256=Lstm2m8_QJz04NvLF8oWn644CglXiU89wHPICDMje00,2466
10
+ cardiac_geometriesx-0.1.0.dist-info/METADATA,sha256=GucJisXyXVj82W-8QdwKuL5QvEZmw1vTHq1K0v8c1MY,1349
11
+ cardiac_geometriesx-0.1.0.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
12
+ cardiac_geometriesx-0.1.0.dist-info/entry_points.txt,sha256=xOBnlc6W-H9oCDYLNz3kpki26OmpfYSoFSrmi_4V-Ec,52
13
+ cardiac_geometriesx-0.1.0.dist-info/top_level.txt,sha256=J0gQxkWR2my5Vf7Qt8buDY8ZOjYdVfIweVunCGXWKNE,19
14
+ cardiac_geometriesx-0.1.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (70.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,14 +0,0 @@
1
- cardiac_geometries/__init__.py,sha256=-I-0nXbVFRgfZ-mbXeC-OMg2jh7WnTch6_DkBbAGnGg,202
2
- cardiac_geometries/cli.py,sha256=nOI56WV1fXstL3vxhux90qPnmZ69y1r-PGDYgFMgNeA,19324
3
- cardiac_geometries/geometry.py,sha256=MYF9diZl9igayAuptSyOsHf7-3zJHFd8UgfWtXJgrHk,4849
4
- cardiac_geometries/mesh.py,sha256=tAB9A6J-C4do-pvwShr20s8iQzUm4YfYmXqzGRmYW8Q,25180
5
- cardiac_geometries/utils.py,sha256=BXEpU6qYylE3y7rabBvTXGhNZYbiT177UjJ8assiuXE,3693
6
- cardiac_geometries/fibers/__init__.py,sha256=p6d-3uql8pFailBcLPPGLfRDQs38wefnarS3aSQV0FE,151
7
- cardiac_geometries/fibers/lv_ellipsoid.py,sha256=DWDUV0sGrsZH9O-EtN3veSkE96U6XuHko3WUW9Ce_uc,3695
8
- cardiac_geometries/fibers/slab.py,sha256=sY9VXv-J1D2wSPTcB_6opRmGMLqUXb5ix7C3gJlSJOU,3867
9
- cardiac_geometries/fibers/utils.py,sha256=iozqorgu2KcxbzR52b2Not2IyJ-DrPyqn2Ds-QX2QLE,2584
10
- cardiac_geometriesx-0.0.3.dist-info/METADATA,sha256=5PZwkcOwkoz-4euqoXoRhUsEcS2UlgIagPk2sJRu8Zw,1395
11
- cardiac_geometriesx-0.0.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
12
- cardiac_geometriesx-0.0.3.dist-info/entry_points.txt,sha256=xOBnlc6W-H9oCDYLNz3kpki26OmpfYSoFSrmi_4V-Ec,52
13
- cardiac_geometriesx-0.0.3.dist-info/top_level.txt,sha256=J0gQxkWR2my5Vf7Qt8buDY8ZOjYdVfIweVunCGXWKNE,19
14
- cardiac_geometriesx-0.0.3.dist-info/RECORD,,