Skip to content

Commit

Permalink
fix bug in do_get_array_slice related to snapping
Browse files Browse the repository at this point in the history
  • Loading branch information
oskooi committed Dec 30, 2020
1 parent e6f7123 commit 33dfce9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion doc/docs/Python_User_Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -3334,7 +3334,7 @@ See also [Field Functions](Field_Functions.md), and [Synchronizing the Magnetic

#### Array Slices

The output functions described above write the data for the fields and materials for the entire cell to an HDF5 file. This is useful for post-processing as you can later read in the HDF5 file to obtain field/material data as a NumPy array. However, in some cases it is convenient to bypass the disk altogether to obtain the data *directly* in the form of a NumPy array without writing/reading HDF5 files. Additionally, you may want the field/material data on just a subregion (or slice) of the entire volume. This functionality is provided by the `get_array` method which takes as input a subregion of the cell and the field/material component. The method returns a NumPy array containing values of the field/material at the current simulation time.
The output functions described above write the data for the fields and materials for the entire cell to an HDF5 file. This is useful for post-processing large datasets which may not fit into memory as you can later read in the HDF5 file to obtain field/material data as a NumPy array. However, in some cases it is convenient to bypass the disk altogether to obtain the data *directly* in the form of a NumPy array without writing/reading HDF5 files. Additionally, you may want the field/material data on just a subregion (or slice) of the entire volume. This functionality is provided by the `get_array` method which takes as input a subregion of the cell and the field/material component. The method returns a NumPy array containing values of the field/material at the current simulation time.


<a id="Simulation.get_array"></a>
Expand Down
2 changes: 1 addition & 1 deletion doc/docs/Python_User_Interface.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ See also [Field Functions](Field_Functions.md), and [Synchronizing the Magnetic

#### Array Slices

The output functions described above write the data for the fields and materials for the entire cell to an HDF5 file. This is useful for post-processing as you can later read in the HDF5 file to obtain field/material data as a NumPy array. However, in some cases it is convenient to bypass the disk altogether to obtain the data *directly* in the form of a NumPy array without writing/reading HDF5 files. Additionally, you may want the field/material data on just a subregion (or slice) of the entire volume. This functionality is provided by the `get_array` method which takes as input a subregion of the cell and the field/material component. The method returns a NumPy array containing values of the field/material at the current simulation time.
The output functions described above write the data for the fields and materials for the entire cell to an HDF5 file. This is useful for post-processing large datasets which may not fit into memory as you can later read in the HDF5 file to obtain field/material data as a NumPy array. However, in some cases it is convenient to bypass the disk altogether to obtain the data *directly* in the form of a NumPy array without writing/reading HDF5 files. Additionally, you may want the field/material data on just a subregion (or slice) of the entire volume. This functionality is provided by the `get_array` method which takes as input a subregion of the cell and the field/material component. The method returns a NumPy array containing values of the field/material at the current simulation time.

@@ Simulation.get_array @@
@@ Simulation.get_dft_array @@
Expand Down
32 changes: 19 additions & 13 deletions src/array_slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ void *fields::do_get_array_slice(const volume &where, std::vector<component> com
size_t dims[3];
direction dirs[3];
array_slice_data data;
int rank = get_array_slice_dimensions(where, dims, dirs, false, 0, &data);
int rank = get_array_slice_dimensions(where, dims, dirs, snap, 0, &data);
size_t slice_size = data.slice_size;
bool complex_data = (rfun == 0);
cdouble *zslice;
Expand Down Expand Up @@ -634,40 +634,46 @@ void *fields::do_get_array_slice(const volume &where, std::vector<component> com
++data.ninvmu;
}

loop_in_chunks(get_array_slice_chunkloop, (void *)&data, where, Centered, true, false);
loop_in_chunks(get_array_slice_chunkloop, (void *)&data, where, Centered, true, snap);

void *vslice_collapsed = (void *)collapse_array((double *)vslice_uncollapsed, &rank, dims, dirs, where, complex_data ? 2 : 1);
void *vslice_collapsed = 0;
if (!snap) {
vslice_collapsed = (void *)collapse_array((double *)vslice_uncollapsed, &rank, dims, dirs, where, complex_data ? 2 : 1);

rank = get_array_slice_dimensions(where, dims, dirs, true, 0, &data);
slice_size = data.slice_size;
rank = get_array_slice_dimensions(where, dims, dirs, true, 0, &data);
slice_size = data.slice_size;
}

cdouble *zslice_collapsed = 0;
double *slice_collapsed = 0;
cdouble *zslice_ref = 0;
double *slice_ref = 0;
if (vslice != 0) {
if (complex_data) {
zslice = (cdouble *)vslice;
zslice_collapsed = (cdouble *)vslice_collapsed;
zslice_ref = (cdouble *) (snap ? vslice_uncollapsed : vslice_collapsed);
for (size_t i = 0; i < slice_size; ++i)
zslice[i] = zslice_collapsed[i];
zslice[i] = zslice_ref[i];
zslice = array_to_all(zslice, slice_size);
} else {
slice = (double *)vslice;
slice_collapsed = (double *)vslice_collapsed;
slice_ref = (double *) (snap ? vslice_uncollapsed : vslice_collapsed);
for (size_t i = 0; i < slice_size; ++i)
slice[i] = slice_collapsed[i];
slice[i] = slice_ref[i];
slice = array_to_all(slice, slice_size);
}
}

vslice_collapsed = (void *)array_to_all((double *)vslice_collapsed, (complex_data ? 2 : 1) * slice_size);
if (snap)
vslice_uncollapsed = (void *)array_to_all((double *)vslice_uncollapsed, (complex_data ? 2 : 1) * slice_size);
else
vslice_collapsed = (void *)array_to_all((double *)vslice_collapsed, (complex_data ? 2 : 1) * slice_size);

delete[] data.offsets;
delete[] data.fields;
delete[] data.ph;
delete[] data.cS;
finished_working();

return vslice_collapsed;
return snap ? vslice_uncollapsed : vslice_collapsed;
}

/***************************************************************/
Expand Down

0 comments on commit 33dfce9

Please sign in to comment.