numerics 0.1.0
Loading...
Searching...
No Matches
field_solver.hpp
Go to the documentation of this file.
1/// @file pde/field_solver.hpp
2/// @brief Elliptic solvers and vector calculus on 3D field containers.
3#pragma once
4
5#include "fields/field3d.hpp"
7#include <vector>
8
9namespace num {
10
12public:
13 /// Dirichlet boundary condition: fix phi = value at grid node flat_idx.
14 struct DirichletBC {
15 int flat_idx; ///< k*ny*nx + j*nx + i
16 double value;
17 };
18
19 /// @brief Solve \f$\Delta\phi=s\f$ with zero Dirichlet boundaries.
21 const ScalarField3D& source,
22 double tol = 1e-6,
23 int max_iter = 500);
24
25 /// @brief Solve \f$\nabla\cdot(c\nabla\phi)=0\f$ with Dirichlet data.
27 const ScalarField3D& coeff,
28 const std::vector<DirichletBC>& bcs,
29 double tol = 1e-6,
30 int max_iter = 500);
31
32 /// @brief Compute \f$\nabla\phi\f$.
34
35 /// @brief Compute \f$\nabla\cdot f\f$.
36 static ScalarField3D divergence(const VectorField3D& f);
37
38 /// @brief Compute \f$\nabla\times A\f$.
39 static VectorField3D curl(const VectorField3D& A);
40};
41
43public:
44 static constexpr double MU0 = 1.2566370614e-6; ///< mu_0 [H/m]
45
46 /// Compute current density J = -sigma*grad(phi) [A/m^2].
48 const ScalarField3D& phi);
49
50 /// Solve for static magnetic field B given current density J.
51 /// Solves Laplacian(A) = -mu0*J (Coulomb gauge, Dirichlet A=0) via three CG
52 /// solves, then returns B = curl(A).
54 double tol = 1e-6,
55 int max_iter = 500);
56};
57
58} // namespace num
static VectorField3D gradient(const ScalarField3D &phi)
Compute .
static SolverResult solve_var_poisson(ScalarField3D &phi, const ScalarField3D &coeff, const std::vector< DirichletBC > &bcs, double tol=1e-6, int max_iter=500)
Solve with Dirichlet data.
static SolverResult solve_poisson(ScalarField3D &phi, const ScalarField3D &source, double tol=1e-6, int max_iter=500)
Solve with zero Dirichlet boundaries.
static VectorField3D curl(const VectorField3D &A)
Compute .
static ScalarField3D divergence(const VectorField3D &f)
Compute .
static VectorField3D solve_magnetic_field(const VectorField3D &J, double tol=1e-6, int max_iter=500)
static VectorField3D current_density(const ScalarField3D &sigma, const ScalarField3D &phi)
Compute current density J = -sigma*grad(phi) [A/m^2].
static constexpr double MU0
mu_0 [H/m]
3D scalar and vector fields on uniform Cartesian grids.
constexpr real phi
Golden ratio.
Definition math.hpp:45
constexpr real e
Definition math.hpp:44
Umbrella include for all linear solvers.
Dirichlet boundary condition: fix phi = value at grid node flat_idx.
int flat_idx
k*ny*nx + j*nx + i