District heating systems are a relevant solution for reducing CO2 emissions, especially in dense areas with older buildings. However, due to the heavy investment costs, there is a great interest in simulation and software solutions to reduce distribution losses, limit the overuse of peak generators and optimize the use of storage capacities. In this paper, we describe how we designed, validated and used a library of fast, precise and robust components for district heating systems. Among other results, we could reduce the number of equations in some components by a factor of 40 and demonstrate more than 10% reduction in heat losses on a sample application.