/*
* p4vasp is a GUI-program and library for processing outputs of the
* Vienna Ab-inition Simulation Package (VASP)
* (see http://cms.mpi.univie.ac.at/vasp/Welcome.html)
*
* Copyright (C) 2003 Orest Dubay <odubay@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _MATH_H
#include <math.h>
#endif
#include <stdio.h>
#include <p4vasp/Exceptions.h>
double *createvec3d(double x,double y,double z){
double *v= new double [3];
v[0]=x;
v[1]=y;
v[2]=z;
return v;
}
void setvec3d(double *dest,double x,double y,double z){
dest[0]=x;
dest[1]=y;
dest[2]=z;
}
void deletevec3d(double *dest){
if (dest!=NULL){
delete dest;
dest=NULL;
}
}
double *createmat3d(double a11,double a12,double a13,
double a21,double a22,double a23,
double a31,double a32,double a33){
double *m = new double[9];
m[0]=a11;
m[1]=a12;
m[2]=a13;
m[3]=a21;
m[4]=a22;
m[5]=a23;
m[6]=a31;
m[7]=a32;
m[8]=a33;
return m;
}
void setmat3d(double *dest,
double a11,double a12,double a13,
double a21,double a22,double a23,
double a31,double a32,double a33){
dest[0]=a11;
dest[1]=a12;
dest[2]=a13;
dest[3]=a21;
dest[4]=a22;
dest[5]=a23;
dest[6]=a31;
dest[7]=a32;
dest[8]=a33;
}
void deletemat3d(double *dest){
if (dest!=NULL){
delete dest;
dest=NULL;
}
}
double getVecElement3d(double *dest, int i){
#if CHECK>0
if (dest==NULL){
NTHROW_NP_EXC("dest=NULL in getVecElement3d(dest,i)");
}
if ((i<0) || (i>=3)){
NTHROW_R_EXC("Index out of range in getVecElement3d(dest,i)",0,3,i);
}
#endif
return dest[i];
}
void setVecElement3d(double *dest, int i,double value){
#if CHECK>0
if (dest==NULL){
NTHROW_NP_EXC("dest=NULL in setVecElement3d(dest,i,value)");
}
if ((i<0) || (i>=3)){
NTHROW_R_EXC("Index out of range in setVecElement3d(dest,i,value)",0,3,i);
}
#endif
dest[i]=value;
}
double *getMatVecElement3d(double *m, int i){
#if CHECK>0
if (m==NULL){
NTHROW_NP_EXC("m=NULL in getMatVecElement3d(m,i)");
}
if ((i<0) || (i>=3)){
NTHROW_R_EXC("Index out of range in getMatVecElement3d(m,i)",0,3,i);
}
#endif
return &m[3*i];
}
void setMatVecElement3d(double *m, int i,double *v){
#if CHECK>0
if (m==NULL){
NTHROW_NP_EXC("m=NULL in setMatVecElement3d(m,i,value)");
}
if (v==NULL){
NTHROW_NP_EXC("value=NULL in setMatVecElement3d(m,i,value)");
}
if ((i<0) || (i>=3)){
NTHROW_R_EXC("Index out of range in setMatVecElement3d(m,i,value)",0,3,i);
}
#endif
m[3*i] =v[0];
m[3*i+1]=v[1];
m[3*i+2]=v[2];
}
double getMatElement3d(double *m, int i,int j){
#if CHECK>0
if (m==NULL){
NTHROW_NP_EXC("m=NULL in getMatElement3d(m,i,j)");
}
if ((i<0) || (i>=3)){
NTHROW_R_EXC("Index i out of range in getMatElement3d(m,i,j)",0,3,i);
}
if ((j<0) || (j>=3)){
NTHROW_R_EXC("Index j out of range in getMatElement3d(m,i,j)",0,3,j);
}
#endif
return m[3*i+j];
}
void setMatElement3d(double *m, int i,int j,double value){
#if CHECK>0
if (m==NULL){
NTHROW_NP_EXC("m=NULL in setMatElement3d(m,i,j,value)");
}
if ((i<0) || (i>=3)){
NTHROW_R_EXC("Index i out of range in setMatElement3d(m,i,j,value)",0,3,i);
}
if ((j<0) || (j>=3)){
NTHROW_R_EXC("Index j out of range in setMatElement3d(m,i,j,value)",0,3,j);
}
#endif
m[3*i+j]=value;
}
double *add3d(double *dest,double *a){
#if CHECK>0
if (dest==NULL){
NTHROW_NP_EXC("dest=NULL in add3d(dest,a)");
}
if (a==NULL){
NTHROW_NP_EXC("a=NULL in add3d(dest,a)");
}
#endif
dest[0]+=a[0];
dest[1]+=a[1];
dest[2]+=a[2];
return dest;
}
double *plus3d(double *dest,double *a,double *b){
#if CHECK>0
if (dest==NULL){
NTHROW_NP_EXC("dest=NULL in plus3d(dest,a,b)");
}
if (a==NULL){
NTHROW_NP_EXC("a=NULL in plus3d(dest,a,b)");
}
if (b==NULL){
NTHROW_NP_EXC("b=NULL in plus3d(dest,a,b)");
}
#endif
dest[0]=a[0]+b[0];
dest[1]=a[1]+b[1];
dest[2]=a[2]+b[2];
return dest;
}
double *createplus3d(double *a,double *b){
double *dest = new double[3];
#if CHECK>0
if (dest==NULL){
NTHROW_MA_EXC("dest allocation failed in createplus3d(a,b)");
}
if (a==NULL){
NTHROW_NP_EXC("a=NULL in createplus3d(a,b)");
}
if (b==NULL){
NTHROW_NP_EXC("b=NULL in createplus3d(a,b)");
}
#endif
dest[0]=a[0]+b[0];
dest[1]=a[1]+b[1];
dest[2]=a[2]+b[2];
return dest;
}
double *createplusmat3d(double *a,double *b){
double *dest = new double[9];
#if CHECK>0
if (dest==NULL){
NTHROW_MA_EXC("dest allocation failed in createplusmat3d(a,b)");
}
if (a==NULL){
NTHROW_NP_EXC("a=NULL in createplusmat3d(a,b)");
}
if (b==NULL){
NTHROW_NP_EXC("b=NULL in createplusmat3d(a,b)");
}
#endif
dest[0]=a[0]+b[0];
dest[1]=a[1]+b[1];
dest[2]=a[2]+b[2];
dest[3]=a[3]+b[3];
dest[4]=a[4]+b[4];
dest[5]=a[5]+b[5];
dest[6]=a[6]+b[6];
dest[7]=a[7]+b[7];
dest[8]=a[8]+b[8];
return dest;
}
double *sub3d(double *dest,double *a){
#if CHECK>0
if (dest==NULL){
NTHROW_NP_EXC("dest=NULL in sub3d(dest,a)");
}
if (a==NULL){
NTHROW_NP_EXC("a=NULL in sub3d(dest,a)");
}
#endif
dest[0]-=a[0];
dest[1]-=a[1];
dest[2]-=a[2];
return dest;
}
double *minus3d(double *dest,double *a,double *b){
#if CHECK>0
if (dest==NULL){
NTHROW_NP_EXC("dest=NULL in minus3d(dest,a,b)");
}
if (a==NULL){
NTHROW_NP_EXC("a=NULL in minus3d(dest,a,b)");
}
if (b==NULL){
NTHROW_NP_EXC("b=NULL in minus3d(dest,a,b)");
}
#endif
dest[0]=a[0]-b[0];
dest[1]=a[1]-b[1];
dest[2]=a[2]-b[2];
return dest;
}
double *createminus3d(double *a,double *b){
double *dest = new double[3];
#if CHECK>0
if (dest==NULL){
NTHROW_MA_EXC("dest allocation failed in createminus3d(a,b)");
}
if (a==NULL){
NTHROW_NP_EXC("a=NULL in createminus3d(a,b)");
}
if (b==NULL){
NTHROW_NP_EXC("b=NULL in createminus3d(a,b)");
}
#endif
dest[0]=a[0]-b[0];
dest[1]=a[1]-b[1];
dest[2]=a[2]-b[2];
return dest;
}
double *createminusmat3d(double *a,double *b){
double *dest = new double[9];
#if CHECK>0
if (dest==NULL){
NTHROW_MA_EXC("dest allocation failed in createminusmat3d(a,b)");
}
if (a==NULL){
NTHROW_NP_EXC("a=NULL in createminusmat3d(a,b)");
}
if (b==NULL){
NTHROW_NP_EXC("b=NULL in createminusmat3d(a,b)");
}
#endif
dest[0]=a[0]-b[0];
dest[1]=a[1]-b[1];
dest[2]=a[2]-b[2];
dest[3]=a[3]-b[3];
dest[4]=a[4]-b[4];
dest[5]=a[5]-b[5];
dest[6]=a[6]-b[6];
dest[7]=a[7]-b[7];
dest[8]=a[8]-b[8];
return dest;
}
double *createneg3d(double *v){
double *dest = new double[3];
#if CHECK>0
if (dest==NULL){
NTHROW_MA_EXC("dest allocation failed in createneg3d(v)");
}
if (v==NULL){
NTHROW_NP_EXC("createneg3d(NULL)");
}
#endif
dest[0]=-v[0];
dest[1]=-v[1];
dest[2]=-v[2];
return dest;
}
double *createnegmat3d(double *m){
double *dest = new double[9];
#if CHECK>0
if (dest==NULL){
NTHROW_MA_EXC("dest allocation failed in createnegmat3d(m)");
}
if (m==NULL){
NTHROW_NP_EXC("createnegmat3d(NULL)");
}
#endif
dest[0]=-m[0];
dest[1]=-m[1];
dest[2]=-m[2];
dest[3]=-m[3];