*** empty log message ***
This commit is contained in:
		
							parent
							
								
									57971235dd
								
							
						
					
					
						commit
						a80f82b6ee
					
				
							
								
								
									
										49
									
								
								diis.h
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								diis.h
									
									
									
									
									
								
							@ -16,7 +16,7 @@
 | 
				
			|||||||
// actually it can be anything what has operator=(const T&), clear(), dot() , axpy(), norm() and copyonwrite(), and LA_traits<T>::normtype and elementtype
 | 
					// actually it can be anything what has operator=(const T&), clear(), dot() , axpy(), norm() and copyonwrite(), and LA_traits<T>::normtype and elementtype
 | 
				
			||||||
// and get() and put() if external storage is requested
 | 
					// and get() and put() if external storage is requested
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename T>
 | 
					template<typename T, typename U>
 | 
				
			||||||
class DIIS
 | 
					class DIIS
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	int dim;
 | 
						int dim;
 | 
				
			||||||
@ -24,45 +24,48 @@ class DIIS
 | 
				
			|||||||
	bool incore;
 | 
						bool incore;
 | 
				
			||||||
	int cyclicshift; //circular buffer of last dim vectors
 | 
						int cyclicshift; //circular buffer of last dim vectors
 | 
				
			||||||
	typedef typename LA_traits<T>::elementtype Te;
 | 
						typedef typename LA_traits<T>::elementtype Te;
 | 
				
			||||||
	NRSMat<Te> bmat;
 | 
						typedef typename LA_traits<U>::elementtype Ue;
 | 
				
			||||||
	AuxStorage<Te> *st, *errst;
 | 
						NRSMat<Ue> bmat;
 | 
				
			||||||
	T *stor, *errstor;
 | 
						AuxStorage<Te> *st;
 | 
				
			||||||
 | 
						AuxStorage<Ue> *errst;
 | 
				
			||||||
 | 
						T *stor;
 | 
				
			||||||
 | 
						U *errstor;
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	DIIS() {dim=0; st=NULL; stor=NULL;}; //for array of diis
 | 
						DIIS() {dim=0; st=NULL; stor=NULL;}; //for array of diis
 | 
				
			||||||
	DIIS(const int n, const bool core=1);
 | 
						DIIS(const int n, const bool core=1);
 | 
				
			||||||
	void setup(const int n, const bool core=1);
 | 
						void setup(const int n, const bool core=1);
 | 
				
			||||||
	~DIIS();
 | 
						~DIIS();
 | 
				
			||||||
	typename LA_traits<T>::normtype extrapolate(T &vec, const T &errvec); //vec is input/output; returns square residual norm
 | 
						typename LA_traits<U>::normtype extrapolate(T &vec, const U &errvec); //vec is input/output; returns square residual norm
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename T>
 | 
					template<typename T, typename U>
 | 
				
			||||||
DIIS<T>::DIIS(const int n, const bool core) : dim(n), incore(core), bmat(n,n)
 | 
					DIIS<T,U>::DIIS(const int n, const bool core) : dim(n), incore(core), bmat(n,n)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
st=incore?NULL: new AuxStorage<Te>;
 | 
					st=incore?NULL: new AuxStorage<Te>;
 | 
				
			||||||
errst=incore?NULL: new AuxStorage<Te>;
 | 
					errst=incore?NULL: new AuxStorage<Ue>;
 | 
				
			||||||
stor= incore? new T[dim] : NULL;
 | 
					stor= incore? new T[dim] : NULL;
 | 
				
			||||||
errstor= incore? new T[dim] : NULL;
 | 
					errstor= incore? new U[dim] : NULL;
 | 
				
			||||||
bmat= (Te)0; for(int i=1; i<n; ++i) bmat(0,i) = (Te)-1; 
 | 
					bmat= (Ue)0; for(int i=1; i<n; ++i) bmat(0,i) = (Ue)-1; 
 | 
				
			||||||
aktdim=cyclicshift=0;
 | 
					aktdim=cyclicshift=0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename T>
 | 
					template<typename T, typename U>
 | 
				
			||||||
void DIIS<T>::setup(const int n, const bool core)
 | 
					void DIIS<T,U>::setup(const int n, const bool core)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
dim=n;
 | 
					dim=n;
 | 
				
			||||||
incore=core;
 | 
					incore=core;
 | 
				
			||||||
bmat.resize(n);
 | 
					bmat.resize(n);
 | 
				
			||||||
st=incore?NULL: new AuxStorage<Te>;
 | 
					st=incore?NULL: new AuxStorage<Te>;
 | 
				
			||||||
errst=incore?NULL: new AuxStorage<Te>;
 | 
					errst=incore?NULL: new AuxStorage<Ue>;
 | 
				
			||||||
stor= incore? new T[dim] : NULL;
 | 
					stor= incore? new T[dim] : NULL;
 | 
				
			||||||
errstor= incore? new T[dim] : NULL;
 | 
					errstor= incore? new U[dim] : NULL;
 | 
				
			||||||
bmat= (Te)0; for(int i=1; i<n; ++i) bmat(0,i) = (Te)-1;
 | 
					bmat= (Ue)0; for(int i=1; i<n; ++i) bmat(0,i) = (Ue)-1;
 | 
				
			||||||
aktdim=cyclicshift=0;
 | 
					aktdim=cyclicshift=0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename T>
 | 
					template<typename T, typename U>
 | 
				
			||||||
DIIS<T>::~DIIS()
 | 
					DIIS<T,U>::~DIIS()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
if(st) delete st;
 | 
					if(st) delete st;
 | 
				
			||||||
if(errst) delete errst;
 | 
					if(errst) delete errst;
 | 
				
			||||||
@ -72,8 +75,8 @@ if(errstor) delete[] errstor;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<typename T>
 | 
					template<typename T, typename U>
 | 
				
			||||||
typename LA_traits<T>::normtype DIIS<T>::extrapolate(T &vec, const T &errvec)
 | 
					typename LA_traits<U>::normtype DIIS<T,U>::extrapolate(T &vec, const U &errvec)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
if(!dim) laerror("attempt to extrapolate from uninitialized DIIS");
 | 
					if(!dim) laerror("attempt to extrapolate from uninitialized DIIS");
 | 
				
			||||||
//if dim exceeded, shift 
 | 
					//if dim exceeded, shift 
 | 
				
			||||||
@ -110,18 +113,18 @@ if(incore)
 | 
				
			|||||||
		bmat(i,aktdim-1)=errvec.dot(errstor[(i+cyclicshift)%dim]);
 | 
							bmat(i,aktdim-1)=errvec.dot(errstor[(i+cyclicshift)%dim]);
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	T tmp = vec; tmp.copyonwrite(); //copy dimensions
 | 
						U tmp = errvec; tmp.copyonwrite(); //copy dimensions
 | 
				
			||||||
	for(int i=1; i<aktdim-1; ++i) 
 | 
						for(int i=1; i<aktdim-1; ++i) 
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
		st->get(tmp,(i+cyclicshift)%dim);
 | 
							errst->get(tmp,(i+cyclicshift)%dim);
 | 
				
			||||||
		bmat(i,aktdim-1)= errvec.dot(tmp);
 | 
							bmat(i,aktdim-1)= errvec.dot(tmp);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//prepare rhs-solution vector
 | 
					//prepare rhs-solution vector
 | 
				
			||||||
NRVec<Te> rhs(dim);
 | 
					NRVec<Ue> rhs(dim);
 | 
				
			||||||
rhs= (Te)0; rhs[0]= (Te)-1;
 | 
					rhs= (Ue)0; rhs[0]= (Ue)-1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//solve for coefficients
 | 
					//solve for coefficients
 | 
				
			||||||
//@@@@@@ implement checking for bad condition number and eliminating old vectors
 | 
					//@@@@@@ implement checking for bad condition number and eliminating old vectors
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user