## 3 Numerical Implementation  
The multi-level analysis described above is implemented within the visual programming environment offered by Rhinoceros3D + Grasshopper. The proposed method is compartmentalised into clusters, where each group performs logical functions.  
The first step of the visual script is devoted to importing the geometry of the structure that the user wants to investigate (BLOCK 1, Figure 3). This step of the procedure may be performed by following different approaches, i.e., parametric modelling of the structure, importing of the NURBS geometry previously modelled in Rhino3D or importing of the geometry directly using laser scanning. The same group of the visual script contains a series of components devoted to the setting of parameters required: friction coefficient, dimensions of the blocks, specific weight and the position of the rotational hinge (whereas its height with respect to the ground is assumed as a variable). In the same group, the user has to define the geometry of the openings, if present.  
The second group is formed by a series of Grasshopper components able to split the structure by means of crack lines which define the geometry of the collapsing macro-block (BLOCK 2, Figure 3). This group contains a series of sliders that allow the visual program to cover a broad range of macro-block geometries according to the geometrical constraints defined in Equation (3). These sliders correspond to unknown variables in the optimization procedure.  
The subsequent group (BLOCK 3, Figure 3) contains an ad-hoc programmed C# component, which formulates the principle of virtual work of the problem. The output of this cluster is the calculated load multiplier (BLOCK 4, Figure 3). In this work, to solve the minimisation problem reported in Equation (4), the Nelder-Mead method is adopted [33]. The Nelder-Mead method (NMM) is a commonly applied numerical method used to find the minimum or maximum of an objective function in a multidimensional space. The NMM component (BLOCK 5, Figure 3) is linked to the parameters that define the geometry of the collapsing macroblocks (inclination of the cracks) and the load multiplier that has to be optimised.  
Once the geometry of the macro-block (i.e., the collapse mechanism) and its associated minimum load multiplier \(\lambda\) have been obtained using the optimisation procedure described, a GhPython script (the Python interpreter component for Grasshopper) follows (BLOCK 6,  
Figure 3: Flow chart representation of the proposed two-step analysis.  
Figure 3). This component takes as input the macro-block geometry and hinge location, and automatically extracts the required geometric properties (such as volume, centroid and moment of inertia) defining the kinematic constants, which, in turn, are used to compute the parameters defining the rocking equation of motion. For a more detailed description of how the script works, the readers are directed to References [14; 26].  
The rocking equation of motion can then be solved for full time-histories, (BLOCK 7, Figure 3) for both harmonic and random, i.e., earthquake, ground motions. Note that in the case of the latter, the corresponding ground motion records would need to be provided as user-defined input (BLOCK 8, Figure 2).  
The solution of the equation of motion requires additional Python packages such as NumPy [34] and SciPy [35], which are not available in IronPython, which is the implementation of Python used by Rhino and by extension, Grasshopper. Thus, to make the proposed modelling strategy work within the Grasshopper environment, a GH Python Remote component [36] was added to the cluster (BLOCK 7), as it provides a connection to an external instance of Python through which the required NumPy and SciPy functions can be executed.