Skip to content

Commit

Permalink
Merge pull request #1941 from zenustech/XPBD
Browse files Browse the repository at this point in the history
Xpbd update to master
  • Loading branch information
littlemine authored Jun 18, 2024
2 parents c881387 + 051872e commit f092388
Show file tree
Hide file tree
Showing 22 changed files with 2,448 additions and 515 deletions.
6 changes: 3 additions & 3 deletions projects/CUDA/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ retrieve_bounding_volumes(Pol &pol, const TileVecT &vtemp,
template <typename Pol, typename TileVecT>
zs::Vector<typename ZenoParticles::lbvh_t::Box>
retrieve_bounding_volumes(Pol &pol, const TileVecT &vtemp,
float radius = 0.f,
const zs::SmallString &xTag = "xn") {
const float& radius,
const zs::SmallString &xTag) {
using namespace zs;
using bv_t = typename ZenoParticles::lbvh_t::Box;
constexpr auto space = Pol::exec_tag::value;
Expand Down Expand Up @@ -225,7 +225,7 @@ void retrieve_bounding_volumes(Pol &pol, const TileVecT &vtemp,
}

// for ccd
template <typename Pol, typename TileVecT0, typename TileVecT1, int codim = 3>
template <typename Pol, typename TileVecT0, typename TileVecT1, int codim>
zs::Vector<typename ZenoParticles::lbvh_t::Box> retrieve_bounding_volumes(
Pol &pol, const TileVecT0 &verts,
const typename ZenoParticles::particles_t &eles, const TileVecT1 &vtemp,
Expand Down
3 changes: 3 additions & 0 deletions projects/CuLagrange/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ target_sources(zeno PRIVATE
pbd/ConstraintsBuilder.cu
pbd/ConstraintsSolver.cu
pbd/CollisionSolver.cu
pbd/ConstraintsUpdator.cu
)

# fem-cloth
Expand Down Expand Up @@ -125,4 +126,6 @@ target_sources(zeno PRIVATE
geometry/Intersections.cu # CHECK THIS
geometry/Detangle.cu
geometry/HalfEdgeStructures.cu

geometry/ShapeMatching.cu
)
63 changes: 29 additions & 34 deletions projects/CuLagrange/fem/FleshDynamicStepping.cu
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,10 @@ struct FleshDynamicStepping : INode {
T stiffness = (2.0066 * mu + 1.0122 * lambda) * b_verts("strength",vi);


auto alpha = stiffness * bone_driven_weight * bcws("strength",vi) * bcws("cnorm",vi) * eles("vol",ei) * eles("bdw",ei);
auto area = (T)1.0;
if(b_verts.hasProperty("area"))
area = b_verts("area",vi);
auto alpha = area * stiffness * bone_driven_weight * bcws("strength",vi) * bcws("cnorm",vi) * eles("vol",ei) * eles("bdw",ei);

for(size_t i = 0;i != 4;++i){
auto tmp = -pdiff * alpha * w[i];
Expand Down Expand Up @@ -1331,12 +1334,13 @@ struct FleshDynamicStepping : INode {
{"inds",1},
{"w",4},
{"strength",1},
{"cnorm",1}},0,zs::memsrc_e::device,0);
{"cnorm",1}},0,zs::memsrc_e::device);

auto bverts = typename ZenoParticles::particles_t({
{"x",3},
{"intersect",1},
{"strength",1}},0,zs::memsrc_e::device,0);
{"area",1},
{"strength",1}},0,zs::memsrc_e::device);
if(has_input<ZenoParticles>("driven_boudary") && zsparticles->hasAuxData(driven_tag)){
auto zsbones = get_input<ZenoParticles>("driven_boudary");
const auto& zsbones_verts = zsbones->getParticles();
Expand All @@ -1354,23 +1358,21 @@ struct FleshDynamicStepping : INode {
else
TILEVEC_OPS::fill(cudaPol,bverts,"intersect",(T)0.0);

if(zsbones_verts.hasProperty("area")) {
TILEVEC_OPS::copy(cudaPol,zsbones_verts,"area",bverts,"area");
std::cout << "use dynamic area driven weight" << std::endl;
} else
TILEVEC_OPS::fill(cudaPol,bverts,"area",(T)1.0);

const auto& inbbw = (*zsparticles)[driven_tag];
bbw.resize(inbbw.size());
TILEVEC_OPS::copy(cudaPol,inbbw,"X",bbw,"X");
TILEVEC_OPS::copy(cudaPol,inbbw,"inds",bbw,"inds");
TILEVEC_OPS::copy(cudaPol,inbbw,"w",bbw,"w");
TILEVEC_OPS::copy(cudaPol,inbbw,"strength",bbw,"strength");
TILEVEC_OPS::copy(cudaPol,inbbw,"cnorm",bbw,"cnorm");

// if(zsbones_verts.has_attr<float>("drivenStrength"))
// ompExec(zs::range(zsbones_verts.size()),
// [bverts = proxy<host_space>(bverts),&zsbones_verts] (int i) mutable {
// auto v = zsbones_verts[i];
// bverts[i] = zs::vec<T,3>{v[0],v[1],v[2]};
// });

}
// bverts = bverts.clone({zs::memsrc_e::device,0});
// bverts = bverts.clone({zs::memsrc_e::device});
// std::cout << "bverts.size() = " << bverts.size() << std::endl;

auto kverts = typename ZenoParticles::particles_t({
Expand All @@ -1380,29 +1382,11 @@ struct FleshDynamicStepping : INode {
{"binderStiffness",1},
{planeConsIDTag,1},
{"nrm",3},
{"area",1}},0,zs::memsrc_e::device,0);
{"area",1}},0,zs::memsrc_e::device);
auto ktris = typename ZenoParticles::particles_t({
{"inds",3},
{"nrm",3}},0,zs::memsrc_e::device,0);

{"nrm",3}},0,zs::memsrc_e::device);

// dtiles_t surf_tris_buffer{tris.get_allocator(),{
// {"inds",3},
// {"nrm",3},
// {"he_inds",1}
// },tris.size()};

// dtiles_t surf_verts_buffer{points.get_allocator(),{
// {"inds",1},
// {"xn",3},
// {"is_loop_vertex",1},
// {"mustExclude",1}
// },points.size()};
// TILEVEC_OPS::copy(cudaPol,points,"inds",surf_verts_buffer,"inds");
// TILEVEC_OPS::copy(cudaPol,tris,"inds",surf_tris_buffer,"inds");
// TILEVEC_OPS::copy(cudaPol,tris,"he_inds",surf_tris_buffer,"he_inds");
// reorder_topology(cudaPol,points,surf_tris_buffer);
// zs::Vector<int> nodal_colors{surf_verts_buffer.get_allocator(),surf_verts_buffer.size()};
dtiles_t gia_res{points.get_allocator(),{
{"ring_mask",1},
{"type_mask",1},
Expand Down Expand Up @@ -1515,10 +1499,11 @@ struct FleshDynamicStepping : INode {
// auto max_collision_pairs = tris.size() / 10;
dtiles_t etemp(eles.get_allocator(), {
// {"H", 12 * 12},
{"ActInv",3*3},\
{"ActInv",3*3},
{"dfiber",3},
// {"muscle_ID",1},
{"is_inverted",1}
{"is_inverted",1},
{"fiberStretch",1}
}, eles.size()
);

Expand Down Expand Up @@ -1619,6 +1604,12 @@ struct FleshDynamicStepping : INode {
if(!eles.hasProperty("Act"))
eles.append_channels(cudaPol,{{"Act",1}});


if(!eles.hasProperty("fiberStretch"))
eles.append_channels(cudaPol,{{"fiberStretch",1}});

TILEVEC_OPS::fill(cudaPol,eles,"fiberStretch",1.f);

if(!eles.hasProperty("fiber"))
fmt::print(fg(fmt::color::red),"the quadrature has no \"fiber\"\n");
if(!verts.hasProperty(muscle_id_tag))
Expand Down Expand Up @@ -1691,13 +1682,17 @@ struct FleshDynamicStepping : INode {
verts.template pack<3>("x",inds[3]),
eles.template pack<3,3>("IB",ei));
auto dfiber = F * fiber;
auto dfiberN = dfiber.norm();
auto fiberN = fiber.norm();
dfiber = dfiber / dfiber.norm();
etemp.tuple(dim_c<3>,"dfiber",ei) = dfiber;
eles("fiberStretch",ei) = dfiberN / fiberN;
}
}else{
fiber = zs::vec<T,3>(1.0,0.0,0.0);
act = vec3{1,1,1};
eles("Act",ei) = (T)0.0;

}
if(fabs(fiber.norm() - 1.0) > 0.1) {
printf("invalid fiber[%d] detected : %f %f %f\n",(int)ei,
Expand Down
Loading

0 comments on commit f092388

Please sign in to comment.