Skip to content

Commit 83f8d07

Browse files
committed
8_self_friction
1 parent 4ac39a9 commit 83f8d07

3 files changed

Lines changed: 9 additions & 16 deletions

File tree

simulators/7_self_contact/src/BarrierEnergy.cu

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ const DeviceTripletMatrix<T, 1> &BarrierEnergy<T, dim>::hess()
213213
int Nbp = device_bp.size(), Nbe = device_be.size() / 2;
214214
int Npe = Nbp * Nbe;
215215
int N = device_x.size() / dim;
216+
device_hess_val.fill(0);
216217
ParallelFor(256).apply(N, [device_x = device_x.cviewer(), device_contact_area = device_contact_area.cviewer(), device_hess_val = device_hess_val.viewer(), device_hess_row_idx = device_hess_row_idx.viewer(), device_hess_col_idx = device_hess_col_idx.viewer(), N, device_n = device_n.cviewer(), device_o = device_o.cviewer()] __device__(int i) mutable
217218
{
218219
T d = 0;
@@ -230,8 +231,6 @@ const DeviceTripletMatrix<T, 1> &BarrierEnergy<T, dim>::hess()
230231
device_hess_col_idx(idx) = i * dim + k;
231232
if (d < dhat)
232233
device_hess_val(idx) = device_contact_area(i) * dhat * kappa / (2 * d * d * dhat) * (d + dhat) * device_n(j) * device_n(k);
233-
else
234-
device_hess_val(idx) = 0;
235234
}
236235
} })
237236
.wait();
@@ -257,8 +256,6 @@ const DeviceTripletMatrix<T, 1> &BarrierEnergy<T, dim>::hess()
257256
device_hess_val(idx) = device_contact_area(i) * dhat * kappa / (2 * d * d * dhat) * (d + dhat) * device_n_ceil(j) * device_n_ceil(k);
258257
else
259258
device_hess_val(idx) = -device_contact_area(i) * dhat * kappa / (2 * d * d * dhat) * (d + dhat) * device_n_ceil(j) * device_n_ceil(k);
260-
else
261-
device_hess_val(idx) = 0;
262259
}
263260
} })
264261
.wait();
@@ -276,7 +273,6 @@ const DeviceTripletMatrix<T, 1> &BarrierEnergy<T, dim>::hess()
276273
int idx = N * dim * dim + (N - 1) * dim * dim * 4 + i * dim * dim*9 + nI * dim * dim*3 + nJ * dim * dim + j * dim + k;
277274
device_hess_row_idx(idx) = index[nI] * dim + j;
278275
device_hess_col_idx(idx) = index[nJ] * dim + k;
279-
device_hess_val(idx) = 0;
280276
}
281277
}
282278
if (xI != eI0 && xI != eI1){
@@ -398,17 +394,17 @@ template class BarrierEnergy<double, 2>;
398394
template class BarrierEnergy<double, 3>;
399395

400396
template <typename T, int dim>
401-
void BarrierEnergy<T, dim>::compute_mu_lambda(T mu, DeviceBuffer<T>& device_mu_lambda)
397+
void BarrierEnergy<T, dim>::compute_mu_lambda(T mu, DeviceBuffer<T> &device_mu_lambda)
402398
{
403-
auto& device_x = pimpl_->device_x;
404-
auto& device_n = pimpl_->device_n;
405-
auto& device_o = pimpl_->device_o;
406-
auto& device_contact_area = pimpl_->device_contact_area;
399+
auto &device_x = pimpl_->device_x;
400+
auto &device_n = pimpl_->device_n;
401+
auto &device_o = pimpl_->device_o;
402+
auto &device_contact_area = pimpl_->device_contact_area;
407403
int N = device_x.size() / dim;
408404
device_mu_lambda.fill(0);
409405
ParallelFor(256)
410406
.apply(N, [device_x = device_x.cviewer(), device_mu_lambda = device_mu_lambda.viewer(), mu, device_n = device_n.cviewer(), device_o = device_o.cviewer(), device_contact_area = device_contact_area.cviewer()] __device__(int i) mutable
411-
{
407+
{
412408
T d = 0;
413409
for (int j = 0; j < dim; j++)
414410
{
@@ -418,7 +414,6 @@ void BarrierEnergy<T, dim>::compute_mu_lambda(T mu, DeviceBuffer<T>& device_mu_l
418414
{
419415
T s = d / dhat;
420416
device_mu_lambda(i) = mu * -device_contact_area(i) * dhat * (kappa / 2 * (log(s) / dhat + (s - 1) / d));
421-
}
422-
})
417+
} })
423418
.wait();
424419
}

simulators/7_self_contact/src/FrictionEnergy.cu

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ void FrictionEnergy<T, dim>::update_v(const DeviceBuffer<T> &v)
5555
pimpl_->device_v.view().copy_from(v);
5656
}
5757
template <typename T, int dim>
58-
DeviceBuffer<T>& FrictionEnergy<T, dim>::get_mu_lambda()
58+
DeviceBuffer<T> &FrictionEnergy<T, dim>::get_mu_lambda()
5959
{
6060
return pimpl_->device_mu_lambda;
6161
}
6262

63-
6463
template <typename T, int dim>
6564
T __device__ FrictionEnergy<T, dim>::f0(T vbarnorm, T Epsv, T hhat)
6665
{

simulators/8_self_friction/src/FrictionEnergy.cu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ const DeviceTripletMatrix<T, 1> &FrictionEnergy<T, dim>::hess()
248248
auto device_hess_col_idx = device_hess.col_indices();
249249
auto device_hess_val = device_hess.values();
250250
int N = device_v.size() / dim;
251-
device_hess_val.fill(0);
252251
ParallelFor(256).apply(N, [device_v = device_v.cviewer(), device_mu_lambda = device_mu_lambda.cviewer(), device_hess_val = device_hess_val.viewer(), device_hess_row_idx = device_hess_row_idx.viewer(), device_hess_col_idx = device_hess_col_idx.viewer(), hhat, n, N, this] __device__(int i) mutable
253252
{
254253
Eigen::Matrix<T, dim, dim> T_mat = Eigen::Matrix<T, dim, dim>::Identity() - n * n.transpose();

0 commit comments

Comments
 (0)