Skip to content

Commit a8f9313

Browse files
committed
use inheritance
1 parent 9360ac2 commit a8f9313

File tree

2 files changed

+17
-54
lines changed

2 files changed

+17
-54
lines changed

src/shared/shared_ck/body_relation/neighbor_method.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ class NeighborMethod<SingleValued> : public NeighborMethod<Base>
126126
inline Real Gradient2Factor(const Vec3d &) const { return inv_h_fifth_ * dimension_factor_3D_; };
127127
};
128128

129-
class CriterionKernel
129+
class NeighborCriterion
130130
{
131131
Vecd *source_pos_;
132132
Vecd *target_pos_;
133133
Real kernel_size_squared_, inv_h_;
134134

135135
public:
136136
template <class ExecutionPolicy, class EncloserType>
137-
CriterionKernel(const ExecutionPolicy &ex_policy, EncloserType &encloser,
137+
NeighborCriterion(const ExecutionPolicy &ex_policy, EncloserType &encloser,
138138
DiscreteVariable<Vecd> *dv_source_pos, DiscreteVariable<Vecd> *dv_target_pos)
139139
: source_pos_(dv_source_pos->DelegatedData(ex_policy)),
140140
target_pos_(dv_target_pos->DelegatedData(ex_policy)),
@@ -147,20 +147,20 @@ class NeighborMethod<SingleValued> : public NeighborMethod<Base>
147147
};
148148
};
149149

150-
class SmoothingRatioKernel
150+
class SmoothingRatio
151151
{
152152
public:
153153
template <class ExecutionPolicy, class EncloserType>
154-
SmoothingRatioKernel(const ExecutionPolicy &ex_policy, EncloserType &encloser){};
154+
SmoothingRatio(const ExecutionPolicy &ex_policy, EncloserType &encloser){};
155155

156156
Real operator()(UnsignedInt i) const { return 1.0; };
157157
};
158158

159-
class SearchDepthKernel
159+
class SearchDepth
160160
{
161161
public:
162162
template <class ExecutionPolicy, class EncloserType>
163-
SearchDepthKernel(const ExecutionPolicy &ex_policy, EncloserType &encloser)
163+
SearchDepth(const ExecutionPolicy &ex_policy, EncloserType &encloser)
164164
: search_depth_(encloser.search_depth_){};
165165

166166
int operator()(UnsignedInt i) const { return search_depth_; };

src/shared/shared_ck/body_relation/neighborhood_ck.h

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -36,89 +36,52 @@
3636
namespace SPH
3737
{
3838
template <class NeighborMethodType>
39-
class Neighbor
39+
class Neighbor : public NeighborMethodType
4040
{
4141
public:
4242
template <class SourceIdentifier, class TargetIdentifier>
4343
Neighbor(SourceIdentifier &source_identifier, TargetIdentifier &contact_identifier,
4444
DiscreteVariable<Vecd> *dv_source_pos, DiscreteVariable<Vecd> *dv_target_pos)
45-
: neighbor_method_(source_identifier, contact_identifier),
45+
: NeighborMethodType(source_identifier, contact_identifier),
4646
dv_source_pos_(dv_source_pos), dv_target_pos_(dv_target_pos){};
4747

48-
class NeighborKernel
48+
class NeighborKernel : public NeighborMethodType::SmoothingKernel
4949
{
50-
using SmoothingKernel = typename NeighborMethodType::SmoothingKernel;
50+
using BaseKernel = typename NeighborMethodType::SmoothingKernel;
5151

5252
public:
5353
template <class ExecutionPolicy, class EncloserType>
5454
NeighborKernel(const ExecutionPolicy &ex_policy, EncloserType &encloser)
55-
: smoothing_kernel_(ex_policy, encloser.neighbor_method_),
55+
: BaseKernel(ex_policy, encloser),
5656
source_pos_(encloser.dv_source_pos_->DelegatedData(ex_policy)),
5757
target_pos_(encloser.dv_target_pos_->DelegatedData(ex_policy)){};
5858

5959
inline Vecd vec_r_ij(UnsignedInt i, UnsignedInt j) const { return source_pos_[i] - target_pos_[j]; };
6060
inline Vecd e_ij(UnsignedInt i, UnsignedInt j) const { return vec_r_ij(i, j).normalized(); };
61-
inline Real W_ij(UnsignedInt i, UnsignedInt j) const { return smoothing_kernel_.W(vec_r_ij(i, j)); };
62-
inline Real dW_ij(UnsignedInt i, UnsignedInt j) const { return smoothing_kernel_.dW(vec_r_ij(i, j)); };
63-
inline Real W(const Vecd &displacement) const { return smoothing_kernel_.W(displacement); };
61+
inline Real W_ij(UnsignedInt i, UnsignedInt j) const { return BaseKernel::W(vec_r_ij(i, j)); };
62+
inline Real dW_ij(UnsignedInt i, UnsignedInt j) const { return BaseKernel::dW(vec_r_ij(i, j)); };
6463

6564
protected:
66-
SmoothingKernel smoothing_kernel_;
6765
Vecd *source_pos_;
6866
Vecd *target_pos_;
6967
};
7068

71-
class NeighborCriterion
69+
class NeighborCriterion : public NeighborMethodType::NeighborCriterion
7270
{
73-
using CriterionKernel = typename NeighborMethodType::CriterionKernel;
71+
using BaseKernel = typename NeighborMethodType::NeighborCriterion;
7472

7573
public:
7674
template <class ExecutionPolicy, class EncloserType>
7775
NeighborCriterion(const ExecutionPolicy &ex_policy, EncloserType &encloser)
78-
: criterion_kernel_(ex_policy, encloser.neighbor_method_,
79-
encloser.dv_source_pos_, encloser.dv_target_pos_){};
76+
: BaseKernel(ex_policy, encloser, encloser.dv_source_pos_, encloser.dv_target_pos_){};
8077

8178
inline bool operator()(UnsignedInt target_index, UnsignedInt source_index) const
8279
{
83-
return criterion_kernel_(source_index, target_index);
80+
return BaseKernel::operator()(source_index, target_index); // Note the order of indices
8481
};
85-
86-
protected:
87-
CriterionKernel criterion_kernel_;
88-
};
89-
90-
class SearchDepth
91-
{
92-
using SearchDepthKernel = typename NeighborMethodType::SearchDepthKernel;
93-
94-
public:
95-
template <class ExecutionPolicy, class EncloserType>
96-
SearchDepth(const ExecutionPolicy &ex_policy, EncloserType &encloser)
97-
: search_depth_kernel_(ex_policy, encloser.neighbor_method_){};
98-
99-
inline int operator()(UnsignedInt i) const { return search_depth_kernel_(i); };
100-
101-
protected:
102-
SearchDepthKernel search_depth_kernel_;
103-
};
104-
105-
class SmoothingRatio
106-
{
107-
using SmoothingRatioKernel = typename NeighborMethodType::SmoothingRatioKernel;
108-
109-
public:
110-
template <class ExecutionPolicy, class EncloserType>
111-
SmoothingRatio(const ExecutionPolicy &ex_policy, EncloserType &encloser)
112-
: smoothing_ratio_kernel_(ex_policy, encloser.neighbor_method_){};
113-
114-
inline Real operator()(UnsignedInt i) const { return smoothing_ratio_kernel_(i); };
115-
116-
protected:
117-
SmoothingRatioKernel smoothing_ratio_kernel_;
11882
};
11983

12084
protected:
121-
NeighborMethodType neighbor_method_; /**< The neighbor method for the neighborhood. */
12285
DiscreteVariable<Vecd> *dv_source_pos_;
12386
DiscreteVariable<Vecd> *dv_target_pos_;
12487
};

0 commit comments

Comments
 (0)