Analyze magnetic field

From pjt222/agent-almanac · View interactive version

Analyze magnetic field is an AI agent skill from the GitHub repository pjt222/agent-almanac. Calculate and visualize magnetic fields produced by current distributions using the Biot-Savart law, Ampere's law, and magnetic dipole approximations. Use when computing B-fields from arbitrary current geometries, exploiting symmetry with Ampere's law, analyzing superposition of multiple sources, or

How to use this skill

Skill file

Analyze Magnetic Field

Calc B-field from current distribution: characterize src geometry → select law (Biot-Savart arbitrary, Ampere high-sym) → eval integrals → check limits → incorporate material effects → visualize field-line topology.

Use When

In

Do

Step 1: Characterize Current + Geometry

Fully spec src pre-method:

  1. Current path: Geometry each current element. Line currents → parametric curve r'(t). Surface currents → K (A/m). Volume currents → J (A/m^2).
  2. Coord system: Align w/ dominant sym. Cylindrical (rho, phi, z) wires/solenoids. Spherical (r, theta, phi) dipoles/loops far dist. Cartesian planar sheets.
  3. Sym analysis: ID translational, rotational, reflection. Src sym = field sym. Doc nonzero B-components + vanish.
  4. Current continuity: Verify div(J) = 0 (steady) or div(J) = -d(rho)/dt (time-varying). Inconsistent → unphysical fields.
## Source Characterization
- **Current type**: [line I / surface K / volume J]
- **Geometry**: [parametric description]
- **Coordinate system**: [and justification]
- **Symmetries**: [translational / rotational / reflection]
- **Nonzero B-components by symmetry**: [list]
- **Current continuity**: [verified / issue noted]

→ Complete geometric desc, coord system chosen, sym cataloged, continuity verified.

If err: Too complex for closed-form → discretize short straight segments (numerical Biot-Savart). Continuity violated → add displacement current or return charge accumulation before proceeding.

Step 2: Select Law

Match method to sym + complexity:

  1. Ampere (high sym): Use when B extractable from line integral. Applicable:
  1. Biot-Savart (general): Arbitrary geometries Ampere can't simplify:
  1. Dipole approx (far field): Obs far from src (r >> src dim d):
  1. Superposition: Multi-src → B each independent + sum vectorially. Maxwell linearity → exact.
## Method Selection
- **Primary method**: [Ampere / Biot-Savart / dipole]
- **Justification**: [symmetry argument or distance criterion]
- **Expected complexity**: [closed-form / single integral / numerical]
- **Fallback method**: [if primary fails or for cross-validation]

→ Justified method choice, clear why law appropriate for sym level.

If err: Ampere chosen but insufficient sym (B not extractable) → fallback Biot-Savart. Src geometry too complex analytic Biot-Savart → discretize numerically.

Step 3: Set Up + Eval Field Integrals

Execute calc via Step 2 method:

  1. Ampere path: Per Amperian loop:
  1. Biot-Savart integration: Per field pt r:
  1. Dipole calc:
  1. Superposition assembly: Sum all srcs per obs pt. Track components separately → preserve cancellation accuracy.
## Field Calculation
- **Integral setup**: [explicit expression]
- **Evaluation method**: [analytic / numeric with N segments]
- **Result**: B(r) = [expression with units]
- **Convergence check** (if numerical): [N vs. 2N comparison]

→ Explicit B(r) expr at obs pts, correct units (Tesla/Gauss), convergence check numerical.

If err: Integral diverges → missing regularization (field on thin wire diverges → use finite wire radius). Numerical oscillates w/ N → near-singularity → adaptive quadrature or analytical subtraction.

Step 4: Check Limits

Verify vs known physics pre-trust:

  1. Far-field dipole limit: Large r, localized src → dipole formula. Compute B → r → infinity, compare (mu_0 / 4 pi) * [3(m . r_hat) r_hat - m] / r^3.
  1. Near-field infinite-wire limit: Close to long straight segment (rho << length L) → B = mu_0 I / (2 pi rho). Check for relevant geometry portion.
  1. On-axis special cases: Loops + solenoids have simple closed forms:
  1. Sym consistency: Verify components predicted vanish (Step 1) are 0. Nonzero forbidden → err.
  1. Dim analysis: Verify B = Tesla. Every term mu_0 * [current] / [length].
## Limiting Case Verification
| Case | Condition | Expected | Computed | Match |
|------|-----------|----------|----------|-------|
| Far-field dipole | r >> d | mu_0 m / (4 pi r^3) scaling | [result] | [Yes/No] |
| Near-field wire | rho << L | mu_0 I / (2 pi rho) | [result] | [Yes/No] |
| On-axis formula | [geometry] | [known result] | [result] | [Yes/No] |
| Symmetry zeros | [component] | 0 | [result] | [Yes/No] |
| Units | -- | Tesla | [check] | [Yes/No] |

→ All limits match. Field: correct units, sym, asymptotic behavior.

If err: Failed limit → err in integral setup/eval. Common: wrong sign cross product, missing factor 2/pi, wrong integration limits, coord mismatch src vs field.

Step 5: Materials + Visualize

Extend to material effects + produce viz:

  1. Linear materials: Replace mu_0 w/ mu = mu_r * mu_0 inside. Boundary conds at interfaces:
  1. Nonlinear (B-H curves): Ferromagnetic cores:
  1. Demagnetization: Finite-geometry magnetic materials (short rods, spheres) → internal field reduced by N_d: H_internal = H_applied - N_d * M.
  1. Viz:
  1. Intuition check: Field pattern makes sense qualitatively. Strongest near src, circulates around currents (right-hand rule), decays w/ dist.
## Material Effects and Visualization
- **Material model**: [vacuum / linear mu_r / nonlinear B-H / hysteretic]
- **Boundary conditions applied**: [list interfaces]
- **Visualization**: [field lines / magnitude contour / both]
- **Div B = 0 check**: [field lines close / verified numerically]

→ Complete field solution + material effects, viz closed field lines consistent div B = 0, qualitative intuition match.

If err: Field lines don't close → divergence err in calc → recheck integral/numerical. Material → unexpected amplification → verify mu_r only inside material vol + boundary conds enforced each interface.

Check

Traps

→

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.