Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor bug fixes #61

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/divfreemotion/divfree2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

# 4. plot results
savename = savefigpath + "df2d_maxnsupers_validation.png"
pltmoms.plot_maxnsupers(time, maxnsupers, savename=savename)
pltmoms.plot_totnsupers(time, maxnsupers, savename=savename)

nsample = 500
savename = savefigpath + "df2d_motion2d_validation.png"
Expand Down
2 changes: 1 addition & 1 deletion examples/yac/fromfile/yac1_fromfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

# plot super-droplet results
savename = savefigpath + "yac1_maxnsupers_validation.png"
pltmoms.plot_maxnsupers(time, maxnsupers, savename=savename)
pltmoms.plot_totnsupers(time, maxnsupers, savename=savename)

nsample = 1000
savename = savefigpath + "yac1_motion2d_validation.png"
Expand Down
43 changes: 16 additions & 27 deletions libs/cartesiandomain/cartesianmaps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Author: Clara Bayley (CB)
* Additional Contributors:
* -----
* Last Modified: Wednesday 1st May 2024
* Last Modified: Friday 3rd May 2024
* Modified By: CB
* -----
* License: BSD 3-Clause "New" or "Revised" License
Expand Down Expand Up @@ -59,9 +59,9 @@ struct CartesianMaps {
kokkos_uintmap to_forward_coord2nghbr;

/* additional gridbox / domain information */
kokkos_dblmap to_area; // map from gbxindex to horizontal (x-y planar) area of gridbox
kokkos_dblmap to_volume; // map from gbxindex to volume of gridbox
viewd_ndims ndims; // dimensions (ie. no. gridboxes) in [coord3, coord1, coord2] directions
kokkos_dblmaph to_area; // map from gbxindex to horizontal (x-y planar) area of gridbox on host
kokkos_dblmaph to_volume; // map from gbxindex to volume of gridbox on host
viewd_ndims ndims; // dimensions (ie. no. gridboxes) in [coord3, coord1, coord2] directions

public:
/* initialise maps with hint for their capacity
Expand All @@ -78,8 +78,8 @@ struct CartesianMaps {
to_forward_coord1nghbr(kokkos_uintmap(ngbxs)),
to_back_coord2nghbr(kokkos_uintmap(ngbxs)),
to_forward_coord2nghbr(kokkos_uintmap(ngbxs)),
to_area(kokkos_dblmap(ngbxs)),
to_volume(kokkos_dblmap(ngbxs)),
to_area(kokkos_dblmaph(ngbxs)),
to_volume(kokkos_dblmaph(ngbxs)),
ndims("ndims") {}

/* insert 1 value into to_coord3bounds
Expand Down Expand Up @@ -158,19 +158,10 @@ struct CartesianMaps {
}

/* insert 1 value into to_area map at key = idx with value=area */
void insert_gbxarea(const unsigned int idx, double area) {
/* parallel for for 1 value so that execution of insert occurs on device if necessary */
Kokkos::parallel_for(
"gbxarea", 1, KOKKOS_CLASS_LAMBDA(const unsigned int i) { to_area.insert(idx, area); });
}
void insert_gbxarea(const unsigned int idx, double area) { to_area.insert(idx, area); }

/* insert 1 value into to_volume map at key = idx with value=volume */
void insert_gbxvolume(const unsigned int idx, double volume) {
/* parallel for for 1 value so that execution of insert occurs on device if necessary */
Kokkos::parallel_for(
"gbxvolume", 1,
KOKKOS_CLASS_LAMBDA(const unsigned int i) { to_volume.insert(idx, volume); });
}
void insert_gbxvolume(const unsigned int idx, double volume) { to_volume.insert(idx, volume); }

/* copies of h_ndims to ndims,
possibly into device memory */
Expand All @@ -193,6 +184,13 @@ struct CartesianMaps {
return h_ndims;
}

/* returns volume of gridbox with index 'gbxidx' on host */
double get_gbxvolume(const unsigned int gbxidx) const {
const auto i(to_volume.find(gbxidx)); // index in map of key 'gbxindex'

return to_volume.value_at(i); // value returned by map at index i
}

/* returns model dimensions ie. number of gridboxes
along [coord3, coord1, coord2] directions */
KOKKOS_INLINE_FUNCTION
Expand All @@ -206,22 +204,13 @@ struct CartesianMaps {
KOKKOS_INLINE_FUNCTION
size_t get_ndim(const unsigned int d) const { return ndims(d); }

/* returns horizontal (x-y planar) area of gridbox with index 'gbxidx' on device */
KOKKOS_INLINE_FUNCTION
/* returns horizontal (x-y planar) area of gridbox with index 'gbxidx' on host */
double get_gbxarea(const unsigned int gbxidx) const {
const auto i(to_area.find(gbxidx)); // index in map of key 'gbxindex'

return to_area.value_at(i); // value returned by map at index i
}

/* returns volume of gridbox with index 'gbxidx' on device */
KOKKOS_INLINE_FUNCTION
double get_gbxvolume(const unsigned int gbxidx) const {
const auto i(to_volume.find(gbxidx)); // index in map of key 'gbxindex'

return to_volume.value_at(i); // value returned by map at index i
}

/* returns {lower bound, upper bound} in coord3
(z) direction of gridbox with index 'gbxidx'
on device */
Expand Down
6 changes: 3 additions & 3 deletions libs/kokkosaliases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Author: Clara Bayley (CB)
* Additional Contributors:
* -----
* Last Modified: Wednesday 1st May 2024
* Last Modified: Friday 3rd May 2024
* Modified By: CB
* -----
* License: BSD 3-Clause "New" or "Revised" License
Expand Down Expand Up @@ -48,8 +48,8 @@ using kokkos_pairmap = Kokkos::UnorderedMap<unsigned int, Kokkos::pair<double, d
/**< E.g. for map from unsigned int gbxindex to gridbox boundaries */
using kokkos_uintmap = Kokkos::UnorderedMap<unsigned int, unsigned int, ExecSpace>;
/**< E.g. for map from one unsigned int gbxindex to another */
using kokkos_dblmap = Kokkos::UnorderedMap<unsigned int, double, ExecSpace>;
/**< E.g. for map from unsigned int gbxindex to gridbox area/volume */
using kokkos_dblmaph = Kokkos::UnorderedMap<unsigned int, double, HostSpace>;
/**< E.g. for map from unsigned int gbxindex to gridbox area/volume on host*/
using viewd_ndims =
Kokkos::View<size_t[3]>; /**< View in device memory for number of gridboxes in CartesianMaps. */

Expand Down
Loading