During my Diploma thesis in Physics I had to calculate the Madelung constant for a lattice of ZnO supercells. For this purpose, I implemented a small Python programm. The only prerequisite is SciPy. The script calculates the Madelung constant for an infinite lattice of point charges, neuralized by a counter-charged jellium background. All documentation is inside the file madelung.py. There’s another script sc_mad.py (supercell madelung constant) in there which demonstrates reading a POSCAR file describing an atomic lattice and calculating the Madelung constant for it.
Maybe someone can so something useful with the stuff. I would be happy about feedback whether the implementation actually works for your specific case 🙂
For the case that you’re interested in
mod = a % b
with and there’s a simple method
mod = a & (b-1);
For negative a it gets more complicated
mod = (a & (b-1)) | ~(b-1);
In optics, the law of refraction by Snellius is widely known.
The calculation of can actually be done using geometry exclusively.
mere geometric calculation of the refraction of a ray
I have created this nice image using CarMetal, a geometry program. You can download the CarMetal-file brechung_regulaerundtotal.zir and play around with the angles yourself. While you change , f0r example, CarMetal maintains the introduced relationships like „… being parallel to …“ or „… goes through the intersection of … and … „. The green ray shows near total reflection which appears as soon as there’s no intersection of the vertical line with the inner circle.