Skip to content

Commit

Permalink
Working on the XDG interface. Reorganizing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pshriwise committed Jan 5, 2024
1 parent f6c6d5b commit d2f9a6b
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 125 deletions.
25 changes: 16 additions & 9 deletions include/xdg/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ constexpr double INFTY {std::numeric_limits<double>::max()};

// Whether information pertains to a surface or volume
enum class GeometryType {
SURFACE = 2,
VOLUME = 3
SURFACE = 2,
VOLUME = 3
};

// Surface to Volume sense values (may differ from mesh-specific values)
enum class Sense {
UNSET = -1,
FORWARD = 0,
REVERSE = 1
UNSET = -1,
FORWARD = 0,
REVERSE = 1
};

// Mesh library identifier
enum class MeshLibrary {
INTERANAL = 0,
MOAB,
LIBMESH
};

// Mesh identifer type
Expand All @@ -35,10 +42,10 @@ constexpr int BVH_MAX_DEPTH = 64;
// geometric property type (e.g. material assignment or boundary condition)
// TODO: separate into VolumeProperty and SurfaceProperty
enum class PropertyType {
BOUNDARY_CONDITION = -1,
MATERIAL = 0,
DENSITY = 1,
TEMPERATURE = 2
BOUNDARY_CONDITION = -1,
MATERIAL = 0,
DENSITY = 1,
TEMPERATURE = 2
};

static const std::map<PropertyType, std::string> PROP_TYPE_TO_STR =
Expand Down
6 changes: 4 additions & 2 deletions include/xdg/mesh_manager_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class MeshManager {

virtual std::vector<MeshID> get_surface_elements(MeshID surface) const = 0;


// TODO: can we accomplish this without allocating memory?
virtual std::vector<Vertex> element_vertices(MeshID element) const = 0;

Expand All @@ -49,7 +48,6 @@ class MeshManager {

virtual BoundingBox surface_bounding_box(MeshID surface) const = 0;


// Topology
// Returns parent with forward sense, then reverse
virtual std::pair<MeshID, MeshID> get_parent_volumes(MeshID surface) const = 0;
Expand Down Expand Up @@ -79,13 +77,17 @@ class MeshManager {
const std::vector<MeshID>& surfaces() const { return surfaces_; }
std::vector<MeshID>& surfaces() { return surfaces_; }

virtual MeshLibrary mesh_library() const = 0;

protected:
// metadata
std::map<std::pair<MeshID, PropertyType>, Property> volume_metadata_;
std::map<std::pair<MeshID, PropertyType>, Property> surface_metadata_;

std::vector<MeshID> volumes_;
std::vector<MeshID> surfaces_;


};

} // namespace xdg
Expand Down
5 changes: 4 additions & 1 deletion include/xdg/moab/mesh_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ class MOABMeshManager : public MeshManager {

Property get_surface_property(MeshID surface, PropertyType type) const override;

std::string get_volume_property(const std::string& property, MeshID vol) const;
// Other
MeshLibrary mesh_library() const override {return MeshLibrary::MOAB; }

private:
// Internal MOAB methods
std::vector<moab::EntityHandle> _ents_of_dim(int dim) const;
moab::Range _surface_elements(MeshID surface) const;

std::string get_volume_property(const std::string& property, MeshID vol) const;

public:
// Accessors
moab::Interface* moab_interface() const { return moab_raw_ptr_; };
Expand Down
7 changes: 4 additions & 3 deletions include/xdg/ray_tracing_interface.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _XDG_RAY_TRACING_INTERFACE_H
#define _XDG_RAY_TRACING_INTERFACE_H

#include <memory>
#include <vector>
#include <unordered_map>

Expand All @@ -13,11 +14,11 @@
namespace xdg
{

class RayTracingInterface {
class RayTracer {
// Constructors
public:
RayTracingInterface();
~RayTracingInterface();
RayTracer();
~RayTracer();

// Methods
void init();
Expand Down
42 changes: 42 additions & 0 deletions include/xdg/xdg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef _XDG_INTERFACE_H
#define _XDG_INTERFACE_H

#include <memory>

#include "xdg/mesh_manager_interface.h"
#include "xdg/ray_tracing_interface.h"

namespace xdg {

class XDG {

public:

// Methods
void prepare_raytracer() {
ray_tracing_interface_->register_all_volumes(mesh_manager_interface_);
}

// Mutators
void set_mesh_manager_interface(std::shared_ptr<MeshManager> mesh_manager_interface) {
mesh_manager_interface_ = mesh_manager_interface;
}

// Accessors
const RayTracer* ray_tracing_interface() const {
return ray_tracing_interface_.get();
}

const MeshManager* mesh_manager_interface() const {
return mesh_manager_interface_.get();
}

private:
const std::shared_ptr<RayTracer> ray_tracing_interface_ {std::make_shared<RayTracer>()};
std::shared_ptr<MeshManager> mesh_manager_interface_ {nullptr};
};

}


#endif
5 changes: 3 additions & 2 deletions src/closest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "xdg/geometry/closest.h"
#include "xdg/error.h"

namespace xdg {

Expand Down Expand Up @@ -53,8 +54,6 @@ Region determine_region(double s, double t, double det) {
Position closest_location_on_triangle(const std::array<Position, 3>& vertices,
const Position& point)
{
Position closest_out;

const Position sv {vertices[1] - vertices[0]};
const Position tv {vertices[2] - vertices[0]};
const Position pv {vertices[0] - point};
Expand Down Expand Up @@ -177,6 +176,8 @@ Position closest_location_on_triangle(const std::array<Position, 3>& vertices,
return vertices[0] - ( sp / ss ) * sv;
break;
default:
fatal_error("Invalid region {}", static_cast<int>(region));
return {INFTY, INFTY, INFTY};
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/ray_tracing_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ void error(void* dum, RTCError code, const char* str) {
}


RayTracingInterface::RayTracingInterface()
RayTracer::RayTracer()
{
device_ = rtcNewDevice(nullptr);
rtcSetDeviceErrorFunction(device_, (RTCErrorFunction)error, nullptr);
}

RayTracingInterface::~RayTracingInterface()
RayTracer::~RayTracer()
{
rtcReleaseDevice(device_);
}

void RayTracingInterface::init()
void RayTracer::init()
{

}

void
RayTracingInterface::register_volume(const std::shared_ptr<MeshManager> mesh_manager,
RayTracer::register_volume(const std::shared_ptr<MeshManager> mesh_manager,
MeshID volume_id)
{
// allocate storage for this volume
Expand Down Expand Up @@ -108,7 +108,7 @@ RayTracingInterface::register_volume(const std::shared_ptr<MeshManager> mesh_man
}

void
RayTracingInterface::ray_fire(MeshID volume,
RayTracer::ray_fire(MeshID volume,
const Position& origin,
const Direction& direction,
double& distance,
Expand Down Expand Up @@ -144,7 +144,7 @@ RayTracingInterface::ray_fire(MeshID volume,
}
}

void RayTracingInterface::closest(MeshID volume,
void RayTracer::closest(MeshID volume,
const Position& point,
double& distance)
{
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

set(
TEST_NAMES
test_initialize
test_bbox
test_bvh
test_closest
test_ray_fire
test_mesh_internal
test_xdg_interface
test_moab
)

foreach(test ${TEST_NAMES})
Expand Down
3 changes: 3 additions & 0 deletions tests/mesh_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class MeshMock : public MeshManager {
return Property();
}

// Other
virtual MeshLibrary mesh_library() const override { return MeshLibrary::INTERANAL; }

// Data members
private:
const BoundingBox bounding_box {-2.0, -3.0, -4.0, 5.0, 6.0, 7.0};
Expand Down
24 changes: 11 additions & 13 deletions tests/test_bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@
// xdg includes
#include "xdg/constants.h"
#include "xdg/mesh_manager_interface.h"
#include "xdg/moab/mesh_manager.h"
#include "xdg/ray_tracing_interface.h"

#include "mesh_mock.h"

using namespace xdg;

TEST_CASE("Test BVH Build")
TEST_CASE("Test Mesh BVH")
{
std::shared_ptr<MeshManager> mesh_manager = std::make_shared<MOABMeshManager>();

mesh_manager->load_file("cube.h5m");
mesh_manager->init();
std::shared_ptr<MeshManager> mm = std::make_shared<MeshMock>();
mm->init(); // this should do nothing

REQUIRE(mesh_manager->num_volumes() == 1);
REQUIRE(mesh_manager->num_surfaces() == 6);
REQUIRE(mm->num_volumes() == 1);
REQUIRE(mm->num_surfaces() == 6);
REQUIRE(mm->num_volume_elements(1) == 12);

std::unique_ptr<RayTracingInterface> ray_tracing_interface = std::make_unique<RayTracingInterface>();
std::shared_ptr<RayTracer> rti = std::make_shared<RayTracer>();

for (auto volume : mesh_manager->volumes()) {
ray_tracing_interface->register_volume(mesh_manager, volume);
}
rti->register_all_volumes(mm);

REQUIRE(ray_tracing_interface->num_registered_volumes() == 1);
REQUIRE(rti->num_registered_volumes() == 1);
}
2 changes: 1 addition & 1 deletion tests/test_closest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TEST_CASE("Test Mesh Mock")
REQUIRE(mm->num_surfaces() == 6);
REQUIRE(mm->num_volume_elements(1) == 12);

std::shared_ptr<RayTracingInterface> rti = std::make_shared<RayTracingInterface>();
std::shared_ptr<RayTracer> rti = std::make_shared<RayTracer>();

rti->register_all_volumes(mm);

Expand Down
50 changes: 0 additions & 50 deletions tests/test_initialize.cpp

This file was deleted.

Loading

0 comments on commit d2f9a6b

Please sign in to comment.