How can we represent thermal energy and heat diffusion in the Lagrangian? My question has two parts. But let's first introduce the problem:
In Lagrangian mechanics, a central part is the Lagrangian
$$
\mathcal
L\left(t, q,\dot{q}\right)
=
T\left(t, q,\dot{q}\right)
-
V\left(t, q,\dot{q}\right),
$$
where $t$ is the time, $q$ are the generalized coordinates and $\dot q$ are the corresponding time derivatives, $T$ is the total kinetic energy of the system, and $V$ is the total potential energy of the system. Alternatively, in a field theory, the Lagrangian would be the density
$$
\mathcal
L\left(t, q(\vec{x}),\dot{q}(\vec{x}), \vec{\nabla}q(\vec{x})\right)
=
T\left(t, q(\vec{x}),\dot{q}(\vec{x}), \vec{\nabla}q(\vec{x})\right)
-
V\left(t, q(\vec{x}),\dot{q}(\vec{x}), \vec{\nabla}q(\vec{x})\right),
$$
where $q$ are now the fields and $\dot{q}$ and $\vec{\nabla}q$ are the corresponding time- and spatial derivatives, respectively, and $T$ and $V$ are now the kinetic and potential energy densities, respectively. The equations of motion of the system are then given by the Euler–Lagrange equations.
However, if the system contains a gas, the gas may vary in temperature and will become hotter if it is compressed, which means that some kinetic energy was converted to thermal energy, which should increase the pressure of the gas more than if it was just the density of the gas that was considered, hence changing the behavior of the system.
Besides, since sound waves traveling in a gas will not only create pressure waves but also temperature waves, since an increase in pressure is accompanied by an increase in temperature, we will have a varying temperature within the gas. This variation will give rise to thermal diffusion, causing thermal energy to diffuse from the pressure tops to the pressure valleys, in turn causing the sound waves to weaken over time (the "life expectancy" is proportional to the wavelength squared).
My questions are:

*

*How do we take thermal energy into account in the Lagrangian? Should this be counted as just a form of potential energy, since macroscopically, it doesn't directly cause anything to move? Or should it be counted as partially potential energy and partially kinetic energy, since microscopically, it both makes the gas particles move faster, which increases the total kinetic energy, and makes particles press against each other harder during collisions which, during the collision between two particles, temporarily causes a higher potential energy?


*How do we model thermal diffusion in the Lagrangian of a field theory?
Note that I'm still only interested in macroscopic systems, as temperature is an inherently macroscopic property, not to mention that treating each individual fluid particle would become too complex.
 A: If you want to look at individual atoms and molecules, then thermal energy is just particle motion. Thus, if you have represented your particle motion in your Lagrangian, you have represented thermal motion. In the ordinary case it would be seriously impractical to use such. You are talking something in the range of $10^{22}$ particles in a gram of air. (More or less depending on the type of atoms.) So you can't really do it that way.
If you wanted to treat the system as whole and include thermal energy that is very different. For example, if you wanted to do a Lagranian representation of thermal energy in a fluid. Then you bring in the equation of state for the fluid. That will relate temperature and pressure, and possibly chemical identity if you wanted to include chemical processes. The equation of state will let you do things like relate pressure, temperature, and density. Depending on what you are doing, that can come into the system in a variety of ways.
For example, the equation of state might enter as a constraint. You would add the equation of state to the Lagrangian with a Lagrange multiplier. Then you treat the Lagrange multiplier as a new system variable, the equation of motion of which is the equation of state.  You might get some incite into that process by looking at the Dirac method of dealing with constrained systems. Just don't get bogged down since he's doing it to head towards quantum systems.
Diffusion is going to be a gnarly problem in a Lagrangian formulation. I like Lagrangians, but they would not be my first choice for it. Diffusion does not really have anything like cannoncial coords
or momentum.
