ParticleSampler_EN - CCSEPBVR/CS-IS-PBVR GitHub Wiki
By inserting generate_partices functions into the simulation code, the particle sampler can generate particles for visualization in-situ.
This function is defined in kvs_wrapper.h and can be used by referencing and linking to the particle generation library.
The particle sampler coupled to the simulation is executed along with the batch processing of the simulation, and the volume data of the calculation result is converted into particle data for visualization while referring to environment variables and transfer function files.
The particle sampler outputs a particle data file and a t_pfi_coords_minmax.txt file describing the minimum and maximum values of the region in the directory specified by PARTICLE_DIR.
The particle data file consists of a header file (KVSML), a coordinate file (coord.dat), a color file (color.dat), and a normal file (normal.dat), and one set is output for each node at each time step.
At the same time, the particle sampler outputs a $TF_NAME_ timestep.tf file with a history of changes to the transfer function in the VIS_PARAM_DIR, a histogram, a history_ timestep .txt file with the range of physical values to be visualized, and a state.txt with the processing timestep interval.
#include “kvs_wrapper.h”
void generate_particles( int time_step, domain_parameters dom, Typs** volume_data, int num_volume_data );
This function takes the time step of the simulation, the locking of the calculation area, and the volume data of the simulation result.
-
int time_step : Simulation timestep
-
domain_parameters dom : A structure that defines the following calculation area.
typedef struct { float x_global_min; // Minimum x-coordinate of the entire computational domain float y_global_min; // Minimum y-coordinate of the entire computational domain float z_global_min; // Minimum z-coordinate of the entire computational domain float x_global_max; // Maximum x-coordinate of the entire computational domain float y_global_max; // Maximum y-coordinate of the entire computational domain float z_global_max; // Maximum z-coordinate of the entire computational domain float x_min; // Minimum x-coordinate of the subdomain float y_min; // Minimum y-coordinate of the subdomain float z_min; // Minimum z-coordinate of the subdomain int* resolution; // Pointer to grid resolution (int resolution[3]) float cell_length; // Unit length of the grid } domain_parameters;
Types volume_data: Pointer to an array of volume data for simulation results. Type is the type of a user-specified physical value, and multivariable volume data is defined as a two-dimensional array. In the volume data of the lattice resolution (X, Y, Z), the value of the position (i, j, k) of the nth variable is referred to by volume_data [n][i + j * X + k* X * Y].
- int num_volume_data : Number of variables
#include “kvs_wrapper.h”
void generate_particles(
int time_step, domain_parameters dom, Type** values, int nvariables, float* coordinates,
int ncoords, unsigned int* connections, int ncells,
const pbvr::VolumeObjectBase::CellType&celltype);
This function takes the time step of the simulation, the locking method of the computational domain, the volume data of the simulation results, and the lattice locking method of the unstructured lattice.
-
int time_step : Simulation timestep
-
domain_parameters dom : A structure that defines the following calculation area.
typedef struct { float x_global_min; // Minimum x-coordinate of the entire computational domain float y_global_min; // Minimum y-coordinate of the entire computational domain float z_global_min; // Minimum z-coordinate of the entire computational domain float x_global_max; // Maximum x-coordinate of the entire computational domain float y_global_max; // Maximum y-coordinate of the entire computational domain float z_global_max; // Maximum z-coordinate of the entire computational domain } domain_parameters;
Typs volume_data: Pointer to an array of volume data for simulation results. Type is the type of a user-specified physical value, and multivariable volume data is defined as a two-dimensional array. The value on the cell-th vertex of the nth variable is referenced by volume_data[n][cell].
- float* coordinates: Pointer to an array of vertex coordinates. The coordinates of the i-th vertex (x, y, z) are accessed as (coordinates[3i], coordinates[3i+1], coordinates[3*i+2]).
- int ncoords:Number of vertices.
- unsigned int* connections: A pointer to a connection list of vertex IDs that make up the hexahedral element. The configuration of the hexahedral elements is shown in the figure below. The nth vertex of the i-th hexahedral element is referenced by connections[8*i+n].
- int ncells:Number of elements.
- pbvr::VolumeObjectBase::CellType & celltype: Element type. IS-PBVR can be used with tetrahedron, hexahedron, pyramid, prism, tetrahedral secondary element, and hexahedral secondary element. Each element type is defined in the VolumeObjectBase class in the following file: /DaemonAndSampler/InSituLib/unstruct/TFS/VolumeObjectBase.h
In-Situ PBVR supports Block Structured AMR, which is optimized for the memory layout of many-core computers. This type of lattice defines the N3 orthogonal lattice as the smallest processing area unit (leaf), with leaves of different sizes connected at each level. Therefore, a Block Structured AMR is defined as a four-dimensional lattice of NxNxNxL, where L is the number of leaves. A two-dimensional example is shown below.
#include “kvs_wrapper.h”
void generate_particles(
int time_step, domain_* parameters dom,
std::vector<float>& leaf_length,
std::vector<float>& leaf_min_coord,
int nvariables, float** values);
This function takes information about the time step and calculation area of the simulation, the configuration information of the hierarchical grid, and the volume data of the simulation result as arguments.
-
int time_step : Simulation time step.
-
domain_patameters dom: A structure that defines the following computation areas:
typedef struct { float x_global_min; // Minimum x-coordinate of the entire computational domain float y_global_min; // Minimum y-coordinate of the entire computational domain float z_global_min; // Minimum z-coordinate of the entire computational domain float x_global_max; // Maximum x-coordinate of the entire computational domain float y_global_max; // Maximum y-coordinate of the entire computational domain float z_global_max; // Maximum z-coordinate of the entire computational domain int* resolution; // Pointer to grid resolution int resolution[4] } domain_parameters;
-
std::vector& leaf_length: A reference to an array of leaf lengths. The length of the lth leaf is referred to by leaf_length [l].
-
std::vector& leaf_min_coord: A reference to an array of the minimum position coordinates of the leaf. Seat of the lth leaf
-
Marks are referred to as (leaf_min_coord[3L], leaf_min_coord[3L+1], leaf_min_coord[3L+2]). float values: Pointer to an array of volume data for simulation results. Multivariable volume data is defined as a two-dimensional array. In the volume data of the lattice resolution (X,Y,Z,L), the value of the position (i,j,k,l) of the nth variable is referred to by values[n][i+jX+kXY+lXY*Z].
-
int nvariables:Number of variables.
By incorporating and compiling generate_particles functions into the user's simulation code, in-situ visualization is possible. This chapter describes the procedure for embedding a particle sampler using test simulation code as an example. The test simulation code calculates the charge density value on the lattice vertex at each time step by the charge density equation for hydrogen. Therefore, the name of the class to be calculated is Hydrogen. The code without the particle sampler is as follows.
#include "Hydrogen.h"
#include <iostream>
#include <mpi.h>
int main( int argc, char** argv )
{
MPI_Init(&argc, &argv);
Hydrogen hydro;
int time_step = 0;
for(;;)
{
hydro.values;
time_step++;
}
MPI_Finalize();
return 0 ;
}
In the above source code, the Hydrogen class outputs the volume data of each time step with hydro.values in the for statement.
The generate_particles function retrieves the region information by means of the structure domain_parameters. The user needs to copy the region information obtained from the simulation code into the structure.
int mpi_rank;
MPI_Comm_rank( MPI_COMM_WORLD, &(mpi_rank) );
int resol[3] = { hydro.resolution.x(), hydro.resolution.y(), hydro.resolution.z() };
domain_parameters house = {
hydro.global_min_coord.x(),
hydro.global_min_coord.y(),
hydro.global_min_coord.z(),
hydro.global_max_coord.x(),
hydro.global_max_coord.y(),
hydro.global_max_coord.z(),
hydro.global_region[mpi_rank].x(),
hydro.global_region[mpi_rank].y(),
0.0,
Solves
hydro.cell_length
};
In the above code, the number of MPI ranks is obtained to obtain information about the subregion of the Hydrogen. Input the region information and the volume data of the simulation results into the generate_particles function. generate_particles The function is called after simulation inside a time-step loop. In the case of the Hydrogen example, it is inserted as follows:
int time_step = 0;
for(;;) {
generate_particles( time_step, dom, hydro.values, hydro.nvariables )
time_step++;
}