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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "openmx_common.h"
#include "mpi.h"
double Mixing_DM(int MD_iter,
int SCF_iter,
int SCF_iter0,
int SucceedReadingDMfile,
double ***ReRhok,
double ***ImRhok,
double **Residual_ReRhok,
double **Residual_ImRhok,
double *ReVk,
double *ImVk,
double *ReRhoAtomk,
double *ImRhoAtomk)
{
int pSCF_iter,NumMix,NumSlide;
int spin,ct_AN,wan1,TNO1,h_AN,Gh_AN,wan2;
int TNO2,i,j,ian,jan,m,n;
int spinmax,k1,k2,k3;
int Mc_AN,Gc_AN;
double time0;
double TStime,TEtime;
int numprocs,myid,ID;
/* MPI */
MPI_Comm_size(mpi_comm_level1,&numprocs);
MPI_Comm_rank(mpi_comm_level1,&myid);
MPI_Barrier(mpi_comm_level1);
dtime(&TStime);
/* In case of rmm-diish, then return. */
if (Cnt_switch!=1 && Mixing_switch==5) return 0.0;
/* In case of (rmm-diis || rmm-adiis) && SCF_iter<(Pulay_SCF/2)), then return. */
if ( Cnt_switch!=1 && SucceedReadingDMfile!=1
&& (Mixing_switch==1 || Mixing_switch==6) && SCF_iter<=(Pulay_SCF/2) && Solver!=4) return 0.0;
/*******************************************************
Simple Mixing
*******************************************************/
if (Mixing_switch==0){
if (MD_iter==1 && SCF_iter==1){
/*---------- modified by TOYODA 18/JAN/2010 */
#if EXX_MIX_DM
if (g_exx_switch) {
Simple_Mixing_DM(0,1.0,DM[0],DM[1],DM[2],
iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2],
g_exx, g_exx_DM[0], g_exx_DM[1], g_exx_DM[2]);
} else {
Simple_Mixing_DM(0,1.0,DM[0],DM[1],DM[2],
iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2],
NULL, NULL, NULL, NULL);
}
#else
Simple_Mixing_DM( 0,1.0,DM[0],DM[1],DM[2],
iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2]);
#endif
/*---------- until here */
}
else{
/*---------- modified by TOYODA 18/JAN/2010 */
#if EXX_MIX_DM
if (g_exx_switch) {
Simple_Mixing_DM(1,Mixing_weight,DM[0],DM[1],DM[2],
iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2],
g_exx, g_exx_DM[0], g_exx_DM[1], g_exx_DM[2]);
} else {
Simple_Mixing_DM(1,Mixing_weight,DM[0],DM[1],DM[2],
iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2],
NULL, NULL, NULL, NULL);
}
#else
Simple_Mixing_DM(1,Mixing_weight,DM[0],DM[1],DM[2],iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2]);
#endif
/*---------- until here */
}
}
/*******************************************************
Pulay's method
Residual Minimazation Method (RMM) using
Direct Inversion in the Iterative Subspace (DIIS)
*******************************************************/
else if (Mixing_switch==1){
if (SCF_iter==1){
DIIS_Mixing_DM(1,ResidualDM,iResidualDM);
}
else if (SCF_iter<=(Pulay_SCF-1)){
/*---------- added by TOYODA 18/JAN/2010 */
#if EXX_MIX_DM
if (g_exx_switch) {
Simple_Mixing_DM(1,Mixing_weight,DM[0],DM[1],DM[2],
iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2],
g_exx, g_exx_DM[0], g_exx_DM[1], g_exx_DM[2]);
} else {
Simple_Mixing_DM(1,Mixing_weight,DM[0],DM[1],DM[2],
iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2],
NULL, NULL, NULL, NULL);
}
#else
Simple_Mixing_DM(1,Mixing_weight,DM[0],DM[1],DM[2],iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2]);
#endif
/*---------- until here */
}
else if (SCF_iter==Pulay_SCF)
DIIS_Mixing_DM(2,ResidualDM,iResidualDM);
else
DIIS_Mixing_DM(SCF_iter-(Pulay_SCF-2),ResidualDM,iResidualDM);
}
/*********************************************************
Guaranteed-Reduction Pulay's method (GR-Pulay method)
*********************************************************/
else if (Mixing_switch==2){
if (SCF_iter==1){
GR_Pulay_DM(1,ResidualDM);
}
else if (SCF_iter<=(Pulay_SCF-1))
/*---------- added by TOYODA 18/JAN/2010 */
#if EXX_MIX_DM
if (g_exx_switch) {
Simple_Mixing_DM(1,Mixing_weight,DM[0],DM[1],DM[2],
iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2],
g_exx, g_exx_DM[0], g_exx_DM[1], g_exx_DM[2]);
} else {
Simple_Mixing_DM(1,Mixing_weight,DM[0],DM[1],DM[2],
iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2],
NULL, NULL, NULL, NULL);
}
#else
Simple_Mixing_DM(1,Mixing_weight,DM[0],DM[1],DM[2],iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2]);
#endif
/*---------- until here */
else if (SCF_iter==Pulay_SCF)
GR_Pulay_DM(2,ResidualDM);
else
GR_Pulay_DM(SCF_iter-(Pulay_SCF-2),ResidualDM);
}
/*********************************************************
Kerker simple mixing in k-space
*********************************************************/
else if (Mixing_switch==3){
if (MD_iter==1 && SCF_iter0==1 && SucceedReadingDMfile==0){
Kerker_Mixing_Rhok(0, Mixing_weight,
ReRhok,ImRhok,
Residual_ReRhok,Residual_ImRhok,
ReVk,ImVk,ReRhoAtomk,ImRhoAtomk);
}
else if (MD_iter==1 && SCF_iter==1){
Kerker_Mixing_Rhok(0, Mixing_weight,
ReRhok,ImRhok,
Residual_ReRhok,Residual_ImRhok,
ReVk,ImVk,ReRhoAtomk,ImRhoAtomk);
}
else if ( (SCF_iter%30)==1) {
Kerker_Mixing_Rhok(1,Max_Mixing_weight,
ReRhok,ImRhok,
Residual_ReRhok,Residual_ImRhok,
ReVk,ImVk,ReRhoAtomk,ImRhoAtomk);
}
else{
Kerker_Mixing_Rhok(1,Mixing_weight,
ReRhok,ImRhok,
Residual_ReRhok,Residual_ImRhok,
ReVk,ImVk,ReRhoAtomk,ImRhoAtomk);
}
}
/*********************************************************
RMM-DIIS mixing with Kerker's weighting factor in k-space
*********************************************************/
else if (Mixing_switch==4){
if (MD_iter==1 && SCF_iter==1){
Kerker_Mixing_Rhok(0,Mixing_weight,
ReRhok,ImRhok,
Residual_ReRhok,Residual_ImRhok,
ReVk,ImVk,ReRhoAtomk,ImRhoAtomk);
}
else if (SCF_iter<Pulay_SCF){
Kerker_Mixing_Rhok(1,Mixing_weight,
ReRhok,ImRhok,
Residual_ReRhok,Residual_ImRhok,
ReVk,ImVk,ReRhoAtomk,ImRhoAtomk);
}
else{
if (6<SCF_iter){
DIIS_Mixing_Rhok(SCF_iter-(Pulay_SCF-3),
Mixing_weight,
ReRhok,ImRhok,
Residual_ReRhok,Residual_ImRhok,
ReVk,ImVk,ReRhoAtomk,ImRhoAtomk);
}
else{
DIIS_Mixing_Rhok(SCF_iter,
Mixing_weight,
ReRhok,ImRhok,
Residual_ReRhok,Residual_ImRhok,
ReVk,ImVk,ReRhoAtomk,ImRhoAtomk);
}
}
}
/*******************************************************
ADIIS method:
Augmented Roothaan-Hall (ARH) energy function
+
Direct Inversion in the Iterative Subspace (DIIS)
*******************************************************/
else if (Mixing_switch==6){
if (SCF_iter<=(Pulay_SCF-1)){
Simple_Mixing_DM(1,Mixing_weight,DM[0],DM[1],DM[2],
iDM[0],iDM[1],iDM[2],ResidualDM[2],iResidualDM[2],
NULL, NULL, NULL, NULL);
}
else
ADIIS_Mixing_DM(SCF_iter-Pulay_SCF+2,ResidualDM,iResidualDM);
}
/*******************************************************
not supported
*******************************************************/
else {
printf("Mixing_switch=%i is not supported.\n",Mixing_switch);
MPI_Finalize();
exit(0);
}
/* if SCF_iter0==1, then NormRD[0]=1 */
if (SCF_iter0==1) NormRD[0] = 1.0;
MPI_Barrier(mpi_comm_level1);
dtime(&TEtime);
time0 = TEtime - TStime;
return time0;
}
|