spirit-code / spirit

Atomistic Spin Simulation Framework
http://spirit-code.github.io
MIT License
118 stars 52 forks source link

Core: spatial gradient for arbitrary lattices #283

Open GPMueller opened 7 years ago

GPMueller commented 7 years ago

This is related to #64.

If the basis is irregular and does not produce a simple lattice structure for which the neighbours for the spatial gradient are known, we should use tetrahedra from qhull.

Even when some tetrahedra are chose sub-optimally, the fact that other neighbouring tetrahedra will likely be fine makes large errors for single spins quite unlikely.

GPMueller commented 7 years ago

Related to #224, the neighbouring spins for the gradient could, in 2D, be determined by Delaunay triangulation and in 3D by dividing the lattice into tetrahedra. Both could be achieved using QHull.

GPMueller commented 7 years ago

Since cf99c840f63e5154b61a97a4f8dbb2d1ab6fbae0, for 2D, the Delaunay triangulation of the lattice could be used. Both triangulation and tetrahedra are available, so this could now be implemented.

GPMueller commented 7 years ago

Note that the Delaunay triangulation and the tetrahedra do not include periodical neighbours, so they need to be extended with boundaries in order to give physically correct results (see also #292).

GPMueller commented 7 years ago

This seems to be a non-trivial thing to do...

CGAL has this functionality:

but it is only for periodicity in all directions.

Implementing this by hand would mean adding an additional layer of points around the positions. The resulting triangles/tetrahedra could be checked, where an index>nos would mean that it is an artificial triangle. If at least one index is not artificial, the triangle/tetrahedron is valid.

GPMueller commented 7 years ago

Started work on better triangulations and tetrahedra with ca42835b3a1d6c6ecb1fe606fb9f0ad1e6b52f45 on feature-triangulations. Open questions:

GPMueller commented 6 years ago

A good starting point is the implementation done with 8b7f3e8416ad964face02adf2ec6e5f3821aa8ae. Using the given approach, the gradient could be calculated as a weighted average over the finite differences to the atoms in the same cell and the neighbouring cells. That approach should work adequately in almost any case.