-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6225989
commit 54fd080
Showing
8 changed files
with
183 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
#include "solver.h" | ||
|
||
void InitPBFData(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp) | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
#ifndef SIM_PBF_SOLVER_H | ||
#define SIM_PBF_SOLVER_H | ||
|
||
#include "data.h" | ||
#include "utils.h" | ||
|
||
#include <GU/GU_Detail.h> | ||
void InitPBFData(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp); | ||
#include <SIM/SIM_PointNeighbourList.h> | ||
#include <UT/UT_ParallelUtil.h> | ||
|
||
//void InitPBFData(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp); | ||
|
||
|
||
|
||
template<typename SRC> | ||
void BuildNeighbourList_Native( | ||
UT_Array<UT_Array<GA_Offset>> &OutNeighbourList, const UT_Vector3TArrayHandle<SRC> &InPoints, sz InPointsSize, sz StartIndex = 0) | ||
{ | ||
|
||
} | ||
#endif //SIM_PBF_SOLVER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1 @@ | ||
#include "utils.h" | ||
|
||
void SyncParticlePositionFromGDP(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp) | ||
{ | ||
|
||
} | ||
void SyncGDPFromParticlePosition(GU_Detail &gdp, const HinaPE_PBF::PBF_DATA &data) | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,103 @@ | ||
#ifndef SIM_PBF_UTILS_H | ||
#define SIM_PBF_UTILS_H | ||
|
||
#include "data.h" | ||
#include <GU/GU_Detail.h> | ||
|
||
namespace HinaPE_PBF | ||
{ | ||
template<typename T, typename Prim> | ||
struct ArrayHandle | ||
#include <numeric> | ||
|
||
using real = float; | ||
using sz = int32; | ||
|
||
template<typename SRC> | ||
struct UT_Vector3TArrayHandle | ||
{ | ||
ArrayHandle(T *_internal) : internal(_internal) {} | ||
~ArrayHandle() = default; | ||
explicit UT_Vector3TArrayHandle(SRC *_internal, std::function<sz(sz)> &&ito = [](sz i) { return i; }) | ||
: internal(_internal), index_to_offset(std::move(ito)) {} | ||
virtual ~UT_Vector3TArrayHandle() = default; | ||
|
||
virtual Prim get(int off) const = 0; | ||
virtual void set(int off, Prim p) = 0; | ||
virtual UT_Vector3T<real> geti(int idx) const { return geto(index_to_offset(idx)); } | ||
virtual void seti(int idx, UT_Vector3T<real> p) { seto(index_to_offset(idx), p); } | ||
|
||
T *internal; | ||
virtual UT_Vector3T<real> geto(int off) const = 0; | ||
virtual void seto(int off, UT_Vector3T<real> p) = 0; | ||
|
||
std::function<sz(sz)> index_to_offset; | ||
|
||
protected: | ||
SRC *internal; | ||
}; | ||
|
||
template<typename T, typename Prim> | ||
struct ConstArrayHandle | ||
template<typename SRC> | ||
struct MultipleUT_Vector3TArrayHandle | ||
{ | ||
ConstArrayHandle(ArrayHandle<T, Prim> *_internal) : internal(_internal) {} | ||
~ConstArrayHandle() = default; | ||
explicit MultipleUT_Vector3TArrayHandle(std::vector<std::pair<UT_Vector3TArrayHandle<SRC> *, sz>> *InArrays) | ||
: Arrays(InArrays) {} | ||
~MultipleUT_Vector3TArrayHandle() = default; | ||
|
||
Prim get(int off) const { return internal->get(off); } | ||
virtual UT_Vector3T<real> geti(int idx) const | ||
{ | ||
int sum = 0; | ||
int last_sum = 0; | ||
int iter = -1; | ||
while (sum <= idx) | ||
{ | ||
iter++; | ||
last_sum = sum; | ||
sum += (*Arrays)[iter].second; | ||
} | ||
if (iter >= Arrays->size() || iter < 0) | ||
return UT_Vector3T<real>(); | ||
int real_idx = idx - last_sum; | ||
return (*Arrays)[iter].first->geti(real_idx); | ||
} | ||
virtual void seti(int idx, UT_Vector3T<real> p) | ||
{ | ||
int sum = 0; | ||
int last_sum = 0; | ||
int iter = -1; | ||
while (sum <= idx) | ||
{ | ||
iter++; | ||
last_sum = sum; | ||
sum += (*Arrays)[iter].second; | ||
} | ||
if (iter >= Arrays->size() || iter < 0) | ||
return; | ||
int real_idx = idx - last_sum; | ||
(*Arrays)[iter].first->seti(real_idx, p); | ||
} | ||
virtual sz value_size() | ||
{ | ||
return std::accumulate(Arrays->begin(), Arrays->end(), 0, [](sz acc, const std::pair<UT_Vector3TArrayHandle<SRC> *, sz> &p) | ||
{ | ||
return acc + p.second; | ||
}); | ||
} | ||
sz size() | ||
{ | ||
return Arrays->size(); | ||
} | ||
|
||
ArrayHandle<T, Prim> *internal; | ||
protected: | ||
std::vector<std::pair<UT_Vector3TArrayHandle<SRC> *, sz>> *Arrays; | ||
}; | ||
|
||
struct NativeVector3Handle : public ArrayHandle<std::vector<real>, UT_Vector3T<real>> | ||
struct NativeArrayHandle : public UT_Vector3TArrayHandle<std::vector<real>> | ||
{ | ||
NativeVector3Handle(std::vector<real> *_internal) : ArrayHandle(_internal) {} | ||
~NativeVector3Handle() = default; | ||
NativeArrayHandle(std::vector<real> *_internal) : UT_Vector3TArrayHandle(_internal) {} | ||
~NativeArrayHandle() override = default; | ||
|
||
UT_Vector3T<real> get(int off) const override { return UT_Vector3T<real>(internal->data() + off * 3); } | ||
void set(int off, UT_Vector3T<real> p) override { memcpy(internal->data() + off * 3, p.data(), sizeof(real) * 3); } | ||
UT_Vector3T<real> geto(int off) const override { return UT_Vector3T<real>(internal->data() + off * 3); } | ||
void seto(int off, UT_Vector3T<real> p) override { memcpy(internal->data() + off * 3, p.data(), sizeof(real) * 3); } | ||
}; | ||
|
||
struct GDPVector3Handle : public ArrayHandle<GU_Detail, UT_Vector3T<real>> | ||
struct GA_ArrayHandle : public UT_Vector3TArrayHandle<GA_RWHandleT<UT_Vector3T<real>>> | ||
{ | ||
GDPVector3Handle(GU_Detail *gdp) : ArrayHandle(gdp) {} | ||
~GDPVector3Handle() = default; | ||
GA_ArrayHandle(GA_RWHandleT<UT_Vector3T<real>> *handle) : UT_Vector3TArrayHandle(handle) {} | ||
~GA_ArrayHandle() override = default; | ||
|
||
UT_Vector3T<real> get(int off) const override { return internal->getPos3(off); } | ||
void set(int off, UT_Vector3T<real> p) override { internal->setPos3(off, p); } | ||
UT_Vector3T<real> geto(int off) const override { return internal->get(off); } | ||
void seto(int off, UT_Vector3T<real> p) override { internal->set(off, p); } | ||
}; | ||
} | ||
|
||
void SyncParticlePositionFromGDP(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp); | ||
void SyncGDPFromParticlePosition(GU_Detail &gdp, const HinaPE_PBF::PBF_DATA &data); | ||
|
||
#endif //SIM_PBF_UTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "src/utils.h" | ||
|
||
#include <random> | ||
#include <iostream> | ||
|
||
bool Test_NativeArrayHandle() | ||
{ | ||
std::vector<real> test; | ||
for (int i = 0; i < 3000; ++i) | ||
test.emplace_back(i); | ||
|
||
NativeArrayHandle test_handle(&test); | ||
std::cout << test_handle.geti(0) << std::endl; | ||
std::cout << test_handle.geti(1) << std::endl; | ||
std::cout << test_handle.geti(2) << std::endl; | ||
std::cout << test_handle.geti(3) << std::endl; | ||
std::cout << test_handle.geti(4) << std::endl; | ||
|
||
return true; | ||
} | ||
|
||
bool Test_GA_ArrayHandle() | ||
{ | ||
// TODO: Implement | ||
return true; | ||
} | ||
|
||
bool Test_MultipleUT_Vector3TArrayHandle() | ||
{ | ||
std::vector<real> test1, test2, test3; | ||
for (int i = 0; i < 3000; ++i) | ||
test1.emplace_back(i); | ||
for (int i = 0; i < 3000; ++i) | ||
test2.emplace_back(i + 3000); | ||
for (int i = 0; i < 3000; ++i) | ||
test3.emplace_back(i + 6000); | ||
NativeArrayHandle test_handle1(&test1); | ||
NativeArrayHandle test_handle2(&test2); | ||
NativeArrayHandle test_handle3(&test3); | ||
|
||
std::vector<std::pair<UT_Vector3TArrayHandle<std::vector<real>> *, sz>> test_array; | ||
test_array.emplace_back(&test_handle1, 3000); | ||
test_array.emplace_back(&test_handle2, 3000); | ||
test_array.emplace_back(&test_handle3, 3000); | ||
|
||
MultipleUT_Vector3TArrayHandle<std::vector<real>> test_handle(&test_array); | ||
std::cout << test_handle.geti(0) << std::endl; | ||
std::cout << test_handle.geti(1) << std::endl; | ||
std::cout << test_handle.geti(2) << std::endl; | ||
std::cout << test_handle.geti(3000) << std::endl; | ||
std::cout << test_handle.geti(3001) << std::endl; | ||
std::cout << test_handle.geti(3002) << std::endl; | ||
std::cout << test_handle.geti(6000) << std::endl; | ||
std::cout << test_handle.geti(6001) << std::endl; | ||
std::cout << test_handle.geti(6002) << std::endl; | ||
return true; | ||
}; | ||
|
||
int main() | ||
{ | ||
Test_NativeArrayHandle(); | ||
Test_MultipleUT_Vector3TArrayHandle(); | ||
return 0; | ||
} |