EGS Brachy
An egs++ user code for rapid brachytherapy calculations
Loading...
Searching...
No Matches
test.py
Go to the documentation of this file.
1"""
2A test for ensuring x-ray sources mode is working. The test consists of a
31cm^2 beam of electrons incident on a thin cylindrical disc with dose
4being calculated in cylindrical slabs behind the target. The egs_brachy
5energy deposition doses are compared with values calculated by dosrznrc.
6"""
7
8import csv
9import math
10import re
11
12from eb_tests.utils import doses_approx_equal, extract_all_doses
13
14EGSINP = "brem_cyl.egsinp"
15TIME_LIMIT_S_PER_MHZ = 20/2993. # s / MHz
16
17# doses calcualted using dosrz_brem_cyl.egsinp
18DOSRZ_NRC_DOSES = [
19 (3.0107E-013, 0.0002),
20 (1.0088E-016, 0.0040),
21 (5.6843E-017, 0.0042),
22 (3.8797E-017, 0.0041),
23]
24
25
26expected_doses = {
27 "tlen": [
28 (3.702E-16, 2.84),
29 (1.042E-16, 2.90),
30 (5.933E-17, 3.04),
31 (4.064E-17, 3.14),
32 ],
33 "edep": [
34 (3.002E-13, 0.41),
35 (1.073E-16, 3.15),
36 (5.943E-17, 3.66),
37 (3.912E-17, 4.20),
38 ]
39}
40
41
42
43def compare_results(egslst, inp_name):
44
45 actual = {
46 "tlen": [],
47 "edep": [],
48 }
49
50 doses = extract_all_doses(egslst)
51 doses = doses[1:] # ignore first region since covered by source
52
53 for reg, tlen, tlen_unc, edep, edep_unc in doses:
54 actual['tlen'].append((float(tlen), float(tlen_unc)))
55 actual['edep'].append((float(edep), float(edep_unc)))
56
57 all_close = True
58 for calc_type, region_doses in list(expected_doses.items()):
59 if calc_type == "edep":
60 region_doses = DOSRZ_NRC_DOSES
61 compare_unc = False
62 else:
63 compare_unc = True
64
65 for region, (expected_dose, expected_unc) in enumerate(region_doses):
66
67 calc_dose, calc_unc = actual[calc_type][region]
68
69 doses_close = doses_approx_equal(
70 expected_dose, expected_unc, calc_dose, calc_unc,
71 compare_unc=compare_unc, max_unc_percent_diff=0.5,
72 )
73
74 if not doses_close:
75 msg = "%s dose comparison failed for reg %d: Actual= %E +/- %E Expected= %E +/- %E"
76 print((msg % (calc_type, region + 1, calc_dose, calc_unc, expected_dose, expected_unc)))
77 all_close = False
78
79 return all_close, actual, expected_doses