funkalicious 0.1

func_sum.c

Go to the documentation of this file.
00001 /*
00002  *func_sum
00003  *Outputs the sum of a wavefunction's probability.
00004  
00005     Copyright (C) 2009 Joseph Pingenot
00006 
00007     This program is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU Affero General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU Affero General Public License for more details.
00016 
00017     You should have received a copy of the GNU Affero General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 
00020 */
00021 
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <glib-2.0/glib.h>
00026 #include <libdotcode/function_parser.h>
00027 #include "config.h"
00028 #include "common.h"
00029 
00030 #define EV_PER_HARTREE 27.2113834
00031 #define NM_PER_BOHR 0.05291772083
00032 
00033 /*This many gridsites in*/
00034 #define INSET 10
00035 
00036 int main(int argv, char* argc[]) {
00037   g_type_init();
00038   int i;
00039   struct wavefunc_header header;
00040   double *matrix;
00041   int err;
00042   int retval;
00043   /*probability of being within the specified region*/
00044   double prob;
00045   int x, y, z, band;
00046   double re, im;
00047   /*TOTAL sum*/
00048   double tsum;
00049   if(argv == 1) {
00050     fprintf(stderr, "Umm, you probably want to pass me a file or space-separated list of files to read.\n");
00051     exit(1);
00052   }
00053   for(i=1; i<argv; i++) {
00054     retval = read_wavefunction(argc[i], &header, &matrix, &err);
00055     if(retval != 0) {
00056       fprintf(stderr, "ERROR: read_wavefunction returned %d, err=%d (%s).\n", retval, err, strerror(err));
00057     }
00058     tsum=prob=0;
00059     for(z=0; z<header.Nz; ++z) {
00060       for(y=0; y<header.Ny; ++y) {
00061   for(x=0; x<header.Nx; ++x) {
00062     for(band=0; band<header.Nc; ++band) {
00063       re = matrix[band*2 + x*header.Nc*2 + y*header.Nx*header.Nc*2 + z*header.Ny*header.Nx*header.Nc*2];
00064       im = matrix[1 + band*2 + x*header.Nc*2 + y*header.Nx*header.Nc*2 + z*header.Ny*header.Nx*header.Nc*2];
00065       #ifdef DEBUG
00066       fprintf(stderr, "x=%d,y=%d,z=%d,b=%d: %g + i%g\n", x, y, z, band, re, im);
00067       #endif
00068       tsum += re*re + (im*im);
00069       if(
00070          (x < INSET) || ((header.Nx-x-1) < INSET)
00071          || (y < INSET) || ((header.Ny-y-1) < INSET)
00072          || (z < INSET) || ((header.Nz-z-1) < INSET)
00073          ){ 
00074         prob += re*re + (im*im);
00075       }
00076     }
00077   }
00078       }
00079     }
00080     printf("%s\t%g\n", argc[i], prob);
00081   }
00082   exit(0);
00083 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines