# Finite Element Method - 2D Mesh Generator - Metfem2D

## Generator Optimization via the Metropolis method

### Boundary mesh elements

The Metropolis algorithm[1, 2] applied to boundary nodes slightly differs from the above– described case and could be summarize in the following steps:

1. Find all the boundary or edge nodes i. e. nodes for which pk, edge ∈ Γ.
2. Find triangles in the closest neighbourhood of the considered pk,edge node. Then calculate an area of each triangle Al,edge.
3. Calculate the force acting on each boundary node and coming only from nodes connected to it (as previously).

 J Fk = - ∑ Fboundary δ |rjk| versor(rjk) j=1
where J denotes the total number of nodes linked to the k-th node and δ|rjk| is defined as previously. Let us impose the following constrain on the motion of the k-th node in order to keep it in the boundary Γ. The force must be tangential to the boundary Γ so the boundary projection of the force Fk must be found:
 Fk, Γ = versor(LΓ) (LΓ ⋅ Fk) / |LΓ|

where LΓ denotes a vector lying along boundary Γ.

4. Similarly, find an area of each triangle Anewl,edge after shifting pk,edge → pnewk,edge according to the force Fk.
5. Adopt the Metropolis energetic condition to the boundary case i.e.
 δE = ∑ l ( (Anewl, edge - A)2 - (Al, edge - A)2 ) l = 1, 2, …, L.

If

e-δE⁄T > r
the new configuration is accepted otherwise is rejected. T denotes temperature and a random number r ∈ U(0; 1) as previously.
6. The main point of this part is to ensure that the boundary nodes are moved just along the boundary Γ.

### References

1. ^ O. C. Zienkiewicz, R. L. Taylor and J. Z. Zhu, The Finite Element Method: Its Basis and Fundamentals, Sixth edition., Elsevier 2005
2. ^ N. Metropolis, S. Ulam, The Monte Carlo Method, J. Amer. Stat. Assoc., 44, No. 247., pp. 335-341, 1949