G4ITModelHandler.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id: G4ITModelHandler.cc 64057 2012-10-30 15:04:49Z gcosmo $
00027 //
00028 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 
00029 //
00030 // History:
00031 // -----------
00032 // 10 Oct 2011 M.Karamitros created
00033 //
00034 // -------------------------------------------------------------------
00035 
00036 #include "G4ITModelHandler.hh"
00037 #include <assert.h>
00038 
00039 G4ITModelHandler::G4ITModelHandler()
00040 {
00041     //ctor
00042     fIsInitialized = false;
00043     fTimeStepComputerFlag = false;
00044     fReactionProcessFlag = false;
00045 
00046     size_t IT_size (G4ITType::size());
00047 
00048     fModelManager.assign(IT_size, std::vector<G4ITModelManager*>());
00049     for(G4int i = 0 ; i < (int) IT_size ; i++)
00050     {
00051         fModelManager[i].assign(IT_size,0);
00052     }
00053 }
00054 
00055 G4ITModelHandler::~G4ITModelHandler()
00056 {
00057     //dtor
00058     G4int size = fModelManager.size();
00059 
00060     for(G4int i = 0 ; i < size ; i++)
00061     {
00062         for(G4int j = 0 ; j <= i ; j++)
00063         {
00064             if(fModelManager[i][j])
00065             {
00066                 delete fModelManager[i][j];
00067                 fModelManager[i][j] = 0;
00068                 fModelManager[j][i] = 0;
00069             }
00070         }
00071     }
00072     fModelManager.clear();
00073 }
00074 
00075 G4ITModelHandler::G4ITModelHandler(const G4ITModelHandler& other)
00076 {
00077     //copy ctor
00078     size_t IT_size (G4ITType::size());
00079 
00080     fModelManager.assign(IT_size, std::vector<G4ITModelManager*>());
00081     for(int i = 0 ; i < (int) IT_size ; i++)
00082     {
00083         fModelManager[i].assign(IT_size,0);
00084         for(int j = 0 ; j < (int) IT_size ; j++)
00085         {
00086             if(other.fModelManager[i][j] != 0)
00087             {
00088                 fModelManager[i][j] = new G4ITModelManager(*(other.fModelManager[i][j])) ;
00089             }
00090         }
00091     }
00092 
00093     fIsInitialized = other.fIsInitialized;
00094     fTimeStepComputerFlag = other.fTimeStepComputerFlag;
00095     fReactionProcessFlag = other.fReactionProcessFlag;
00096 }
00097 
00098 G4ITModelHandler& G4ITModelHandler::operator=(const G4ITModelHandler& rhs)
00099 {
00100     if (this == &rhs) return *this; // handle self assignment
00101     //assignment operator
00102     return *this;
00103 }
00104 
00105 void G4ITModelHandler::Initialize()
00106 {
00107     fIsInitialized = true;
00108 
00109     for(G4int i = 0 ; i < int(fModelManager.size()) ; i++)
00110     {
00111         for(G4int j = 0 ; j <= i ; j++)
00112         {
00113             G4ITModelManager* modman = fModelManager[i][j];
00114             if(modman)
00115             {
00116                 modman->Initialize();
00117             }
00118         }
00119     }
00120 }
00121 
00122 void G4ITModelHandler::RegisterModel(
00123     G4VITModel* aModel,
00124     G4double startingTime)
00125 {
00126     assert(aModel != 0);
00127 
00128     //________________________________________________
00129     // Prepare the correct model manager
00130     if( fModelManager.empty() )
00131     {
00132         size_t IT_size (G4ITType::size());
00133         fModelManager.assign(IT_size, std::vector<G4ITModelManager*>());
00134 
00135         for(int i = 0 ; i < (int) IT_size ; i++)
00136         {
00137             fModelManager[i].assign((size_t) i,0);
00138         }
00139     }
00140 
00141     G4ITType type1;
00142     G4ITType type2;
00143 
00144     //________________________________________________
00145     // Retrieve applicability
00146     aModel->IsApplicable(type1, type2);
00147 
00148     if(type1 > type2)
00149     {
00150         G4ITType buffer(-1);
00151         buffer = type1;
00152         type1 = type2;
00153         type2 = buffer;
00154     }
00155 
00156     if(fModelManager[type1][type2] == 0)
00157     {
00158         fModelManager[type1][type2] = new G4ITModelManager();
00159     }
00160 
00161     fModelManager[type1][type2]-> SetModel(aModel, startingTime);
00162 
00163     //________________________________________________
00164     // Setup ITStepManager
00165     if(aModel->GetTimeStepper())
00166     {
00167         fTimeStepComputerFlag = true;
00168     }
00169     if(aModel->GetReactionProcess())
00170     {
00171         fReactionProcessFlag = true;
00172     }
00173 }
00174 
00175 void G4ITModelHandler::SetModel(G4ITType type1,
00176                               G4ITType type2,
00177                               G4VITModel* aModel,
00178                               G4double startingTime)
00179 {
00180     assert(aModel == 0);
00181 
00182     if(type1 > type2)
00183     {
00184         G4ITType buffer(-1);
00185         buffer = type1;
00186         type1 = type2;
00187         type2 = buffer;
00188     }
00189 
00190     if(type1 > (int) fModelManager.capacity())
00191     {
00192         fModelManager.reserve(type1);
00193     }
00194 
00195     if(type2 > (int) fModelManager[type1].capacity())
00196     {
00197         fModelManager[type1].reserve(type2);
00198     }
00199 
00200     fModelManager[type1][type2] -> SetModel(aModel, startingTime);
00201 }
00202 
00203 
00204 G4VITModel* G4ITModelHandler::GetModel(G4ITType type1,
00205                                      G4ITType type2,
00206                                      const G4double globalTime)
00207 {
00208     if(fModelManager.empty())
00209     {
00210         return 0;
00211     }
00212 
00213     if((int) fModelManager.size() < type1) return 0;
00214 
00215     std::vector<G4ITModelManager*>* v = &(fModelManager.at(type1));
00216 
00217     if((int) v->size() < type2) return 0;
00218 
00219     if(v->at(type2))
00220     {
00221         return v->at(type2)->GetModel(globalTime);
00222     }
00223     return 0;
00224 }

Generated on Mon May 27 17:48:41 2013 for Geant4 by  doxygen 1.4.7