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 cout << " Cross Section data for " << Process
00084 <<" from file " << FileName
00085 << " for A= " << A
00086 << " and Z= " << Z << endl;
00087
00088 }
00089 ReactorNeutrons::XCdata::~XCdata(){
00090 delete[] KE;
00091 delete[] XC;
00092 }
00093 ReactorNeutrons::XCdata::XCdata(const ReactorNeutrons::XCdata& X){
00094
00095 A=X.A;
00096 Z=X.Z;
00097
00098 strcpy(FileName,X.FileName);
00099 strcpy(Process,X.Process);
00100
00101 Size = X.Size;
00102
00103 KE = new double[Size];
00104 XC = new double[Size];
00105
00106 LastKE = KE+Size-1;
00107 LastXC = XC+Size-1;
00108
00109 double* pold = X.KE+Size;
00110 double* pnew = KE+Size;
00111 while(pnew>KE)*--pnew=*--pold;
00112
00113 pold = X.XC+Size;
00114 pnew = XC+Size;
00115 while(pnew>XC)*--pnew=*--pold;
00116 }
00117
00118
00119
00120 ReactorNeutrons::XCdata&
00121 ReactorNeutrons::XCdata::operator=(const ReactorNeutrons::XCdata& rhs){
00122
00123 if(this==&rhs)return *this;
00124
00125 A=rhs.A;
00126 Z=rhs.Z;
00127
00128 strcpy(FileName,rhs.FileName);
00129 strcpy(Process,rhs.Process);
00130
00131 Size = rhs.Size;
00132 delete[] KE;
00133 delete[] XC;
00134
00135 KE = new double[Size];
00136 XC = new double[Size];
00137
00138 LastKE = KE+Size-1;
00139 LastXC = XC+Size-1;
00140
00141 double* pold = rhs.KE+Size;
00142 double* pnew = KE+Size;
00143 while(pnew>KE)*--pnew=*--pold;
00144
00145 pold = rhs.XC+Size;
00146 pnew = XC+Size;
00147 while(pnew>XC)*--pnew=*--pold;
00148
00149 return *this;
00150 }
00151
00152
00153
00154 void ReactorNeutrons::AddData(char* file1,char* file2,char* file3){
00155 ReactorNeutrons::XCdata d1(file1);
00156 *DataPtr++=d1;
00157 ReactorNeutrons::XCdata d2(file2);
00158 *DataPtr++=d2;
00159 ReactorNeutrons::XCdata d3(file3);
00160 *DataPtr++=d3;
00161 }
00162
00163 void ReactorNeutrons::XCdata::GetData(const char* file,int& size,double* e,double* xc){
00164 size=0;
00165 double* eptr=e;
00166 double* xcptr=xc;
00167 ifstream infile(file);
00168 while(infile.good()){
00169 infile>> *eptr++ >> *xcptr++;size++;
00170 }
00171 size-=1;
00172 infile.close();
00173 }
00174
00175
00176
00177 int ReactorNeutrons::GetTotalSize(int Z,int A){
00178 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00179 if(data->GetA()==A&&data->GetZ()==Z&&data->Total())return data->GetSize();
00180 }
00181 }
00182 int ReactorNeutrons::GetElastSize(int Z,int A){
00183 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00184 if(data->GetA()==A&&data->GetZ()==Z&&data->Elastic())return data->GetSize();
00185 }
00186 }
00187 int ReactorNeutrons::GetGammaSize(int Z,int A){
00188 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00189 if(data->GetA()==A&&data->GetZ()==Z&&data->Gamma())return data->GetSize();
00190 }
00191 }
00192
00193
00194
00195 double* ReactorNeutrons::GetTotalKE(int Z,int A){
00196 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00197 if(data->GetA()==A&&data->GetZ()==Z&&data->Total())return data->GetKE();
00198 }
00199 }
00200 double* ReactorNeutrons::GetElastKE(int Z,int A){
00201 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00202 if(data->GetA()==A&&data->GetZ()==Z&&data->Elastic())return data->GetKE();
00203 }
00204 }
00205 double* ReactorNeutrons::GetGammaKE(int Z,int A){
00206 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00207 if(data->GetA()==A&&data->GetZ()==Z&&data->Gamma())return data->GetKE();
00208 }
00209 }
00210
00211 double* ReactorNeutrons::GetTotalXC(int Z,int A){
00212 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00213 if(data->GetA()==A&&data->GetZ()==Z&&data->Total())return data->GetXC();
00214 }
00215 }
00216 double* ReactorNeutrons::GetElastXC(int Z,int A){
00217 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00218 if(data->GetA()==A&&data->GetZ()==Z&&data->Elastic())return data->GetXC();
00219 }
00220 }
00221 double* ReactorNeutrons::GetGammaXC(int Z,int A){
00222 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00223 if(data->GetA()==A&&data->GetZ()==Z&&data->Gamma())return data->GetXC();
00224 }
00225 }
00226
00227
00228
00229 double* ReactorNeutrons::GetLastKE(int Z,int A,char option){
00230 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00231 if(data->GetA()==A&&data->GetZ()==Z&&option=='T'&&data->Total()){
00232 return data->GetLastKE();
00233 }
00234 if(data->GetA()==A&&data->GetZ()==Z&&option=='E'&&data->Elastic()){
00235 return data->GetLastKE();
00236 }
00237 if(data->GetA()==A&&data->GetZ()==Z&&option=='G'&&data->Gamma()){
00238 return data->GetLastKE();
00239 }
00240 }
00241 }
00242 double* ReactorNeutrons::GetLastXC(int Z,int A,char option){
00243 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00244 if(data->GetA()==A&&data->GetZ()==Z&&option=='T'&&data->Total()){
00245 return data->GetLastXC();
00246 }
00247 if(data->GetA()==A&&data->GetZ()==Z&&option=='E'&&data->Elastic()){
00248 return data->GetLastXC();
00249 }
00250 if(data->GetA()==A&&data->GetZ()==Z&&option=='G'&&data->Gamma()){
00251 return data->GetLastXC();
00252 }
00253 }
00254 }
00255
00256 void ReactorNeutrons::SetLastData(int Z,int A,char option,double* lastKE,double* lastXC){
00257 for(ReactorNeutrons::XCdata* data = Data;data<Data+DataSize;data++){
00258 if(data->GetA()==A&&data->GetZ()==Z&&option=='T'&&data->Total()){
00259 data->SetLastKE(lastKE);
00260 data->SetLastXC(lastXC);
00261 return;
00262 }
00263 if(data->GetA()==A&&data->GetZ()==Z&&option=='E'&&data->Elastic()){
00264 data->SetLastKE(lastKE);
00265 data->SetLastXC(lastXC);
00266 return;
00267 }
00268 if(data->GetA()==A&&data->GetZ()==Z&&option=='G'&&data->Gamma()){
00269 data->SetLastKE(lastKE);
00270 data->SetLastXC(lastXC);
00271 return;
00272 }
00273 }
00274 }
00275 double ReactorNeutrons::GetXC(int Z,int A,double ke,char option){
00276 double xc=1e-6;
00277
00278 double* KE;
00279 double* XC;
00280 if(option=='T'){
00281 KE=GetTotalKE(Z,A);
00282 XC=GetTotalXC(Z,A);
00283 }
00284 if(option=='E'){
00285 KE=GetElastKE(Z,A);
00286 XC=GetElastXC(Z,A);
00287 }
00288 if(option=='G'){
00289 KE=GetGammaKE(Z,A);
00290 XC=GetGammaXC(Z,A);
00291 }
00292
00293 double* LastKE=GetLastKE(Z,A,option);
00294 double* LastXC=GetLastXC(Z,A,option);
00295
00296 if(ke<*KE){
00297 return *XC;
00298 }
00299 else if(ke<*LastKE){
00300 double* xcptr=LastXC;
00301 for(double* keptr=LastKE;keptr>KE;keptr--){
00302 if(ke<*keptr && ke>*(keptr-1)){
00303 xc=*(xcptr-1)+(*xcptr-*(xcptr-1))/(*keptr-*(keptr-1))*(ke-*(keptr-1));
00304 SetLastData(Z,A,option,keptr,xcptr);
00305 return xc;
00306 }
00307 xcptr--;
00308 }
00309 }
00310 else{
00311 int size;
00312 if(option=='T')size=GetTotalSize(Z,A);
00313 if(option=='E')size=GetElastSize(Z,A);
00314 if(option=='G')size=GetGammaSize(Z,A);
00315 double *xcptr=LastXC;
00316 for(double* keptr=LastKE;keptr<KE+size-1;keptr++){
00317 if(ke<*(keptr+1) && ke>*keptr){
00318 xc=*xcptr+(*(xcptr+1)-*xcptr)/(*(keptr+1)-*keptr)*(ke-*keptr);
00319 SetLastData(Z,A,option,keptr,xcptr);
00320 return xc;
00321 }
00322 ++xcptr;
00323 }
00324 }
00325 return xc;
00326 }