Main Page   Compound List   File List   Compound Members   File Members  

ReactorNeutrons.cpp

00001 #include <math.h>
00002 #include <iostream.h>
00003 #include <fstream.h>
00004 #include <string.h>
00005 #include "ReactorNeutrons.hh"
00006 #include "ReactorConstants.hh"
00007 
00008 ReactorNeutrons::ReactorNeutrons(){
00009   Data = new XCdata[0];
00010 }
00011 
00012 ReactorNeutrons::ReactorNeutrons(int option){
00013   Data = new XCdata[DataSize];
00014   DataPtr = Data;
00015   AddHdata();
00016   AddCdata();
00017   AddGd155data();
00018   AddGd157data();
00019 }
00020 ReactorNeutrons::~ReactorNeutrons(){
00021   delete[] Data;
00022 }
00023 ReactorNeutrons::ReactorNeutrons(const ReactorNeutrons& N){
00024 
00025   Data = new XCdata[DataSize];
00026   XCdata* pold = N.Data+DataSize;
00027   XCdata* pnew = Data+DataSize;
00028   while (pnew>Data)*--pnew=*--pold;
00029   
00030   DataPtr=Data;
00031 }
00032 ReactorNeutrons& ReactorNeutrons::operator=(const ReactorNeutrons& rhs){
00033   if(this==&rhs)return *this;
00034 
00035   delete[] Data;
00036   Data = new XCdata[DataSize];
00037   XCdata* pold = rhs.Data+DataSize;
00038   XCdata* pnew = Data+DataSize;
00039   while (pnew>Data)*--pnew=*--pold;
00040 
00041   DataPtr=Data;
00042 
00043   return *this;
00044 
00045 }
00046 //
00047 //
00048 //
00049 ReactorNeutrons::XCdata::XCdata(){
00050   Size = 0;
00051   KE = new double[0];
00052   XC = new double[0];
00053   LastKE=KE;
00054   LastXC=XC;
00055 }
00056 ReactorNeutrons::XCdata::XCdata(char* filename){
00057 
00058   int n;
00059   double ke[MaxSize];
00060   double xc[MaxSize];
00061 
00062   strcpy(FileName,filename);
00063 
00064   GetData(filename,n,ke,xc);
00065 
00066   Size = n;
00067   KE = new double[n];
00068   XC = new double[n];
00069 
00070   for(int i=0;i<n;i++){
00071     *(KE+i)=ke[i];
00072     *(XC+i)=xc[i];
00073   }
00074   LastKE = KE+n-1;
00075   LastXC = XC+n-1;
00076 
00077   strncpy(Process,FileName+11,5);
00078   Process[5] = '\0';
00079 
00080   Z = 100*(FileName[5]-'0')+10*(FileName[6]-'0')+(FileName[7]-'0');
00081   A = 100*(FileName[8]-'0')+10*(FileName[9]-'0')+(FileName[10]-'0');
00082 
00083   /*
00084   cout << " Cross Section data for " << Process 
00085        <<" from file " << FileName 
00086        << " for A= " << A
00087        << " and Z= " << Z << endl;
00088   */
00089 }
00090 ReactorNeutrons::XCdata::~XCdata(){
00091   delete[] KE;
00092   delete[] XC;
00093 }
00094 ReactorNeutrons::XCdata::XCdata(const ReactorNeutrons::XCdata& X){
00095   
00096   A=X.A;
00097   Z=X.Z;
00098   //
00099   strcpy(FileName,X.FileName);
00100   strcpy(Process,X.Process);
00101   //
00102   Size = X.Size;
00103   //
00104   KE = new double[Size];
00105   XC = new double[Size];
00106   //
00107   LastKE = KE+Size-1;
00108   LastXC = XC+Size-1;
00109   //
00110   double* pold = X.KE+Size;
00111   double* pnew = KE+Size;
00112   while(pnew>KE)*--pnew=*--pold;
00113   //
00114   pold = X.XC+Size;
00115   pnew = XC+Size;
00116   while(pnew>XC)*--pnew=*--pold;
00117 }
00118 //
00119 //
00120 //
00121 ReactorNeutrons::XCdata& 
00122 ReactorNeutrons::XCdata::operator=(const ReactorNeutrons::XCdata& rhs){
00123   
00124   if(this==&rhs)return *this;
00125   //
00126   A=rhs.A;
00127   Z=rhs.Z;
00128   //
00129   strcpy(FileName,rhs.FileName);
00130   strcpy(Process,rhs.Process);
00131   //
00132   Size = rhs.Size;
00133   delete[] KE;
00134   delete[] XC;
00135   //
00136   KE = new double[Size];
00137   XC = new double[Size];
00138   //
00139   LastKE = KE+Size-1;
00140   LastXC = XC+Size-1;
00141   //
00142   double* pold = rhs.KE+Size;
00143   double* pnew = KE+Size;
00144   while(pnew>KE)*--pnew=*--pold;
00145   //
00146   pold = rhs.XC+Size;
00147   pnew = XC+Size;
00148   while(pnew>XC)*--pnew=*--pold;
00149   //
00150   return *this;
00151 }
00152 //
00153 //
00154 //
00155 void ReactorNeutrons::AddData(char* file1,char* file2,char* file3){
00156   ReactorNeutrons::XCdata d1(file1);
00157   *DataPtr++=d1;
00158   ReactorNeutrons::XCdata d2(file2);
00159   *DataPtr++=d2;
00160   ReactorNeutrons::XCdata d3(file3);
00161   *DataPtr++=d3;
00162 }
00163 
00164 void ReactorNeutrons::XCdata::GetData(const char* file,int& size,double* e,double* xc){
00165   size=0;
00166   double* eptr=e;
00167   double* xcptr=xc;
00168   ifstream infile(file);
00169   while(infile.good()){
00170     infile>> *eptr++ >> *xcptr++;size++;
00171   }  
00172   size-=1;
00173   infile.close();
00174 }
00175 //
00176 //
00177 //
00178 int ReactorNeutrons::GetTotalSize(int Z,int A){
00179   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00180     if(data->GetA()==A&&data->GetZ()==Z&&data->Total())return data->GetSize();
00181   }
00182 }    
00183 int ReactorNeutrons::GetElastSize(int Z,int A){
00184   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00185     if(data->GetA()==A&&data->GetZ()==Z&&data->Elastic())return data->GetSize();
00186   }
00187 }    
00188 int ReactorNeutrons::GetGammaSize(int Z,int A){
00189   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00190     if(data->GetA()==A&&data->GetZ()==Z&&data->Gamma())return data->GetSize();
00191   }
00192 }    
00193 //
00194 //
00195 //
00196 double* ReactorNeutrons::GetTotalKE(int Z,int A){
00197   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00198     if(data->GetA()==A&&data->GetZ()==Z&&data->Total())return data->GetKE();
00199   }
00200 }    
00201 double* ReactorNeutrons::GetElastKE(int Z,int A){
00202   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00203     if(data->GetA()==A&&data->GetZ()==Z&&data->Elastic())return data->GetKE();
00204   }
00205 }    
00206 double* ReactorNeutrons::GetGammaKE(int Z,int A){
00207   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00208     if(data->GetA()==A&&data->GetZ()==Z&&data->Gamma())return data->GetKE();
00209   }
00210 }    
00211 //
00212 double* ReactorNeutrons::GetTotalXC(int Z,int A){
00213   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00214     if(data->GetA()==A&&data->GetZ()==Z&&data->Total())return data->GetXC();
00215   }
00216 }    
00217 double* ReactorNeutrons::GetElastXC(int Z,int A){
00218   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00219     if(data->GetA()==A&&data->GetZ()==Z&&data->Elastic())return data->GetXC();
00220   }
00221 }    
00222 double* ReactorNeutrons::GetGammaXC(int Z,int A){
00223   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00224     if(data->GetA()==A&&data->GetZ()==Z&&data->Gamma())return data->GetXC();
00225   }
00226 }    
00227 //
00228 //
00229 //
00230 double* ReactorNeutrons::GetLastKE(int Z,int A,char option){
00231   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00232     if(data->GetA()==A&&data->GetZ()==Z&&option=='T'&&data->Total()){
00233       return data->GetLastKE();
00234     }
00235     if(data->GetA()==A&&data->GetZ()==Z&&option=='E'&&data->Elastic()){
00236       return data->GetLastKE();
00237     }
00238     if(data->GetA()==A&&data->GetZ()==Z&&option=='G'&&data->Gamma()){
00239       return data->GetLastKE();
00240     }
00241   } 
00242 }
00243 double* ReactorNeutrons::GetLastXC(int Z,int A,char option){
00244   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00245     if(data->GetA()==A&&data->GetZ()==Z&&option=='T'&&data->Total()){
00246       return data->GetLastXC();
00247     }
00248     if(data->GetA()==A&&data->GetZ()==Z&&option=='E'&&data->Elastic()){
00249       return data->GetLastXC();
00250     }
00251     if(data->GetA()==A&&data->GetZ()==Z&&option=='G'&&data->Gamma()){
00252       return data->GetLastXC();
00253     }
00254   } 
00255 }
00256 //
00257 void ReactorNeutrons::SetLastData(int Z,int A,char option,double* lastKE,double* lastXC){
00258   for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00259     if(data->GetA()==A&&data->GetZ()==Z&&option=='T'&&data->Total()){
00260       data->SetLastKE(lastKE);
00261       data->SetLastXC(lastXC);
00262       return;
00263     }
00264     if(data->GetA()==A&&data->GetZ()==Z&&option=='E'&&data->Elastic()){
00265       data->SetLastKE(lastKE);
00266       data->SetLastXC(lastXC);
00267       return;
00268     }
00269     if(data->GetA()==A&&data->GetZ()==Z&&option=='G'&&data->Gamma()){
00270       data->SetLastKE(lastKE);
00271       data->SetLastXC(lastXC);
00272       return;
00273     }
00274   } 
00275 }
00276 double ReactorNeutrons::GetXC(int Z,int A,double ke,char option){
00277   double xc=1e-6;
00278   //
00279   double* KE;
00280   double* XC;
00281   if(option=='T'){
00282     KE=GetTotalKE(Z,A);
00283     XC=GetTotalXC(Z,A);
00284   }
00285   if(option=='E'){
00286     KE=GetElastKE(Z,A);
00287     XC=GetElastXC(Z,A);
00288   }
00289   if(option=='G'){
00290     KE=GetGammaKE(Z,A);
00291     XC=GetGammaXC(Z,A);
00292   }
00293   //
00294   double* LastKE=GetLastKE(Z,A,option);
00295   double* LastXC=GetLastXC(Z,A,option);
00296   //
00297   if(ke<*KE){
00298     return *XC;
00299   }
00300   else if(ke<*LastKE){
00301     double* xcptr=LastXC;
00302     for(double* keptr=LastKE;keptr>KE;keptr--){
00303       if(ke<*keptr && ke>*(keptr-1)){
00304         xc=*(xcptr-1)+(*xcptr-*(xcptr-1))/(*keptr-*(keptr-1))*(ke-*(keptr-1));
00305         SetLastData(Z,A,option,keptr,xcptr);
00306         return xc;
00307       }
00308       xcptr--;
00309     }
00310   }
00311   else{
00312     int size;
00313     if(option=='T')size=GetTotalSize(Z,A);
00314     if(option=='E')size=GetElastSize(Z,A);
00315     if(option=='G')size=GetGammaSize(Z,A);
00316     double *xcptr=LastXC;
00317     for(double* keptr=LastKE;keptr<KE+size-1;keptr++){
00318       if(ke<*(keptr+1) && ke>*keptr){
00319         xc=*xcptr+(*(xcptr+1)-*xcptr)/(*(keptr+1)-*keptr)*(ke-*keptr);
00320         SetLastData(Z,A,option,keptr,xcptr);
00321         return xc;
00322       }
00323       ++xcptr;
00324     }
00325   }
00326   return xc;
00327 }

Generated on Thu Jul 29 14:27:03 2004 for ReactorFsim by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002