1 /**********************************************************************
2   neb_run.c:
3 
4      neb_run.c is a code which mediates between neb.c and openmx.
5 
6   Log of neb_run.c:
7 
8      13th/April/2011,  Released by T.Ozaki
9 
10 ***********************************************************************/
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <math.h>
15 #include <string.h>
16 #include <ctype.h>
17 #include <time.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <unistd.h>
21 #include "openmx_common.h"
22 #include "mpi.h"
23 #include <omp.h>
24 
25 
26 
neb_run(char * argv[],MPI_Comm mpi_commWD,int index_images,double *** neb_atom_coordinates,int * WhatSpecies_NEB,int * Spe_WhatAtom_NEB,char ** SpeName_NEB)27 void neb_run(char *argv[], MPI_Comm mpi_commWD, int index_images, double ***neb_atom_coordinates,
28              int *WhatSpecies_NEB, int *Spe_WhatAtom_NEB, char **SpeName_NEB)
29 {
30   int i,j,MD_iter;
31   int numprocs,myid;
32   double TStime,TEtime;
33   static char fileMemory[YOUSO10];
34 
35   MPI_COMM_WORLD1 = mpi_commWD;
36   mpi_comm_level1 = mpi_commWD;
37   MPI_Comm_size(MPI_COMM_WORLD1,&numprocs);
38   MPI_Comm_rank(MPI_COMM_WORLD1,&myid);
39   NUMPROCS_MPI_COMM_WORLD = numprocs;
40   MYID_MPI_COMM_WORLD = myid;
41   Num_Procs = numprocs;
42 
43   /* for measuring elapsed time */
44 
45   dtime(&TStime);
46 
47   /* allocation of CompTime */
48 
49   CompTime = (double**)malloc(sizeof(double*)*numprocs);
50   for (i=0; i<numprocs; i++){
51     CompTime[i] = (double*)malloc(sizeof(double)*20);
52     for (j=0; j<20; j++) CompTime[i][j] = 0.0;
53   }
54 
55   Init_List_YOUSO();
56   remake_headfile = 0;
57   ScaleSize = 1.2;
58 
59   /****************************************************
60                     Read the input file
61   ****************************************************/
62 
63   MPI_Comm_size(MPI_COMM_WORLD1,&numprocs);
64   MPI_Comm_rank(MPI_COMM_WORLD1,&myid);
65 
66   init_alloc_first();
67 
68   CompTime[myid][1] = readfile(argv);
69   MPI_Barrier(MPI_COMM_WORLD1);
70 
71   /* initialize PrintMemory routine */
72 
73   sprintf(fileMemory,"%s%s.memory%i",filepath,filename,myid);
74   PrintMemory(fileMemory,0,"init");
75   PrintMemory_Fix();
76 
77   /* initialize */
78 
79   init();
80 
81   /* for DFTD-vdW by okuno */
82   if(dftD_switch==1) DFTDvdW_init();
83 
84   /****************************************************
85                      SCF-DFT calculations
86   ****************************************************/
87 
88   MD_iter = 1;
89 
90   CompTime[myid][2] += truncation(MD_iter,1);
91   CompTime[myid][3] += DFT(MD_iter,(MD_iter-1)%orbitalOpt_per_MDIter+1);
92 
93   /****************************************************
94    store the total energy, coordinates, and gradients
95   ****************************************************/
96 
97   /* total energy */
98   neb_atom_coordinates[index_images][0][0] = Utot;
99 
100   /* atomic coordinates */
101 
102   for (i=1; i<=atomnum; i++){
103     neb_atom_coordinates[index_images][i][1] = Gxyz[i][1];
104     neb_atom_coordinates[index_images][i][2] = Gxyz[i][2];
105     neb_atom_coordinates[index_images][i][3] = Gxyz[i][3];
106   }
107 
108   /* gradients on atoms */
109 
110   for (i=1; i<=atomnum; i++){
111     neb_atom_coordinates[index_images][i][17] = Gxyz[i][17];
112     neb_atom_coordinates[index_images][i][18] = Gxyz[i][18];
113     neb_atom_coordinates[index_images][i][19] = Gxyz[i][19];
114   }
115 
116   /****************************************************
117     store WhatSpecies_NEB, Spe_WhatAtom_NEB,
118     and SpeName_NEB
119   ****************************************************/
120 
121   for (i=1; i<=atomnum; i++){
122     WhatSpecies_NEB[i] = WhatSpecies[i];
123   }
124 
125   for (i=0; i<SpeciesNum; i++){
126     Spe_WhatAtom_NEB[i] = Spe_WhatAtom[i];
127   }
128 
129   for (i=0; i<SpeciesNum; i++){
130     sprintf(SpeName_NEB[i],"%s",SpeName[i]);
131   }
132 
133   /****************************************************
134                finalize the calculation
135   ****************************************************/
136 
137   /* elapsed time */
138 
139   dtime(&TEtime);
140   CompTime[myid][0] = TEtime - TStime;
141   Output_CompTime();
142   for (i=0; i<numprocs; i++){
143     free(CompTime[i]);
144   }
145   free(CompTime);
146 
147   /* merge log files */
148 
149   Merge_LogFile(argv[1]);
150 
151   /* print memory */
152 
153   PrintMemory("total",0,"sum");
154 
155   /* free arrays */
156 
157   Free_Arrays(0);
158 }
159