Generated from read_data.c with ROBODoc v3.2.2 on Fri Sep 14 14:23:23 2001

TABLE OF CONTENTS

  1. QMD-MGDFT/read_data.c

QMD-MGDFT/read_data.c

NAME
   Ab initio real space code with multigrid acceleration
   Quantum molecular dynamics package.
   Version: 2.1.5
COPYRIGHT
   Copyright (C) 1995  Emil Briggs
   Copyright (C) 1998  Emil Briggs, Charles Brabec, Mark Wensell, 
                       Dan Sullivan, Chris Rapcewicz, Jerzy Bernholc
   Copyright (C) 2001  Emil Briggs, Wenchang Lu,
                       Marco Buongiorno Nardelli,Charles Brabec, 
                       Mark Wensell,Dan Sullivan, Chris Rapcewicz,
                       Jerzy Bernholc
FUNCTION
   void read_data(char *name, REAL *vh, REAL *rho, REAL *vxc, STATE *states)
   when ct.runflag == 1,
   Reads the hartree potential, the wavefunctions
   and various other things from a file which is created by the 
   previous run.          
INPUTS
   name:  file name
OUTPUT
   vh: Hartree potential
   rho:  total valence charge density
   vxc:  exchange correlation potential
   states: point to orbital structure
PARENTS
   init.c
CHILDREN
   scatter_psi.c
SEE ALSO
   write_data.c
SOURCE
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <unistd.h>
    #include "md.h"
    
    void read_data(char *name, REAL *vh, REAL *rho, REAL *vxc, STATE *states)
    {
        int size, fhand, ion;
        int state, kpt;
        int t1;
        int i,ic,flag;
        char newname[MAX_PATH+200];
        STATE *sp;
        REAL *work, *work1;
        REAL temp_occ;
        REAL temp_pos[3];
        unsigned nbytes;
    
    
        sprintf(newname, "%s%d", name, pct.thispe);
    
        /* Get a temporary buffer */
        work = get_mem(2*P0_BASIS);
        if(work == NULL)
            error_handler("read_data", "Out of memory");
    
    
        /* Wait until everybody gets here */
        my_barrier();
    
    
            fhand = open(newname, O_RDWR);
            if(fhand < 0) error_handler("read_data", " Unable to open file ");
    
    
            /* Some control information */
            nbytes = read(fhand, &t1, sizeof(int));
            if(nbytes != sizeof(int))
                error_handler("read_data", "Unexpected end of file");
            if(t1 != ct.nbasis)
                error_handler("read_data", "Wrong number of points in basis");
    
    
            nbytes = read(fhand, &t1, sizeof(int));
            if(nbytes != sizeof(int))
                error_handler("read_data", "Unexpected end of file");
            if(t1 != ct.num_states)
                error_handler("read_data", "Wrong number of states");
    
            nbytes = read(fhand, &t1, sizeof(int));
            if(nbytes != sizeof(int))
                error_handler("read_data", "Unexpected end of file");
            if(t1 != PE_X)
                error_handler("read_data", "Wrong processor topology");
    
    
            nbytes = read(fhand, &t1, sizeof(int));
            if(nbytes != sizeof(int))
                error_handler("read_data", "Unexpected end of file");
            if(t1 != PE_Y)
                error_handler("read_data", "Wrong processor topology");
    
    
            nbytes = read(fhand, &t1, sizeof(int));
            if(nbytes != sizeof(int))
                error_handler("read_data", "Unexpected end of file");
            if(t1 != PE_Z)
                error_handler("read_data", "Wrong processor topology");
    
            nbytes = read(fhand, &t1, sizeof(int));
            if(nbytes != sizeof(int))
                error_handler("read_data", "Unexpected end of file");
            if(t1 != PHYS_PES)
                error_handler("read_data", "Wrong number of processors");
    
            nbytes = read(fhand, &t1, sizeof(int));
            if(nbytes != sizeof(int))
                error_handler("read_data", "Unexpected end of file");
            if(t1 != P0_BASIS)
                error_handler("read_data", "Wrong number of processors");
    
    
            /* Read the hartree potential PE0 component */
            nbytes = read(fhand, vh, P0_BASIS * sizeof(REAL));
            if(nbytes != (unsigned)(P0_BASIS * sizeof(REAL)))
                error_handler("read_data", "Unexpected end of file");
    
    
            /* Density */
            nbytes = read(fhand, rho, P0_BASIS * sizeof(REAL));
            if(nbytes != (unsigned)(P0_BASIS * sizeof(REAL)))
                error_handler("read_data", "Unexpected end of file");
    
            /* Vxc */
            nbytes = read(fhand, vxc, P0_BASIS * sizeof(REAL));
            if(nbytes != (unsigned)(P0_BASIS * sizeof(REAL)))
                error_handler("read_data", "Unexpected end of file");
    
            /* Wavefunctions */
            sp = states;
            for(kpt = 0;kpt < ct.num_kpts;kpt++) {
              
              for(state = 0;state < ct.num_states;state++) {
                
                size = P0_BASIS;
                work1 = NULL;
                if(!GAMMA_PT) {
                  size *= 2;
                  work1 = work + P0_BASIS;
                }
    #if (MACHINE_TYPE == PARALLEL_SMP)
                nbytes = read(fhand, work, size * sizeof(REAL));
                scatter_psi(work, work1, sp, 0);
    #else
                nbytes = read(fhand, sp->psiR, size * sizeof(REAL));
    #endif
                
                if(nbytes != (unsigned)(size * sizeof(REAL)))
                  error_handler("read_data", "Unexpected end of file");
                
                sp++;
                
              } /* end for state */
              /*  for calculating band structures, 
                  only read-in one wave function */
              if(ct.forceflag == 8) return;
            } /* end for kpt */
            
            /* Read current ionic Cartesian positions from the file */
            for(ion = 0;ion < ct.num_ions;ion++) {
    
                nbytes = read(fhand, &temp_pos[0], 3*sizeof(REAL));
                if(nbytes != 3*sizeof(REAL))
                    error_handler("read_data", "Unexpected end of file");
    
                if (ct.override_atoms != 1){
                  for (i = 0; i< 3; i++){
                    ct.ions[ion].crds[i] = temp_pos[i];
                  } /* i */
                } /* end if "override" */
    
            } /* end for */
    
            /* Read current ionic Crystal positions from the file */
            for(ion = 0;ion < ct.num_ions;ion++) {
    
                nbytes = read(fhand, &temp_pos[0], 3*sizeof(REAL));
                if(nbytes != 3*sizeof(REAL))
                    error_handler("read_data", "Unexpected end of file");
    
                if (ct.override_atoms != 1){
                  for (i = 0; i< 3; i++){
                    ct.ions[ion].xtal[i] = temp_pos[i];
                  } /* i */
                } /* end if "override" */
    
                if(ct.ions[ion].xtal[0] < 0.0) ct.ions[ion].xtal[0] += 1.0;
                if(ct.ions[ion].xtal[0] > 1.0) ct.ions[ion].xtal[0] -= 1.0;
                if(ct.ions[ion].xtal[1] < 0.0) ct.ions[ion].xtal[1] += 1.0;
                if(ct.ions[ion].xtal[1] > 1.0) ct.ions[ion].xtal[1] -= 1.0;
                if(ct.ions[ion].xtal[2] < 0.0) ct.ions[ion].xtal[2] += 1.0;
                if(ct.ions[ion].xtal[2] > 1.0) ct.ions[ion].xtal[2] -= 1.0;
                to_cartesian(ct.ions[ion].xtal, ct.ions[ion].crds);
    
            } /* end for */
    
            /* If constrained dynamics is on and you want to overwrite
               the initial positions */
    
                
    
            /* Read initial ionic Cartesian positions from the file */
            for(ion = 0;ion < ct.num_ions;ion++) {
    
                nbytes = read(fhand, &ct.ions[ion].icrds[0], 3*sizeof(REAL));
                if(nbytes != 3*sizeof(REAL))
                    error_handler("read_data", "Unexpected end of file");
    
                if (ct.forceflag==5) {
                  if ((ct.override_atoms==1 ||ct.override_atoms==2)) {
                    for (i = 0; i< 3; i++){
                      ct.ions[ion].icrds[i] = ct.ions[ion].crds[i];
                    } /* end for */
                  } /* end if */
                } /* end if */
    
            } /* end for */
    
    
            /* Read initial ionic Crystal positions from the file */
            for(ion = 0;ion < ct.num_ions;ion++) {
    
                nbytes = read(fhand, &ct.ions[ion].ixtal[0], 3*sizeof(REAL));
                if(nbytes != 3*sizeof(REAL))
                    error_handler("read_data", "Unexpected end of file");
    
                if (ct.forceflag==5) {
                  if ((ct.override_atoms==1 ||ct.override_atoms==2)) {
                    for (i = 0; i< 3; i++){
                      ct.ions[ion].ixtal[i] = ct.ions[ion].xtal[i];
                    } /* end for */
                  } /* end if */
                } /* end if */
    
            } /* end for */
    
    
            /* Read ionic velocities from the file */
            for(ion = 0;ion < ct.num_ions;ion++) {
    
                nbytes = read(fhand, &ct.ions[ion].velocity[0], 3*sizeof(REAL));
                if(nbytes != 3*sizeof(REAL))
                    error_handler("read_data", "Unexpected end of file");
    
            } /* end for */
    
            /* Read forces pointer from the file */
            read(fhand, &ct.fpt[0], 4*sizeof(int));
    
            /* Read ionic forces from the file */
            flag = 0;
            for(ion = 0;ion < ct.num_ions;ion++) {
    
                nbytes = read(fhand, &ct.ions[ion].force[0][0], 3*4*sizeof(REAL));
                if(nbytes != 3*4*sizeof(REAL)) {
                    flag = 1;
                    for (ic = 0; ic < 4; ic ++) {
                       ct.ions[ion].force[ic][0]=0.0;
                       ct.ions[ion].force[ic][1]=0.0;
                       ct.ions[ion].force[ic][2]=0.0;
                    }
                }
    
            } /* end for */
            if(pct.thispe == 0 && flag) {
               printf("\nWARNING: No previous forces - initializing forces to zero");
               fflush(NULL);
            }
    
            /* Read Nose positions,velocities, masses and forces from the file */
            flag = 0;
            nbytes = read(fhand, &ct.nose.xx[0], 10*sizeof(REAL));
            if (nbytes != 10*sizeof(REAL)) flag = 1;
            nbytes = read(fhand, &ct.nose.xv[0], 10*sizeof(REAL));
            if (nbytes != 10*sizeof(REAL)) flag = 1;
            nbytes = read(fhand, &ct.nose.xq[0], 10*sizeof(REAL));
            if (nbytes != 10*sizeof(REAL)) flag = 1;
            nbytes = read(fhand, &ct.nose.xf[0][0], 10*4*sizeof(REAL));
            if (nbytes != 10*4*sizeof(REAL)) flag = 1;
            if(pct.thispe == 0 && flag) {
               printf("\nWARNING: No previous Nose vars - initializing Nose vars to zero");
               fflush(NULL);
               for (i=0;i<10;i++) {
                  ct.nose.xx[i] = 0.0;
                  ct.nose.xv[i] = 0.0;
                  ct.nose.xq[i] = 0.0;
                  ct.nose.xf[0][i] = 0.0;
                  ct.nose.xf[1][i] = 0.0;
                  ct.nose.xf[2][i] = 0.0;
                  ct.nose.xf[3][i] = 0.0;
               }
            }
    
    
            /* Occupations */
            sp = states;
            for(kpt = 0;kpt < ct.num_kpts;kpt++) {
              for(state = 0;state < ct.num_states;state++) {
                
                nbytes = read(fhand, &temp_occ, sizeof(REAL));          
                if(nbytes != sizeof(REAL))
                  error_handler("read_data", "Unexpected end of file");
                
                if (ct.override_occ != 1)
                  sp->occupation = temp_occ;
                
                sp++;
                
              } /* end for state */
            } /* end for kpt */
            
    
            close(fhand);
    
    
        /* Free memory */
        release_mem(work);
    
    
    } /* end read_data */