The temperature distribution and distortion of fluid flow inside the closed cavities, square and triangle, are studied for different boundary conditions. Two different conditions of thermal boundary conditions are used for studying square cavities: (i) Left wall is hot, right wall is cold, top and bottom walls are adiabatic. (ii) Left and right walls are cold, top wall is adiabatic, bottom wall is hot. For triangular enclosure, the boundary conditions are (i) the vertical wall is insulated, bottom wall is hot. (ii) The vertical wall is hot, the bottom wall insulated and the inclined walls are kept cold in both conditions. The velocity of the flow is observed by means of stream function and the temperature distribution is displayed in the form of contours. The study is carried out in ANSYS software. The mathematical procedure for solving the nonlinear system of partial differential equations by penalty finite element method involving bi-quadratic elements is also discussed in detail. © M.H.M. JK and P. V, Published by EDP Sciences, 2021.