@@ -81,6 +81,7 @@ void neo_hookean(RXMeshStatic& rx, T dx)
8181 volume.reset (0 , DEVICE);
8282
8383 auto is_dbc_satisfied = *rx.add_vertex_attribute <int >(" DBCSatisfied" , 1 );
84+ is_dbc_satisfied.reset (0 , DEVICE);
8485
8586 VertexReduceHandle<int > rh (is_dbc_satisfied);
8687
@@ -107,12 +108,12 @@ void neo_hookean(RXMeshStatic& rx, T dx)
107108
108109 NetwtonSolver newton_solver (problem, &solver);
109110
110- auto x = *rx.get_input_vertex_coordinates ();
111+ auto & x = *problem.objective ;
112+ x.copy_from (*rx.get_input_vertex_coordinates (), DEVICE, DEVICE);
111113
112- auto x_n = *rx.add_vertex_attribute_like (" x_n" , x);
114+ auto x_n = *rx.add_vertex_attribute_like (" x_n" , x);
115+ auto x_tilde = *rx.add_vertex_attribute_like (" x_tilde" , x);
113116
114- auto & x_tilde = *problem.objective ;
115- x_tilde.copy_from (x, DEVICE, DEVICE);
116117
117118 // Initializations
118119 init_volume_inverse_b (rx, x, volume, inv_b);
@@ -130,7 +131,7 @@ void neo_hookean(RXMeshStatic& rx, T dx)
130131
131132
132133 typename ProblemT::DenseMatT alpha (
133- rx, std::max (rx.get_num_vertices (), rx.get_num_faces ()), DEVICE);
134+ rx, std::max (rx.get_num_vertices (), rx.get_num_faces ()), 1 , DEVICE);
134135
135136#if USE_POLYSCOPE
136137 // add BC to polyscope
@@ -142,10 +143,10 @@ void neo_hookean(RXMeshStatic& rx, T dx)
142143#endif
143144
144145 // add inertial energy term OK
145- inertial_energy (problem, x, is_dbc, mass);
146+ inertial_energy (problem, x, x_tilde, is_dbc, mass);
146147
147148 // add spring energy term
148- spring_energy (problem, dbc_target, is_dbc, mass, dbc_stiff);
149+ spring_energy (problem, x, dbc_target, is_dbc, mass, dbc_stiff);
149150
150151
151152 // add gravity energy OK
@@ -154,7 +155,6 @@ void neo_hookean(RXMeshStatic& rx, T dx)
154155 // add barrier energy
155156 floor_barrier_energy (problem,
156157 contact_area,
157- v_dbc[0 ],
158158 x,
159159 time_step,
160160 is_dbc,
@@ -206,27 +206,28 @@ void neo_hookean(RXMeshStatic& rx, T dx)
206206 x_n.copy_from (x, DEVICE, DEVICE);
207207
208208 // compute mu * lambda for each node using x_n
209- compute_mu_lambda (rx,
209+ /* compute_mu_lambda(rx,
210210 fricition_coef,
211211 dhat,
212212 kappa,
213213 ground_n,
214214 ground_o,
215215 x,
216216 contact_area,
217- mu_lambda);
217+ mu_lambda);*/
218218
219219 // target position for each DBC in the current time step
220220 update_dbc (
221221 rx, is_dbc, x, v_dbc_vel, v_dbc_limit, time_step, dbc_target);
222222
223223 // evaluate energy
224- add_contact (rx, problem.vv_pairs , v_dbc[0 ], x_tilde, dhat);
224+ add_contact (rx, problem.vv_pairs , v_dbc[0 ], is_dbc, x, dhat);
225+ problem.update_hessian ();
225226 problem.eval_terms ();
226227
227228 // DBC satisfied
228229 check_dbc_satisfied (
229- rx, is_dbc_satisfied, x_tilde , is_dbc, dbc_target, time_step, tol);
230+ rx, is_dbc_satisfied, x , is_dbc, dbc_target, time_step, tol);
230231
231232 // how many DBC are satisfied
232233 int num_satisfied = rh.reduce (is_dbc_satisfied, cub::Sum (), 0 );
@@ -239,7 +240,6 @@ void neo_hookean(RXMeshStatic& rx, T dx)
239240 // get newton direction
240241 newton_solver.compute_direction ();
241242
242-
243243 // residual is abs_max(newton_dir)/ h
244244 T residual = newton_solver.dir .abs_max () / time_step;
245245
@@ -249,7 +249,6 @@ void neo_hookean(RXMeshStatic& rx, T dx)
249249 int iter = 0 ;
250250 while (residual > tol || num_satisfied != num_dbc_vertices) {
251251
252-
253252 if (residual <= tol && num_satisfied != num_dbc_vertices) {
254253 dbc_stiff.multiply (T (2 ));
255254 }
@@ -271,17 +270,16 @@ void neo_hookean(RXMeshStatic& rx, T dx)
271270 newton_solver.line_search (line_search_init_step, 0.5 );
272271
273272 // evaluate energy
274- add_contact (rx, problem.vv_pairs , v_dbc[0 ], x_tilde, dhat);
273+ add_contact (rx, problem.vv_pairs , v_dbc[0 ], is_dbc, x, dhat);
274+ problem.update_hessian ();
275275 problem.eval_terms ();
276276
277+ // T f = problem.get_current_loss();
278+ // RXMESH_INFO("Subsetp, Energy: {}", f);
279+
277280 // DBC satisfied
278- check_dbc_satisfied (rx,
279- is_dbc_satisfied,
280- x_tilde,
281- is_dbc,
282- dbc_target,
283- time_step,
284- tol);
281+ check_dbc_satisfied (
282+ rx, is_dbc_satisfied, x, is_dbc, dbc_target, time_step, tol);
285283
286284 // how many DBC are satisfied
287285 num_satisfied = rh.reduce (is_dbc_satisfied, cub::Sum (), 0 );
@@ -301,13 +299,12 @@ void neo_hookean(RXMeshStatic& rx, T dx)
301299 // update velocity
302300 rx.for_each_vertex (
303301 DEVICE,
304- [x, x_tilde , velocity, inv_time_step = 1.0 / time_step] __device__ (
302+ [x, x_n , velocity, inv_time_step = 1.0 / time_step] __device__ (
305303 VertexHandle vh) mutable {
306304 for (int i = 0 ; i < 3 ; ++i) {
307- velocity (vh, i) =
308- inv_time_step * (x_tilde (vh, i) - x (vh, i));
305+ velocity (vh, i) = inv_time_step * (x (vh, i) - x_n (vh, i));
309306
310- x (vh, i) = x_tilde (vh, i);
307+ // x(vh, i) = x_tilde(vh, i);
311308 }
312309 });
313310
@@ -316,7 +313,7 @@ void neo_hookean(RXMeshStatic& rx, T dx)
316313 };
317314
318315#if USE_POLYSCOPE
319- draw (rx, x_tilde , velocity, step_forward, steps);
316+ draw (rx, x , velocity, step_forward, steps);
320317#else
321318 while (steps < 5 ) {
322319 step_forward ();
@@ -344,7 +341,7 @@ void neo_hookean(RXMeshStatic& rx, T dx)
344341
345342int main (int argc, char ** argv)
346343{
347- Log::init ( spdlog::level::info);
344+ rx_init ( 0 , spdlog::level::info);
348345
349346
350347 std::vector<std::vector<T>> verts;
0 commit comments