-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add trace utility for matrices * Add arbitrary-direction rotation matrix helper * Add transform simplifier * Fix and document single precision issues * Add deduplication test * Deduplicate transforms on insertion * Address review feedback
- Loading branch information
Showing
14 changed files
with
474 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file orange/transform/TransformSimplifier.cc | ||
//---------------------------------------------------------------------------// | ||
#include "TransformSimplifier.hh" | ||
|
||
#include "corecel/math/ArrayUtils.hh" | ||
#include "orange/MatrixUtils.hh" | ||
|
||
namespace celeritas | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Translation may simplify to no transformation. | ||
*/ | ||
VariantTransform TransformSimplifier::operator()(Translation const& t) | ||
{ | ||
if (norm(t.translation()) <= eps_) | ||
{ | ||
// Distance to origin is less than tolerance | ||
return NoTransformation{}; | ||
} | ||
return t; | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Simplify, possibly to translation or no transform. | ||
* | ||
* See the derivation in the class documentation. | ||
*/ | ||
VariantTransform TransformSimplifier::operator()(Transformation const& t) | ||
{ | ||
real_type tr = trace(t.rotation()); | ||
if (tr >= 3 - ipow<2>(eps_)) | ||
{ | ||
// Rotation results in no more then epsilon movement | ||
return (*this)(Translation{t.translation()}); | ||
} | ||
return t; | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace celeritas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file orange/transform/TransformSimplifier.hh | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include "corecel/Macros.hh" | ||
#include "orange/OrangeTypes.hh" | ||
|
||
#include "VariantTransform.hh" | ||
|
||
namespace celeritas | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Return a simplified version of a transformation. | ||
* | ||
* Like surface simplification, we want to consider whether two different | ||
* transformations will result in a distance change of \f$\epsilon\f$ for a | ||
* point that's at the length scale from the origin. Setting the length scale | ||
* to unity (the default), we use the relative tolerance. | ||
* | ||
* A *translation* can be deleted if its magnitude is less than epsilon. | ||
* | ||
* For a translation, we use the fact that the trace (sum of diagonal elements) | ||
* of any proper (non-reflecting) rotation matrix has an angle of rotation \f[ | ||
\mathrm{Tr}[R] = 2 \cos \theta + 1 | ||
* \f] about an axis of rotation. Applying the rotation to a point | ||
* at a unit distance will yield an iscoceles triangle with sides 1 and inner | ||
* angle \f$\theta\f$. For the displacement to be no more than \f$\epsilon\f$ | ||
* then the angle must be \f[ | ||
\sin \theta/2 \le \epsilon/2 | ||
\f] | ||
* which with some manipulation means that a "soft zero" rotation has a trace | ||
* \f[ | ||
\mathrm{Tr}[R] \ge 3 - \epsilon^2 \,. | ||
\f] | ||
* | ||
* Note that this means no rotational simplifications may be performed when the | ||
* geometry tolerance is less than the square root of machine precision. | ||
*/ | ||
class TransformSimplifier | ||
{ | ||
public: | ||
// Construct with tolerance | ||
explicit inline TransformSimplifier(Tolerance<> const& tol); | ||
|
||
//! No simplification can be applied to a null transformation | ||
VariantTransform operator()(NoTransformation const& nt) { return nt; } | ||
|
||
// Translation may simplify to no transformation | ||
VariantTransform operator()(Translation const& nt); | ||
|
||
// Simplify, possibly to translation or no transform | ||
VariantTransform operator()(Transformation const& nt); | ||
|
||
private: | ||
real_type eps_; | ||
}; | ||
|
||
//---------------------------------------------------------------------------// | ||
// INLINE DEFINITIONS | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Construct with tolerance. | ||
*/ | ||
TransformSimplifier::TransformSimplifier(Tolerance<> const& tol) | ||
: eps_{tol.rel} | ||
{ | ||
CELER_EXPECT(tol); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace celeritas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.