From 6daffc246fa8414e5a5ba0137a16c6ac4928dda6 Mon Sep 17 00:00:00 2001
From: Paul Dechamps <paul.dechamps@uliege.be>
Date: Fri, 22 Nov 2024 10:18:23 +0100
Subject: [PATCH] (fix) Pinned DOF for Neumann boundary condition

Ensures that the same DOF is pinned between two consecutive runs when using Neumann boundary condition
---
 dart/src/wAssign.cpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/dart/src/wAssign.cpp b/dart/src/wAssign.cpp
index 382827f..07c130c 100644
--- a/dart/src/wAssign.cpp
+++ b/dart/src/wAssign.cpp
@@ -77,9 +77,16 @@ void Initial::write(std::ostream &out) const
 Dirichlet::Dirichlet(std::shared_ptr<tbox::MshData> _msh, int no, int dim, double alpha, double beta, bool pin) : Assign(_msh, no)
 {
     f = new F0PsPhiInf(dim, alpha, beta);
-    // Only retain the first node, so that the DOF associated to this node will be pinned
+    // Only retain one node, so that the DOF associated to this node will be pinned
     if (pin)
-        this->nodes.resize(1);
+    {
+        // Pin node with min x min y min z
+        auto it = std::min_element(nodes.begin(), nodes.end(), [](Node *n1, Node *n2) {
+            return n1->pos[0] < n2->pos[0] || (n1->pos[0] == n2->pos[0] && n1->pos[1] < n2->pos[1]) || (n1->pos[0] == n2->pos[0] && n1->pos[1] == n2->pos[1] && n1->pos[2] < n2->pos[2]);
+        });
+        nodes.resize(1);
+        nodes[0] = *it;
+    }
 }
 Dirichlet::Dirichlet(std::shared_ptr<tbox::MshData> _msh, std::string const &name, int dim, double alpha, double beta) : Assign(_msh, name)
 {
-- 
GitLab