33 SymmInfo.setGroup(nGroup);
35 Isizes =
new int[SymmInfo.getNumberOfIrreps()];
36 storage =
new double*[SymmInfo.getNumberOfIrreps()];
38 for (
int cnt=0; cnt<SymmInfo.getNumberOfIrreps(); cnt++){
39 Isizes[cnt] = IrrepSizes[cnt];
40 if (Isizes[cnt]>0) storage[cnt] =
new double[Isizes[cnt]*(Isizes[cnt]+1)/2];
49 for (
int cnt=0; cnt<SymmInfo.getNumberOfIrreps(); cnt++)
if (Isizes[cnt]>0)
delete [] storage[cnt];
57 for (
int irrep = 0; irrep < SymmInfo.getNumberOfIrreps(); irrep++){
58 const int loopsize = (Isizes[irrep]*(Isizes[irrep]+1))/2;
59 for (
int count = 0; count < loopsize; count++){ storage[irrep][count] = 0.0; }
66 if (i>j) storage[irrep][j + i*(i+1)/2] = val;
67 else storage[irrep][i + j*(j+1)/2] = val;
73 if (i>j)
return storage[irrep][j + i*(i+1)/2];
74 return storage[irrep][i + j*(j+1)/2];
81 hid_t file_id = H5Fcreate(name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
84 hid_t group_id = H5Gcreate(file_id,
"/MetaData", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
87 hsize_t dimarray = SymmInfo.getNumberOfIrreps();
88 hid_t dataspace_id = H5Screate_simple(1, &dimarray, NULL);
89 hid_t dataset_id = H5Dcreate(group_id,
"IrrepSizes", H5T_STD_I32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
90 H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, Isizes);
93 hid_t attribute_space_id1 = H5Screate(H5S_SCALAR);
94 hid_t attribute_id1 = H5Acreate(dataset_id,
"nGroup", H5T_STD_I32LE, attribute_space_id1, H5P_DEFAULT, H5P_DEFAULT);
95 int nGroup = SymmInfo.getGroupNumber();
96 H5Awrite(attribute_id1, H5T_NATIVE_INT, &nGroup);
98 hid_t attribute_space_id2 = H5Screate(H5S_SCALAR);
99 hid_t attribute_id2 = H5Acreate(dataset_id,
"nIrreps", H5T_STD_I32LE, attribute_space_id2, H5P_DEFAULT, H5P_DEFAULT);
100 int nIrreps = SymmInfo.getNumberOfIrreps();
101 H5Awrite(attribute_id2, H5T_NATIVE_INT, &nIrreps);
103 H5Aclose(attribute_id1);
104 H5Aclose(attribute_id2);
105 H5Sclose(attribute_space_id1);
106 H5Sclose(attribute_space_id2);
108 H5Dclose(dataset_id);
109 H5Sclose(dataspace_id);
114 for (
int cnt=0; cnt<SymmInfo.getNumberOfIrreps(); cnt++){
118 std::stringstream sstream;
119 sstream <<
"/TwoIndex" << cnt ;
120 hid_t group_id3 = H5Gcreate(file_id, sstream.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
122 hsize_t dimarray3 = Isizes[cnt]*(Isizes[cnt]+1)/2;
123 hid_t dataspace_id3 = H5Screate_simple(1, &dimarray3, NULL);
124 hid_t dataset_id3 = H5Dcreate(group_id3,
"Matrix elements", H5T_IEEE_F64LE, dataspace_id3, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
125 H5Dwrite(dataset_id3, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, storage[cnt]);
127 H5Dclose(dataset_id3);
128 H5Sclose(dataspace_id3);
143 hid_t file_id = H5Fopen(name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
146 hid_t group_id = H5Gopen(file_id,
"/MetaData",H5P_DEFAULT);
149 hid_t dataset_id = H5Dopen(group_id,
"IrrepSizes", H5P_DEFAULT);
152 hid_t attribute_id1 = H5Aopen_by_name(group_id,
"IrrepSizes",
"nGroup", H5P_DEFAULT, H5P_DEFAULT);
154 H5Aread(attribute_id1, H5T_NATIVE_INT, &nGroup);
155 assert( nGroup==SymmInfo.getGroupNumber() );
157 hid_t attribute_id2 = H5Aopen_by_name(group_id,
"IrrepSizes",
"nIrreps", H5P_DEFAULT, H5P_DEFAULT);
159 H5Aread(attribute_id2, H5T_NATIVE_INT, &nIrreps);
160 assert( nIrreps==SymmInfo.getNumberOfIrreps() );
162 H5Aclose(attribute_id1);
163 H5Aclose(attribute_id2);
165 int * IsizesAgain =
new int[SymmInfo.getNumberOfIrreps()];
166 H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, IsizesAgain);
167 for (
int cnt=0; cnt<SymmInfo.getNumberOfIrreps(); cnt++){
168 assert( IsizesAgain[cnt]==Isizes[cnt] );
170 delete [] IsizesAgain;
171 H5Dclose(dataset_id);
176 for (
int cnt=0; cnt<SymmInfo.getNumberOfIrreps(); cnt++){
180 std::stringstream sstream;
181 sstream <<
"/TwoIndex" << cnt ;
182 hid_t group_id3 = H5Gopen(file_id, sstream.str().c_str(), H5P_DEFAULT);
184 hid_t dataset_id3 = H5Dopen(group_id3,
"Matrix elements", H5P_DEFAULT);
185 H5Dread(dataset_id3, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, storage[cnt]);
186 H5Dclose(dataset_id3);
void Clear()
Set all one-body matrix elements to zero.
virtual ~TwoIndex()
Destructor.
void read(const std::string name)
Load the TwoIndex object.
TwoIndex(const int nGroup, const int *IrrepSizes)
Constructor.
void set(const int irrep, const int i, const int j, const double val)
Set an element.
double get(const int irrep, const int i, const int j) const
Get an element.
void save(const std::string name) const
Save the TwoIndex object.