Example¶
The example libyt/example/amr-example
demonstrates how to implement libyt
in an adaptive mesh refinement (AMR) grid simulation.
The example has a set of pre-calculated data.
It assigns the data to MPI processes randomly to simulate data distributed on different processes. (Though in real world, data won’t distribute randomly.)
The steps related to implementation of libyt
is commented like this:
// ==========================================
// libyt: 0. include libyt header
// ==========================================
// ==========================================
// libyt: [Optional] ...
// ==========================================
The example initializes libyt
, loads data to libyt
in every simulation time step in the iterative process and uses yt
to do in situ Python analysis, and finalizes it before terminating the simulation.
Building and Running the Example¶
Using CMake¶
Follow Install.
Enter example folder. Assume we build the project under
libyt/build
:cd libyt # go to libyt project root folder cd build/example/amr-example # go to example folder
Using Make¶
Follow Install.
Go to
libyt/example/amr-example
folder.cd libyt/example/amr-example
Compile the code:
Serial Mode (using GCC):
make OPTIONS=-DSERIAL_MODE LIBYT_PATH=<libyt-install-prefix>
Parallel Mode (using MPI):
make MPI_PATH=<mpi-install-prefix> LIBYT_PATH=<libyt-install-prefix>
Make sure you are using the same MPI to compilelibyt
and the example.
Running the Example¶
Run the example:
Serial Mode (using GCC):
./example
Parallel Mode (using MPI):
OMPI_MCA_osc=sm,pt2pt mpirun -np 2 ./example
OMPI_MCA_osc=sm,pt2pt
is for using one-sided MPI communications.
The output results we get from the first step:
Density projection along z-axis,
FigName000000000_Projection_z_density.png
:Density profile with respect to x coordinate,
FigName000000000_1d-Profile_x_density.png
:Slice plot of the reciprocal of the density field,
FigName000000000_Slice_z_InvDens.png
:Particle plot of the level of a grid. Each grid has one particle with its position set at the center of the grid with value equals to grid level. The result is
FigName000000000_Particle_z_Level.png
. We can only see some tiny dots in the figure, since there is only one particle in each grid. (The plot tries to demonstrate the particle functionality.)
After loading simulation data using libyt API, we call Python functions defined in
inline_script.py
usingyt_run_Function
/yt_run_FunctionArguments
and useyt
to analyze the data and plot figures. For how to useyt
see:
What’s Next¶
Change Python Script Name¶
The example uses inline_script.py
for in situ Python analysis.
To change the Python script name, simpy change param_libyt.script
and do not include file extension .py
in example.cpp
.
// file: example/example.cpp
yt_param_libyt param_libyt;
param_libyt.verbose = YT_VERBOSE_INFO; // libyt log level
param_libyt.script = "inline_script"; // inline python script, excluding ".py"
param_libyt.check_data = false; // check passed in data or not
To know more about writing inline Python script, you can refer to Using Python for In Situ Analysis in libyt.
Other Python Entry Points for Interactive Data Analysis¶
To try interactive Python prompt:
Go to
amr-example
build folder.Create
LIBYT_STOP
. The file is signal forlibyt
to decide whether to launch the file-based Python prompt.Run the program. See more in Interactive Python Prompt.
To try file-based Python prompt:
Go to
amr-example
build folder.Create
LIBYT_RELOAD
. The file is signal forlibyt
to decide whether to launch the file-based Python prompt.Run the program. See more in Reload Script.
To try Jupyter Notebook / JupyterLab access:
Go to
amr-example
build folder.Create
LIBYT_JUPYTER
. The file is signal forlibyt
to decide whether to launch Jupyter kernel used for Jupyter Notebook / JupyterLab access.Run the program. See more in Jupyter Notebook Access.