Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: false
AlignEscapedNewlines: Left
AlignOperands: true
Expand All @@ -15,11 +15,10 @@ AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: TopLevel
AlwaysBreakAfterReturnType: All
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
Expand All @@ -31,14 +30,15 @@ BraceWrapping:
AfterStruct: true
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
BreakStringLiterals: false
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Expand All @@ -65,7 +65,7 @@ KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
NamespaceIndentation: All
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
Expand All @@ -76,7 +76,7 @@ PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
ReflowComments: false
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
Expand Down
218 changes: 112 additions & 106 deletions Examples/AMReX_DCEL/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,105 +16,105 @@
using namespace amrex;

namespace amrex {
namespace EB2 {

/*!
@brief This is an AMReX-capable version of the EBGeometry BVH accelerator. It
is templated as T, BV, K which indicate the EBGeometry precision, bounding
volume, and tree degree.
*/
template <class T, class BV, int K>
class SignedDistanceBVH
{
public:
/*!
@brief Alias for builder node, for encapsulating a "standard" BVH node
*/
using BuilderNode = EBGeometry::BVH::NodeT<T, EBGeometry::DCEL::FaceT<T>, BV, K>;

/*!
@brief Alias for linearized BVH node
*/
using LinearNode = EBGeometry::BVH::LinearBVH<T, EBGeometry::DCEL::FaceT<T>, BV, K>;

/*!
@brief Alias for always-3D vector
*/
using Vec3 = EBGeometry::Vec3T<T>;

/*!
@brief Full constructor.
@param[in] a_filename File name. Must be a PLY file and will be parser by the
PLY parser.
@param[in] a_flipSign Hook for swapping inside/outside.
*/
SignedDistanceBVH(const std::string a_filename, const bool a_flipSign)
{

// 1. Read mesh from file.
auto mesh = EBGeometry::Parser::PLY<T>::readIntoDCEL(a_filename);

// 2. Create a standard BVH hierarchy. This is not a compact ree.
auto root = std::make_shared<BuilderNode>(mesh->getFaces());
root->topDownSortAndPartitionPrimitives(
EBGeometry::DCEL::defaultBVConstructor<T, BV>, EBGeometry::DCEL::defaultPartitioner<T, BV, K>,
EBGeometry::DCEL::defaultStopFunction<T, BV, K>);

// 3. Flatten the tree onto a tighter memory representation.
m_rootNode = root->flattenTree();
}

/*!
@brief Copy constructor.
@param[in] a_other Other SDF.
*/
SignedDistanceBVH(const SignedDistanceBVH& a_other)
{
this->m_rootNode = a_other.m_rootNode;
this->m_flipSign = a_other.m_flipSign;
}

/*!
@brief AMReX's implicit function definition.
*/
Real operator()(AMREX_D_DECL(Real x, Real y, Real z)) const noexcept
{
const Real sign = (m_flipSign) ? -1.0 : 1.0;

return sign * m_rootNode->signedDistance(Vec3(x, y, z));
};

/*!
@brief Also an AMReX implicit function implementation
*/
inline Real
operator()(const RealArray& p) const noexcept
{
return this->operator()(AMREX_D_DECL(p[0], p[1], p[2]));
}

protected:
/*!
@brief Root node of the linearized BVH hierarchy.
*/
std::shared_ptr<LinearNode> m_rootNode;

/*!
@brief Hook for flipping the sign
*/
bool m_flipSign;
};
} // namespace EB2
namespace EB2 {

/*!
@brief This is an AMReX-capable version of the EBGeometry BVH accelerator. It
is templated as T, BV, K which indicate the EBGeometry precision, bounding
volume, and tree degree.
*/
template <class T, class BV, int K>
class SignedDistanceBVH
{
public:
/*!
@brief Alias for builder node, for encapsulating a "standard" BVH node
*/
using BuilderNode = EBGeometry::BVH::NodeT<T, EBGeometry::DCEL::FaceT<T>, BV, K>;

/*!
@brief Alias for linearized BVH node
*/
using LinearNode = EBGeometry::BVH::LinearBVH<T, EBGeometry::DCEL::FaceT<T>, BV, K>;

/*!
@brief Alias for always-3D vector
*/
using Vec3 = EBGeometry::Vec3T<T>;

/*!
@brief Full constructor.
@param[in] a_filename File name. Must be a PLY file and will be parser by the
PLY parser.
@param[in] a_flipSign Hook for swapping inside/outside.
*/
SignedDistanceBVH(const std::string a_filename, const bool a_flipSign)
{

// 1. Read mesh from file.
auto mesh = EBGeometry::Parser::PLY<T>::readIntoDCEL(a_filename);

// 2. Create a standard BVH hierarchy. This is not a compact ree.
auto root = std::make_shared<BuilderNode>(mesh->getFaces());
root->topDownSortAndPartitionPrimitives(EBGeometry::DCEL::defaultBVConstructor<T, BV>,
EBGeometry::DCEL::defaultPartitioner<T, BV, K>,
EBGeometry::DCEL::defaultStopFunction<T, BV, K>);

// 3. Flatten the tree onto a tighter memory representation.
m_rootNode = root->flattenTree();
}

/*!
@brief Copy constructor.
@param[in] a_other Other SDF.
*/
SignedDistanceBVH(const SignedDistanceBVH& a_other)
{
this->m_rootNode = a_other.m_rootNode;
this->m_flipSign = a_other.m_flipSign;
}

/*!
@brief AMReX's implicit function definition.
*/
Real operator()(AMREX_D_DECL(Real x, Real y, Real z)) const noexcept
{
const Real sign = (m_flipSign) ? -1.0 : 1.0;

return sign * m_rootNode->signedDistance(Vec3(x, y, z));
};

/*!
@brief Also an AMReX implicit function implementation
*/
inline Real
operator()(const RealArray& p) const noexcept
{
return this->operator()(AMREX_D_DECL(p[0], p[1], p[2]));
}

protected:
/*!
@brief Root node of the linearized BVH hierarchy.
*/
std::shared_ptr<LinearNode> m_rootNode;

/*!
@brief Hook for flipping the sign
*/
bool m_flipSign;
};
} // namespace EB2
} // namespace amrex

int
main(int argc, char* argv[])
{
amrex::Initialize(argc, argv);

int n_cell = 128;
int n_cell = 128;
int max_grid_size = 32;
int which_geom = 0;
int which_geom = 0;

std::string filename;

Expand All @@ -129,26 +129,32 @@ main(int argc, char* argv[])
RealBox rb;

if (which_geom == 0) { // Airfoil case
rb = RealBox({-100, -100, -75}, {400, 100, 125});
rb = RealBox({-100, -100, -75}, {400, 100, 125});
filename = "../PLY/airfoil.ply";
} else if (which_geom == 1) { // Sphere case
rb = RealBox({-400, -400, -400}, {400, 400, 400});
}
else if (which_geom == 1) { // Sphere case
rb = RealBox({-400, -400, -400}, {400, 400, 400});
filename = "../PLY/sphere.ply";
} else if (which_geom == 2) { // Dodecahedron
rb = RealBox({-2., -2., -2.}, {2., 2., 2.});
}
else if (which_geom == 2) { // Dodecahedron
rb = RealBox({-2., -2., -2.}, {2., 2., 2.});
filename = "../PLY/dodecahedron.ply";
} else if (which_geom == 3) { // Horse
rb = RealBox({-0.12, -0.12, -0.12}, {0.12, 0.12, 0.12});
}
else if (which_geom == 3) { // Horse
rb = RealBox({-0.12, -0.12, -0.12}, {0.12, 0.12, 0.12});
filename = "../PLY/horse.ply";
} else if (which_geom == 4) { // Car
}
else if (which_geom == 4) { // Car
// rb = RealBox({-20,-20,-20}, {20,20,20}); // Doesn't work.
rb = RealBox({-10, -5, -5}, {10, 5, 5}); // Works.
rb = RealBox({-10, -5, -5}, {10, 5, 5}); // Works.
filename = "../PLY/porsche.ply";
} else if (which_geom == 5) { // Orion
rb = RealBox({-10, -5, -10}, {10, 10, 10});
}
else if (which_geom == 5) { // Orion
rb = RealBox({-10, -5, -10}, {10, 10, 10});
filename = "../PLY/orion.ply";
} else if (which_geom == 6) { // Armadillo
rb = RealBox({-100, -75, -100}, {100, 125, 100});
}
else if (which_geom == 6) { // Armadillo
rb = RealBox({-100, -75, -100}, {100, 125, 100});
filename = "../PLY/armadillo.ply";
}

Expand All @@ -162,9 +168,9 @@ main(int argc, char* argv[])
// EBGeometry precision.
constexpr int K = 4;

using T = float;
using T = float;
using Vec3 = EBGeometry::Vec3T<T>;
using BV = EBGeometry::BoundingVolumes::AABBT<T>;
using BV = EBGeometry::BoundingVolumes::AABBT<T>;

EB2::SignedDistanceBVH<T, BV, K> sdf(filename, false);

Expand Down
Loading