From b000ebb539dfa0cad578ae23d5cdc2e1517d9694 Mon Sep 17 00:00:00 2001
From: Nils Kohl <nils.kohl@fau.de>
Date: Thu, 4 Apr 2019 12:04:53 +0200
Subject: [PATCH] Replaced boost::tribool with walberla::optional.

---
 src/mesh/MeshOperations.h                  | 23 ++++++++++-----------
 src/mesh/blockforest/RefinementSelection.h |  5 +++--
 tests/mesh/MeshAABBIntersectionTest.cpp    | 24 +++++++++++-----------
 3 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/src/mesh/MeshOperations.h b/src/mesh/MeshOperations.h
index cd4cf4f3f..03a00f219 100644
--- a/src/mesh/MeshOperations.h
+++ b/src/mesh/MeshOperations.h
@@ -25,8 +25,7 @@
 #include "TriangleMeshes.h"
 
 #include "core/math/GenericAABB.h"
-
-#include <boost/logic/tribool.hpp>
+#include "core/Optional.h"
 
 #include <set>
 #include <iterator>
@@ -72,13 +71,13 @@ template< typename MeshType >
 void findConnectedVertices( const MeshType & mesh, const typename MeshType::FaceHandle & face, std::vector< typename MeshType::VertexHandle > & outVertices );
 
 template< typename DistanceObject, typename T, typename U >
-boost::logic::tribool isIntersecting( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const T & maxError );
+walberla::optional< bool > isIntersecting( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const T & maxError );
 
 template< typename DistanceObject, typename T, typename U >
-boost::logic::tribool fullyCoversAABB( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const T & maxError );
+walberla::optional< bool > fullyCoversAABB( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const T & maxError );
 
 template< typename DistanceObject, typename T, typename U, typename V >
-boost::logic::tribool intersectsSurface( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const U & maxError, const V & surfaceDistance );
+walberla::optional< bool > intersectsSurface( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const U & maxError, const V & surfaceDistance );
 
 template< typename MeshType, typename InputIterator >
 typename MeshType::Point principalComponent( const MeshType & mesh, InputIterator beginFh, InputIterator endFh, const uint_t iterations = uint_t(10) );
@@ -341,7 +340,7 @@ void findConnectedVertices( const MeshType & mesh, const typename MeshType::Face
 
 
 template< typename DistanceObject, typename T, typename U >
-boost::logic::tribool isIntersecting( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const U & maxError )
+walberla::optional< bool > isIntersecting( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const U & maxError )
 {
    typedef typename DistanceObject::Scalar Scalar;
 
@@ -388,7 +387,7 @@ boost::logic::tribool isIntersecting( const DistanceObject & distanceObject, con
 
       if( error < maxErrorScalar )
       {
-         return boost::logic::indeterminate; // we still don't know if there is an intersection but the error margin is already small enough
+         return walberla::nullopt; // we still don't know if there is an intersection but the error margin is already small enough
       }
 
       const auto &    min = curAabb.minCorner();
@@ -413,7 +412,7 @@ boost::logic::tribool isIntersecting( const DistanceObject & distanceObject, con
 
 
 template< typename DistanceObject, typename T, typename U >
-boost::logic::tribool fullyCoversAABB( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const U & maxError )
+walberla::optional< bool > fullyCoversAABB( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const U & maxError )
 {
    typedef typename DistanceObject::Scalar Scalar;
 
@@ -459,7 +458,7 @@ boost::logic::tribool fullyCoversAABB( const DistanceObject & distanceObject, co
 
       if( error < maxErrorScalar )
       {
-         return boost::logic::indeterminate; // we still don't know if there is an intersection but the error margin is already small enough
+         return walberla::nullopt; // we still don't know if there is an intersection but the error margin is already small enough
       }
 
       const auto &    min = curAabb.minCorner();
@@ -484,7 +483,7 @@ boost::logic::tribool fullyCoversAABB( const DistanceObject & distanceObject, co
 
 
 template< typename DistanceObject, typename T, typename U, typename V >
-boost::logic::tribool intersectsSurface( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const U & maxError, const V & surfaceDistance )
+walberla::optional< bool > intersectsSurface( const DistanceObject & distanceObject, const math::GenericAABB< T > & aabb, const U & maxError, const V & surfaceDistance )
 {
    typedef typename DistanceObject::Scalar Scalar;
 
@@ -532,7 +531,7 @@ boost::logic::tribool intersectsSurface( const DistanceObject & distanceObject,
 
       if(error < maxErrorScalar)
       {
-         return boost::logic::indeterminate; // we still don't know if there is an intersection but the error margin is already small enough
+         return walberla::nullopt; // we still don't know if there is an intersection but the error margin is already small enough
       }
 
       const auto &    min = curAabb.minCorner();
@@ -609,4 +608,4 @@ typename MeshType::Point principalComponent( const MeshType & mesh, const uint_t
 
 
 } // namespace mesh
-} // namespace walberla
\ No newline at end of file
+} // namespace walberla
diff --git a/src/mesh/blockforest/RefinementSelection.h b/src/mesh/blockforest/RefinementSelection.h
index 30493d9e6..4c2977354 100644
--- a/src/mesh/blockforest/RefinementSelection.h
+++ b/src/mesh/blockforest/RefinementSelection.h
@@ -30,6 +30,7 @@
 #include "core/cell/CellInterval.h"
 #include "core/mpi/MPIManager.h"
 #include "core/mpi/Reduce.h"
+#include "core/Optional.h"
 
 #include <random>
 #include <vector>
@@ -101,8 +102,8 @@ inline void walberla::mesh::RefinementSelection<DistanceObject>::operator()( blo
       if( blockLevel >= level_ )
          continue;
 
-      boost::tribool intersects = intersectsSurface( *distanceObject_, blocks[ shuffle[ii] ]->getAABB(), maxError_, distance_ );
-      if( indeterminate( intersects ) || intersects )
+      walberla::optional< bool > intersects = intersectsSurface( *distanceObject_, blocks[ shuffle[ii] ]->getAABB(), maxError_, distance_ );
+      if( intersects.value_or( true ) )
          refine[ shuffle[ ii ] ] = uint8_t( 1 );
    }
 
diff --git a/tests/mesh/MeshAABBIntersectionTest.cpp b/tests/mesh/MeshAABBIntersectionTest.cpp
index e1286dbc6..967c8ce21 100644
--- a/tests/mesh/MeshAABBIntersectionTest.cpp
+++ b/tests/mesh/MeshAABBIntersectionTest.cpp
@@ -23,6 +23,7 @@
 #include "core/logging/Logging.h"
 #include "core/math/AABB.h"
 #include "core/mpi/Environment.h"
+#include "core/Optional.h"
 
 #include "mesh/MeshIO.h"
 #include "mesh/MeshOperations.h"
@@ -50,7 +51,7 @@ void runTests( const uint_t numAABBs )
 
    TriangleDistance<MeshType> triDist( mesh );
 
-   WALBERLA_CHECK( isIntersecting( triDist, meshAABB, real_t(0) ).value, boost::logic::tribool::true_value );
+   WALBERLA_CHECK( isIntersecting( triDist, meshAABB, real_t(0) ).value_or( false ) );
 
    std::mt19937 rng( uint32_t(42) );
 
@@ -60,19 +61,18 @@ void runTests( const uint_t numAABBs )
 
       const real_t maxErr = real_t(1e-2);
 
-      boost::tribool result = isIntersecting( triDist, testAABB, maxErr );
+      walberla::optional< bool > result = isIntersecting( triDist, testAABB, maxErr );
 
-      if(result)
+      if ( result.has_value() )
       {
-         WALBERLA_CHECK( meshAABB.intersects( testAABB ), "Box#: " << i );
-      }
-      else if(!result)
-      {
-         WALBERLA_CHECK( !meshAABB.intersects( testAABB ), "Box#: " << i );
-      }
-      else
-      {
-         WALBERLA_ASSERT( boost::logic::indeterminate( result ) );
+         if(result.value())
+         {
+            WALBERLA_CHECK( meshAABB.intersects( testAABB ), "Box#: " << i );
+         }
+         else if(!result.value())
+         {
+            WALBERLA_CHECK( !meshAABB.intersects( testAABB ), "Box#: " << i );
+         }
       }
    }
 }
-- 
GitLab