From f2cc0780897b772879c83b7346c1f4138c01d656 Mon Sep 17 00:00:00 2001 From: Sam Reeve <6740307+streeve@users.noreply.github.com> Date: Fri, 19 Apr 2024 10:10:16 -0400 Subject: [PATCH] Create body term applied to all local particles (e.g. temperature) --- src/CabanaPD.hpp | 1 + src/CabanaPD_BodyTerm.hpp | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/CabanaPD_BodyTerm.hpp diff --git a/src/CabanaPD.hpp b/src/CabanaPD.hpp index 95e66b32..bd094231 100644 --- a/src/CabanaPD.hpp +++ b/src/CabanaPD.hpp @@ -12,6 +12,7 @@ #ifndef CABANAPD_HPP #define CABANAPD_HPP +#include #include #include #include diff --git a/src/CabanaPD_BodyTerm.hpp b/src/CabanaPD_BodyTerm.hpp new file mode 100644 index 00000000..b575ce44 --- /dev/null +++ b/src/CabanaPD_BodyTerm.hpp @@ -0,0 +1,53 @@ +/**************************************************************************** + * Copyright (c) 2022-2023 by Oak Ridge National Laboratory * + * All rights reserved. * + * * + * This file is part of CabanaPD. CabanaPD is distributed under a * + * BSD 3-clause license. For the licensing terms see the LICENSE file in * + * the top-level directory. * + * * + * SPDX-License-Identifier: BSD-3-Clause * + ****************************************************************************/ + +#ifndef BODYTERM_H +#define BODYTERM_H + +#include + +#include + +namespace CabanaPD +{ + +template +struct BodyTerm +{ + UserFunctor _user_functor; + + BodyTerm( UserFunctor user ) + : _user_functor( user ) + { + } + + // This function interface purposely matches the boundary conditions in + // order to use the two interchangeably in Solvers. + template + void apply( ExecSpace, ParticleType& particles, const double time ) + { + Kokkos::RangePolicy policy( 0, particles.n_local ); + auto user = _user_functor; + Kokkos::parallel_for( + "CabanaPD::BodyTerm::apply", policy, + KOKKOS_LAMBDA( const int p ) { user( p, time ); } ); + } +}; + +template +auto createBodyTerm( UserFunctor user_functor ) +{ + return BodyTerm( user_functor ); +} + +} // namespace CabanaPD + +#endif