
\section{Introduction} \label{sec:intro}

Jets are ubiquitous in astrophysical accreting systems. Two types of jets have been observed, namely continuous jets and episodic ones. In addition to the temporal difference,  the radiation spectrum, polarization, and velocities of these two types of jet are also different, as summarized in \citet{Fender04}. Episodic jets and radiation flares are often found to be physically associated with each other. One such example is Sgr A*, the supermassive black hole in the Galactic center. Flares are observed in multi-wavebands, ranging from radio, submm, infrared, and X-ray \citep{Baganoff01,Genzel2003,Eckart06,Trippe2007,Yusef-Zadeh2006,Marrone2008}. The flares are strongest in IR and X-ray \citep{Baganoff01,Genzel2003} and they occur simultaneously \citep{Genzel2003}, followed by flares at submm and radio wavebands \citep{Eckart06,Marrone2008}. The peak of the light curve at 43 GHz is found to lead that at 22 GHz by 20-40 minutes \citep{Yusef-Zadeh2006}. This time lag is regarded as the evidence for the ejection and adiabatic expansion of plasmoid from the accretion flow \citep{Yusef-Zadeh2006,Marrone2008}. This interpretation is confirmed by the 7 mm VLBA observations which found possible image of the ejected blob 4.5 hour later after the IR flare, and the speed of the blob is estimated to be 0.4 speed of light \citep{Rauch2016}. 

The phenomena of multi-waveband flares with frequency-dependent time lag and associated ejection are common in black hole sources. For example, large radio flares were detected in three AGNs, namely M81  \citep{King2016}, blazar PKS 1510–089 \citep{Park2019}, and M87 \citep{Hada2014}, preceded by an X-ray flare, $\gamma$-ray flare, and $\gamma$-ray flare in these three sources, respectively. Discrete blobs associated with flares were clearly detected by VLBA or VLBI, with the speed of the blob measured to be 0.5 and 0.2 speed of light in the case of M81 \citep{King2016} and M87 \citep{Hada2014}. Similar phenomenon occurs in a black hole X-ray binary, Cygnus X-1 \citep{Wilms2007}.  

Flares and episodic ejection (as jet knots) have also been observed in protostellar accretion systems \citep{Lee2020,Wolk2005,Feigelson1999}. Although consensus has not been reached on the mechanisms of the ejection and flares, both of them are believed to be powered by magnetic activities in the accretion flow \citep{Feigelson1999}, so it is natural to conjecture that they are physically associated with each other. More interestingly, even in the case of the Sun, large solar flares and coronal mass ejections (CMEs) also occur together \citep{2000JGR...105.2375L,Zhang2005}. 

Many works have been published to explain the origin of black hole flares, usually by invoking synchrotron radiation or Compton scattering by relativistic electrons. These electrons are either accelerated by shocks in jets \citep{Markoff2001} or by magnetic reconnection in accretion flows \citep{Yuan2004,Yuan09,Dodds2009,Dodds2010,Nathanail20,Nathanail2021,Ripperda20,Ripperda2021,Dexter20,Dexter2021,2020MNRAS.499.1561Z}. 
These works usually focus only on the flares, with little discussions on episodic ejections and their associations with flares.

An exception is \citet{Yuan09}. In this work, by analogy with the coronal mass ejections in the Sun, they propose that the turbulent motion and differential rotation of the black hole accretion flow will deform the magnetic field lines; consequently, magnetic reconnection occurs and flux ropes are formed in the coronal region of the accretion flow, which will then be ejected by the magnetic compression force. 

These processes must be highly dynamic but assumptions and simplifications have to be adopted in the analytical treatment of \citet{Yuan09}. 
In the present work, we perform three dimensional  magnetohydrodynamical numerical simulations to examine the  scenario proposed in \citet{Yuan09}, investigating the formation of episodic jets and their association with flares. The paper is structured as follows. In {\S\ref{sec:model}
, we briefly describe our model of general relativity magnetohydrodynamical simulations of hot accretion flows. In {\S\ref{sec:floats}
, we present the main results obtained from our simulations, including the formation of flux rope, its ejection, and the periodicity of the whole processes. In {\S\ref{sec:observation}
, we discuss the applications of our model to observations, including the periodic flares detected in Sgr A* and other sources, the hot spot in Sgr A* detected by the GRAVITY observations, the velocity and the possible periodicity of the ejected blobs in Sgr A*, M81, and M87, and finally the periodic ejection and flares in protostellar accretion systems. 
The comparison between our present work and previous ones are presented in {\S\ref{sec:comp}}. Finally, we summarize our work in {\S\ref{summary}}

\begin{figure*}[htbp!]
 
   \plottwo{figures/figs1a.jpeg}
   {figures/figs1b.jpeg}
    \caption{Snapshots of properties of SANE and MAD in the $x-z$ plane. The color indicates {plasma} $\beta$, black lines denote magnetic field lines .}
    \label{fig:figs1}
\end{figure*}

\section{Model} \label{sec:model}
All black hole sources mentioned in the introduction section are powered by hot accretion flows \citep{Ho2008,YuanNar14}. We therefore perform a set of three-dimensional general relativity magnetohydrodynamical numerical simulations of a hot accretion flow around a black hole using the ATHENA++ code. Spherical coordinates are adopted. We have simulated two kinds of accretion flows, namely SANE (standard and normal evolution) and MAD (magnetically arrested disk), with the magnetization of the accretion flow in MAD much stronger than SANE \citep{Igum03,Nar03,Tchek11}. Two values of black hole spin are considered, $a=0$ and $a=0.98$. The details of the simulations are presented in Appendix A. We find that the value of $a$ is not important for our problem, so in the following we simply refer the models as SANE and MAD. Snapshots of the distributions of magnetic field lines and plasma $\beta$ (defined as the gas-to-magnetic pressure ratio) of the models are shown in Figure~\ref{fig:figs1}.


  

\section{Results} \label{sec:floats}
\subsection{Formation  of flux ropes}
 Solar flares and CMEs have been intensively studied, and the physical mechanism is known to be magnetic reconnection \citep{Zhang2005,Gou2019}. After reconnection, some plasma will be enclosed within helical magnetic field lines and form a “flux rope’’. The flux rope will then be ejected by strong magnetic pressure force and form the CMEs. It was proposed in \citet{Yuan09} that similar processes should also occur in the black hole accretion flows and result in the formation of episodic jets. 
 
\begin{figure*}
\includegraphics[width=.305\linewidth]{figures/fig2-1.jpeg}\quad\includegraphics[width=.305\linewidth]{figures/fig2-2.jpeg}\quad\includegraphics[width=.39\linewidth]{figures/fig2-3.jpeg}
\includegraphics[width=.305\linewidth]{figures/fig2-4.jpeg}\quad\includegraphics[width=.305\linewidth]{figures/fig2-5.jpeg}\quad\includegraphics[width=.39\linewidth]{figures/fig2-6.jpeg}

\includegraphics[width=.305\linewidth]{figures/fig2-7.jpeg}\quad\includegraphics[width=.305\linewidth]{figures/fig2-8.jpeg}\quad\includegraphics[width=.39\linewidth]{figures/fig2-9.jpeg}

\caption{The poloidal magnetic field structure of a flux rope identified in MAD and at simulation time of T=20000{$r_g/c$} at various azimuthal angles $\varphi$ (denoted by the grid cell number $i$ at the top of each plot) in the $x-z$ plane. The magnetic field is denoted by black solid lines with arrows indicating the direction of the field while the color indicates the logarithmic value of the ratio of poloidal and toroidal magnetic field strength. The flux rope is located at $(x,z)=(5-10,5-10)$, depending on the value of $\varphi$.  In this example, the flux rope extends in the $\varphi$-direction for roughly $(63-41)\times5.6=123^{\circ}$.}
\label{fig:fluxrope}
\end{figure*}

\begin{figure*}
\includegraphics[width=0.65\columnwidth]{Figsmiki/densstrSane00T17400}
\includegraphics[width=0.65\columnwidth]{Figsmiki/densstrSane00T18400}
\includegraphics[width=0.65\columnwidth]{Figsmiki/densstrSane00T19400}
\caption{Six reconnection layers from our SANE simulation (marked with blue circles). They will evolve and result in the occurrence of magnetic reconnection and formation of six magnetic islands in $100r_g/c$, shown by the first column of Figure \ref{fig:isla}.  The density is shown by colour and magnetic field by solid lines, with arrows indicating the direction of the field.}
\label{islarec}
\end{figure*}

\begin{figure*}
\includegraphics[width=0.65\columnwidth]{Figsmiki/densstrSane00T19400b}
\includegraphics[width=0.65\columnwidth]{Figsmiki/densstrSane00T19430b}
\includegraphics[width=0.65\columnwidth]{Figsmiki/densstrSane00T19480b}
\caption{Evolution of the magnetic field structure around a reconnection layer shown in the rightmost panel of Figure \ref{islarec}, i.e, at $t=19400r_g/c$. Formation of magnetic island and its further motion can be found in the bottom panels of Fig. \ref{fig:isla}.  }
\label{islarec2}
\end{figure*}

 Stimulated by the above scenario, we have analyzed the simulation data of accretion flows, looking for flux ropes.  We do find that many such helical structure magnetic field lines (i.e., the flux ropes) exist both within and at the coronal region of the accretion flow, from radius as small as 4$r_g$ up to $\sim 30~r_g$, where $r_g$ stands for gravitational radius. The flux ropes are found to keep forming throughout the evolution of the accretion flows in all four models once they reach the steady state. 

 In the present paper, we have tried to find as many as possible flux ropes. We then measure the properties of individual flux ropes and present the typical results. 
 
 One example of flux rope identified in the case of MAD at time T=20000~$r_g/c$ is shown in Figure~\ref{fig:fluxrope}. The poloidal magnetic field structure  is presented in the $x-z$ plane at nine various azimuthal angles\footnote{ The time-averaged magnetic field configuration at a larger scale will show an ``hourglass'' shape, as shown by Figure 5 in \citet{Yang21}.}. As we can see from the figure, in the two-dimensional plane, these flux ropes will be represented by circular magnetic field line patterns --- “magnetic islands”. Note that if a constant-$\varphi$ slice through the flux rope were not perpendicular to the axis of the rope, we would see a whirl in poloidal field lines instead of a circular magnetic island.  

\begin{figure*}
\includegraphics[width=2\columnwidth]{figures/phizratBpBphiSANET18500shifted}
  \includegraphics[width=2\columnwidth]{figures/phizplanedensSANET18500shifted
    \caption{The spatial distribution of the magnetic field strength and density when a flux rope is present in the SANE model. Top panel: Distribution of the ratio of poloidal and toroidal magnetic field strength in the $\varphi-z$ plane with a constant cylindrical radius $r= 30.29$ above the equatorial plane at $T = 18500~r_g/c$. The poloidal field reaches a local minimum at the center of the flux rope, which is shown as a slice through the azimuthal extensions of the magnetic islands. Bottom panel: Distribution of density in the same $\varphi-z$ plane. It is clear that the density of gas in the flux rope ({\bf middle of which is located around $(\varphi,z)=(25^\circ ,20)$ in this case}) is higher than the surrounding medium. Note that only parts of the arcs of the flux ropes lie in this $\varphi-z$ plane, because the cylindrical radius of the flux rope is not constant.  }
    \label{fig:banddensity}
\end{figure*}

To understand the physical mechanism of the formation of flux ropes, after we find a flux rope, we have traced back to the time and location of the flux rope formation. The motion of the flux ropes is traced by examining their movement in different $r-\theta$ planes with various angles $\varphi$. The center of the flux rope is identified by the minimum of the poloidal magnetic field and the circular pattern of the magnetic field lines, as we will explain at the end of section 3.1. Figures \ref{islarec} \& \ref{islarec2} show the tracing results. Three panels in Figure \ref{islarec} show the magnetic field structure in the $r-\theta$ plane at three snapshots. In each panel we can see two reconnection layers, located above and below the equatorial plane of the accretion flow respectively\footnote{We note that the appearance of reconnection layer and subsequent occurence of magnetic reconnection are found to occur randomly, not necessarily simultaneously above and below the equatorial plane.}. These reconnection layers will continue to evolve, result in the occurrence of magnetic reconnection and formation of magnetic islands after a time of $\sim 100r_g/c$. As an example, the evolution process of the reconnection layer located above the equatorial plane in the rightmost (i.e, $t=19400$) snapshot of Figure \ref{islarec} is illustrated in Figure \ref{islarec2}. The six magnetic islands finally formed are shown by the first column of Figure \ref{fig:isla}. We emphasize that similar steps of evolution from the reconnection layer to the magnetic island can be traced in all the cases of island formation captured in our simulations. It is interesting to note that similar to our case, magnetic reconnection is also invoked to explain the formation of solar prominence \citep{Chenpf2020}. 

We speculate that the physical mechanism underlying the above processes is likely as follows.  In the inner region of the accretion flow, the field lines are tangled, due to the MHD turbulence driven by magnetorotational instability \citep{Balbus1991}. Thus the field lines with opposite polarity can come close enough, resulting in the occurrence of reconnection. In addition, the Parker instability and wind launched from the accretion flow will make the magnetic field lines emerge out of the accretion flow into the corona. The differential rotation and turbulent motion of the accretion flow where the field lines are rooted twist the field lines in the coronal region and make the reconnection occur there as well. This scenario of the formation of flux ropes is fully consistent with that proposed by \citet{Yuan09}. It has also been confirmed by other recent MHD numerical simulations \citep{Nathanail20,Nathanail2021,Ripperda20,Ripperda2021}, and it is confirmed again by our present analysis. The detailed comparison with these works will be presented in Section \ref{sec:comp}. 

We find that, the formation of flux rope occurs not only in the coronal region, but also within the accretion flow, as also pointed out in \citet{Nathanail20}.  The reconnection rate is proportional to the Alfven speed. Since $\beta \gg 1$ in the accretion flow, the reconnection rate is much smaller there compared to the coronal region. Combined with the fact that the energy density of the magnetic field in the corona is also stronger than that in the accretion flow \citep[e.g.,][]{Yang21}, we expect that the energy release
during reconnection occurs slowly and weakly thus may not correspond
to observed strong flares. Because of these reasons, in the present paper, we only focus on the
flux ropes formed in the coronal region of the accretion flow.

Because of the reconnection, the poloidal magnetic field at the center of the flux rope should become weaker compared to its surrounding medium. This is confirmed by the top panel of Figure~\ref{fig:banddensity}. In fact, the movement of flux ropes is followed by tracing the trajectories of those minima and the circular magnetic field line pattern. The released magnetic energy should be converted into the thermal and kinetic energy of plasma, and be used to accelerate electrons whose radiation will be responsible for flares. In addition, the density within the flux rope is larger than its surrounding medium, as shown in the bottom panel of Figure~\ref{fig:banddensity}. We speculate the reason as follows. The weakening of the magnetic field results in the decrease of magnetic pressure within the flux rope; consequently the pressure from the surrounding medium compresses the flux rope and increases its density and pressure until a new pressure balance within and outside of the flux rope is established.  Combining
the top and bottom panels of the figure, we can find that the plasma $\beta$ within the flux rope should be higher while the magnetization parameter $\sigma\equiv B^2/(\rho c^2)$ should be lower than its surrounding medium. These results are consistent with \citep{Ripperda20}.

To present quantitative results, the change of various components of the magnetic field and density as a function of $\varphi$ at a given cylindrical radius are given in Figure \ref{fig:densityB}. Note
that since the cylindrical radius of the flux rope is different for different $\varphi$, in this figure, the flux rope is present only at two places, i.e., at $\varphi\sim 100^{\circ}$
and $\varphi\sim 350^{\circ}$. At these two
places, the poloidal field reaches its minima while the density reaches its maxima.

\begin{figure}
  \includegraphics[width=1\columnwidth]{figures/bandrhoalongphiT18500.png}
    \caption{The $\varphi$-profiles of various components of magnetic field and density of the flux rope shown in Fig. \ref{fig:banddensity} at about $z =27r_g$
in SANE, with the star mark denoting the same
magnetic island shown in Fig. \ref{islarec}. Note that since the cylindrical radius of the flux rope at different $\varphi$ is not a constant, in this figure the flux rope is present only at two places.}
    \label{fig:densityB}
\end{figure}

\begin{figure}
  \includegraphics[width=1\columnwidth]{figures/spiralkaa.png}
    \caption{The movement of a flux rope (i.e., a magnetic island) in the SANE simulation, denoted by slices crossing the center of the flux rope at different times and azimuthal angle $\varphi$.  We can see that with the increase of the radial distance of the island from the black hole, its corresponding $\theta$-angle is decreasing, indicating a  ``collimation'' effect.}
    \label{fig:spiral}
\end{figure}


\begin{figure}

  \includegraphics[width=1\columnwidth]{figures/fig3a.jpeg}
    \caption{The time-dependent location (represented by spherical radius) of a plasmoid in the case of MAD.}
    \label{fig:movement}
\end{figure}

\begin{figure*}
 
   \plottwo
      {figures/fig3b.jpeg}
      {figures/fig3c.jpeg}
    \caption{ (Left:) Various velocity components in units of speed of light of the plasmoid shown in Fig. \ref{fig:movement} as a function of time. (Right): Various velocity components in units of speed of light of a plasmoid in the case of SANE as a function of time.}
    \label{fig:blobvel}
\end{figure*}



\subsection{Ejection of flux ropes}

Although flux ropes can be formed at both small and large radii, we find that there is an important difference between them.  At small radii, within roughly $r\sim 10-15\, r_g$, although the flux ropes can be formed, few of them are ejected out. Many flux ropes just stay within the accretion flow and finally fall onto the black hole. This is likely because of the strong gravitational force of the black hole, similar to the existence of the ``stagnation radius’’ within which the motion of the matter is always toward the black hole. This is indicated by the direction of the velocity vectors close to the black hole shown in \citet{Yang21} (refer to Fig. 3 therein). Such a result is also consistent with the absence of wind in the innermost region of the accretion flow \citep{Yang21}. For other flux ropes, although they are found to be able to propagate outward for some distance, they quickly disappear because of the strong differential rotation of the accretion flow at small radii which tears the flux ropes. 

Beyond 10-15 $r_g$, however, we find that the flux ropes  can be ejected out. This is because both the gravity and the differential rotation become weaker. The flux rope is found to become entangled soon after its ejection, because its two end-points are anchored in two different radii of the accretion disk which have different angular velocities. Such an entanglement would lead to the ejection of the flux rope due to the kink instability within an orbital timescale, similar to the solar and space physics cases \citep{Wang2016,2021JPlPh..87f9016S}. The short lifetime is consistent with previous analytical argument \citep{Broderick2006} and perhaps also related to the short lifetime of three flares detected by high resolution GRAVITY observations \citep{Gravity2018}. 

We trace the motion of the broken flux rope (i.e., plasmoid) by examining its movement. The result is shown in Fig. \ref{fig:spiral}. We can see from the figure that the plasmoid is spiraling outward, reminding us of the helical structure of magnetic field in a continuous jet. It is interesting to note that the corresponding  $\theta$-angle of the plasmoid decreases with the increasing distance to the black hole, indicating a collimation effect, which is again similar to the behavior of continuous jets. 

To give a quantitative result, we show by Figure \ref{fig:movement}  the radial location of a plasmoid in MAD as a function of time. The left panel of Fig. \ref{fig:blobvel} shows various components of the velocity as a function of time for this plasmoid.  It reaches as high as 0.3 speed of light at T=23000~$r_g/c$ from 0.05 speed of light at T=20000~$r_g/c$. As a comparison, we show by the right panel of Figure \ref{fig:blobvel} the evolution of various component of the velocity in the case of SANE. Compared to MAD, the typical values of both the magnitude of velocity and acceleration are much smaller. 
\begin{figure}

  \includegraphics[width=1\columnwidth]{figures/fig4b}
    \caption{Forces along the radial direction acting on the magnetic island shown in the left plot of Figure~\ref{fig:blobvel}. The values of $\theta$ and $\varphi$ are indicated atop the upper right corner of the figure. The vertical solid line denotes the location of the magnetic island. We can see from the figure that the Lorentz force is the dominant force that accelerates the motion of the flux rope. }
    \label{fig:force}
\end{figure}

To understand the physical reason for the acceleration of the plasmoid, we have analyzed the forces acting on the flux rope shown in Figure~\ref{fig:movement} (and the left panel of Figure~\ref{fig:blobvel}). They include gravitational force, centrifugal force, Lorentz force, and the gradient of gas pressure. The result is shown in Figure~\ref{fig:force}. We can see from the figure that the Lorentz force is the dominant force that accelerates the plasmoid. The dominant component of the Lorentz force is the gradient of the magnetic pressure, which is enhanced by the occurrence of reconnection below the plasmoid. From this result, we can understand why the acceleration in the SANE case is much weaker than MAD; it is because the plasma $\beta$ in SANE is more than ten times larger than in MAD (refer to Figure~\ref{fig:figs1} and Figure 4 in \citet{Yang21}). Such a scenario of the magnetic acceleration of the ejected plasmoid confirms the prediction in \citet{Yuan09}, and is very similar to the case of solar CMEs \citep{Zhang2005}.

\begin{figure*}[htbp]
\includegraphics[width=0.55\columnwidth]{Figsmiki/densstrSane00T17500}
\includegraphics[width=0.55\columnwidth]{Figsmiki/densstrSane00T17700}
\includegraphics[width=0.55\columnwidth]{Figsmiki/densstrSane00T17900}\\
\includegraphics[width=0.55\columnwidth]{Figsmiki/densstrSane00T18500}
\includegraphics[width=0.55\columnwidth]{Figsmiki/densstrSane00T18800}
\includegraphics[width=0.55\columnwidth]{Figsmiki/densstrSane00T19100}\\
\includegraphics[width=0.55\columnwidth]{Figsmiki/densstrSane00T19500}
\includegraphics[width=0.55\columnwidth]{Figsmiki/densstrSane00T19800}
\includegraphics[width=0.55\columnwidth]{Figsmiki/densstrSane00T20100}

\caption{{Three successive cases of magnetic islands formation at T=17500, 18500 and 19500$~r_{\mathrm g}/c$, just after the reconnection events shown in Fig.~\ref{islarec}, and their subsequent evolution. The data is based on SANE simulation. Colour denotes density while solid lines magnetic field. The dashed black and red lines are spherical coordinate lines passing through the centers of two magnetic islands located at the crossings of the circular and straight dashed lines of the same color. The value of $\varphi$ is indicated atop the upper right corner of each panel. }}
\label{fig:isla}
\end{figure*}



\begin{figure}[t]
   
   
     
     \includegraphics[width=.48\textwidth]{figures/fig5a.jpeg}
     \includegraphics[width=.48\textwidth]{figures/Fig5b.jpeg}
   
   

   
   
   
     \caption{Properties of magnetic field at two different evolution times. The time (“T”) and the number of grid in the $\varphi$-direction (“i”) are shown at the top of each plot. The magnetic field is denoted by black solid lines with arrows indicating the direction of the field. The color indicates the logarithmic value of the ratio of poloidal and toroidal magnetic field strength. In the top panel, two flux ropes are located at $(x,z)=(8,7)$ and (20,28); in the bottom panel two flux ropes are located at (21,12) and (35,20). The magnetic field in the region where the two flux ropes are located is poloidally and toroidally dominated in the top and bottom panels, respectively. At the very center of the two flux ropes in the bottom panel, the poloidal field is weaker than the toroidal field because of the occurrence of reconnection (see text for details). The figure is plotted based on the simulation data of MAD.}
   
     \label{fig:fig5}
\end{figure}

\subsection{Periodicity of the formation and ejection of flux ropes}

We find from the simulation data that, in both SANE and MAD cases, every time when magnetic islands
are formed, their corresponding azimuthal angles $\varphi$ are usually different; but their corresponding radii are almost
always within the range of $20\la r\la 30 r_g$. More interestingly, the formation of flux rope seems to occur quasi-periodically, once the simulations have reached the steady state. Such a phenomenon does not depend on model parameters or numerical resolution. As an example, we show in Figure \ref{fig:isla}  three successive cases of magnetic island formation and their subsequent evolution. The formation time of the three islands is $T=17500, 18500$ and $19500${$~r_{\mathrm g}/c$}, respectively. More cases before $T=17500$ and after $T=19500${$~r_{\mathrm g}/c$} exist but are not shown in the figure due to the spatial limitation. This implies a period of $\sim 1000 r_g/c.$  Such a period matches the orbiting timescale of both
SANE and MAD at $20-30 r_g$ well, which are slightly larger than the Keplerian timescale since the angular velocities of both SANE and MAD are sub-Keplerian \citep{YuanNar14}.  Since the formation of flux rope at relatively large radii is accompanied by plasmoid ejection, such a periodicity implies that, in addition to flares, the ejection of plasmoids also occurs periodically. At smaller radii, the reconnection (thus flare) is also found to occur periodically, although not accompanied by ejections.

The presence of periodicity combined with its orbital timescale strongly implies that, compared to turbulence, the differential rotation of the accretion flow seems to play a more important role in twisting the magnetic field lines and resulting in the occurrence of magnetic reconnection. This scenario is enhanced by the fact that there seem to be no difference in terms of the periodicity of the
formation of flux ropes in SANE and MAD cases, although MAD is much less turbulent compared to SANE. In contrast, the occurrence of CMEs in the Sun mainly depends on solar activity. Although various periodicities exist for CMEs and flares \citep[e.g.,][]{Lou2003}, the periods are not related to the rotation period of the Sun. This is because, unlike the differentially rotating accretion flow, the geometry of Sun is spherical and the motion of the foot points of the field loops is driven by solar dynamo through local convection rather than by the rotation of the Sun.

In addition to the periodicity, another interesting finding is that in some cases, when a plasmoid moves outward, it may catch up and merge with a previously produced plasmoid having a slower speed. The merger of two magnetized islands must be accompanied by magnetic reconnection. This will results in  strong radiation so strong flares
are expected to occur. \citet{Yuan2012} have proposed this scenario as the mechanism of Gamma-Ray bursts.

\section{Applications to observations} \label{sec:observation}

\subsection{Periodic flares and the hot spot in Sgr A* and other black holes}

The formation of the flux rope occurs because of magnetic reconnection, which must be accompanied by electron acceleration. The synchrotron radiation of the accelerated electrons will be responsible for the observed flares in various wavebands, ranging from IR to X-ray and $\gamma$-ray flares in black hole sources mentioned above. 

Near-infrared flares in Sgr A* were recently resolved by high resolution GRAVITY observations, with a compact ``hot spot’’ detected orbiting around the black hole with orbiting radius of 6-10 $r_g$ \citep{Gravity2018} . This hot spot is produced by  magnetic reconnection found in our simulations at small radii of the accretion flow. The flares are found to be polarized, with the polarization signature being consistent with orbital motion of a hot spot in a strong poloidal magnetic field \citep{Gravity2018}. In our simulation, we find that at the place of reconnection (i.e., the place of ``hot spot’’), which is also roughly where the flux rope is located, the magnetic field could be dominated by either poloidal or toroidal components, depending on time. This is shown by the two panels of Figure~\ref{fig:fig5}. The top panel of this figure shows a case that the field is dominated by the poloidal component, which is consistent with the observation. But at another time shown by the bottom panel of this figure, the field is dominated by toroidal component. This prediction could be verified by future observations. The detailed phenomenological modeling of the IR and X-ray light curves of Sgr A* indicates that to explain the simultaneity and symmetry of the X-ray and near-infrared light curves, the magnetic field strength is required to significantly decrease during the flare \citep{Dodds2010}. This is consistent with the weakening of the magnetic field during reconnection which we have described above and explicitly shown in Figure~\ref{fig:banddensity}.

From the over 2-hour long infrared light curve of Sgr A*, several periods of variability are identified by observations, with period ranging from 17 to 40 minute \citep{Genzel2003,Trippe2007,Genzel2010,Eckart2006}. The observed periods are consistent with orbital period at 3-5$r_g$ for the $3.6\times10^6$ solar mass black hole in Sgr A*, assuming the accretion flow in Sgr A* is described by an MAD. Given that the typical lifetime of a “hot spot” is shorter than one orbit timescale as we have explained before, the detected periodicity is best explained by the periodic occurrence of reconnection events found in our simulation at small radii.  The observed period is not a fixed value but has a range,  consistent with our finding that reconnection occurs in a range of radii.

\subsection{Ejected blobs in Sgr A*, M81, and M87: origin, velocity, and the possible periodicity}

In our simulations, the flux ropes (i.e., plasmoid) formed beyond 10-15 $r_g$ will be ejected outward from the surface of the accretion flow. This explains the origin of the radio-emitting blobs observed in Sgr A*, M81, M87, and other black hole sources. The observationally measured ejection velocity of 0.4, 0.5, and 0.2 of the speed of light for the ejected plasmoids in Sgr A*, M81 and M87 is also quantitatively similar to what we have obtained in the case of MAD, as shown in Figure~\ref{fig:blobvel}, which is about 0.3 of the speed of light. The ``MAD’’ nature of the accretion flow in M81 and M87 is consistent with most recent studies \citep{Shi2021,EHT2021,Yuan22}. 

Examining the periodicity of the ejection of plasmoids is difficult since it requires very high spatial resolution and sensitivity of the telescope and the suitable observational targets. The high-resolution Global Millimeter-VLBI-Array observation to M87 jet reveals some discrete blobs at distance of about 100 $r_g$ from the central black hole \citep{Algaba2021}. By measuring the spacing between two adjacent blobs from the image and adopting a projected moving speed of 0.2 of the speed of light \citep{Hada2014}, we can estimate that the time interval of two adjacent ejections is about one year. This is in good consistency with our predicted period of 1000 $r_g/c \sim$ 1 yr for the $6\times10^9$ solar mass supermassive black hole in M87 \citep{Gebhardt2011}. 

Most recently, two quasi-periodic oscillations (QPOs) are detected in the TeV blazar PKS 1510-089 by the Fermi Large Area Telescope \citep{Roy2021}. One is a 3.6-day QPO that lasted for five cycles with a moderate significance of $\sim 3.5 \sigma$, another is a 92-day QPO that lasted for seven cycles, with a significance of $\sim 7.0\sigma$. As discussed in \citet{Roy2021}, models like binary black holes and a procession jet are unlikely; two attractive models are a rotating hot spot in the inner region of the accretion flow and ``equispaced magnetic islands'' inside the jet. The remaining problem for the first model is that since the accretion flow in a blazar should have an almost face-on orientation, it may be hard for the rotating hot spot to produce enough variability. 

Obviously, these two scenarios are very similar to what we have proposed in the present work. The only difference is that, for the first ``hot spot'' model, we think the variability is not caused by a single hot spot orbiting around the black hole, but several hot spots periodically appeared in the inner region of the accretion flow since the typical lifetime of a hot spot is shorter than one orbital time thus difficult to explain the observed several cycles.  Moreover, our ``modified'' hot spot model has the advantage of overcoming the ``not-enough variability'' difficulty.   

\subsection{Possible application to protostellar accretion systems}

Although our simulations are done for hot accretion flows around black holes, we speculate that the basic physics relevant to flares and ejections should also work for accretion disks in protostars. This is why very similar phenomena have been observed in these systems. Specifically, in this case, the period should correspond to the orbital period at the inner edge of the accretion flow where it is truncated by the magnetosphere of the protostar, which is a few days. Periodic ejections are observed from the spacings of the jet knots \citep{Lee2020} in those systems, and the period can be estimated from the spatial intervals and the jet velocities. Unfortunately, the current instrumental limit of spatial resolution $\sim 0.1^{"}$ sets a limit on the period detection no shorter than about 1 yr \citep{Lee2020}. On the other hand, the Chandra light curve does show obvious periodicity with the period of $2\times10^5$ second or a few days, according to \citet{Wolk2005} and \citet{Flaccomio2012} (Ref. to Fig. 3 in \citet{Wolk2005} and Fig. 4 in \citet{Flaccomio2012}), consistent with our prediction. 

\section{Comparison with previous works}
\label{sec:comp}

The most relevant previous work is \citet{Yuan09}. In that work, by analogy with the coronal mass ejection in the Sun, an analytical model was proposed to explain the formation of episodic jets and their association with flares. The basic scenario proposed in that work, i.e., flux ropes are formed due to magnetic reconnection and they are then ejected out by the magnetic forces, are fully confirmed by the present numerical simulations. Due to the limitation of analytical calculations, although the whole physical processes involved are highly dynamic, many assumptions and simplifications have to be adopted in \citep{Yuan09}. For example, the formation of flux rope is purely an assumption there. The quantitative calculation to the ejected velocity of the flux rope is also based on assumptions on the distributions of magnetic field and density of the coronal gas. Compared to \citet{Yuan09}, our current work is much more realistic and comprehensive.  Moreover, important new findings are obtained, e.g., the periodic formation of the flux rope and its ejection, and the quantitative prediction of the velocity of the ejected blobs. 

Recently several MHD numerical simulation works focusing on the analysis of reconnection in accretion flows have been published. It is thus useful to compare our simulations with these works. In the two-dimensional general relativity ideal magnetohydrodynamic numerical simulations by \citet{Nathanail20}, the formation and evolution of current sheets are investigated. Special attention is paid to the effect of different initial magnetic field configurations. Similar to our work, they find that plasmoids are formed both within and at the surface of the accretion flow due to magnetic reconnection, which is driven by the turbulent motion of the accretion flow. Moreover, they find that plasmoids are formed during the reconnection, which is again consistent with our work. 

In the works by another group, the two and three dimensional MHD simulations including weak Ohmic resistivity are performed, focusing on the modeling of magnetic reconnection and the formation of palsmoids \citep{Ripperda20,Ripperda2021}. Since an explicit resistivity is included which can approximately mimic the kinetic effects, their simulations are more suitable than ours to describe magnetic reconnection. Both SANE and MAD are studied as in our work. They find that within about $20r_g$ of the accretion flow current sheets and plasmoids are ubiquitous features that form regardless of the initial magnetic field, the magnetization of accretion flows, and the spin of the black hole. 

Different from our work and \citet{Nathanail20}, another mechanism for the formation of plasmoid is identified in \citet{Ripperda20}, namely the tearing instability of the current sheet. When the reconnection layer becomes thin enough, the reconnection layer can break up and produce chains of plasmoids. These small plasmoids can merge and grow to macroscopic scales of the order of a few Schwarzschild radius, and be advected along the jet’s sheath or into the disk. We do not find such an instability in our simulations.  For this instability to occur, the Lundquist number $S=v_{\rm A} L/\eta$ needs to be larger than $10^4$. Here $v_{\rm A}$ being the Alfven speed, L being the typical length of the current sheet, and $\eta$ being the resitivity \citep{McKinney2012}. In our simulations, $S\lll10^4$   because of the high numerical resistivity caused by the relatively low resolution of our three-dimensional simulations. In reality both turbulence of the accretion flow and tearing instability in current sheet should be able to drive reconnection and the formation of plasmoids, as seems to be confirmed by a recent work \citep{Rosenberg2021}. In this work, resistive MHD equations are solved, reconnection and plasmoids are found to be formed both via merging current sheets due to turbulent motions of the accretion flow and through reconnection due to current sheet instabilities. 

\section{Summary}\label{summary}

Episodic ejections  of blobs (episodic jets) have been observed in both black hole and protostellar accretion systems and they are often associated with radiation flares. Notable sources include Sgr A*, M81, and M87, among others. \citet{Yuan09} has proposed an analytical MHD model for episodic jet and its association with flares. In the present work, we develop that work by performing three dimensional GRMHD  numerical simulation of hot accretion flows. Both SANE and MAD are considered. We have analyzed the simulation data and obtained the following results. 

\begin{itemize}
    \item[(1)] We find once the simulations have reached the steady state, flux ropes are keep forming both within and at the coronal region of the accretion flow, from radius as small as 4$r_g$ up to $\sim 30r_g$.  One example of a flux rope in the case of MAD is shown in Figure \ref{fig:fluxrope}. It extends in the $\varphi$ direction for about 120$^{\circ}$.
    
    \item[(2)] We find that the flux rope is formed due to the reconnection of magnetic field lines, driven by the differential rotation and turbulent motion of the accretion flow. This scenario is consistent with that proposed in \citet{Yuan09} and recent MHD numerical simulations. The detailed comparison between the present work and those previous ones are presented in Section \ref{sec:comp}.
    
    \item[(3)] We find that flux ropes formed at small and large radii have different fate. At small radii, inside of $\sim$ 10-15$r_g$, few flux ropes can be ejected out, likely because of the strong gravitational force of the black hole, similar to the absence of wind at small radii. Beyond that radius, flux ropes can be ejected out. The ejected flux ropes are found to break within one orbital timescale due to the kink instability. 
    
    \item[(4)] The broken flux ropes (i.e., plasmoids)  spiral outward, with radial velocities shown in Figure \ref{fig:blobvel}. A clear acceleration in both cases is found and the  velocity can reach $0.3c$ and $0.08c$ for MAD and SANE, respectively. We have analyzed the forces and found that the acceleration is mainly due to the gradient of the magnetic pressure, as shown by Figure \ref{fig:force}, again consistent with \citet{Yuan09}. 
    
    \item[(5)] The whole processes mentioned above, i.e., the formation of the flux ropes and their subsequent ejection, occur periodically, with the period being the orbiting time at the radius where the flux ropes are formed. This implies that differential rotation of the accretion flow plays a more important  role than turbulence in twisting the magnetic field lines and result in the formation of reconnection. 
    
    \item[(6)] Magnetic reconnection should accelerate some electrons, their synchrotron emission explains observed flares and the origin of the ``hot spot'' in Sgr A* detected by GRAVITY. 
   
    The periodicity detected from the IR light curves of Sgr A* and $\gamma-$ray light curves of blazar PKS 1510-089 are explained by the periodic formation of flux ropes. 
    
    \item[(7)] The observed ejection of blobs is explained by the ejection of flux ropes formed at relatively large radii. In Sgr A$^*$, M81, and M87, the measured velocity of the ejected blobs agrees with the velocity predicted in our simulations of MAD. The predicted periodicity of the  ejection seems to be supported by some observations of M87 and PKS 1510-089.  
    
    \item[(8)] Finally, we speculate that our results may also be able to interpreting flares and episodic ejection observed in protostellar systems. The measured period in the X-ray light curve is roughly consistent with the orbital period at the inner edge of the accretion flow where it is truncated by the magnetosphere of the protostar. 
    
\end{itemize}


\section*{Acknowledgments}
We thank the useful discussions with Drs. P.F. Chen, J. Lin, and Y.M. Wang on the solar flares and coronal mass ejections, and C. White for his help of using ATHENA++ code. The {anonymous} referee is acknowledged for
constructive suggestions and comments. This work has made use of the High Performance Computing Resource in the Core Facility for Advanced Research Computing at Shanghai Astronomical Observatory. We also thank ASIAA, Taipei for the use of their visualization servers. This work was supported by CAS President’s International Fellowship for Visiting Scientists grant 2020VMC0002 (MC), Polish NCN grant 2019/33/B/ST9/01564 (MC), Natural Science Foundation of China grants 12133008, 12192220, and 12192223 (FY, HY), and Ministry of Science and Technology of Taiwan grants 108-2112-M-001-009 and 109-2112-M-001-028 (HS)





