@@ -17,7 +17,7 @@ struct MovDirichletSimulator<T, dim>::Impl
1717 T h, rho, side_len, initial_stretch, m, tol, mu, DBC_stiff;
1818 int resolution = 900 , scale = 200 , offset = resolution / 2 , radius = 5 ;
1919 std::vector<T> x, x_tilde, v, k, l2, DBC_limit, DBC_v, DBC_target;
20- std::vector<int > e, DBC, DBC_satisfied;
20+ std::vector<int > e, DBC, DBC_satisfied, is_DBC ;
2121 DeviceBuffer<int > device_DBC;
2222 DeviceBuffer<T> device_contact_area;
2323 sf::RenderWindow window;
@@ -67,10 +67,13 @@ MovDirichletSimulator<T, dim>::Impl::Impl(T rho, T side_len, T initial_stretch,
6767 DBC_limit.push_back (0 );
6868 DBC_limit.push_back (-0.6 );
6969 DBC_v.push_back (0 );
70- DBC_v.push_back (-1 );
70+ DBC_v.push_back (-0.5 );
7171 DBC_stiff = 10 ;
7272 x.push_back (0 );
7373 x.push_back (side_len * 0.6 );
74+ DBC_satisfied.resize (x.size () / dim);
75+ is_DBC.resize (x.size () / dim, 0 );
76+ is_DBC[(n_seg + 1 ) * (n_seg + 1 )] = 1 ;
7477 std::vector<T> contact_area (x.size () / dim, side_len / n_seg);
7578 std::vector<T> ground_n (dim);
7679 ground_n[0 ] = 0 , ground_n[1 ] = 1 ;
@@ -106,7 +109,7 @@ MovDirichletSimulator<T, dim>::Impl::Impl(T rho, T side_len, T initial_stretch,
106109 springenergy = SpringEnergy<T, dim>(x, std::vector<T>(N, m), DBC, DBC_stiff);
107110 DeviceBuffer<T> x_device (x);
108111 update_x (x_device);
109- device_DBC = DeviceBuffer<int >(DBC );
112+ device_DBC = DeviceBuffer<int >(is_DBC );
110113 device_contact_area = DeviceBuffer<T>(contact_area);
111114}
112115template <typename T, int dim>
@@ -194,6 +197,7 @@ void MovDirichletSimulator<T, dim>::Impl::update_x(const DeviceBuffer<T> &new_x)
194197 massspringenergy.update_x (new_x);
195198 gravityenergy.update_x (new_x);
196199 barrierenergy.update_x (new_x);
200+ springenergy.update_x (new_x);
197201 new_x.copy_to (x);
198202}
199203template <typename T, int dim>
@@ -276,17 +280,13 @@ T MovDirichletSimulator<T, dim>::Impl::IP_val()
276280template <typename T, int dim>
277281DeviceBuffer<T> MovDirichletSimulator<T, dim>::Impl::IP_grad()
278282{
279- return add_vector<T>(add_vector<T>(add_vector<T>(add_vector<T>(add_vector<T>(inertialenergy.grad (),
280- massspringenergy.grad (), 1.0 , h * h),
281- gravityenergy.grad (), 1.0 , h * h),
282- barrierenergy.grad (), 1.0 , h * h),
283- frictionenergy.grad (), 1.0 , h * h),
284- springenergy.grad (), 1.0 , 1.0 );
285- // return add_vector<T>(add_vector<T>(add_vector<T>(add_vector<T>(inertialenergy.grad(),
286- // massspringenergy.grad(), 1.0, h * h),
287- // gravityenergy.grad(), 1.0, h * h),
288- // barrierenergy.grad(), 1.0, h * h),
289- // frictionenergy.grad(), 1.0, h * h);
283+ return add_vector<T>(
284+ add_vector<T>(add_vector<T>(add_vector<T>(add_vector<T>(inertialenergy.grad (),
285+ massspringenergy.grad (), 1.0 , h * h),
286+ gravityenergy.grad (), 1.0 , h * h),
287+ barrierenergy.grad (), 1.0 , h * h),
288+ frictionenergy.grad (), 1.0 , h * h),
289+ springenergy.grad (), 1.0 , 1.0 );
290290}
291291
292292template <typename T, int dim>
@@ -311,14 +311,19 @@ DeviceBuffer<T> MovDirichletSimulator<T, dim>::Impl::search_direction()
311311 DeviceBuffer<T> grad = IP_grad ();
312312 DeviceTripletMatrix<T, 1 > hess = IP_hess ();
313313 // check whether each DBC is satisfied
314- DBC_satisfied.resize (x.size () / dim, 0 );
314+ for (int i = 0 ; i < DBC_satisfied.size (); i++)
315+ {
316+ DBC_satisfied[i] = 0 ;
317+ }
318+
315319 for (int i = 0 ; i < DBC.size (); i++)
316320 {
317321 T diff = 0 ;
318322 for (int d = 0 ; d < dim; d++)
319323 {
320324 diff += (x[DBC[i] * dim + d] - DBC_target[i * dim + d]) * (x[DBC[i] * dim + d] - DBC_target[i * dim + d]);
321325 }
326+ diff = sqrt (diff);
322327 if (diff / h < tol)
323328 {
324329 DBC_satisfied[DBC[i]] = 1 ;
0 commit comments