diff options
author | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-12-07 18:44:06 +0000 |
---|---|---|
committer | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-12-07 18:44:06 +0000 |
commit | 9d689af8e563441560fa0b7bde3a8c2d2093fb15 (patch) | |
tree | 75e7c36f1b2a77e7cabb85d1fc247b54728f6f14 /src/basis.c | |
parent | acdeee2c5432855cb959c2c2f21d141cd9f4dfb7 (diff) |
Save lattice parameters with reflection data
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@228 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/basis.c')
-rw-r--r-- | src/basis.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/basis.c b/src/basis.c index f3b9b7a..46335fa 100644 --- a/src/basis.c +++ b/src/basis.c @@ -14,6 +14,9 @@ #endif #include <math.h> +#include <gsl/gsl_matrix.h> +#include <gsl/gsl_blas.h> +#include <gsl/gsl_linalg.h> #include "reflections.h" #include "basis.h" @@ -80,3 +83,43 @@ Basis basis_add(Basis u, Basis v) { } +UnitCell basis_get_cell(Basis *basis) { + + UnitCell cell; + gsl_matrix *m; + gsl_matrix *inv; + gsl_permutation *perm; + double ax, ay, az, bx, by, bz, cx, cy, cz; + int s; + + m = gsl_matrix_alloc(3, 3); + gsl_matrix_set(m, 0, 0, basis->a.x); gsl_matrix_set(m, 0, 1, basis->b.x); gsl_matrix_set(m, 0, 2, basis->c.x); + gsl_matrix_set(m, 1, 0, basis->a.y); gsl_matrix_set(m, 1, 1, basis->b.y); gsl_matrix_set(m, 1, 2, basis->c.y); + gsl_matrix_set(m, 2, 0, basis->a.z); gsl_matrix_set(m, 2, 1, basis->b.z); gsl_matrix_set(m, 2, 2, basis->c.z); + + gsl_matrix_transpose(m); + + perm = gsl_permutation_alloc(m->size1); + inv = gsl_matrix_alloc(m->size1, m->size2); + gsl_linalg_LU_decomp(m, perm, &s); + gsl_linalg_LU_invert(m, perm, inv); + gsl_permutation_free(perm); + gsl_matrix_free(m); + + ax = gsl_matrix_get(inv, 0, 0); bx = gsl_matrix_get(inv, 0, 1); cx = gsl_matrix_get(inv, 0, 2); + ay = gsl_matrix_get(inv, 1, 0); by = gsl_matrix_get(inv, 1, 1); cy = gsl_matrix_get(inv, 1, 2); + az = gsl_matrix_get(inv, 2, 0); bz = gsl_matrix_get(inv, 2, 1); cz = gsl_matrix_get(inv, 2, 2); + + cell.a = sqrt(ax*ax + ay*ay + az*az); + cell.b = sqrt(bx*bx + by*by + bz*bz); + cell.c = sqrt(cx*cx + cy*cy + cz*cz); + cell.alpha = acos((bx*cx + by*cy + bz*cz)/(cell.b * cell.c)); + cell.beta = acos((ax*cx + ay*cy + az*cz)/(cell.a * cell.c)); + cell.gamma = acos((bx*ax + by*ay + bz*az)/(cell.b * cell.a)); + + gsl_matrix_free(inv); + + return cell; + +} + |