Magnets module
pymagnet.magnets
This module imports the classes and functions in the private modules to create a public API.
Circle
Bases: Magnet2D
Circle 2D Magnet Class
Source code in src/pymagnet/magnets/_magnet2D.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
__init__(radius=10, Jr=1.0, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius. Defaults to 10.0. |
10
|
Jr
|
float
|
Remnant magnetisation. Defaults to 1.0. |
1.0
|
Kwargs
alpha (float): Unused. For rotations use phi instead center (tuple or ndarray): magnet center (x, y). Defaults to (0,0) phi (float): Rotation Angle (in degrees) of magnet w.r.t x-axis. Defaults to 90.
Source code in src/pymagnet/magnets/_magnet2D.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
get_Jr()
Returns signed remnant magnetisation
Returns:
| Type | Description |
|---|---|
ndarray
|
remnant magnetisation |
Source code in src/pymagnet/magnets/_magnet2D.py
360 361 362 363 364 365 366 | |
get_field(x, y)
Calculates the magnetic field due to long bipolar cylinder
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x coordinates |
required |
y
|
ndarray
|
y coordinates |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Bx, By magnetic field in cartesian coordinates |
Source code in src/pymagnet/magnets/_magnet2D.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
get_size()
Returns radius
Returns:
| Type | Description |
|---|---|
ndarray
|
radius |
Source code in src/pymagnet/magnets/_magnet2D.py
352 353 354 355 356 357 358 | |
Cube
Bases: Prism
Cube 3D Magnet Class
Source code in src/pymagnet/magnets/_magnet3D.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | |
__init__(width=10.0, Jr=1.0, **kwargs)
Init method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
Cube side length. Defaults to 10.0. |
10.0
|
Kwargs
center (ndarray): Magnet center. Defaults to (0.0, 0.0, 0.0) mask_magnet (bool): Flag to mask magnet or not in plots alpha (float): Magnet Orientation angle about z (degrees). Defaults to 0.0 beta (float): Magnet Orientation angle about y (degrees). Defaults to 0.0 gamma (float): Magnet Orientation angle about x (degrees). Defaults to 0.0 phi (float): Angle of magnetisation vector (in degrees) with respect to x-axis. Defaults to 90.0 theta (float): Angle of magnetisation vector (in degrees) with respect to z-axis. Defaults to 0.0
Source code in src/pymagnet/magnets/_magnet3D.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | |
Cylinder
Bases: Magnet3D
Cylinder 3D Magnet Class
Returns:
| Type | Description |
|---|---|
Cylinder
|
Cylinder 3D magnet object |
Source code in src/pymagnet/magnets/_magnet3D.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 | |
__init__(radius=10.0, length=10.0, Jr=1.0, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
radius. Defaults to 10.0. |
10.0
|
length
|
float
|
length. Defaults to 10.0. |
10.0
|
Kwargs
center (ndarray): Magnet center. Defaults to (0.0, 0.0, 0.0) mask_magnet (bool): Flag to mask magnet or not in plots alpha (float): Magnet Orientation angle about z (degrees). Defaults to 0.0 beta (float): Magnet Orientation angle about y (degrees). Defaults to 0.0 gamma (float): Magnet Orientation angle about x (degrees). Defaults to 0.0 phi (float): Angle of magnetisation vector (in degrees) with respect to x-axis. Defaults to 90.0 theta (float): Angle of magnetisation vector (in degrees) with respect to z-axis. Defaults to 0.0
Source code in src/pymagnet/magnets/_magnet3D.py
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 | |
get_force_torque(num_samples=20, unit='mm')
Calculates the force and torque on a cylinder magnet due to all other magnets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples
|
int
|
Number of samples per axis per face. Defaults to 20. |
20
|
unit
|
str
|
Length scale. Defaults to 'mm'. |
'mm'
|
Returns:
| Type | Description |
|---|---|
tuple
|
force (ndarray (3,) ) and torque (ndarray (3,) ) |
Source code in src/pymagnet/magnets/_magnet3D.py
733 734 735 736 737 738 739 740 741 742 743 744 745 746 | |
get_size()
Returns magnet dimesions
Returns:
| Type | Description |
|---|---|
size[ndarray]
|
numpy array [radius, length] |
Source code in src/pymagnet/magnets/_magnet3D.py
722 723 724 725 726 727 728 | |
Line
Line Class for storing properties of a sheet manget
Source code in src/pymagnet/magnets/_polygon2D.py
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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
__init__(length, center, beta, K)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
float
|
side length |
required |
center
|
ndarray
|
magnet center (x, y) |
required |
beta
|
float
|
Orientation w.r.t. z-axis in degrees |
required |
K
|
float
|
Sheet current density in tesla |
required |
Source code in src/pymagnet/magnets/_polygon2D.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
get_center()
Returns line center
Returns:
| Type | Description |
|---|---|
ndarray
|
center (x,y) |
Source code in src/pymagnet/magnets/_polygon2D.py
299 300 301 302 303 304 305 306 | |
get_field(x, y)
Calculates the magnetic field due to a sheet magnet First a transformation into the local coordinates is made, the field calculated and then the magnetic field it rotated out to the global coordinates
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x-coordinates |
required |
y
|
ndarray
|
y-coordinates |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Bx (ndarray), By (ndarray) magnetic field vector |
Source code in src/pymagnet/magnets/_polygon2D.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
LineUtils
Utility class consisting of rountines for 2D line elements
Source code in src/pymagnet/magnets/_polygon2D.py
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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
line_center(vertex_1, vertex_2)
staticmethod
Gets midpoint of two vertices
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex_1
|
ndarray
|
vertex 1 |
required |
vertex_2
|
ndarray
|
vertex 2 |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
midpoint |
Source code in src/pymagnet/magnets/_polygon2D.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
signed_area2D(polygon)
staticmethod
Calculates signed area of a polygon
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
Polygon
|
Polygon instance |
required |
Returns:
| Type | Description |
|---|---|
float
|
signed area |
Source code in src/pymagnet/magnets/_polygon2D.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
unit_norm(vertex_1, vertex_2, clockwise=True)
staticmethod
Get unit normal to vertex
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex_1
|
ndarray
|
vertex 1 |
required |
vertex_2
|
ndarray
|
vertex 2 |
required |
clockwise
|
bool
|
Clockwise orientation of points. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
tuple
|
normal vector (ndarray), length i.e. distance between vertices (float) |
Source code in src/pymagnet/magnets/_polygon2D.py
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 | |
Magnet
Bases: Registry
Magnet base class
Returns:
| Type | Description |
|---|---|
Magnet
|
magnet base class |
Source code in src/pymagnet/magnets/_magnet_base.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
Magnet2D
Bases: Magnet
2D Magnet Base Class
Source code in src/pymagnet/magnets/_magnet2D.py
19 20 21 22 23 24 25 26 27 28 29 30 31 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 70 71 72 73 74 75 76 77 | |
__init__(Jr, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Jr
|
float
|
signed magnetised of remnant magnetisation |
required |
Kwargs
alpha (float): Magnetisation orientation angle (in degrees). Defaults to 0. center (tuple or ndarray): magnet center (x, y). Defaults to (0,0).
Source code in src/pymagnet/magnets/_magnet2D.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
get_center()
Returns magnet centre
Returns:
| Type | Description |
|---|---|
center (ndarray
|
numpy array [xc, yc] |
Source code in src/pymagnet/magnets/_magnet2D.py
44 45 46 47 48 49 50 | |
get_field(x, y)
Calculates the magnetic field.
This is a template that needs to be implemented for each magnet
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x co-ordinates |
required |
y
|
ndarray
|
y co-ordinates |
required |
Source code in src/pymagnet/magnets/_magnet2D.py
61 62 63 64 65 66 67 68 69 70 | |
get_force_torque()
Calculates the force and torque on a magnet due to all other magnets.
This is a template that needs to be implemented for each magnet.
Source code in src/pymagnet/magnets/_magnet2D.py
72 73 74 75 76 77 | |
get_orientation()
Returns magnet orientation, alpha in degrees
Returns:
| Type | Description |
|---|---|
float
|
alpha, rotation angle w.r.t x-axis. |
Source code in src/pymagnet/magnets/_magnet2D.py
52 53 54 55 56 57 58 59 | |
Magnet3D
Bases: Magnet
3D Magnet Base Class
Returns:
| Type | Description |
|---|---|
Magnet3D
|
3D magnet object |
Source code in src/pymagnet/magnets/_magnet3D.py
29 30 31 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 70 71 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 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 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
__init__(Jr, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Jr
|
float
|
Signed remnant magnetisation |
required |
Kwargs
center (ndarray): Magnet center. Defaults to (0.0, 0.0, 0.0) mask_magnet (bool): Flag to mask magnet or not in plots alpha (float): Magnet Orientation angle about z (degrees). Defaults to 0.0 beta (float): Magnet Orientation angle about y (degrees). Defaults to 0.0 gamma (float): Magnet Orientation angle about x (degrees). Defaults to 0.0
Source code in src/pymagnet/magnets/_magnet3D.py
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 70 71 72 73 74 75 | |
get_Jr()
Returns local magnetisation orientation
Must be implemented for all classes
Source code in src/pymagnet/magnets/_magnet3D.py
85 86 87 88 89 90 | |
get_center()
Returns magnet center
Returns:
| Type | Description |
|---|---|
ndarray
|
[center_x, center_y, center_z] |
Source code in src/pymagnet/magnets/_magnet3D.py
77 78 79 80 81 82 83 | |
get_field(x, y, z)
Calculates the magnetic field at point(s) x,y,z due to a 3D magnet The calculations are always performed in local coordinates with the centre of the magnet at origin and z magnetisation pointing along the local z' axis.
The rotations and translations are performed first, and the internal field calculation functions are called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x co-ordinates |
required |
y
|
ndarray
|
y co-ordinates |
required |
z
|
ndarray
|
z co-ordinates |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Bx(ndarray), By(ndarray), Bz(ndarray) field vector |
Source code in src/pymagnet/magnets/_magnet3D.py
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 | |
get_force_torque()
Calculates the force and torque on a magnet due to all other magnets.
This is a template that needs to be implemented for each magnet.
Source code in src/pymagnet/magnets/_magnet3D.py
209 210 211 212 213 214 | |
get_orientation()
Returns magnet orientation, alpha, beta, gamma in degrees
Returns:
| Type | Description |
|---|---|
ndarray
|
alpha, beta, gamma rotation angles w.r.t z, y, and x axes |
Source code in src/pymagnet/magnets/_magnet3D.py
92 93 94 95 96 97 98 99 | |
get_size()
Returns magnet dimesions
Must be implemented for each magnet
Source code in src/pymagnet/magnets/_magnet3D.py
237 238 239 240 241 242 | |
Mesh
Bases: Magnet3D
Mesh Magnet Class.
Source code in src/pymagnet/magnets/_polygon3D.py
25 26 27 28 29 30 31 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 70 71 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 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 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | |
__init__(filename, Jr=1.0, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
string
|
path to stl file to be imported |
required |
Jr
|
float
|
Signed remnant magnetisation. Defaults to 1.0. |
1.0
|
Kwargs
phi (float): theta (float): mesh_scale (float): scaling factor if mesh needs to be resized. Defaults to 1.0
Source code in src/pymagnet/magnets/_polygon3D.py
30 31 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
calcB_triangle(triangle, Jr, x, y, z, i)
Calculates the magnetic field due to a triangle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
triangle
|
ndarray
|
Vertices of a triangle |
required |
Jr
|
float
|
Remnant magnetisation component normal to triangle |
required |
x
|
ndarray
|
x coordinates |
required |
y
|
ndarray
|
y coordinates |
required |
z
|
ndarray
|
z coordinates |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Bx, By, Bz magnetic field components |
Source code in src/pymagnet/magnets/_polygon3D.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
get_Jr()
Returns Magnetisation vector
Returns:
| Type | Description |
|---|---|
ndarray
|
[Jx, Jy, Jz] |
Source code in src/pymagnet/magnets/_polygon3D.py
107 108 109 110 111 112 113 | |
get_center()
Returns magnet center
Returns:
| Type | Description |
|---|---|
ndarray
|
magnet center |
Source code in src/pymagnet/magnets/_polygon3D.py
123 124 125 126 127 128 129 | |
get_field(x, y, z, parallel=True, r_cut=_np.inf)
Calculates the magnetic field at point(s) x,y,z due to a 3D magnet The calculations are always performed in local coordinates with the centre of the magnet at origin and z magnetisation pointing along the local z' axis.
The rotations and translations are performed first, and the internal field calculation functions are called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float / array
|
x co-ordinates |
required |
y
|
float / array
|
y co-ordinates |
required |
z
|
float / array
|
z co-ordinates |
required |
parallel
|
bool
|
If True, use parallel numba implementation |
True
|
r_cut
|
float
|
Distance cutoff. Triangles whose centroid is farther
than |
inf
|
Returns:
| Type | Description |
|---|---|
tuple
|
Bx(ndarray), By(ndarray), Bz(ndarray) field vector |
Source code in src/pymagnet/magnets/_polygon3D.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
get_force_torque(depth=4, unit='mm')
Calculates the force and torque on a prism magnet due to all other magnets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depth
|
int
|
Number of recursions of division by 4 per simplex |
4
|
unit
|
str
|
Length scale. Defaults to 'mm'. |
'mm'
|
Returns:
| Type | Description |
|---|---|
tuple
|
force (ndarray (3,) ) and torque (ndarray (3,) ) |
Source code in src/pymagnet/magnets/_polygon3D.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
size()
Returns magnet dimesions
Returns:
| Type | Description |
|---|---|
size (ndarray
|
numpy array [width, depth, height] |
Source code in src/pymagnet/magnets/_polygon3D.py
115 116 117 118 119 120 121 | |
PolyMagnet
Bases: Magnet2D
2D Magnet Polygon class.
Source code in src/pymagnet/magnets/_polygon2D.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
__init__(Jr, **kwargs)
Init method
NOTE
- When creating a regular polygon, one of apothem, radius, or length must be defined as a kwarg or an exception will be raised.
- When creating a regular polygon, the number of sides
num_sidesmust be at least 3 or an exception will be raised. - When creating a custom polygon at least one vertex pair must be
defined with
verticesor an exception will be raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Jr
|
float
|
signed magnitude of remnant magnetisation |
required |
Kwargs
alpha (float): Not used theta (float): Orientation of magnet w.r.t x-axis of magnet phi (float): Orientation of magnetisation w.r.t x-axis of magnet in degrees. Defaults to 90.0. center (ndarray): magnet center (x, y). Defaults to (0.0, 0.0) length (float): side length if creating a regular polygon apothem (float): apothem (incircle radius) if creating a regular polygon radius (float): radius (circumcircle radius) if creating a regular polygon num_sides (int): number of sides of a regular polygon. Defaults to 6. custom_polygon (bool): Flag to define a custom polygon. Defaults to False. vertices (ndarray, list): List of custom vertices. Defaults to None.
Raises:
| Type | Description |
|---|---|
Exception
|
If creating a custom polygon, |
Source code in src/pymagnet/magnets/_polygon2D.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
get_center()
Returns magnet centre
Returns:
| Type | Description |
|---|---|
center (ndarray
|
numpy array [xc, yc] |
Source code in src/pymagnet/magnets/_polygon2D.py
432 433 434 435 436 437 438 | |
get_field(x, y)
Calculates the magnetic field of a polygon due to each face
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x-coordinates |
required |
y
|
ndarray
|
y-coordinates |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Bx (ndarray), By (ndarray) magnetic field vector |
Source code in src/pymagnet/magnets/_polygon2D.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
get_orientation()
Returns magnet orientation, alpha in degrees
Returns:
| Type | Description |
|---|---|
float
|
alpha, rotation angle w.r.t x-axis. |
Source code in src/pymagnet/magnets/_polygon2D.py
440 441 442 443 444 445 446 447 | |
Polygon
Polygon class for generating list of vertices
Source code in src/pymagnet/magnets/_polygon2D.py
29 30 31 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 70 71 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 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 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 | |
append(vertex)
Appends vertex to list of vertices
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex
|
list
|
list of vertices |
required |
Source code in src/pymagnet/magnets/_polygon2D.py
51 52 53 54 55 56 57 58 59 60 61 62 63 | |
check_radius(N, apothem, length, radius)
staticmethod
Checks which of apothem, side length, or radius has been passed as kwargs
to gen_polygon(). Order of precendence is apothem, length, radius.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
Number of sides |
required |
apothem
|
float
|
polygon apothem |
required |
length
|
float
|
side length |
required |
radius
|
float
|
outcircle radius |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
One of apothem, length, or raduis must be defined |
Returns:
| Type | Description |
|---|---|
float
|
returns radius |
Source code in src/pymagnet/magnets/_polygon2D.py
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 | |
gen_polygon(N=6, center=(0.0, 0.0), alpha=0.0, **kwargs)
staticmethod
Generates regular polygon. One of apothem, side length or radius must be defined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
Number of sides. Defaults to 6. |
6
|
center
|
tuple
|
Polygon center. Defaults to (0.0, 0.0). |
(0.0, 0.0)
|
alpha
|
float
|
Orientration with respect to x-axis. Defaults to 0.0. |
0.0
|
Raises:
| Type | Description |
|---|---|
Exception
|
N must be > 2 |
Returns:
| Type | Description |
|---|---|
ndarray
|
polygon vertices |
Source code in src/pymagnet/magnets/_polygon2D.py
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
num_vertices()
Gets number of vertices
Returns:
| Type | Description |
|---|---|
int
|
number of vertices |
Source code in src/pymagnet/magnets/_polygon2D.py
65 66 67 68 69 70 71 | |
set_center()
Sets center of polygon to be centroid
Source code in src/pymagnet/magnets/_polygon2D.py
73 74 75 76 | |
Prism
Bases: Magnet3D
Prism 3D Magnet Class
Returns:
| Type | Description |
|---|---|
Prism
|
Prism magnet object |
Source code in src/pymagnet/magnets/_magnet3D.py
245 246 247 248 249 250 251 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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
__init__(width=10.0, depth=20.0, height=30.0, Jr=1.0, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
Magnet width in x. Defaults to 10.0. |
10.0
|
depth
|
float
|
Magnet depth in y. Defaults to 20.0. |
20.0
|
height
|
float
|
Magnet height in z. Defaults to 30.0. |
30.0
|
Kwargs
center (ndarray): Magnet center. Defaults to (0.0, 0.0, 0.0) mask_magnet (bool): Flag to mask magnet or not in plots alpha (float): Magnet Orientation angle about z (degrees). Defaults to 0.0 beta (float): Magnet Orientation angle about y (degrees). Defaults to 0.0 gamma (float): Magnet Orientation angle about x (degrees). Defaults to 0.0 phi (float): Angle of magnetisation vector (in degrees) with respect to x-axis. Defaults to 90.0 theta (float): Angle of magnetisation vector (in degrees) with respect to z-axis. Defaults to 0.0
Source code in src/pymagnet/magnets/_magnet3D.py
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 299 300 301 | |
get_Jr()
Returns magnetisation vector J
Returns:
| Type | Description |
|---|---|
ndarray
|
[Jx, Jy, Jz] |
Source code in src/pymagnet/magnets/_magnet3D.py
323 324 325 326 327 328 329 | |
get_force_torque(num_samples=20, unit='mm')
Calculates the force and torque on a prism magnet due to all other magnets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples
|
int
|
Number of samples per axis per face. Defaults to 20. |
20
|
unit
|
str
|
Length scale. Defaults to 'mm'. |
'mm'
|
Returns:
| Type | Description |
|---|---|
tuple
|
force (ndarray (3,) ) and torque (ndarray (3,) ) |
Source code in src/pymagnet/magnets/_magnet3D.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
get_size()
Returns magnet dimesions
Returns: ndarray: [width, depth, height]
Source code in src/pymagnet/magnets/_magnet3D.py
331 332 333 334 335 336 337 | |
Rectangle
Bases: Magnet2D
Rectangular 2D Magnet Class
Source code in src/pymagnet/magnets/_magnet2D.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 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 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
__init__(width=20.0, height=40.0, Jr=1.0, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
Magnet Width. Defaults to 20.0. |
20.0
|
height
|
float
|
Magnet Height. Defaults to 40.0. |
40.0
|
Jr
|
float
|
Remnant Magnetisation. Defaults to 1.0. |
1.0
|
Kwargs
alpha (float): Magnetisation orientation angle (in degrees). Defaults to 0. center (tuple or ndarray): magnet center (x, y). Defaults to (0,0). phi (float): Rotation Angle (in degrees) of magnet w.r.t x-axis. Defaults to 90.
Source code in src/pymagnet/magnets/_magnet2D.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
get_Jr()
Returns Magnetisation vector
Returns:
| Type | Description |
|---|---|
ndarray
|
[Jx, Jy] |
Source code in src/pymagnet/magnets/_magnet2D.py
140 141 142 143 144 145 146 | |
get_field(x, y)
Calculates the magnetic field at point(s) x,y due to a rectangular magnet
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x co-ordinates |
required |
y
|
ndarray
|
y co-ordinates |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
magnetic field vector Bx (ndarray), By (ndarray) |
Source code in src/pymagnet/magnets/_magnet2D.py
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 | |
get_size()
Returns magnet dimesions
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy array [width, height] |
Source code in src/pymagnet/magnets/_magnet2D.py
112 113 114 115 116 117 118 | |
Sphere
Bases: Magnet3D
Sphere 3D Magnet Class
Returns:
| Type | Description |
|---|---|
Sphere
|
Sphere 3D magnet object |
Source code in src/pymagnet/magnets/_magnet3D.py
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 | |
__init__(radius=10.0, Jr=1.0, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
radius. Defaults to 10.0. |
10.0
|
Jr
|
float
|
remnant magnetisation. Defaults to 1.0. |
1.0
|
Kwargs
center (ndarray): Magnet center. Defaults to (0.0, 0.0, 0.0) mask_magnet (bool): Flag to mask magnet or not in plots alpha (float): Magnet Orientation angle about z (degrees). Defaults to 0.0 beta (float): Magnet Orientation angle about y (degrees). Defaults to 0.0 gamma (float): Magnet Orientation angle about x (degrees). Defaults to 0.0
Source code in src/pymagnet/magnets/_magnet3D.py
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 | |
get_force_torque(num_samples=100, unit='mm')
Calculates the force and torque on a sphere magnet due to all other magnets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples
|
int
|
Number of samples per axis per face. Defaults to 100. |
100
|
unit
|
str
|
Length scale. Defaults to 'mm'. |
'mm'
|
Returns:
| Type | Description |
|---|---|
tuple
|
force (ndarray (3,) ) and torque (ndarray (3,) ) |
Source code in src/pymagnet/magnets/_magnet3D.py
913 914 915 916 917 918 919 920 921 922 923 924 925 926 | |
get_size()
Returns magnet dimesions
Returns:
| Type | Description |
|---|---|
size[ndarray]
|
numpy array [radius, length] |
Source code in src/pymagnet/magnets/_magnet3D.py
902 903 904 905 906 907 908 | |
Square
Bases: Rectangle
Square 2D Magnet Class
Source code in src/pymagnet/magnets/_magnet2D.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
__init__(width=20, Jr=1.0, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
Square side length. Defaults to 20.0. |
20
|
Jr
|
float
|
Remnant Magnetisation. Defaults to 1.0. |
1.0
|
Kwargs
alpha (float): Magnetisation orientation angle (in degrees). Defaults to 0.
center (tuple or ndarray): magnet center (x, y). Defaults to (0,0).
phi (float): Rotation Angle (in degrees) of magnet w.r.t x-axis. Defaults to 90.
Source code in src/pymagnet/magnets/_magnet2D.py
283 284 285 286 287 288 289 290 291 292 293 294 295 | |
get_total_field_mesh(meshes, x, y, z, r_cut=_np.inf)
Compute the total magnetic field from multiple Mesh magnets in one pass.
Concatenates triangle data from all meshes and evaluates the field at
every point (x, y, z) using the points-outer parallel kernel
_get_field_parallel_pts_njit. An optional distance cutoff skips
triangles whose centroid is farther than r_cut from an evaluation
point, which can give a large speedup for sparse or localised geometries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meshes
|
list
|
list (or any iterable) of |
required |
x
|
float or ndarray
|
x co-ordinates of the evaluation points. |
required |
y
|
float or ndarray
|
y co-ordinates of the evaluation points. |
required |
z
|
float or ndarray
|
z co-ordinates of the evaluation points. |
required |
r_cut
|
float
|
distance cutoff in the same length units as the mesh
coordinates. Triangles farther than |
inf
|
Returns:
| Type | Description |
|---|---|
Field3
|
total magnetic field array (attributes |
Example::
import pymagnet as pm
import numpy as np
pm.reset()
m1 = pm.magnets.Mesh("left.stl", Jr=1.0, center=[-30, 0, 0])
m2 = pm.magnets.Mesh("right.stl", Jr=1.0, center=[ 30, 0, 0])
x = np.linspace(-60, 60, 40)
X, Y, Z = np.meshgrid(x, x, x, indexing="ij")
# Single fused pass — equivalent to summing m1.get_field() + m2.get_field()
B = pm.magnets.get_total_field_mesh([m1, m2], X, Y, Z, r_cut=40.0)
Source code in src/pymagnet/magnets/_polygon3D.py
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 | |
magnetic_field_cylinder_1D(magnet, z)
Calculates the magnetic field z-component due to a cuboid along its axial symmetry center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
magnet
|
Magnet3D
|
magnet object, Cylinder |
required |
z
|
ndarray
|
Array of points along the symmetry axis |
required |
Returns:
| Type | Description |
|---|---|
Field1
|
z-component of the magnetic field and associated unit ('T') |
Source code in src/pymagnet/magnets/_magnet1D.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
magnetic_field_prism_1D(magnet, z)
Calculates the magnetic field z-component due to a cuboid along its axial symmetry center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
magnet
|
Magnet3D
|
magnet object, one of Prism, or Cube |
required |
z
|
ndarray
|
Array of points along the symmetry axis |
required |
Returns:
| Type | Description |
|---|---|
Field1
|
z-component of the magnetic field and associated unit ('T') |
Source code in src/pymagnet/magnets/_magnet1D.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
Magnet Base class
This private module implements the registry and base magnet classes
Magnet
Bases: Registry
Magnet base class
Returns:
| Type | Description |
|---|---|
Magnet
|
magnet base class |
Source code in src/pymagnet/magnets/_magnet_base.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
Registry
Registry class for tracking instances
Instances are tracked in class.instances using weak references.
This also includes any instances that are deleted manually or go out of
scope.
Class methods:
`print_instances()`
`get_instances()`
`get_num_instances()`
`reset()
Source code in src/pymagnet/magnets/_magnet_base.py
19 20 21 22 23 24 25 26 27 28 29 30 31 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 70 71 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 102 103 104 105 106 107 | |
get_instances()
classmethod
Gets lists of instances
Returns:
| Type | Description |
|---|---|
set
|
all class instances |
Source code in src/pymagnet/magnets/_magnet_base.py
62 63 64 65 66 67 68 69 | |
get_num_instances(Print_Val=False)
classmethod
Return number of instances of class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Print_Val
|
bool
|
[Print to screen]. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
num_instances[int]
|
|
Source code in src/pymagnet/magnets/_magnet_base.py
71 72 73 74 75 76 77 78 79 80 81 82 83 | |
print_instances()
classmethod
Prints class instantiations
Source code in src/pymagnet/magnets/_magnet_base.py
53 54 55 56 57 58 59 60 | |
reset()
classmethod
Removes all instances from registry.
Source code in src/pymagnet/magnets/_magnet_base.py
97 98 99 100 101 102 103 | |
list()
Returns a list of all instantiated magnets.
Assumes that the child class registries have not been modified outside of
using pymagnet.reset().
Source code in src/pymagnet/magnets/_magnet_base.py
152 153 154 155 156 157 158 | |
reset()
Clears the instance registry of every magnet class.
Source code in src/pymagnet/magnets/_magnet_base.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
1D High symmetry methods
This private module implements magnetic field calculations in z along the symmetry centre of a cylindrical or cuboidal magnet.
magnetic_field_cylinder_1D(magnet, z)
Calculates the magnetic field z-component due to a cuboid along its axial symmetry center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
magnet
|
Magnet3D
|
magnet object, Cylinder |
required |
z
|
ndarray
|
Array of points along the symmetry axis |
required |
Returns:
| Type | Description |
|---|---|
Field1
|
z-component of the magnetic field and associated unit ('T') |
Source code in src/pymagnet/magnets/_magnet1D.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
magnetic_field_prism_1D(magnet, z)
Calculates the magnetic field z-component due to a cuboid along its axial symmetry center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
magnet
|
Magnet3D
|
magnet object, one of Prism, or Cube |
required |
z
|
ndarray
|
Array of points along the symmetry axis |
required |
Returns:
| Type | Description |
|---|---|
Field1
|
z-component of the magnetic field and associated unit ('T') |
Source code in src/pymagnet/magnets/_magnet1D.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
2D Magnet Classes
This private module implements the Rectangle and Square and Circle 2D magnet classes. The parent class Magnet2D implements the location and orientation
methods, i.e. magnet center and quaternion methods for rotating the magnet with respect
to each principal axis.
Circle
Bases: Magnet2D
Circle 2D Magnet Class
Source code in src/pymagnet/magnets/_magnet2D.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
__init__(radius=10, Jr=1.0, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius. Defaults to 10.0. |
10
|
Jr
|
float
|
Remnant magnetisation. Defaults to 1.0. |
1.0
|
Kwargs
alpha (float): Unused. For rotations use phi instead center (tuple or ndarray): magnet center (x, y). Defaults to (0,0) phi (float): Rotation Angle (in degrees) of magnet w.r.t x-axis. Defaults to 90.
Source code in src/pymagnet/magnets/_magnet2D.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
get_Jr()
Returns signed remnant magnetisation
Returns:
| Type | Description |
|---|---|
ndarray
|
remnant magnetisation |
Source code in src/pymagnet/magnets/_magnet2D.py
360 361 362 363 364 365 366 | |
get_field(x, y)
Calculates the magnetic field due to long bipolar cylinder
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x coordinates |
required |
y
|
ndarray
|
y coordinates |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Bx, By magnetic field in cartesian coordinates |
Source code in src/pymagnet/magnets/_magnet2D.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
get_size()
Returns radius
Returns:
| Type | Description |
|---|---|
ndarray
|
radius |
Source code in src/pymagnet/magnets/_magnet2D.py
352 353 354 355 356 357 358 | |
Magnet2D
Bases: Magnet
2D Magnet Base Class
Source code in src/pymagnet/magnets/_magnet2D.py
19 20 21 22 23 24 25 26 27 28 29 30 31 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 70 71 72 73 74 75 76 77 | |
__init__(Jr, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Jr
|
float
|
signed magnetised of remnant magnetisation |
required |
Kwargs
alpha (float): Magnetisation orientation angle (in degrees). Defaults to 0. center (tuple or ndarray): magnet center (x, y). Defaults to (0,0).
Source code in src/pymagnet/magnets/_magnet2D.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
get_center()
Returns magnet centre
Returns:
| Type | Description |
|---|---|
center (ndarray
|
numpy array [xc, yc] |
Source code in src/pymagnet/magnets/_magnet2D.py
44 45 46 47 48 49 50 | |
get_field(x, y)
Calculates the magnetic field.
This is a template that needs to be implemented for each magnet
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x co-ordinates |
required |
y
|
ndarray
|
y co-ordinates |
required |
Source code in src/pymagnet/magnets/_magnet2D.py
61 62 63 64 65 66 67 68 69 70 | |
get_force_torque()
Calculates the force and torque on a magnet due to all other magnets.
This is a template that needs to be implemented for each magnet.
Source code in src/pymagnet/magnets/_magnet2D.py
72 73 74 75 76 77 | |
get_orientation()
Returns magnet orientation, alpha in degrees
Returns:
| Type | Description |
|---|---|
float
|
alpha, rotation angle w.r.t x-axis. |
Source code in src/pymagnet/magnets/_magnet2D.py
52 53 54 55 56 57 58 59 | |
Rectangle
Bases: Magnet2D
Rectangular 2D Magnet Class
Source code in src/pymagnet/magnets/_magnet2D.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 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 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
__init__(width=20.0, height=40.0, Jr=1.0, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
Magnet Width. Defaults to 20.0. |
20.0
|
height
|
float
|
Magnet Height. Defaults to 40.0. |
40.0
|
Jr
|
float
|
Remnant Magnetisation. Defaults to 1.0. |
1.0
|
Kwargs
alpha (float): Magnetisation orientation angle (in degrees). Defaults to 0. center (tuple or ndarray): magnet center (x, y). Defaults to (0,0). phi (float): Rotation Angle (in degrees) of magnet w.r.t x-axis. Defaults to 90.
Source code in src/pymagnet/magnets/_magnet2D.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
get_Jr()
Returns Magnetisation vector
Returns:
| Type | Description |
|---|---|
ndarray
|
[Jx, Jy] |
Source code in src/pymagnet/magnets/_magnet2D.py
140 141 142 143 144 145 146 | |
get_field(x, y)
Calculates the magnetic field at point(s) x,y due to a rectangular magnet
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x co-ordinates |
required |
y
|
ndarray
|
y co-ordinates |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
magnetic field vector Bx (ndarray), By (ndarray) |
Source code in src/pymagnet/magnets/_magnet2D.py
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 | |
get_size()
Returns magnet dimesions
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy array [width, height] |
Source code in src/pymagnet/magnets/_magnet2D.py
112 113 114 115 116 117 118 | |
Square
Bases: Rectangle
Square 2D Magnet Class
Source code in src/pymagnet/magnets/_magnet2D.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
__init__(width=20, Jr=1.0, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
Square side length. Defaults to 20.0. |
20
|
Jr
|
float
|
Remnant Magnetisation. Defaults to 1.0. |
1.0
|
Kwargs
alpha (float): Magnetisation orientation angle (in degrees). Defaults to 0.
center (tuple or ndarray): magnet center (x, y). Defaults to (0,0).
phi (float): Rotation Angle (in degrees) of magnet w.r.t x-axis. Defaults to 90.
Source code in src/pymagnet/magnets/_magnet2D.py
283 284 285 286 287 288 289 290 291 292 293 294 295 | |
2D Polygon Magnet class
Line
Line Class for storing properties of a sheet manget
Source code in src/pymagnet/magnets/_polygon2D.py
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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
__init__(length, center, beta, K)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
float
|
side length |
required |
center
|
ndarray
|
magnet center (x, y) |
required |
beta
|
float
|
Orientation w.r.t. z-axis in degrees |
required |
K
|
float
|
Sheet current density in tesla |
required |
Source code in src/pymagnet/magnets/_polygon2D.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
get_center()
Returns line center
Returns:
| Type | Description |
|---|---|
ndarray
|
center (x,y) |
Source code in src/pymagnet/magnets/_polygon2D.py
299 300 301 302 303 304 305 306 | |
get_field(x, y)
Calculates the magnetic field due to a sheet magnet First a transformation into the local coordinates is made, the field calculated and then the magnetic field it rotated out to the global coordinates
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x-coordinates |
required |
y
|
ndarray
|
y-coordinates |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Bx (ndarray), By (ndarray) magnetic field vector |
Source code in src/pymagnet/magnets/_polygon2D.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
LineUtils
Utility class consisting of rountines for 2D line elements
Source code in src/pymagnet/magnets/_polygon2D.py
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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
line_center(vertex_1, vertex_2)
staticmethod
Gets midpoint of two vertices
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex_1
|
ndarray
|
vertex 1 |
required |
vertex_2
|
ndarray
|
vertex 2 |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
midpoint |
Source code in src/pymagnet/magnets/_polygon2D.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
signed_area2D(polygon)
staticmethod
Calculates signed area of a polygon
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
Polygon
|
Polygon instance |
required |
Returns:
| Type | Description |
|---|---|
float
|
signed area |
Source code in src/pymagnet/magnets/_polygon2D.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
unit_norm(vertex_1, vertex_2, clockwise=True)
staticmethod
Get unit normal to vertex
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex_1
|
ndarray
|
vertex 1 |
required |
vertex_2
|
ndarray
|
vertex 2 |
required |
clockwise
|
bool
|
Clockwise orientation of points. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
tuple
|
normal vector (ndarray), length i.e. distance between vertices (float) |
Source code in src/pymagnet/magnets/_polygon2D.py
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 | |
PolyMagnet
Bases: Magnet2D
2D Magnet Polygon class.
Source code in src/pymagnet/magnets/_polygon2D.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
__init__(Jr, **kwargs)
Init method
NOTE
- When creating a regular polygon, one of apothem, radius, or length must be defined as a kwarg or an exception will be raised.
- When creating a regular polygon, the number of sides
num_sidesmust be at least 3 or an exception will be raised. - When creating a custom polygon at least one vertex pair must be
defined with
verticesor an exception will be raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Jr
|
float
|
signed magnitude of remnant magnetisation |
required |
Kwargs
alpha (float): Not used theta (float): Orientation of magnet w.r.t x-axis of magnet phi (float): Orientation of magnetisation w.r.t x-axis of magnet in degrees. Defaults to 90.0. center (ndarray): magnet center (x, y). Defaults to (0.0, 0.0) length (float): side length if creating a regular polygon apothem (float): apothem (incircle radius) if creating a regular polygon radius (float): radius (circumcircle radius) if creating a regular polygon num_sides (int): number of sides of a regular polygon. Defaults to 6. custom_polygon (bool): Flag to define a custom polygon. Defaults to False. vertices (ndarray, list): List of custom vertices. Defaults to None.
Raises:
| Type | Description |
|---|---|
Exception
|
If creating a custom polygon, |
Source code in src/pymagnet/magnets/_polygon2D.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
get_center()
Returns magnet centre
Returns:
| Type | Description |
|---|---|
center (ndarray
|
numpy array [xc, yc] |
Source code in src/pymagnet/magnets/_polygon2D.py
432 433 434 435 436 437 438 | |
get_field(x, y)
Calculates the magnetic field of a polygon due to each face
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x-coordinates |
required |
y
|
ndarray
|
y-coordinates |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Bx (ndarray), By (ndarray) magnetic field vector |
Source code in src/pymagnet/magnets/_polygon2D.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
get_orientation()
Returns magnet orientation, alpha in degrees
Returns:
| Type | Description |
|---|---|
float
|
alpha, rotation angle w.r.t x-axis. |
Source code in src/pymagnet/magnets/_polygon2D.py
440 441 442 443 444 445 446 447 | |
Polygon
Polygon class for generating list of vertices
Source code in src/pymagnet/magnets/_polygon2D.py
29 30 31 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 70 71 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 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 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 | |
append(vertex)
Appends vertex to list of vertices
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex
|
list
|
list of vertices |
required |
Source code in src/pymagnet/magnets/_polygon2D.py
51 52 53 54 55 56 57 58 59 60 61 62 63 | |
check_radius(N, apothem, length, radius)
staticmethod
Checks which of apothem, side length, or radius has been passed as kwargs
to gen_polygon(). Order of precendence is apothem, length, radius.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
Number of sides |
required |
apothem
|
float
|
polygon apothem |
required |
length
|
float
|
side length |
required |
radius
|
float
|
outcircle radius |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
One of apothem, length, or raduis must be defined |
Returns:
| Type | Description |
|---|---|
float
|
returns radius |
Source code in src/pymagnet/magnets/_polygon2D.py
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 | |
gen_polygon(N=6, center=(0.0, 0.0), alpha=0.0, **kwargs)
staticmethod
Generates regular polygon. One of apothem, side length or radius must be defined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
Number of sides. Defaults to 6. |
6
|
center
|
tuple
|
Polygon center. Defaults to (0.0, 0.0). |
(0.0, 0.0)
|
alpha
|
float
|
Orientration with respect to x-axis. Defaults to 0.0. |
0.0
|
Raises:
| Type | Description |
|---|---|
Exception
|
N must be > 2 |
Returns:
| Type | Description |
|---|---|
ndarray
|
polygon vertices |
Source code in src/pymagnet/magnets/_polygon2D.py
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
num_vertices()
Gets number of vertices
Returns:
| Type | Description |
|---|---|
int
|
number of vertices |
Source code in src/pymagnet/magnets/_polygon2D.py
65 66 67 68 69 70 71 | |
set_center()
Sets center of polygon to be centroid
Source code in src/pymagnet/magnets/_polygon2D.py
73 74 75 76 | |
Mesh
Bases: Magnet3D
Mesh Magnet Class.
Source code in src/pymagnet/magnets/_polygon3D.py
25 26 27 28 29 30 31 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 70 71 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 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 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | |
__init__(filename, Jr=1.0, **kwargs)
Init Method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
string
|
path to stl file to be imported |
required |
Jr
|
float
|
Signed remnant magnetisation. Defaults to 1.0. |
1.0
|
Kwargs
phi (float): theta (float): mesh_scale (float): scaling factor if mesh needs to be resized. Defaults to 1.0
Source code in src/pymagnet/magnets/_polygon3D.py
30 31 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
calcB_triangle(triangle, Jr, x, y, z, i)
Calculates the magnetic field due to a triangle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
triangle
|
ndarray
|
Vertices of a triangle |
required |
Jr
|
float
|
Remnant magnetisation component normal to triangle |
required |
x
|
ndarray
|
x coordinates |
required |
y
|
ndarray
|
y coordinates |
required |
z
|
ndarray
|
z coordinates |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Bx, By, Bz magnetic field components |
Source code in src/pymagnet/magnets/_polygon3D.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
get_Jr()
Returns Magnetisation vector
Returns:
| Type | Description |
|---|---|
ndarray
|
[Jx, Jy, Jz] |
Source code in src/pymagnet/magnets/_polygon3D.py
107 108 109 110 111 112 113 | |
get_center()
Returns magnet center
Returns:
| Type | Description |
|---|---|
ndarray
|
magnet center |
Source code in src/pymagnet/magnets/_polygon3D.py
123 124 125 126 127 128 129 | |
get_field(x, y, z, parallel=True, r_cut=_np.inf)
Calculates the magnetic field at point(s) x,y,z due to a 3D magnet The calculations are always performed in local coordinates with the centre of the magnet at origin and z magnetisation pointing along the local z' axis.
The rotations and translations are performed first, and the internal field calculation functions are called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float / array
|
x co-ordinates |
required |
y
|
float / array
|
y co-ordinates |
required |
z
|
float / array
|
z co-ordinates |
required |
parallel
|
bool
|
If True, use parallel numba implementation |
True
|
r_cut
|
float
|
Distance cutoff. Triangles whose centroid is farther
than |
inf
|
Returns:
| Type | Description |
|---|---|
tuple
|
Bx(ndarray), By(ndarray), Bz(ndarray) field vector |
Source code in src/pymagnet/magnets/_polygon3D.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
get_force_torque(depth=4, unit='mm')
Calculates the force and torque on a prism magnet due to all other magnets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depth
|
int
|
Number of recursions of division by 4 per simplex |
4
|
unit
|
str
|
Length scale. Defaults to 'mm'. |
'mm'
|
Returns:
| Type | Description |
|---|---|
tuple
|
force (ndarray (3,) ) and torque (ndarray (3,) ) |
Source code in src/pymagnet/magnets/_polygon3D.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
size()
Returns magnet dimesions
Returns:
| Type | Description |
|---|---|
size (ndarray
|
numpy array [width, depth, height] |
Source code in src/pymagnet/magnets/_polygon3D.py
115 116 117 118 119 120 121 | |
get_total_field_mesh(meshes, x, y, z, r_cut=_np.inf)
Compute the total magnetic field from multiple Mesh magnets in one pass.
Concatenates triangle data from all meshes and evaluates the field at
every point (x, y, z) using the points-outer parallel kernel
_get_field_parallel_pts_njit. An optional distance cutoff skips
triangles whose centroid is farther than r_cut from an evaluation
point, which can give a large speedup for sparse or localised geometries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meshes
|
list
|
list (or any iterable) of |
required |
x
|
float or ndarray
|
x co-ordinates of the evaluation points. |
required |
y
|
float or ndarray
|
y co-ordinates of the evaluation points. |
required |
z
|
float or ndarray
|
z co-ordinates of the evaluation points. |
required |
r_cut
|
float
|
distance cutoff in the same length units as the mesh
coordinates. Triangles farther than |
inf
|
Returns:
| Type | Description |
|---|---|
Field3
|
total magnetic field array (attributes |
Example::
import pymagnet as pm
import numpy as np
pm.reset()
m1 = pm.magnets.Mesh("left.stl", Jr=1.0, center=[-30, 0, 0])
m2 = pm.magnets.Mesh("right.stl", Jr=1.0, center=[ 30, 0, 0])
x = np.linspace(-60, 60, 40)
X, Y, Z = np.meshgrid(x, x, x, indexing="ij")
# Single fused pass — equivalent to summing m1.get_field() + m2.get_field()
B = pm.magnets.get_total_field_mesh([m1, m2], X, Y, Z, r_cut=40.0)
Source code in src/pymagnet/magnets/_polygon3D.py
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 | |