Skip to content

Commit e924def

Browse files
committed
fix failed tests
1 parent 0eb983e commit e924def

File tree

2 files changed

+50
-36
lines changed

2 files changed

+50
-36
lines changed

src/polyfem/solver/SolveData.cpp

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

tests/test_periodic.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ namespace
110110
double former_functional_val = problem.value(x - theta * dt);
111111

112112
double finite_difference = (next_functional_val - former_functional_val) / dt / 2;
113-
logger().trace("f(x) {.16} f(x-dt) {.16} f(x+dt) {.16}", functional_val, former_functional_val, next_functional_val);
114-
logger().trace("derivative: {.12}, fd: {.12}", derivative, finite_difference);
115-
logger().trace("relative error: {.12}", abs((finite_difference - derivative) / derivative));
113+
logger().trace("f(x) {:.16f} f(x-dt) {:.16f} f(x+dt) {:.16f}", functional_val, former_functional_val, next_functional_val);
114+
logger().trace("derivative: {:.12f}, fd: {:.12f}", derivative, finite_difference);
115+
logger().trace("relative error: {:.12f}", abs((finite_difference - derivative) / derivative));
116116
REQUIRE(derivative == Catch::Approx(finite_difference).epsilon(tol));
117117
}
118118

@@ -134,9 +134,9 @@ namespace
134134
double former_functional_val = problem.value(x - theta * dt);
135135

136136
double finite_difference = (next_functional_val - former_functional_val) / dt / 2;
137-
logger().trace("f(x) {.16} f(x-dt) {.16} f(x+dt) {.16}", functional_val, former_functional_val, next_functional_val);
138-
logger().trace("derivative: {.12}, fd: {.12}", derivative, finite_difference);
139-
logger().trace("relative error: {.12}", abs((finite_difference - derivative) / derivative));
137+
logger().trace("f(x) {:.16f} f(x-dt) {:.16f} f(x+dt) {:.16f}", functional_val, former_functional_val, next_functional_val);
138+
logger().trace("derivative: {:.12f}, fd: {:.12f}", derivative, finite_difference);
139+
logger().trace("relative error: {:.12f}", abs((finite_difference - derivative) / derivative));
140140
REQUIRE(derivative == Catch::Approx(finite_difference).epsilon(tol));
141141
}
142142
} // namespace

0 commit comments

Comments
 (0)