Skip to content

Commit

Permalink
Adding a find_volume test program
Browse files Browse the repository at this point in the history
  • Loading branch information
pshriwise committed Jan 5, 2024
1 parent b001729 commit cd4a9da
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/dagmc/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ set(SRC_FILES ray_fire_test.cpp)
dagmc_install_exe(ray_fire_test)
set(SRC_FILES test_geom.cpp)
dagmc_install_exe(test_geom)
set(SRC_FILES find_vol.cpp)
dagmc_install_exe(find_vol)
80 changes: 80 additions & 0 deletions src/dagmc/tools/find_vol.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <math.h>
#include <stdlib.h>

#include <iostream>
#include <limits>
#include <vector>

#include "DagMC.hpp"
#include "MBTagConventions.hpp"
#include "moab/Core.hpp"
#include "moab/Interface.hpp"

#define CHKERR \
if (MB_SUCCESS != rval) return rval

using namespace moab;

int main(int argc, char* argv[]) {
ErrorCode rval;

if (argc != 5 && argc != 8) {
std::cerr << "Usage: " << argv[0] << " <mesh_filename> "
<< "<xxx> <yyy> <zzz> [<uuu> <vvv> <www>]" << std::endl;
return 1;
}

char* filename = argv[1];
double xxx = atof(argv[2]);
double yyy = atof(argv[3]);
double zzz = atof(argv[4]);
double uuu = 0;
double vvv = 0;
double www = 0;

if (argc > 5) {
uuu = atof(argv[5]);
vvv = atof(argv[6]);
www = atof(argv[7]);
}

std::cout << "Searching for volume containing:" << std::endl
<< "(x,y,z) = (" << xxx << "," << yyy << "," << zzz << ")"
<< std::endl
<< " of geometry " << filename
<< std::endl;

DagMC dagmc{};
rval = dagmc.load_file(filename);
if (MB_SUCCESS != rval) {
std::cerr << "Failed to load file." << std::endl;
return 2;
}
rval = dagmc.init_OBBTree();
if (MB_SUCCESS != rval) {
std::cerr << "Failed to initialize DagMC." << std::endl;
return 2;
}

double xyz[3] = {xxx, yyy, zzz};
double uvw[3] = {uuu, vvv, www};
int inside {0};

int volume {-1};
for (int vol = 1; vol <= dagmc.num_entities(3); ++vol) {
EntityHandle volHandle = dagmc.entity_by_index(3, vol);
rval = dagmc.point_in_volume(volHandle, xyz, inside);
if (inside != 0) {
volume = vol;
break;
}
}

if (volume >= 0) {
int volume_id = dagmc.id_by_index(3, volume);
std::cout << "Point is inside volume " << volume_id << std::endl;
} else {
std::cout << "Point is outside all volumes" << std::endl;
}

}

0 comments on commit cd4a9da

Please sign in to comment.