Skip to content

Commit 39c2dff

Browse files
feat: new function to reset superdroplet radii in BCs
1 parent 369d771 commit 39c2dff

5 files changed

Lines changed: 50 additions & 10 deletions

File tree

cleo_1dkid/cleo_deps/libs/cartesiandomain/cartesianmaps.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
KOKKOS_FUNCTION
2727
unsigned int get_no_decomposition_bounding_gridbox(const CartesianMaps &gbxmaps,
2828
const unsigned int gbxindex, double &coord3,
29-
double &coord1, double &coord2);
29+
double &coord1, double &coord2, double &radius);
3030

3131
/* on host, throws error if maps are not all
3232
the same size, else returns size of maps */
@@ -70,7 +70,8 @@ size_t CartesianMaps::local_to_global_gridbox_index(unsigned int local_gridbox_i
7070
// TODO(ALL) make domain_decomp call compatible with GPUs and then remove comm_size guard
7171
KOKKOS_FUNCTION
7272
unsigned int CartesianMaps::get_local_bounding_gridbox(const unsigned int gbxindex, double &coord3,
73-
double &coord1, double &coord2) const {
73+
double &coord1, double &coord2,
74+
double &radius) const {
7475
if (is_decomp) {
7576
auto coordinates = std::array<double, 3>{coord3, coord1, coord2};
7677
const auto idx = domain_decomposition.get_local_bounding_gridbox(coordinates);
@@ -79,7 +80,7 @@ unsigned int CartesianMaps::get_local_bounding_gridbox(const unsigned int gbxind
7980
coord2 = coordinates[2];
8081
return idx;
8182
}
82-
return get_no_decomposition_bounding_gridbox(*this, gbxindex, coord3, coord1, coord2);
83+
return get_no_decomposition_bounding_gridbox(*this, gbxindex, coord3, coord1, coord2, radius);
8384
}
8485

8586
/* returns flag to keep idx the same (flag = 0) or
@@ -264,14 +265,17 @@ if flag = 2 idx updated to forwards neighbour gbxindex.
264265
_Note:_ backwards/forwards functions may change the
265266
superdroplet's coords e.g. if it leaves the domain. */
266267
KOKKOS_FUNCTION
267-
unsigned int change_if_coord3nghbr(const CartesianMaps &gbxmaps, unsigned int idx, double &coord3) {
268+
unsigned int change_if_coord3nghbr(const CartesianMaps &gbxmaps, unsigned int idx, double &coord3,
269+
double &radius) {
268270
const auto flag = flag_sdgbxindex(idx, gbxmaps.coord3bounds(idx), coord3); // !=0 idx shld change
269271
switch (flag) {
270272
case 1:
271273
idx = change_to_backwards_coord3nghbr(idx, gbxmaps, coord3);
274+
radius = kid_reinitialise_radius(radius);
272275
break;
273276
case 2:
274277
idx = change_to_forwards_coord3nghbr(idx, gbxmaps, coord3);
278+
radius = kid_reinitialise_radius(radius);
275279
break;
276280
}
277281
return idx;
@@ -280,8 +284,8 @@ unsigned int change_if_coord3nghbr(const CartesianMaps &gbxmaps, unsigned int id
280284
KOKKOS_FUNCTION
281285
unsigned int get_no_decomposition_bounding_gridbox(const CartesianMaps &gbxmaps,
282286
const unsigned int gbxindex, double &coord3,
283-
double &coord1, double &coord2) {
284-
auto idx = (unsigned int)change_if_coord3nghbr(gbxmaps, gbxindex, coord3);
287+
double &coord1, double &coord2, double &radius) {
288+
auto idx = (unsigned int)change_if_coord3nghbr(gbxmaps, gbxindex, coord3, radius);
285289
idx = change_if_coord1nghbr(gbxmaps, idx, coord1);
286290
idx = change_if_coord2nghbr(gbxmaps, idx, coord2);
287291
return idx;

cleo_1dkid/cleo_deps/libs/cartesiandomain/cartesianmaps.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "../kokkosaliases.hpp"
3636
#include "cartesiandomain/cartesian_decomposition.hpp"
3737
#include "cartesiandomain/doubly_periodic_domain.hpp"
38+
#include "cartesiandomain/kid_reinit.hpp"
3839

3940
namespace dlc = dimless_constants;
4041

@@ -302,7 +303,7 @@ struct CartesianMaps {
302303
*/
303304
KOKKOS_FUNCTION
304305
unsigned int get_local_bounding_gridbox(const unsigned int gbxindex, double& coord3,
305-
double& coord1, double& coord2) const;
306+
double& coord1, double& coord2, double& radius) const;
306307
};
307308

308309
#endif // CLEO_1DKID_CLEO_DEPS_LIBS_CARTESIANDOMAIN_CARTESIANMAPS_HPP_
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2025 MPI-M, Clara Bayley
3+
*
4+
*
5+
* ----- CLEO_1dkid -----
6+
* File: kid_reinit.hpp
7+
* Project: cartesiandomain
8+
* Created Date: Monday 14th July 2025
9+
* Author: Clara Bayley (CB)
10+
* Additional Contributors:
11+
* -----
12+
* Last Modified: Monday 14th July 2025
13+
* Modified By: CB
14+
* -----
15+
* License: BSD 3-Clause "New" or "Revised" License
16+
* https://opensource.org/licenses/BSD-3-Clause
17+
* -----
18+
* File Description:
19+
* Definition of the boundary condition for the KiD 1-D test case where superdroplets that leave the
20+
* top of the domain are reinitialised with their dry radius.
21+
*/
22+
23+
#ifndef CLEO_1DKID_CLEO_DEPS_LIBS_CARTESIANDOMAIN_KID_REINIT_HPP_
24+
#define CLEO_1DKID_CLEO_DEPS_LIBS_CARTESIANDOMAIN_KID_REINIT_HPP_
25+
26+
#include <Kokkos_Core.hpp>
27+
28+
/* combiined with change_radius function this will set a superdroplet's radius to its dry radius */
29+
double kid_reinitialise_radius(const double radius) {
30+
return 0.0;
31+
}
32+
33+
#endif // CLEO_1DKID_CLEO_DEPS_LIBS_CARTESIANDOMAIN_KID_REINIT_HPP_

cleo_1dkid/cleo_deps/libs/gridboxes/gridboxmaps.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ concept GridboxMaps = requires(GbxMaps gbxmaps, unsigned int idx, size_t s, doub
5353

5454
{ gbxmaps.global_to_local_gbxindex(s) } -> std::convertible_to<unsigned int>;
5555
{ gbxmaps.local_to_global_gridbox_index(idx) } -> std::convertible_to<size_t>;
56-
{ gbxmaps.get_local_bounding_gridbox(idx, d, d, d) } -> std::convertible_to<unsigned int>;
56+
{ gbxmaps.get_local_bounding_gridbox(idx, d, d, d, d) } -> std::convertible_to<unsigned int>;
5757
};
5858

5959
#endif // CLEO_1DKID_CLEO_DEPS_LIBS_GRIDBOXES_GRIDBOXMAPS_HPP_

cleo_1dkid/cleo_deps/libs/gridboxes/predcorrmotion.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ struct PredCorrMotion {
9191
auto coord3 = drop.get_coord3();
9292
auto coord1 = drop.get_coord1();
9393
auto coord2 = drop.get_coord2();
94-
const auto idx = gbxmaps.get_local_bounding_gridbox(gbxindex, coord3, coord1,
95-
coord2); // drop_coords may change(!)
94+
auto radius = drop.get_radius();
95+
// (!) drop_coords and radius may change inside get_local_bounding_gridbox (!)
96+
const auto idx = gbxmaps.get_local_bounding_gridbox(gbxindex, coord3, coord1, coord2, radius);
9697

9798
// Sets the updated superdroplet coordinates and gridbox index
9899
drop.set_coords(coord3, coord1, coord2);
99100
drop.set_sdgbxindex(idx);
101+
drop.change_radius(radius);
100102

101103
// If the index is non-local return
102104
// For superdrops going to other processes checks will be perfomed in the receiver

0 commit comments

Comments
 (0)