Skip to content

Commit

Permalink
Merge pull request #90 from streeve/body_term
Browse files Browse the repository at this point in the history
Create body term
  • Loading branch information
streeve authored May 8, 2024
2 parents 4e2acb3 + f2cc078 commit 47fbc04
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
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 *
* 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

0 comments on commit 47fbc04

Please sign in to comment.