# Magnetic field modeling with noises

I am trying to make a 3d grid of a magnetic field with some noises (which will be added to the ordinary field) for a computer simulation. I have the formula for the ordinary field, also I am using a fast Fourier transform (FFT) to create Gaussian Random Field for noises.

The problem is, that the noise field I have created is a scalar field not a vector. So I need to find a way for creating vector-valued Gaussian random field whose divergence will be equal to zero.

You can use the fact that the divergence-free constraint, $$\nabla\cdot\mathbf{B}=0$$, becomes $$\mathbf{k}\cdot\tilde{\mathbf{B}} = 0$$ in Fourier space, where $$\tilde{\mathbf{B}}$$ denotes the Fourier transform of $$\mathbf{B}$$ and $$\mathbf{k}$$ is the wavevector.
To get a vector-valued field, you could first generate a random field for each of the three components (e.g. $$\tilde{\mathbf{B}} =(\tilde{B}_x,\tilde{B}_y,\tilde{B}_z)$$ in Fourier space). Once you have these, you can subtract off the projection of $$\tilde{\mathbf{B}}$$ along $$\mathbf{k}$$ to satisfy $$\mathbf{k}\cdot\tilde{\mathbf{B}} = 0$$: $$\tilde{\mathbf{B}} \to \tilde{\mathbf{B}} - \frac{\mathbf{k}}{k^2}(\tilde{\mathbf{B}}\cdot\mathbf{k}).$$
Taking the inverse Fourier transform of this new $$\tilde{\mathbf{B}}$$ will then give you a divergence-free noise field.