Skip to content

Endchecker

Module providing utilities for choosing and initializing end checkers for simulations.

ElasticEnergyDropEndChecker

Class for checking if the end of the simulation is reached based on elastic energy drop. With this end checker, the end of the simulation is reached when elastic energy reaches drop % of its maximum value.

Attributes:

Name Type Description
postprocessor PostProcessor

Post-processor for analyzing simulation results.

maximum_elastic_energy float

Maximum elastic energy encountered during the simulation.

drop float

Drop coefficient.

Source code in src/fragma/endchecker.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
class ElasticEnergyDropEndChecker:
    """
    Class for checking if the end of the simulation is reached based on elastic energy drop.
    With this end checker, the end of the simulation is reached when elastic energy reaches drop % of its maximum value.

    Attributes
    ----------
    postprocessor : PostProcessor
        Post-processor for analyzing simulation results.
    maximum_elastic_energy : float
        Maximum elastic energy encountered during the simulation.
    drop : float
        Drop coefficient.
    """

    def __init__(self, postprocessor, drop):
        """
        Initialize the ElasticEnergyEndChecker.

        Parameters
        ----------
        postprocessor : PostProcessor
            Post-processor for analyzing simulation results.
        drop : float
            Drop coefficient.
        """
        # Store the post processor
        self.postprocessor = postprocessor
        # Get the drop coefficient
        self.drop = drop
        # Initiliaze the maximum elastic energy
        self.maximum_elastic_energy = 0

    def end(self):
        """
        Check if the end time of the simulation is reached based on elastic energy drop.

        Returns
        -------
        bool
            True if the end time of the simulation is reached, False otherwise.
        """
        # Get the current elastic energy
        current_elastic_energy = self.postprocessor.scalar_data["elastic_energy"]
        # Update the maximum elastic energy
        self.maximum_elastic_energy = max(
            self.maximum_elastic_energy, current_elastic_energy
        )
        # Check if the current elastic energy is less than 1% of the maximum elastic energy
        return current_elastic_energy < self.drop * self.maximum_elastic_energy

__init__(postprocessor, drop)

Initialize the ElasticEnergyEndChecker.

Parameters:

Name Type Description Default
postprocessor PostProcessor

Post-processor for analyzing simulation results.

required
drop float

Drop coefficient.

required
Source code in src/fragma/endchecker.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def __init__(self, postprocessor, drop):
    """
    Initialize the ElasticEnergyEndChecker.

    Parameters
    ----------
    postprocessor : PostProcessor
        Post-processor for analyzing simulation results.
    drop : float
        Drop coefficient.
    """
    # Store the post processor
    self.postprocessor = postprocessor
    # Get the drop coefficient
    self.drop = drop
    # Initiliaze the maximum elastic energy
    self.maximum_elastic_energy = 0

end()

Check if the end time of the simulation is reached based on elastic energy drop.

Returns:

Type Description
bool

True if the end time of the simulation is reached, False otherwise.

Source code in src/fragma/endchecker.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def end(self):
    """
    Check if the end time of the simulation is reached based on elastic energy drop.

    Returns
    -------
    bool
        True if the end time of the simulation is reached, False otherwise.
    """
    # Get the current elastic energy
    current_elastic_energy = self.postprocessor.scalar_data["elastic_energy"]
    # Update the maximum elastic energy
    self.maximum_elastic_energy = max(
        self.maximum_elastic_energy, current_elastic_energy
    )
    # Check if the current elastic energy is less than 1% of the maximum elastic energy
    return current_elastic_energy < self.drop * self.maximum_elastic_energy

TimeEndChecker

Class for checking if the end of the simulation is reached based on time. With this end checker, the end of the simulation is reached when the time reaches 1.

Attributes:

Name Type Description
stepper ProportionalTimeStepper

Time stepper for time integration during simulation.

t_max int

Final time step.

Source code in src/fragma/endchecker.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class TimeEndChecker:
    """
    Class for checking if the end of the simulation is reached based on time.
    With this end checker, the end of the simulation is reached when the time reaches 1.

    Attributes
    ----------
    stepper : ProportionalTimeStepper
        Time stepper for time integration during simulation.
    t_max : int
        Final time step.
    """

    def __init__(self, time_stepper, t_max):
        """
        Initialize the EndChecker.

        Parameters
        ----------
        time_stepper : ProportionalTimeStepper
            Time stepper for time integration during simulation.
        t_max : int
            Final time step.
        """
        # Store the time stepper
        self.time_stepper = time_stepper
        # Store the final time step
        self.t_max = t_max

    def end(self):
        """
        Check if the end time of the simulation is reached.

        Returns
        -------
        bool
            True if the end time of the simulation is reached, False otherwise.
        """
        return self.time_stepper.t > self.t_max

__init__(time_stepper, t_max)

Initialize the EndChecker.

Parameters:

Name Type Description Default
time_stepper ProportionalTimeStepper

Time stepper for time integration during simulation.

required
t_max int

Final time step.

required
Source code in src/fragma/endchecker.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def __init__(self, time_stepper, t_max):
    """
    Initialize the EndChecker.

    Parameters
    ----------
    time_stepper : ProportionalTimeStepper
        Time stepper for time integration during simulation.
    t_max : int
        Final time step.
    """
    # Store the time stepper
    self.time_stepper = time_stepper
    # Store the final time step
    self.t_max = t_max

end()

Check if the end time of the simulation is reached.

Returns:

Type Description
bool

True if the end time of the simulation is reached, False otherwise.

Source code in src/fragma/endchecker.py
71
72
73
74
75
76
77
78
79
80
def end(self):
    """
    Check if the end time of the simulation is reached.

    Returns
    -------
    bool
        True if the end time of the simulation is reached, False otherwise.
    """
    return self.time_stepper.t > self.t_max

choose_end_checker(end_pars, time_stepper, postprocessor)

Choose and initialize the end checker.

Parameters:

Name Type Description Default
end_pars dict

Parameters used to determine the end of the simulation.

required
time_stepper ProportionalTimeStepper

Time stepper for time integration during simulation.

required
postprocessor PostProcessor

Post-processor for analyzing simulation results.

required

Returns:

Type Description
EndChecker

The initialized end checker.

Raises:

Type Description
RuntimeError

If the specified end criterion does not exist.

Source code in src/fragma/endchecker.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def choose_end_checker(end_pars, time_stepper, postprocessor):
    """
    Choose and initialize the end checker.

    Parameters
    ----------
    end_pars : dict
        Parameters used to determine the end of the simulation.
    time_stepper : ProportionalTimeStepper
        Time stepper for time integration during simulation.
    postprocessor : PostProcessor
        Post-processor for analyzing simulation results.

    Returns
    -------
    EndChecker
        The initialized end checker.

    Raises
    ------
    RuntimeError
        If the specified end criterion does not exist.
    """
    match end_pars["criterion"]:
        case "t":
            t_max = end_pars["t_max"]
            return TimeEndChecker(time_stepper, t_max)
        case "elastic_energy_drop":
            drop = end_pars["drop"]
            return ElasticEnergyDropEndChecker(postprocessor, drop)
        case _:
            raise RuntimeError(
                f"The end criterion '{end_pars['criterion']}' does not exists."
            )