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

Create body term #90

Merged
merged 1 commit into from
May 8, 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
1 change: 1 addition & 0 deletions src/CabanaPD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#ifndef CABANAPD_HPP
#define CABANAPD_HPP

#include <CabanaPD_BodyTerm.hpp>
#include <CabanaPD_Boundary.hpp>
#include <CabanaPD_Comm.hpp>
#include <CabanaPD_Fields.hpp>
Expand Down
53 changes: 53 additions & 0 deletions src/CabanaPD_BodyTerm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/****************************************************************************
* Copyright (c) 2022-2023 by Oak Ridge National Laboratory *
streeve marked this conversation as resolved.
Show resolved Hide resolved
* 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 <Kokkos_Core.hpp>

#include <Cabana_Core.hpp>

namespace CabanaPD
{

template <class UserFunctor>
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 <class ExecSpace, class ParticleType>
void apply( ExecSpace, ParticleType& particles, const double time )
{
Kokkos::RangePolicy<ExecSpace> 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 <class UserFunctor>
auto createBodyTerm( UserFunctor user_functor )
{
return BodyTerm<UserFunctor>( user_functor );
}

} // namespace CabanaPD

#endif
Loading