@@ -344,37 +344,51 @@ namespace polyfem::solver
344344 {
345345 const bool use_adaptive_barrier_stiffness = !barrier_stiffness.is_number ();
346346
347- if (contact_params[" use_smooth_formulation" ])
348- {
349- if (collision_mesh.dim () == 2 )
350- contact_form = std::make_shared<SmoothContactForm<2 >>(
351- collision_mesh, contact_params, avg_mass,
352- use_adaptive_barrier_stiffness, is_time_dependent, enable_shape_derivatives, broad_phase,
353- ccd_tolerance * units.characteristic_length (), ccd_max_iterations);
354- else
355- contact_form = std::make_shared<SmoothContactForm<3 >>(
356- collision_mesh, contact_params, avg_mass,
357- use_adaptive_barrier_stiffness, is_time_dependent, enable_shape_derivatives, broad_phase,
358- ccd_tolerance * units.characteristic_length (), ccd_max_iterations);
359- }
360- else if (periodic_contact)
347+ if (periodic_contact)
361348 {
362349 periodic_contact_form = std::make_shared<PeriodicContactForm>(
363350 collision_mesh, tiled_to_single, dhat, avg_mass, use_area_weighting, use_improved_max_operator, use_physical_barrier,
364351 use_adaptive_barrier_stiffness, is_time_dependent, enable_shape_derivatives, broad_phase, ccd_tolerance,
365352 ccd_max_iterations);
353+
354+ if (use_adaptive_barrier_stiffness)
355+ {
356+ periodic_contact_form->set_barrier_stiffness (1 );
357+ // logger().debug("Using adaptive barrier stiffness");
358+ }
359+ else
360+ {
361+ assert (barrier_stiffness.is_number ());
362+ assert (barrier_stiffness.get <double >() > 0 );
363+ periodic_contact_form->set_barrier_stiffness (barrier_stiffness);
364+ // logger().debug("Using fixed barrier stiffness of {}", contact_form->barrier_stiffness());
365+ }
366+
367+ // periodic_contact_form is not pushed into forms since it takes different input vectors.
366368 }
367369 else
368370 {
369- contact_form = std::make_shared<BarrierContactForm>(
370- collision_mesh, dhat, avg_mass, use_area_weighting, use_improved_max_operator, use_physical_barrier,
371- use_adaptive_barrier_stiffness, is_time_dependent, enable_shape_derivatives, broad_phase, ccd_tolerance * units.characteristic_length (),
372- ccd_max_iterations);
373- }
374-
371+ if (contact_params[" use_smooth_formulation" ])
372+ {
373+ if (collision_mesh.dim () == 2 )
374+ contact_form = std::make_shared<SmoothContactForm<2 >>(
375+ collision_mesh, contact_params, avg_mass,
376+ use_adaptive_barrier_stiffness, is_time_dependent, enable_shape_derivatives, broad_phase,
377+ ccd_tolerance * units.characteristic_length (), ccd_max_iterations);
378+ else
379+ contact_form = std::make_shared<SmoothContactForm<3 >>(
380+ collision_mesh, contact_params, avg_mass,
381+ use_adaptive_barrier_stiffness, is_time_dependent, enable_shape_derivatives, broad_phase,
382+ ccd_tolerance * units.characteristic_length (), ccd_max_iterations);
383+ }
384+ else
385+ {
386+ contact_form = std::make_shared<BarrierContactForm>(
387+ collision_mesh, dhat, avg_mass, use_area_weighting, use_improved_max_operator, use_physical_barrier,
388+ use_adaptive_barrier_stiffness, is_time_dependent, enable_shape_derivatives, broad_phase, ccd_tolerance * units.characteristic_length (),
389+ ccd_max_iterations);
390+ }
375391
376- if (contact_form)
377- {
378392 if (use_adaptive_barrier_stiffness)
379393 {
380394 contact_form->set_barrier_stiffness (contact_params[" initial_barrier_stiffness" ]);
@@ -389,15 +403,15 @@ namespace polyfem::solver
389403 }
390404
391405 forms.push_back (contact_form);
406+ }
392407
393- if (friction_coefficient != 0 )
394- {
395- friction_form = std::make_shared<FrictionForm>(
396- collision_mesh, time_integrator, epsv, friction_coefficient,
397- broad_phase, *contact_form, friction_iterations);
398- friction_form->init_lagging (sol);
399- forms.push_back (friction_form);
400- }
408+ if (friction_coefficient != 0 )
409+ {
410+ friction_form = std::make_shared<FrictionForm>(
411+ collision_mesh, time_integrator, epsv, friction_coefficient,
412+ broad_phase, *contact_form, friction_iterations);
413+ friction_form->init_lagging (sol);
414+ forms.push_back (friction_form);
401415 }
402416
403417 if (adhesion_enabled)
0 commit comments