Stress distributions and material response in thermal spraying of metallic and ceramic deposits