-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathiteration.c
More file actions
29 lines (26 loc) · 732 Bytes
/
iteration.c
File metadata and controls
29 lines (26 loc) · 732 Bytes
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
/*
* The fixed point problem of the density is solved using a Picard iteration.
* rho_new = (1.0-alpha) * rho_iteration + alpha * rho_old,
* where alpha is less than 0.9.
* */
#include "headdefs.h"
void Iteration(){
int loop;
real Density_temp;
real Sum;
while(1){
Sum = 0.0;
Cal_Miu_HS_ex();
for(loop=0;loop<VProd(Pts);loop++){
Density_temp = Atom[0].density * exp(Atom[0].miu - Miu_ex[loop] - Beta * Vext[loop]);
Sum +=Sqr((1.0-Alpha) * Density_temp + Alpha * Density[loop] - Density[loop]);
Density[loop] = (1.0-Alpha) * Density_temp + Alpha * Density[loop];
}
printf("Sum = %lf\n", Sum);
if (Sum < Stop){
printf("The iteration is successfully finished!\n");
break;
}
}
return;
}