Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DNAMesh Class Reference

#include <G4DNAMesh.hh>

Inheritance diagram for G4DNAMesh:

Public Types

using Box = G4DNABoundingBox
using MolType = const G4MolecularConfiguration*
using Data = std::map<MolType, size_t>
using Voxel = std::tuple<Index, Box, Data>
using IndexMap = std::unordered_map<Index, G4int, G4VDNAMesh::hashFunc>
using VoxelVector = std::vector<Voxel>

Public Member Functions

 G4DNAMesh (const G4DNABoundingBox &, G4int)
 ~G4DNAMesh () override
Index GetIndex (const G4ThreeVector &position) const
VoxelGetVoxel (const Index &index)
size_t size ()
Index ConvertIndex (const Index &index, const G4int &) const
Index GetRandomIndex (const Index &, const G4double &resolution) const
std::vector< IndexFindNeighboringVoxels (const Index &index) const
void Reset ()
DataGetVoxelMapList (const Index &index)
auto end ()
auto begin ()
VoxelVector::const_iterator const_end () const
VoxelVector::const_iterator const_begin () const
void PrintMesh ()
void PrintVoxel (const Index &index)
const G4DNABoundingBoxGetBoundingBox () const
G4DNABoundingBox GetBoundingBox (const Index &index)
G4int GetNumberOfType (MolType type) const
void InitializeVoxel (const Index &key, Data &&mapList)
G4double GetResolution () const
Public Member Functions inherited from G4VDNAMesh
 G4VDNAMesh ()=default
virtual ~G4VDNAMesh ()=default

Detailed Description

Definition at line 41 of file G4DNAMesh.hh.

Member Typedef Documentation

◆ Box

Definition at line 44 of file G4DNAMesh.hh.

◆ Data

using G4DNAMesh::Data = std::map<MolType, size_t>

Definition at line 46 of file G4DNAMesh.hh.

◆ IndexMap

using G4DNAMesh::IndexMap = std::unordered_map<Index, G4int, G4VDNAMesh::hashFunc>

Definition at line 48 of file G4DNAMesh.hh.

◆ MolType

Definition at line 45 of file G4DNAMesh.hh.

◆ Voxel

using G4DNAMesh::Voxel = std::tuple<Index, Box, Data>

Definition at line 47 of file G4DNAMesh.hh.

◆ VoxelVector

using G4DNAMesh::VoxelVector = std::vector<Voxel>

Definition at line 49 of file G4DNAMesh.hh.

Constructor & Destructor Documentation

◆ G4DNAMesh()

G4DNAMesh::G4DNAMesh ( const G4DNABoundingBox & boundingBox,
G4int pixel )

Definition at line 54 of file G4DNAMesh.cc.

55 : fpBoundingMesh(&boundingBox)
56 , fResolution((2 * boundingBox.halfSideLengthInY() / pixel))
57{}
G4double halfSideLengthInY() const

◆ ~G4DNAMesh()

G4DNAMesh::~G4DNAMesh ( )
override

Definition at line 59 of file G4DNAMesh.cc.

59{ Reset(); }
void Reset()
Definition G4DNAMesh.cc:133

Member Function Documentation

◆ begin()

auto G4DNAMesh::begin ( )
inline

Definition at line 61 of file G4DNAMesh.hh.

61{ return fVoxelVector.begin(); }

◆ const_begin()

VoxelVector::const_iterator G4DNAMesh::const_begin ( ) const
inline

Definition at line 63 of file G4DNAMesh.hh.

64 {
65 return fVoxelVector.begin();
66 }

◆ const_end()

VoxelVector::const_iterator G4DNAMesh::const_end ( ) const
inline

Definition at line 62 of file G4DNAMesh.hh.

62{ return fVoxelVector.end(); }

◆ ConvertIndex()

G4VDNAMesh::Index G4DNAMesh::ConvertIndex ( const Index & index,
const G4int & pixels ) const

Definition at line 214 of file G4DNAMesh.cc.

216{
217 G4int xmax = std::floor(
218 (fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution);
219 G4int ymax = std::floor(
220 (fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution);
221 G4int zmax = std::floor(
222 (fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution);
223 auto dx = (G4int) (index.x * pixels / xmax);
224 auto dy = (G4int) (index.y * pixels / ymax);
225 auto dz = (G4int) (index.z * pixels / zmax);
226 if(dx < 0 || dy < 0 || dz < 0)
227 {
228 G4ExceptionDescription exceptionDescription;
229 exceptionDescription << "the old index: " << index
230 << " to new index : " << Index(dx, dx, dx);
231 G4Exception("G4DNAMesh::CheckIndex", "G4DNAMesh013", FatalErrorInArgument,
232 exceptionDescription);
233 }
234 return Index{ dx, dy, dz };
235}
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
int G4int
Definition G4Types.hh:85

◆ end()

auto G4DNAMesh::end ( )
inline

Definition at line 60 of file G4DNAMesh.hh.

60{ return fVoxelVector.end(); }

◆ FindNeighboringVoxels()

std::vector< G4DNAMesh::Index > G4DNAMesh::FindNeighboringVoxels ( const Index & index) const

Definition at line 145 of file G4DNAMesh.cc.

146{
147 std::vector<Index> neighbors;
148 neighbors.reserve(6);
149 auto xMax = (G4int) (std::floor(
150 (fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution));
151 auto yMax = (G4int) (std::floor(
152 (fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution));
153 auto zMax = (G4int) (std::floor(
154 (fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution));
155
156 if(index.x - 1 >= 0)
157 {
158 neighbors.emplace_back(index.x - 1, index.y, index.z);
159 }
160 if(index.y - 1 >= 0)
161 {
162 neighbors.emplace_back(index.x, index.y - 1, index.z);
163 }
164 if(index.z - 1 >= 0)
165 {
166 neighbors.emplace_back(index.x, index.y, index.z - 1);
167 }
168 if(index.x + 1 < xMax)
169 {
170 neighbors.emplace_back(index.x + 1, index.y, index.z);
171 }
172 if(index.y + 1 < yMax)
173 {
174 neighbors.emplace_back(index.x, index.y + 1, index.z);
175 }
176 if(index.z + 1 < zMax)
177 {
178 neighbors.emplace_back(index.x, index.y, index.z + 1);
179 }
180
181 return neighbors;
182}

◆ GetBoundingBox() [1/2]

const G4DNABoundingBox & G4DNAMesh::GetBoundingBox ( ) const

Definition at line 139 of file G4DNAMesh.cc.

140{
141 return *fpBoundingMesh;
142}

Referenced by GetVoxel().

◆ GetBoundingBox() [2/2]

G4DNABoundingBox G4DNAMesh::GetBoundingBox ( const Index & index)

Definition at line 122 of file G4DNAMesh.cc.

123{
124 auto xlo = fpBoundingMesh->Getxlo() + index.x * fResolution;
125 auto ylo = fpBoundingMesh->Getylo() + index.y * fResolution;
126 auto zlo = fpBoundingMesh->Getzlo() + index.z * fResolution;
127 auto xhi = fpBoundingMesh->Getxlo() + (index.x + 1) * fResolution;
128 auto yhi = fpBoundingMesh->Getylo() + (index.y + 1) * fResolution;
129 auto zhi = fpBoundingMesh->Getzlo() + (index.z + 1) * fResolution;
130 return G4DNABoundingBox({ xhi, xlo, yhi, ylo, zhi, zlo });
131}

◆ GetIndex()

G4DNAMesh::Index G4DNAMesh::GetIndex ( const G4ThreeVector & position) const

Definition at line 186 of file G4DNAMesh.cc.

187{
188 if(!fpBoundingMesh->contains(position))
189 {
190 G4ExceptionDescription exceptionDescription;
191 exceptionDescription << "the position: " << position
192 << " is not in the box : " << *fpBoundingMesh;
193 G4Exception("G4DNAMesh::GetKey", "G4DNAMesh010", FatalErrorInArgument,
194 exceptionDescription);
195 }
196
197 G4int dx =
198 std::floor((position.x() - fpBoundingMesh->Getxlo()) / fResolution);
199 G4int dy =
200 std::floor((position.y() - fpBoundingMesh->Getylo()) / fResolution);
201 G4int dz =
202 std::floor((position.z() - fpBoundingMesh->Getzlo()) / fResolution);
203 if(dx < 0 || dy < 0 || dz < 0)
204 {
205 G4ExceptionDescription exceptionDescription;
206 exceptionDescription << "the old index: " << position
207 << " to new index : " << Index(dx, dx, dx);
208 G4Exception("G4DNAMesh::CheckIndex", "G4DNAMesh015", FatalErrorInArgument,
209 exceptionDescription);
210 }
211 return Index{ dx, dy, dz };
212}
double z() const
double x() const
double y() const

◆ GetNumberOfType()

G4int G4DNAMesh::GetNumberOfType ( G4DNAMesh::MolType type) const

Definition at line 85 of file G4DNAMesh.cc.

86{
87 G4int output = 0;
88
89 for(const auto& iter : fVoxelVector)
90 {
91 auto data = std::get<2>(iter);
92 auto it = data.find(type);
93 if(it != data.end())
94 {
95 output += it->second;
96 }
97 }
98 return output;
99}

◆ GetRandomIndex()

G4VDNAMesh::Index G4DNAMesh::GetRandomIndex ( const Index & oldIndex,
const G4double & resolution ) const

Definition at line 237 of file G4DNAMesh.cc.

238{
239 G4double x_min = oldIndex.x * OldReso;
240 G4double x_max = (oldIndex.x + 1) * OldReso;
241 G4double y_min = oldIndex.y * OldReso;
242 G4double y_max = (oldIndex.y + 1) * OldReso;
243 G4double z_min = oldIndex.z * OldReso;
244 G4double z_max = (oldIndex.z + 1) * OldReso;
245
246 G4int i_max = std::floor(x_max / fResolution);
247 G4int j_max = std::floor(y_max / fResolution);
248 G4int k_max = std::floor(z_max / fResolution);
249
250 G4int i_min = std::floor(x_min / fResolution);
251 G4int j_min = std::floor(y_min / fResolution);
252 G4int k_min = std::floor(z_min / fResolution);
253
254 G4double r1 = G4UniformRand();
255 G4double r2 = G4UniformRand();
256 G4double r3 = G4UniformRand();
257
258 G4int i_n = i_min + (G4int)std::floor(r1 * (i_max - i_min + 1));
259 G4int j_n = j_min + (G4int)std::floor(r2 * (j_max - j_min + 1));
260 G4int k_n = k_min + (G4int)std::floor(r3 * (k_max - k_min + 1));
261
262 return Index{ i_n, j_n, k_n };
263}
double G4double
Definition G4Types.hh:83
#define G4UniformRand()
Definition Randomize.hh:52

◆ GetResolution()

G4double G4DNAMesh::GetResolution ( ) const

Definition at line 184 of file G4DNAMesh.cc.

184{ return fResolution; }

◆ GetVoxel()

G4DNAMesh::Voxel & G4DNAMesh::GetVoxel ( const Index & index)

Definition at line 37 of file G4DNAMesh.cc.

38{
39 auto iter = fIndexMap.find(key);
40 if(iter == fIndexMap.end())
41 {
42 auto box = GetBoundingBox(key);
43 Data mapList;
44 G4DNAMesh::Voxel& voxel =
45 fVoxelVector.emplace_back(std::make_tuple(key, box, std::move(mapList)));
46 fIndexMap[key] = G4int(fVoxelVector.size() - 1);
47 return voxel;
48 }
49
50 auto index = fIndexMap[key];
51 return fVoxelVector[index];
52}
std::tuple< Index, Box, Data > Voxel
Definition G4DNAMesh.hh:47
std::map< MolType, size_t > Data
Definition G4DNAMesh.hh:46
const G4DNABoundingBox & GetBoundingBox() const
Definition G4DNAMesh.cc:139

Referenced by GetVoxelMapList(), and InitializeVoxel().

◆ GetVoxelMapList()

G4DNAMesh::Data & G4DNAMesh::GetVoxelMapList ( const Index & index)

Definition at line 61 of file G4DNAMesh.cc.

62{
63 auto& pVoxel = GetVoxel(key);
64 return std::get<2>(pVoxel);
65}
Voxel & GetVoxel(const Index &index)
Definition G4DNAMesh.cc:37

Referenced by PrintVoxel().

◆ InitializeVoxel()

void G4DNAMesh::InitializeVoxel ( const Index & key,
Data && mapList )

Definition at line 116 of file G4DNAMesh.cc.

117{
118 auto& pVoxel = GetVoxel(index);
119 std::get<2>(pVoxel) = std::move(mapList);
120}

◆ PrintMesh()

void G4DNAMesh::PrintMesh ( )

Definition at line 67 of file G4DNAMesh.cc.

68{
69 G4cout << "*********PrintMesh::Size : " << fVoxelVector.size() << G4endl;
70 for(const auto& iter : fVoxelVector)
71 {
72 auto data = std::get<2>(iter);
73 G4cout << "Index : " << std::get<0>(iter)
74 << " number of type : " << std::get<2>(iter).size() << G4endl;
75 for(const auto& it : data)
76 {
77 G4cout << "_____________" << it.first->GetName() << " : " << it.second
78 << G4endl;
79 }
80 G4cout << G4endl;
81 }
82 G4cout << G4endl;
83}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout

◆ PrintVoxel()

void G4DNAMesh::PrintVoxel ( const Index & index)

Definition at line 101 of file G4DNAMesh.cc.

102{
103 G4cout << "*********PrintVoxel::";
104 G4cout << " index : " << index
105 << " number of type : " << this->GetVoxelMapList(index).size()
106 << G4endl;
107
108 for(const auto& it : this->GetVoxelMapList(index))
109 {
110 G4cout << "_____________" << it.first->GetName() << " : " << it.second
111 << G4endl;
112 }
113 G4cout << G4endl;
114}
Data & GetVoxelMapList(const Index &index)
Definition G4DNAMesh.cc:61

◆ Reset()

void G4DNAMesh::Reset ( )

Definition at line 133 of file G4DNAMesh.cc.

134{
135 fIndexMap.clear();
136 fVoxelVector.clear();
137}

Referenced by ~G4DNAMesh().

◆ size()

size_t G4DNAMesh::size ( )
inline

Definition at line 54 of file G4DNAMesh.hh.

54{ return fVoxelVector.size(); };

The documentation for this class was generated from the following files: