From a17ec1fd83b3c63eeb52aa67dc4d19711e3370ac Mon Sep 17 00:00:00 2001
From: Baptiste Mouginot <mouginot.baptiste@gmail.com>
Date: Tue, 14 Jan 2014 11:40:38 +0000
Subject: [PATCH] many speed improvement and memory gestion

git-svn-id: svn+ssh://svn.in2p3.fr/class@174 0e7d625b-0364-4367-a6be-d5be4a48d228
---
 source/trunk/include/CLSSFacility.hxx     |   4 +-
 source/trunk/include/CLSSObject.hxx       |   1 -
 source/trunk/include/DataBank.hxx         |   2 +-
 source/trunk/include/EvolutionData.hxx    |   3 +
 source/trunk/include/FabricationPlant.hxx |   1 -
 source/trunk/include/Pool.hxx             |   3 +-
 source/trunk/include/ZAI.hxx              |   4 +-
 source/trunk/src/CLASS.cxx                |  80 +++++-----------
 source/trunk/src/CLSSFacility.cxx         |   5 +-
 source/trunk/src/CLSSObject.cxx           |   3 +-
 source/trunk/src/DataBank.cxx             | 110 +++++++++++++++++-----
 source/trunk/src/EvolutionData.cxx        |  53 ++++++++++-
 source/trunk/src/FabricationPlant.cxx     |  16 +++-
 source/trunk/src/Pool.cxx                 |  42 ++++-----
 source/trunk/src/Reactor.cxx              |  21 ++++-
 source/trunk/src/Storage.cxx              |   6 +-
 16 files changed, 232 insertions(+), 122 deletions(-)

diff --git a/source/trunk/include/CLSSFacility.hxx b/source/trunk/include/CLSSFacility.hxx
index 77780ee81..5b9ccaa4b 100644
--- a/source/trunk/include/CLSSFacility.hxx
+++ b/source/trunk/include/CLSSFacility.hxx
@@ -29,11 +29,11 @@ class CLSSFacility : public CLSSObject
 {
 public :
 		///< Normal Constructor.
-		//CLSSFacility();
+	CLSSFacility();
 	
 		//********* Get Method *********//
 	int 		GetId()			const	{ return fId; }			//!< Return the Facility Parc'Is
-	virtual IsotopicVector 	GetInsideIV()	const	{ return fInsideIV; } 		//!< Return the IV contain in the Facility
+	IsotopicVector 	GetInsideIV()		const	{ return fInsideIV; } 		//!< Return the IV contain in the Facility
 
 	cSecond	GetInternalTime() const		{ return fInternalTime; }	//!< Return Creation Time
 
diff --git a/source/trunk/include/CLSSObject.hxx b/source/trunk/include/CLSSObject.hxx
index 7ea6d2617..66c0d2a3f 100644
--- a/source/trunk/include/CLSSObject.hxx
+++ b/source/trunk/include/CLSSObject.hxx
@@ -29,7 +29,6 @@ public :
 	CLSSObject();
 	virtual CLSSObject* Clone()	{ return new CLSSObject(*this); } //!< Correct way to copy a CLSSObject in case of derivation
 
-	virtual ~CLSSObject(){}			//!< destructor
 
 	void		SetLog(LogFile* log)	{ fLog = log; }
 	void		IsLog(bool islog)	{ fNoLog = islog; }
diff --git a/source/trunk/include/DataBank.hxx b/source/trunk/include/DataBank.hxx
index 7960dc42d..b1018fdfc 100755
--- a/source/trunk/include/DataBank.hxx
+++ b/source/trunk/include/DataBank.hxx
@@ -164,8 +164,8 @@ protected :
 
 	double	*fTheNucleiVector;	//!< The evolving atoms copied from Material proportions.
 	double 	**fTheMatrix;  		//!< The evolution Matrix
-
 	int	fNVar;		 //!< The size of the composition vector and /or number of ZAIs involved.
+
 	double	fPrecision;	//!< Precision of the RungeKutta
 	double	fHestimate;	//!< RK Step estimation.
 	double	fHmin;		//!< RK minimum Step.
diff --git a/source/trunk/include/EvolutionData.hxx b/source/trunk/include/EvolutionData.hxx
index 2fb3861c3..a546b1b28 100755
--- a/source/trunk/include/EvolutionData.hxx
+++ b/source/trunk/include/EvolutionData.hxx
@@ -49,6 +49,9 @@ public :
 	///< Normal Destructor.
 	~EvolutionData();
 
+	void DeleteEvolutionData();
+
+
 //********* Set Method *********//
 	void 	SetReactorType(string reactortype)	{ fReactorType = reactortype; }
 	void	SetFuelType(string fueltype)		{ fFuelType = fueltype; }
diff --git a/source/trunk/include/FabricationPlant.hxx b/source/trunk/include/FabricationPlant.hxx
index 4b44bf4dd..cde3a296a 100644
--- a/source/trunk/include/FabricationPlant.hxx
+++ b/source/trunk/include/FabricationPlant.hxx
@@ -108,7 +108,6 @@ protected :
 
 	DataBank<ZAI>*		fDecayDataBase;	//!< Pointer to the Decay DataBase
 
-
 	Storage*	fStorage;			//!< Pointer to the Storage to recycle
 	Storage*	fReUsable;			//!< Pointer to the Storage using for recycling unused Product
 
diff --git a/source/trunk/include/Pool.hxx b/source/trunk/include/Pool.hxx
index 694d91c7b..57ccc2175 100755
--- a/source/trunk/include/Pool.hxx
+++ b/source/trunk/include/Pool.hxx
@@ -82,8 +82,7 @@ public :
 	vector<IsotopicVector>	GetIVCooling() const		{ return fIVCooling; }	//!< Return the vector of Cooling IsotopicVector
 	void			AddIVCooling(IsotopicVector IV);			//!< Add Cooling IsotopicVector
 	void			RemoveIVCooling(int i);					//!< Remove a Cooling IsotopicVector
-	IsotopicVector		GetFullCooling();
-	IsotopicVector		GetInsideIV()			{ return GetFullCooling(); } 		//!< Return the IV contain in the Facility
+	IsotopicVector		GetFullCooling()		{return GetInsideIV(); }
 
 
 //********* Other Method *********//
diff --git a/source/trunk/include/ZAI.hxx b/source/trunk/include/ZAI.hxx
index 903bb134e..37749e302 100755
--- a/source/trunk/include/ZAI.hxx
+++ b/source/trunk/include/ZAI.hxx
@@ -64,7 +64,9 @@ class ZAI : public TObject
 	bool operator ==(const ZAI& zai) const	{ return ( fZ == zai.Z()  && fA == zai.A() &&  fI == zai.I()); }
 						//!< ZAI Comparator
 	void Print() const	{ cout << fZ << " " << fA << " " << fI << endl;}
-	protected :
+
+
+protected :
  	
  	string 	fName;		///< Name of the ZAI
 	short	fZ;		///< number of protons
diff --git a/source/trunk/src/CLASS.cxx b/source/trunk/src/CLASS.cxx
index 647529d63..32c70b7a7 100755
--- a/source/trunk/src/CLASS.cxx
+++ b/source/trunk/src/CLASS.cxx
@@ -57,7 +57,9 @@ CLASS::CLASS()
 	
 	fOutputFileName = "CLASS_Default.root";
 	fOutputTreeName = "Data";
-	
+	fOutFile = 0;
+	fOutT = 0;
+
 	SetLog(new LogFile("CLASS.log"));
 	fParcPower = 0;
 	
@@ -94,7 +96,9 @@ CLASS::CLASS(LogFile* Log)
 	
 	fOutputFileName = "CLASS_Default.root";
 	fOutputTreeName = "Data";
-	
+	fOutFile = 0;
+	fOutT = 0;
+
 	SetLog(Log);
 	fParcPower = 0;
 	
@@ -130,7 +134,9 @@ CLASS::CLASS(double abstime)
 	
 	fOutputFileName = "CLASS_Default.root";
 	fOutputTreeName = "Data";
-	
+	fOutFile = 0;
+	fOutT = 0;
+
 	SetLog(new LogFile("CLASS.log"));
 	fParcPower = 0;
 	
@@ -162,6 +168,7 @@ CLASS::~CLASS()
 	
 #pragma omp single
 	{CloseOutputTree();}
+
 	
 }
 
@@ -411,6 +418,7 @@ void CLASS::BuildTimeVector(cSecond t)
 void CLASS::PoolEvolution()
 {
 	
+#pragma omp parallel for
 	for(int i = 0; i < (int) fPool.size();i++)
 		fPool[i]->Evolution(fAbsoluteTime);
 	
@@ -422,6 +430,7 @@ void CLASS::PoolEvolution()
 void CLASS::StorageEvolution()
 {
 	
+#pragma omp parallel for
 	for(int i = 0; i < (int) fStorage.size();i++)
 		fStorage[i]->Evolution(fAbsoluteTime);
 	
@@ -431,6 +440,7 @@ void CLASS::StorageEvolution()
 void CLASS::FabricationPlantEvolution()
 {
 	
+#pragma omp parallel for
 	for(int i = 0; i < (int) fFabricationPlant.size();i++)
 		fFabricationPlant[i]->Evolution(fAbsoluteTime);
 	
@@ -473,61 +483,21 @@ void CLASS::Evolution(double t)
 	{
 		
 		fAbsoluteTime = (*it).first;
-		if( (*it).second & 2 || (*it).second & 1 )
-		{
-			if( (*it).second & 1 )
-				StorageEvolution();
-			
-			PoolEvolution();
-			FabricationPlantEvolution();
-			ReactorEvolution();
-			
-			if((*it).second & 2 )
-				(*it).second ^= 2;
-			if((*it).second & 4 )
-				(*it).second ^= 4;
-			if((*it).second & 8 )
-				(*it).second ^= 8;
-			if((*it).second & 16 )
-				(*it).second ^= 16;
-		}
-		
-		
-		if( (*it).second & 4 )
-		{
+
+
+		if( (*it).second & 1 || (*it).second & 4 || (*it).second & 8 || (*it).second & 16 )
 			StorageEvolution();
+
+		if( (*it).second & 1 || (*it).second & 2 || (*it).second & 4 || (*it).second & 8 || (*it).second & 16 )
 			PoolEvolution();
+
+		if( (*it).second & 1 || (*it).second & 2 || (*it).second & 4 || (*it).second & 16 )
 			FabricationPlantEvolution();
+
+		if( (*it).second & 1 || (*it).second & 2 || (*it).second & 4 )
 			ReactorEvolution();
-			
-			(*it).second ^= 4;
-			if((*it).second & 8 )
-				(*it).second ^= 8;
-		}
-		
-		if( (*it).second & 16 )
-		{
-			StorageEvolution();
-			PoolEvolution();
-			FabricationPlantEvolution();
-			
-			(*it).second ^= 16;
-			if((*it).second & 8 )
-				(*it).second ^= 8;
-		}
-		
-		
-		if( (*it).second & 8 )
-		{
-			StorageEvolution();
-			PoolEvolution();
-			
-			(*it).second ^= 8;
-		}
-		
-		
-		
-		if( (*it).second & 1 || (*it).first == (*fTimeStep.begin()).first )
+
+		if( (*it).second & 1 || it == fTimeStep.begin() )
 		{
 #pragma omp single
 			{
@@ -578,7 +548,7 @@ void CLASS::UpdateParc()
 	
 	ResetQuantity();
 	
-	for (int i =0; i < (int)fFabricationPlant.size(); i++)
+	for(int i =0; i < (int)fFabricationPlant.size(); i++)
 		fFuelFabrication += fFabricationPlant[i]->GetFullFabrication();
 	
 	for(int i = 0; i < (int) fPool.size();i++)
diff --git a/source/trunk/src/CLSSFacility.cxx b/source/trunk/src/CLSSFacility.cxx
index d85eb9ac2..95b8b389d 100644
--- a/source/trunk/src/CLSSFacility.cxx
+++ b/source/trunk/src/CLSSFacility.cxx
@@ -15,4 +15,7 @@ using namespace std;
 ClassImp(CLSSFacility)
 
 
-
+CLSSFacility::CLSSFacility()
+{
+	fParc = 0;
+}
diff --git a/source/trunk/src/CLSSObject.cxx b/source/trunk/src/CLSSObject.cxx
index 82a31537a..49f7d2ca7 100644
--- a/source/trunk/src/CLSSObject.cxx
+++ b/source/trunk/src/CLSSObject.cxx
@@ -17,5 +17,6 @@ ClassImp(CLSSObject)
 
 CLSSObject::CLSSObject()
 {
-	
+	fLog = 0;
 }
+
diff --git a/source/trunk/src/DataBank.cxx b/source/trunk/src/DataBank.cxx
index ae0f62f93..745449ca3 100755
--- a/source/trunk/src/DataBank.cxx
+++ b/source/trunk/src/DataBank.cxx
@@ -63,6 +63,8 @@ double ReactionRateWeightedDistance(EvolutionData DB, IsotopicVector IV1  )
 template<class T>
 DataBank<T>::DataBank()
 {
+	fTheNucleiVector = 0;
+	fTheMatrix = 0;
 }
 
 //________________________________________________________________________
@@ -81,6 +83,9 @@ DataBank<ZAI>::DataBank(LogFile* Log, string DB_index_file, bool setlog, bool ol
 
 	fOldReadMethod = olfreadmethod;
 
+	fTheNucleiVector = 0;
+	fTheMatrix = 0;
+
 	// Warning
 	if(PrintLog())
 	{
@@ -98,6 +103,25 @@ template<>
 DataBank<ZAI>::~DataBank()
 {
 
+	if(fTheMatrix)
+	{
+		for(int i= 0; i<fNVar; i++)
+			delete [] fTheMatrix[i];
+		delete [] fTheMatrix;
+	}
+	if(fTheNucleiVector)
+	{
+		delete fTheNucleiVector;
+	}
+
+
+	map<ZAI ,EvolutionData >::iterator it_del;
+	for( it_del = fDataBank.begin(); it_del != fDataBank.end(); it_del++)
+		(*it_del).second.DeleteEvolutionData();
+
+	for( it_del = fDataBankCalculated.begin(); it_del != fDataBankCalculated.end(); it_del++)
+		(*it_del).second.DeleteEvolutionData();
+
 }
 
 //________________________________________________________________________
@@ -216,6 +240,9 @@ DataBank<IsotopicVector>::DataBank():DynamicalSystem()
 	fDataDirectoryName += "/source/data/";
 	fDataFileName = "chart.JEF3T";
 
+	fTheNucleiVector = 0;
+	fTheMatrix = 0;
+
 	SetForbidNegativeValue();
 
 }
@@ -244,6 +271,9 @@ DataBank<IsotopicVector>::DataBank(LogFile* Log, string DB_index_file, bool setl
 	fShorstestHalflife = 3600.*24*2.;
 	fZAIThreshold = 90;
 
+	fTheNucleiVector = 0;
+	fTheMatrix = 0;
+
 	ReadDataBase();
 
 	SetForbidNegativeValue();
@@ -265,6 +295,25 @@ DataBank<IsotopicVector>::DataBank(LogFile* Log, string DB_index_file, bool setl
 template<>
 DataBank<IsotopicVector>::~DataBank()
 {
+
+	if(fTheMatrix)
+	{
+		for(int i= 0; i<fNVar; i++)
+			delete [] fTheMatrix[i];
+		delete [] fTheMatrix;
+	}
+	if(fTheNucleiVector)
+	{
+		delete fTheNucleiVector;
+	}
+
+	map<IsotopicVector ,EvolutionData >::iterator it_del;
+	for( it_del = fDataBank.begin(); it_del != fDataBank.end(); it_del++)
+		(*it_del).second.DeleteEvolutionData();
+
+	for( it_del = fDataBankCalculated.begin(); it_del != fDataBankCalculated.end(); it_del++)
+		(*it_del).second.DeleteEvolutionData();
+
 }
 
 //________________________________________________________________________
@@ -368,7 +417,6 @@ template<>
 void DataBank<IsotopicVector>::BuildDecayMatrix()
 {
 	// List of Decay Time and Properties
-
 	map<ZAI, pair<double, map< ZAI, double > > > ZAIDecay;
 
 	{	// TMP
@@ -471,7 +519,8 @@ void DataBank<IsotopicVector>::BuildDecayMatrix()
 						daughter_A = daughter_Z = Iso = -3;
 					// not spontaneous fission
 					ZAI DaughterZAI = ZAI(daughter_Z,daughter_A,Iso);
-					if((BR>1e-10) && (!stable))
+
+						if((BR>1e-10) && (!stable))
 					{
 						if(DM <= 15)
 						{
@@ -484,7 +533,7 @@ void DataBank<IsotopicVector>::BuildDecayMatrix()
 							{
 								DaughtersMap += 2*BR * ZAI(-2,-2,-2);
 
-								branch_test_f += 2*BR;
+								branch_test_f += BR;
 							}
 							else
 							{
@@ -493,7 +542,7 @@ void DataBank<IsotopicVector>::BuildDecayMatrix()
 								if(it_yield != fSpontaneusYield.end())
 								{
 									DaughtersMap += (BR* (*it_yield).second );
-									branch_test_f += (*it_yield).second.GetSumOfAll() / 2.;
+									branch_test_f += BR* (*it_yield).second.GetSumOfAll() / 2.;
 
 								}
 								else
@@ -558,7 +607,6 @@ void DataBank<IsotopicVector>::BuildDecayMatrix()
 
 			FD_it_Origin = fFastDecay.find(FD_it->first);
 
-
 			map<ZAI, double> BR = (*FD_it).second;
 			map<ZAI, double>::iterator BR_it;
 
@@ -570,34 +618,41 @@ void DataBank<IsotopicVector>::BuildDecayMatrix()
 				if( it_index == findex_inver.end() )
 				{
 					map<ZAI, map<ZAI, double> >::iterator FD2_it = FastDecayCopy.find((*BR_it).first);
-					if( FD2_it == fFastDecay.end() )
-					{
-						(*FD_it_Origin).second.erase((*BR_it).first);
-						pair<map<ZAI, double>::iterator, bool> IResult;
-						IResult = (*FD_it_Origin).second.insert( pair<ZAI, double> ( ZAI(-3,-3,-3), (*BR_it).second) );
-						if( !IResult.second)
-							(*IResult.first).second += (*BR_it).second ;
-					}
-					else
+					if( FD2_it != FastDecayCopy.end() )
 					{
 						map<ZAI, double>::iterator BR2_it;
 						(*FD_it_Origin).second.erase((*BR_it).first);
 
 						for (BR2_it = (*FD2_it).second.begin(); BR2_it != (*FD2_it).second.end(); BR2_it++)
 						{
+
 							pair<map<ZAI, double>::iterator, bool> IResult;
 							IResult = (*FD_it_Origin).second.insert( pair<ZAI, double> ( (*BR2_it).first, (*BR_it).second * (*BR2_it).second ) );
+
 							if( !IResult.second)
 								(*IResult.first).second += (*BR_it).second * (*BR2_it).second ;
-						}
 
+							
+						}
+						
+					}
+					else
+					{
+						(*FD_it_Origin).second.erase( (*BR_it).first );
+						pair< map<ZAI, double>::iterator, bool> IResult;
+						IResult = (*FD_it_Origin).second.insert( pair<ZAI, double> ( ZAI(-3,-3,-3), (*BR_it).second) );
+						if( !IResult.second)
+							(*IResult.first).second += (*BR_it).second ;
 					}
 
+
+
 				}
 			}
 
 		}
 
+
 		FastDecayValidation = true;
 		for(FD_it = fFastDecay.begin(); FD_it != fFastDecay.end(); FD_it++)
 		{
@@ -673,6 +728,7 @@ void DataBank<IsotopicVector>::BuildDecayMatrix()
 
 		}
 	}
+
 	//exit(1);
 
 }
@@ -762,7 +818,7 @@ map< ZAI,IsotopicVector > DataBank<IsotopicVector>::ReadFPYield(string Yield)
 			{
 				cout << "!!Error!! !!!DataBank!!! Many accurance of the PF " << Z << " " << A;
 				cout << " in " << Yield << " file!! Please Check it";
-				cout << "(Number of yiled does not match the number of ZAI that fission !!!" << endl;
+				cout << "(Number of yield does not match the number of ZAI that fission !!!" << endl;
 				exit(1);
 
 			}
@@ -777,7 +833,6 @@ map< ZAI,IsotopicVector > DataBank<IsotopicVector>::ReadFPYield(string Yield)
 
 
 	} while (!infile.eof());
-
 	return Yield_map;
 }
 
@@ -821,22 +876,27 @@ TMatrixT<double> DataBank<IsotopicVector>::GetFissionXsMatrix(EvolutionData Evol
 			else
 			{
 				map<ZAI, IsotopicVector>::iterator it_yield = fReactionYield.find( (*it).first );
+
 				if( it_yield != fReactionYield.end())
 				{
 					map<ZAI ,double>::iterator it_IVQ;
-					for( it_IVQ = (*it_yield).second.GetIsotopicQuantity().begin(); it_IVQ != (*it_yield).second.GetIsotopicQuantity().end(); it_IVQ++ )
+					map<ZAI ,double> IVQ = (*it_yield).second.GetIsotopicQuantity();
+
+					for( it_IVQ = IVQ.begin(); it_IVQ != IVQ.end(); it_IVQ++ )
 					{
 						map<ZAI, int>::iterator findex_it_PF = findex_inver.find( (*it_IVQ).first );
+
 						if(findex_it_PF != findex_inver.end() )
 							BatemanMatrix[(*findex_it_PF).second][ (*findex_inver_it).second ] += (*it_IVQ).second*y* 1e-24;
 						else
 						{
 							map<ZAI, map<ZAI, double> >::iterator it_FD = fFastDecay.find( (*it_IVQ).first);
+
 							if( it_FD == fFastDecay.end() )
 							{
-								cout << "Capture Problem in FastDecay for nuclei " << (*it_IVQ).first.Z() << " " << (*it_IVQ).first.A() << " " << (*it_IVQ).first.I() << endl;
+								//cout << "Fission Problem in FastDecay for nuclei " << (*it_IVQ).first.Z() << " " << (*it_IVQ).first.A() << " " << (*it_IVQ).first.I() << endl;
 
-								BatemanMatrix[0][findex_it_PF->second] += (*it_IVQ).second * y * 1e-24  ;
+								BatemanMatrix[1][ (*findex_inver_it).second ] += (*it_IVQ).second * y * 1e-24  ;
 							}
 							else
 							{
@@ -924,8 +984,8 @@ TMatrixT<double> DataBank<IsotopicVector>::GetCaptureXsMatrix(EvolutionData Evol
 					if( it4 == fFastDecay.end() )
 					{
 						cout << "Capture Problem in FastDecay for nuclei " << (*it).first.Z() << " " << (*it).first.A()+1 << " " << (*it).first.I() << endl;
-
 						BatemanMatrix[0][Index_it->second] += y* 1e-24  ;
+
 					}
 					else
 					{
@@ -1351,13 +1411,12 @@ void DataBank<IsotopicVector>::SetTheMatrixToZero()
 	for(int i= 0; i < fNVar; i++)
 		fTheMatrix[i] = new double[fNVar];
 
+#pragma omp parallel for
 	for(int i = 0; i < fNVar; i++)
-	{
 		for(int k = 0; k < fNVar; k++)
 		{
 			fTheMatrix[i][k]=0.0;
 		}
-	}
 
 }
 
@@ -1418,6 +1477,7 @@ void DataBank<IsotopicVector>::BuildEqns(double t, double *N, double *dNdt)
 template<>
 void DataBank<IsotopicVector>::SetTheMatrix(TMatrixT<double> BatemanMatrix)
 {
+#pragma omp parallel for
 	for (int k = 0; k < (int)fNVar; k++)
 		for (int l = 0; l < (int)findex_inver.size(); l++)
 			fTheMatrix[l][k] = BatemanMatrix[l][k];
@@ -1428,6 +1488,7 @@ template<>
 TMatrixT<double> DataBank<IsotopicVector>::GetTheMatrix()
 {
 	TMatrixT<double> BatemanMatrix = TMatrixT<double>(findex.size(),findex.size());
+#pragma omp parallel for
 	for (int k = 0; k < (int)fNVar; k++)
 		for (int l = 0; l < (int)findex_inver.size(); l++)
 			BatemanMatrix[l][k] = fTheMatrix[l][k];
@@ -1439,6 +1500,7 @@ TMatrixT<double> DataBank<IsotopicVector>::GetTheMatrix()
 template<>
 void DataBank<IsotopicVector>::SetTheNucleiVector(TMatrixT<double> NEvolutionMatrix)
 {
+#pragma omp parallel for
 	for (int k = 0; k < (int)fNVar; k++)
 		fTheNucleiVector[k] = NEvolutionMatrix[k][0];
 }
@@ -1448,6 +1510,7 @@ template<>
 TMatrixT<double> DataBank<IsotopicVector>::GetTheNucleiVector()
 {
 	TMatrixT<double> NEvolutionMatrix = TMatrixT<double>(findex.size(),1);
+#pragma omp parallel for
 	for (int k = 0; k < (int)fNVar; k++)
 		NEvolutionMatrix[k][0] = fTheNucleiVector[k];
 
@@ -1461,7 +1524,6 @@ TMatrixT<double> DataBank<IsotopicVector>::GetTheNucleiVector()
 template<>
 EvolutionData DataBank<IsotopicVector>::GenerateEvolutionData(IsotopicVector isotopicvector, double cycletime, double Power)
 {
-
 	if(fFastDecay.size() == 0)
 	{
 		BuildDecayMatrix();
diff --git a/source/trunk/src/EvolutionData.cxx b/source/trunk/src/EvolutionData.cxx
index 1d6fc58bd..8ae2ecb05 100755
--- a/source/trunk/src/EvolutionData.cxx
+++ b/source/trunk/src/EvolutionData.cxx
@@ -90,6 +90,12 @@ ClassImp(EvolutionData)
 
 EvolutionData::EvolutionData()
 {
+	fIsCrossSection = false;
+	fPower = 0;
+	fCycleTime = 0;
+	fNormFactor = 0;
+	fKeff = 0;
+	fFlux = 0;
 }
 
 	//________________________________________________________________________
@@ -101,6 +107,8 @@ EvolutionData::EvolutionData(LogFile* Log)
 	fPower = 0;
 	fCycleTime = 0;
 	fNormFactor = 0;
+	fKeff = 0;
+	fFlux = 0;
 
 	
 }
@@ -115,6 +123,8 @@ EvolutionData::EvolutionData(LogFile* Log, string DB_file, bool oldread, ZAI zai
 	fPower = 0;
 	fCycleTime = 0;
 	fNormFactor = 0;
+	fKeff = 0;
+	fFlux = 0;
 	
 	if(zai != ZAI(0,0,0))
 		AddAsStable(zai);
@@ -129,8 +139,47 @@ EvolutionData::EvolutionData(LogFile* Log, string DB_file, bool oldread, ZAI zai
 	//________________________________________________________________________
 EvolutionData::~EvolutionData()
 {
-	
-	
+
+}
+//________________________________________________________________________
+void EvolutionData::DeleteEvolutionData()
+{
+
+	map<ZAI ,TGraph* >::iterator it_del;
+
+	for( it_del = fEvolutionData.begin(); it_del != fEvolutionData.end(); it_del++)
+	{
+		delete (*it_del).second;
+		(*it_del).second = 0;
+	}
+	for( it_del = fFissionXS.begin(); it_del != fFissionXS.end(); it_del++)
+	{
+		delete (*it_del).second;
+		(*it_del).second = 0;
+	}
+	for( it_del = fCaptureXS.begin(); it_del != fCaptureXS.end(); it_del++)
+	{
+		delete (*it_del).second;
+		(*it_del).second = 0;
+	}
+	for( it_del = fn2nXS.begin(); it_del != fn2nXS.end(); it_del++)
+	{
+		delete (*it_del).second;
+		(*it_del).second = 0;
+	}
+
+
+	delete	fKeff;
+	delete	fFlux;
+
+	fEvolutionData.clear();
+	fFissionXS.clear();
+	fCaptureXS.clear();
+	fn2nXS.clear();
+
+	fFlux = 0;
+	fKeff = 0;
+
 }
 
 
diff --git a/source/trunk/src/FabricationPlant.cxx b/source/trunk/src/FabricationPlant.cxx
index 2c554ae22..dcface35c 100644
--- a/source/trunk/src/FabricationPlant.cxx
+++ b/source/trunk/src/FabricationPlant.cxx
@@ -44,6 +44,9 @@ ClassImp(FabricationPlant)
 
 FabricationPlant::FabricationPlant()
 {
+	fDecayDataBase = 0;
+	fStorage = 0;
+	fReUsable = 0;
 }
 
 FabricationPlant::FabricationPlant(LogFile* log)
@@ -54,8 +57,10 @@ FabricationPlant::FabricationPlant(LogFile* log)
 	SetCycleTime(-1);
 	fUpdateReferenceDBatEachStep = false;
 	fSubstitutionFuel = false;
-	
-	
+	fDecayDataBase = 0;
+	fStorage = 0;
+	fReUsable = 0;
+
 	cout	<< "!!INFO!! !!!FabricationPlant!!! A FabricationPlant has been define :" << endl;
 	cout	<< "\t Chronological Stock Priority set! "<< endl << endl;
 	cout	<< "!!WARNING!! !!!FabricationPlant!!! You need to set the different stock manually as well as the Fabrication Time Manualy !! " << endl;
@@ -75,7 +80,9 @@ FabricationPlant::FabricationPlant(LogFile* log, Storage* storage, Storage* reus
 	fChronologicalTimePriority = false;
 	fUpdateReferenceDBatEachStep = false;
 	fSubstitutionFuel = false;
-	
+	fDecayDataBase = 0;
+
+
 	SetCycleTime((cSecond)fabircationtime );
 	fStorage = storage;
 	fReUsable = reusable;
@@ -151,7 +158,8 @@ void FabricationPlant::FabricationPlantEvolution(cSecond t)
 		{
 			if( (*it).second == t )
 			{
-				BuildFuelForReactor( (*it).first );
+#pragma omp critical(FuelBuild)
+				{BuildFuelForReactor( (*it).first );}
 				(*it).second += GetParc()->GetReactor()[ (*it).first ]->GetCycleTime();
 			}
 			else if ( (*it).second - GetParc()->GetReactor()[ (*it).first ]->GetCycleTime() + GetCycleTime() > t )
diff --git a/source/trunk/src/Pool.cxx b/source/trunk/src/Pool.cxx
index 80c4fa0d0..808b682df 100755
--- a/source/trunk/src/Pool.cxx
+++ b/source/trunk/src/Pool.cxx
@@ -24,9 +24,8 @@ ClassImp(Pool)
 
 Pool::Pool()
 {
-
-
-
+	fStorage = 0;
+	fDecayDataBase = 0;
 }
 
 Pool::Pool(LogFile* log)
@@ -40,6 +39,10 @@ Pool::Pool(LogFile* log)
 	fInternalTime = 0 ;
 	SetCreationTime( 0 );
 	fCoolingLastIndex = 0;
+
+	fStorage = 0;
+	fDecayDataBase = 0;
+
 	
 	cout	<< "!!INFO!! !!!Pool!!! A new Pool has been define :" << endl;
 	cout	<< "\t Creation time set at \t " << (double)(GetCreationTime()/3600/24/365.25) << " year" << endl;
@@ -54,8 +57,7 @@ Pool::Pool(LogFile* log)
 	
 }
 	//________________________________________________________________________
-Pool::Pool(LogFile* log, double creation,
-				   double coolingtime)
+Pool::Pool(LogFile* log, double creation, double coolingtime)
 {
 
 	SetLog(log);
@@ -65,6 +67,10 @@ Pool::Pool(LogFile* log, double creation,
 	fIsStarted = false;
 	fPutToWaste = true;
 	fCoolingLastIndex = 0;
+
+	fStorage = 0;
+	fDecayDataBase = 0;
+
 	
 	cout	<< "!!INFO!! !!!Pool!!! A new Pool has been define :" << endl;
 	cout	<< "\t Creation time set at \t " << (double)(GetCreationTime()/3600/24/365.25) << " year" << endl;
@@ -80,9 +86,7 @@ Pool::Pool(LogFile* log, double creation,
 }
 
 //________________________________________________________________________
-Pool::Pool(LogFile* log, Storage* storage,
-				   double creation,
-				   double coolingtime)
+Pool::Pool(LogFile* log, Storage* storage, double creation, double coolingtime)
 {
 
 	SetLog(log);
@@ -93,7 +97,9 @@ Pool::Pool(LogFile* log, Storage* storage,
 	fIsStarted = false;
 	fPutToWaste = false;
 	fCoolingLastIndex = 0;
-	
+
+	fDecayDataBase = 0;
+
 	
 	cout	<< "!!INFO!! !!!Pool!!! A new Pool has been define :" << endl;
 	cout	<< "\t Creation time set at \t " << (double)(GetCreationTime()/3600/24/365.25) << " year" << endl;
@@ -149,6 +155,7 @@ void Pool::AddIVCooling(IsotopicVector IV)
 { 
 
 	fIVCooling.push_back(IV);
+	fInsideIV += IV;
 	fCoolingStartingTime.push_back(fInternalTime);
 	fCoolingLastIndex++;
 	fCoolingIndex.push_back(fCoolingLastIndex);
@@ -165,17 +172,6 @@ void Pool::RemoveIVCooling(int i)		//!< Remove a Cooling IsotopicVector
 
 }
 
-IsotopicVector Pool::GetFullCooling()
-{
-
-	IsotopicVector tmp = 0*ZAI(0,0,0);
-	
-	for(int i =0; i< (int)fIVCooling.size(); i++)
-		tmp += fIVCooling[i];
-	fInsideIV = tmp;
-	return fInsideIV;
-
-}
 
 
 
@@ -196,6 +192,9 @@ void Pool::CoolingEvolution(cSecond t)
 	if(t == fInternalTime && t!=0) return;
 	int RemainingCoolingTime;
 	cSecond EvolutionTime = t - fInternalTime;
+
+	fInsideIV = IsotopicVector();
+
 #pragma omp parallel for
 	for ( int i = 0 ; i < (int)fIVCooling.size() ; i++)
 	{
@@ -215,6 +214,7 @@ void Pool::CoolingEvolution(cSecond t)
 			//Cooling Decay
 			fIVCooling[i] = GetDecay( fIVCooling[i], RemainingCoolingTime);
 
+
 #pragma omp critical(DeleteCoolingIVPB)
 			{fCoolingEndOfCycle.push_back(i);}
 
@@ -222,6 +222,7 @@ void Pool::CoolingEvolution(cSecond t)
 		else if ( fCoolingStartingTime[i] != t )
 		{
 			fIVCooling[i] = GetDecay( fIVCooling[i] , EvolutionTime);
+			fInsideIV += fIVCooling[i];
 		}
 	}
 #pragma omp critical(DeleteCoolingIVPB)
@@ -271,7 +272,6 @@ void Pool::Dump()
 		
 		fCoolingEndOfCycle.erase(fCoolingEndOfCycle.begin()+i);	// Remove index entry
 		RemoveIVCooling(idx);					// Remove IVcooling
-
 	}
 	
 	if((int)fCoolingEndOfCycle.size() != 0 )// Control
diff --git a/source/trunk/src/Reactor.cxx b/source/trunk/src/Reactor.cxx
index a482c6f7f..79af71ab6 100755
--- a/source/trunk/src/Reactor.cxx
+++ b/source/trunk/src/Reactor.cxx
@@ -29,17 +29,24 @@ ClassImp(Reactor)
 
 Reactor::Reactor()
 {
-
+	fAssociedPool = 0;
+	fStorage = 0;
+	fFuelTypeDB = 0;
+	fFabricationPlant = 0;
 }
 
 Reactor::Reactor(LogFile* log)
 {
 
 	SetLog(log);
+	fAssociedPool = 0;
+	fStorage = 0;
+	fFuelTypeDB = 0;
+	fFabricationPlant = 0;
 
 }
 
-Reactor::Reactor(LogFile* log, DataBank<IsotopicVector>* 	fueltypeDB,
+Reactor::Reactor(LogFile* log, DataBank<IsotopicVector>* fueltypeDB,
 		 FabricationPlant* fabricationplant,
  		 Pool* Pool,
  		 double creationtime, double lifetime)
@@ -55,6 +62,7 @@ Reactor::Reactor(LogFile* log, DataBank<IsotopicVector>* 	fueltypeDB,
 	fFixedFuel = false;
 	fBurnUp = -1.;
 	fHeavyMetalMass = -1.;
+	fStorage = 0;
 
 	fAssociedPool = Pool;
 
@@ -85,13 +93,14 @@ Reactor::Reactor(LogFile* log, DataBank<IsotopicVector>* 	fueltypeDB,
 
 }
 
-Reactor::Reactor(LogFile* log, DataBank<IsotopicVector>* 	fueltypeDB, FabricationPlant* fabricationplant, Pool* Pool,
+Reactor::Reactor(LogFile* log, DataBank<IsotopicVector>* fueltypeDB, FabricationPlant* fabricationplant, Pool* Pool,
  		 double creationtime, double lifetime,
  		 double Power, double HMMass, double BurnUp, double ChargeFactor)
 {
 
 	SetLog(log);
 
+	fStorage = 0;
 	fIsStarted = false;
 	fShutDown = false;
 	fEndOfCycle = false;
@@ -153,6 +162,8 @@ Reactor::Reactor(LogFile* log, DataBank<IsotopicVector>* 	fueltypeDB,
 	fShutDown = false;
 	fEndOfCycle = false;
 
+	fStorage = 0;
+
 	fFabricationPlant = fabricationplant;
 	fFixedFuel = false;
 	fBurnUp = BurnUp;
@@ -208,7 +219,9 @@ Reactor::Reactor(LogFile* log, EvolutionData evolutivedb,
 	fShutDown = false;
 	fEndOfCycle = false;
 
-
+	fStorage = 0;
+	fFuelTypeDB = 0;
+	fFabricationPlant = 0;
 
 	fFixedFuel = true;
 	fIsStorage = false;
diff --git a/source/trunk/src/Storage.cxx b/source/trunk/src/Storage.cxx
index d025ebf2e..8cd468f06 100644
--- a/source/trunk/src/Storage.cxx
+++ b/source/trunk/src/Storage.cxx
@@ -23,13 +23,15 @@ ClassImp(Storage)
 
 Storage::Storage()
 {
+	fDecayDataBase = 0;
 }
 
 Storage::Storage(LogFile* log)
 {
 	
 	SetLog(log);
-	
+	fDecayDataBase = 0;
+
 	cout	<< "!!INFO!! !!!Storage!!! A new Storage has been define." << endl;
 	
 	GetLog()->fLog	<< "!!INFO!! !!!Storage!!! A new Storage has been define." << endl;
@@ -153,7 +155,7 @@ void Storage::StorageEvolution(cSecond t)
 
 	if(t == fInternalTime && t !=0 ) return;
 
-	for(int i = (int)fIVStock.size()-1 ; i >=0; i--)
+	for(int i = (int)fIVStock.size()-1 ; i >=0; i--) //Removing empty Stock
 		if(Norme(fIVStock[i]) == 0)
 			fIVStock.erase(fIVStock.begin()+i); 
 	
-- 
GitLab