Skip to content

Commit 0fa3af5

Browse files
committed
bug fix
1 parent fc26f30 commit 0fa3af5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+80
-1391
lines changed

simulators/1_mass_spring/include/SparseMatrix.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

simulators/1_mass_spring/include/uti.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22
#include <Eigen/Dense>
3-
#include "SparseMatrix.h"
43
#include <muda/cub/device/device_reduce.h>
54
#include <muda/container.h>
65
#include <muda/muda.h>

simulators/1_mass_spring/src/MassSpringEnergy.cu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const DeviceTripletMatrix<T, 1> &MassSpringEnergy<T, dim>::hess()
137137
auto device_hess_row_idx = device_hess.row_indices();
138138
auto device_hess_col_idx = device_hess.col_indices();
139139
auto device_hess_val = device_hess.values();
140+
device_hess_val.fill(0);
140141
ParallelFor(256).apply(N, [device_x = device_x.cviewer(), device_e = device_e.cviewer(), device_l2 = device_l2.cviewer(), device_k = device_k.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__(int i) mutable
141142
{
142143
int idx[2] = {device_e(2 * i), device_e(2 * i + 1)}; // First node index
@@ -162,7 +163,7 @@ const DeviceTripletMatrix<T, 1> &MassSpringEnergy<T, dim>::hess()
162163
int indStart = i * 4*dim*dim + (ni * 2 + nj) * dim*dim;
163164
for (int d1 = 0; d1 < dim; d1++)
164165
for (int d2 = 0; d2 < dim; d2++){
165-
device_hess_row_idx(indStart + d1 * dim + d2)= idx[ni]*dim + d1;
166+
device_hess_row_idx(indStart + d1 * dim + d2)= idx[ni] * dim + d1;
166167
device_hess_col_idx(indStart + d1 * dim + d2)= idx[nj] * dim + d2;
167168
device_hess_val(indStart + d1 * dim + d2) = H_local(ni * dim + d1, nj * dim + d2);
168169
}

simulators/1_mass_spring/src/SparseMatrix.cu

Lines changed: 0 additions & 144 deletions
This file was deleted.

simulators/1_mass_spring/src/device_uti.cu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ void __device__ make_PSD(const Eigen::Matrix<T, Size, Size> &hess, Eigen::Matrix
3131
Eigen::Matrix<T, Size, Size> lamDiag;
3232
lamDiag.setZero();
3333
for (int i = 0; i < Size; i++)
34-
lamDiag(i, i) = lam(i);
34+
if (lam(i) > 0)
35+
lamDiag(i, i) = lam(i);
3536

3637
Eigen::Matrix<T, Size, Size> VT = V.transpose();
3738

simulators/1_mass_spring/src/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
int main()
44
{
5-
float rho = 1000, k = 1e5, initial_stretch = 1.4, n_seg = 10, h = 0.004, side_len = 1, tol = 0.01;
6-
// printf("Running mass-spring simulator with parameters: rho = %f, k = %f, initial_stretch = %f, n_seg = %d, h = %f, side_len = %f, tol = %f\n", rho, k, initial_stretch, n_seg, h, side_len, tol);
7-
MassSpringSimulator<float, 2> simulator(rho, side_len, initial_stretch, k, h, tol, n_seg);
5+
double rho = 1000, k = 1e5, initial_stretch = 1.4, n_seg = 1, h = 0.004, side_len = 1, tol = 0.01;
6+
MassSpringSimulator<double, 2> simulator(rho, side_len, initial_stretch, k, h, tol, n_seg);
87
simulator.run();
98
}

simulators/1_mass_spring/src/simulator.cu

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void MassSpringSimulator<T, dim>::run()
7979
assert(dim == 2);
8080
bool running = true;
8181
auto &window = pimpl_->window;
82+
int time_step = 0;
8283
while (running)
8384
{
8485
sf::Event event;
@@ -89,7 +90,7 @@ void MassSpringSimulator<T, dim>::run()
8990
}
9091

9192
pimpl_->draw(); // Draw the current state
92-
93+
std::cout << "Time step " << time_step++ << "\n";
9394
// Update the simulation state
9495
pimpl_->step_forward();
9596

@@ -113,6 +114,7 @@ void MassSpringSimulator<T, dim>::Impl::step_forward()
113114
// std::cout << "Initial residual " << residual << "\n";
114115
while (residual > tol)
115116
{
117+
std::cout << "Iteration " << iter << " residual " << residual << "E_last" << E_last << "\n";
116118
// Line search
117119
T alpha = 1;
118120
DeviceBuffer<T> x0 = x;
@@ -122,9 +124,8 @@ void MassSpringSimulator<T, dim>::Impl::step_forward()
122124
alpha /= 2;
123125
update_x(add_vector<T>(x0, p, 1.0, alpha));
124126
}
125-
// std::cout << "step size = " << alpha << "\n";
127+
std::cout << "step size = " << alpha << "\n";
126128
E_last = IP_val();
127-
// std::cout << "Iteration " << iter << " residual " << residual << "E_last" << E_last << "\n";
128129
p = search_direction();
129130
residual = max_vector(p) / h;
130131
iter += 1;

simulators/2_dirichlet/include/SparseMatrix.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

simulators/2_dirichlet/include/uti.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22
#include <Eigen/Dense>
3-
#include "SparseMatrix.h"
43
#include <muda/cub/device/device_reduce.h>
54
#include <muda/container.h>
65
#include <muda/muda.h>

0 commit comments

Comments
 (0)