Python API
oersted
Python bindings for oersted
BHCurve
dataclass
B-H curve for a nonlinear magnetic material
Source code in src/oersted/materials.py
11 12 13 14 15 16 17 18 19 20 21 | |
lookup
lookup(h: float) -> float
Linearly interpolate from the B-H curve
Source code in src/oersted/materials.py
18 19 20 21 | |
CentroidMesh
A finite element mesh represented solely by the centroidal values of the elements
This is used in the point source calculations. It is an approximation, but extremely
fast and accurate for far field or force calculations.
Source code in src/oersted/mesh.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
LinearMaterial
dataclass
Bases: Material
A linear magnetic material that has a constant mu_r for all values of applied H-field.
Source code in src/oersted/materials.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
Mesh
A continuous finite element mesh made of tet4 elements
Source code in src/oersted/mesh.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
centroids
property
centroids: NDArray[float64]
Returns an (N,3) array of all element centroids in the mesh
connectivity
property
connectivity: NDArray[uint32]
Returns an (N,4) array of the node numbers associated with each element
Node numbers are indices into the self._nodes array
edges
property
edges
Returns an (N,2) array of edges in the model
Each value in the array is a node number associated with that edge. The first node is the start node, the second is the end node. This provides directionality for the edge.
faces
property
faces
Returns an (N,3) array of nodes associated with each element face in the model
Nodes are ordered such that the right hand rule forms the face normal.
nodes
property
nodes: NDArray[float64]
Returns an (N,3) array of nodal coordinates in the mesh
num_elems
property
num_elems: int
Returns the number of elements in the model
num_nodes
property
num_nodes: int
Returns the number of nodes in the model
volumes
property
volumes: NDArray[float64]
Return an (N,) array of the volume of each element in the mesh
to_centroid_mesh
to_centroid_mesh() -> CentroidMesh
Create a centroid mesh from a tet4 mesh
Source code in src/oersted/mesh.py
170 171 172 | |
NonlinearMaterial
dataclass
Bases: Material
A nonlinear magnetic material that has a B-H curve
Source code in src/oersted/materials.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
b_field
b_field(
source: Mesh | CentroidMesh,
j_density: NDArray[float64],
targets: NDArray[float64],
solver: DirectSolver | OctreeSolver | None = None,
) -> NDArray[float64]
Compute the magnetic flux density at a collection of target points using the specific source mesh and solver options, assuming the target points are in free space
Source code in src/oersted/biotsavart.py
23 24 25 26 27 28 29 | |
h_field
h_field(
source: Mesh | CentroidMesh,
j_density: NDArray[float64],
targets: NDArray[float64],
solver: DirectSolver | OctreeSolver | None = None,
) -> NDArray[float64]
Compute the magnetic field strength at a collection of target points using a current-carrying source mesh.
Source code in src/oersted/biotsavart.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
h_mag
h_mag(
source: Mesh | CentroidMesh,
m_field: NDArray[float64],
targets: NDArray[float64],
solver: DirectSolver | OctreeSolver | None = None,
) -> NDArray[float64]
Compute the magnetic field strength using a magnetized mesh as the source
Source code in src/oersted/biotsavart.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
mesh_step
mesh_step(
infile: str,
min_size: float,
max_size: float,
scale=0.001,
) -> Mesh
Mesh a step file using gmsh
Source code in src/oersted/mesh.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
oersted.testing
Utility functions for tests
bz_finite_length_solenoid
bz_finite_length_solenoid(
jmag: float,
length: float,
r: float,
dr: float,
z: float,
) -> float
Compute the magnetic field on the axis of a finite-length solenoid
This function assumes that the solenoid dr dimension is small relative to the
radius and thickness, and does not correct for finite radial thickness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jmag
|
float
|
(A/m2) magnitude of current density in the solenoid |
required |
length
|
float
|
(m) length of the solenoid |
required |
r
|
float
|
(m) representative radius of the solenoid |
required |
dr
|
float
|
(m) thickness of the solenoid cross section |
required |
z
|
float
|
(m) position along the axis of the solenoid at which the field should be calculated |
required |
Returns:
| Type | Description |
|---|---|
float
|
(T) axial magnetic field |
Reference
https://en.wikipedia.org/wiki/Solenoid#Finite_continuous_solenoid (with modifications for current density and finite thickness)
Source code in src/oersted/testing.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
make_helmholtz
make_helmholtz(
filename: str,
size: float,
jmag: None | float = None,
scale=0.001,
) -> tuple[Mesh, NDArray[float64]]
Make the helmholtz coil test problem
Source code in src/oersted/testing.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
mean_absolute_error
mean_absolute_error(
baseline: NDArray[float64],
measurement: NDArray[float64],
) -> float
Compute the mean absolute error of measurement against baseline
Source code in src/oersted/testing.py
44 45 46 47 48 49 50 51 52 | |
mean_relative_error
mean_relative_error(
baseline: NDArray[float64],
measurement: NDArray[float64],
) -> float
Compute the mean relative error of measurement against baseline
Source code in src/oersted/testing.py
32 33 34 35 36 37 38 39 40 41 | |
mean_squared_error
mean_squared_error(
baseline: NDArray[float64],
measurement: NDArray[float64],
) -> float
Compute the mean squared error of measurement measured against baseline
Error is computed according to this reference: https://en.wikipedia.org/wiki/Mean_squared_error#Predictor
This is an absolute, not a relative error measurement.
baseline: N-length array of 'ground-truth' values
measurement: N-length array of values to which determine error (deviation) from baseline
Source code in src/oersted/testing.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
smape
smape(
baseline: NDArray[float64],
measurement: NDArray[float64],
) -> float
Compute the symmetric mean absolute percentage error of measurement against baseline
SMAPE is defined here: https://en.wikipedia.org/wiki/Symmetric_mean_absolute_percentage_error
Source code in src/oersted/testing.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |