gimme-alpha 0.1

nextnano_wavefunction_conversion.c File Reference

#include <math.h>
#include <stdio.h>
#include <libnextnano/nextnano_wavefunction_conversion.h>
#include <libmodeling/wavefunction.h>
#include <libcommon/gcc_hints.h>
Include dependency graph for nextnano_wavefunction_conversion.c:

Go to the source code of this file.

Defines

#define CLOSE_ENOUGH   1e-8
#define NEXTNANO_FIELD_TITLE_BUFFER_LEN   32
#define NEXTNANO_FILENAME_PART_BUFFER_LEN   32

Functions

static gint coordinate_density_sorter (gconstpointer a, gconstpointer b)
static gint approx_coordinate_density_sorter (gconstpointer a, gconstpointer b)
struct mstar_wavefunction_1dconvert_nextnano_mstar_wavefunction_to_general_1d (GList *wf, const char *xtitle, const char *real_title, const char *imaginary_title, const char *title_terminator, unsigned short int eigval)

Define Documentation

#define CLOSE_ENOUGH   1e-8

Definition at line 31 of file nextnano_wavefunction_conversion.c.

Referenced by approx_coordinate_density_sorter().

#define NEXTNANO_FIELD_TITLE_BUFFER_LEN   32
#define NEXTNANO_FILENAME_PART_BUFFER_LEN   32

Definition at line 38 of file nextnano_wavefunction_conversion.c.


Function Documentation

static gint approx_coordinate_density_sorter ( gconstpointer  a,
gconstpointer  b 
) [static]

Definition at line 57 of file nextnano_wavefunction_conversion.c.

References CLOSE_ENOUGH.

Referenced by convert_nextnano_mstar_wavefunction_to_general_1d().

                                                                               {
  double *c;
  double *d;
  if((c=g_hash_table_lookup((GHashTable*)a, "x")) == NULL) {
    if((d=g_hash_table_lookup((GHashTable*)b, "x")) == NULL) return 0;
    return -1;
  }else if((d=g_hash_table_lookup((GHashTable*)b, "x")) == NULL) {
    return 1;
  }
  //fprintf(stderr, "got x values c=%g(%p) and d=%g(%p) (a=%p,b=%p)\n", *c, c, *d, d, a, b);
  if(fabs(*c - *d) < fabs(CLOSE_ENOUGH*(*c))) return 0;
  if(*c < *d) return -1;
  if(*c > *d) return 1;
  return 0;
}

Here is the caller graph for this function:

struct mstar_wavefunction_1d* convert_nextnano_mstar_wavefunction_to_general_1d ( GList *  wf,
const char *  xtitle,
const char *  real_title,
const char *  imaginary_title,
const char *  title_terminator,
unsigned short int  eigval 
) [read]

Definition at line 73 of file nextnano_wavefunction_conversion.c.

References approx_coordinate_density_sorter(), mstar_wavefunction_1d_free(), mstar_wavefunction_1d_new(), NEXTNANO_FIELD_TITLE_BUFFER_LEN, mstar_wavefunction_1d::points, and unlikely.

Referenced by read_effectivemass_complex_wavefunction2().

                                                                                                                                                                                                                             {
  char rtitle[NEXTNANO_FIELD_TITLE_BUFFER_LEN];
  char ititle[NEXTNANO_FIELD_TITLE_BUFFER_LEN];
  snprintf(rtitle, NEXTNANO_FIELD_TITLE_BUFFER_LEN, "%s%03d%s", real_title, eigval, title_terminator);
  rtitle[NEXTNANO_FIELD_TITLE_BUFFER_LEN-1]='\0';
  snprintf(ititle, NEXTNANO_FIELD_TITLE_BUFFER_LEN, "%s%03d%s", imaginary_title, eigval, title_terminator);
  ititle[NEXTNANO_FIELD_TITLE_BUFFER_LEN-1]='\0';
  struct mstar_wavefunction_1d* wavefunc;
  if(unlikely((wavefunc = mstar_wavefunction_1d_new(g_list_length(wf))) == NULL)) {
    return NULL;
  }
  register int i;
  GList *l;
  double *v;
  /*We make a copy because we don't want to modify the calling wavefuntion.*/
  GList *m = g_list_sort(g_list_copy(wf), approx_coordinate_density_sorter);
  for(i=0, l=g_list_first(m); l != NULL; i++, l=g_list_next(l)) {
    if(unlikely((v = g_hash_table_lookup((GHashTable*)(l->data), xtitle)) == NULL)) {
      fprintf(stderr, "convert_netnano_mstar_wavefunction_to_general_1d: INTERNAL ERROR: a wavefunction's x coordinate (i=%d; title=\"%s\") was NULL!\n", i, xtitle);
      g_list_free(m);
      mstar_wavefunction_1d_free(wavefunc);
      return NULL;
    }
    ((wavefunc->points)[i]).x = *v;
    if(unlikely((v = g_hash_table_lookup((GHashTable*)(l->data), rtitle)) == NULL)) {
      fprintf(stderr, "convert_netnano_mstar_wavefunction_to_general_1d: INTERNAL ERROR: a wavefunction's real value (i=%d; title=\"%s\") was NULL!\n", i, rtitle);
      g_list_free(m);
      mstar_wavefunction_1d_free(wavefunc);
      return NULL;
    }
    ((wavefunc->points)[i]).re = *v;
    if(unlikely((v = g_hash_table_lookup((GHashTable*)(l->data), ititle)) == NULL)) {
      fprintf(stderr, "convert_netnano_mstar_wavefunction_to_general_1d: INTERNAL ERROR: a wavefunction's imaginary value (i=%d; title=\"%s\") was NULL!\n", i, ititle);
      g_list_free(m);
      mstar_wavefunction_1d_free(wavefunc);
      return NULL;
    }
    ((wavefunc->points)[i]).im = *v;
  }
  g_list_free(g_list_first(m));
  return wavefunc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static gint coordinate_density_sorter ( gconstpointer  a,
gconstpointer  b 
) [static]

Definition at line 42 of file nextnano_wavefunction_conversion.c.

                                                                        {
  double *c;
  double *d;
  if((c=g_hash_table_lookup((GHashTable*)a, "x")) == NULL) {
    if((d=g_hash_table_lookup((GHashTable*)b, "x")) == NULL) return 0;
    return -1;
  }else if((d=g_hash_table_lookup((GHashTable*)b, "x")) == NULL) {
    return 1;
  }
  if(*c < *d) return -1;
  if(*c > *d) return 1;
  return 0;
}
 All Classes Files Functions Variables Enumerations Enumerator Defines