40 minutes of shower time seems like a bit longer than I’d expect to get out of a 40 gallon electric water heater… I would’ve thought 20-25 minutes would be around what you’d get.
The first hour rating gets at this concept, but if you have a 2.5 GPM shower head that’d be 100 gallons of water required for a 40 minute shower. It wouldn’t be too surprising that a 40 gallon electric heater couldn’t keep up with that kind of demand, considering that electric units’ recovery is traditionally lower than gas units’. A quick google says that electric units have first hour ratings around 50-55 gallons.
Of course, this is a simplification (I.E, you’re probably mixing in some cold water at the tap, so you’d be using less than 2.5 gallons of hot water per minute), but I think that the scenario is a pretty big ask from the heater. Setting the temp higher would increase capacity in theory, as you’d need to mix less hot water in per minute to get the same output temp from the faucet, but there are scald risks associated with higher settings.
What GPM rating does your shower head have? And how cold is the water entering the water heater? (Our 40 gallon gas water heater performs much better when the incoming water isn’t as cold as it is in winter in MN, which bottoms out around 40 degrees or so.)