Skip to content

Commit 60a466a

Browse files
committed
Add ShearingPeriodic boundary support to GSPH
Reuse SPH's shearing box implementation (Stone 2010) for GSPH: - Add set_boundary_shearing_periodic() method to SolverConfig - Handle ShearingPeriodic in gen_ghost_handler() using SPH ghost handler - Handle ShearingPeriodic in apply_position_boundary() using integrator utilities This enables differentially rotating system simulations (e.g., accretion disks) with the GSPH solver.
1 parent f781521 commit 60a466a

2 files changed

Lines changed: 47 additions & 12 deletions

File tree

src/shammodels/gsph/include/shammodels/gsph/SolverConfig.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,20 @@ struct shammodels::gsph::SolverConfig {
229229
boundary_config.set_wall(num_layers, wall_flags);
230230
}
231231

232+
/**
233+
* @brief Set shearing periodic boundary conditions
234+
*
235+
* Implements shearing box boundaries (Stone 2010) for simulations
236+
* of differentially rotating systems (e.g., accretion disks).
237+
*
238+
* @param shear_base Base vector for shear periodicity count
239+
* @param shear_dir Direction of the shear velocity shift
240+
* @param speed Shear velocity magnitude
241+
*/
242+
inline void set_boundary_shearing_periodic(i32_3 shear_base, i32_3 shear_dir, Tscal speed) {
243+
boundary_config.set_shearing_periodic(shear_base, shear_dir, speed);
244+
}
245+
232246
//////////////////////////////////////////////////////////////////////////////////////////////
233247
// Boundary Config (END)
234248
//////////////////////////////////////////////////////////////////////////////////////////////

src/shammodels/gsph/src/Solver.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ void shammodels::gsph::Solver<Tvec, Kern>::gen_ghost_handler(Tscal time_val) {
117117
using CfgClass = sph::BasicSPHGhostHandlerConfig<Tvec>;
118118
using BCConfig = typename CfgClass::Variant;
119119

120-
using BCFree = typename CfgClass::Free;
121-
using BCPeriodic = typename CfgClass::Periodic;
120+
using BCFree = typename CfgClass::Free;
121+
using BCPeriodic = typename CfgClass::Periodic;
122+
using BCShearingPeriodic = typename CfgClass::ShearingPeriodic;
122123

123-
using SolverConfigBC = typename Config::BCConfig;
124-
using SolverBCFree = typename SolverConfigBC::Free;
125-
using SolverBCPeriodic = typename SolverConfigBC::Periodic;
124+
using SolverConfigBC = typename Config::BCConfig;
125+
using SolverBCFree = typename SolverConfigBC::Free;
126+
using SolverBCPeriodic = typename SolverConfigBC::Periodic;
127+
using SolverBCShearingPeriodic = typename SolverConfigBC::ShearingPeriodic;
126128

127129
// Boundary condition selection - similar to SPH solver
128130
// Note: Wall boundaries use Periodic with dynamic wall particles
@@ -132,10 +134,17 @@ void shammodels::gsph::Solver<Tvec, Kern>::gen_ghost_handler(Tscal time_val) {
132134
SolverBCPeriodic *c
133135
= std::get_if<SolverBCPeriodic>(&solver_config.boundary_config.config)) {
134136
storage.ghost_handler.set(GhostHandle{scheduler(), BCPeriodic{}, storage.patch_rank_owner});
137+
} else if (
138+
SolverBCShearingPeriodic *c
139+
= std::get_if<SolverBCShearingPeriodic>(&solver_config.boundary_config.config)) {
140+
// Shearing periodic boundaries (Stone 2010) - reuse SPH implementation
141+
storage.ghost_handler.set(GhostHandle{
142+
scheduler(),
143+
BCShearingPeriodic{c->shear_base, c->shear_dir, c->shear_speed * time_val, c->shear_speed},
144+
storage.patch_rank_owner});
135145
} else {
136-
// ShearingPeriodic and other BC types not yet supported in GSPH
137146
shambase::throw_with_loc<std::runtime_error>(
138-
"GSPH: Unsupported boundary condition type. Only Free and Periodic are supported.");
147+
"GSPH: Unsupported boundary condition type.");
139148
}
140149
}
141150

@@ -473,9 +482,10 @@ void shammodels::gsph::Solver<Tvec, Kern>::apply_position_boundary(Tscal time_va
473482
const u32 ivxyz = pdl.get_field_idx<Tvec>("vxyz");
474483
auto [bmin, bmax] = sched.get_box_volume<Tvec>();
475484

476-
using SolverConfigBC = typename Config::BCConfig;
477-
using SolverBCFree = typename SolverConfigBC::Free;
478-
using SolverBCPeriodic = typename SolverConfigBC::Periodic;
485+
using SolverConfigBC = typename Config::BCConfig;
486+
using SolverBCFree = typename SolverConfigBC::Free;
487+
using SolverBCPeriodic = typename SolverConfigBC::Periodic;
488+
using SolverBCShearingPeriodic = typename SolverConfigBC::ShearingPeriodic;
479489

480490
if (SolverBCFree *c = std::get_if<SolverBCFree>(&solver_config.boundary_config.config)) {
481491
if (shamcomm::world_rank() == 0) {
@@ -485,10 +495,21 @@ void shammodels::gsph::Solver<Tvec, Kern>::apply_position_boundary(Tscal time_va
485495
SolverBCPeriodic *c
486496
= std::get_if<SolverBCPeriodic>(&solver_config.boundary_config.config)) {
487497
integrators.fields_apply_periodicity(ixyz, std::pair{bmin, bmax});
498+
} else if (
499+
SolverBCShearingPeriodic *c
500+
= std::get_if<SolverBCShearingPeriodic>(&solver_config.boundary_config.config)) {
501+
// Apply shearing periodic boundaries (Stone 2010) - reuse SPH implementation
502+
integrators.fields_apply_shearing_periodicity(
503+
ixyz,
504+
ivxyz,
505+
std::pair{bmin, bmax},
506+
c->shear_base,
507+
c->shear_dir,
508+
c->shear_speed * time_val,
509+
c->shear_speed);
488510
} else {
489-
// ShearingPeriodic and other BC types not yet supported in GSPH
490511
shambase::throw_with_loc<std::runtime_error>(
491-
"GSPH: Unsupported boundary condition type. Only Free and Periodic are supported.");
512+
"GSPH: Unsupported boundary condition type.");
492513
}
493514

494515
reatrib.reatribute_patch_objects(storage.serial_patch_tree.get(), "xyz");

0 commit comments

Comments
 (0)