-
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 sense evaluator for testing (#1168)
- Loading branch information
Showing
9 changed files
with
293 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
//----------------------------------*-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/orangeinp/detail/SenseEvaluator.cc | ||
//---------------------------------------------------------------------------// | ||
#include "SenseEvaluator.hh" | ||
|
||
namespace celeritas | ||
{ | ||
namespace orangeinp | ||
{ | ||
namespace detail | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Evaluate from a node ID. | ||
*/ | ||
SignedSense SenseEvaluator::operator()(NodeId const& n) const | ||
{ | ||
return visit_node_(*this, n); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Evaluate a surface. | ||
*/ | ||
SignedSense SenseEvaluator::operator()(Surface const& s) const | ||
{ | ||
CELER_EXPECT(s.id < surfaces_.size()); | ||
|
||
auto result = std::visit( | ||
[&pos = this->pos_](auto const& surf) { return surf.calc_sense(pos); }, | ||
surfaces_[s.id.get()]); | ||
|
||
// TODO: "inside" wrt a surface (i.e. negative quadric) is "false", so we | ||
// have to flip the result | ||
static_assert(Sense::inside == to_sense(false)); | ||
return flip_sense(result); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Redirect to an aliased node. | ||
*/ | ||
SignedSense SenseEvaluator::operator()(Aliased const& n) const | ||
{ | ||
return (*this)(n.node); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Negate the result of a node. | ||
*/ | ||
SignedSense SenseEvaluator::operator()(Negated const& n) const | ||
{ | ||
return flip_sense((*this)(n.node)); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Visit daughter nodes to evaluate the combined sense. | ||
*/ | ||
SignedSense SenseEvaluator::operator()(Joined const& j) const | ||
{ | ||
CELER_ASSUME(j.op == op_and || j.op == op_or); | ||
|
||
// Only keep testing if this sense results: | ||
// short circuit for the other sense, short circuit for being *on* a | ||
// surface too | ||
auto const maybe | ||
= (j.op == op_and ? SignedSense::inside : SignedSense::outside); | ||
|
||
SignedSense result{}; | ||
|
||
for (NodeId const& d : j.nodes) | ||
{ | ||
result = (*this)(d); | ||
if (result != maybe) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace detail | ||
} // namespace orangeinp | ||
} // 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,85 @@ | ||
//----------------------------------*-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/orangeinp/detail/SenseEvaluator.hh | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include "corecel/cont/VariantUtils.hh" | ||
#include "orange/OrangeTypes.hh" | ||
#include "orange/surf/VariantSurface.hh" | ||
|
||
#include "../CsgTree.hh" | ||
|
||
namespace celeritas | ||
{ | ||
namespace orangeinp | ||
{ | ||
namespace detail | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Evalate whether a point is inside a CSG tree node. | ||
* | ||
* This is a construction-time helper that combines \c SenseCalculator with \c | ||
* LogicEvaluator. Its intended use is primarily for testing. | ||
*/ | ||
class SenseEvaluator | ||
{ | ||
public: | ||
//!@{ | ||
//! \name Type aliases | ||
using result_type = SignedSense; | ||
using VecSurface = std::vector<VariantSurface>; | ||
//!@} | ||
|
||
public: | ||
// Construct with a CSG tree, surfaces, and a point | ||
inline SenseEvaluator(CsgTree const& tree, | ||
VecSurface const& surfaces, | ||
Real3 const& pos); | ||
|
||
//! Visit from a node ID | ||
result_type operator()(NodeId const& n) const; | ||
|
||
//!@{ | ||
//! \name Visit a node directly | ||
//! Point is always inside | ||
result_type operator()(True const&) const { return SignedSense::inside; } | ||
//! Point is always outside | ||
result_type operator()(False const&) const { return SignedSense::outside; } | ||
// Evaluate a surface | ||
result_type operator()(Surface const&) const; | ||
// Redirect an alias | ||
result_type operator()(Aliased const&) const; | ||
// Negate the daughter result | ||
result_type operator()(Negated const&) const; | ||
// Visit daughter nodes using short circuit logic | ||
result_type operator()(Joined const&) const; | ||
//!@} | ||
|
||
private: | ||
ContainerVisitor<CsgTree const&, NodeId> visit_node_; | ||
VecSurface const& surfaces_; | ||
Real3 pos_; | ||
}; | ||
|
||
//---------------------------------------------------------------------------// | ||
// INLINE DEFINITIONS | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Construct with a CSG tree and the position to test. | ||
*/ | ||
SenseEvaluator::SenseEvaluator(CsgTree const& tree, | ||
VecSurface const& surfaces, | ||
Real3 const& pos) | ||
: visit_node_{tree}, surfaces_{surfaces}, pos_{pos} | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace detail | ||
} // namespace orangeinp | ||
} // 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
Oops, something went wrong.