nmag-python-3 0.0.2__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.
Files changed (147) hide show
  1. anisotropy/__init__.py +28 -0
  2. anisotropy/anisotropy.py +13 -0
  3. anisotropy/evaluation.py +70 -0
  4. anisotropy/model.py +200 -0
  5. anisotropy/predefined.py +202 -0
  6. anisotropy/py.typed +1 -0
  7. anisotropy/values.py +84 -0
  8. mag_material/__init__.py +3 -0
  9. mag_material/mag_material.py +231 -0
  10. mag_material/parameters.py +150 -0
  11. mag_material/py.typed +1 -0
  12. nmag/__init__.py +36 -0
  13. nmag/backends.py +493 -0
  14. nmag/checkpoint.py +327 -0
  15. nmag/config.py +174 -0
  16. nmag/demag/__init__.py +39 -0
  17. nmag/demag/bem_operator.py +149 -0
  18. nmag/demag/geometry.py +134 -0
  19. nmag/demag/lindholm.py +133 -0
  20. nmag/demag/lindholm_fast.py +463 -0
  21. nmag/demag/linear.py +489 -0
  22. nmag/dynamics/__init__.py +255 -0
  23. nmag/output.py +27 -0
  24. nmag/parallel.py +45 -0
  25. nmag/py.typed +1 -0
  26. nmag/resources.py +38 -0
  27. nmag/simulation/__init__.py +519 -0
  28. nmag/simulation/anisotropy/__init__.py +5 -0
  29. nmag/simulation/anisotropy/fields.py +56 -0
  30. nmag/simulation/anisotropy/materials.py +138 -0
  31. nmag/simulation/demag/__init__.py +1 -0
  32. nmag/simulation/demag/bem/__init__.py +11 -0
  33. nmag/simulation/demag/bem/diagnostics.py +73 -0
  34. nmag/simulation/demag/bem/dirichlet.py +85 -0
  35. nmag/simulation/demag/bem/hierarchical.py +74 -0
  36. nmag/simulation/demag/bem/operator.py +292 -0
  37. nmag/simulation/demag/fem/__init__.py +11 -0
  38. nmag/simulation/demag/fem/assembly.py +114 -0
  39. nmag/simulation/demag/fem/charges.py +38 -0
  40. nmag/simulation/demag/fem/geometry.py +261 -0
  41. nmag/simulation/demag/fields/__init__.py +11 -0
  42. nmag/simulation/demag/fields/auxiliary.py +186 -0
  43. nmag/simulation/demag/fields/probe.py +77 -0
  44. nmag/simulation/demag/fields/recovery.py +207 -0
  45. nmag/simulation/demag/solver.py +17 -0
  46. nmag/simulation/dynamics/__init__.py +92 -0
  47. nmag/simulation/dynamics/advance.py +199 -0
  48. nmag/simulation/dynamics/integrator.py +263 -0
  49. nmag/simulation/exchange/__init__.py +13 -0
  50. nmag/simulation/exchange/coefficients.py +185 -0
  51. nmag/simulation/exchange/fields.py +106 -0
  52. nmag/simulation/exchange/llg_rhs.py +218 -0
  53. nmag/simulation/fields/__init__.py +19 -0
  54. nmag/simulation/fields/arrays.py +111 -0
  55. nmag/simulation/fields/availability.py +188 -0
  56. nmag/simulation/fields/averages.py +293 -0
  57. nmag/simulation/fields/derived.py +164 -0
  58. nmag/simulation/fields/maxangle.py +163 -0
  59. nmag/simulation/fields/probes.py +106 -0
  60. nmag/simulation/implicit_dynamics.py +221 -0
  61. nmag/simulation/mesh/__init__.py +13 -0
  62. nmag/simulation/mesh/geometry.py +153 -0
  63. nmag/simulation/mesh/materials.py +299 -0
  64. nmag/simulation/mesh/probe.py +234 -0
  65. nmag/simulation/restart.py +103 -0
  66. nmag/simulation/support.py +224 -0
  67. nmag_python_3-0.0.2.dist-info/METADATA +157 -0
  68. nmag_python_3-0.0.2.dist-info/RECORD +147 -0
  69. nmag_python_3-0.0.2.dist-info/WHEEL +5 -0
  70. nmag_python_3-0.0.2.dist-info/licenses/LICENSE +339 -0
  71. nmag_python_3-0.0.2.dist-info/top_level.txt +8 -0
  72. nmesh/__init__.py +130 -0
  73. nmesh/backend.py +286 -0
  74. nmesh/geometry/__init__.py +52 -0
  75. nmesh/geometry/boolean_operations.py +157 -0
  76. nmesh/geometry/primitives.py +453 -0
  77. nmesh/geometry/transform.py +126 -0
  78. nmesh/io/__init__.py +50 -0
  79. nmesh/io/ascii.py +132 -0
  80. nmesh/io/legacy_nmesh_hdf5.py +318 -0
  81. nmesh/io/meshio_support.py +170 -0
  82. nmesh/mesh_generation.py +182 -0
  83. nmesh/mesh_io.py +227 -0
  84. nmesh/mesh_model.py +147 -0
  85. nmesh/mesh_utilities.py +79 -0
  86. nmesh/mesher/__init__.py +21 -0
  87. nmesh/mesher/driver.py +146 -0
  88. nmesh/mesher/meshing_defaults.py +252 -0
  89. nmesh/mesher/meshing_parameters.py +185 -0
  90. nmesh/mesher/parity.py +21 -0
  91. nmesh/mesher/parity_canonical.py +142 -0
  92. nmesh/mesher/parity_comparison.py +191 -0
  93. nmesh/mesher/parity_metrics.py +114 -0
  94. nmesh/mesher/periodic.py +97 -0
  95. nmesh/mesher/relaxation/__init__.py +14 -0
  96. nmesh/mesher/relaxation/_constants.py +20 -0
  97. nmesh/mesher/relaxation/_types.py +15 -0
  98. nmesh/mesher/relaxation/density.py +170 -0
  99. nmesh/mesher/relaxation/engine/__init__.py +18 -0
  100. nmesh/mesher/relaxation/engine/state.py +155 -0
  101. nmesh/mesher/relaxation/engine/steps.py +248 -0
  102. nmesh/mesher/relaxation/engine/topology.py +230 -0
  103. nmesh/mesher/relaxation/forces/__init__.py +96 -0
  104. nmesh/mesher/relaxation/forces/jit.py +102 -0
  105. nmesh/mesher/relaxation/forces/neighbors.py +186 -0
  106. nmesh/mesher/relaxation/forces/simplex.py +302 -0
  107. nmesh/mesher/relaxation/forces/summary.py +207 -0
  108. nmesh/mesher/relaxation/forces/types.py +92 -0
  109. nmesh/mesher/relaxation/geometry/__init__.py +6 -0
  110. nmesh/mesher/relaxation/geometry/builder.py +154 -0
  111. nmesh/mesher/relaxation/geometry/model.py +194 -0
  112. nmesh/mesher/relaxation/seeding/__init__.py +74 -0
  113. nmesh/mesher/relaxation/seeding/periodic.py +88 -0
  114. nmesh/mesher/relaxation/seeding/points.py +88 -0
  115. nmesh/mesher/relaxation/seeding/sampling.py +142 -0
  116. nmesh/mesher/relaxation/topology/__init__.py +297 -0
  117. nmesh/mesher/relaxation/topology/finalize.py +78 -0
  118. nmesh/mesher/relaxation/topology/recovery.py +310 -0
  119. nmesh/mesher/sectioned_config.py +70 -0
  120. nmesh/nmesh.py +99 -0
  121. nmesh/py.typed +1 -0
  122. nmesh/utils/__init__.py +33 -0
  123. nmesh/utils/array_list_utils.py +128 -0
  124. nmesh/utils/constants.py +22 -0
  125. nmesh/utils/timing_memory_utils.py +51 -0
  126. nmesh/utils/types.py +13 -0
  127. si/constants.py +49 -0
  128. si/physical.py +722 -0
  129. si/py.typed +1 -0
  130. simulation/__init__.py +1 -0
  131. simulation/clock.py +237 -0
  132. simulation/data_writer.py +273 -0
  133. simulation/data_writer_collection.py +267 -0
  134. simulation/hysteresis.py +74 -0
  135. simulation/hysteresis_runner.py +286 -0
  136. simulation/hysteresis_schedule.py +180 -0
  137. simulation/inference/__init__.py +3 -0
  138. simulation/inference/inference.py +95 -0
  139. simulation/py.typed +1 -0
  140. simulation/quantity.py +88 -0
  141. simulation/simulation_core.py +458 -0
  142. throttler/__init__.py +3 -0
  143. throttler/py.typed +1 -0
  144. throttler/throttler.py +55 -0
  145. when/__init__.py +3 -0
  146. when/py.typed +1 -0
  147. when/when.py +416 -0
@@ -0,0 +1,51 @@
1
+ import logging
2
+ import os
3
+ import re
4
+ import time
5
+
6
+ log = logging.getLogger(__name__)
7
+
8
+ _time_zero: float | None = None
9
+
10
+
11
+ def time_passed() -> float:
12
+ """Returns elapsed time since the first call to this function."""
13
+ global _time_zero
14
+ if _time_zero is None:
15
+ _time_zero = time.time()
16
+ return 0.0
17
+ return time.time() - _time_zero
18
+
19
+
20
+ def memstats(self_status_file: str = "/proc/self/status") -> list[float]:
21
+ """Reads VmSize and VmRSS from /proc/self/status (Linux)."""
22
+ vmsize_vmrss = [0.0, 0.0]
23
+ if not os.path.exists(self_status_file):
24
+ return vmsize_vmrss
25
+
26
+ # Matches "VmSize: 1234 kB" or "VmRSS: 5678 KB".
27
+ re_pattern = re.compile(r"^(VmSize|VmRSS):\s+(\d+)\s+[kK][bB]", re.MULTILINE)
28
+ try:
29
+ with open(self_status_file) as fd:
30
+ content = fd.read()
31
+ found = 0
32
+ for match in re_pattern.finditer(content):
33
+ key = match.group(1)
34
+ value = float(match.group(2))
35
+ if key == "VmSize":
36
+ vmsize_vmrss[0] = value
37
+ else:
38
+ vmsize_vmrss[1] = value
39
+ found += 1
40
+ if found >= 2:
41
+ break
42
+ except Exception as e:
43
+ log.debug(f"Failed to read memstats: {e}")
44
+ return vmsize_vmrss
45
+
46
+
47
+ def time_vmem_rss() -> tuple[float, float, float]:
48
+ """Returns (elapsed_time, vmem, rss) where memory is in KB."""
49
+ t = time_passed()
50
+ mem = memstats()
51
+ return t, mem[0], mem[1]
nmesh/utils/types.py ADDED
@@ -0,0 +1,13 @@
1
+ """Common type aliases used throughout the nmesh package."""
2
+
3
+ from typing import Any, TypeAlias
4
+
5
+ import numpy as np
6
+ from numpy.typing import NDArray
7
+
8
+ __all__ = ["ArrayLike", "FloatArray", "BoolArray", "IntArray"]
9
+
10
+ ArrayLike: TypeAlias = Any
11
+ FloatArray: TypeAlias = NDArray[np.float64]
12
+ BoolArray: TypeAlias = NDArray[np.bool_]
13
+ IntArray: TypeAlias = NDArray[np.int_]
si/constants.py ADDED
@@ -0,0 +1,49 @@
1
+ """
2
+ Original file: https://github.com/nmag-project/nmag-src/blob/master/interface/nsim/si_units/si.py
3
+ Some useful SI constants, defined using the pint library's authoritative values.
4
+
5
+ This module provides common physical constants as pint Quantity objects
6
+ for direct use in calculations. It replaces hard-coded values with references
7
+ to the pint library's built-in constants, which are based on up-to-date
8
+ CODATA values.
9
+ https://github.com/hgrecco/pint/blob/master/pint/default_en.txt
10
+ https://github.com/hgrecco/pint/blob/master/pint/constants_en.txt
11
+ """
12
+
13
+ from si.physical import ureg
14
+
15
+ # --- Base and Common Units ---
16
+ kilogram = ureg.kilogram
17
+ meter = ureg.meter
18
+ metre = meter # alternative spelling
19
+ Ampere = ureg.ampere
20
+ Kelvin = ureg.kelvin
21
+ second = ureg.second
22
+ candela = ureg.candela
23
+ mol = ureg.mole
24
+ Joule = ureg.joule
25
+ Newton = ureg.newton
26
+ Tesla = ureg.tesla
27
+ Gauss = ureg.gauss
28
+
29
+ # --- Physical Constants (from pint's library) ---
30
+
31
+ mu0 = ureg.mu_0
32
+ Oersted = ureg.oersted
33
+ Oe = Oersted
34
+ bohr_magneton = ureg.bohr_magneton
35
+ positron_charge = ureg.e
36
+ electron_charge = -1 * ureg.e
37
+ boltzmann_constant = ureg.k
38
+ plank_constant = ureg.h
39
+ reduced_plank_constant = ureg.hbar
40
+
41
+ # --- Custom or Specific Values ---
42
+
43
+ degrees_per_ns = 1 * ureg.degree / ureg.nanosecond
44
+
45
+ gamma_e = (ureg.g_e * ureg.e) / (2 * ureg.m_e)
46
+ # This constant, often used in micromagnetics, is the product of the
47
+ # electron gyromagnetic ratio (gamma_e) and the vacuum permeability (mu_0).
48
+ # The negative sign is a convention used in the LLG equation.
49
+ gamma0 = -1 * gamma_e * ureg.mu_0