Thermomechanical modeling and optimization of friction stir welding