Skip to content

Commit

Permalink
fix python continous
Browse files Browse the repository at this point in the history
  • Loading branch information
retkiewi committed Aug 4, 2024
1 parent 8823175 commit a3a8808
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions hadrons/common/continous_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
from numpy.random import Generator, default_rng
from tqdm import tqdm

from hadrons.common.generic_hadron_solver import GenericHadronSolver
from hadrons.utils.common import doserate_to_fluence
Expand Down Expand Up @@ -69,6 +70,7 @@ def __post_init__(self):
def get_number_of_tracks(self, time_step: int) -> bool:
if time_step == 0:
print(self.track_distribution)
return 1
return self.track_distribution[time_step]

def get_random_xy_coordinate(self):
Expand Down Expand Up @@ -96,11 +98,18 @@ def get_track_for_time_step(self, time_step: int):

x, y = self.get_random_coordinates()

for k in range(self.no_z_electrode, self.no_z + self.no_z_electrode):
for k in tqdm(
range(self.no_z_electrode, self.no_z + self.no_z_electrode),
desc="Calculating track...",
):
for i in range(self.no_xy):
x_track_dist_squared = (i - x) ** 2
x_chamber_dist_squared = (i - self.xy_middle_idx) ** 2

for j in range(self.no_xy):
distance_from_center = (
sqrt((i - x) ** 2 + (j - y) ** 2) * self.grid_spacing
sqrt(x_track_dist_squared + (j - y) ** 2)
* self.grid_spacing
)
ion_density = self.Gaussian_factor * exp(
-(distance_from_center**2) / self.track_radius**2
Expand All @@ -109,12 +118,11 @@ def get_track_for_time_step(self, time_step: int):
negative_array[i, j, k] += ion_density
# calculate the recombination only for charge carriers inside the circle
if (
sqrt(
(i - self.xy_middle_idx) ** 2
+ (j - self.xy_middle_idx) ** 2
)
sqrt(x_chamber_dist_squared + (j - self.xy_middle_idx) ** 2)
< self.inner_radius
):
# TODO: I'm not sure why this check is here - when separatioon_time_steps >= computation_time_steps,
# the simulation will not work properly since we are ignoring all the initialised charge carriers
if time_step > self.separation_time_steps:
no_initialised_charge_carriers += ion_density

Expand Down
4 changes: 2 additions & 2 deletions hadrons/common/generic_hadron_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class GenericHadronSolver(ABC):
electrode_gap: float # [cm]
energy: float # [MeV/u]
RDD_model: Literal["Gauss", "Geiss"] = "Gauss"
grid_spacing: float = 3e-4 # [cm]
grid_spacing: float = 3e-3 # [cm]
# TODO: Narrow this type down
particle: str = "proton"
no_z_electrode: int = (
Expand Down Expand Up @@ -118,7 +118,7 @@ def separation_time_steps(self) -> int:
@property
def computation_time_steps(self) -> int:

return self.separation_time_steps * 2
return self.separation_time_steps * 5

@property
def RDD_function(self):
Expand Down

0 comments on commit a3a8808

Please sign in to comment.