## 3 PolyCISAMR Algorithm
### PolyCISAMR Segregated Meshing Algorithm  
The PolyCISAMR algorithm relies on a _segregated_ meshing strategy, meaning that it uses CISAMR to independently mesh individual grains without any information exchange (communication between processors in the parallel implementation) during the meshing process. The resulting meshes, which are automatically assured to have conforming nodes along their edges, are then stitched together by merging these nodes to build a conforming mesh for the polycrystalline microstructure. The main steps of this algorithm, which are schematically illustrated in Figure 19, are as follows:  
* **Step 1:** After superimposing the polycrystalline microstructure onto a structured background mesh, a subset of this mesh that overlaps with the slightly enlarged BBox of each grain is selected. The BBox is enlarged by \(0.1h\) in each direction, where \(h\) is the size of the background elements. It is worth noting that in the parallel implementation (and even for the sequential version), generating a large background mesh and extracting subsets of it for each grain would not be not necessary; instead, a small structured mesh that overlaps with the enlarged BBox of each grain can directly be created, provided that the nodal coordinates of this mesh snap to nodes of an imaginary structured grid covering the entire domain. * **Step 2:** As described in Section 3.2, the CISAMR is then implemented to create a conforming mesh for each grain as an independent meshing problem using the background mesh identified in the previous step. The only restriction at this step is that the same level of SAMR must be used for meshing grains in order to achieve conforming meshing along the edges of neighboring grains. In the parallel implementation, each grain is assigned to a different partition and meshed independently, with no communication between processors during this process. This distinct feature is the reason for referring to PolyCISAMR as a \"segregated meshing algorithm\". Note that because all operations that lead to creating new nodes (SAMR), node relocation (\(r\)-adaptivity), and sub-triangulation in these segregated meshes are non-iterative and identical during the CISAMR implementation, it is automatically guaranteed that the resulting meshes will have matching nodes along adjacent grain boundaries. * **Step 3:** The segregated meshes generated in Step 2 for different grains are then stitched together (merged) to construct the final FE model. In this process, we iterate over all nodes of the individual grain meshes and store them in a red-black tree-based associative container [45], with the coordinates as key and the node pointer as value. In this approach, we do not need to identify neighboring grains and sort the nodes located on their boundaries in a specific order during the merging process. Instead, we can easily search for and identify matching nodes along the grain boundaries through a simple coordinate check and then merge them by assigning the same global node ID in the final mesh. Note that the tree-based associative container has a time complexity of \(O(log(n))\) for insertion/search operations, and does not allow duplicate keys (node coordinates), allowing this task to be performed efficiently. The PolyCISAMR algorithm described here has several advantages, both in its sequential version, as presented in this work, and when implemented in parallel. The ability to mesh individual grains one by one as an independent problem allows for the handling of massive microstructures composed of hundreds or even thousands of grains without facing memory restrictions.