Add power naps to your schedule.
Your brain seems like the kind that needs some rest before it can work full-on on a problem. If you can, nap a bit when you feel you get out of the flow.
If it is not possible, do something totally unrelated for 15-20 minutes. Your employer may object, but for them it is actually irrelevant why you don’t work. If doing something unrelated helps you to do another hour in the flow, they may understand and give you some other tasks to do.