  Context. Acoustic waves in the Sun are affected by the atmospheric layers,
but this region is often ignored in forward models due to the increase in
computational cost. Aims. The purpose of this work is to take into account the
solar atmosphere without increasing significantly the computational cost.
Methods. We solve a scalar wave equation that describes the propagation of
acoustic modes inside the Sun using a finite element method. The boundary
conditions used to truncate the computational domain are learned from the
Dirichlet-to-Neumann operator, that is the relation between the solution and
its normal derivative at the computational boundary. These boundary conditions
may be applied at any height above which the background medium is assumed to be
radially symmetric. Results. Taking into account the atmosphere is important
even for wave frequencies below the acoustic cut-off. In particular, the mode
frequencies computed for an isothermal atmosphere differ by up 10 {\mu}Hz from
those computed for the VAL-C atmospheric model. We show that learned infinite
elements lead to a numerical accuracy similar to that obtained for a
traditional radiation boundary condition. Its main advantage is to reproduce
the solution for any radially symmetric atmosphere to a very good accuracy at a
low computational cost. Conclusions. This work emphasizes the importance of
including atmospheric layers in helioseismology and proposes a computationally
efficient method to do so.
