## 3 Smoothing and Untangling Approach
### Untangling and Smoothing Pipeline  
A detailed description of the proposed simultaneous untangling and smoothing approach is given in this subsection. Algorithm 1 provides the pseudo-code of this EEGT-based simultaneous untangling and smoothing approach for isotropic 2D meshes.  
The element transformation and node positions updating steps are performed iteratively until the current mesh does not contain inverted elements. In step 3 new node positions are not immediately updated, since this would influence the computation of subsequent nodes. Therefore, new node positions computation and applying the new coordinates are separated, ensuring that the computation does not depend on the numbering scheme of nodes and elements, so as to obtain reproducible results. This is important for parallelized implementation of the proposed approach.  
After the above mesh untangling process (step 2-4), the mesh contains no inverted elements. However, quality of the mesh obtained by the untangling process may be low, and further optimization is needed. As the approach is geometry-driven, the steps element transformation and node positions updating may lead to the generation of inverted elements. Therefore, it has to be checked for every element with its new nodes during the mesh smoothing process (step 5). All mesh elements, which are inverted, get a note, that their nodes have to be reset. After all elements are checked, all nodes \(p_{i}^{k+1}\), belonging to one or more inverted elements, are reset to their old coordinates, that is, \(p_{i}^{k+1}=p_{i}^{old}\). These two steps are repeated iteratively until no invalid elements are left. The described method of handling inverted elements during the mesh smoothing process is simple and parallelizable.  
1. Pretreatment 1. For each node \(p_{i}\), save the index set \(E(i)\) of all mesh elements adjacent to it, and record the boundary nodes; 2. Initialize the Boolean variable \(Valid=0\), the number of iterations \(Count=0\), and determine the index set \(j_{inverted}\) of all inverted elements. If \(j_{inverted}=NULL\), let \(Valid=1\), skip the untangling process (step 2-4) and go to step 5 for mesh smoothing.
2. Simultaneous element transformation Perform the following operations for each element \(E_{j}\): 1. Compute the transformed element according to Equation (3) using the scaling factor \(\lambda=0.2(1-q)\), where \(q\) is the quality number of element \(E_{j}\); 2. Scale the transformed element according to Equation(4) resulting in the new temporary nodes \(p_{ij}^{k}\).
3. Update node positions 1. For each inner node \(p_{i}^{k}\) of the mesh, compute its new position \[p_{i}^{k+1}=p_{i}^{k}+\frac{\sum_{j\in E(i)}w_{j}(p_{ij}^{k}-p_{i}^{k})}{\sum _{j\in E(i)}w_{j}},\] (22) where \(w_{j}\) is the weight of element \(E_{j}\); 2. Store old node positions \(p_{i}^{old}=p_{i}^{k}\) and update all inner nodes.
4. Determine the validity of the current mesh Let \(Count=Count+1\), and update the index set \(J_{inverted}\): 1. If \(J_{inverted}=NULL\), let \(Valid=1\), and go to step 5 to further improve mesh quality; 2. If \(J_{inverted}\
eq NULL\) and \(Count\) is less than the maximum number of iterations in the untangling process, go to step 2 for the next iteration; 3. Otherwise, the proposed algorithm fails to untangle the mesh.
5. Mesh smoothing: Keep the boundary nodes fixed, and carry out the simultaneous element transformation, node positions updating and revert nodes of inverted elements to their previous position, until the average mesh quality improvement is below a given tolerance or maximal number of iterations in the smoothing process is reached.  
**Algorithm 1** EEGT-based simultaneous untangling and smoothing of 2D meshes.  
The two main steps of the proposed approach, including element geometric transformation and node positions updating can be easily implemented on GPU due to their fine-grained parallelism. Therefore, a GPU-based implementation is also completed by the authors.