File: Cutoff.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 (116 lines) | stat: -rw-r--r-- 2,616 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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "openmx_common.h"

#ifdef nompi
#include "mimic_mpi.h"
#else
#include "mpi.h"
#endif

void Determine_Cell_from_ECutoff(double tv[4][4], double ECut)
{
  /*********************************************************
     assume cubic cell, determine cell size from ECut 
     input::  tv, Ecut
     output:: tv (tuned) 
  *********************************************************/
   
  double a,len;
  int pow[4],must[4];
  int i,j,k,Scale[4];

  int myid,numprocs;
 
  MPI_Comm_size(mpi_comm_level1,&numprocs);
  MPI_Comm_rank(mpi_comm_level1,&myid);

  /* check whether tv is a rectangular solid or not */
  for (i=1;i<=3;i++) Scale[i]=0;
  for (i=1;i<=3;i++) 
    for (j=1;j<=3;j++) 
      if (fabs(tv[i][j])<1.0e-6)  Scale[i]++;
  for (i=1;i<=3;i++) {
  /*  printf("Scale[%d]=%d\n",i,Scale[i]); */
    if (Scale[i]!=2) {
       printf("Error: Cell is not cubic\n");
       MPI_Finalize();
       exit(1);
    }  
  }
 
  a=PI/sqrt(ECut);

  must[1]=1;
  must[2]=1;
  must[3]=1;

  for (i=1; i<=3; i++) {
     /* printf("axis=%d\n",i); */
     len= sqrt( tv[i][1]*tv[i][1] + tv[i][2]*tv[i][2] +tv[i][3]*tv[i][3] ); 
     Scale[i] = (int) (len/a);

     /* factorize */     
     for (j=Scale[i]; ; j++) {
        /* printf("try %d\n",j); */
        if ( factorize(j, NfundamentalNum,fundamentalNum,pow,must[i])
             && ( (double)(a*j) >=len) ) {

           break; 
        }
     } 

     /* j*a = |tv[i]| */
     for (k=1;k<=3;k++) {
       tv[i][k]*= (a*j)/len;
     }
     Scale[i]=j;

  } 

    
  if (myid==Host_ID) {
    if (unitvector_unit==1) {
      printf("widened unit cell to fit energy cutoff (Bohr)\n");
      i=1;printf("A = %lf %lf %lf (%d)\n", tv[i][1],tv[i][2],tv[i][3],Scale[i]);
      i=2;printf("B = %lf %lf %lf (%d)\n", tv[i][1],tv[i][2],tv[i][3],Scale[i]);
      i=3;printf("C = %lf %lf %lf (%d)\n", tv[i][1],tv[i][2],tv[i][3],Scale[i]);
    }
    else if (unitvector_unit==0 ) {
      printf("widened unit cell to fit energy cutoff (Ang.)\n");
      i=1;printf("A = %lf %lf %lf (%d)\n", tv[i][1]*BohrR,tv[i][2]*BohrR,
		 tv[i][3]*BohrR,Scale[i]);
      i=2;printf("B = %lf %lf %lf (%d)\n", tv[i][1]*BohrR,tv[i][2]*BohrR,
		 tv[i][3]*BohrR,Scale[i]);
      i=3;printf("C = %lf %lf %lf (%d)\n", tv[i][1]*BohrR,tv[i][2]*BohrR,
		 tv[i][3]*BohrR,Scale[i]);
    }
  }

}

#if 0
main()
{

  double tv[3][3],ECut;
  int i,j;

  for (i=0;i<3;i++) {
    for (j=0;j<3;j++) {
      tv[ i][j]= 0.0;
     }
  }

  tv[0][0]=15.0;
  tv[1][1]=16.0;
  tv[2][2]=17.0;

  ECut=150.1;
  Determine_Cell_from_ECutoff(tv,ECut);

}

#endif