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
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
*.out
*.ex
*.ex
*.o
*.d
*.F90
Examples/AMReX/plt*
Examples/AMReX/tmp_build_dir
Examples/AMReX/Backtrace.*

26 changes: 26 additions & 0 deletions Examples/AMReX/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
DEBUG = FALSE
TEST = TRUE
USE_ASSERTION = TRUE

USE_EB = TRUE

USE_MPI = TRUE
USE_OMP = FALSE

COMP = gnu

DIM = 3

AMREX_HOME ?= ../../../../amrex

include $(AMREX_HOME)/Tools/GNUMake/Make.defs

include ./Make.package

Pdirs := Base Boundary AmrCore EB

Ppack += $(foreach dir, $(Pdirs), $(AMREX_HOME)/Src/$(dir)/Make.package)

include $(Ppack)

include $(AMREX_HOME)/Tools/GNUMake/Make.rules
1 change: 1 addition & 0 deletions Examples/AMReX/Make.package
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CEXE_sources += main.cpp
22 changes: 22 additions & 0 deletions Examples/AMReX/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
This example uses the embedded boundary grid generation from AMReX.
To compile this application, first install AMReX somewhere and point the AMREX_HOME environment variable to it.

Compile and run this application (with MPI) by

make -s -j8
mpirun -np 8 main3d.<something>.ex

To select different geometries, put

* Airfoil geometry:

mpirun -np 8 main3d.<something>.ex which_geom=0

* Sphere geometry:

mpirun -np 8 main3d.<something>.ex which_geom=1

* Car geometry:

mpirun -np 8 main3d.<something>.ex which_geom=2

108 changes: 108 additions & 0 deletions Examples/AMReX/airfoil.ply
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
ply
format ascii 1.0
comment VCGLIB generated
element vertex 34
property float x
property float y
property float z
element face 64
property list uchar int vertex_indices
end_header
210 11.231 55
210 11.469 55
15.188 6.51602 55
30.2423 5.14883 55
15.188 6.51602 5
50.2496 4.99624 55
189.816 16.0314 5
210 11.469 5
210 11.231 5
50.2496 4.99624 5
69.3018 29.0838 5
49.3646 27.4572 5
30.2423 5.14883 5
10 11.35 55
10 11.35 5
189.816 16.0314 55
169.656 20.078 55
149.517 23.5479 55
69.3018 29.0838 55
29.519 23.4777 55
109.332 28.2812 5
89.2938 29.273 55
89.2938 29.273 5
19.671 19.6294 55
19.671 19.6294 5
14.7821 16.8157 5
14.7821 16.8157 55
129.406 26.3524 55
149.517 23.5479 5
129.406 26.3524 5
29.519 23.4777 5
49.3646 27.4572 55
109.332 28.2812 55
169.656 20.078 5
3 0 7 1
3 7 0 8
3 7 15 1
3 15 7 6
3 9 0 5
3 0 9 8
3 4 3 2
3 3 4 12
3 22 18 21
3 18 22 10
3 12 5 3
3 5 12 9
3 8 6 7
3 9 6 8
3 6 9 33
3 33 9 28
3 28 9 29
3 29 9 20
3 20 9 22
3 22 9 10
3 9 11 10
3 30 9 12
3 9 30 11
3 12 24 30
3 4 24 12
3 4 25 24
3 25 4 14
3 14 2 13
3 2 14 4
3 15 0 1
3 5 15 16
3 5 16 17
3 5 17 27
3 5 27 32
3 5 32 21
3 5 21 18
3 15 5 0
3 31 5 18
3 19 5 31
3 5 19 3
3 23 3 19
3 23 2 3
3 26 2 23
3 2 26 13
3 20 21 32
3 21 20 22
3 24 26 23
3 26 24 25
3 14 26 25
3 26 14 13
3 28 27 17
3 27 28 29
3 10 31 18
3 31 10 11
3 30 23 19
3 23 30 24
3 11 19 31
3 19 11 30
3 29 32 27
3 32 29 20
3 33 17 16
3 17 33 28
3 6 16 15
3 16 6 33
138 changes: 138 additions & 0 deletions Examples/AMReX/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/* EBGeometry
* Copyright © 2022 Robert Marskar
* Please refer to Copyright.txt and LICENSE in the EBGeometry root directory.
*/

// AMReX includes
#include <AMReX.H>
#include <AMReX_EB2.H>
#include <AMReX_EB2_IF.H>
#include <AMReX_ParmParse.H>
#include <AMReX_PlotFileUtil.H>

// Our include
#include "../../EBGeometry.hpp"

using namespace amrex;

// BVH tree degree
constexpr int K = 2;

namespace amrex {
namespace EB2 {

class SignedDistanceBVH {
public:

using P = float;
using Vec3 = EBGeometry::Vec3T<P>;
using Face = EBGeometry::Dcel::FaceT<P>;
using BV = EBGeometry::BoundingVolumes::AABBT<P>;
using Node = EBGeometry::BVH::NodeT<P, Face, BV, K>;

SignedDistanceBVH(const std::string a_filename, const bool a_flipSign) {

auto mesh = EBGeometry::Dcel::Parser::PLY<P>::readASCII(a_filename);

m_rootNode = std::make_shared<Node> (mesh->getFaces());

m_rootNode->topDownSortAndPartitionPrimitives(EBGeometry::Dcel::defaultStopFunction<P, BV, K>,
EBGeometry::Dcel::spatialSplitPartitioner<P, K>,
EBGeometry::Dcel::defaultBVConstructor<P, BV>);
}

SignedDistanceBVH(const SignedDistanceBVH& a_other) {
m_rootNode = a_other.m_rootNode;
m_flipSign = a_other.m_flipSign;
}

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->pruneTree(Vec3(x,y,z));
};

inline Real operator() (const RealArray& p) const noexcept {
return this->operator()(AMREX_D_DECL(p[0],p[1],p[2]));
}

protected:

std::shared_ptr<Node> m_rootNode;

bool m_flipSign;
};
}
}

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

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

std::string filename;

// read parameters
ParmParse pp;
pp.query("n_cell", n_cell);
pp.query("max_grid_size", max_grid_size);
pp.query("which_geom", which_geom);


Geometry geom;
{
RealBox rb;

if(which_geom == 0){// Airfoil case
rb = RealBox({-100,-100,-75}, {400,100,125});
filename = "airfoil.ply";
}
else if (which_geom == 1){ // Sphere case
rb = RealBox({-400,-400,-400}, {400,400,400});
filename = "sphere.ply";
}
else if (which_geom == 2){ // Car geometry
rb = RealBox({-20.,-20.,-20.}, {20.,20.,20.});
filename = "porsche.ply";
}
else if (which_geom == 3){ // Orion geometry
rb = RealBox({-10.,-10.,-10.}, {10.,10.,10.});
filename = "orion.ply";
}

Array<int,AMREX_SPACEDIM> is_periodic{false, false, false};
Geometry::Setup(&rb, 0, is_periodic.data());
Box domain(IntVect(0), IntVect(n_cell-1));
geom.define(domain);
}

// Create the signed distance function.
EB2::SignedDistanceBVH sphere(filename, false);

auto gshop = EB2::makeShop(sphere);
EB2::Build(gshop, geom, 0, 0);

// Put some data
MultiFab mf;
{
BoxArray ba(geom.Domain());
ba.maxSize(max_grid_size);
DistributionMapping dm{ba};

std::unique_ptr<EBFArrayBoxFactory> factory
= amrex::makeEBFabFactory(geom, ba, dm, {2,2,2}, EBSupport::full);

mf.define(ba, dm, 1, 0, MFInfo(), *factory);
mf.setVal(1.0);
}

EB_WriteSingleLevelPlotfile("plt", mf, {"rho"}, geom, 0.0, 0);
}

amrex::Finalize();
}
Loading