Skip to content

Commit

Permalink
fix bugs and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
littlemine committed Sep 25, 2023
1 parent 1444d0b commit a0570ff
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion projects/CuLagrange/fem/FleshDynamicStepping.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2315,7 +2315,7 @@ struct FleshDynamicStepping : INode {
auto inds = gh_buffer.pack(dim_c<4>,"inds",ei).reinterpret_bits(int_c);
for(int i = 0;i != 4;++i)
if(inds[i] < 0 || inds[i] >= vsize)
printf("negative sttemp inds : %d %d %d\n",inds[0],inds[1],inds[2],inds[3]);
printf("negative sttemp inds : %d %d %d, %d\n",inds[0],inds[1],inds[2],inds[3]);
auto H = gh_buffer.pack(dim_c<12,12>,"H",ei);
update_hessian(spmat,inds,H,true);
});
Expand Down
28 changes: 16 additions & 12 deletions projects/CuLagrange/fem/collision_energy/evaluate_collision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@ void calc_continous_self_PT_collision_impulse(Pol& pol,
else
triCCDBvh.build(pol,bvs);

auto execTag = wrapv<space>{};
pol(zs::range(verts.size()),[
invMass = proxy<space>({},invMass),
xtag = xtag,
Expand All @@ -1309,7 +1310,7 @@ void calc_continous_self_PT_collision_impulse(Pol& pol,
impulse_buffer = proxy<space>(impulse_buffer),
impulse_count = proxy<space>(impulse_count),
eps = eps,
exec_tag = wrapv<space>{},
execTag,
bvh = proxy<space>(triCCDBvh)] ZS_LAMBDA(int vi) mutable {
auto p = verts.pack(dim_c<3>,xtag,vi);
auto v = verts.pack(dim_c<3>,vtag,vi);
Expand Down Expand Up @@ -1392,9 +1393,9 @@ void calc_continous_self_PT_collision_impulse(Pol& pol,

for(int i = 0;i != 4;++i) {
auto beta = (bary[i] * invMass("minv",inds[i])) / cm;
atomic_add(exec_tag,&impulse_count[inds[i]],1);
atomic_add(execTag,&impulse_count[inds[i]],1);
for(int d = 0;d != 3;++d)
atomic_add(exec_tag,&impulse_buffer[inds[i]][d],impulse[d] * beta);
atomic_add(execTag,&impulse_buffer[inds[i]][d],impulse[d] * beta);
}
};
bvh.iter_neighbors(bv,do_close_proximity_detection);
Expand Down Expand Up @@ -1435,6 +1436,7 @@ void calc_continous_self_EE_collision_impulse(Pol& pol,
else
edgeCCDBvh.build(pol,edgeBvs);

auto execTag = wrapv<space>{};
pol(zs::range(edges.size()),[
xtag = xtag,
vtag = vtag,
Expand All @@ -1445,7 +1447,7 @@ void calc_continous_self_EE_collision_impulse(Pol& pol,
impulse_count = proxy<space>(impulse_count),
// thickness = thickness,
eps = eps,
exec_tag = wrapv<space>{},
execTag,
edgeBvs = proxy<space>(edgeBvs),
bvh = proxy<space>(edgeCCDBvh)] ZS_LAMBDA(int ei) mutable {
auto ea = edges.pack(dim_c<2>,"inds",ei,int_c);
Expand Down Expand Up @@ -1541,9 +1543,9 @@ void calc_continous_self_EE_collision_impulse(Pol& pol,
if(!compute_continous_EE_collision_impulse(ps,vs,minvs,imps))
return;
for(int i = 0;i != 4;++i) {
atomic_add(exec_tag,&impulse_count[inds[i]],1);
atomic_add(execTag,&impulse_count[inds[i]],1);
for(int d = 0;d != 3;++d)
atomic_add(exec_tag,&impulse_buffer[inds[i]][d],imps[i][d]);
atomic_add(execTag,&impulse_buffer[inds[i]][d],imps[i][d]);
}
#endif
};
Expand Down Expand Up @@ -1572,15 +1574,17 @@ void apply_impulse(Pol& pol,
zs::Vector<int> impulse_count{verts.get_allocator(),verts.size()};
pol(zs::range(impulse_count),[] ZS_LAMBDA(auto& c) mutable {c = 0;});

auto execTag = wrapv<space>{};
pol(zs::range(imminent_collision_buffer.size()),[
verts = proxy<space>({},verts),
vtag = zs::SmallString(vtag),
imminent_collision_buffer = proxy<space>({},imminent_collision_buffer),
exec_tag = wrapv<space>{},
execTag,
eps = eps,
restitution_rate = imminent_restitution_rate,
impulse_count = proxy<space>(impulse_count),
impulse_buffer = proxy<space>(impulse_buffer)] ZS_LAMBDA(auto ci) mutable {
impulse_buffer = proxy<space>(impulse_buffer)
] ZS_LAMBDA(auto ci) mutable {
auto inds = imminent_collision_buffer.pack(dim_c<4>,"inds",ci,int_c);
auto bary = imminent_collision_buffer.pack(dim_c<4>,"bary",ci);
auto impulse = imminent_collision_buffer.pack(dim_c<3>,"impulse",ci);
Expand All @@ -1594,9 +1598,9 @@ void apply_impulse(Pol& pol,

for(int i = 0;i != 4;++i) {
auto beta = verts("minv",inds[i]) * bary[i] / cminv;
atomic_add(exec_tag,&impulse_count[inds[i]],1);
atomic_add(execTag,&impulse_count[inds[i]],1);
for(int d = 0;d != 3;++d)
atomic_add(exec_tag,&impulse_buffer[inds[i]][d],impulse[d] * beta);
atomic_add(execTag,&impulse_buffer[inds[i]][d],impulse[d] * beta);
}

});
Expand All @@ -1607,14 +1611,14 @@ void apply_impulse(Pol& pol,
impulse_count = proxy<space>(impulse_count),
relaxation_rate = imminent_relaxation_rate,
eps = eps,
exec_tag = wrapv<space>{}] ZS_LAMBDA(int vi) mutable {
execTag] ZS_LAMBDA(int vi) mutable {
if(impulse_buffer[vi].norm() < eps || impulse_count[vi] == 0)
return;
auto impulse = relaxation_rate * impulse_buffer[vi] / (T)impulse_count[vi];
// auto dp = impulse * verts("minv",vi);

for(int i = 0;i != 3;++i)
atomic_add(exec_tag,&verts(vtag,i,vi),impulse[i]);
atomic_add(execTag,&verts(vtag,i,vi),impulse[i]);
});
}

Expand Down
2 changes: 1 addition & 1 deletion projects/CuLagrange/geometry/Topology.cu
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ struct VisualTetrahedraHalfFacet : zeno::INode {
auto opposite_hf_idx = zs::reinterpret_bits<int>(halfFacet("opposite_hf",hf_idx));
if(opposite_hf_idx >= 0) {
if(opposite_hf_idx >= halfFacet.size()) {
printf("opposite_hf_idx = %d exceeding size of halfFacet : %d\n",opposite_hf_idx,halfFacet.size());
printf("opposite_hf_idx = %d exceeding size of halfFacet : %d\n", (int)opposite_hf_idx, (int)halfFacet.size());
return;
}
auto nti = zs::reinterpret_bits<int>(halfFacet("to_tet",opposite_hf_idx));
Expand Down
6 changes: 3 additions & 3 deletions projects/CuLagrange/geometry/kernel/geo_math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ namespace zeno { namespace LSL_GEO {
return (costheta / sintheta);
}

template<typename DREAL,typename VecT, zs::enable_if_all<VecT::dim == 1, (VecT::extent <= 3), (VecT::extent > 1)> = 0,typename REAL = VecT::value_type>
template<typename DREAL,typename VecT, zs::enable_if_all<VecT::dim == 1, (VecT::extent <= 3), (VecT::extent > 1)> = 0,typename REAL = typename VecT::value_type>
constexpr auto cotTheta(const zs::VecInterface<VecT>& e0,const zs::VecInterface<VecT>& e1){
auto de0 = e0.cast<DREAL>();
auto de1 = e1.cast<DREAL>();
auto de0 = e0.template cast<DREAL>();
auto de1 = e1.template cast<DREAL>();
auto costheta = de0.dot(de1);
auto sintheta = de0.cross(de1).norm();
return (REAL)(costheta / sintheta);
Expand Down
5 changes: 3 additions & 2 deletions projects/CuLagrange/geometry/kernel/intersection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,8 @@ int do_global_self_intersection_analysis_on_surface_mesh_info(Pol& pol,
r = LSL_GEO::tri_ray_intersect(v1[j],e1s[j],v0[0],v0[1],v0[2]);
if(r < (T)(1.0)) {
e1_indices[nm_e1_its] = j;
e1_its[nm_e1_its] = v1[i] + e1s[j] * r;
/// @note both these should be 'j'
e1_its[nm_e1_its] = v1[j] + e1s[j] * r;
++nm_e1_its;
}
}
Expand Down Expand Up @@ -3462,7 +3463,7 @@ int do_global_intersection_analysis_with_connected_manifolds(Pol& pol,
auto hi = key[0];
auto no = halfedges_tab.query(hi);
if(no >= closestTriID.size()) {
printf("closestTriID overflow : %d %d\n",no,closestTriID.size());
printf("closestTriID overflow : %d %d\n",(int)no, (int)closestTriID.size());
return;
}
auto cti = closestTriID[no];
Expand Down
2 changes: 1 addition & 1 deletion projects/CuLagrange/geometry/kernel/topology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ namespace zeno {
constexpr auto CODIM = VecTi::extent;
constexpr auto NM_EDGES = (CODIM - 1) * (CODIM) / 2;

zs::vec<Ti,2> out_edges[NM_EDGES] = {};
zs::vec<zs::vec<Ti,2>, NM_EDGES> out_edges{};
int nm_out_edges = 0;
for(int i = 0;i != CODIM;++i)
for(int j = i + 1;j != CODIM;++j)
Expand Down
34 changes: 17 additions & 17 deletions projects/CuLagrange/pbd/constraint_function_kernel/constraint.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace zeno { namespace CONSTRAINT {
return true;
}

template<typename VECTOR3d,typename SCALER = VECTOR3d::value_type>
template<typename VECTOR3d,typename SCALER = typename VECTOR3d::value_type>
constexpr bool init_DihedralBendingConstraint(
const VECTOR3d& p0,
const VECTOR3d& p1,
Expand Down Expand Up @@ -229,7 +229,7 @@ namespace zeno { namespace CONSTRAINT {
return true;
}

template<typename VECTOR3d,typename SCALER = VECTOR3d::value_type>
template<typename VECTOR3d,typename SCALER = typename VECTOR3d::value_type>
constexpr bool solve_DihedralConstraint(
const VECTOR3d& p0, const SCALER& invMass0,
const VECTOR3d& p1, const SCALER& invMass1,
Expand Down Expand Up @@ -310,24 +310,24 @@ namespace zeno { namespace CONSTRAINT {
const VECTOR3d x[4] = { p2, p3, p0, p1 };
// Q = MATRIX4d::uniform(0);

// const auto e0 = x[1].cast<double>() - x[0].cast<double>();
// const auto e1 = x[2].cast<double>() - x[0].cast<double>();
// const auto e2 = x[3].cast<double>() - x[0].cast<double>();
// const auto e3 = x[2].cast<double>() - x[1].cast<double>();
// const auto e4 = x[3].cast<double>() - x[1].cast<double>();
// const auto e0 = x[1].template cast<double>() - x[0].template cast<double>();
// const auto e1 = x[2].template cast<double>() - x[0].template cast<double>();
// const auto e2 = x[3].template cast<double>() - x[0].template cast<double>();
// const auto e3 = x[2].template cast<double>() - x[1].template cast<double>();
// const auto e4 = x[3].template cast<double>() - x[1].template cast<double>();

const auto e0 = x[1].cast<double>() - x[0].cast<double>();
const auto e1 = x[2].cast<double>() - x[0].cast<double>();
const auto e2 = x[3].cast<double>() - x[0].cast<double>();
const auto e3 = x[2].cast<double>() - x[1].cast<double>();
const auto e4 = x[3].cast<double>() - x[1].cast<double>();
const auto e0 = x[1].template cast<double>() - x[0].template cast<double>();
const auto e1 = x[2].template cast<double>() - x[0].template cast<double>();
const auto e2 = x[3].template cast<double>() - x[0].template cast<double>();
const auto e3 = x[2].template cast<double>() - x[1].template cast<double>();
const auto e4 = x[3].template cast<double>() - x[1].template cast<double>();


// auto e0 = e0_.cast<double>();
// auto e1 = e1_.cast<double>();
// auto e2 = e2_.cast<double>();
// auto e3 = e3_.cast<double>();
// auto e4 = e4_.cast<double>();
// auto e0 = e0_.template cast<double>();
// auto e1 = e1_.template cast<double>();
// auto e2 = e2_.template cast<double>();
// auto e3 = e3_.template cast<double>();
// auto e4 = e4_.template cast<double>();

// printf("init isometric bending energy : %f %f %f %f\n",
// (float)p0.norm(),
Expand Down

0 comments on commit a0570ff

Please sign in to comment.