# [porousmedia] Energy balance implementation

We currently have some inconsistencies in the energy balance for porous media. For thermal equilibrium models, we implement

```
\frac{\partial \left( n_s \rho_s u_s + n_f \rho_f u_f \right)}{\partial t} =
- \nabla\cdot{\left( \rho_f h_f \boldsymbol{v}_f \right)} + \nabla\cdot{\left( \left\lbrace n_f \lambda_f + n_s \lambda_s \right\rbrace \nabla T \right)}.
```

but the correct balance would be

```
\frac{\partial \left( n_s \rho_s u_s + n_f \rho_f \left\lbrace u_f - g z \right\rbrace \right)}{\partial t} =
- \nabla\cdot{\left( \left\lbrace \rho_f h_f - \rho_f g z\right\rbrace \boldsymbol{v}_f \right)} + \nabla\cdot{\left( \left\lbrace n_f \lambda_f + n_s \lambda_s \right\rbrace \nabla T \right)}.
```

This might seem like a small change but the difference actually shows some inconsistency. It's not just an omitted term.

Only looking at the fluid balance, the gravity term can also be written like this

`\frac{\partial \left( n_f \rho_f u_f \right)}{\partial t} = - \nabla\cdot{\left( \rho_f h_f \boldsymbol{v}_f \right)} + \nabla\cdot{\left(n_f \lambda_f \nabla T \right)} + \rho_f \boldsymbol{v}_f \cdot \boldsymbol{g} = - \nabla\cdot{\left( (\rho_f u_f + p) \boldsymbol{v}_f \right)} + \nabla\cdot{\left(n_f \lambda_f \nabla T \right)} + \rho_f \boldsymbol{v}_f \cdot \boldsymbol{g}.`

Essentially, if we consider gravity in Darcy's law, we should also consider the corresponding term in the energy balance for consistency. Subtracting the momentum balance multiplied by the velocity gives the balance of internal energy (non-conservative because only total energy is conserved):

`\frac{\partial \left( n_f \rho_f u_f \right)}{\partial t} = - \nabla\cdot{\left( \rho_f u_f \boldsymbol{v}_f \right)} + \nabla\cdot{\left(n_f \lambda_f \nabla T \right)} \underbrace{- p \left(\nabla\cdot{\boldsymbol{v}_f}\right)}_{\text{volume work}} \underbrace{+ \mu_f \boldsymbol{K}^{-1} \boldsymbol{v}_f \cdot \boldsymbol{v}_f}_{\text{viscous dissipation}}`

This shows that there are conversion terms resulting in modification of the internal energy. Even if we assume that one of these is small, or both of these are small, we don't arrive at the implemented equation. If we don't have the gravity/potential energy term in the original balance, there would be an additional gravity term popping up here that mingles with the other energy conversion terms.

The gravity term vanishes if the fluid only moves perpendicular to the gravity field. However, for scenarios with strong upward/downward movement, this should have an effect.