From 1b88024120e61c5838132c6e2207dac5e47b3484 Mon Sep 17 00:00:00 2001
From: Ian Bell <ian.bell@nist.gov>
Date: Tue, 6 Jul 2021 11:37:45 -0400
Subject: [PATCH] Align the eigenvectors to match the direction of the minimum
 concentration

---
 include/teqp/algorithms/critical_tracing.hpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/teqp/algorithms/critical_tracing.hpp b/include/teqp/algorithms/critical_tracing.hpp
index 9998192..0b964ef 100644
--- a/include/teqp/algorithms/critical_tracing.hpp
+++ b/include/teqp/algorithms/critical_tracing.hpp
@@ -95,6 +95,13 @@ struct CriticalTracing {
         else {
             throw std::invalid_argument("More than one non-zero concentration value found; not currently supported");
         }
+        // Align with the eigenvector of the component with the smallest density, and make that one positive
+        Eigen::Index ind;
+        rhovec.minCoeff(&ind);
+        if (ed.eigenvectorscols.col(ind).minCoeff() < 0) {
+            ed.eigenvectorscols *= -1.0;
+        }
+
         ed.v0 = ed.eigenvectorscols.col(0);
         ed.v1 = ed.eigenvectorscols.col(1);
         return ed;
-- 
GitLab