// -*- C++ -*-
// $RCSfile: hexmaterial.C,v $
// $Revision: 1.5 $
// $Author: langer $
// $Date: 2000/10/30 19:23:25 $


/* This software was produced by NIST, an agency of the U.S. government,
 * and by statute is not subject to copyright in the United States.
 * Recipients of this software assume all responsibilities associated
 * with its operation, modification and maintenance. However, to
 * facilitate maintenance we ask that before distributing modifed
 * versions of this software, you first contact the authors at
 * oof_manager@ctcms.nist.gov. 
 */


#include "materialcmd.h"
#include "hexmaterial.h"
#include "readbinary.h"

CharString HexMaterial::type("hexagonal");
MaterialTypeRegistration
    HexMaterial::reg("hexagonal", new MaterialCmd<HexMaterial>, 3.0);

float HexMaterial::c11_dflt(1.0);
float HexMaterial::c12_dflt(0.0);
float HexMaterial::c13_dflt(0.0);
float HexMaterial::c33_dflt(1.0);
float HexMaterial::c44_dflt(0.5);
float HexMaterial::alpha11_dflt(0.0);
float HexMaterial::alpha33_dflt(0.0);
#ifdef THERMAL
float HexMaterial::kappa11_dflt(0.0);
float HexMaterial::kappa33_dflt(0.0);
#endif // THERMAL
EulerAngle HexMaterial::orientation_dflt;

void HexMaterial::output(FILE* fp_goof,  unsigned char &flag,
			 int n1, int n2, int n3) const
{
    MaterialT::output(fp_goof, flag, n1, n2, n3);
    writebinary(fp_goof, float(orientation.alpha()));
    writebinary(fp_goof, float(orientation.beta()));
    writebinary(fp_goof, float(orientation.gamma()));
    writebinary(fp_goof, flag);
    writebinary(fp_goof, c11);
    writebinary(fp_goof, c12);
    writebinary(fp_goof, c13);
    writebinary(fp_goof, c33);
    writebinary(fp_goof, c44);
    writebinary(fp_goof, alpha11);
    writebinary(fp_goof, alpha33);
#ifdef THERMAL
    writebinary(fp_goof, kappa11);
    writebinary(fp_goof, kappa33);
#endif // THERMAL
}

void HexMaterial::output(FILE* fp_goof, unsigned char &flag,
			 int n1, int n2, int n3, int same_element) const
{
    MaterialT::output(fp_goof, flag, n1, n2, n3, same_element);
    writebinary(fp_goof, float(orientation.alpha()));
    writebinary(fp_goof, float(orientation.beta()));
    writebinary(fp_goof, float(orientation.gamma()));
    writebinary(fp_goof, flag);
    writebinary(fp_goof, same_element);
    writebinary(fp_goof, c11);
    writebinary(fp_goof, c12);
    writebinary(fp_goof, c13);
    writebinary(fp_goof, c33);
    writebinary(fp_goof, c44);
    writebinary(fp_goof, alpha11);
    writebinary(fp_goof, alpha33);
#ifdef THERMAL
    writebinary(fp_goof, kappa11);
    writebinary(fp_goof, kappa33);
#endif // THERMAL
}

int HexMaterial::compare(const Material *other) const {
  if(!MaterialT::compare(other)) return 0;
  HexMaterial *m2 = (HexMaterial*) other;
  if(c11 != m2->c11) return 0;
  if(c12 != m2->c12) return 0;
  if(c13 != m2->c13) return 0;
  if(c33 != m2->c33) return 0;
  if(c44 != m2->c44) return 0;
  if(alpha11 != m2->alpha11) return 0;
  if(alpha33 != m2->alpha33) return 0;
#ifdef THERMAL
  if(kappa11 != m2->kappa11) return 0;
  if(kappa33 != m2->kappa33) return 0;
#endif // THERMAL
  if(!(orientation == m2->orientation)) return 0;
  return 1;
}
