Skip to content

Commit

Permalink
ENH: Update required standard to C++20 (#1004)
Browse files Browse the repository at this point in the history
* Updated to Eigen 3.4.0
* Updated to expected-lite 0.8.0
* Updated to nod 0.5.4
* Removed gcc9 CI
* Added /Zc:__cplusplus compile flag for msvc
* Fixed fmtlib formatting
* Fixed tbb::parallel_for functors
* Functors passed to tbb::parallel_for must satisfy the parallel_for_body
concept which requires that they are copy constructible
* Fixed various compile errors on C++20
* Fixed FeatureFaceCurvatureTest where the principal directions
are unique up to a sign
* Fixed ComputeFeatureReferenceCAxisMisorientationsTest and
ComputeFeatureNeighborCAxisMisalignmentsTest by using 
double precision to get the values to agree on all platforms
regardless of vectorization

Signed-off-by: Jared Duffey <[email protected]>
Signed-off-by: Michael Jackson <[email protected]>
Co-authored-by: Michael Jackson <[email protected]>
  • Loading branch information
JDuffeyBQ and imikejackson authored Jul 9, 2024
1 parent 639460e commit 31406a4
Show file tree
Hide file tree
Showing 51 changed files with 179 additions and 244 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ jobs:
os:
- ubuntu-20.04
cxx:
- g++-9
- g++-10
- clang++-10
include:
- cxx: g++-9
cc: gcc-9
- cxx: g++-10
cc: gcc-10
- cxx: clang++-10
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ list(APPEND CMAKE_MODULE_PATH ${simplnx_SOURCE_DIR}/cmake)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(SIMPLNX_DEBUG_POSTFIX "_d")
Expand Down
2 changes: 2 additions & 0 deletions cmake/Utility.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function(simplnx_enable_warnings)

if(MSVC)
target_compile_options(${ARG_TARGET}
PUBLIC
/Zc:__cplusplus # Enables the __cplusplus preprocessor macro to report an updated value for recent C++ language standards support. By default, Visual Studio always returns the value 199711L for the __cplusplus preprocessor macro.
PRIVATE
# Suppressed warnings
/wd4275 # C4275: An exported class was derived from a class that wasn't exported.
Expand Down
12 changes: 6 additions & 6 deletions src/Plugins/OrientationAnalysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,15 @@ if(EXISTS "${DREAM3D_DATA_DIR}" AND SIMPLNX_DOWNLOAD_TEST_FILES)
set_target_properties(Copy_${PLUGIN_NAME}_Small_IN100 PROPERTIES FOLDER ZZ_COPY_FILES)

download_test_data(DREAM3D_DATA_DIR ${DREAM3D_DATA_DIR}
ARCHIVE_NAME 6_6_caxis_data.tar.gz
SHA512 6c3eefac62aecf3344de735c0df932dd9a2623653f39174ec72402c54e8911402ad9903ae2122bc23ff2dba8c94973b2882715908e1913973dff604b614a5293
ARCHIVE_NAME caxis_data.tar.gz
SHA512 56468d3f248661c0d739d9acd5a1554abc700bf136586f698a313804536916850b731603d42a0b93aae47faf2f7ee49d4181b1c3e833f054df6f5c70b5e041dc
)
add_custom_target(Copy_${PLUGIN_NAME}_CAxis_Data ALL
COMMAND ${CMAKE_COMMAND} -E tar xzf "${DREAM3D_DATA_DIR}/TestFiles/6_6_caxis_data.tar.gz"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${DREAM3D_DATA_DIR}/TestFiles/6_6_caxis_data/Combo-EBSD-120130.osc_r0c0.ang" "${DATA_DEST_DIR}/OrientationAnalysis/Combo-EBSD-120130.osc_r0c0.ang"
COMMAND ${CMAKE_COMMAND} -E rm -rf "${DREAM3D_DATA_DIR}/TestFiles/6_6_caxis_data"
COMMAND ${CMAKE_COMMAND} -E tar xzf "${DREAM3D_DATA_DIR}/TestFiles/caxis_data.tar.gz"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${DREAM3D_DATA_DIR}/TestFiles/caxis_data/Combo-EBSD-120130.osc_r0c0.ang" "${DATA_DEST_DIR}/OrientationAnalysis/Combo-EBSD-120130.osc_r0c0.ang"
COMMAND ${CMAKE_COMMAND} -E rm -rf "${DREAM3D_DATA_DIR}/TestFiles/caxis_data"
WORKING_DIRECTORY "${DREAM3D_DATA_DIR}/TestFiles"
COMMENT "Copying ${PLUGIN_NAME}/6_6_caxis_data data into Binary Directory"
COMMENT "Copying ${PLUGIN_NAME}/caxis_data data into Binary Directory"
DEPENDS Fetch_Remote_Data_Files # Make sure all remote files are downloaded before trying this
COMMAND_EXPAND_LISTS
VERBATIM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This **Filter** determines, for each **Feature**, the C-axis misalignments with

**NOTE:** Only features with identical phase values and a crystal structure of **Hexagonal_High** will be calculated. If two features have different phase values or a crystal structure that is *not* Hexagonal_High then a value of NaN is set for the misorientation.

Results from this filter can differ from its original version in DREAM3D 6.6 by around 0.0001. This version uses double precision in part of its calculation to improve agreement and accuracy between platforms (notably ARM).

% Auto generated parameter table will be inserted here

## Example Pipelines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This **Filter** calculates the misorientation angle between the C-axis of each *

This filter requires at least one Hexagonal crystal structure phase (Hexagonal-Low 6/m or Hexagonal-High 6/mmm). Although it is not recommended, you can give input data with mixed phase types and all non hexagonal phases will be skipped in the calculations.

Results from this filter can differ from its original version in DREAM3D 6.6 by around 0.0001. This version uses double precision in part of its calculation to improve agreement and accuracy between platforms (notably ARM).

% Auto generated parameter table will be inserted here

## Example Pipelines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ Result<> ComputeFeatureNeighborCAxisMisalignments::operator()()
std::vector<std::vector<float>> misalignmentLists;
misalignmentLists.resize(totalFeatures);

float32 w = 0.0f;
Eigen::Vector3f c1{0.0f, 0.0f, 0.0f};
Eigen::Vector3f c2{0.0f, 0.0f, 0.0f};
const Eigen::Vector3f cAxis{0.0f, 0.0f, 1.0f};
const Eigen::Vector3d cAxis{0.0, 0.0, 1.0};
usize hexNeighborListSize = 0;
uint32 phase1 = 0, phase2 = 0;
usize nName = 0;
Expand All @@ -85,44 +82,43 @@ Result<> ComputeFeatureNeighborCAxisMisalignments::operator()()
phase1 = crystalStructures[featurePhases[i]];

const usize quatTupleIndex1 = i * numQuatComps;
OrientationF oMatrix1 =
OrientationTransformation::qu2om<QuatF, OrientationF>({avgQuats[quatTupleIndex1], avgQuats[quatTupleIndex1 + 1], avgQuats[quatTupleIndex1 + 2], avgQuats[quatTupleIndex1 + 3]});
OrientationD oMatrix1 =
OrientationTransformation::qu2om<QuatD, OrientationD>({avgQuats[quatTupleIndex1], avgQuats[quatTupleIndex1 + 1], avgQuats[quatTupleIndex1 + 2], avgQuats[quatTupleIndex1 + 3]});

// transpose the g matrix so when c-axis is multiplied by it
// it will give the sample direction that the c-axis is along
c1 = OrientationMatrixToGMatrixTranspose(oMatrix1) * cAxis;
Eigen::Vector3d c1 = OrientationMatrixToGMatrixTranspose(oMatrix1) * cAxis;
// normalize so that the dot product can be taken below without
// dividing by the magnitudes (they would be 1)
c1.normalize();
misalignmentLists[i].resize(neighborList[i].size(), -1.0f);
for(usize j = 0; j < neighborList[i].size(); j++)
{
w = std::numeric_limits<float>::max();
nName = neighborList[i][j];
phase2 = crystalStructures[featurePhases[nName]];
hexNeighborListSize = neighborList[i].size();
if(phase1 == phase2 && (phase1 == EbsdLib::CrystalStructure::Hexagonal_High || phase1 == EbsdLib::CrystalStructure::Hexagonal_Low))
{
const usize quatTupleIndex2 = nName * numQuatComps;
OrientationF oMatrix2 =
OrientationTransformation::qu2om<QuatF, OrientationF>({avgQuats[quatTupleIndex2], avgQuats[quatTupleIndex2 + 1], avgQuats[quatTupleIndex2 + 2], avgQuats[quatTupleIndex2 + 3]});
OrientationD oMatrix2 =
OrientationTransformation::qu2om<QuatD, OrientationD>({avgQuats[quatTupleIndex2], avgQuats[quatTupleIndex2 + 1], avgQuats[quatTupleIndex2 + 2], avgQuats[quatTupleIndex2 + 3]});

// transpose the g matrix so when c-axis is multiplied by it
// it will give the sample direction that the c-axis is along
c2 = OrientationMatrixToGMatrixTranspose(oMatrix2) * cAxis;
Eigen::Vector3d c2 = OrientationMatrixToGMatrixTranspose(oMatrix2) * cAxis;
// normalize so that the dot product can be taken below without
// dividing by the magnitudes (they would be 1)
c2.normalize();

w = ImageRotationUtilities::CosBetweenVectors(c1, c2);
w = std::clamp(w, -1.0f, 1.0f);
w = acosf(w);
if(w > (Constants::k_PiF / 2))
float64 w = ImageRotationUtilities::CosBetweenVectors(c1, c2);
w = std::clamp(w, -1.0, 1.0);
w = std::acos(w);
if(w > (Constants::k_PiD / 2.0))
{
w = Constants::k_PiF - w;
w = Constants::k_PiD - w;
}

misalignmentLists[i][j] = w * Constants::k_180OverPiF;
misalignmentLists[i][j] = static_cast<float32>(w * Constants::k_180OverPiD);
if(m_InputValues->FindAvgMisals)
{
avgCAxisMisalignment[i] += misalignmentLists[i][j];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "EbsdLib/Core/Orientation.hpp"
#include "EbsdLib/Core/OrientationTransformation.hpp"
#include "EbsdLib/Core/Quaternion.hpp"

#include <EbsdLib/Core/EbsdDataArray.hpp>

#include <algorithm>
Expand Down Expand Up @@ -78,11 +77,10 @@ Result<> ComputeFeatureReferenceCAxisMisorientations::operator()()
const usize totalPoints = featureIds.getNumberOfTuples();
const usize totalFeatures = avgCAxes.getNumberOfTuples();

const int32 avgMisComps = 3;
static constexpr usize k_AvgMisComps = 3;
const usize numQuatComps = quats.getNumberOfComponents();
std::vector<float32> avgMis(totalFeatures * avgMisComps, 0);
std::vector<float32> avgMis(totalFeatures * k_AvgMisComps, 0.0f);

float32 w = 0.0f;
SizeVec3 uDims = m_DataStructure.getDataRefAs<ImageGeom>(m_InputValues->ImageGeometryPath).getDimensions();

// We have more points than can be allocated on a 32 bit machine. Assert Now.
Expand All @@ -94,52 +92,44 @@ Result<> ComputeFeatureReferenceCAxisMisorientations::operator()()
const auto xPoints = static_cast<int64>(uDims[0]);
const auto yPoints = static_cast<int64>(uDims[1]);
const auto zPoints = static_cast<int64>(uDims[2]);
int64 point = 0;

Matrix3fR g1T;
g1T.fill(0.0f);
const Eigen::Vector3f cAxis{0.0f, 0.0f, 1.0f};
Eigen::Vector3f c1{0.0f, 0.0f, 0.0f};
Eigen::Vector3f avgCAxisMis = {0.0f, 0.0f, 0.0f};
usize index = 0;

const Eigen::Vector3d cAxis{0.0, 0.0, 1.0};
for(int64 col = 0; col < xPoints; col++)
{
for(int64 row = 0; row < yPoints; row++)
{
for(int64 plane = 0; plane < zPoints; plane++)
{
point = (plane * xPoints * yPoints) + (row * xPoints) + col;
const auto quatTupleIndex = point * numQuatComps;
const auto crystalStructureType = crystalStructures[cellPhases[point]];
int64 point = (plane * xPoints * yPoints) + (row * xPoints) + col;
const usize quatTupleIndex = point * numQuatComps;
const uint32 crystalStructureType = crystalStructures[cellPhases[point]];
const bool isHex = crystalStructureType == EbsdLib::CrystalStructure::Hexagonal_High || crystalStructureType == EbsdLib::CrystalStructure::Hexagonal_Low;
if(featureIds[point] > 0 && cellPhases[point] > 0 && isHex)
{
OrientationF oMatrix =
OrientationTransformation::qu2om<QuatF, Orientation<float32>>({quats[quatTupleIndex], quats[quatTupleIndex + 1], quats[quatTupleIndex + 2], quats[quatTupleIndex + 3]});
OrientationD oMatrix =
OrientationTransformation::qu2om<QuatD, Orientation<float64>>({quats[quatTupleIndex], quats[quatTupleIndex + 1], quats[quatTupleIndex + 2], quats[quatTupleIndex + 3]});
// transpose the g matrices so when caxis is multiplied by it, it will give the sample direction that the caxis is along
g1T = OrientationMatrixToGMatrixTranspose(oMatrix);
c1 = g1T * cAxis;
Matrix3dR g1T = OrientationMatrixToGMatrixTranspose(oMatrix);
Eigen::Vector3d c1 = g1T * cAxis;
// normalize so that the magnitude is 1
c1.normalize();

avgCAxisMis[0] = avgCAxes[3 * featureIds[point]];
avgCAxisMis[1] = avgCAxes[3 * featureIds[point] + 1];
avgCAxisMis[2] = avgCAxes[3 * featureIds[point] + 2];
Eigen::Vector3d avgCAxisMis = {avgCAxes[3 * featureIds[point]], avgCAxes[3 * featureIds[point] + 1], avgCAxes[3 * featureIds[point] + 2]};
// normalize so that the magnitude is 1
avgCAxisMis.normalize();
w = ImageRotationUtilities::CosBetweenVectors(c1, avgCAxisMis);
w = std::clamp(w, -1.0f, 1.0f);
w = acosf(w);
w *= Constants::k_180OverPiF;
if(w > 90.0f)
float64 w = ImageRotationUtilities::CosBetweenVectors(c1, avgCAxisMis);
w = std::clamp(w, -1.0, 1.0);
w = std::acos(w);
w *= Constants::k_180OverPiD;
if(w > 90.0)
{
w = 180.0f - w;
w = 180.0 - w;
}

featRefCAxisMis[point] = w;
index = featureIds[point] * avgMisComps;
featRefCAxisMis[point] = static_cast<float32>(w);
usize index = featureIds[point] * k_AvgMisComps;
avgMis[index]++;
avgMis[index + 1] += w;
avgMis[index + 1] += static_cast<float32>(w);
}
else
{
Expand All @@ -155,10 +145,10 @@ Result<> ComputeFeatureReferenceCAxisMisorientations::operator()()
{
m_MessageHandler(IFilter::Message::Type::Info, fmt::format("Working On Feature {} of {}", i, totalFeatures));
}
index = i * avgMisComps;
usize index = i * k_AvgMisComps;
if(avgMis[index] == 0.0f)
{
featAvgCAxisMis[i] = 0.0;
featAvgCAxisMis[i] = 0.0f;
}
else
{
Expand All @@ -170,19 +160,19 @@ Result<> ComputeFeatureReferenceCAxisMisorientations::operator()()
for(usize j = 0; j < totalPoints; j++)
{
gNum = featureIds[j];
avgMis[(gNum * avgMisComps) + 2] += ((featRefCAxisMis[j] - featAvgCAxisMis[gNum]) * (featRefCAxisMis[j] - featAvgCAxisMis[gNum]));
avgMis[(gNum * k_AvgMisComps) + 2] += ((featRefCAxisMis[j] - featAvgCAxisMis[gNum]) * (featRefCAxisMis[j] - featAvgCAxisMis[gNum]));
}

for(usize i = 1; i < totalFeatures; i++)
{
index = i * avgMisComps;
usize index = i * k_AvgMisComps;
if(avgMis[index] == 0.0f)
{
featStdevCAxisMis[i] = 0.0f;
}
else
{
featStdevCAxisMis[i] = std::sqrt((1 / avgMis[index]) * avgMis[index + 2]);
featStdevCAxisMis[i] = std::sqrt((1.0f / avgMis[index]) * avgMis[index + 2]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ class TrianglesSelector
m_NSym = m_OrientationOps[m_Crystal]->getNumSymOps();
}

virtual ~TrianglesSelector() = default;
TrianglesSelector(const TrianglesSelector&) = default;
TrianglesSelector(TrianglesSelector&&) noexcept = delete;
TrianglesSelector& operator=(const TrianglesSelector&) = delete;
TrianglesSelector& operator=(TrianglesSelector&&) noexcept = delete;

void select(usize start, usize end) const
{
Eigen::Vector3d g1ea = {0.0, 0.0, 0.0};
Expand Down Expand Up @@ -270,12 +264,6 @@ class ProbeDistribution
{
}

virtual ~ProbeDistribution() = default;
ProbeDistribution(const ProbeDistribution&) = default;
ProbeDistribution(ProbeDistribution&&) noexcept = delete;
ProbeDistribution& operator=(const ProbeDistribution&) = delete;
ProbeDistribution& operator=(ProbeDistribution&&) noexcept = delete;

void probe(usize start, usize end) const
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ class TrianglesSelector
m_NSym = m_OrientationOps[m_Crystal]->getNumSymOps();
}

virtual ~TrianglesSelector() = default;
TrianglesSelector(const TrianglesSelector&) = default;
TrianglesSelector(TrianglesSelector&&) noexcept = delete;
TrianglesSelector& operator=(const TrianglesSelector&) = delete;
TrianglesSelector& operator=(TrianglesSelector&&) noexcept = delete;

void select(usize start, usize end) const
{
Eigen::Vector3d g1ea = {0.0, 0.0, 0.0};
Expand Down Expand Up @@ -206,12 +200,6 @@ class ProbeDistribution
m_NSym = m_OrientationOps[crystal]->getNumSymOps();
}

virtual ~ProbeDistribution() = default;
ProbeDistribution(const ProbeDistribution&) = default;
ProbeDistribution(ProbeDistribution&&) noexcept = delete;
ProbeDistribution& operator=(const ProbeDistribution&) = delete;
ProbeDistribution& operator=(ProbeDistribution&&) noexcept = delete;

void probe(usize start, usize end) const
{
for(usize ptIdx = start; ptIdx < end; ptIdx++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ class ComputeQuaternionConjugateImpl
, m_ShouldCancel(shouldCancel)
{
}
ComputeQuaternionConjugateImpl(const ComputeQuaternionConjugateImpl&) = default; // Copy Constructor
ComputeQuaternionConjugateImpl(ComputeQuaternionConjugateImpl&&) = delete; // Move Constructor Not Implemented
ComputeQuaternionConjugateImpl& operator=(const ComputeQuaternionConjugateImpl&) = delete; // Copy Assignment Not Implemented
ComputeQuaternionConjugateImpl& operator=(ComputeQuaternionConjugateImpl&&) = delete; // Move Assignment Not Implemented

virtual ~ComputeQuaternionConjugateImpl() = default;

void convert(size_t start, size_t end) const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ class ConvertQuaternionImpl
, m_ShouldCancel(shouldCancel)
{
}
virtual ~ConvertQuaternionImpl() = default;

ConvertQuaternionImpl(const ConvertQuaternionImpl&) = default; // Copy Constructor Default Implemented
ConvertQuaternionImpl(ConvertQuaternionImpl&&) = delete; // Move Constructor Not Implemented
ConvertQuaternionImpl& operator=(const ConvertQuaternionImpl&) = delete; // Copy Assignment Not Implemented
ConvertQuaternionImpl& operator=(ConvertQuaternionImpl&&) = delete; // Move Assignment Not Implemented

void convert(size_t start, size_t end) const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ class RodriguesConvertorImpl
, m_ShouldCancel(shouldCancel)
{
}
RodriguesConvertorImpl(const RodriguesConvertorImpl&) = default; // Copy Constructor
RodriguesConvertorImpl(RodriguesConvertorImpl&&) = delete; // Move Constructor Not Implemented
RodriguesConvertorImpl& operator=(const RodriguesConvertorImpl&) = delete; // Copy Assignment Not Implemented
RodriguesConvertorImpl& operator=(RodriguesConvertorImpl&&) = delete; // Move Assignment Not Implemented

virtual ~RodriguesConvertorImpl() = default;

void convert(size_t start, size_t end) const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Result<std::any> OEMEbsdScanSelectionParameter::fromJson(const nlohmann::json& j
{
if(!jsonScanNames.is_array())
{
return MakeErrorResult<std::any>(-6054, fmt::format("{}JSON value for key '{} / {}' is not an array", prefix, name()));
return MakeErrorResult<std::any>(-6054, fmt::format("{}JSON value for key '{} / {}' is not an array", prefix, name(), k_ScanNames));
}
const auto scanNameStrings = jsonScanNames.get<std::vector<std::string>>();
std::list<std::string> scanNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Result<std::any> ReadH5EbsdFileParameter::fromJson(const nlohmann::json& json) c
{
if(!jsonDataPaths.is_array())
{
return MakeErrorResult<std::any>(-6054, fmt::format("{}JSON value for key '{} / {}' is not an array", prefix, name()));
return MakeErrorResult<std::any>(-6054, fmt::format("{}JSON value for key '{} / {}' is not an array", prefix, name(), k_HDF5DataPaths));
}
auto dataPathStrings = jsonDataPaths.get<std::vector<std::string>>();
std::vector<std::string> dataPaths;
Expand Down
Loading

0 comments on commit 31406a4

Please sign in to comment.