Development of complex lubrication systems in the Oil&Gas industry has reached high levels of competitiveness in terms of requested performances and reliability. In particular, the use of HazOp (acronym of Hazard and Operability) analysis represents a decisive factor to evaluate safety and reliability of plants. The HazOp analysis is a structured and systematic examination of a planned or existing operation in order to identify and evaluate problems that may represent risks to personnel or equipment. In particular, P&ID schemes (acronym of Piping and Instrument Diagram according to regulation in force ISO 14617) are used to evaluate the design of the plant in order to increase its safety and reliability in different operating conditions. The use of a simulation tool can drastically increase speed, efficiency and reliability of the design process. In this work, a tool, called TTH lib (acronym of Transient Thermal Hydraulic Library) for the 1-D simulation of thermal hydraulic plants is presented. The proposed tool is applied to the analysis of safety relevant components of compressor and pumping units, such as lubrication circuits. Opposed to the known commercial products, TTH lib has been customized in order to ease simulation of complex interactions with digital logic components and plant controllers including their sensors and measurement systems. In particular, the proposed tool is optimized for fixed step execution and fast prototyping of Real Time code both for testing and production purposes. TTH lib can be used as a standard SimScape-Simulink library of components optimized and specifically designed in accordance with the P&ID definitions. Finally, an automatic code generation procedure has been developed, so TTH simulation models can be directly assembled from the P&ID schemes and technical documentation including detailed informations of sensor and measurement system.