{
  "format": "mathssim",
  "version": 1,
  "title": "06 - Gradient, Divergence and Curl",
  "computeMode": "standard",
  "functions": [],
  "notation": {
    "xg": "x_0",
    "yg": "y_0",
    "gradV_at": "\\nabla V",
    "Egrad_at": "\\mathbf{E}",
    "xdiv": "x",
    "divA": "\\nabla\\cdot\\mathbf{A}",
    "curl_z": "(\\nabla\\times\\mathbf{A})_z",
    "aCube": "a",
    "div_volume": "\\int_V(\\nabla\\cdot\\mathbf{A})\\,\\mathrm{d}V",
    "surface_flux": "\\oint_S\\mathbf{A}\\cdot\\mathrm{d}\\mathbf{S}",
    "divergence_theorem_residual": "\\varepsilon_{\\mathrm{div}}",
    "Rcirc": "R",
    "circulation": "\\oint_C\\mathbf{A}\\cdot\\mathrm{d}\\mathbf{l}",
    "curl_flux": "\\int_S(\\nabla\\times\\mathbf{A})\\cdot\\mathrm{d}\\mathbf{S}",
    "stokes_residual": "\\varepsilon_{\\mathrm{Stokes}}",
    "lapV": "\\nabla^2 V",
    "hfd": "h",
    "xfd": "x_0",
    "fd_second": "V^{\\prime\\prime}_{\\mathrm{FD}}",
    "fd_error": "\\varepsilon_{\\mathrm{FD}}"
  },
  "regions": [
    {
      "id": "ch06-head-001",
      "type": "text",
      "x": 65,
      "y": 35,
      "w": 990,
      "content": "06 - Gradient, Divergence and Curl",
      "heading": true
    },
    {
      "id": "ch06-note-002",
      "type": "text",
      "x": 65,
      "y": 140,
      "w": 990,
      "content": "Interactive M²S companion to EM Course Document 06.\nLocal differential operators, integral-theorem checks, Laplacian identities and finite differences.\nEdit the input Math regions, then Calculate. M²S values are unitless, so SI units are stated explicitly in labels and notes.",
      "heading": false
    },
    {
      "id": "ch06-note-003",
      "type": "text",
      "x": 65,
      "y": 291,
      "w": 990,
      "content": "In Cartesian coordinates the course uses grad f = (∂f/∂x,∂f/∂y,∂f/∂z), div A = ∂Ax/∂x+∂Ay/∂y+∂Az/∂z, and curl A as the local circulation operator. Gradient maps scalar→vector; divergence maps vector→scalar; curl maps vector→vector.",
      "heading": false
    },
    {
      "id": "ch06-head-004",
      "type": "text",
      "x": 65,
      "y": 406,
      "w": 990,
      "content": "1. Gradient: steepest increase and electrostatic field",
      "heading": true
    },
    {
      "id": "ch06-note-005",
      "type": "text",
      "x": 65,
      "y": 511,
      "w": 990,
      "content": "Use V=x²+0.5y². Its gradient is (2x,y), and an electrostatic E field is -grad(V).",
      "heading": false
    },
    {
      "id": "ch06-math-006",
      "type": "math",
      "x": 65,
      "y": 626,
      "w": 475,
      "target": "xg",
      "expr": "1"
    },
    {
      "id": "ch06-math-007",
      "type": "math",
      "x": 560,
      "y": 626,
      "w": 475,
      "target": "yg",
      "expr": "2"
    },
    {
      "id": "ch06-math-008",
      "type": "math",
      "x": 65,
      "y": 791,
      "w": 990,
      "target": "gradV_at",
      "expr": "[2*xg,yg,0]"
    },
    {
      "id": "ch06-math-009",
      "type": "math",
      "x": 65,
      "y": 956,
      "w": 990,
      "target": "Egrad_at",
      "expr": "-gradV_at"
    },
    {
      "id": "ch06-plot-010",
      "type": "plot",
      "kind": "contour",
      "title": "Potential contours V=x²+0.5y²",
      "xexpr": "linspace(-2,2,55)",
      "yexpr": "linspace(-2,2,55)",
      "zexpr": "x^2+0.5*y^2",
      "x": 65,
      "y": 1121,
      "w": 990,
      "h": 420,
      "xlabel": "x",
      "ylabel": "y",
      "y2label": "",
      "zlabel": "V",
      "vlines": "",
      "bins": 20,
      "palette": "blue",
      "xlog": false,
      "ylog": false,
      "y2log": false
    },
    {
      "id": "ch06-plot-011",
      "type": "plot",
      "kind": "quiver2d",
      "title": "E = -grad(V)",
      "xexpr": "linspace(-2,2,11)",
      "yexpr": "linspace(-2,2,11)",
      "zexpr": "",
      "x": 65,
      "y": 1646,
      "w": 990,
      "h": 470,
      "xlabel": "x",
      "ylabel": "y",
      "y2label": "",
      "zlabel": "",
      "vlines": "",
      "bins": 20,
      "palette": "blue",
      "xlog": false,
      "ylog": false,
      "y2log": false,
      "uexpr": "-2*x",
      "vexpr": "-y",
      "wexpr": "",
      "vectorAutoScale": true,
      "vectorScale": 0.85,
      "vectorNormalize": true,
      "vectorHeadSize": 0.42,
      "vectorWidth": 2.0,
      "vectorOpacity": 0.92,
      "vectorDensity": 1,
      "vectorAnchor": "tail",
      "vectorColorMode": "magnitude",
      "vectorColor": "#2175b5",
      "vectorPalette": "Viridis",
      "showColorbar": true,
      "animate": false,
      "animVar": "t",
      "animStart": "0",
      "animStop": "2*pi",
      "animFrames": 36,
      "animFps": 16,
      "animLoop": true
    },
    {
      "id": "ch06-head-012",
      "type": "text",
      "x": 65,
      "y": 2221,
      "w": 990,
      "content": "2. Divergence: local sources and sinks",
      "heading": true
    },
    {
      "id": "ch06-note-013",
      "type": "text",
      "x": 65,
      "y": 2326,
      "w": 990,
      "content": "Course checkpoint field A=(x²,2y,-z) has divergence 2x+2-1 = 2x+1.",
      "heading": false
    },
    {
      "id": "ch06-math-014",
      "type": "math",
      "x": 65,
      "y": 2441,
      "w": 990,
      "target": "xdiv",
      "expr": "0.75"
    },
    {
      "id": "ch06-math-015",
      "type": "math",
      "x": 65,
      "y": 2606,
      "w": 990,
      "target": "divA",
      "expr": "2*xdiv+1"
    },
    {
      "id": "ch06-plot-016",
      "type": "plot",
      "kind": "quiver3d",
      "title": "Field A=(x²,2y,-z)",
      "xexpr": "linspace(-1,1,5)",
      "yexpr": "linspace(-1,1,5)",
      "zexpr": "linspace(-1,1,5)",
      "x": 65,
      "y": 2771,
      "w": 990,
      "h": 500,
      "xlabel": "x",
      "ylabel": "y",
      "y2label": "",
      "zlabel": "z",
      "vlines": "",
      "bins": 20,
      "palette": "blue",
      "xlog": false,
      "ylog": false,
      "y2log": false,
      "uexpr": "x^2",
      "vexpr": "2*y",
      "wexpr": "-z",
      "vectorStyle": "arrows",
      "vectorAutoScale": true,
      "vectorScale": 0.8,
      "vectorNormalize": false,
      "vectorHeadSize": 0.58,
      "vectorWidth": 2.0,
      "vectorOpacity": 0.9,
      "vectorDensity": 1,
      "vectorAnchor": "tail",
      "vectorColorMode": "magnitude",
      "vectorColor": "#2175b5",
      "vectorPalette": "Viridis",
      "showColorbar": true,
      "animate": false,
      "animVar": "t",
      "animStart": "0",
      "animStop": "2*pi",
      "animFrames": 32,
      "animFps": 14,
      "animLoop": true
    },
    {
      "id": "ch06-head-017",
      "type": "text",
      "x": 65,
      "y": 3376,
      "w": 990,
      "content": "3. Curl: local circulation",
      "heading": true
    },
    {
      "id": "ch06-note-018",
      "type": "text",
      "x": 65,
      "y": 3481,
      "w": 990,
      "content": "For A=(-y,x,0), curl(A)=2 zhat. Field lines circulate around z, and the local curl points along +z.",
      "heading": false
    },
    {
      "id": "ch06-math-019",
      "type": "math",
      "x": 65,
      "y": 3596,
      "w": 990,
      "target": "curl_z",
      "expr": "2"
    },
    {
      "id": "ch06-plot-020",
      "type": "plot",
      "kind": "quiver2d",
      "title": "Rotational field A=(-y,x)",
      "xexpr": "linspace(-2,2,13)",
      "yexpr": "linspace(-2,2,13)",
      "zexpr": "",
      "x": 65,
      "y": 3761,
      "w": 990,
      "h": 470,
      "xlabel": "x",
      "ylabel": "y",
      "y2label": "",
      "zlabel": "",
      "vlines": "",
      "bins": 20,
      "palette": "blue",
      "xlog": false,
      "ylog": false,
      "y2log": false,
      "uexpr": "-y",
      "vexpr": "x",
      "wexpr": "",
      "vectorAutoScale": true,
      "vectorScale": 0.85,
      "vectorNormalize": true,
      "vectorHeadSize": 0.42,
      "vectorWidth": 2.0,
      "vectorOpacity": 0.92,
      "vectorDensity": 1,
      "vectorAnchor": "tail",
      "vectorColorMode": "single",
      "vectorColor": "#2175b5",
      "vectorPalette": "Viridis",
      "showColorbar": false,
      "animate": false,
      "animVar": "t",
      "animStart": "0",
      "animStop": "2*pi",
      "animFrames": 36,
      "animFps": 16,
      "animLoop": true
    },
    {
      "id": "ch06-head-021",
      "type": "text",
      "x": 65,
      "y": 4336,
      "w": 990,
      "content": "4. Divergence theorem: flux equals integrated divergence",
      "heading": true
    },
    {
      "id": "ch06-note-022",
      "type": "text",
      "x": 65,
      "y": 4441,
      "w": 990,
      "content": "For F=(x,y,z), div(F)=3. Over the cube [-a,a]^3 the volume integral is 3(2a)^3, and the outward flux is 6 faces × 4a³ = 24a³.",
      "heading": false
    },
    {
      "id": "ch06-math-023",
      "type": "math",
      "x": 65,
      "y": 4556,
      "w": 990,
      "target": "aCube",
      "expr": "1.2"
    },
    {
      "id": "ch06-math-024",
      "type": "math",
      "x": 65,
      "y": 4721,
      "w": 990,
      "target": "div_volume",
      "expr": "3*(2*aCube)^3"
    },
    {
      "id": "ch06-math-025",
      "type": "math",
      "x": 65,
      "y": 4886,
      "w": 990,
      "target": "surface_flux",
      "expr": "24*aCube^3"
    },
    {
      "id": "ch06-math-026",
      "type": "math",
      "x": 65,
      "y": 5051,
      "w": 990,
      "target": "divergence_theorem_residual",
      "expr": "surface_flux-div_volume"
    },
    {
      "id": "ch06-table-027",
      "type": "table",
      "x": 65,
      "y": 5216,
      "w": 990,
      "h": 280,
      "title": "Divergence theorem check",
      "headersText": "Value",
      "rowLabels": "Volume integral of div(F)\nClosed-surface flux\nResidual",
      "expr": "cols([div_volume,surface_flux,divergence_theorem_residual])",
      "precision": "12"
    },
    {
      "id": "ch06-head-028",
      "type": "text",
      "x": 65,
      "y": 5586,
      "w": 990,
      "content": "5. Stokes theorem: circulation equals curl flux",
      "heading": true
    },
    {
      "id": "ch06-math-029",
      "type": "math",
      "x": 65,
      "y": 5691,
      "w": 990,
      "target": "Rcirc",
      "expr": "1.3"
    },
    {
      "id": "ch06-math-030",
      "type": "math",
      "x": 65,
      "y": 5856,
      "w": 990,
      "target": "circulation",
      "expr": "2*pi*Rcirc^2"
    },
    {
      "id": "ch06-math-031",
      "type": "math",
      "x": 65,
      "y": 6021,
      "w": 990,
      "target": "curl_flux",
      "expr": "curl_z*pi*Rcirc^2"
    },
    {
      "id": "ch06-math-032",
      "type": "math",
      "x": 65,
      "y": 6186,
      "w": 990,
      "target": "stokes_residual",
      "expr": "circulation-curl_flux"
    },
    {
      "id": "ch06-table-033",
      "type": "table",
      "x": 65,
      "y": 6351,
      "w": 990,
      "h": 280,
      "title": "Stokes theorem check",
      "headersText": "Value",
      "rowLabels": "∮A·dl\n∬curl(A)·dS\nResidual",
      "expr": "cols([circulation,curl_flux,stokes_residual])",
      "precision": "12"
    },
    {
      "id": "ch06-head-034",
      "type": "text",
      "x": 65,
      "y": 6721,
      "w": 990,
      "content": "6. Laplacian and finite difference",
      "heading": true
    },
    {
      "id": "ch06-math-035",
      "type": "math",
      "x": 65,
      "y": 6826,
      "w": 990,
      "target": "lapV",
      "expr": "2+1"
    },
    {
      "id": "ch06-math-036",
      "type": "math",
      "x": 65,
      "y": 6991,
      "w": 475,
      "target": "hfd",
      "expr": "0.02"
    },
    {
      "id": "ch06-math-037",
      "type": "math",
      "x": 560,
      "y": 6991,
      "w": 475,
      "target": "xfd",
      "expr": "0.7"
    },
    {
      "id": "ch06-math-038",
      "type": "math",
      "x": 65,
      "y": 7156,
      "w": 990,
      "target": "fd_second",
      "expr": "((xfd+hfd)^2-2*xfd^2+(xfd-hfd)^2)/hfd^2"
    },
    {
      "id": "ch06-math-039",
      "type": "math",
      "x": 65,
      "y": 7321,
      "w": 990,
      "target": "fd_error",
      "expr": "fd_second-2"
    },
    {
      "id": "ch06-table-040",
      "type": "table",
      "x": 65,
      "y": 7486,
      "w": 990,
      "h": 280,
      "title": "Laplacian / finite difference",
      "headersText": "Value",
      "rowLabels": "∇²(x²+0.5y²)\nFinite-difference d²(x²)/dx²\nFD error",
      "expr": "cols([lapV,fd_second,fd_error])",
      "precision": "12"
    },
    {
      "id": "ch06-head-041",
      "type": "text",
      "x": 65,
      "y": 7856,
      "w": 990,
      "content": "Checkpoint / exploration",
      "heading": true
    },
    {
      "id": "ch06-note-042",
      "type": "text",
      "x": 65,
      "y": 7961,
      "w": 990,
      "content": "M²S does not provide automatic grad/div/curl operators, so the component formulas are written explicitly. This is intentional: the worksheet makes the local derivatives visible rather than hiding them behind an operator.",
      "heading": false
    }
  ]
}
