Can we calculate the magnetic field of a permanent magnet?

We are always introduced to magnets by pictures illustrating a parallepiped magnet, a horseshoe magnet, etc...
Anyway the first time we actually calculate a magnetic field is for eelectromagnets.
Indeed I've rarely seen explaining or calculating the magnetic field of a permanent magnet.
I know formulas for the magnetic field of a moving charge, around a conductive wire, inside a solenoid, but I don't have idea on how to go about calcualting the filed of a simple permanent magnet.
It's like that without the help of electricity I'm stuck.
I'd guess it would be heavily dependent on the magnetic material, its shape and the medium in which is placed.
I hope that someone would provide me some insights on why such formulas are never introduced in most physics courses and lay down some examples of a permanent magnet field caluclation.

• The problem is, the same magnet can be magnetized in different ways and with different strengths, so there is no formula to deduce the magnetic field of a permanent magnet. The field in this case is measured, not calculated. – GRB Jul 8 at 8:58
• I used to do an activity in which I asked students to use coin-sized compasses to map the magnetic fields of real bar and horseshoe magnets. The students were often surprised by how much their maps varied from sample to sample and how much they deviated from symmetry. Physical magnets are messy. – dmckee Jul 8 at 15:10

The solution is a bit messy already, but if the magnet has a total magnetic moment of $$\mathbf{m}$$ and radius $$a$$, then the magnetic field for $$r>a$$ is:
$$\mathbf{B}(r>a)=\frac{\mu_0}{4\pi} \left[ -\frac{\mathbf{m}}{r^3}+\frac{3(\mathbf{m}\cdot\mathbf{r})\mathbf{r}}{r^5}\right]$$
If you look at large enough distances $$r>>a$$, most magnets roughly have fields like that in the above equation. However, when you have a strangely shaped magnet and are looking at the field really close to it, you can get more complex behavior. 