Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
#ifndef G4DNAEventSet_hh
|
||||
#define G4DNAEventSet_hh 1
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <G4memory.hh>
|
||||
#include "G4Track.hh"
|
||||
#include <set>
|
||||
#include "G4DNAMesh.hh"
|
||||
#include <variant>
|
||||
class G4DNAMolecularReactionTable;
|
||||
class G4DNAMolecularReactionData;
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
using Index = G4Voxel::Index;
|
||||
using MolType = const G4MolecularConfiguration*;
|
||||
using JumpingData = std::pair<MolType, Index>;
|
||||
using ReactionData = const G4DNAMolecularReactionData;
|
||||
|
||||
// to test C++17
|
||||
// using Data = std::variant<std::unique_ptr<JumpingData>, ReactionData*>
|
||||
using Data = std::pair<std::unique_ptr<JumpingData>, ReactionData*>;
|
||||
|
||||
Event(G4double time, unsigned int key, ReactionData*);
|
||||
Event(G4double time, unsigned int key, std::unique_ptr<JumpingData>&&);
|
||||
|
||||
virtual ~Event();
|
||||
G4double GetTime() const { return fTimeStep; }
|
||||
unsigned int GetKey() const { return fKey; }
|
||||
void PrintEvent() const;
|
||||
|
||||
JumpingData* GetJumpingData() const { return std::get<0>(fData).get(); }
|
||||
|
||||
ReactionData* GetReactionData() const { return std::get<1>(fData); }
|
||||
|
||||
private:
|
||||
G4double fTimeStep;
|
||||
unsigned int fKey;
|
||||
Data fData;
|
||||
};
|
||||
|
||||
struct comparatorEventSet
|
||||
{
|
||||
G4bool operator()(std::unique_ptr<Event> const& rhs,
|
||||
std::unique_ptr<Event> const& lhs) const;
|
||||
};
|
||||
|
||||
class IEventSet
|
||||
{
|
||||
public:
|
||||
IEventSet() = default;
|
||||
~IEventSet() = default;
|
||||
};
|
||||
|
||||
class G4DNAEventSet : public IEventSet
|
||||
{
|
||||
public:
|
||||
using Key = unsigned int;
|
||||
using EventSet = std::set<std::unique_ptr<Event>, comparatorEventSet>;
|
||||
using EventMap = std::map<Key, EventSet::iterator>;
|
||||
G4DNAEventSet();
|
||||
virtual ~G4DNAEventSet();
|
||||
|
||||
void CreateEvent(G4double time, Key index,
|
||||
Event::ReactionData* pReactionData);
|
||||
void CreateEvent(G4double time, Key index,
|
||||
std::unique_ptr<Event::JumpingData> jum);
|
||||
|
||||
void AddEvent(std::unique_ptr<Event> pEvent);
|
||||
void RemoveEventSet()
|
||||
{
|
||||
fEventSet.clear();
|
||||
fEventMap.clear();
|
||||
}
|
||||
void RemoveEventOfVoxel(const size_t& key);
|
||||
|
||||
EventSet::iterator end() { return fEventSet.end(); }
|
||||
EventSet::iterator begin() { return fEventSet.begin(); }
|
||||
|
||||
EventSet::reverse_iterator rend() { return fEventSet.rend(); }
|
||||
EventSet::reverse_iterator rbegin() { return fEventSet.rbegin(); }
|
||||
|
||||
EventSet::const_iterator end() const { return fEventSet.end(); }
|
||||
|
||||
EventSet::const_iterator begin() const { return fEventSet.begin(); }
|
||||
|
||||
size_t size() { return fEventSet.size(); }
|
||||
|
||||
G4bool Empty() { return fEventSet.empty(); }
|
||||
|
||||
void RemoveEvent(EventSet::iterator iter);
|
||||
[[maybe_unused]] void PrintEventSet();
|
||||
|
||||
private:
|
||||
EventSet fEventSet;
|
||||
EventMap fEventMap;
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,156 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
#ifndef G4DNAMesh_hh
|
||||
#define G4DNAMesh_hh 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4DNABoundingBox.hh"
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include "G4MolecularConfiguration.hh"
|
||||
#include "G4Track.hh"
|
||||
|
||||
class G4Voxel
|
||||
{
|
||||
public:
|
||||
struct Index
|
||||
{
|
||||
Index()
|
||||
: x(0)
|
||||
, y(0)
|
||||
, z(0)
|
||||
{}
|
||||
Index(int x0, int y0, int z0)
|
||||
: x(x0)
|
||||
, y(y0)
|
||||
, z(z0)
|
||||
{}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& stream, const Index& rhs)
|
||||
{
|
||||
stream << "(" << rhs.x << ", " << rhs.y << ", " << rhs.z << ")";
|
||||
return stream;
|
||||
}
|
||||
G4bool operator==(const Index& rhs) const
|
||||
{
|
||||
return x == rhs.x && y == rhs.y && z == rhs.z;
|
||||
}
|
||||
G4bool operator!=(const Index& rhs) const
|
||||
{
|
||||
return x != rhs.x || y != rhs.y || z != rhs.z;
|
||||
}
|
||||
Index operator+(const Index& rhs) const
|
||||
{
|
||||
return { x + rhs.x, y + rhs.y, z + rhs.z };
|
||||
}
|
||||
int x, y, z;
|
||||
};
|
||||
using MolType = const G4MolecularConfiguration*;
|
||||
using MapList = std::map<MolType, size_t>;
|
||||
|
||||
G4Voxel(MapList&& list, Index& index, G4DNABoundingBox&& box)
|
||||
: fMapList(std::move(list))
|
||||
, fIndex(index)
|
||||
, fBox(std::move(box))
|
||||
{}
|
||||
|
||||
~G4Voxel() = default;
|
||||
|
||||
const Index& GetIndex() const { return fIndex; }
|
||||
|
||||
MapList& GetMapList() { return fMapList; }
|
||||
|
||||
void SetMapList(MapList&& mapList) { fMapList = std::move(mapList); }
|
||||
|
||||
G4double GetVolume() const
|
||||
{
|
||||
auto xlo = fBox.Getxlo();
|
||||
auto ylo = fBox.Getylo();
|
||||
auto zlo = fBox.Getzlo();
|
||||
|
||||
auto xhi = fBox.Getxhi();
|
||||
auto yhi = fBox.Getyhi();
|
||||
auto zhi = fBox.Getzhi();
|
||||
|
||||
return (xhi - xlo) * (yhi - ylo) * (zhi - zlo);
|
||||
}
|
||||
|
||||
private:
|
||||
MapList fMapList;
|
||||
Index fIndex;
|
||||
G4DNABoundingBox fBox;
|
||||
};
|
||||
|
||||
class G4DNAMesh
|
||||
{
|
||||
public:
|
||||
using Index = G4Voxel::Index;
|
||||
using Key = unsigned int;
|
||||
using VoxelMap = std::map<Key, G4Voxel*>;
|
||||
G4DNAMesh(const G4DNABoundingBox&, G4int);
|
||||
~G4DNAMesh();
|
||||
|
||||
Key GetKey(const G4ThreeVector& pos) const;
|
||||
Index GetIndex(Key key) const;
|
||||
Index GetIndex(const G4ThreeVector& position) const;
|
||||
|
||||
G4Voxel* GetVoxel(Key key);
|
||||
[[maybe_unused]] G4Voxel* GetVoxel(const Index& index);
|
||||
size_t size() { return fMesh.size(); }
|
||||
Index GetIndex(const Index& index, int) const;
|
||||
std::vector<Index> FindVoxelNeighbors(const Index& index) const;
|
||||
std::vector<Index> FindNeighboringVoxels(const Index& index) const;
|
||||
void Reset();
|
||||
|
||||
G4Voxel::MapList& GetVoxelMapList(Key key);
|
||||
G4Voxel::MapList& GetVoxelMapList(const Index& index);
|
||||
|
||||
Key GetKey(const Index& index) const;
|
||||
VoxelMap::iterator end() { return fMesh.end(); }
|
||||
VoxelMap::iterator begin() { return fMesh.begin(); }
|
||||
VoxelMap::const_iterator end() const { return fMesh.end(); }
|
||||
VoxelMap::const_iterator begin() const { return fMesh.begin(); }
|
||||
|
||||
void PrintMesh();
|
||||
void PrintVoxel(const Index& index);
|
||||
const G4DNABoundingBox& GetBoundingBox() const;
|
||||
G4DNABoundingBox GetBoundingBox(const Index& index);
|
||||
G4int GetNumberOfType(G4Voxel::MolType type) const;
|
||||
void SetVoxelMapList(const Key& key, G4Voxel::MapList&& mapList);
|
||||
|
||||
G4double GetResolution() const;
|
||||
|
||||
private:
|
||||
VoxelMap fMesh;
|
||||
const G4DNABoundingBox* fpBoundingMesh;
|
||||
G4double fResolution;
|
||||
};
|
||||
#endif
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "G4ITReactionTable.hh"
|
||||
#include "G4MolecularConfiguration.hh"
|
||||
#include "G4ReferenceCast.hh"
|
||||
#include "G4VDNAMolecularGeometry.hh"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
@@ -208,6 +209,9 @@ public:
|
||||
|
||||
void SetReaction(G4DNAMolecularReactionData*);
|
||||
|
||||
void SetGeometry(G4VDNAMolecularGeometry* geometry){fGeometry = geometry;};
|
||||
G4VDNAMolecularGeometry* GetGeometry() const;
|
||||
|
||||
Data* GetReactionData(Reactant*, Reactant*) const;
|
||||
|
||||
Data* GetReactionData(const G4String&, const G4String&) const;
|
||||
@@ -238,6 +242,7 @@ public:
|
||||
protected:
|
||||
G4bool fVerbose;
|
||||
|
||||
G4VDNAMolecularGeometry* fGeometry;
|
||||
ReactionDataMap fReactionData;
|
||||
ReactivesMV fReactantsMV;
|
||||
ReactionDataMV fReactionDataMV;
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
#ifndef G4DNASCAVENGERMATERIAL_HH
|
||||
#define G4DNASCAVENGERMATERIAL_HH
|
||||
#include "globals.hh"
|
||||
#include "G4ios.hh"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "G4MoleculeCounter.hh"
|
||||
#include "G4VScavengerMaterial.hh"
|
||||
class G4Material;
|
||||
class G4MolecularConfiguration;
|
||||
class G4VChemistryWorld;
|
||||
|
||||
using NbMoleculeAgainstTime =
|
||||
std::map<G4double, G4int, G4::MoleculeCounter::TimePrecision>;
|
||||
|
||||
class G4DNAScavengerMaterial : public G4VScavengerMaterial
|
||||
{
|
||||
public:
|
||||
using MolType = const G4MolecularConfiguration*;
|
||||
using MaterialMap = std::map<MolType, G4double>;
|
||||
using ReactantList = std::vector<MolType>;
|
||||
using CounterMapType = std::map<MolType, NbMoleculeAgainstTime>;
|
||||
G4DNAScavengerMaterial() = default;
|
||||
explicit G4DNAScavengerMaterial(G4VChemistryWorld*);
|
||||
~G4DNAScavengerMaterial() override = default;
|
||||
G4DNAScavengerMaterial(const G4DNAScavengerMaterial& right) = delete;
|
||||
G4DNAScavengerMaterial& operator=(const G4DNAScavengerMaterial&) = delete;
|
||||
void Initialize();
|
||||
|
||||
void ReduceNumberMoleculePerVolumeUnitForMaterialConf(MolType, G4double);
|
||||
void AddNumberMoleculePerVolumeUnitForMaterialConf(MolType, G4double);
|
||||
G4double GetNumberMoleculePerVolumeUnitForMaterialConf(MolType) const;
|
||||
|
||||
void AddAMoleculeAtTime(MolType, G4double time,
|
||||
const G4ThreeVector* position = nullptr,
|
||||
G4int number = 1);
|
||||
void RemoveAMoleculeAtTime(MolType, G4double time,
|
||||
const G4ThreeVector* position = nullptr,
|
||||
G4int number = 1);
|
||||
|
||||
void Reset() override;
|
||||
|
||||
void PrintInfo();
|
||||
|
||||
MaterialMap::iterator end() { return fScavengerTable.end(); }
|
||||
MaterialMap::iterator begin() { return fScavengerTable.begin(); }
|
||||
size_t size() { return fScavengerTable.size(); }
|
||||
|
||||
G4bool find(MolType type)
|
||||
{
|
||||
auto it = fScavengerTable.find(type);
|
||||
if(it != fScavengerTable.end())
|
||||
{
|
||||
return it->second > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void SetCounterAgainstTime() { fCounterAgainstTime = true; }
|
||||
|
||||
std::vector<MolType> GetScavengerList() const
|
||||
{
|
||||
std::vector<MolType> output;
|
||||
for(const auto& it : fScavengerTable)
|
||||
{
|
||||
output.push_back(it.first);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
void Dump();
|
||||
G4int GetNMoleculesAtTime(MolType molecule, G4double time);
|
||||
G4bool SearchTimeMap(MolType molecule);
|
||||
G4int SearchUpperBoundTime(G4double time, G4bool sameTypeOfMolecule);
|
||||
|
||||
private:
|
||||
G4VChemistryWorld* fpChemistryInfo;
|
||||
G4bool fIsInitialized;
|
||||
std::map<MolType, G4double> fScavengerTable;
|
||||
CounterMapType fCounterMap;
|
||||
G4bool fCounterAgainstTime;
|
||||
G4int fVerbose;
|
||||
struct Search
|
||||
{
|
||||
Search() { fLowerBoundSet = false; }
|
||||
CounterMapType::iterator fLastMoleculeSearched;
|
||||
NbMoleculeAgainstTime::iterator fLowerBoundTime;
|
||||
G4bool fLowerBoundSet;
|
||||
};
|
||||
|
||||
std::unique_ptr<Search> fpLastSearch;
|
||||
};
|
||||
#endif // G4DNASCAVENGERMATERIAL_HH
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef G4VCHEMISTRYWORLD_HH
|
||||
#define G4VCHEMISTRYWORLD_HH
|
||||
|
||||
#include <memory>
|
||||
#include <map>
|
||||
class G4DNABoundingBox;
|
||||
class G4Material;
|
||||
class G4MolecularConfiguration;
|
||||
class G4VChemistryWorld
|
||||
{
|
||||
public:
|
||||
using MolType = const G4MolecularConfiguration*;
|
||||
G4VChemistryWorld() = default;
|
||||
virtual ~G4VChemistryWorld() = default;
|
||||
|
||||
virtual void ConstructChemistryBoundary() = 0;
|
||||
virtual void ConstructChemistryComponents() = 0;
|
||||
|
||||
std::map<MolType,double>::iterator begin()
|
||||
{
|
||||
return fpChemicalComponent.begin();
|
||||
}
|
||||
|
||||
std::map<MolType,double>::iterator end()
|
||||
{
|
||||
return fpChemicalComponent.end();
|
||||
}
|
||||
|
||||
size_t size()
|
||||
{
|
||||
return fpChemicalComponent.size();
|
||||
}
|
||||
|
||||
std::map<MolType,double>::const_iterator begin_const()
|
||||
{
|
||||
return fpChemicalComponent.begin();
|
||||
}
|
||||
|
||||
std::map<MolType,double>::const_iterator end_const()
|
||||
{
|
||||
return fpChemicalComponent.end();
|
||||
}
|
||||
|
||||
G4DNABoundingBox* GetChemistryBoundary() const
|
||||
{
|
||||
return fpChemistryBoundary.get();
|
||||
}
|
||||
protected:
|
||||
std::unique_ptr<G4DNABoundingBox> fpChemistryBoundary;
|
||||
std::map<MolType,double> fpChemicalComponent;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -28,7 +28,11 @@ geant4_add_module(G4emdna-utils
|
||||
# physchemIO
|
||||
G4VPhysChemIO.hh
|
||||
G4PhysChemIO.hh
|
||||
G4IRTUtils.hh
|
||||
G4IRTUtils.hh
|
||||
G4DNAScavengerMaterial.hh
|
||||
G4VChemistryWorld.hh
|
||||
G4DNAMesh.hh
|
||||
G4DNAEventSet.hh
|
||||
SOURCES
|
||||
G4DNAChemistryManager.cc
|
||||
G4DNACPA100LogLogInterpolation.cc
|
||||
@@ -54,7 +58,10 @@ geant4_add_module(G4emdna-utils
|
||||
# physchemIO
|
||||
G4VPhysChemIO.cc
|
||||
G4PhysChemIO.cc
|
||||
G4IRTUtils.cc)
|
||||
G4IRTUtils.cc
|
||||
G4DNAScavengerMaterial.cc
|
||||
G4DNAMesh.cc
|
||||
G4DNAEventSet.cc)
|
||||
|
||||
geant4_module_link_libraries(G4emdna-utils
|
||||
PUBLIC
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
#include <memory>
|
||||
#include "G4DNAEventSet.hh"
|
||||
#include "globals.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4DNAMolecularReactionTable.hh"
|
||||
|
||||
Event::Event(G4double time, unsigned int key, ReactionData* pReactionData)
|
||||
: fTimeStep(time)
|
||||
, fKey(key)
|
||||
, fData(std::pair<std::unique_ptr<JumpingData>, ReactionData*>(nullptr,
|
||||
pReactionData))
|
||||
{}
|
||||
|
||||
Event::Event(G4double time, unsigned int key,
|
||||
std::unique_ptr<JumpingData>&& jumping)
|
||||
: fTimeStep(time)
|
||||
, fKey(key)
|
||||
, fData(std::pair<std::unique_ptr<JumpingData>, ReactionData*>(
|
||||
std::move(jumping), nullptr))
|
||||
{}
|
||||
|
||||
Event::~Event() = default;
|
||||
|
||||
void Event::PrintEvent() const
|
||||
{
|
||||
G4cout << "****PrintEvent::TimeStep : " << G4BestUnit(fTimeStep, "Time")
|
||||
<< " key : " << fKey << " action : ";
|
||||
if(std::get<0>(fData) == nullptr)
|
||||
{
|
||||
G4cout << std::get<1>(fData)->GetReactant1()->GetName() << " + "
|
||||
<< std::get<1>(fData)->GetReactant2()->GetName() << " -> "
|
||||
<< std::get<1>(fData)->GetProducts()->size() << G4endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
G4cout << std::get<0>(fData)->first->GetName() << " jumping to "
|
||||
<< std::get<0>(fData)->second << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
G4bool comparatorEventSet::operator()(std::unique_ptr<Event> const& rhs,
|
||||
std::unique_ptr<Event> const& lhs) const
|
||||
{
|
||||
return rhs->GetTime() < lhs->GetTime();
|
||||
}
|
||||
|
||||
G4DNAEventSet::G4DNAEventSet()
|
||||
: fEventSet(comparatorEventSet())
|
||||
{}
|
||||
|
||||
void G4DNAEventSet::CreateEvent(G4double time, Key key,
|
||||
Event::ReactionData* pReactionData)
|
||||
{
|
||||
auto pEvent = std::make_unique<Event>(time, key, pReactionData);
|
||||
AddEvent(std::move(pEvent));
|
||||
}
|
||||
|
||||
void G4DNAEventSet::CreateEvent(G4double time, Key key,
|
||||
std::unique_ptr<Event::JumpingData> jum)
|
||||
{
|
||||
auto pEvent = std::make_unique<Event>(time, key, std::move(jum));
|
||||
AddEvent(std::move(pEvent));
|
||||
}
|
||||
|
||||
void G4DNAEventSet::RemoveEventOfVoxel(const size_t& key)
|
||||
{
|
||||
auto it = fEventMap.find(key);
|
||||
if(it != fEventMap.end())
|
||||
{
|
||||
fEventSet.erase(it->second);
|
||||
fEventMap.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void G4DNAEventSet::RemoveEvent(EventSet::iterator iter)
|
||||
{
|
||||
auto key = (*iter)->GetKey();
|
||||
RemoveEventOfVoxel(key);
|
||||
}
|
||||
|
||||
void G4DNAEventSet::AddEvent(std::unique_ptr<Event> pEvent)
|
||||
{
|
||||
// idea is no 2 events in one key (or index)
|
||||
auto key = pEvent->GetKey();
|
||||
RemoveEventOfVoxel(key);
|
||||
auto it = fEventSet.emplace(std::move(pEvent));
|
||||
fEventMap[key] = std::get<0>(it);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________________
|
||||
|
||||
G4DNAEventSet::~G4DNAEventSet() { RemoveEventSet(); }
|
||||
|
||||
[[maybe_unused]] void G4DNAEventSet::PrintEventSet()
|
||||
{
|
||||
G4cout << "G4DNAEventSet::PrintEventSet()" << G4endl;
|
||||
for(const auto& it : fEventSet)
|
||||
{
|
||||
(*it).PrintEvent();
|
||||
}
|
||||
G4cout << "End PrintEventSet()" << G4endl;
|
||||
G4cout << G4endl;
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
#include "G4DNAMesh.hh"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <ostream>
|
||||
|
||||
G4DNAMesh::G4DNAMesh(const G4DNABoundingBox& boundingBox, G4int pixel)
|
||||
: fpBoundingMesh(&boundingBox)
|
||||
, fResolution((2 * boundingBox.halfSideLengthInY() / pixel))
|
||||
{}
|
||||
|
||||
G4DNAMesh::~G4DNAMesh() { Reset(); }
|
||||
|
||||
G4Voxel::MapList& G4DNAMesh::GetVoxelMapList(Key key)
|
||||
{
|
||||
auto iter = fMesh.find(key);
|
||||
if(iter == fMesh.end())
|
||||
{
|
||||
G4Voxel::MapList maplist;
|
||||
SetVoxelMapList(key, std::move(maplist));
|
||||
return GetVoxelMapList(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return iter->second->GetMapList();
|
||||
}
|
||||
}
|
||||
|
||||
G4Voxel::MapList& G4DNAMesh::GetVoxelMapList(const Index& index)
|
||||
{
|
||||
auto key = GetKey(index);
|
||||
return GetVoxelMapList(key);
|
||||
}
|
||||
|
||||
G4DNAMesh::Key G4DNAMesh::GetKey(const Index& index) const
|
||||
{
|
||||
auto xmax = (unsigned int) (std::floor(
|
||||
(fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution));
|
||||
auto ymax = (unsigned int) (std::floor(
|
||||
(fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution));
|
||||
return index.z * ymax * xmax + index.y * xmax + index.x;
|
||||
}
|
||||
|
||||
void G4DNAMesh::PrintMesh()
|
||||
{
|
||||
G4cout << "*********PrintMesh::Size : " << fMesh.size() << G4endl;
|
||||
auto iter = fMesh.begin();
|
||||
for(; iter != fMesh.end(); iter++)
|
||||
{
|
||||
auto index = iter->second->GetIndex();
|
||||
PrintVoxel(index);
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
G4int G4DNAMesh::GetNumberOfType(G4Voxel::MolType type) const
|
||||
{
|
||||
G4int output = 0;
|
||||
auto iter = fMesh.begin();
|
||||
for(; iter != fMesh.end(); iter++)
|
||||
{
|
||||
auto node = dynamic_cast<G4Voxel*>(iter->second);
|
||||
if(node == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
auto it = node->GetMapList().find(type);
|
||||
if(it != node->GetMapList().end())
|
||||
{
|
||||
output += it->second;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
void G4DNAMesh::PrintVoxel(const Index& index)
|
||||
{
|
||||
G4cout << "*********PrintVoxel::";
|
||||
G4cout << "key: " << GetKey(index) << " index : " << index
|
||||
<< " number of type : " << this->GetVoxelMapList(index).size()
|
||||
<< G4endl;
|
||||
|
||||
for(const auto& it : this->GetVoxelMapList(index))
|
||||
{
|
||||
G4cout << "_____________" << it.first->GetName() << " : " << it.second
|
||||
<< G4endl;
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
|
||||
void G4DNAMesh::SetVoxelMapList(const Key& key, G4Voxel::MapList&& mapList)
|
||||
{
|
||||
auto index = GetIndex(key);
|
||||
auto pVoxel = fMesh[key];
|
||||
if(nullptr == pVoxel)
|
||||
{
|
||||
pVoxel = new G4Voxel(std::move(mapList), index, GetBoundingBox(index));
|
||||
fMesh[key] = pVoxel;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(pVoxel->GetMapList().empty()); // check if map list is empty
|
||||
pVoxel->SetMapList(std::move(mapList));
|
||||
}
|
||||
}
|
||||
|
||||
G4Voxel::Index G4DNAMesh::GetIndex(const G4ThreeVector& position) const
|
||||
{
|
||||
int dx = std::floor((position.x() - fpBoundingMesh->Getxlo()) / fResolution);
|
||||
int dy = std::floor((position.y() - fpBoundingMesh->Getylo()) / fResolution);
|
||||
int dz = std::floor((position.z() - fpBoundingMesh->Getzlo()) / fResolution);
|
||||
assert(dx >= 0 && dy >= 0 && dz >= 0);
|
||||
return G4Voxel::Index{ dx, dy, dz };
|
||||
}
|
||||
G4Voxel::Index G4DNAMesh::GetIndex(const Index& index, int pixels) const
|
||||
{
|
||||
int xmax =
|
||||
std::floor((fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution);
|
||||
int ymax =
|
||||
std::floor((fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution);
|
||||
int zmax =
|
||||
std::floor((fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution);
|
||||
int dx = (int) (index.x * pixels / xmax);
|
||||
int dy = (int) (index.y * pixels / ymax);
|
||||
int dz = (int) (index.z * pixels / zmax);
|
||||
assert(dx >= 0 && dy >= 0 && dz >= 0);
|
||||
return Index{ dx, dy, dz };
|
||||
}
|
||||
|
||||
G4DNABoundingBox G4DNAMesh::GetBoundingBox(const Index& index)
|
||||
{
|
||||
auto xlo = fpBoundingMesh->Getxlo() + index.x * fResolution;
|
||||
auto ylo = fpBoundingMesh->Getylo() + index.y * fResolution;
|
||||
auto zlo = fpBoundingMesh->Getzlo() + index.z * fResolution;
|
||||
|
||||
auto xhi = fpBoundingMesh->Getxlo() + (index.x + 1) * fResolution;
|
||||
auto yhi = fpBoundingMesh->Getylo() + (index.y + 1) * fResolution;
|
||||
auto zhi = fpBoundingMesh->Getzlo() + (index.z + 1) * fResolution;
|
||||
return G4DNABoundingBox({ xhi, xlo, yhi, ylo, zhi, zlo });
|
||||
}
|
||||
|
||||
G4Voxel::Index G4DNAMesh::GetIndex(Key key) const
|
||||
{
|
||||
G4int xmax =
|
||||
std::floor((fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution);
|
||||
G4int ymax =
|
||||
std::floor((fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution);
|
||||
G4int id = key;
|
||||
G4int x_ = id % xmax;
|
||||
id /= xmax;
|
||||
G4int y_ = id % ymax;
|
||||
id /= ymax;
|
||||
G4int z_ = id;
|
||||
|
||||
if(xmax != ymax)
|
||||
{
|
||||
G4cout << xmax << " " << ymax << " " << key << G4endl;
|
||||
G4ExceptionDescription exceptionDescription;
|
||||
exceptionDescription << "xmax != ymax";
|
||||
G4Exception("G4DNAMesh::GetIndex", "G4DNAMesh006", FatalErrorInArgument,
|
||||
exceptionDescription);
|
||||
}
|
||||
|
||||
if(x_ < 0 || y_ < 0 || z_ < 0)
|
||||
{
|
||||
G4cout << xmax << " " << ymax << " " << key << G4endl;
|
||||
G4cout << x_ << " " << y_ << " " << z_ << G4endl;
|
||||
G4ExceptionDescription exceptionDescription;
|
||||
exceptionDescription << "x_ < 0 || y_ < 0 || z_ < 0";
|
||||
G4Exception("G4DNAMesh::GetIndex", "G4DNAMesh005", FatalErrorInArgument,
|
||||
exceptionDescription);
|
||||
}
|
||||
return Index{ x_, y_, z_ };
|
||||
}
|
||||
|
||||
void G4DNAMesh::Reset()
|
||||
{
|
||||
if(fMesh.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
for(auto iter : fMesh) // should use smart ptr
|
||||
{
|
||||
delete iter.second;
|
||||
}
|
||||
fMesh.clear();
|
||||
}
|
||||
|
||||
const G4DNABoundingBox& G4DNAMesh::GetBoundingBox() const
|
||||
{
|
||||
return *fpBoundingMesh;
|
||||
}
|
||||
|
||||
G4Voxel* G4DNAMesh::GetVoxel(Key key)
|
||||
{
|
||||
auto it = fMesh.find(key);
|
||||
if(it != fMesh.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
[[maybe_unused]] G4Voxel* G4DNAMesh::GetVoxel(const Index& index)
|
||||
{
|
||||
return GetVoxel(GetKey(index));
|
||||
}
|
||||
|
||||
std::vector<G4Voxel::Index> // array is better ?
|
||||
G4DNAMesh::FindVoxelNeighbors(const Index& index) const
|
||||
{
|
||||
std::vector<Index> neighbors;
|
||||
|
||||
auto xMax = (int) (std::floor(
|
||||
(fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution));
|
||||
auto yMax = (int) (std::floor(
|
||||
(fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution));
|
||||
auto zMax = (int) (std::floor(
|
||||
(fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution));
|
||||
|
||||
auto xmin = (index.x - 1) < 0 ? 0 : (index.x - 1);
|
||||
auto ymin = (index.y - 1) < 0 ? 0 : (index.y - 1);
|
||||
auto zmin = (index.z - 1) < 0 ? 0 : (index.z - 1);
|
||||
|
||||
auto xmax = (index.x + 1) > xMax ? xMax : (index.x + 1);
|
||||
auto ymax = (index.y + 1) > yMax ? yMax : (index.y + 1);
|
||||
auto zmax = (index.z + 1) > zMax ? zMax : (index.z + 1);
|
||||
for(int ix = xmin; ix <= xmax; ix++)
|
||||
{
|
||||
for(int iy = ymin; iy <= ymax; iy++)
|
||||
{
|
||||
for(int iz = zmin; iz <= zmax; iz++)
|
||||
{
|
||||
auto key = iz * yMax * xMax + iy * xMax + ix;
|
||||
if(GetIndex(key) != index)
|
||||
{ // deleting the middle element
|
||||
neighbors.push_back(GetIndex(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(neighbors.empty())
|
||||
{
|
||||
G4ExceptionDescription exceptionDescription;
|
||||
exceptionDescription << "neighbors.empty()";
|
||||
G4Exception("G4DNAMesh::FindVoxelNeighbors", "G4DNAMesh001",
|
||||
FatalErrorInArgument, exceptionDescription);
|
||||
}
|
||||
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
std::vector<G4Voxel::Index> // array is better ?
|
||||
G4DNAMesh::FindNeighboringVoxels(const Index& index) const
|
||||
{
|
||||
std::vector<Index> neighbors;
|
||||
// auto key = GetKey(index);
|
||||
auto xMax = (int) (std::floor(
|
||||
(fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution));
|
||||
auto yMax = (int) (std::floor(
|
||||
(fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution));
|
||||
auto zMax = (int) (std::floor(
|
||||
(fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution));
|
||||
|
||||
if(index.x - 1 >= 0)
|
||||
{
|
||||
neighbors.emplace_back(Index(index.x - 1, index.y, index.z));
|
||||
}
|
||||
if(index.y - 1 >= 0)
|
||||
{
|
||||
neighbors.emplace_back(Index(index.x, index.y - 1, index.z));
|
||||
}
|
||||
if(index.z - 1 >= 0)
|
||||
{
|
||||
neighbors.emplace_back(Index(index.x, index.y, index.z - 1));
|
||||
}
|
||||
if(index.x + 1 < xMax)
|
||||
{
|
||||
neighbors.emplace_back(Index(index.x + 1, index.y, index.z));
|
||||
}
|
||||
if(index.y + 1 < yMax)
|
||||
{
|
||||
neighbors.emplace_back(Index(index.x, index.y + 1, index.z));
|
||||
}
|
||||
if(index.z + 1 < zMax)
|
||||
{
|
||||
neighbors.emplace_back(Index(index.x, index.y, index.z + 1));
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
G4cout << "Neighbors of : " << index << G4endl;
|
||||
for(const auto& it : neighbors)
|
||||
{
|
||||
G4cout << it << G4endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(neighbors.size() > 6)
|
||||
{
|
||||
G4ExceptionDescription exceptionDescription;
|
||||
exceptionDescription << "neighbors.size() > 6";
|
||||
G4Exception("G4DNAMesh::FindVoxelNeighbors", "G4DNAMesh002",
|
||||
FatalErrorInArgument, exceptionDescription);
|
||||
}
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
G4double G4DNAMesh::GetResolution() const { return fResolution; }
|
||||
|
||||
G4DNAMesh::Key G4DNAMesh::GetKey(const G4ThreeVector& position) const
|
||||
{
|
||||
if(!fpBoundingMesh->contains(position))
|
||||
{
|
||||
G4ExceptionDescription exceptionDescription;
|
||||
exceptionDescription << "the position: " << position
|
||||
<< " is not in the box";
|
||||
G4Exception("G4DNAMesh::GetKey", "G4DNAMesh010", FatalErrorInArgument,
|
||||
exceptionDescription);
|
||||
}
|
||||
|
||||
auto dx = std::floor((position.x() - fpBoundingMesh->Getxlo()) / fResolution);
|
||||
auto dy = std::floor((position.y() - fpBoundingMesh->Getylo()) / fResolution);
|
||||
auto dz = std::floor((position.z() - fpBoundingMesh->Getzlo()) / fResolution);
|
||||
auto xmax =
|
||||
std::floor((fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution);
|
||||
auto ymax =
|
||||
std::floor((fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution);
|
||||
return dz * ymax * xmax + dy * xmax + dx;
|
||||
}
|
||||
@@ -382,6 +382,7 @@ void G4DNAMolecularReactionTable::DeleteInstance()
|
||||
G4DNAMolecularReactionTable::G4DNAMolecularReactionTable()
|
||||
: G4ITReactionTable()
|
||||
, fVerbose(false)
|
||||
, fGeometry(nullptr)
|
||||
, fpMessenger(new G4ReactionTableMessenger(this))
|
||||
{
|
||||
}
|
||||
@@ -592,6 +593,11 @@ void G4DNAMolecularReactionTable::PrintTable(G4VDNAReactionModel* pReactionModel
|
||||
//______________________________________________________________________________
|
||||
// Get/Set methods
|
||||
|
||||
G4VDNAMolecularGeometry* G4DNAMolecularReactionTable::GetGeometry() const
|
||||
{
|
||||
return fGeometry;
|
||||
}
|
||||
|
||||
G4DNAMolecularReactionTable::Data*
|
||||
G4DNAMolecularReactionTable::GetReactionData(Reactant* pReactant1,
|
||||
Reactant* pReactant2) const
|
||||
|
||||
@@ -0,0 +1,475 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
#include <memory>
|
||||
#include "G4DNAScavengerMaterial.hh"
|
||||
#include "G4StateManager.hh"
|
||||
#include "G4DNAMolecularMaterial.hh"
|
||||
#include "G4PhysicalConstants.hh"
|
||||
#include "G4MolecularConfiguration.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "G4DNABoundingBox.hh"
|
||||
#include "G4VChemistryWorld.hh"
|
||||
#include "G4Scheduler.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4MoleculeTable.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
G4DNAScavengerMaterial::G4DNAScavengerMaterial(
|
||||
G4VChemistryWorld* pChemistryInfo)
|
||||
: G4VScavengerMaterial()
|
||||
, fpChemistryInfo(pChemistryInfo)
|
||||
, fIsInitialized(false)
|
||||
, fCounterAgainstTime(false)
|
||||
, fVerbose(0)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void G4DNAScavengerMaterial::Initialize()
|
||||
{
|
||||
if(fIsInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(fpChemistryInfo->size() == 0)
|
||||
{
|
||||
G4cout << "G4DNAScavengerMaterial existed but empty" << G4endl;
|
||||
}
|
||||
Reset();
|
||||
fIsInitialized = true;
|
||||
}
|
||||
|
||||
G4double G4DNAScavengerMaterial::GetNumberMoleculePerVolumeUnitForMaterialConf(
|
||||
MolType matConf) const
|
||||
{
|
||||
// no change these molecules
|
||||
if(G4MoleculeTable::Instance()->GetConfiguration("H2O") == matConf)
|
||||
{
|
||||
G4ExceptionDescription exceptionDescription;
|
||||
exceptionDescription << "matConf : "<<matConf->GetName();
|
||||
G4Exception("G4DNAScavengerMaterial::GetNumberMoleculePerVolumeUnitForMaterialConf", "G4DNAScavengerMaterial001",
|
||||
FatalErrorInArgument, exceptionDescription);
|
||||
}
|
||||
|
||||
auto iter = fScavengerTable.find(matConf);
|
||||
if(iter == fScavengerTable.end())
|
||||
{
|
||||
// G4cout<<matConf->GetName()<<G4endl;
|
||||
// throw std::runtime_error("this material is not existed");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(iter->second >= 1)
|
||||
{
|
||||
return (floor)(iter->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void G4DNAScavengerMaterial::ReduceNumberMoleculePerVolumeUnitForMaterialConf(
|
||||
MolType matConf, G4double time)
|
||||
{
|
||||
// no change these molecules
|
||||
if(G4MoleculeTable::Instance()->GetConfiguration("H2O") == matConf ||
|
||||
G4MoleculeTable::Instance()->GetConfiguration("H3Op(B)") ==
|
||||
matConf || // suppose that pH is not changed during simu
|
||||
G4MoleculeTable::Instance()->GetConfiguration("OHm(B)") == matConf)
|
||||
{
|
||||
// G4cout<<"moletype : "<<matConf->GetName()<<G4endl;
|
||||
// kobs is already counted these molecule concentrations
|
||||
return;
|
||||
}
|
||||
if(!find(matConf)) // matConf must greater than 0
|
||||
{
|
||||
return;
|
||||
}
|
||||
fScavengerTable[matConf]--;
|
||||
if(fScavengerTable[matConf] < 0) // projection
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
if(fCounterAgainstTime)
|
||||
{
|
||||
RemoveAMoleculeAtTime(matConf, time);
|
||||
}
|
||||
}
|
||||
|
||||
void G4DNAScavengerMaterial::AddNumberMoleculePerVolumeUnitForMaterialConf(
|
||||
MolType matConf, G4double time)
|
||||
{
|
||||
// no change these molecules
|
||||
|
||||
if(G4MoleculeTable::Instance()->GetConfiguration("H2O") == matConf ||
|
||||
G4MoleculeTable::Instance()->GetConfiguration("H3Op(B)") ==
|
||||
matConf || // pH has no change
|
||||
G4MoleculeTable::Instance()->GetConfiguration("OHm(B)") == matConf)
|
||||
{
|
||||
// G4cout<<"moletype : "<<matConf->GetName()<<G4endl;
|
||||
// kobs is already counted these molecule concentrations
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = fScavengerTable.find(matConf);
|
||||
if(it == fScavengerTable.end()) // matConf must be in fScavengerTable
|
||||
{
|
||||
return;
|
||||
}
|
||||
fScavengerTable[matConf]++;
|
||||
|
||||
if(fCounterAgainstTime)
|
||||
{
|
||||
AddAMoleculeAtTime(matConf, time);
|
||||
}
|
||||
}
|
||||
|
||||
void G4DNAScavengerMaterial::PrintInfo()
|
||||
{
|
||||
auto pConfinedBox = fpChemistryInfo->GetChemistryBoundary();
|
||||
auto iter = fpChemistryInfo->begin();
|
||||
G4cout << "**************************************************************"
|
||||
<< G4endl;
|
||||
for(; iter != fpChemistryInfo->end(); iter++)
|
||||
{
|
||||
auto containedConf = iter->first;
|
||||
// auto concentration = iter->second;
|
||||
auto concentration =
|
||||
fScavengerTable[containedConf] / (Avogadro * pConfinedBox->Volume());
|
||||
G4cout << "Scavenger:" << containedConf->GetName() << " : "
|
||||
<< concentration / 1.0e-6 /*mm3 to L*/ << " (M) with : "
|
||||
<< fScavengerTable[containedConf] << " (molecules)"
|
||||
<< "in: " << pConfinedBox->Volume() / (um * um * um) << " (um3)"
|
||||
<< G4endl;
|
||||
if(fScavengerTable[containedConf] < 1)
|
||||
{
|
||||
G4cout << "!!!!!!!!!!!!! this molecule has less one molecule for "
|
||||
"considered volume"
|
||||
<< G4endl;
|
||||
// assert(false);
|
||||
}
|
||||
if(fVerbose != 0)
|
||||
{
|
||||
Dump();
|
||||
}
|
||||
}
|
||||
G4cout << "**************************************************************"
|
||||
<< G4endl;
|
||||
}
|
||||
|
||||
void G4DNAScavengerMaterial::Reset()
|
||||
{
|
||||
if(fpChemistryInfo == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(fpChemistryInfo->size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fScavengerTable.clear();
|
||||
fCounterMap.clear();
|
||||
fpLastSearch.reset(nullptr);
|
||||
|
||||
auto pConfinedBox = fpChemistryInfo->GetChemistryBoundary();
|
||||
auto iter = fpChemistryInfo->begin();
|
||||
for(; iter != fpChemistryInfo->end(); iter++)
|
||||
{
|
||||
auto containedConf = iter->first;
|
||||
auto concentration = iter->second;
|
||||
fScavengerTable[containedConf] =
|
||||
floor(Avogadro * concentration * pConfinedBox->Volume());
|
||||
fCounterMap[containedConf][1 * picosecond] =
|
||||
floor(Avogadro * concentration * pConfinedBox->Volume());
|
||||
}
|
||||
PrintInfo();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void G4DNAScavengerMaterial::AddAMoleculeAtTime(
|
||||
MolType molecule, G4double time, const G4ThreeVector* /*position*/,
|
||||
int number)
|
||||
{
|
||||
if(fVerbose != 0)
|
||||
{
|
||||
G4cout << "G4DNAScavengerMaterial::AddAMoleculeAtTime : "
|
||||
<< molecule->GetName() << " at time : " << G4BestUnit(time, "Time")
|
||||
<< G4endl;
|
||||
}
|
||||
|
||||
auto counterMap_i = fCounterMap.find(molecule);
|
||||
|
||||
if(counterMap_i == fCounterMap.end())
|
||||
{
|
||||
fCounterMap[molecule][time] = number;
|
||||
}
|
||||
else if(counterMap_i->second.empty())
|
||||
{
|
||||
counterMap_i->second[time] = number;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto end = counterMap_i->second.rbegin();
|
||||
|
||||
if(end->first <= time || fabs(end->first - time) <=
|
||||
G4::MoleculeCounter::TimePrecision::fPrecision)
|
||||
{
|
||||
G4double newValue = end->second + number;
|
||||
counterMap_i->second[time] = newValue;
|
||||
if(newValue != (floor)(fScavengerTable[molecule])) // protection
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
// G4cout<<" AddAMoleculeAtTime : "<<molecule->GetName()<< " :
|
||||
// "<<newValue<<G4endl;
|
||||
}
|
||||
// else
|
||||
// {
|
||||
//
|
||||
// G4ExceptionDescription errMsg;
|
||||
// errMsg << "Time of species "
|
||||
// << molecule->GetName() << " is "
|
||||
// << G4BestUnit(time, "Time") << " while "
|
||||
// << " global time is "
|
||||
// <<" end->first : "<<end->first
|
||||
// //<<
|
||||
// G4BestUnit(G4Scheduler::Instance()->GetGlobalTime(),
|
||||
// "Time")
|
||||
// << G4endl;
|
||||
// G4Exception("G4DNAScavengerMaterial::AddAMoleculeAtTime",
|
||||
// "TIME_DONT_MATCH",
|
||||
// FatalException, errMsg);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void G4DNAScavengerMaterial::RemoveAMoleculeAtTime(
|
||||
MolType pMolecule, G4double time, const G4ThreeVector* /*position*/,
|
||||
int number)
|
||||
{
|
||||
NbMoleculeAgainstTime& nbMolPerTime = fCounterMap[pMolecule];
|
||||
|
||||
if(fVerbose != 0)
|
||||
{
|
||||
auto it_ = nbMolPerTime.rbegin();
|
||||
G4cout << "G4DNAScavengerMaterial::RemoveAMoleculeAtTime : "
|
||||
<< pMolecule->GetName() << " at time : " << G4BestUnit(time, "Time")
|
||||
|
||||
<< " form : " << it_->second << G4endl;
|
||||
}
|
||||
|
||||
if(nbMolPerTime.empty())
|
||||
{
|
||||
Dump();
|
||||
G4String errMsg = "You are trying to remove molecule " +
|
||||
pMolecule->GetName() +
|
||||
" from the counter while this kind of molecules has not "
|
||||
"been registered yet";
|
||||
G4Exception("G4DNAScavengerMaterial::RemoveAMoleculeAtTime", "",
|
||||
FatalErrorInArgument, errMsg);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto it = nbMolPerTime.rbegin();
|
||||
|
||||
if(it == nbMolPerTime.rend())
|
||||
{
|
||||
it--;
|
||||
|
||||
G4String errMsg = "There was no " + pMolecule->GetName() +
|
||||
" recorded at the time or even before the time asked";
|
||||
G4Exception("G4DNAScavengerMaterial::RemoveAMoleculeAtTime", "",
|
||||
FatalErrorInArgument, errMsg);
|
||||
}
|
||||
|
||||
G4double finalN = it->second - number;
|
||||
if(finalN < 0)
|
||||
{
|
||||
Dump();
|
||||
|
||||
G4cout << "fScavengerTable : " << pMolecule->GetName() << " : "
|
||||
<< (fScavengerTable[pMolecule]) << G4endl;
|
||||
|
||||
G4ExceptionDescription errMsg;
|
||||
errMsg << "After removal of " << number << " species of "
|
||||
<< " " << it->second << " " << pMolecule->GetName()
|
||||
<< " the final number at time " << G4BestUnit(time, "Time")
|
||||
<< " is less than zero and so not valid." << G4endl;
|
||||
G4cout << " Global time is "
|
||||
<< G4BestUnit(G4Scheduler::Instance()->GetGlobalTime(), "Time")
|
||||
<< ". Previous selected time is " << G4BestUnit(it->first, "Time")
|
||||
<< G4endl;
|
||||
G4Exception("G4DNAScavengerMaterial::RemoveAMoleculeAtTime", "N_INF_0",
|
||||
FatalException, errMsg);
|
||||
}
|
||||
nbMolPerTime[time] = finalN;
|
||||
|
||||
if(finalN != (floor)(fScavengerTable[pMolecule])) // protection
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void G4DNAScavengerMaterial::Dump()
|
||||
{
|
||||
auto pConfinedBox = fpChemistryInfo->GetChemistryBoundary();
|
||||
auto V = pConfinedBox->Volume();
|
||||
for(auto it : fCounterMap)
|
||||
{
|
||||
auto pReactant = it.first;
|
||||
|
||||
G4cout << " --- > For " << pReactant->GetName() << G4endl;
|
||||
|
||||
for(auto it2 : it.second)
|
||||
{
|
||||
G4cout << " " << G4BestUnit(it2.first, "Time") << " "
|
||||
<< it2.second / (Avogadro * V * 1.0e-6 /*mm3 to L*/) << G4endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int G4DNAScavengerMaterial::GetNMoleculesAtTime(MolType molecule, G4double time)
|
||||
{
|
||||
if(!fCounterAgainstTime)
|
||||
{
|
||||
G4cout << "fCounterAgainstTime == false" << G4endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
G4bool sameTypeOfMolecule = SearchTimeMap(molecule);
|
||||
return SearchUpperBoundTime(time, sameTypeOfMolecule);
|
||||
}
|
||||
|
||||
G4bool G4DNAScavengerMaterial::SearchTimeMap(MolType molecule)
|
||||
{
|
||||
if(fpLastSearch == nullptr)
|
||||
{
|
||||
fpLastSearch = std::make_unique<Search>();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fpLastSearch->fLowerBoundSet &&
|
||||
fpLastSearch->fLastMoleculeSearched->first == molecule)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
auto mol_it = fCounterMap.find(molecule);
|
||||
fpLastSearch->fLastMoleculeSearched = mol_it;
|
||||
|
||||
if(mol_it != fCounterMap.end())
|
||||
{
|
||||
fpLastSearch->fLowerBoundTime =
|
||||
fpLastSearch->fLastMoleculeSearched->second.end();
|
||||
fpLastSearch->fLowerBoundSet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fpLastSearch->fLowerBoundSet = false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int G4DNAScavengerMaterial::SearchUpperBoundTime(G4double time,
|
||||
G4bool sameTypeOfMolecule)
|
||||
{
|
||||
auto mol_it = fpLastSearch->fLastMoleculeSearched;
|
||||
if(mol_it == fCounterMap.end())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NbMoleculeAgainstTime& timeMap = mol_it->second;
|
||||
if(timeMap.empty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(sameTypeOfMolecule)
|
||||
{
|
||||
if(fpLastSearch->fLowerBoundSet &&
|
||||
fpLastSearch->fLowerBoundTime != timeMap.end())
|
||||
{
|
||||
if(fpLastSearch->fLowerBoundTime->first < time)
|
||||
{
|
||||
auto upperToLast = fpLastSearch->fLowerBoundTime;
|
||||
upperToLast++;
|
||||
|
||||
if(upperToLast == timeMap.end())
|
||||
{
|
||||
return fpLastSearch->fLowerBoundTime->second;
|
||||
}
|
||||
|
||||
if(upperToLast->first > time)
|
||||
{
|
||||
return fpLastSearch->fLowerBoundTime->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto up_time_it = timeMap.upper_bound(time);
|
||||
|
||||
if(up_time_it == timeMap.end())
|
||||
{
|
||||
auto last_time = timeMap.rbegin();
|
||||
return last_time->second;
|
||||
}
|
||||
if(up_time_it == timeMap.begin())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
up_time_it--;
|
||||
|
||||
fpLastSearch->fLowerBoundTime = up_time_it;
|
||||
fpLastSearch->fLowerBoundSet = true;
|
||||
|
||||
return fpLastSearch->fLowerBoundTime->second;
|
||||
}
|
||||
Reference in New Issue
Block a user