The relationship between metabolism, physical fatigue, and the energy cost of physical motion is relatively well-understood.
Such robust, quantitative models are mostly lacking when we try to study and explain thought.
Mental fatigue, akrasia, demotivation, and discomfort are common experiences. However, the factors that influence them seem diverse and contextual. The effect of glucose, sleep, drugs, physical fatigue, boredom, sensory stimulation, being watched, having a conversation, talking to yourself vs. thinking in your head, flow states, and many other factors seem to have an effect, but learning how to trigger desirable states, avoid undesirable ones, and make efficient short- vs. longterm tradeoffs and investments is a challenging process of self-discovery.
Placebo effects, behavior compensation, the body's attempt to preserve homeostasis, and the effects of aging and changing life circumstances conspire to give a short life expectancy to knowledge we might hope to gain via self-experimentation.
Yet many people enthusiastically put a lot of effort into trying to optimize their mental state and abilities, even if they don't think about it in those terms. So when is it advantageous to try anyway, despite the difficulty?
More than anything, I think it's important to look for robust but common-sense solutions, and to avoid getting bogged down with unknowable answers to noncentral questions. We don't need to settle the debate on whether and when glucose intake, reducing air particulates, or lowering the temperature can improve mental performance. Instead, we can just look for intuitive signals that these needs might be affecting our own cognition at a particular time, and then provide for being able to make the necessary adjustments.
Keep some healthy snacks near your workspace, open a window, get a fan or A/C, keep a water bottle handy. If you're feeling tired midday, take a little caffeine and see if it helps, but not so much that you risk overcaffeinating yourself or ruining your sleep later. Learn to take broad plausible treatments for low mental performance, in moderation.