%!TEX root = ../main.tex

\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\label{chapter:introduction}

RFX, RFX-mod, and RFX-mod2 are the names that have marked the evolution over time of one of the largest experiment for the study of plasma physics in the Reversed Field Pinch (RFP) magnetic configuration located in Padua and held by RFX Consortium\footnote{RFX achieved its first plasma in 1997, progressed to RFX-mod operational between 2004-2016, updating now to RFX-mod2
\url{https://www.igi.cnr.it/en/research/magnetic-confinement-research-in-padova/rfx-mod2/unveiling-the-evolution-upgrades-from-rfx-mod-to-rfx-mod2}.}.

Given the inherent complexity of a fusion device, executing an experiment in such an environment requires a comprehensive set of tools designed to accurately record and manage data from each experimental attempt, as well as to support users in analyzing the large volumes of data generated.

The phases of an experimental campaign -- and the associated recording of data and documentation -- are numerous and heterogeneous. Consequently, a wide variety of tools are needed to capture the different aspects involved. The description of the experimental setup -- including the documentation outlining the experiment's rationale, design specifications, and parameter configurations -- typically relies on the use of a document management system and an experimental logbook. Parameter configuration, control system definition, and data acquisition are generally handled by an integrated Supervisory Control and Data Acquisition (SCADA) system. Finally, data post-processing and result synthesis are carried out using a dedicated summary code.

This thesis proposes the development of an integrated system for logbook data recording, access to experimental data, and automatic generation of summary reports.

Such an integrated tool for data access provides a solid foundation for ensuring the correlation of all information sources associated with the experimental campaigns to be conducted on RFX-mod2. This is essential for maintaining a consistent interpretation of experimental data and for enabling broader contextualization, particularly in the perspective of future studies employing Big Data methodologies.


% \section{Scope and organization of the thesis}
\vspace{1em}
This thesis is organized into five chapters, each addressing a crucial aspect of the unified platform for experimental data access and documentation. Below is a brief overview of each chapter's content and purpose.

\paragraph{Chapter 1: Data Management in Magnetic Confined Nuclear Fusion Experiments}
This chapter presents a detailed explanation of the motivation, objectives, and scope of the thesis. It discusses the challenges involved in managing data generated by fusion experiments and in documenting the processes and outcomes of large-scale scientific research. To address these challenges, the thesis proposes the development of a unified platform designed to support efficient data management and to ensure comprehensive, consistent documentation throughout the experimental workflow.

\paragraph{Chapter 2: Experiment Logbook Management}
This chapter describes the design and implementation of the Experiment Logbook Management system, a web-based application for managing semantic information related to experiments. It emphasizes the importance of effective documentation for reproducibility and collaboration in scientific research.

\paragraph{Chapter 3: Scientific Data Access}
This chapter focuses on the design and implementation of the Query Engine system, an integrated framework for efficient access to, retrieval of, and processing of large volumes of experimental data stored in MDSplus. It describes how the system streamlines data retrieval and processing tasks and supports reusable and extensible data analytics workflows.

\paragraph{Chapter 4: Results and System Evaluation}
This chapter presents the results of evaluating the Query Engine system. It details the system setup, performance testing methodology, and experimental results, analyzing the system's functionality, scalability, and the impact of different configurations.

\paragraph{Chapter 5: Conclusions and Future Works}
The final chapter summarizes the findings and contributions of the work, discusses the system's overall impact on experimental research workflows, and proposes potential directions for further development and improvements.





%   ____ _                 _              _ 
%  / ___| |__   __ _ _ __ | |_ ___ _ __  / |
% | |   | '_ \ / _` | '_ \| __/ _ \ '__| | |
% | |___| | | | (_| | |_) | ||  __/ |    | |
%  \____|_| |_|\__,_| .__/ \__\___|_|    |_|
%                   |_|                     

\chapter{Data Management in Magnetic Confined Nuclear Fusion Experiments} 
\label{chapter:data-management-in-magnetic-confined-nuclear-fusion-experiments}

Nuclear fusion is the process by which two atomic nuclei combine to form a heavier nucleus, releasing a significant amount of energy. In thermonuclear fusion -- used in experimental fusion research -- high temperatures are employed to increase the kinetic energy of the particles, thereby enhancing the frequency and effectiveness of nuclear collisions. At the typical temperatures used in such experiments, matter exists in the plasma state -- that is, a highly ionized gas composed of free electrons and atomic nuclei. In this state, the thermal energy is sufficient to overcome the electrostatic forces that normally bind electrons to nuclei, allowing the charged particles to move freely and interact through electromagnetic and nuclear forces. 
The most efficient fusion reactions involve light nuclei, with particular focus on the fusion of hydrogen isotopes such as deuterium (${}^2\mathrm{H}$) and tritium (${}^3\mathrm{H}$). These isotopes are widely used in fusion experiments due to their favorable reaction cross-section and energy yield. The primary reaction of interest is given by~\cite{plasma-physics-and-fusion-energy}:

\begin{equation}\label{fuzion_reaction}
{}^{2}\mathrm{H} + {}^{3}\mathrm{H} \rightarrow {}^{4}\mathrm{He}\ (3.5\ \mathrm{MeV}) + n\ (14.1\ \mathrm{MeV})
\end{equation}

The goal of any fusion reactor is to satisfy the so-called "Lawson criterion", that is, to reach an operational state in which the reaction rate is sufficient to self-sustain the energy spent to keep the plasma ignited. By considering specific energy loss parameters, such as bremsstrahlung radiation or collisional and turbulent phenomena, the reactor's performance is expressed through a single value called the "triple product"~\cite{cecco}:
%
\begin{equation}
n \tau_E T_i \geq 3 \cdot 10^{21} m^{-3}s \cdot keV
\end{equation}
%
The plasma ignition curve that satisfies the Lawson criterion shows a minimum value at $T_i \simeq 20keV$: this is the temperature to be achieved in the energy balance, by varying the density ($n$) and the confinement time ($\tau_E$).
%
Due to the high temperature, no material can contain the reaction without contaminating it. A solution studied for over 60 years is the \textbf{magnetic confinement}, where the plasma is contained trapped within a magnetic field gradient\footnote{Another method is \textbf{inertial confinement (ICF)}, achieved by imploding a spherical shell with the D-T mixture, compressed by laser or high-energy ion beams.}.
%
The design of each fusion machine reflects the chosen configuration of its field. The \textbf{toroidal} configuration seemed the most topologically advantageous: the torus is the only orient-able, compact surface where a continuous vector field can be defined without critical points\footnote{This allows the field lines to recombine, minimizing energy and maximizing stability.}. The field configuration then consists of a composition of toroidal and poloidal magnetic components. A usual toroidal reference system is proposed with the following coordinate notation:
%
\begin{itemize}
\item \(r\) = radial coordinate
\item \(\vartheta\) = poloidal angle
\item \(\varphi\) = toroidal angle
\end{itemize}
In Figure~\ref{fig:toroidal_coords}, a sketch of the toroidal coordinates notation is shown for a better comprehension of the main geometry.
%
Within this topological structure, the confinement machines can be also further divided into three main categories:
\begin{itemize}
\item \emph{Tokamak}: Both fields are present, with a dominant toroidal field that stabilizes the plasma.
\item \emph{Stellarator}: A complex coil structure twists the plasma column.
\item \emph{Reversed Field Pinch (RFP)}: The toroidal and poloidal fields are comparable, but stability is more critical. This configuration offers higher efficiency.
\end{itemize}

The RFX experiment, based in Padova at the Consorzio RFX, aim at studying the latter solution, namely the Reversed Field Configuration~\cite{the-reversed-field-pinch}.

RFX and the subsequent modifications are characterized by a toroidal circular shaped geometry, with minor radius of 0.46~m and major radius of 2~m. The toroidal field can reach a maximum field of 0.7~T with a typical plasma pulse duration that spans along 0.5~s. 
The experiment evolved in 2004 in RFX-mod which was able to achieve a plasma current up to 2~MA. This high currents has been shown to be crucial for achieving the magnetic field reversals typical of RFP devices. The experiment uses a sophisticated system of magnetic coils to create and control the magnetic fields within the torus. These include: the toroidal field coils, winded around the torus and generating a magnetic field parallel to the torus's circular axis, and poloidal field coils, that shape the plasma equilibrium and control its stability by generating a magnetic field that runs in loops inside.

In addition to the standard configuration RFX exploits also the so called ``saddle coils'' that, injecting radial field through the vessel, can actively control Magnetohydrodynamic (MHD) instabilities. These coils are crucial for stabilizing the plasma and improving the confinement. They are named "saddle" coils due to their shape, which allows them to be placed around the torus to exert localized magnetic influence on the plasma.

The RFX-mod experiment has contributed significantly to the understanding of plasma confinement, stability, and the behavior of RFP systems. With its advanced control system it played a key role in exploring the high current regimes.
The plasma in a such configuration, when the current exceeds a certain threshold value, shows to organize itself spontaneously assuming the shape of a helix: in this condition the temperature is higher and the confinement is more stable. This discovery, that has been initially observed in the RFX laboratories, became the principal matter of investigation of such kind of experiments since 2009~\cite{lorenzini2009self}.

% show the experiment and the helics
A pictorial representation of the main helix structure is shown in Figure~\ref{fig:rfx_helix}.

\begin{figure}[htbp]
    \centering
    \begin{subfigure}[b]{0.65\textwidth}
        \centering
        \includegraphics[width=\textwidth]{figures/toroidal_coords.png}
        \caption{}
        \label{fig:toroidal_coords}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.25\textwidth}
        \centering
        \includegraphics[width=\textwidth]{figures/helix.png}
        \caption{}
        \label{fig:rfx_helix}
    \end{subfigure}
    \caption{Typical notation for the toroidal coordinates reference system (a), and a pictorial representation of the self-organized helical single mode of a RFP (b). }
    \label{fig:coods_and_helix}
\end{figure}


% explain safety factor and MHD in brief ?
The overall plasma equilibrium is obtained trough the study of the plasma dynamics using the model called Magnetohydrodynamic (MHD) system.
In the MHD model, the equations of classical electromagnetism are combined with those of the fluid motion~\cite{wesson2004tokamaks}. Typically, the analysis of fluid plasma involves the generalized movements of each ionic species; however, for simplicity it is possible to consider each pair of values relating to ions and electrons in a single parameter and thus obtain a single fluid trend. 

Each charge is subjected to a forces that comes from pressure and electromagnetic interaction with fields. In the static equilibrium condition, the model assume a particularly simple shape and is described by the equations:
\begin{align*}
    \nabla \cdot \Vec{B} &= 0 \\
    \nabla \times \Vec{B} &= \mu_0 \Vec{J} \\
    \Vec{J} \times \Vec{B} &= \nabla p
\end{align*}

% explain the fourier modes decomposition
Instabilities can develop around this equilibrium condition, and due to the system's strict toroidal periodic geometry, these perturbations can be effectively described as deviations from equilibrium expressed in the time-space frequency domain:
\begin{equation}
    \Tilde{\psi}(\Vec{r},t) = \sum_k \Tilde{\psi}_k(r) e^{i(\Vec{k}\cdot\Vec{r}-\omega t)} = \sum_k \Tilde{\psi}_k e^{i(m\vartheta+n\varphi-\omega t)}
\end{equation}
Here, $m$ and $n$ denote the poloidal and toroidal mode numbers, respectively, corresponding to the number of oscillation periods in the poloidal ($\vartheta$) and toroidal ($\varphi$) directions. These mode numbers characterize the spatial structure of the fluctuations within the plasma.

A gradient in the poloidal magnetic field creates a barrier that traps and pinches ions toward the center of the plasma column that forms inside the torus. In the same way, the perturbation wave numbers are closely related to this magnetic field configuration, which appears in the equilibrium condition as a series of nested magnetic surfaces -- or "shells" -- with increasing field lines pitch moving outward in the radial axis, as illustrated in Figure~\ref{fig:EM_fields_windiwng}.

Thus, having parallel shells with the same winding number corresponds to surfaces where field lines attract each other, seeding a new possible instability caused by a growing de-structured internal field configuration. For this reason, a good prerequisite for stability is obtained keeping a winding number ( and so the $m/n$ ratio ) monotonically changing along the radial section of the plasma column, thus ensuring that surfaces that are close to each other keep different winding number of the field lines. The usual quantity to observe for this behavior is the parameter called ``\emph{safety factor}'' that in this case needs to be monotonically shaped.
%
\begin{equation}
    q(r) = \frac{rB_\varphi(r)}{R_0B_\vartheta(r)} = \frac{m}{n}(r)
\end{equation}

The RFP configuration is also affected by the fact that, for $q$ values that result rational numbers, a single shell present field lines that reconnect with them selves after $m/n$ periods, creating the so called "resonant" surface.   
Many instabilities grow in such condition, making RFP generally unstable and prone to evolve in a chaotic configuration.
However, as before stated, in high current regimes the system showed to relax in a more stable condition where a single mode dominates the others -- the mode (1,-7) for the RFX and RFX-mod geometry\footnote{the n modes will be presented to be negative values hereafter to match the orientation of the reference that has been used in RFX} -- a state of the plasma that appears convenient for the overall confinement.

RFX-mod helped to improve our understanding in this RFP self-organization, observing the formation of high transport barrier and the growth of convective cells. It can be also operated in the Tokamak configuration, in which it helped to explore shallow safety factor profiles (that are usually avoided by Tokamaks), with experiments reaching the edge of the safety factor values as low as q(a) = 1.2 (where $a$ is the radial position of the wall).

It also contributed to the study of the so called tearing modes mitigation\footnote{Tearing modes are instabilities caused by the direct reconnection of the field lines from different magnetic shells, forming a chaotic configuration called magnetic island, that are very common in RFP due to the low q factor and plasma resistivity.} and the stabilization of resistive wall modes using both poloidal and radial sensors. Controlling these may help to understand in a general experiment how to actively prevent disruptions, that are particularly dangerous in Tokamaks, and how to control the safety factor to actively move the plasma in the desired configuration~\cite{Puiatti_2015}.

% show example of diagnostic and signals
To observe the inherent complexity of hot plasmas with their interaction with the surrounding matter, and to validate the related inherent models, RFX-mod has been equipped with a very large number of different diagnostics. In the Figure~\ref{fig:diagnostics}, a brief schematic of the diagnostic components localization has been reported, due to space allocation around the torus the diagnostics are usually marked with their angular position as they observe a particular phase of the plasma perturbations.

% present some of the diagnostics from puiatti presentation

In Figure~\ref{fig:signals}, some of the most representative observed quantities have been reported from the shot $\texttt{\#}31477$. The first plot from the top presents the rapid increase of the plasma current profile followed by a stationary saturation period. The second plot shows the evolution of the magnetic structure of the plasma over time, where it can be easily appreciated the self organization behavior of the plasma that starts when the current reach a value of about 1.5~T. At that level the chaotic exchange of energy among different mode perturbation relaxes into a single "dominant" one characterized by the wave number (1,-7), this configuration is not completely stable though and the helix gets lost in time leaving space for a chaotic state of multi-modes interplay.
The third plot shows the actual electron density of the plasma with respect to a particular density reference, called Greenwald limit, where other kind of perturbations grows~\cite{Martin_Greenwald_2002}.
In Chapter~\ref{chapter:ResultsAndSystemEvaluation} both the current profile and the dominant mode ratio will be used as an example of RFX data access routines, specifically to extract from this signals some possible pulse summary quantities, such as the maximum of achieved current and the ratio of ordered single-elicity time over the chaotic state.

\begin{figure}[htbp]
    \centering
    \begin{subfigure}[b]{0.55\textwidth}
        \centering
        \includegraphics[width=\textwidth]{figures/diagnostics.png}
        \caption{}
        \label{fig:diagnostics}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.40\textwidth}
        \centering
        \includegraphics[width=\textwidth]{figures/nf512366f01_online.jpg}
        \caption{}
        \label{fig:signals}
    \end{subfigure}
    \caption{RFX map of diagnostics with related toroidal position (a). A RFP discharge time evolution for pulse $\texttt{\#}31477$ of plasma current, dominant $m=1, n=-7$ mode vs secondary $m=1, n=-8,-15$ modes, and obtained Greenwald fraction for electron density (b)}
    \label{fig:diag_and_signals}
\end{figure}

RFX-mod2 will be built thanks to the results obtained in RFX-mod, the RFP experiment in operation until 2016, when the design of its upgrades started. The RFX-mod2 machine is designed to complete and enhance the study of the properties of both the RFP configuration in the plasma current regimes up to 2MA and a variety of Tokamak equilibria~\cite{tokamaks}. To this end, modifications of some components of the RFX-mod machine are underway\footnote{\url{https://www.igi.cnr.it/en/research/magnetic-confinement-research-in-padova/rfx-mod2/}}.

The substantial modification of the toroidal complex of the RFX experiment represents the second major modification since its original design~\cite{topical-issue-rfx}. 
%
The challenge of this new machine is to be able to produce a plasma with much improved parameters compared to those of RFX-mod and to clarify whether the RFP configuration can represent a valid alternative to the tokamak design in the perspective of a future fusion reactor.

In RFX-mod2, the internal inconel vacuum chamber will be removed, and the plasma will be directly surrounded by the copper shell (protected by 2016 graphite tiles). This increase in the conductivity of the first conductive material surrounding the plasma will allow to observe it without stationary localized interaction, even at high current regimes (Figure~\ref{fig:rfx-mod2_modifications}).

% \begin{figure}[ht]
%     \centering
%     \includegraphics[width=0.8\linewidth]{figures/rfx-mod2-modifications.png}
%     \caption{RFX-mod2 modifications}
%     \label{fig:rfx-mod2-modifications}
% \end{figure}

\begin{figure}[htbp]
    \centering
    \begin{subfigure}[T]{0.30\textwidth}
        \centering
        \includegraphics[width=\textwidth]{figures/EM_fields_winding_shells_RFP.jpg}
        \caption{}
        \label{fig:EM_fields_windiwng}
    \end{subfigure}
    \hfill
    \begin{subfigure}[T]{0.65\textwidth}
        \centering
        \includegraphics[width=\textwidth]{figures/rfx-mod2-modifications.png}
        \caption{}
        \label{fig:rfx-mod2_modifications}
    \end{subfigure}
    \caption{A reversed field pinch internal magnetic shells, showing how the direction of the magnetic field varies with radius (a). The current ongoing modification of the RFX-mod experiment into RFX-mod2 showing the structural changes and the removal of the inner vacuum vessel component (b). }
    \label{fig:rfx-mod2_fieds_and_modifications}
\end{figure}


It is expected that this will enable the production of better-confined plasmas with more stationary helical states. It should be emphasized that these results will be very important for understanding whether the RFP configuration can indeed have potential as a future reactor.

The purpose of these changes is twofold:
\begin{itemize}
    \item Significantly decrease the resistivity of the first conducting structure surrounding the plasma.
    \item Bring the plasma closer to the copper stabilizing shell
\end{itemize}

Thanks to these modifications, firstly, it will be possible to more effectively control the energy losses connected to the interaction of the plasma with the chamber walls that contain it, obtaining more stationary Single Helicity states~\cite{escande2000single} and warmer and better confined plasmas. Secondly, the new machine will have a larger plasma volume which is also closer to the control systems. The sophisticated magnetic instability control system already installed on the RFX-mod experiment is one of the flagships of the laboratory, being the most advanced currently operating on fusion experiments.\footnote{\url{https://www.igi.cnr.it/en/research/magnetic-confinement-research-in-padova/rfx-mod2/unveiling-the-evolution-upgrades-from-rfx-mod-to-rfx-mod2/}}.

The modifications, designed to enhance the efficiency and reliability of the machine, will not only improve its performance but also provide researchers with a further increased amount of diagnostics. These elements together will finally offer a detailed view of plasma phenomena at an unprecedented level of granularity. However, this improvement introduces another challenge on managing this even larger volume of data, underscoring the necessity for a robust data acquisition system and effective methods to monitor experiment sessions within this complex experimental framework.



Figure~\ref{fig:unified-platform} briefly illustrates the general life cycle of an experimental session, from initial setup to data elaboration and summary. The workflow begins with Experiment Setup, proceeds through Parameter Configuration, and continues with the execution of the experiment. This is followed by Data Collection and Data Elaboration stages. Control Systems interface directly with the experimental setup to manage and monitor various aspects of the experiment. 

For each of such stages a proper software tool is devoted to document and gather data. The Logbook component captures semantic information related to the experiment, including detailed descriptions, diagrams, version-controlled software repositories, and both pre-experiment and post-experiment observations. Experimental data from each session is stored in a hierarchical structure using MDSplus\footnote{\url{https://www.mdsplus.org/index.php/Introduction}}, where each session is uniquely identified by a Shot Number (or Pulse Identifier). After data collection and elaboration, critical results are distilled and summarized in the Summary section, which highlights key findings and insights.

The logbook plays a critical role in enriching raw data by providing essential context of what we was aiming to achieve and how it was configured, while collecting only sensor data offers a limited view, often confined to a single pulse. As a result, integrating that data with logbook information enables a broader experimental perspective, allowing researchers to identify meaningful correlations across entire experimental campaigns.

\begin{figure}[ht]
    \centering
    \includegraphics[width=1.0\linewidth]{figures/unified-platform.png}
    \caption{Unified Platform}
    \label{fig:unified-platform}
\end{figure}

In present-day scientific workflows, managing the vast amount of information generated during experiments remains a significant challenge. The complexity of keeping track of all documentation -- spanning from configuration parameters to contextual and observational data -- makes it extremely difficult to relate information that originates from different experimental campaigns or from evolving stages within a single experiment. As a result, scientists frequently create localized databases tailored to specific configurations or setups. These databases typically serve immediate analytical needs but are developed independently, often retained privately by individual researchers or small teams.

Such localized solutions introduce several limitations. They are rarely shared among researchers, making collaboration difficult and limiting reproducibility. These databases are often developed in a way that makes them difficult to port to other analysis systems, thereby impeding integration with advanced analytical environments. Moreover, they tend to fall out of sync with the experimental data pipeline, particularly when updates, calibrations, or corrections are made to the raw data over time. As a result, important insights can become disconnected from the context in which the data was originally produced, reducing their relevance and reliability for future analysis.

At the same time, the scientific community is increasingly leveraging machine learning and data-driven methodologies to uncover complex and correlations across diverse datasets. These correlations can emerge not only within a single experimental campaign but also across multiple setups with different goals or even between entirely different experiments. However, the effectiveness of such techniques critically depends on the availability of comprehensive, well-integrated metadata and semantic context. Without it, the capacity of these methods to produce meaningful results is constrained.

% Why we are adding this and what scientists do now

% 1- very often the complexity of keepeng track of all components documentation among phases make impossible to relate data that are distant from experimental campaigns or during an experiment evolution, so what happens is that scientists use to build local databases whith data coming from a single specific configfuration an keep those data for their own.

% 2- . those databases are not shared
%    . use to be difficoult to port to other analysis systems
%    . the do not keep in synch wiht the experiment and with possible fixes on the experiemntal raw data

% 3- we are facing times where machine learning could catch distant correlation among experiment features that can come from different
%    . campaign
%    . setup ( different run purposes )
%    . even different exepriments
% but we need to ad as much information as we can

% We propose to make a unified tool to access the overall data of all the components that spans the stages. 

This thesis presents the implementation of a unified platform to streamline experimental data access and documentation. The primary objective is to facilitate advanced data analytics by integrating a web-based application for managing semantic information from the experiment logbook with a query engine for efficient scientific data access. By providing a more accessible and integrated framework for data analysis, this unified system aims to improve the efficiency and reliability of the overall research workflow.
