Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
Xayah-Hina committed Dec 28, 2023
1 parent 6225989 commit 54fd080
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 51 deletions.
2 changes: 2 additions & 0 deletions hdk/example-06 neighbor search/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <SIM/SIM_DopDescription.h>
#include <SIM/SIM_Utils.h>

#include <UT/UT_ParallelUtil.h>

/// Very Simple Gravity and Collision With Plane Example
class NeighborSearchSolver : public SIM_SingleSolver, public SIM_OptionsUser
{
Expand Down
24 changes: 24 additions & 0 deletions test/test1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,27 @@ target_include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
houdini_configure_target(${TARGET})

set(TEST_TARGET test)
add_executable(
${TEST_TARGET}
test.cpp
)
# Link Houdini Toolkit
target_link_libraries(
${TEST_TARGET}
PUBLIC
${TARGET}
Houdini
)
target_link_directories(
${TEST_TARGET}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_include_directories(
${TEST_TARGET}
PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
7 changes: 1 addition & 6 deletions test/test1/src/data.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#ifndef SIM_PBF_DATA_H
#define SIM_PBF_DATA_H

#include "utils.h"
#include <vector>

namespace HinaPE_PBF
{
using real = float;
using size = int32_t;

struct PBF_DATA
{
// Sim Data
Expand All @@ -23,6 +19,5 @@ struct PBF_DATA
std::vector<real> lambdas;
std::vector<real> delta_p;
};
}

#endif //SIM_PBF_DATA_H
4 changes: 0 additions & 4 deletions test/test1/src/solver.cpp
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)
{

}
15 changes: 13 additions & 2 deletions test/test1/src/solver.h
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
9 changes: 0 additions & 9 deletions test/test1/src/utils.cpp
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)
{

}
109 changes: 79 additions & 30 deletions test/test1/src/utils.h
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
64 changes: 64 additions & 0 deletions test/test1/test.cpp
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;
}

0 comments on commit 54fd080

Please sign in to comment.