CCEX-1.0.0
Loading...
Searching...
No Matches
utilities.h
1#ifndef __CCEX_UTILITIES_UTILITIES_H_
2#define __CCEX_UTILITIES_UTILITIES_H_
3
4#include <Eigen/Dense>
5#include <iostream>
6#include <mpi.h>
7#include <unistd.h>
8
9#define EIGEN_USE_MKL_ALL
10#define _USE_MATH_DEFINES
11
12/* MPI Global variable ------------------------------------------*/
13extern int rank;
14extern int nprocess;
16
17/* Print Global variable ----------------------------------------*/
18extern bool verbosity;
20
21/* Data Types ---------------------------------------------------*/
28typedef struct {
29 double real;
30 double imag;
32
37typedef struct {
38 double xx, xy, xz;
39 double yx, yy, yz;
40 double zx, zy, zz;
42
43/* Eigen Library ------------------------------------------------*/
48typedef std::complex<double>doublec;
49
54typedef Eigen::Matrix<doublec, Eigen::Dynamic, Eigen::Dynamic> MatrixXcd;
55
60using namespace Eigen;
61
62
63/* Math Constants -----------------------------------------------*/
64// Planck constant : 1.054 571 729 x 10^-34 [J*s]
65// H_BAR is the unit conversion constant (Not the Planck constant)
66#define H_BAR 1.054571729
67
68// Unit conversion
69#define MHZ_TO_RADKHZ(x) (1 * (2.0 * M_PI * 1.0e+3) * x)
70#define RADKHZ_TO_MHZ(x) (1 / (2.0 * M_PI * 1.0e+3) * x)
71#define KHZ_TO_RADKHZ(x) (1 * (2.0 * M_PI) * x)
72#define RADKHZ_TO_KHZ(x) (1 / (2.0 * M_PI) * x)
73
74// Gyromagnetic ratio of electron spin [radkHz/G]
75#define GAMMA_ELECTRON -17608.597050;
76
77/* File Constants -----------------------------------------------*/
78#define MAX_FILEPATH 500
79
80/* cce.in line constants ----------------------------------------*/
81#define MAX_OPTION_ARRAY_LENGTH 500
82#define MAX_OPTION_ELEMENT_LENGTH 50
83#define MAX_CHARARRAY_LENGTH 20
84
85#define MAX_MAINTAG_SUBOPTION_NUMBER 500
86#define MAX_MAINTAG_SUBOPTION_LINE_LENGTH 1000
87
88
89/* utils -------------------------------------------------------*/
90double* MatrixXcdToDouble1d(MatrixXcd mat);
91MatrixXcd Double1dToMatrixXcd(double* val, int n);
92int Double_is_same_row(double* row1, double* row2);
93
94/* math functions -----------------------------------------------*/
95
96// geometry
97double dist(double spin1[],double spin2[]);
98double cosTheta(double spin1[], double spin2[],double dist);
99double sinTheta(double spin1[], double spin2[], double dist);
100double cosPhi(double spin1[], double spin2[]);
101double sinPhi(double spin1[], double spin2[]);
102
103/* Physics functions --------------------------------------------*/
104
105// spin state control
106float* substates(float S);
107bool isSubLevel(float S, float ms);
108MatrixXcd getSpinor(float S, float ms);
109MatrixXcd kron(MatrixXcd a, MatrixXcd b);
110MatrixXcd partialtrace(MatrixXcd Mij, int dimrow, int dimcol);
111double calNorm(MatrixXcd m);
112int normalize(MatrixXcd* m);
113float findZbasisSubLevel(MatrixXcd spinor);
114
115MatrixXcd powMatrixXcdElementWise(MatrixXcd a, int n);
116MatrixXcd mulMatrixXcdElementWise(MatrixXcd a, MatrixXcd b);
117
118/* Easy print ---------------------------------------------------*/
119void printInlineMatrixXcd(char* key, MatrixXcd mat);
120void printStateInDiracNot(char* key, MatrixXcd mat);
121void printStructElementChar(char* key,char* val);
122void printStructElementChar2d(char* key, char** val, int n);
123void printStructElementInt(char* key, int val);
124void printStructElementInt1dIdx(char* key, int* val, int n);
125void printStructElementFloat(char* key, float val);
126void printStructElementFloat1d(char* key, float* val, int n);
127void printStructElementDouble(char* key, double val);
128void printStructElementDouble1d(char* key, double* val, int n);
129void printStructElementBool(char* key, bool val);
130void printLine();
131void printLineSection();
132void printTitle(char* title);
133void printSubTitle(char* title);
134void printMessage(char* message);
135
136/* Find index ---------------------------------------------------*/
137int findIndexInt(int* array, int ista, int iend, int val); // find in the range of ista <= i <= iend
138int findIndexCharFix(char array[][MAX_CHARARRAY_LENGTH], int ista, int iend, char* val); // find in the range of ista <= i <= iend, strcasecmp
139int findIndexChar(char** array, int ista, int iend, char* val); // find in the range of ista <= i <= iend, strcasecmp
140int findIndexFloat(float* array, int ista, int iend, float val); // find in the range of ista <= i <= iend
141
142/* Type checker ---------------------------------------------------*/
143int isStringDouble(char *s);
144
145/* Quick Sort --------------------------------------------------*/
146void QuickSort(int** d_Array, int left, int right);
147int Partition(int** d_Array, int left, int right);
148void Swap(int** d_Array, int a, int b);
149
150/* MPI ---------------------------------------------------------*/
151void para_range(int n1,int n2, int nprocs, int myrank, int*ista, int *iend);
152int min(int x, int y);
153int*** MPI_getLocalClusters(int order, int*** clusters);
154// MatrixXcd* MPI_reduceLocalResult(int nstep, MatrixXcd* local);
155
156/* Print help and banner ---------------------------------------------------------*/
157void printBanner();
158void printHelp();
159
160#endif // __CCEX_UTILITIES_UTILITIES_H_
161
162
Eigen namespace.
Complex number with double precision.
Definition utilities.h:28
double real
Definition utilities.h:29
double imag
Definition utilities.h:30
Tensor with double precision.
Definition utilities.h:37
double yz
Definition utilities.h:39
double xz
Definition utilities.h:38
double zz
Definition utilities.h:40