Skip to content

Commit

Permalink
Merge pull request #721 from Xiangyu-Hu/ck-sycl/surface_indication_ck
Browse files Browse the repository at this point in the history
Add Surface Indication With CK/SYCL? Feature to SPHinXsys
  • Loading branch information
Xiangyu-Hu authored Jan 22, 2025
2 parents fa859e7 + 4360200 commit b8b20f2
Show file tree
Hide file tree
Showing 6 changed files with 417 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
#include "geometric_dynamics.hpp"
#include "interpolation_dynamics.hpp"
#include "kernel_correction_ck.hpp"
#include "all_surface_indication_ck.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* ------------------------------------------------------------------------- *
* SPHinXsys *
* ------------------------------------------------------------------------- *
* SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle *
* Hydrodynamics for industrial compleX systems. It provides C++ APIs for *
* physical accurate simulation and aims to model coupled industrial dynamic *
* systems including fluid, solid, multi-body dynamics and beyond with SPH *
* (smoothed particle hydrodynamics), a meshless computational method using *
* particle discretization. *
* *
* SPHinXsys is partially funded by German Research Foundation *
* (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1, *
* HU1527/12-1 and HU1527/12-4. *
* *
* Portions copyright (c) 2017-2023 Technical University of Munich and *
* the authors' affiliations. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain a *
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
* *
* ------------------------------------------------------------------------- */

#ifndef B9F4AD2C_8E17_4C49_BCAA_4BD2C6A6951F
#define B9F4AD2C_8E17_4C49_BCAA_4BD2C6A6951F
/**
* @file all_general_dynamics.h
* @brief This is the header file that user code should include to pick up all
* general dynamics used in SPHinXsys.
* @author Chi Zhang and Xiangyu Hu
*/


#include "surface_indication_ck.hpp"


#endif /* B9F4AD2C_8E17_4C49_BCAA_4BD2C6A6951F */
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#ifndef SURFACE_INDICATION_CK_H
#define SURFACE_INDICATION_CK_H

#include "base_general_dynamics.h"
#include "base_fluid_dynamics.h"
#include "interaction_ck.hpp"

namespace SPH
{
namespace fluid_dynamics
{
/**
* @class FreeSurfaceIndicationCK
* @brief Free-surface indication with configurable relationship types.
*
* This template is specialized for different combinations of
* "Base" + "Inner" / "Contact" relations to handle free-surface
* detection and updating in SPH simulations.
*/
template <typename... RelationTypes>
class FreeSurfaceIndicationCK;

//=================================================================================================//
// Base relation version
//=================================================================================================//
/**
* @class FreeSurfaceIndicationCK<Base, RelationType<Parameters...>>
* @brief Basic free-surface indication logic, storing and computing
* positional divergence, surface indicators, etc.
*/
template <template <typename...> class RelationType, typename... Parameters>
class FreeSurfaceIndicationCK<Base, RelationType<Parameters...>>
: public Interaction<RelationType<Parameters...>>
{
public:
template <class BaseRelationType>
explicit FreeSurfaceIndicationCK(BaseRelationType &base_relation);
virtual ~FreeSurfaceIndicationCK() {}

//------------------------------------------------------------------------------------------//
/**
* @class InteractKernel
* @brief Base interaction kernel that calculates positional divergence,
* used in detecting free-surface particles.
*/
class InteractKernel : public Interaction<RelationType<Parameters...>>::InteractKernel
{
public:
template <class ExecutionPolicy, typename... Args>
InteractKernel(const ExecutionPolicy &ex_policy,
FreeSurfaceIndicationCK<Base, RelationType<Parameters...>> &encloser,
Args &&...args);

void interact(size_t index_i, Real dt = 0.0);

protected:
int *indicator_;
Real *pos_div_;
Real *Vol_;
Real threshold_by_dimensions_;
Real smoothing_length_;
};

protected:
DiscreteVariable<int> *dv_indicator_;
DiscreteVariable<Real> *dv_pos_div_;
DiscreteVariable<Real> *dv_Vol_;
Real dv_threshold_by_dimensions_;
Real dv_smoothing_length_;
};

//=================================================================================================//
// Inner relation version with "WithUpdate"
//=================================================================================================//
/**
* @class FreeSurfaceIndicationCK<Inner<WithUpdate, FlowType, Parameters...>>
* @brief Extends the base free-surface indication for inner relations that also require
* an updating step (e.g., "WithUpdate").
*/
template <class FlowType, typename... Parameters>
class FreeSurfaceIndicationCK<Inner<WithUpdate, FlowType, Parameters...>>
: public FreeSurfaceIndicationCK<Base, Inner<Parameters...>>
{
public:
explicit FreeSurfaceIndicationCK(Relation<Inner<Parameters...>> &inner_relation);
virtual ~FreeSurfaceIndicationCK() {}

//------------------------------------------------------------------------------------------//
/**
* @class InteractKernel
* @brief Interaction kernel for detecting free surface in an inner relation.
*/
class InteractKernel
: public FreeSurfaceIndicationCK<Base, Inner<Parameters...>>::InteractKernel
{
public:
template <class ExecutionPolicy>
InteractKernel(const ExecutionPolicy &ex_policy,
FreeSurfaceIndicationCK<Inner<WithUpdate, FlowType, Parameters...>> &encloser);

void interact(size_t index_i, Real dt = 0.0);

/// Pointer to the previously stored surface indicator.
int *previous_surface_indicator_;
};

//------------------------------------------------------------------------------------------//
/**
* @class UpdateKernel
* @brief Post-processing/update kernel that modifies the surface indicator
* based on the newly computed positional divergences and neighbor information.
*/
class UpdateKernel
: public FreeSurfaceIndicationCK<Base, Inner<Parameters...>>::InteractKernel
{
public:
template <class ExecutionPolicy>
UpdateKernel(const ExecutionPolicy &ex_policy,
FreeSurfaceIndicationCK<Inner<WithUpdate, FlowType, Parameters...>> &encloser);

void update(size_t index_i, Real dt = 0.0);

protected:
int *previous_surface_indicator_;
FreeSurfaceIndicationCK<Inner<WithUpdate, FlowType, Parameters...>> *outer_;
};

protected:
DiscreteVariable<int> *dv_previous_surface_indicator_;
};

//------------------------------------------------------------------------------------------//
// Common type alias for internal flow with free-surface indication (with update).
using FreeSurfaceIndicationInnerCK = FreeSurfaceIndicationCK<Inner<WithUpdate, Internal>>;

//=================================================================================================//
// Contact relation version
//=================================================================================================//
/**
* @class FreeSurfaceIndicationCK<Contact<Parameters...>>
* @brief Extends the base free-surface indication for contact relations.
*/
template <typename... Parameters>
class FreeSurfaceIndicationCK<Contact<Parameters...>>
: public FreeSurfaceIndicationCK<Base, Contact<Parameters...>>
{
public:
explicit FreeSurfaceIndicationCK(Relation<Contact<Parameters...>> &contact_relation);
virtual ~FreeSurfaceIndicationCK() {}

//------------------------------------------------------------------------------------------//
/**
* @class InteractKernel
* @brief Interaction kernel for a contact relation, combining data from multiple contact bodies.
*/
class InteractKernel
: public FreeSurfaceIndicationCK<Base, Contact<Parameters...>>::InteractKernel
{
public:
template <class ExecutionPolicy>
InteractKernel(const ExecutionPolicy &ex_policy,
FreeSurfaceIndicationCK<Contact<Parameters...>> &encloser,
size_t contact_index);

void interact(size_t index_i, Real dt = 0.0);

protected:
Real *contact_Vol_;
};

protected:
StdVec<DiscreteVariable<Real> *> dv_contact_Vol_;
};

//------------------------------------------------------------------------------------------//
// Common type alias for complex free-surface indication (inner + contact).
using FreeSurfaceIndicationComplexCK = FreeSurfaceIndicationCK<Inner<WithUpdate, Internal>, Contact<>>;
//------------------------------------------------------------------------------------------//

} // namespace fluid_dynamics
} // namespace SPH

#endif // SURFACE_INDICATION_CK_H
Loading

0 comments on commit b8b20f2

Please sign in to comment.