@@ -74,42 +74,58 @@ void ContactData::reset()
7474 }
7575}
7676
77- void ContactData::updateGaps (int cycle, double time, double & dt, const mfem::Vector& u_shape, const mfem::Vector& u,
78- bool eval_jacobian)
77+ void ContactData::updateGaps (int cycle, double time, double & dt,
78+ std::optional<std::reference_wrapper<const mfem::Vector>> u_shape,
79+ std::optional<std::reference_wrapper<const mfem::Vector>> u, bool eval_jacobian)
7980{
8081 cycle_ = cycle;
8182 time_ = time;
8283 dt_ = dt;
8384
84- setDisplacements (u_shape, u);
85+ if (u_shape && u) {
86+ setDisplacements (u_shape->get (), u->get ());
87+ }
8588
8689 for (auto & interaction : interactions_) {
8790 interaction.evalJacobian (eval_jacobian);
8891 }
8992 // This updates the redecomposed surface mesh based on the current displacement, then transfers field quantities to
9093 // the updated mesh.
91- tribol::updateMfemParallelDecomposition ();
94+ if (u_shape && u) {
95+ tribol::updateMfemParallelDecomposition ();
96+ }
9297 // This function computes gaps (and optionally geometric Jacobian blocks) based on the current mesh.
9398 tribol::update (cycle, time, dt);
9499}
95100
96- void ContactData::update (int cycle, double time, double & dt, const mfem::Vector& u_shape, const mfem::Vector& u,
97- const mfem::Vector& p)
101+ void ContactData::update (int cycle, double time, double & dt,
102+ std::optional<std::reference_wrapper<const mfem::Vector>> u_shape,
103+ std::optional<std::reference_wrapper<const mfem::Vector>> u,
104+ std::optional<std::reference_wrapper<const mfem::Vector>> p)
98105{
99- // First pass: update gaps
100- updateGaps (cycle, time, dt, u_shape, u);
106+ // First pass: update gaps if coordinates are provided
107+ if (u_shape && u) {
108+ updateGaps (cycle, time, dt, u_shape, u, false );
109+ } else {
110+ // Ensure internal timing is updated even if coordinates are not
111+ cycle_ = cycle;
112+ time_ = time;
113+ dt_ = dt;
114+ }
101115
102- // with updated gaps, we can update pressure for contact interactions (active set detection and penalty)
103- setPressures (p);
116+ // second pass: update pressures and compute forces/Jacobians if p is provided
117+ if (p) {
118+ // with updated gaps, we can update pressure for contact interactions (active set detection and penalty)
119+ setPressures (p->get ());
104120
105- // second pass: compute forces and Jacobians
106- for (auto & interaction : interactions_) {
107- interaction.evalJacobian (true );
121+ for (auto & interaction : interactions_) {
122+ interaction.evalJacobian (true );
123+ }
124+ // This second call is required to synchronize the updated pressures to Tribol's internal redecomposed surface mesh
125+ // and to ensure Tribol's internal state is correctly reset for the second pass.
126+ tribol::updateMfemParallelDecomposition ();
127+ tribol::update (cycle, time, dt);
108128 }
109- // This second call is required to synchronize the updated pressures to Tribol's internal redecomposed surface mesh
110- // and to ensure Tribol's internal state is correctly reset for the second pass.
111- tribol::updateMfemParallelDecomposition ();
112- tribol::update (cycle, time, dt);
113129}
114130
115131FiniteElementDual ContactData::forces () const
@@ -468,14 +484,16 @@ void ContactData::addContactInteraction([[maybe_unused]] int interaction_id,
468484}
469485
470486void ContactData::updateGaps ([[maybe_unused]] int cycle, [[maybe_unused]] double time, [[maybe_unused]] double & dt,
471- [[maybe_unused]] const mfem::Vector& u_shape, [[maybe_unused]] const mfem::Vector& u,
487+ [[maybe_unused]] std::optional<std::reference_wrapper<const mfem::Vector>> u_shape,
488+ [[maybe_unused]] std::optional<std::reference_wrapper<const mfem::Vector>> u,
472489 [[maybe_unused]] bool eval_jacobian)
473490{
474491}
475492
476493void ContactData::update ([[maybe_unused]] int cycle, [[maybe_unused]] double time, [[maybe_unused]] double & dt,
477- [[maybe_unused]] const mfem::Vector& u_shape, [[maybe_unused]] const mfem::Vector& u,
478- [[maybe_unused]] const mfem::Vector& p)
494+ [[maybe_unused]] std::optional<std::reference_wrapper<const mfem::Vector>> u_shape,
495+ [[maybe_unused]] std::optional<std::reference_wrapper<const mfem::Vector>> u,
496+ [[maybe_unused]] std::optional<std::reference_wrapper<const mfem::Vector>> p)
479497{
480498}
481499
0 commit comments