numerics 0.1.0
Loading...
Searching...
No Matches
Field Examples

Field types provide grid storage for PDE and vector-calculus examples.

Scalar Field

const int nx = 64;
const int ny = 64;
const int nz = 64;
const float dx = 1.0f / 63.0f;
num::ScalarField3D rho(nx, ny, nz, dx);
rho.fill([&](int i, int j, int k) {
const double x = i * dx;
const double y = j * dx;
const double z = k * dx;
return std::exp(-40.0 * ((x - 0.5) * (x - 0.5)
+ (y - 0.5) * (y - 0.5)
+ (z - 0.5) * (z - 0.5)));
});

Vector Field

num::VectorField3D v(nx, ny, nz, dx);
v.x.fill(0.0);
v.y.fill(0.0);
v.z.fill(1.0);

Poisson Utility

num::ScalarField3D phi(nx, ny, nz, dx);
num::FieldSolver::solve_poisson(phi, rho, 1e-8, 1000);
static SolverResult solve_poisson(ScalarField3D &phi, const ScalarField3D &source, double tol=1e-6, int max_iter=500)
Solve with zero Dirichlet boundaries.

Internally this wraps the finite-difference operator with num::operators::make_op and solves with conjugate gradients.

Magnetic Field Utility

num::VectorField3D J(nx, ny, nz, dx);
load_current_density(J);
static VectorField3D solve_magnetic_field(const VectorField3D &J, double tol=1e-6, int max_iter=500)

This computes vector potential components from Poisson solves and returns \(\mathbf{B}=\nabla\times\mathbf{A}\).