Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4DNAChemistryManager.cc
이 파일의 문서화 페이지로 가기
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: G4DNAChemistryManager.cc 103042 2017-03-10 11:50:07Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara@cenbg.in2p3.fr)
29 //
30 // WARNING : This class is released as a prototype.
31 // It might strongly evolve or even disapear in the next releases.
32 //
33 // History:
34 // -----------
35 // 10 Oct 2011 M.Karamitros created
36 //
37 // -------------------------------------------------------------------
38 
39 #include "G4DNAChemistryManager.hh"
40 
41 #include "G4Scheduler.hh"
42 #include "G4SystemOfUnits.hh"
43 #include "G4Molecule.hh"
44 #include "G4VITTrackHolder.hh"
45 #include "G4H2O.hh"
49 #include "G4Electron_aq.hh"
51 #include "G4VMoleculeCounter.hh"
52 #include "G4VUserChemistryList.hh"
53 #include "G4AutoLock.hh"
54 #include "G4UIcmdWithABool.hh"
57 #include "G4GeometryManager.hh"
58 #include "G4StateManager.hh"
59 #include "G4MoleculeFinder.hh"
60 #include "G4MoleculeTable.hh"
61 #include "G4PhysChemIO.hh"
62 
63 using namespace std;
64 
66 
69 
71 
72 //------------------------------------------------------------------------------
73 
75 {
76  fpPhysChemIO = nullptr;
77  fThreadInitialized_tl = false;
78 }
79 
80 //------------------------------------------------------------------------------
81 
83 {
84  if(fpPhysChemIO) delete fpPhysChemIO;
85  fThreadInitialized_tl = false;
86 }
87 
88 //------------------------------------------------------------------------------
89 
91 {
92  if(fpThreadData->fpPhysChemIO)
93  delete fpThreadData->fpPhysChemIO;
94  fpThreadData->fpPhysChemIO = physChemIO;
95 }
96 
97 //------------------------------------------------------------------------------
98 
101 {
102 
103 //------------------------------------------------------------------------------
104 /*
105  * The chemistry manager is shared between threads
106  * It is initialized both on the master thread and on the worker threads
107  */
108 //------------------------------------------------------------------------------
109 
110  fpExcitationLevel = 0;
111  fpIonisationLevel = 0;
113  fMasterInitialized = false;
114  fpChemDNADirectory = new G4UIdirectory("/chem/");
115  fpActivateChem = new G4UIcmdWithABool("/chem/activate", this);
116  fpRunChem = new G4UIcmdWithoutParameter("/chem/run", this);
117  //fpGridSize = new G4UIcmdWithADoubleAndUnit("/chem/gridRes", this);
118  fpScaleForNewTemperature = new G4UIcmdWithADoubleAndUnit("/chem/temperature",
119  this);
121  new G4UIcmdWithoutParameter("/chem/skipReactionsFromChemList", this);
122  fpInitChem = new G4UIcmdWithoutParameter("/chem/init", this);
123  //fDefaultGridResolution = -1;
124  fBuildPhysicsTable = false;
125  fGeometryClosed = false;
126  fPhysicsTableBuilt = false;
128  fVerbose = 0;
129  fActiveChemistry = false;
130  fSkipReactions = false;
132 }
133 
134 //------------------------------------------------------------------------------
135 
138 {
139  if(fgInstance == 0)
140  {
142  if (fgInstance == 0) // MT : double check at initialisation
143  {
145  }
146  lock.unlock();
147  }
148 
150  // make sure thread local data is initialized for all threads
151 
152  return fgInstance;
153 }
154 
155 //------------------------------------------------------------------------------
156 
159 {
160  return fgInstance;
161 }
162 
163 //------------------------------------------------------------------------------
164 
166 {
167 // G4cout << "Deleting G4DNAChemistryManager" << G4endl;
168  Clear();
169  fgInstance = 0;
170  /*
171  * DEBUG : check that the chemistry manager has well been deregistered
172  * assert(G4StateManager::GetStateManager()->
173  * DeregisterDependent(this) == true);
174  */
175 }
176 
177 //------------------------------------------------------------------------------
178 
180 {
181  if (fpIonisationLevel)
182  {
183  delete fpIonisationLevel;
184  fpIonisationLevel = 0;
185 
186  }
187  if (fpExcitationLevel)
188  {
189  delete fpExcitationLevel;
190  fpExcitationLevel = 0;
191  }
193  {
195  {
196  delete fpUserChemistryList;
197  }
198 // else
199 // {
200 // G4cout << "G4DNAChemistryManager will not delete the chemistry list "
201 // "since it inherits from G4VPhysicsConstructor and it is then "
202 // "expected to be the responsability to the G4VModularPhysics to handle"
203 // " the chemistry list." << G4endl;
204 // }
206  }
207  if (fpChemDNADirectory)
208  {
209  delete fpChemDNADirectory;
210  fpChemDNADirectory = 0;
211  }
212  if (fpActivateChem)
213  {
214  delete fpActivateChem;
215  fpActivateChem = 0;
216  }
217  if(fpRunChem)
218  {
219  delete fpRunChem;
220  fpRunChem = 0;
221  }
223  {
226  }
227  if(fpInitChem)
228  {
229  delete fpInitChem;
230  fpInitChem = 0;
231  }
232 
234  //G4MoleculeHandleManager::DeleteInstance();
237 }
238 
239 //------------------------------------------------------------------------------
240 
242 {
243  //G4cout << "G4DNAChemistryManager::DeleteInstance" << G4endl;
244 
246 
247  if(fgInstance)
248  {
249  G4DNAChemistryManager* deleteMe = fgInstance;
250  fgInstance = 0;
251  lock.unlock();
252  delete deleteMe;
253  }
254  else
255  {
256  G4cout << "G4DNAChemistryManager already deleted" << G4endl;
257  }
258  lock.unlock();
259 }
260 
261 //------------------------------------------------------------------------------
262 
264 {
265  if (requestedState == G4State_Quit)
266  {
267  if(fVerbose)
268  G4cout << "G4DNAChemistryManager::Notify ---> received G4State_Quit"
269  << G4endl;
270  //DeleteInstance();
271  Clear();
272  }
273 // else if(requestedState == G4State_EventProc)
274 // Note: From here we can know that a new event is started
275 // But the run and event IDs remain unknown
276 // {
277 // if(fpThreadData->fpPhysChemIO)
278 // {
279 //
280 // }
281 // }
282  else if(requestedState == G4State_GeomClosed)
283  {
284  fGeometryClosed = true;
285  }
286 
287  else if (requestedState == G4State_Idle)
288  {
290  }
291 
292  return true;
293 }
294 
295 //------------------------------------------------------------------------------
296 
298 {
299  if (command == fpActivateChem)
300  {
302  }
303  else if (command == fpRunChem)
304  {
305  Run();
306  }
307  /*
308  else if(command == fpGridSize)
309  {
310  fDefaultGridResolution = fpGridSize->ConvertToDimensionedDouble(value);
311  }*/
312  else if (command == fpSkipReactionsFromChemList)
313  {
314  fSkipReactions = true;
315  }
316  else if(command == fpScaleForNewTemperature)
317  {
319  ConvertToDimensionedDouble(value));
320  }
321  else if(command == fpInitChem)
322  {
323  Initialize();
325  }
326 }
327 
328 //------------------------------------------------------------------------------
329 
331 {
332  if (command == fpActivateChem)
333  {
335  }
336 
337  return "";
338 }
339 
340 //------------------------------------------------------------------------------
341 
343 {
344  if (fActiveChemistry)
345  {
347 
348  if (fMasterInitialized == false)
349  {
350  G4ExceptionDescription description;
351  description << "Global components were not initialized.";
352  G4Exception("G4DNAChemistryManager::Run", "MASTER_INIT", FatalException,
353  description);
354  }
355 
357  {
358  G4ExceptionDescription description;
359  description << "Thread local components were not initialized.";
360  G4Exception("G4DNAChemistryManager::Run", "THREAD_INIT", FatalException,
361  description);
362  }
363 
367  {
369  }
370  CloseFile();
371  }
372 }
373 
374 //------------------------------------------------------------------------------
375 
376 void G4DNAChemistryManager::Gun(G4ITGun* gun, bool physicsTableToBuild)
377 {
378  fBuildPhysicsTable = physicsTableToBuild;
380 }
381 
382 //------------------------------------------------------------------------------
383 
385 {
386  //===========================================================================
387  // MT MODE
388  //===========================================================================
390  {
391  //==========================================================================
392  // ON WORKER THREAD
393  //==========================================================================
395  {
396  InitializeThread(); // Will create and initialize G4Scheduler
397  return;
398  }
399  //==========================================================================
400  // ON MASTER THREAD
401  //==========================================================================
402  else
403  {
405  return;
406  }
407  }
408  //===========================================================================
409  // IS NOT IN MT MODE
410  //===========================================================================
411  else
412  {
414  // In this case: InitializeThread is called when Run() is called
415  return;
416  }
417 
418 }
419 
420 //------------------------------------------------------------------------------
421 
423 {
424  if (fMasterInitialized == false)
425  {
426  if(fVerbose)
427  {
428  G4cout << "G4DNAChemistryManager::InitializeMaster() is called" << G4endl;
429  }
430 
432  // creates a concrete object of the scheduler
433 
435  {
437  if(fSkipReactions == false)
438  {
441  }
442  else
443  {
445  }
446  fMasterInitialized = true;
447  }
448  else
449  {
450  if (fActiveChemistry)
451  {
452  G4ExceptionDescription description;
453  description << "No user chemistry list has been provided.";
454  G4Exception("G4DNAChemistryManager::InitializeMaster", "NO_CHEM_LIST",
455  FatalException, description);
456  }
457  }
458  }
459 }
460 
461 //------------------------------------------------------------------------------
462 
464 {
465  if (fpThreadData->fThreadInitialized_tl == false
466  || fForceThreadReinitialization == true)
467  {
469  {
470  if(fVerbose)
471  {
472  G4cout << "G4DNAChemistryManager::InitializeThread() is called"
473  << G4endl;
474  }
475 
476  if (fBuildPhysicsTable && fPhysicsTableBuilt == false)
477  {
478  if(fVerbose)
479  {
480  G4cout << "G4DNAChemistryManager: Build the physics tables for "
481  "molecules."
482  << G4endl;
483  }
484 
486  if (fGeometryClosed == false)
487  {
488  if(fVerbose)
489  {
490  G4cout << "G4DNAChemistryManager: Close geometry"
491  << G4endl;
492  }
493 
495  // G4cout << "Start closing geometry." << G4endl;
496  geomManager->OpenGeometry();
497  geomManager->CloseGeometry(true, true);
498  fGeometryClosed = true;
499  }
500 
501  fPhysicsTableBuilt = true;
502  }
506 
508  }
509  else
510  {
511  G4ExceptionDescription description;
512  description << "No user chemistry list has been provided.";
513  G4Exception("G4DNAChemistryManager::InitializeThread", "NO_CHEM_LIST",
514  FatalException, description);
515  }
516 
518  }
519 
520  InitializeFile();
521 }
522 
523 //------------------------------------------------------------------------------
524 
526 {
527  if(fVerbose)
528  {
529  G4cout << "G4DNAChemistryManager::InitializeFile() is called"
530  << G4endl;
531  }
532 
535  }
536 }
537 
538 //------------------------------------------------------------------------------
539 
541 {
542  return Instance()->fActiveChemistry;
543 }
544 
545 //------------------------------------------------------------------------------
546 
548 {
549  Instance()->fActiveChemistry = flag;
550 }
551 
552 //------------------------------------------------------------------------------
553 
555 {
556  return fActiveChemistry;
557 }
558 
559 //------------------------------------------------------------------------------
560 
562 {
563  fActiveChemistry = flag;
564 }
565 
566 //------------------------------------------------------------------------------
567 
569  ios_base::openmode mode)
570 {
571  if (fVerbose)
572  {
573  G4cout << "G4DNAChemistryManager: Write chemical stage into "
574  << output.data() << G4endl;
575  }
576 
578  fpThreadData->fpPhysChemIO->WriteInto(output, mode);
579  }
580  else{
582  fpThreadData->fpPhysChemIO->WriteInto(output, mode);
583  }
584 }
585 
586 //------------------------------------------------------------------------------
587 
589 {
592  }
593 }
594 
595 //------------------------------------------------------------------------------
596 
598 {
601  }
602 }
603 
604 //------------------------------------------------------------------------------
605 
608 {
609  if (!fpExcitationLevel)
610  {
612  }
613  return fpExcitationLevel;
614 }
615 
616 //------------------------------------------------------------------------------
617 
620 {
621  if (!fpIonisationLevel)
622  {
624  }
625  return fpIonisationLevel;
626 }
627 
628 //------------------------------------------------------------------------------
629 
630 void
632  G4int electronicLevel,
633  const G4Track* theIncomingTrack)
634 {
636  G4double energy = -1.;
637 
638  switch (modification)
639  {
641  energy = 0;
642  break;
643  case eExcitedMolecule:
644  energy = GetExcitationLevel()->ExcitationEnergy(electronicLevel);
645  break;
646  case eIonizedMolecule:
647  energy = GetIonisationLevel()->IonisationEnergy(electronicLevel);
648  break;
649  }
650 
652  4-electronicLevel,
653  energy,
654  theIncomingTrack);
655  }
656 
657  if(fActiveChemistry)
658  {
659  G4Molecule * H2O = new G4Molecule (G4H2O::Definition());
660 
661  switch (modification)
662  {
664  H2O -> AddElectron(5,1);
665  break;
666  case eExcitedMolecule :
667  H2O -> ExciteMolecule(4-electronicLevel);
668  break;
669  case eIonizedMolecule :
670  H2O -> IonizeMolecule(4-electronicLevel);
671  break;
672  }
673 
674  G4Track * H2OTrack = H2O->BuildTrack(1*picosecond,
675  theIncomingTrack->GetPosition());
676 
677  H2OTrack -> SetParentID(theIncomingTrack->GetTrackID());
678  H2OTrack -> SetTrackStatus(fStopButAlive);
679  H2OTrack -> SetKineticEnergy(0.);
680  G4VITTrackHolder::Instance()->Push(H2OTrack);
681  }
682 }
683 
684 //------------------------------------------------------------------------------
685 
686 void
688  G4ThreeVector* finalPosition)
689 // finalPosition is a pointer because this argument is optional
690 {
693  finalPosition);
694  }
695 
696  if(fActiveChemistry)
697  {
699  G4Track * e_aqTrack(0);
700  if(finalPosition)
701  {
702  e_aqTrack = e_aq->BuildTrack(picosecond,*finalPosition);
703  }
704  else
705  {
706  e_aqTrack = e_aq->BuildTrack(picosecond,theIncomingTrack->GetPosition());
707  }
708  e_aqTrack -> SetTrackStatus(fAlive);
709  e_aqTrack -> SetParentID(theIncomingTrack->GetTrackID());
710  G4VITTrackHolder::Instance()->Push(e_aqTrack);
711  }
712 }
713 
714 //------------------------------------------------------------------------------
715 
717  double time,
718  const G4ThreeVector& position,
719  int parentID)
720 {
721  // TODO: PhysChemIO - method unused in the released code
722 
723  if(fActiveChemistry)
724  {
725  G4Track* track = molecule->BuildTrack(time,position);
726  track -> SetTrackStatus(fAlive);
727  track -> SetParentID(parentID);
729  }
730  else
731  {
732  delete molecule;
733  molecule = 0;
734  }
735 }
736 
737 //------------------------------------------------------------------------------
738 
739 
742  const G4Track* theIncomingTrack)
743 {
744  // TODO: PhysChemIO - method unused in the released code
745 
746  if(fActiveChemistry)
747  {
748  G4Track* track = molecule->BuildTrack(theIncomingTrack->GetGlobalTime(),
749  theIncomingTrack->GetPosition());
750  track -> SetTrackStatus(fAlive);
751  track -> SetParentID(theIncomingTrack->GetTrackID());
753  }
754  else
755  {
756  delete molecule;
757  molecule = 0;
758  }
759 }
760 
761 //------------------------------------------------------------------------------
762 
764 {
767  ScaleReactionRateForNewTemperature(temp_K);
768 }
769 
static G4MoleculeTable * Instance()
ElectronicModification
static G4DNAMolecularReactionTable * Instance()
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
void Gun(G4ITGun *, bool physicsTableToBuild=true)
G4UIcmdWithoutParameter * fpSkipReactionsFromChemList
void Finalize(G4MoleculeDefinition *)
virtual G4bool Notify(G4ApplicationState requestedState)
#define G4endl
Definition: G4ios.hh:61
G4DNAWaterExcitationStructure * GetExcitationLevel()
static G4DNAChemistryManager * GetInstanceIfExists()
void SetGlobalTemperature(G4double temp_K)
void WriteInto(const G4String &, std::ios_base::openmode mode=std::ios_base::out)
G4int GetTrackID() const
static G4Electron_aq * Definition()
G4UIdirectory * fpChemDNADirectory
virtual void CreateSolvatedElectron(const G4Track *, G4ThreeVector *finalPosition=0)=0
void SetGun(G4ITGun *)
Definition: G4Scheduler.hh:418
#define G4ThreadLocal
Definition: tls.hh:69
static void SetGlobalTemperature(G4double)
static G4bool GetNewBoolValue(const char *paramString)
G4UIcmdWithoutParameter * fpInitChem
G4DNAWaterIonisationStructure * GetIonisationLevel()
virtual G4String GetCurrentValue(G4UIcommand *command)
void CreateSolvatedElectron(const G4Track *, G4ThreeVector *finalPosition=0)
virtual void CloseFile()=0
void Initialize()
Definition: G4Scheduler.cc:282
void PushMoleculeAtParentTimeAndPlace(G4Molecule *&molecule, const G4Track *)
static G4DNAChemistryManager * fgInstance
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
const XML_Char int const XML_Char * value
Definition: expat.h:331
G4bool IsWorkerThread()
Definition: G4Threading.cc:129
static G4VITTrackHolder * Instance()
static G4GeometryManager * GetInstance()
const char * data() const
G4double GetGlobalTime() const
void CreateWaterMolecule(ElectronicModification, G4int, const G4Track *)
double energy
Definition: plottest35.C:25
const G4ThreeVector & GetPosition() const
virtual void ConstructDissociationChannels()
static void DeleteInstance()
void OpenGeometry(G4VPhysicalVolume *vol=0)
G4Mutex chemManExistence
static void Activated(G4bool flag=true)
void PrepareMolecularConfiguration()
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:374
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4VUserChemistryList * fpUserChemistryList
G4bool IsMultithreadedApplication()
Definition: G4Threading.cc:136
G4UIcmdWithABool * fpActivateChem
int G4int
Definition: G4Types.hh:78
virtual void ConstructTimeStepModel(G4DNAMolecularReactionTable *reactionTable)=0
void Process()
Definition: G4Scheduler.cc:377
virtual void CreateWaterMolecule(G4int electronicModif, G4int, G4double energy, const G4Track *)=0
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=0)
static G4H2O * Definition()
Definition: G4H2O.cc:46
G4GLOB_DLL std::ostream G4cout
G4UIcmdWithoutParameter * fpRunChem
G4ApplicationState
virtual void Push(G4Track *)
virtual void ResetCounter()=0
G4UIcmdWithADoubleAndUnit * fpScaleForNewTemperature
virtual void ConstructReactionTable(G4DNAMolecularReactionTable *reactionTable)=0
virtual void InitializeFile()=0
virtual void SetNewValue(G4UIcommand *, G4String)
static G4DNAMolecularReactionTable * GetReactionTable()
G4Track * BuildTrack(G4double globalTime, const G4ThreeVector &Position)
Definition: G4Molecule.cc:395
G4DNAWaterExcitationStructure * fpExcitationLevel
static constexpr double picosecond
Definition: G4SIunits.hh:161
virtual void WriteInto(const G4String &, std::ios_base::openmode mode=std::ios_base::out)=0
static G4DNAChemistryManager * Instance()
G4DNAWaterIonisationStructure * fpIonisationLevel
static G4Scheduler * Instance()
Definition: G4Scheduler.cc:102
static void InitializeInstance()
static G4ThreadLocal ThreadLocalData * fpThreadData
void SetPhysChemIO(G4VPhysChemIO *physChemIO)
static G4VMoleculeCounter * Instance()
virtual void AddEmptyLineInOuputFile()
void PushMolecule(G4Molecule *&molecule, G4double time, const G4ThreeVector &position, G4int parentID)
std::mutex G4Mutex
Definition: G4Threading.hh:84