matlab/matlab-agentic-toolkit / skills-catalog/math-and-optimization/matlab-solve-pde
matlab-solve-pde
VerifiedEnd-to-end finite element analysis in MATLAB PDE Toolbox — geometry creation, model setup, solve, and post-processing in one skill. Use when building geometry from primitives or file import, setting up femodel with BCs/loads/materials, solving thermal/structural/EM problems, and extracting or visualizing results. Covers fegeometry, multicuboid, multicylinder, multisphere, decsg, boolean ops, mesh generation, femodel, all AnalysisTypes (thermalSteady, thermalTransient, structuralStatic, structuralTransient, structuralModal, structuralFrequency, electrostatic, magnetostatic, dcConduction, harmonic EM), materialProperties, faceBC, faceLoad, cellLoad, vertexLoad, solve, interpolation, von Mises stress, principal stress, reaction forces, heat flux, pdeplot3D visualization. Triggers on: PDE Toolbox, finite element, FEA, thermal analysis, structural analysis, electromagnetic analysis, femodel, mesh, boundary conditions, stress, displacement, heat transfer, post-processing.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 25.1 KB |
| manifest.yaml | config | 496 B |
| references/bc-load-reference.md | markdown | 4.9 KB |
| references/boolean-and-cell-ops.md | markdown | 4.5 KB |
| references/damping-reference.md | markdown | 2.1 KB |
| references/decsg-and-2d-geometry.md | markdown | 2.3 KB |
| references/electromagnetic-setup.md | markdown | 4.8 KB |
| references/em-postprocessing.md | markdown | 4.1 KB |
| references/modal-and-reduced-order.md | markdown | 3.0 KB |
| references/nonconstant-parameters.md | markdown | 4.3 KB |
| references/primitives-and-import.md | markdown | 4.8 KB |
| references/time-dependent-loads.md | markdown | 2.7 KB |
| references/visualization-reference.md | markdown | 6.0 KB |
references/electromagnetic-setup.md
View on GitHub# Electromagnetic Model Setup
## Required Vacuum Constants
| Analysis | Required Constants |
|---|---|
| `electrostatic` | `VacuumPermittivity` |
| `magnetostatic` | `VacuumPermeability` |
| `dcConduction` | Neither (conductivity only) |
| `electricHarmonic` | Both `VacuumPermittivity` AND `VacuumPermeability` |
| `magneticHarmonic` | Both `VacuumPermittivity` AND `VacuumPermeability` |
```matlab
model.VacuumPermittivity = 8.854187817e-12; % F/m
model.VacuumPermeability = 4*pi*1e-7; % H/m
```
## Material Properties per Analysis
```matlab
% Electrostatic
model.MaterialProperties = materialProperties(RelativePermittivity=4);
% Magnetostatic
model.MaterialProperties = materialProperties(RelativePermeability=1);
% DC Conduction
model.MaterialProperties = materialProperties(ElectricalConductivity=5.8e7);
% Harmonic (all three required)
model.MaterialProperties = materialProperties(RelativePermittivity=4, ...
RelativePermeability=1, ElectricalConductivity=0.01);
```
## EM Boundary Conditions
```matlab
model.FaceBC(faces) = faceBC(Voltage=100); % Electrostatic
model.FaceBC(faces) = faceBC(MagneticPotential=[0;0;0]); % 3-D: vector [Ax;Ay;Az]
model.EdgeBC(edges) = edgeBC(MagneticPotential=0); % 2-D: scalar
model.FaceBC(faces) = faceBC(ElectricField=[1;0;0]); % Harmonic
model.FaceBC(faces) = faceBC(MagneticField=[Hx;Hy;0]); % Tangential to face
model.FaceBC(outer) = faceBC(FarField=farFieldBC(Thickness=0.1)); % Absorbing BC
```
**MagneticPotential:** 3-D requires a 3-element vector `[Ax;Ay;Az]`; 2-D takes a scalar.
**MagneticField orientation:** Nedelec elements enforce tangential H only. Normal component is ignored. Orient H tangential to the face.
## CurrentDensity Format
The format depends on analysis type and dimensionality:
| Analysis | 2-D (faceLoad) | 3-D (cellLoad) | Function return |
|----------|----------------|-----------------|-----------------|
| `magnetostatic` | Scalar (Jz only) | 3-element vector or `ConductionResults` | 1×N (2-D) or 3×N (3-D) |
| `electricHarmonic` | 2-element vector | 3-element vector | 2×N (2-D) or 3×N (3-D) |
| `magneticHarmonic` | Scalar (Jz only) | 3-element vector | 1×N (2-D) or 3×N (3-D) |
```matlab
% Magnetostatic 2-D — scalar (Jz component only, applied out-of-plane)
model.FaceLoad(coilFace) = faceLoad(CurrentDensity=1e6);
% Magnetostatic 3-D — vector or function (3×N return)
model.CellLoad(coilCell) = cellLoad(CurrentDensity=[0; 0; 1e6]);
model.CellLoad(coilCell) = cellLoad(CurrentDensity=@applyJ);
% Magnetostatic 3-D — from DC conduction results (coupling)
model.CellLoad(coilCell) = cellLoad(CurrentDensity=conductionResults);
function J = applyJ(location, ~)
x = location.x; y = location.y;
r = sqrt(x.^2 + y.^2);
J0 = 1e6;
J = [-J0.*y./r; J0.*x./r; zeros(1, numel(x))]; % 3×N
end
```
**Key rule:** In 2-D magnetostatic/magneticHarmonic, current flows out-of-plane (z-direction only), so only a scalar Jz is needed. In 3-D, you specify the full vector.
## Nonlinear B-H Curve (Magnetostatic)
Two-step workflow: solve linear first, use result as initial guess for nonlinear.
```matlab
% Step 1: Linear solve with constant high muR
model.MaterialProperties(ironFace) = materialProperties(RelativePermeability=5000);
Rlin = solve(model);
% Step 2: Replace with nonlinear muR from tabulated B-H data
B = [0 0.3 0.8 1.12 1.32 1.46 1.54 1.62 1.74];
H = [0 29.8 79.6 159.2 318.3 795.8 1591.6 3376.7 7957.8];
HofB = griddedInterpolant(B, H, "makima", "linear");
mu0 = 4*pi*1e-7;
muRfcn = @(Bval) Bval ./ HofB(Bval) / mu0;
model.MaterialProperties(ironFace) = materialProperties(...
RelativePermeability=@(~,s) muRfcn(s.NormFluxDensity));
% Use linear solution as initial guess for nonlinear solver
model.FaceIC = faceIC(MagneticVectorPotential=Rlin);
Rnonlin = solve(model);
```
**Key patterns:**
- Function handle signature: `@(location, state)` — use `state.NormFluxDensity`
- `griddedInterpolant` for B-H interpolation (not `interp1` inside the function)
- Linear result passed directly to `faceIC(MagneticVectorPotential=...)` as initial guess
- Without initial guess, nonlinear solver may fail with singular Jacobian
## Harmonic EM Solve
Frequency is positional (NOT a named argument):
```matlab
freqs = linspace(1e6, 1e9, 20);
result = solve(model, freqs); % NOT Frequency=freqs
```
### CurrentDensity for Harmonic — Coordinate-Dependent Only
| Analysis | 2-D | 3-D |
|---|---|---|
| `electricHarmonic` | 2-element vector | 3-element vector or fn(coordinates) |
| `magneticHarmonic` | Scalar (Jz) | 3-element vector or fn(coordinates) |
```matlab
model.CellLoad(coil) = cellLoad(CurrentDensity=[0;0;1e4]); % electricHarmonic 3-D
model.FaceLoad(coil) = faceLoad(CurrentDensity=1e4); % magneticHarmonic 2-D
```
----
Copyright 2026 The MathWorks, Inc.
----
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 470k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |