EGS Brachy
An egs++ user code for rapid brachytherapy calculations
Loading...
Searching...
No Matches
test.py
Go to the documentation of this file.
1"""
2
3A very simple dose calculation in a spherical phantom with multiple media. The
4simple geometry allows a fast calculation with high precision for comparing
5against a previously calculated dose.
6
7"""
8
9import math
10import re
11
12from eb_tests.utils import doses_approx_equal, extract_all_doses
13
14EGSINP = "simple_dose_sph.egsinp"
15TIME_LIMIT_S_PER_MHZ = 22/2993. # s / MHz
16
17# expected doses taken from initial run of simple_dose_sph.egsinp
18# when egs_brachy believed to be in a good state.
19# regions 1-5 (reg 0 excluded because of source overlap)
20expected_doses = {
21 "tlen": [
22 (5.219E-12, 0.0004),
23 (1.117E-12, 0.0002),
24 (4.292E-13, 0.0002),
25 (2.126E-13, 0.0002),
26 (1.332E-13, 0.0001),
27 ],
28 "edep": [
29 (5.212E-12, 0.0073),
30 ]
31}
32
33
34
35def compare_results(egslst, inp_name):
36
37 actual = {
38 "tlen": [],
39 "edep": [],
40 }
41
42 doses = extract_all_doses(egslst)
43 for reg, tlen, tlen_unc, edep, edep_unc in doses:
44 actual['tlen'].append((float(tlen), float(tlen_unc)/100))
45 actual['edep'].append((float(edep), float(edep_unc)/100))
46
47 tolerances = {
48 'tlen': 0.001,
49 'edep': 0.015,
50 }
51
52 all_close = True
53 for calc_type, region_doses in list(expected_doses.items()):
54 for region, (expected_dose, expected_unc) in enumerate(region_doses):
55
56 calc_dose, calc_unc = actual[calc_type][region]
57
58 tol = tolerances[calc_type]
59 doses_close = doses_approx_equal(expected_dose, expected_unc, calc_dose, calc_unc, max_percent_diff=tol)
60
61 if not doses_close:
62 msg = "%s dose comparison failed for reg %d: Actual= %.4E +/- %.2F%% Expected= %.4E +/- %.2F%%"
63 print((msg % (calc_type, region + 1, calc_dose, 100*calc_unc, expected_dose, 100*expected_unc)))
64 all_close = False
65
66 return all_close, actual, expected_doses