Simplify translational periodic boundary conditions (#3697)

This commit is contained in:
GuySten 2026-01-09 15:56:40 +02:00 committed by GitHub
parent dfc80c7069
commit 551bf0730b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 18 deletions

View file

@ -129,23 +129,8 @@ TranslationalPeriodicBC::TranslationalPeriodicBC(int i_surf, int j_surf)
void TranslationalPeriodicBC::handle_particle(
Particle& p, const Surface& surf) const
{
int i_particle_surf = p.surface_index();
// Figure out which of the two BC surfaces were struck then find the
// particle's new location and surface.
Position new_r;
int new_surface;
if (i_particle_surf == i_surf_) {
new_r = p.r() + translation_;
new_surface = p.surface() > 0 ? j_surf_ + 1 : -(j_surf_ + 1);
} else if (i_particle_surf == j_surf_) {
new_r = p.r() - translation_;
new_surface = p.surface() > 0 ? i_surf_ + 1 : -(i_surf_ + 1);
} else {
throw std::runtime_error(
"Called BoundaryCondition::handle_particle after "
"hitting a surface, but that surface is not recognized by the BC.");
}
auto new_r = p.r() + translation_;
int new_surface = p.surface() > 0 ? j_surf_ + 1 : -(j_surf_ + 1);
// Handle the effects of the surface albedo on the particle's weight.
BoundaryCondition::handle_albedo(p, surf);

View file

@ -1357,7 +1357,7 @@ void prepare_boundary_conditions(std::set<std::pair<int, int>>& periodic_pairs,
// condition. Otherwise, it is a rotational periodic BC.
if (std::abs(1.0 - dot_prod) < FP_PRECISION) {
surf1.bc_ = make_unique<TranslationalPeriodicBC>(i_surf, j_surf);
surf2.bc_ = make_unique<TranslationalPeriodicBC>(i_surf, j_surf);
surf2.bc_ = make_unique<TranslationalPeriodicBC>(j_surf, i_surf);
} else {
// check that both normals have at least one 0 component
if (std::abs(norm1.x) > FP_PRECISION &&