File: IS_LU.c

package info (click to toggle)
openmx 3.2.4.dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze
  • size: 62,572 kB
  • ctags: 2,684
  • sloc: ansic: 130,666; python: 876; makefile: 560; xml: 63; perl: 18; sh: 4
file content (196 lines) | stat: -rw-r--r-- 4,774 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**********************************************************************
  IS_LU.c:

     IS_LU.c is a subroutine to calculate the inverse of overlap
     matrix using the divide (LU) method.

  Log of IS_LU.c:

     22/Nov/2001  Released by T.Ozaki

***********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "openmx_common.h"
#include "lapack_prototypes.h"

static void LU(int ct_AN, double ****S0, double ****IOLP);

void IS_LU(double ****S0, double ****IOLP)
{
  static int ct_AN;
  static int wan,tno1,i,ig,ino1,k,p,q;
  static double dum1,dum2,dum;

  printf("LU\n"); 


  for (ct_AN=1; ct_AN<=atomnum; ct_AN++){
    LU(ct_AN,S0,IOLP);
  }

  /****************************************************
                  Averaging of IOLP
  ****************************************************/

  for (ct_AN=1; ct_AN<=atomnum; ct_AN++){
    wan = WhatSpecies[ct_AN];
    tno1 = Spe_Total_CNO[wan] - 1;
    for (i=0; i<=(FNAN[ct_AN]+SNAN[ct_AN]); i++){
      ig = natn[ct_AN][i];
      ino1 = Spe_Total_CNO[WhatSpecies[ig]] - 1;
      k = RMI2[ct_AN][i][0];
      for (p=0; p<=tno1; p++){
	for (q=0; q<=ino1; q++){
	  dum1 = IOLP[ct_AN][i][p][q];
	  dum2 = IOLP[ig][k][q][p];
	  dum = 0.50*(dum1 + dum2);
	  IOLP[ct_AN][i][p][q] = dum;
	  IOLP[ig][k][q][p] = dum;
	}
      }
    } 
  }
}

void LU(int ct_AN, double ****S0, double ****IOLP)
{
  static INTEGER N,lda,info,lwork;
  static INTEGER *piv;
  static int **jun;
  static int i0,j0; 
  static int i,j,k,l;
  static int ig,ian,jg,jan,kg,kan,qb;
  static int po,fan,san,can,wan,m,n,kl;
  static double *LoS,*work;


  /****************************************************
    allocation of arrays:

     static INTEGER piv[List_YOUSO[2]*List_YOUSO[7]];
     static int jun[List_YOUSO[2]][List_YOUSO[7]];
  ****************************************************/

  piv = (INTEGER*)malloc(sizeof(INTEGER)*List_YOUSO[2]*List_YOUSO[7]);
  jun = (int**)malloc(sizeof(int*)*List_YOUSO[2]); 
  for (i=0; i<List_YOUSO[2]; i++){
    jun[i] = (int*)malloc(sizeof(int)*List_YOUSO[7]); 
  }

  /****************************************************
                  Setting of S-matrix           
  ****************************************************/

  fan = FNAN[ct_AN];
  san = SNAN[ct_AN];
  can = fan + san;

  N = 0;
  for (i=0; i<=can; i++){
    ig = natn[ct_AN][i];
    ian = Spe_Total_CNO[WhatSpecies[ig]];
    for (k=0; k<ian; k++){
      N++;
      jun[i][k] = N-1; 
    }
  }  

  LoS = (double*)malloc(sizeof(double)*N*N);
  work = (double*)malloc(sizeof(double)*N);

  for (i=0; i<=can; i++){
    ig = natn[ct_AN][i];
    ian = Spe_Total_CNO[WhatSpecies[ig]];
    for (j=0; j<=can; j++){
      kl = RMI1[ct_AN][i][j];
      jg = natn[ct_AN][j];
      jan = Spe_Total_CNO[WhatSpecies[jg]];

      if (0<=kl){
	for (m=0; m<=(ian-1); m++){
          i0 = jun[i][m];
	  for (n=0; n<=(jan-1); n++){
            j0 = jun[j][n];
            k = N*j0 + i0;
            LoS[k] = S0[ig][kl][m][n];
	  }
	}
      }
      else{
	for (m=0; m<=(ian-1); m++){
          i0 = jun[i][m];
	  for (n=0; n<=(jan-1); n++){
            j0 = jun[j][n];
            k = N*j0 + i0; 
            LoS[k] = 0.0;
	  }
	}
      }
    }
  }

  /****************************************************
                Call dgetrf_() in clapack
  ****************************************************/

  lda = N;
  F77_NAME(dgetrf,DGETRF)(&N, &N, LoS, &lda, piv, &info);

  if (info!=0){
    printf("Error in dgetrf_() which is called from IS_LU  info=%2d\n",info);
  }

  /****************************************************
                Call dgetri_() in clapack
  ****************************************************/

  lwork = N;
  F77_NAME(dgetri,DGETRI)(&N, LoS, &lda, piv, work, &lwork, &info);
  if (info!=0){
    printf("Error in dgetri_() which is called from IS_LU  info=%2d\n",info);
  }

  /****************************************************
                       LoS -> IOLP
  ****************************************************/

  i = 0;
  ig = natn[ct_AN][i];
  ian = Spe_Total_CNO[WhatSpecies[ig]];
  for (j=0; j<=can; j++){
    jg = natn[ct_AN][j];
    jan = Spe_Total_CNO[WhatSpecies[jg]];
    for (m=0; m<=(ian-1); m++){
      i0 = jun[i][m];
      for (n=0; n<=(jan-1); n++){
        j0 = jun[j][n];
        k = N*j0 + i0;
        IOLP[ct_AN][j][m][n] = LoS[k];
      }
    }
  }

  free(LoS);
  free(work);

  /****************************************************
    freeing of arrays:

     static INTEGER piv[List_YOUSO[2]*List_YOUSO[7]];
     static int jun[List_YOUSO[2]][List_YOUSO[7]];
  ****************************************************/

  free(piv);
  for (i=0; i<List_YOUSO[2]; i++){
    free(jun[i]);
  }
  free(jun);

}