Topology optimization of photonics based on thermodynamically consistent variational principles | Synapse