Skip to content

Commit

Permalink
Merge pull request #46 from cindytsai/Rename
Browse files Browse the repository at this point in the history
Rename yt_data.data_dim to data_dimensions.
  • Loading branch information
cindytsai authored Jan 22, 2022
2 parents 403b354 + 19b245a commit b946bbb
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 277 deletions.
12 changes: 6 additions & 6 deletions doc/DerivedField.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
## Definition of Derived Field
When you want your simulation code to generate or convert existing data to `yt`-needed type, you should set to this option. These field data will be generated by your input function `derived_func`, whenever `yt` needs them.

These functions will only be called when `yt` is doing analysis, which is when `yt_inline` or `yt_inline_argument` API is called.
These functions will only be called when `yt` is doing analysis, which is when `yt_inline` or `yt_inline_argument` API is called.

## Use `libyt` API to Build Derived Field Function
### Derived Field Function
`derived_func` should be able to write the correspond output into the array passed in, just by knowing the grid id. It should not generate ghost cell data. Make sure your function writes the data in x-address alters first orientation (which is [z][y][x]), if `swap_axes` is set to `true`. Write the data in z-address alters first orientation (which is [x][y][z]), if `swap_axes` is set to `false`.
`derived_func` should be able to write the correspond output into the array passed in, just by knowing the grid id. It should not generate ghost cell data. Make sure your function writes the data in x-address alters first orientation (which is [z][y][x]), if `swap_axes` is set to `true`. Write the data in z-address alters first orientation (which is [x][y][z]), if `swap_axes` is set to `false`.

`derived_func` must have a prototype like this:
`derived_func` must have a prototype like this:
```cpp
void DerivedFunc(long gid, double *output);
```
Expand All @@ -26,13 +26,13 @@ int yt_getGridInfo_Dimensions( const long gid, int (*dimensions)[3] );
```cpp
int yt_getGridInfo_FieldData( const long gid, const char *field_name, yt_data *field_data);
```
- Get the field data `field_name` in grid `gid`. The result will be in `field_data`.
- Get the field data `field_name` in grid id `gid`. The result will be stored in `field_data`.
- yt_data
- `data_ptr`: Data pointer.
- `data_dim[3]`: Dimension of the `data_ptr` array, in the point of view in itself.
- `data_dimensions[3]`: Dimension of the `data_ptr` array, in the point of view of itself.
- `data_dtype`: Data type of the array.
> :information_source: Do not mix grid dimensions get by `yt_getGridInfo_Dimensions` with data dimensions get by `yt_getGridInfo_FieldData`. Grid dimensions are grid length in [0][1][2] <-> [x][y][z]. Whereas data dimensions are just data length in their point of view, which may consist of ghost cells.
> :information_source: Do not mix grid dimensions get by `yt_getGridInfo_Dimensions` with data dimensions get by `yt_getGridInfo_FieldData`. Grid dimensions are grid length in [0][1][2] <-> [x][y][z]. Whereas data dimensions are just data length in data's point of view, which may consist of ghost cells.
> :warning: You should not be modifying `data_ptr`, as they are those data pointers you passed in and will be used in your later on iterations.
Expand Down
54 changes: 27 additions & 27 deletions doc/SetLocalGridsInformation.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ One `yt_grid` contains the hierarchy of the grid, particle counts, and field dat
- Usage: Grid global id.
- Valid Value: It is 0-index based and should be in between `0` and `num_grids - 1`.
- `parent_id`
- Usage: Parent grid id.
- Usage: Parent grid id.
- Valide Value:
- Should be in between `0` and `num_grids - 1`.
- If the grid does not have parent grid, set to `-1`.
Expand All @@ -36,43 +36,43 @@ One `yt_grid` contains the hierarchy of the grid, particle counts, and field dat
- Usage: Store all the field data under this grid. This is a `yt_data` array, and `libyt` will initialize this for you.
- Valid Value: Each element in `field_data` is a `yt_data` struct.
- `data_ptr`: Data pointer to the field data of the grid.
- `data_dim[3]`: Dimension of `data_ptr`.
- `data_dimensions[3]`: Dimension of `data_ptr`.
- `data_dtype`: Data type of `data_ptr`.
> :information_source: If it is a cell-centered field, `libyt` will fill in `data_dim` according to `grid_dimensions` in [`yt_grid`](#yt_grid) and `field_ghost_cell` in [`yt_field`](./SetFieldsInformation.md#yt_field).
> Otherwise, you should always fill in `data_dim`, if you wish to wrap an existing data in memory.
> :information_source: If it is a cell-centered field, `libyt` will fill in `data_dimensions` according to `grid_dimensions` in [`yt_grid`](#yt_grid) and `field_ghost_cell` in [`yt_field`](./SetFieldsInformation.md#yt_field).
> Otherwise, you should always fill in `data_dimensions`, if you wish to wrap an existing data in memory.
> :information_source: You only need to set `data_dtype` when this grid's data type is different from the one set in fields'.
## Example
```cpp
/* libyt API */
yt_grid *grids_local;
yt_grid *grids_local;
yt_get_gridsPtr( &grids_local );
int index_local = 0;
for (int gid = 0; gid < param_yt.num_grids; gid = gid + 1){
if (grids_MPI[gid] == myrank) {
/* Fill in hierarchy. */
for (int d = 0; d < 3; d = d+1) {
grids_local[index_local].left_edge[d] = sim_grids[gid].left_edge[d];
grids_local[index_local].right_edge[d] = sim_grids[gid].right_edge[d];
grids_local[index_local].grid_dimensions[d] = sim_grids[gid].grid_dimensions[d];
}
grids_local[index_local].id = sim_grids[gid].id;
grids_local[index_local].parent_id = sim_grids[gid].parent_id;
grids_local[index_local].level = sim_grids[gid].level;
/* Fill in particle count. */
grids_local[index_local].particle_count_list[0] = 1;
int index_local = 0;
for (int gid = 0; gid < param_yt.num_grids; gid = gid + 1){
if (grids_MPI[gid] == myrank) {
/* Fill in hierarchy. */
for (int d = 0; d < 3; d = d+1) {
grids_local[index_local].left_edge[d] = sim_grids[gid].left_edge[d];
grids_local[index_local].right_edge[d] = sim_grids[gid].right_edge[d];
grids_local[index_local].grid_dimensions[d] = sim_grids[gid].grid_dimensions[d];
}
grids_local[index_local].id = sim_grids[gid].id;
grids_local[index_local].parent_id = sim_grids[gid].parent_id;
grids_local[index_local].level = sim_grids[gid].level;
/* Fill in particle count. */
grids_local[index_local].particle_count_list[0] = 1;
/* Fill in field data. */
for (int v = 0; v < param_yt.num_fields; v = v + 1){
grids_local[index_local].field_data[v].data_ptr = sim_grids[gid].field_data[v].data_ptr;
}
index_local = index_local + 1;
}
/* Fill in field data. */
for (int v = 0; v < param_yt.num_fields; v = v + 1){
grids_local[index_local].field_data[v].data_ptr = sim_grids[gid].field_data[v].data_ptr;
}
index_local = index_local + 1;
}
}
```
206 changes: 103 additions & 103 deletions include/yt_type_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
//
// Notes : 1. This struct will be use in yt_grid data member field_data.
//
// Data Member : data_ptr : field data pointer
// data_dim[3] : dimension of the field data to be passed to python, which is the actual
// size of the array.
// Def => fieldData[ dim[0] ][ dim[1] ][ dim[2] ]
// data_dtype : Data type of the field in specific grid. If this is set as YT_DTYPE_UNKNOWN,
// then we will use field_dtype define in field_list as input field data type.
// Data Member : data_ptr : field data pointer
// data_dimensions[3] : dimension of the field data to be passed to python, which is the actual
// size of the array.
// Def => fieldData[ dim[0] ][ dim[1] ][ dim[2] ]
// data_dtype : Data type of the field in specific grid. If this is set as YT_DTYPE_UNKNOWN,
// then we will use field_dtype define in field_list as input field data type.
//
// Methods : yt_data : Constructor
// ~yt_data : Destructor, does nothing for now.
//-------------------------------------------------------------------------------------------------------
struct yt_data
{
void *data_ptr;
int data_dim[3];
yt_dtype data_dtype;
void *data_ptr;
int data_dimensions[3];
yt_dtype data_dtype;

//===================================================================================
// Method : yt_data
Expand All @@ -44,7 +44,7 @@ struct yt_data
yt_data()
{
data_ptr = NULL;
for(int d=0; d<3; d++){ data_dim[d] = 0; }
for(int d=0; d<3; d++){ data_dimensions[d] = 0; }
data_dtype = YT_DTYPE_UNKNOWN;
}
~yt_data()
Expand Down Expand Up @@ -84,105 +84,105 @@ struct yt_grid

// data members
// ===================================================================================
double left_edge[3];
double right_edge[3];

long *particle_count_list;
long grid_particle_count;
long id;
long parent_id;

int grid_dimensions[3];
int level;
int proc_num;

yt_data *field_data;

//===================================================================================
// Method : yt_grid
// Description : Constructor of the structure "yt_grid"
//
// Note : Initialize all data members
//
// Parameter : None
//===================================================================================
yt_grid()
{
double left_edge[3];
double right_edge[3];

long *particle_count_list;
long grid_particle_count;
long id;
long parent_id;

int grid_dimensions[3];
int level;
int proc_num;

yt_data *field_data;

//===================================================================================
// Method : yt_grid
// Description : Constructor of the structure "yt_grid"
//
// Note : Initialize all data members
//
// Parameter : None
//===================================================================================
yt_grid()
{

// set defaults
for (int d=0; d<3; d++) {
left_edge [d] = DBL_UNDEFINED;
right_edge[d] = DBL_UNDEFINED; }

for (int d=0; d<3; d++) {
grid_dimensions[d] = INT_UNDEFINED; }

grid_particle_count = 0;
particle_count_list = NULL;
id = LNG_UNDEFINED;
parent_id = LNG_UNDEFINED;
level = INT_UNDEFINED;

proc_num = INT_UNDEFINED;

field_data = NULL;

} // METHOD : yt_grid


//===================================================================================
// Method : ~yt_grid
// Description : Destructor of the structure "yt_grid"
//
// Note : 1. Not used currently
// 2. We do not free the pointer arrays "field_list" and "field_data" here
// ==> They are freed by yt_free_gridsPtr
//
// Parameter : None
//===================================================================================
~yt_grid()
{

} // METHOD : ~yt_grid


//===================================================================================
// Method : validate
// Description : Check if all data members have been set properly by users
//
// Note : 1. This function does not perform checks that depend on the input
// YT parameters (e.g., whether left_edge lies within the simulation domain)
// ==> These checks are performed in check_grid()
// 2. If check needs information other than grid info, we will do it elsewhere.
//
// Parameter : None
//
// Return : YT_SUCCESS or YT_FAIL
//===================================================================================
int validate() const
{

for (int d=0; d<3; d++) {
if ( left_edge [d] == DBL_UNDEFINED ) YT_ABORT( "\"%s[%d]\" has not been set for grid id [%ld]!\n", "left_edge", d, id );
if ( right_edge[d] == DBL_UNDEFINED ) YT_ABORT( "\"%s[%d]\" has not been set for grid id [%ld]!\n", "right_edge", d, id ); }

for (int d=0; d<3; d++) {
if ( grid_dimensions[d] == INT_UNDEFINED ) YT_ABORT( "\"%s[%d]\" has not been set for grid id [%ld]!\n", "grid_dimensions", d, id ); }
if ( id == LNG_UNDEFINED ) YT_ABORT( "\"%s\" has not been set for grid id [%ld]!\n", "id", id );
if ( parent_id == LNG_UNDEFINED ) YT_ABORT( "\"%s\" has not been set for grid id [%ld]!\n", "parent_id", id );
if ( level == INT_UNDEFINED ) YT_ABORT( "\"%s\" has not been set for grid id [%ld]!\n", "level", id );
if ( proc_num == INT_UNDEFINED ) YT_ABORT( "\"%s\" has not been set for grid id [%ld]!\n", "proc_num", id );
if ( field_data == NULL ) YT_ABORT( "\"%s\" has not been set for grid id [%ld]!\n", "field_data", id );
for (int d=0; d<3; d++) {
left_edge [d] = DBL_UNDEFINED;
right_edge[d] = DBL_UNDEFINED; }

for (int d=0; d<3; d++) {
grid_dimensions[d] = INT_UNDEFINED; }

grid_particle_count = 0;
particle_count_list = NULL;
id = LNG_UNDEFINED;
parent_id = LNG_UNDEFINED;
level = INT_UNDEFINED;

proc_num = INT_UNDEFINED;

field_data = NULL;

} // METHOD : yt_grid


//===================================================================================
// Method : ~yt_grid
// Description : Destructor of the structure "yt_grid"
//
// Note : 1. Not used currently
// 2. We do not free the pointer arrays "field_list" and "field_data" here
// ==> They are freed by yt_free_gridsPtr
//
// Parameter : None
//===================================================================================
~yt_grid()
{

} // METHOD : ~yt_grid


//===================================================================================
// Method : validate
// Description : Check if all data members have been set properly by users
//
// Note : 1. This function does not perform checks that depend on the input
// YT parameters (e.g., whether left_edge lies within the simulation domain)
// ==> These checks are performed in check_grid()
// 2. If check needs information other than grid info, we will do it elsewhere.
//
// Parameter : None
//
// Return : YT_SUCCESS or YT_FAIL
//===================================================================================
int validate() const
{

for (int d=0; d<3; d++) {
if ( left_edge [d] == DBL_UNDEFINED ) YT_ABORT( "\"%s[%d]\" has not been set for grid id [%ld]!\n", "left_edge", d, id );
if ( right_edge[d] == DBL_UNDEFINED ) YT_ABORT( "\"%s[%d]\" has not been set for grid id [%ld]!\n", "right_edge", d, id ); }

for (int d=0; d<3; d++) {
if ( grid_dimensions[d] == INT_UNDEFINED ) YT_ABORT( "\"%s[%d]\" has not been set for grid id [%ld]!\n", "grid_dimensions", d, id ); }
if ( id == LNG_UNDEFINED ) YT_ABORT( "\"%s\" has not been set for grid id [%ld]!\n", "id", id );
if ( parent_id == LNG_UNDEFINED ) YT_ABORT( "\"%s\" has not been set for grid id [%ld]!\n", "parent_id", id );
if ( level == INT_UNDEFINED ) YT_ABORT( "\"%s\" has not been set for grid id [%ld]!\n", "level", id );
if ( proc_num == INT_UNDEFINED ) YT_ABORT( "\"%s\" has not been set for grid id [%ld]!\n", "proc_num", id );
if ( field_data == NULL ) YT_ABORT( "\"%s\" has not been set for grid id [%ld]!\n", "field_data", id );

// additional checks
for (int d=0; d<3; d++) {
if ( grid_dimensions[d] <= 0 ) YT_ABORT( "\"%s[%d]\" == %d <= 0 for grid [%ld]!\n", "grid_dimensions", d, grid_dimensions[d], id ); }
if ( id < 0 ) YT_ABORT( "\"%s\" == %d < 0!\n", "id", id );
if ( level < 0 ) YT_ABORT( "\"%s\" == %d < 0 for grid [%ld]!\n", "level", level, id );
for (int d=0; d<3; d++) {
if ( grid_dimensions[d] <= 0 ) YT_ABORT( "\"%s[%d]\" == %d <= 0 for grid [%ld]!\n", "grid_dimensions", d, grid_dimensions[d], id ); }
if ( id < 0 ) YT_ABORT( "\"%s\" == %d < 0!\n", "id", id );
if ( level < 0 ) YT_ABORT( "\"%s\" == %d < 0 for grid [%ld]!\n", "level", level, id );

return YT_SUCCESS;
return YT_SUCCESS;

} // METHOD : validate
} // METHOD : validate

}; // struct yt_grid

Expand Down
Loading

0 comments on commit b946bbb

Please sign in to comment.