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

TABLE OF CONTENTS

  1. QMD-MGDFT/write_data.c

QMD-MGDFT/write_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 write_data(char *name, REAL *vh, REAL *rho, REAL *vxc, STATE *states)
   Writes the hartree potential, the wavefunctions, the 
   charge density and various other things to a file.
   This file is useful for re-run (ct.runflag =1)
INPUTS
   name: file name
   vh:  Hartree potential
   rho: total valence charge density
   vxc: exchange correlation potential
   states: points to orbital structure
OUTPUT
   write to a file 
PARENTS
   md.c
CHILDREN
   gather_psi.c 
SEE ALSO
   read_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"
    
    
    
    /* Writes the hartree potential, the wavefunctions, the */
    /* compensating charges and various other things to a file. */
    void write_data(char *name, REAL *vh, REAL *rho, REAL *vxc, STATE *states)
    {
        int fhand, amode, ion, size;
        int state, i1, kpt;
        STATE *sp;
        REAL *work, *work1;
        char newname[MAX_PATH+20];
    
    
        /* Wait until everyone gets here */
        my_barrier();
    
        /* On clusters with NFS mounted filesystems having all nodes
         * dump there data at the same time can cause network congestion
         * and hangups so if wait_flag is set in the input file the
         * total bandwidth going to disk is throttled */
        if(ct.wait_flag) sleep(ct.wait_flag * pct.thispe);
    
        /* Make the new output file name */
        sprintf(newname, "%s%d", name, pct.thispe);
    
        /* Get a temporary buffer */
        work = get_mem(2*P0_BASIS);
        if(work == NULL)
            error_handler("write_data", "Out of memory");
    
    
        amode = S_IREAD | S_IWRITE;
    
        fhand = open(newname, O_CREAT|O_TRUNC|O_RDWR, amode);
        if(fhand < 0) error_handler("write_data", " Unable to write file ");
    
    
        /* Some control information */
        write(fhand, &ct.nbasis, sizeof(int));
        write(fhand, &ct.num_states, sizeof(int));
    
        i1 = PE_X;
        write(fhand, &i1, sizeof(int));
        i1 = PE_Y;
        write(fhand, &i1, sizeof(int));
        i1 = PE_Z;
        write(fhand, &i1, sizeof(int));
        i1 = PHYS_PES;
        write(fhand, &i1, sizeof(int));
        i1 = P0_BASIS;
        write(fhand, &i1, sizeof(int));
    
    
        /* Dump the hartree potential */
        write(fhand, vh, P0_BASIS * sizeof(REAL));
    
        /* Density */
        write(fhand, rho, P0_BASIS * sizeof(REAL));
    
        /* Vxc */
        write(fhand, vxc, P0_BASIS * sizeof(REAL));
    
        /* 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;
              } /* end if */
    
    
    #if (MACHINE_TYPE == PARALLEL_SMP)
              gather_psi(work, work1, sp, 0);
              write(fhand, work, size * sizeof(REAL));
    #else
              write(fhand, sp->psiR, size * sizeof(REAL));
    #endif
    
              sp++;
    
          } /* end for */
        } /* end for */
    
    
        /* Write current ionic Cartesian positions to the file */
        for(ion = 0;ion < ct.num_ions;ion++)
            write(fhand, &ct.ions[ion].crds[0], 3*sizeof(REAL));
    
    
        /* Write current ionic Crystal positions to the file */
        for(ion = 0;ion < ct.num_ions;ion++)
            write(fhand, &ct.ions[ion].xtal[0], 3*sizeof(REAL));
    
    
        /* Write original ionic Cartesian positions to the file */
        for(ion = 0;ion < ct.num_ions;ion++)
            write(fhand, &ct.ions[ion].icrds[0], 3*sizeof(REAL));
    
    
        /* Write original ionic Crystal positions to the file */
        for(ion = 0;ion < ct.num_ions;ion++)
                    write(fhand, &ct.ions[ion].ixtal[0], 3*sizeof(REAL));
    
    
        /* Write current ionic velocities to the file */
        for(ion = 0;ion < ct.num_ions;ion++)
                write(fhand, &ct.ions[ion].velocity[0], 3*sizeof(REAL));
    
    
        /* Write current ionic forces pointer array to the file */
        write(fhand, &ct.fpt[0], 4*sizeof(int));
    
    
        /* Write current ionic forces to the file */
        for(ion = 0;ion < ct.num_ions;ion++)
            write(fhand, &ct.ions[ion].force[0][0], 3*4*sizeof(REAL));
    
    
        /* Write Nose positions,velocities, masses and forces to the file */
        write(fhand, &ct.nose.xx[0], 10*sizeof(REAL));
        write(fhand, &ct.nose.xv[0], 10*sizeof(REAL));
        write(fhand, &ct.nose.xq[0], 10*sizeof(REAL));
        write(fhand, &ct.nose.xf[0][0], 4*10*sizeof(REAL));
    
    
        /* Occupations */
        sp = states;
    
        for(kpt = 0; kpt <ct.num_kpts; kpt++){
          for(state = 0;state < ct.num_states;state++) {
            
            write(fhand, &sp->occupation, sizeof(REAL));
            sp++;
            
          } /* end for state */
        } /* end for kpt */
    
        close(fhand);
    
    
        /* Force change mode of output file */
        amode = S_IREAD | S_IWRITE;
        chmod(newname, amode);
    
        /* Release memory */
        release_mem(work);
    
    } /* end write_data */