Skip to content

Commit

Permalink
Add temperature control to target definition
Browse files Browse the repository at this point in the history
  • Loading branch information
gwm17 committed Jul 30, 2024
1 parent c2a4e1c commit 11c443a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/spyral_utils/nuclear/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TargetData:
compound: list[tuple[int, int, int]] = field(default_factory=list) # (Z, A, S)
pressure: float | None = None # torr
thickness: float | None = None # ug/cm^2
temperature: float | None = None # K

def density(self) -> float:
"""Get the gas density in g/cm^3
Expand All @@ -70,7 +71,10 @@ def density(self) -> float:
molar_mass: float = 0.0
for z, a, s in self.compound:
molar_mass += a * s
return molar_mass * self.pressure / (GAS_CONSTANT * ROOM_TEMPERATURE)
T = self.temperature
if T is None:
T = ROOM_TEMPERATURE
return molar_mass * self.pressure / (GAS_CONSTANT * T)


def deserialize_target_data(target_path: Path) -> TargetData | None:
Expand All @@ -95,11 +99,19 @@ def deserialize_target_data(target_path: Path) -> TargetData | None:
):
return None
else:
return TargetData(
json_data["compound"],
json_data["pressure(Torr)"],
json_data["thickness(ug/cm^2)"],
)
if "temperature(K)" not in json_data:
return TargetData(
json_data["compound"],
json_data["pressure(Torr)"],
json_data["thickness(ug/cm^2)"],
)
else:
return TargetData(
json_data["compound"],
json_data["pressure(Torr)"],
json_data["thickness(ug/cm^2)"],
json_data["temperature(K)"],
)


def serialize_target_data(target_path: Path, data: TargetData):
Expand Down
12 changes: 12 additions & 0 deletions tests/gas_target_temp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compound": [
[
1,
1,
2
]
],
"pressure(Torr)": 300.0,
"temperature(K)": 300.0,
"thickness(ug/cm^2)": null
}
12 changes: 12 additions & 0 deletions tests/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

GAS_TARGET_PATH: Path = Path(__file__).parent.resolve() / "gas_target.json"
SOLID_TARGET_PATH: Path = Path(__file__).parent.resolve() / "solid_target.json"
GAS_TARGET_TEMP_PATH: Path = Path(__file__).parent.resolve() / "gas_target_temp.json"
PROJ_Z: int = 1
PROJ_A: int = 1
PROJ_KE: float = 5.0 # MeV
Expand Down Expand Up @@ -76,3 +77,14 @@ def test_solid_target_range():
print(target.material.density())

assert abs(range - LISE_VALUE) < PRECISION * LISE_VALUE


def test_gas_target_with_temp():
nuc_map = NuclearDataMap()
target_temp = load_target(GAS_TARGET_TEMP_PATH, nuc_map)
target_no_temp = load_target(GAS_TARGET_PATH, nuc_map)

assert isinstance(target_temp, GasTarget)
assert isinstance(target_no_temp, GasTarget)
assert target_temp.data.temperature is not None
assert target_temp.density != target_no_temp.density

0 comments on commit 11c443a

Please sign in to comment.