• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmc-dev / openmc / 19058781736

04 Nov 2025 05:26AM UTC coverage: 82.008% (-3.1%) from 85.155%
19058781736

Pull #3252

github

web-flow
Merge b8a72730f into bd76fc056
Pull Request #3252: Adding vtkhdf option to write vtk data

16714 of 23236 branches covered (71.93%)

Branch coverage included in aggregate %.

61 of 66 new or added lines in 1 file covered. (92.42%)

3175 existing lines in 103 files now uncovered.

54243 of 63288 relevant lines covered (85.71%)

43393337.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/openmc/trigger.py
1
from collections.abc import Iterable
11✔
2
from numbers import Real
11✔
3

4
import lxml.etree as ET
11✔
5

6
import openmc.checkvalue as cv
11✔
7
from .mixin import EqualityMixin
11✔
8
from ._xml import get_elem_list, get_text
11✔
9

10

11
class Trigger(EqualityMixin):
11✔
12
    """A criterion for when to finish a simulation based on tally uncertainties.
13

14
    Parameters
15
    ----------
16
    trigger_type : {'variance', 'std_dev', 'rel_err'}
17
        Determine whether to trigger on the variance, standard deviation, or
18
        relative error of scores.
19
    threshold : float
20
        The threshold for the trigger type.
21
    ignore_zeros : bool
22
        Whether to allow zero tally bins to be ignored. Note that this option
23
        can cause the trigger to fire prematurely if there are zero scores in
24
        any bin at the first evaluation.
25

26
        .. versionadded:: 0.15.0
27

28
    Attributes
29
    ----------
30
    trigger_type : {'variance', 'std_dev', 'rel_err'}
31
        Determine whether to trigger on the variance, standard deviation, or
32
        relative error of scores.
33
    threshold : float
34
        The threshold for the trigger type.
35
    scores : list of str
36
        Scores which should be checked against the trigger
37
    ignore_zeros : bool
38
        Whether to allow zero tally bins to be ignored.
39

40
    """
41

42
    def __init__(self, trigger_type: str, threshold: float, ignore_zeros: bool = False):
11✔
43
        self.trigger_type = trigger_type
11✔
44
        self.threshold = threshold
11✔
45
        self.ignore_zeros = ignore_zeros
11✔
46
        self._scores = []
11✔
47

48
    def __repr__(self):
11✔
49
        string = 'Trigger\n'
×
50
        string += '{: <16}=\t{}\n'.format('\tType', self._trigger_type)
×
51
        string += '{: <16}=\t{}\n'.format('\tThreshold', self._threshold)
×
52
        string += '{: <16}=\t{}\n'.format('\tIgnore Zeros', self._ignore_zeros)
×
53
        string += '{: <16}=\t{}\n'.format('\tScores', self._scores)
×
UNCOV
54
        return string
×
55

56
    @property
11✔
57
    def trigger_type(self):
11✔
58
        return self._trigger_type
11✔
59

60
    @trigger_type.setter
11✔
61
    def trigger_type(self, trigger_type):
11✔
62
        cv.check_value('tally trigger type', trigger_type,
11✔
63
                       ['variance', 'std_dev', 'rel_err'])
64
        self._trigger_type = trigger_type
11✔
65

66
    @property
11✔
67
    def threshold(self):
11✔
68
        return self._threshold
11✔
69

70
    @threshold.setter
11✔
71
    def threshold(self, threshold):
11✔
72
        cv.check_type('tally trigger threshold', threshold, Real)
11✔
73
        self._threshold = threshold
11✔
74

75
    @property
11✔
76
    def ignore_zeros(self):
11✔
UNCOV
77
        return self._ignore_zeros
×
78

79
    @ignore_zeros.setter
11✔
80
    def ignore_zeros(self, ignore_zeros):
11✔
81
        cv.check_type('tally trigger ignores zeros', ignore_zeros, bool)
11✔
82
        self._ignore_zeros = ignore_zeros
11✔
83

84
    @property
11✔
85
    def scores(self):
11✔
86
        return self._scores
11✔
87

88
    @scores.setter
11✔
89
    def scores(self, scores):
11✔
90
        cv.check_type('trigger scores', scores, Iterable, str)
11✔
91

92
        # Set scores making sure not to have duplicates
93
        self._scores = []
11✔
94
        for score in scores:
11✔
95
            if score not in self._scores:
11✔
96
                self._scores.append(score)
11✔
97

98
    def to_xml_element(self):
11✔
99
        """Return XML representation of the trigger
100

101
        Returns
102
        -------
103
        element : lxml.etree._Element
104
            XML element containing trigger data
105

106
        """
107

108
        element = ET.Element("trigger")
11✔
109
        element.set("type", self._trigger_type)
11✔
110
        element.set("threshold", str(self._threshold))
11✔
111
        if self._ignore_zeros:
11✔
112
            element.set("ignore_zeros", "true")
11✔
113
        if len(self._scores) != 0:
11✔
114
            element.set("scores", ' '.join(self._scores))
11✔
115
        return element
11✔
116

117
    @classmethod
11✔
118
    def from_xml_element(cls, elem: ET.Element):
11✔
119
        """Generate trigger object from an XML element
120

121
        Parameters
122
        ----------
123
        elem : lxml.etree._Element
124
            XML element
125

126
        Returns
127
        -------
128
        openmc.Trigger
129
            Trigger object
130

131
        """
132
        # Generate trigger object
133
        trigger_type = get_text(elem, "type")
11✔
134
        threshold = float(get_text(elem, "threshold"))
11✔
135
        ignore_zeros = str(get_text(elem, "ignore_zeros", "false")).lower()
11✔
136
        # Try to convert to bool. Let Trigger error out on instantiation.
137
        ignore_zeros = ignore_zeros in ('true', '1')
11✔
138
        trigger = cls(trigger_type, threshold, ignore_zeros)
11✔
139

140
        # Add scores if present
141
        scores = get_elem_list(elem, "scores", str)
11✔
142
        if scores is not None:
11✔
143
            trigger.scores = scores
11✔
144

145
        return trigger
11✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc