25 #include "DMRGSCFmatrix.h" 26 #include "MPIchemps2.h" 36 for (
int irrep = 0; irrep <
num_irreps; irrep++ ){
37 const int NORB = iHandler->
getNORB( irrep );
38 entries[ irrep ] =
new double[ NORB * NORB ];
45 for (
int irrep = 0; irrep <
num_irreps; irrep++ ){
60 for (
int irrep = 0; irrep <
num_irreps; irrep++ ){
62 for (
int counter = 0; counter < size; counter++ ){
63 entries[ irrep ][ counter ] = 0.0;
72 for (
int irrep = 0; irrep <
num_irreps; irrep++ ){
74 for (
int diag = 0; diag < NORB; diag++ ){
75 entries[ irrep ][ ( NORB + 1 ) * diag ] = 1.0;
96 double rms_diff = 0.0;
97 for (
int irrep = 0; irrep <
num_irreps; irrep++ ){
99 for (
int row = 0; row < NORB; row++ ){
100 for (
int col = 0; col < NORB; col++ ){
101 const double diff = this->
get( irrep, row, col ) - other->
get( irrep, row, col );
102 rms_diff += diff * diff;
106 rms_diff = sqrt( rms_diff );
113 hid_t file_id = H5Fcreate( filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
114 hid_t group_id = H5Gcreate( file_id,
"/Data", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
116 for (
int irrep = 0; irrep < idx->
getNirreps(); irrep++ ){
118 std::stringstream irrepname;
119 irrepname <<
"irrep_" << irrep;
122 hid_t dataspace_id = H5Screate_simple( 1, &dimarray, NULL );
123 hid_t dataset_id = H5Dcreate( group_id, irrepname.str().c_str(), H5T_IEEE_F64LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
124 H5Dwrite( dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, storage[ irrep ] );
126 H5Dclose( dataset_id );
127 H5Sclose( dataspace_id );
131 H5Gclose( group_id );
138 hid_t file_id = H5Fopen( filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT );
139 hid_t group_id = H5Gopen( file_id,
"/Data", H5P_DEFAULT );
141 for (
int irrep = 0; irrep < n_irreps; irrep++ ){
143 std::stringstream irrepname;
144 irrepname <<
"irrep_" << irrep;
146 hid_t dataset_id = H5Dopen( group_id, irrepname.str().c_str(), H5P_DEFAULT );
147 H5Dread( dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, storage[ irrep ] );
149 H5Dclose( dataset_id );
153 H5Gclose( group_id );
158 #ifdef CHEMPS2_MPI_COMPILATION 159 void CheMPS2::DMRGSCFmatrix::broadcast(
const int ROOT ){
161 for (
int irrep = 0; irrep <
num_irreps; irrep++ ){
163 const int size = NORB * NORB;
165 MPIchemps2::broadcast_array_double(
entries[ irrep ], size, ROOT );
int getNORB(const int irrep) const
Get the number of orbitals for an irrep.
double * getBlock(const int irrep)
Get a matrix block.
const DMRGSCFindices * iHandler
The information on the occupied, active, and virtual spaces.
static void read(const string filename, const int n_irreps, double **storage)
Read the DMRGSCFmatrix from disk.
void set(const int irrep, const int p, const int q, const double val)
Set an element.
double ** entries
The matrix entries.
static void write(const string filename, const DMRGSCFindices *idx, double **storage)
Write a DMRGSCFmatrix to disk.
double rms_deviation(const DMRGSCFmatrix *other) const
Get the RMS deviation with another DMRGSCFmatrix.
double get(const int irrep, const int p, const int q) const
Get an element.
DMRGSCFmatrix(const DMRGSCFindices *iHandler)
Constructor.
int num_irreps
The number of irreps.
void identity()
Make this matrix the identity matrix.
void clear()
Clear the matrix.
virtual ~DMRGSCFmatrix()
Destructor.
int getNirreps() const
Get the number of irreps.