We present 2-D, fully compressible radiation-MHD simulations of the solar p
hotospheric and subphotospheric layers that run for 2 hours of solar time s
tarting from a magnetic configuration with mixed polarities. In the atmosph
eric layers the simulation reveals a correlation between field strength and
inclination, with a nearly vertical strong-field magnetic component and a
more horizontal weak-field component, in agreement with the observations. O
ur simulation also shows that magnetic flux is converted from one of these
states to the other. In particular, magnetic flux sheets can also be formed
when a new downflow lane starts due to granule fragmentation. The dynamics
of the granulation and field-line reconnection are found to play a role in
the initial stages of a magnetic element's formation. The simulation predi
cts that during or shortly after their formation magnetic elements could be
associated with oppositely polarized flux at a small spatial scale.