  Mathematical modeling of real-world physical systems requires the consistent
combination of a multitude of physical laws and phenomenological models. This
challenging task can be greatly simplified by hierarchically decomposing
systems. Moreover, the use of diagrams for expressing such decompositions helps
make the process more intuitive and facilitates communication, even with
non-experts. As an important requirement, models have to respect fundamental
physical laws such as the first and the second law of thermodynamics. While
some existing modeling frameworks can make such guarantees based on structural
properties of their models, they lack a formal graphical syntax. We present a
compositional and thermodynamically consistent modeling language with a
graphical syntax. As its semantics, port-Hamiltonian systems are endowed with
further structural properties and a fixed physical interpretation such that
thermodynamic consistency is ensured in a way that is closely related to the
GENERIC framework. While port-Hamiltonian systems are inspired by graphical
modeling with bond graphs, neither the link between the two, nor bond graphs
themselves, can be easily formalized. In contrast, our syntax is based on a
refinement of the well-studied operad of undirected wiring diagrams. The
language effectively decouples the construction of complex models via the
graphical syntax from physical concerns, which are dealt with only at the level
of primitive subsystems that represent elementary physical behaviors. As a
consequence, reuse of models and substitution of their parts becomes possible.
Finally, by construction, systems interact by exchanging exergy, i.e. energy
that is available for doing work, so the language is particularly well suited
for thermodynamic analysis and optimization.
