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 87f8dc8 commit 6225989
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/test1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.26)

project(SIM_PBF)

set(CMAKE_CXX_STANDARD 17)
set(TARGET SIM_PBFSolver)

# Find Houdini
set(Houdini_PATH "C:/Program Files/Side Effects Software/Houdini 20.0.547")
set(Houdini_DIR ${Houdini_PATH}/toolkit/cmake)
find_package(Houdini REQUIRED)

# Load Source
add_library(
${TARGET}
SHARED
Entrance.cpp
SIM_PBF.cpp
SIM_PBF.h

src/solver.cpp
src/solver.h
src/utils.cpp
src/utils.h
src/data.cpp
src/data.h
)

# Link Houdini Toolkit
target_link_libraries(
${TARGET}
PUBLIC
Houdini
)
target_link_directories(
${TARGET}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_include_directories(
${TARGET}
PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
houdini_configure_target(${TARGET})
8 changes: 8 additions & 0 deletions test/test1/Entrance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <UT/UT_DSOVersion.h> // Very Important!!! Include this!!!

#include "SIM_PBF.h"

void initializeSIM(void *)
{
IMPLEMENT_DATAFACTORY(SIM_PBFSolver);
}
40 changes: 40 additions & 0 deletions test/test1/SIM_PBF.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "SIM_PBF.h"

#include <PRM/PRM_Name.h>
#include <PRM/PRM_Template.h>
#include <PRM/PRM_Shared.h>
#include <PRM/PRM_Default.h>

#include <SIM/SIM_Engine.h>
#include <SIM/SIM_Object.h>
#include <SIM/SIM_ObjectArray.h>
#include <SIM/SIM_PositionSimple.h>
#include <SIM/SIM_GeometryCopy.h>

SIM_Solver::SIM_Result SIM_PBFSolver::solveSingleObjectSubclass(SIM_Engine &engine, SIM_Object &object, SIM_ObjectArray &feedbacktoobjects, const SIM_Time &timestep, bool newobject)
{
static bool NeedReBuild = true;

if (NeedReBuild || newobject)
{
NeedReBuild = false;
return SIM_SOLVER_SUCCESS;
}

return SIM_Solver::SIM_SOLVER_SUCCESS;
}

const SIM_DopDescription *SIM_PBFSolver::GetDescription()
{
static std::array<PRM_Template, 1> PRMS{
PRM_Template()
};

static SIM_DopDescription DESC(true,
"pbf_solver",
"PBF Solver",
"PBFSolver",
classname(),
PRMS.data());
return &DESC;
}
21 changes: 21 additions & 0 deletions test/test1/SIM_PBF.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef HINAPE_SIM_PBF_H
#define HINAPE_SIM_PBF_H

#include <SIM/SIM_SingleSolver.h>
#include <SIM/SIM_OptionsUser.h>
#include <SIM/SIM_DopDescription.h>
#include <SIM/SIM_Utils.h>

class SIM_PBFSolver : public SIM_SingleSolver, public SIM_OptionsUser
{
private:
SIM_PBFSolver(const SIM_DataFactory *factory) : SIM_SingleSolver(factory), SIM_OptionsUser(this) {}
~SIM_PBFSolver() override = default;
SIM_Result solveSingleObjectSubclass(SIM_Engine &engine, SIM_Object &object, SIM_ObjectArray &feedbacktoobjects, const SIM_Time &timestep, bool newobject) override;
static const SIM_DopDescription* GetDescription();

DECLARE_STANDARD_GETCASTTOTYPE();
DECLARE_DATAFACTORY(SIM_PBFSolver, SIM_SingleSolver, "PBF Solver Description", GetDescription());
};

#endif //HINAPE_SIM_PBF_H
1 change: 1 addition & 0 deletions test/test1/src/data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "data.h"
28 changes: 28 additions & 0 deletions test/test1/src/data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef SIM_PBF_DATA_H
#define SIM_PBF_DATA_H

#include <vector>

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

struct PBF_DATA
{
// Sim Data
std::vector<real> positions;
std::vector<real> positions_predicted;
std::vector<real> velocities;
std::vector<real> forces;
std::vector<real> mass;
std::vector<real> inv_mass;

// State Data
std::vector<real> densities;
std::vector<real> lambdas;
std::vector<real> delta_p;
};
}

#endif //SIM_PBF_DATA_H
6 changes: 6 additions & 0 deletions test/test1/src/solver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "solver.h"

void InitPBFData(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp)
{

}
9 changes: 9 additions & 0 deletions test/test1/src/solver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef SIM_PBF_SOLVER_H
#define SIM_PBF_SOLVER_H

#include "data.h"

#include <GU/GU_Detail.h>
void InitPBFData(HinaPE_PBF::PBF_DATA &data, const GU_Detail &gdp);

#endif //SIM_PBF_SOLVER_H
10 changes: 10 additions & 0 deletions test/test1/src/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#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)
{

}
54 changes: 54 additions & 0 deletions test/test1/src/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#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
{
ArrayHandle(T *_internal) : internal(_internal) {}
~ArrayHandle() = default;

virtual Prim get(int off) const = 0;
virtual void set(int off, Prim p) = 0;

T *internal;
};

template<typename T, typename Prim>
struct ConstArrayHandle
{
ConstArrayHandle(ArrayHandle<T, Prim> *_internal) : internal(_internal) {}
~ConstArrayHandle() = default;

Prim get(int off) const { return internal->get(off); }

ArrayHandle<T, Prim> *internal;
};

struct NativeVector3Handle : public ArrayHandle<std::vector<real>, UT_Vector3T<real>>
{
NativeVector3Handle(std::vector<real> *_internal) : ArrayHandle(_internal) {}
~NativeVector3Handle() = 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); }
};

struct GDPVector3Handle : public ArrayHandle<GU_Detail, UT_Vector3T<real>>
{
GDPVector3Handle(GU_Detail *gdp) : ArrayHandle(gdp) {}
~GDPVector3Handle() = 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); }
};
}

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

0 comments on commit 6225989

Please sign in to comment.