sparse_pattern.h

Go to the documentation of this file.
00001 /* Ergo, version 3.2, a program for linear scaling electronic structure
00002  * calculations.
00003  * Copyright (C) 2012 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
00004  * 
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  * 
00018  * Primary academic reference:
00019  * Kohn−Sham Density Functional Theory Electronic Structure Calculations 
00020  * with Linearly Scaling Computational Time and Memory Usage,
00021  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
00022  * J. Chem. Theory Comput. 7, 340 (2011),
00023  * <http://dx.doi.org/10.1021/ct100611z>
00024  * 
00025  * For further information about Ergo, see <http://www.ergoscf.org>.
00026  */
00027 #if !defined(_DFT_SPARSE_PATTERN_H_)
00028 #define _DFT_SPARSE_PATTERN_H_ 1
00029 
00030 #if !defined(BEGIN_NAMESPACE)
00031 #define BEGIN_NAMESPACE(x) namespace x {
00032 #define END_NAMESPACE(x)   } /* x */
00033 #endif
00034 
00035 #include <vector>
00036 #include <stdio.h>
00037 
00038 #include "basisinfo.h"
00039 
00040 BEGIN_NAMESPACE(Dft)
00041 
00042 
00043 class SparsePattern {
00044  public:
00046   struct Interval {
00047     int lo, hi;
00048   Interval(int l_, int h_) : lo(l_), hi(h_){}
00049   };
00050   typedef std::vector<Interval> IntervalList;
00051   struct Column {
00052     IntervalList list;
00053 
00054     void addInterval(int lo, int hi);
00055     void addIntervals(int nIntervals, int (*intervals)[2]);
00056     struct Iterator {
00057       IntervalList::const_iterator current, end;
00058       int pos;
00059       Iterator(const IntervalList::const_iterator& beg,
00060                const IntervalList::const_iterator& end_, int p)
00061         : current(beg), end(end_), pos(p)
00062       {}
00063 
00064       Iterator& operator++() {
00065         ++pos;
00066 #if 0
00067         if(pos == current->hi)
00068           printf("Iterator increased to %d current limit %d last? %s %s\n",
00069                  pos, current->hi,
00070                  & *current == & *end ? "YES" : "NO",
00071                  current == end ? "YES" : "NO");
00072 #endif
00073         if(pos >= current->hi) {
00074           ++current;
00075           if(current != end)
00076             pos = current->lo; 
00077           else pos = 0;
00078         }
00079         return *this;
00080       }
00081       bool operator!=(const Iterator& other) const {
00082         bool res = !(& *current == & *other.current && pos == other.pos);
00083 #if 0
00084         printf("Iterator::operator!=() compares %p with %p, returns %s \n",
00085                & *current, & *other.current, res ? "TRUE" : "FALSE");
00086 #endif
00087         return res;
00088       }
00089       int operator*() const {
00090         //printf("Iterator::operator*() returns %d\n", pos);
00091         return pos;
00092       }
00093       const Interval* operator->() const {
00094         return &(*current);
00095       }
00096       
00097     };
00098 
00099     Iterator begin() const {
00100       IntervalList::const_iterator a = list.begin();
00101       IntervalList::const_iterator b = list.end();
00102       return Iterator(a, b, a != list.end() ? a->lo : 0);
00103     }
00104 
00105     Iterator end() const {
00106       return Iterator(list.end(),list.end(),0);
00107     }
00108 
00109     int size() const {
00110       int result = 0;
00111       for(IntervalList::const_iterator i = list.begin();
00112           i != list.end(); ++i)
00113         result += i->hi- i->lo;
00114       return result;
00115     }
00116   };
00117 
00118  private:
00119   const BasisInfoStruct& bis;
00120   Column *ranges;
00121  public:
00122  explicit SparsePattern(const BasisInfoStruct& bis_)
00123     : bis(bis_), ranges(new Column[bis_.noOfBasisFuncs])
00124     { }
00125     
00126     ~SparsePattern() {
00127       delete []ranges;
00128     }
00129 
00132     void add(int nRanges, const int (*range)[2]);
00133 
00134     void save(FILE *f) const;
00135     void load(FILE *f);
00136     const Column& operator[](int column) const {
00137       return ranges[column];
00138     }
00139 
00141     int getColumnSize(int col) const {
00142       return ranges[col].size();
00143     }
00144 
00146     int size() const {
00147       return bis.noOfBasisFuncs;
00148     }
00150     int sizeTotal() const;
00151 };
00152 
00153 void setupShellMap(const BasisInfoStruct& bis, int *shellMap, int *aoMap);
00154 
00155 END_NAMESPACE(Dft)
00156 
00157 #endif /* _DFT_SPARSE_PATTERN_H_ */

Generated on Wed Nov 21 09:32:32 2012 for ergo by  doxygen 1.4.7