00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "G4ITModelProcessor.hh"
00037 #include "G4VITTimeStepper.hh"
00038 #include "G4VITReactionProcess.hh"
00039
00040 std::map<const G4Track*, G4bool> G4ITModelProcessor::fHasReacted ;
00041
00042 G4ITModelProcessor::G4ITModelProcessor()
00043 {
00044
00045 fpTrack = 0;
00046 fpModelHandler = 0;
00047 fpModel = 0;
00048 fInitialized = false;
00049 fpModelManager = 0;
00050 fCurrentModel.assign(G4ITType::size(), std::vector<G4VITModel*>());
00051
00052 for(int i = 0 ; i < (int) G4ITType::size() ; i++)
00053 {
00054 fCurrentModel[i].assign(G4ITType::size(),0);
00055 }
00056 fUserMinTimeStep = -1.;
00057 }
00058
00059 G4ITModelProcessor::~G4ITModelProcessor()
00060 {
00061
00062
00063 fCurrentModel.clear();
00064 fReactionInfo.clear();
00065 }
00066
00067
00068 G4ITModelProcessor::G4ITModelProcessor(const G4ITModelProcessor& )
00069 {
00070
00071 fpTrack = 0;
00072 fpModelHandler = 0;
00073 fpModel = 0;
00074 fInitialized = false;
00075 fpModelManager = 0;
00076 fUserMinTimeStep = -1.;
00077 }
00078
00079
00080 G4ITModelProcessor& G4ITModelProcessor::operator=(const G4ITModelProcessor& rhs)
00081 {
00082 if (this == &rhs) return *this;
00083
00084 return *this;
00085 }
00086
00087 void G4ITModelProcessor::Initialize()
00088 {
00089 fpModelHandler->Initialize();
00090 fInitialized = true;
00091 }
00092
00093
00094 void G4ITModelProcessor::InitializeStepper(const G4double& currentGlobalTime,
00095 const G4double& userMinTime)
00096 {
00097
00098 if(fpModelHandler==0)
00099 {
00100 G4ExceptionDescription exceptionDescription ;
00101 exceptionDescription << "No G4ITModelHandler was passed to the modelProcessor.";
00102 G4Exception("G4ITModelProcessor::InitializeStepper","ITModelProcessor002",
00103 FatalErrorInArgument,exceptionDescription);
00104 }
00105 const std::vector<std::vector<G4ITModelManager*> >* modelManager = fpModelHandler
00106 ->GetAllModelManager();
00107
00108 if(modelManager==0)
00109 {
00110 G4ExceptionDescription exceptionDescription ;
00111 exceptionDescription << "No G4ITModelManager was register to G4ITModelHandler.";
00112 G4Exception("G4ITModelProcessor::InitializeStepper","ITModelProcessor003",
00113 FatalErrorInArgument,exceptionDescription);
00114 }
00115
00116 int nbModels1 = modelManager->size() ;
00117
00118 G4VITTimeStepper::SetTimes(currentGlobalTime, userMinTime) ;
00119
00120
00121
00122 {
00123 int nbModels2 = -1;
00124 G4VITModel* model = 0;
00125 G4ITModelManager* modman = 0;
00126
00127 for(int i = 0 ; i < nbModels1 ; i++)
00128 {
00129 nbModels2 = (*modelManager)[i].size();
00130
00131 for(int j = 0 ; j <= i ; j++)
00132 {
00133 modman = (*modelManager)[i][j];
00134
00135 if(modman == 0) continue ;
00136
00137 model = modman -> GetModel(currentGlobalTime);
00138 G4VITTimeStepper* stepper = model->GetTimeStepper() ;
00139
00140
00141 stepper -> Prepare() ;
00142 fCurrentModel[i][j] = model;
00143 }
00144 }
00145
00146 if(nbModels1 == 1 && nbModels2 ==1)
00147 {
00148 fpModelManager = modman;
00149 fpModel = model;
00150 }
00151 else fpModel = 0;
00152 }
00153 }
00154
00155
00156 void G4ITModelProcessor::CalculateTimeStep(const G4Track* track, const G4double userMinTimeStep)
00157 {
00158
00159 CleanProcessor();
00160 if(track == 0)
00161 {
00162 G4ExceptionDescription exceptionDescription ;
00163 exceptionDescription << "No track was passed to the method (track == 0).";
00164 G4Exception("G4ITModelProcessor::CalculateStep","ITModelProcessor004",
00165 FatalErrorInArgument,exceptionDescription);
00166 }
00167 SetTrack(track);
00168 fUserMinTimeStep = userMinTimeStep ;
00169
00170 DoCalculateStep();
00171 }
00172
00173
00174 void G4ITModelProcessor::DoCalculateStep()
00175 {
00176 if(fpModel)
00177 {
00178 fpModel -> GetTimeStepper()->CalculateStep(*fpTrack, fUserMinTimeStep);
00179 }
00180 else
00181 {
00182 std::vector<G4VITModel*>& model = fCurrentModel[GetIT(fpTrack)->GetITType()];
00183
00184 for(int i =0 ; i < (int) model.size() ; i++)
00185 {
00186 if(model[i] == 0) continue;
00187 model[i]->GetTimeStepper()->CalculateStep(*fpTrack, fUserMinTimeStep);
00188 }
00189 }
00190 }
00191
00192
00193 void G4ITModelProcessor::FindReaction(std::map<G4Track*, G4TrackVectorHandle>* tracks,
00194 const double currentStepTime,
00195 const double previousStepTime,
00196 const bool reachedUserStepTimeLimit)
00197 {
00198
00199
00200 if(tracks == 0) return ;
00201
00202 if(fpModelHandler->GetAllModelManager()->empty()) return ;
00203
00204 std::map<G4Track*, G4TrackVectorHandle>::iterator tracks_i = tracks->begin();;
00205
00206 for(tracks_i = tracks->begin() ; tracks_i != tracks-> end() ; tracks_i ++)
00207 {
00209 G4Track* trackA = tracks_i->first;
00210
00211 if(trackA == 0) continue;
00212
00213 std::map<const G4Track*, G4bool>::iterator it_hasReacted = fHasReacted.find(trackA);
00214 if(it_hasReacted != fHasReacted.end()) continue;
00215 if(trackA->GetTrackStatus() == fStopAndKill) continue;
00216
00217 G4IT* ITA = GetIT(trackA);
00218 G4ITType ITypeA = ITA -> GetITType();
00219
00220 const std::vector<G4VITModel*> model = fCurrentModel[ITypeA];
00221
00222 G4TrackVectorHandle& trackB_vector = tracks_i->second ;
00223 std::vector<G4Track*>::iterator trackB_i = trackB_vector->begin();
00224
00225 G4Track* trackB = 0 ;
00226 G4ITType ITypeB(-1);
00227 G4VITReactionProcess* process = 0;
00228 G4ITReactionChange* changes = 0;
00229
00230 for(; trackB_i != trackB_vector->end() ; trackB_i++)
00231 {
00232 trackB = *trackB_i;
00233
00234 if(trackB == 0) continue;
00235 it_hasReacted = fHasReacted.find(trackB);
00236 if(it_hasReacted != fHasReacted.end()) continue;
00237 if(trackB->GetTrackStatus() == fStopAndKill) continue;
00238
00239
00240
00241
00242
00243
00244
00245
00246 if(trackB == trackA)
00247 {
00248 G4ExceptionDescription exceptionDescription ;
00249 exceptionDescription << "The IT reaction process sent back a reaction between trackA and trackB. ";
00250 exceptionDescription << "The problem is trackA == trackB";
00251 G4Exception("G4ITModelProcessor::FindReaction","ITModelProcessor005",
00252 FatalErrorInArgument,exceptionDescription);
00253 }
00254
00255 G4IT* ITB = GetIT(trackB);
00256 G4ITType ITypeBtmp = ITB -> GetITType();
00257
00258 if(ITypeB != ITypeBtmp)
00259 {
00260 ITypeB = ITypeBtmp ;
00261
00262 if(model[ITypeB])
00263 process = model[ITypeB]->GetReactionProcess();
00264 }
00265
00266 if(process && process -> TestReactibility(*trackA, *trackB,
00267 currentStepTime, previousStepTime,
00268 reachedUserStepTimeLimit))
00269 {
00270 changes = process->MakeReaction(*trackA, *trackB);
00271 }
00272
00273 if(changes)
00274 {
00275 fHasReacted[trackA] = true;
00276 fHasReacted[trackB] = true;
00277 changes -> GetTrackA();
00278 changes -> GetTrackB();
00279
00280 fReactionInfo.push_back(changes);
00281
00282 process->ResetChanges();
00283 changes = 0;
00284
00285 break;
00286 }
00287 }
00288 }
00289
00290 fHasReacted.clear();
00291 }