k-dot-p 0.1

kdotp::libmodelxx::structure::material Class Reference

#include <material.h++>

List of all members.

Public Member Functions

 material (const struct matdb *mdb, const char *mat1, const char *mat2, double x)
char * get_name ()
double get_property (const char *ppt, int *err)
double get_property (int ppt)
int get_property_index (const char *ppt, int *err)
bool operator== (const material &m2)
bool operator!= (const material &m2)
bool lenient_equals (const material &m2, double tolerance=1e-10)

Public Attributes

char * matname1
char * matname2
double m_x
double * indexed_properties
GHashTable * property_indices
GHashTable * properties

Private Member Functions

 material ()

Detailed Description

Definition at line 35 of file material.h++.


Constructor & Destructor Documentation

kdotp::libmodelxx::structure::material::material ( const struct matdb mdb,
const char *  mat1,
const char *  mat2,
double  x 
)

Definition at line 55 of file material.c++.

References kdotp::libmodelxx::structure::get_material(), kdotp::libmodelxx::structure::index_properties(), indexed_properties, m_x, matname1, matname2, properties, and property_indices.

                                                                                              {
  properties = get_material(mdb, mat1, mat2, x);
  /*Kick out if the material specified doesn't exist.*/
  if(properties == NULL) {
    fprintf(stderr, "ERROR in material consturctor: unable to get properties for material: %s/%g/%s\n", mat1, x, mat2); 
    return;
  }
  int ptsize = g_hash_table_size(properties);
  indexed_properties = (double*)malloc(ptsize*sizeof(double));
  property_indices = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
  struct index_struct idxs = {indexed_properties, property_indices, 0};
  /*Now we go ahead and set up the indexed hash*/
  //g_hash_table_foreach(properties, print_property, NULL);
  if(properties == NULL) {
    fprintf(stderr, "material::material: properties is NULL!\n");
  }
  if(property_indices == NULL) {
    fprintf(stderr, "material::material: property_indices is NULL!\n");
  }
  g_hash_table_foreach(properties, index_properties, &idxs);
  //g_hash_table_foreach(properties, print_property, NULL);
  matname1 = g_strdup(mat1);
  matname2 = g_strdup(mat2);
  m_x = x;
      }

Here is the call graph for this function:

kdotp::libmodelxx::structure::material::material ( ) [inline, private]

Definition at line 71 of file material.h++.

{}

Member Function Documentation

char * kdotp::libmodelxx::structure::material::get_name ( )

Definition at line 110 of file material.c++.

References kdp::constants::c, m_x, matname1, and matname2.

Referenced by kdotp::libkdotp::hamiltonian::cartesian_8band::cartesian_8band(), and kdotp::libkdotp::hamiltonian::store_reduced_material_parameters().

                               {
  GString* s = g_string_new("");
  if(matname2 != NULL) {
    g_string_printf(s, "%s(%f)%s", matname1, m_x, matname2);
  }else{
    g_string_printf(s, "%s", matname1);
  }
  char *c = s->str;
  g_string_free(s, FALSE);
  return c;
      }

Here is the caller graph for this function:

double kdotp::libmodelxx::structure::material::get_property ( const char *  ppt,
int *  err 
)

Gets a property for this material. If you need speed, use the int version.

Parameters:
pptproperty name
errpointer to int to store the error code
Returns:
the property, or NaN if lookup failed
Note:
error values are 0 for success, and 1 for failure to find the property

Definition at line 81 of file material.c++.

References properties.

Referenced by kdotp::libkdotp::hamiltonian::cartesian_8band::cartesian_8band(), kdotp::libkdotp::hamiltonian::cartesian_effective_mass::cartesian_effective_mass(), and kdotp::libkdotp::hamiltonian::store_reduced_material_parameters().

                                                             {
  //fprintf(stderr, "Looking up property %s: ", ppt);
  if(properties == NULL) {
    fprintf(stderr, "Error getting property %s: properties is NULL!!\n", ppt);
    return nan("NaN");
  }
  double* match = (double*)g_hash_table_lookup(properties, ppt);
  if(match == NULL) {
    //fprintf(stderr, "FAILED\n");
    *err = 1;
    return nan("NaN");
  }
  //fprintf(stderr, "%g\n", *match);
  *err = 0; 
  return *match;
      }

Here is the caller graph for this function:

double kdotp::libmodelxx::structure::material::get_property ( int  ppt) [inline]

Definition at line 50 of file material.h++.

References indexed_properties.

{return indexed_properties[ppt];}
int kdotp::libmodelxx::structure::material::get_property_index ( const char *  ppt,
int *  err 
)

Definition at line 99 of file material.c++.

References property_indices.

                                                                {
  if(property_indices == NULL) {
    return -2;
  }
  int* i = (int*)g_hash_table_lookup(property_indices, ppt);
  if(i == NULL) {*err = 1; return -1;}
  *err = 0;
  return *i;
      }
bool kdotp::libmodelxx::structure::material::lenient_equals ( const material m2,
double  tolerance = 1e-10 
)

compares two materials like the operator, but uses a tolerance to compare the percentage of material1.

Definition at line 142 of file material.c++.

References m_x, matname1, and matname2.

                                                                        {
  if(g_strcmp0(matname1, m2.matname1)) return false;
  if(g_strcmp0(matname2, m2.matname2)) return false;
  if(fabs(m_x - m2.m_x) > fabs(tolerance*m_x)) return false;
  return fabs(m_x - m2.m_x) < fabs(tolerance*m2.m_x);
      }
bool kdotp::libmodelxx::structure::material::operator!= ( const material m2)

Definition at line 137 of file material.c++.

References m_x, matname1, and matname2.

                                                  {
  if(!(g_strcmp0(matname1, m2.matname1))) return true;
  if(!(g_strcmp0(matname2, m2.matname2))) return true;
  return m_x != m2.m_x;
      }
bool kdotp::libmodelxx::structure::material::operator== ( const material m2)

comparison operator for material classes

Note:
compares string-wise matnames, and directly (i.e. ==)
use lenient-compare if you want to specify a tolerance

Definition at line 127 of file material.c++.

References m_x, matname1, and matname2.

                                                  {
  if(g_strcmp0(matname1, m2.matname1)) return false;
  if(g_strcmp0(matname2, m2.matname2)) return false;
  return m_x == m2.m_x;
      }

Member Data Documentation

Definition at line 60 of file material.h++.

Referenced by get_property(), and material().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines