funkalicious 0.1

dotcode_wavefunction.c

Go to the documentation of this file.
00001 /**Provides basic routines for getting and using a dotcode wavefunction.
00002  
00003 
00004     Copyright (C) 2011 Joseph Pingenot
00005 
00006     This program is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU Affero General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU Affero General Public License for more details.
00015 
00016     You should have received a copy of the GNU Affero General Public License
00017     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 */
00020 
00021 #include <stdlib.h>
00022 #include <libdotcode/dotcode_wavefunction.h>
00023 
00024 /**
00025  *Gets the index into the storage member for a wavefunction, or for a density
00026  *\param x x index component
00027  *\param y y index component
00028  *\param z z index component
00029  *\param b band index component
00030  *\param im 1 if imaginary component is wanted; 0 else.
00031  *\param Nx Number of x sites
00032  *\param Ny Number of y sites
00033  *\param Nb Number of bands
00034  *\returns long unsigned int, which is the address in the storage
00035  *array.
00036  *\note there is no error checking, for speed purposes. E.g. if im is
00037  *3, it'll just be blindly used as a 3 and you'll be addressing the
00038  *imaginary component of the next index.
00039  *\note Nz is not needed.
00040  */
00041 hotfunc ___const ___always_inline long unsigned int get_wavefunction_storage_index(unsigned int x, unsigned int y, unsigned int z, unsigned int im, unsigned int b, unsigned int Nx, unsigned int Ny, int Nb) {
00042   return im + 2*(b + Nb*(x + Nx*(y + Ny*(z))));
00043 }
00044 ___const long unsigned int get_wavefunction_storage_index_(unsigned int x, unsigned y, unsigned z, unsigned im, unsigned b, unsigned Nx, unsigned Ny, unsigned Nb) {
00045   return get_wavefunction_storage_index(x, y, z, im, b, Nx, Ny, Nb);
00046 }
00047 
00048 hotfunc ___always_inline double* get_wavefunction_storage(unsigned int x, unsigned int y, unsigned int z, unsigned int im, unsigned int b, struct wavefunction* wf) {
00049   return &(wf->storage[get_wavefunction_storage_index(x, y, z, im, b, wf->N[0], wf->N[1], wf->bands)]);
00050 }
00051 double* get_wavefunction_storage_(unsigned int x, unsigned int y, unsigned int z, unsigned int im, unsigned int b, struct wavefunction* wf) {
00052   return get_wavefunction_storage(x, y, z, im, b, wf);
00053 }
00054 
00055 hotfunc ___always_inline const double* get_wavefunction_storage_c(unsigned int x, unsigned int y, unsigned int z, unsigned int im, unsigned int b, const struct wavefunction* wf) {
00056   return &(wf->storage[get_wavefunction_storage_index(x, y, z, im, b, wf->N[0], wf->N[1], wf->bands)]);
00057 }
00058 const double* get_wavefunction_storage_c_(unsigned int x, unsigned int y, unsigned int z, unsigned int im, unsigned int b, const struct wavefunction* wf) {
00059   return get_wavefunction_storage_c(x, y, z, im, b, wf);
00060 }
00061 
00062 struct density* dotcode_wavefunction_get_density_in_band(const struct wavefunction* wf, int band) { 
00063   if(band >= wf->bands) return NULL;
00064   unsigned x, y, z;
00065   double re, im;
00066   struct density* d = new_density(wf->N, wf->dx, 0.0);
00067   #ifdef OPENMP
00068   #pragma omp parallel for private(x, y, z, re, im)
00069   #endif
00070   for(z=0; z<wf->N[2]; ++z) {
00071     for(y=0; y<wf->N[1]; ++y) {
00072       for(x=0; x<wf->N[0]; ++x) {
00073   re = *get_wavefunction_storage_c(x, y, z, 0, band, wf);
00074   im = *get_wavefunction_storage_c(x, y, z, 1, band, wf);
00075   *get_density_storage_at_(x, y, z, d) = re*re + im*im;
00076       }
00077     }
00078   }
00079   return d;
00080 }
00081 
00082 void dotcode_wavefunction_free(struct wavefunction* wf) {
00083   dotcode_wavefunction_free_resources(wf);
00084   free(wf);
00085 }
00086 
00087 void dotcode_wavefunction_free_resources(struct wavefunction* wf) {
00088   g_object_unref(wf->file);
00089   free(wf->storage);
00090 }
00091 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines