Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sqmatrix-set routine #105

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/docs/Scheme_User_Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ Read/write the current eigenvectors (raw planewave amplitudes) to/from an HDF5 f
`output-eigenvectors` is like `save-eigenvectors`, except that it saves an `evects` object returned by `get-eigenvectors`.
Conversely `input-eigenvectors`, reads back in the eigenvectors into an `evects` object from a file that has `num-bands` bands.

Currently, there's only one other interesting thing you can do with the raw eigenvectors, and that is to compute the dot-product matrix between a set of saved eigenvectors and the current eigenvectors. This can be used, e.g., to detect band crossings or to set phases consistently at different k points. The dot product is returned as a "sqmatrix" object, whose elements can be read with the `sqmatrix-size` and `sqmatrix-ref` routines.
Currently, there's only one other interesting thing you can do with the raw eigenvectors, and that is to compute the dot-product matrix between a set of saved eigenvectors and the current eigenvectors. This can be used, e.g., to detect band crossings or to set phases consistently at different k points. The dot product is returned as a "sqmatrix" object, whose elements can be read or altered with the `sqmatrix-size`, `sqmatrix-ref`, and `sqmatrix-set` routines.

**`(dot-eigenvectors ev first-band)`**
          
Expand All @@ -831,6 +831,10 @@ Return the size *n* of an *n*x*n* sqmatrix `sm`.
          
Return the (`i`,`j`)th element of the *n*x*n* sqmatrix *`sm`*, where {`i`,`j`} range from 0..*n*-1.

**`(sqmatrix-set sm i j c)`**
          
Set the (`i`,`j`)th element of the *n*x*n* sqmatrix *`sm`* to the `cnumber` *`c`*, where {`i`,`j`} range from 0..*n*-1.

Inversion Symmetry
------------------

Expand Down
9 changes: 9 additions & 0 deletions mpb/matrix-smob.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ cnumber sqmatrix_ref(SCM mo, integer i, integer j)
return c;
}

void sqmatrix_set(SCM mo, integer i, integer j, cnumber c)
{
sqmatrix *m = assert_sqmatrix_smob(mo);
CHECK(m && i >= 0 && j >= 0 && i < m->p && j < m->p,
"invalid arguments to sqmatrix-set");
ASSIGN_SCALAR(m->data[i * m->p + j], c.re, c.im);
scm_remember_upto_here_1(mo);
}

SCM sqmatrix_mult(SCM Ao, SCM Bo)
{
sqmatrix *A = assert_sqmatrix_smob(Ao);
Expand Down
2 changes: 2 additions & 0 deletions mpb/mpb.scm.in
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@
(define-external-function sqmatrix-size false false 'integer 'SCM)
(define-external-function sqmatrix-ref false false 'cnumber
'SCM 'integer 'integer)
(define-external-function sqmatrix-set false false no-return-value
'SCM 'integer 'integer 'cnumber)
(define-external-function sqmatrix-mult false false 'SCM
'SCM 'SCM)
(define-external-function sqmatrix-diagm false false 'SCM
Expand Down