[MOAB-dev] commit/MOAB: danwu: Merged master into error_handling_enhancement

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Mar 27 13:50:47 CDT 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/5d3eb97e31f9/
Changeset:   5d3eb97e31f9
Branch:      error_handling_enhancement
User:        danwu
Date:        2014-03-27 19:50:43
Summary:     Merged master into error_handling_enhancement
Affected #:  14 files

diff --git a/.gitignore b/.gitignore
index 4b78fb6..8acb6bb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -130,6 +130,9 @@ test/bsp_tree_test
 test/CMakeLists.txt
 test/coords_connect_iterate
 test/cropvol_test
+test/dagmc/dagmc_pointinvol_test
+test/dagmc/dagmc_rayfire_test
+test/dagmc/dagmc_simple_test
 test/dual/dual_test
 test/elem_eval_test
 test/file_options_test
@@ -156,8 +159,10 @@ test/io/gmsh_test
 test/io/ideas_test
 test/io/nastran_test
 test/io/read_cgm_basic_test
+test/io/read_cgm_connectivity_test
+test/io/read_cgm_group_test
 test/io/read_cgm_load_test
-test/io/read_cgm_test
+test/io/read_cgm_senses_test
 test/io/read_mpas_nc
 test/io/read_nc
 test/io/read_ucd_nc

diff --git a/MeshFiles/unittest/Makefile.am b/MeshFiles/unittest/Makefile.am
index ab3e23e..bc4f522 100644
--- a/MeshFiles/unittest/Makefile.am
+++ b/MeshFiles/unittest/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = io
+SUBDIRS = io dagmc iGeom
 
 EXTRA_DIST  = 125hex.g \
               16_unmerged_hex.h5m \

diff --git a/MeshFiles/unittest/dagmc/Makefile.am b/MeshFiles/unittest/dagmc/Makefile.am
new file mode 100644
index 0000000..0643ad9
--- /dev/null
+++ b/MeshFiles/unittest/dagmc/Makefile.am
@@ -0,0 +1 @@
+EXTRA_DIST =  test_geom.h5m

diff --git a/MeshFiles/unittest/dagmc/test_geom.h5m b/MeshFiles/unittest/dagmc/test_geom.h5m
new file mode 100644
index 0000000..18e1d36
Binary files /dev/null and b/MeshFiles/unittest/dagmc/test_geom.h5m differ

diff --git a/MeshFiles/unittest/iGeom/Makefile.am b/MeshFiles/unittest/iGeom/Makefile.am
new file mode 100644
index 0000000..203b676
--- /dev/null
+++ b/MeshFiles/unittest/iGeom/Makefile.am
@@ -0,0 +1 @@
+EXTRA_DIST = shell.h5m

diff --git a/configure.ac b/configure.ac
index 82bf72b..83d8ea5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1223,6 +1223,7 @@ AC_CONFIG_FILES([Makefile
                  src/parallel/Makefile
                  src/oldinc/Makefile
                  test/Makefile
+		 test/dagmc/Makefile
                  test/h5file/Makefile
                  test/dual/Makefile
                  test/obb/Makefile
@@ -1254,6 +1255,8 @@ AC_CONFIG_FILES([Makefile
                  MeshFiles/Makefile
                  MeshFiles/unittest/Makefile
                  MeshFiles/unittest/io/Makefile
+                 MeshFiles/unittest/iGeom/Makefile
+                 MeshFiles/unittest/dagmc/Makefile
                  ])
 AC_CONFIG_COMMANDS([src/MOAB_FCDefs.h],
   [sed -e "s/FC_FUNC/MOAB_FC_FUNC/" src/FCDefs.h >src/MOAB_FCDefs.h])

diff --git a/test/Makefile.am b/test/Makefile.am
index 4797a49..cf79fd3 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = . io dual obb perf
+SUBDIRS = . io dual obb perf dagmc
 if HDF5_FILE
   SUBDIRS += h5file
 endif

diff --git a/test/dagmc/Makefile.am b/test/dagmc/Makefile.am
new file mode 100644
index 0000000..d092176
--- /dev/null
+++ b/test/dagmc/Makefile.am
@@ -0,0 +1,28 @@
+LDADD = $(top_builddir)/src/libMOAB.la $(top_builddir)/tools/dagmc/DagMC.lo
+
+MESHDIR = $(top_srcdir)/MeshFiles/unittest
+
+AM_CPPFLAGS += -DSRCDIR=$(srcdir) \
+               -DMESHDIR=$(MESHDIR) \
+               -I$(builddir) -I.. -I$(srcdir)/.. \
+               -I$(top_builddir)/src \
+               -I$(top_srcdir)/src \
+               -I$(top_srcdir)/src/io \
+               -I$(top_srcdir)/src/parallel \
+               -I$(top_srcdir)/tools/dagmc 
+TESTS = 
+if HDF5_FILE
+ TESTS += dagmc_simple_test \
+        dagmc_rayfire_test \
+        dagmc_pointinvol_test
+endif
+check_PROGRAMS = $(TESTS)
+
+dagmc_simple_test_SOURCES = $(srcdir)/../TestUtil.hpp dagmc_simple_test.cpp
+dagmc_simple_test_CXXFLAGS = $(CGM_CPPFLAGS) $(CXXFLAGS) $(CGM_LIBS)
+dagmc_rayfire_test_SOURCES = $(srcdir)/../TestUtil.hpp dagmc_rayfire_test.cpp
+dagmc_rayfire_test_CXXFLAGS = $(CGM_CPPFLAGS) $(CXXFLAGS) $(CGM_LIBS)
+dagmc_pointinvol_test_SOURCES = $(srcdir)/../TestUtil.hpp dagmc_pointinvol_test.cpp
+dagmc_pointinvol_test_CXXFLAGS = $(CGM_CPPFLAGS) $(CXXFLAGS) $(CGM_LIBS)
+
+

diff --git a/test/dagmc/dagmc_pointinvol_test.cpp b/test/dagmc/dagmc_pointinvol_test.cpp
new file mode 100644
index 0000000..47ee7c1
--- /dev/null
+++ b/test/dagmc/dagmc_pointinvol_test.cpp
@@ -0,0 +1,283 @@
+#include <iostream>
+#include "moab/Interface.hpp"
+#ifndef IS_BUILDING_MB
+#define IS_BUILDING_MB
+#endif
+#include "TestUtil.hpp"
+#include "Internals.hpp"
+#include "moab/Core.hpp"
+
+#include "DagMC.hpp"
+
+using namespace moab;
+
+using moab::DagMC;
+
+#define DAG DagMC::instance()
+
+#define CHKERR(A) do { if (MB_SUCCESS != (A)) { \
+  std::cerr << "Failure (error code " << (A) << ") at " __FILE__ ":" \
+            << __LINE__ << std::endl; \
+  return A; } } while(false)
+
+#ifdef MESHDIR
+static const char input_file[] = STRINGIFY(MESHDIR) "/dagmc/test_geom.h5m";
+#else
+static const char input_file[] = STRINGIFY(MESHDIR) "/dagmc/test_geom.h5m";
+#endif
+
+
+void dagmc_setup_test() 
+{
+  ErrorCode rval = DAG->load_file(input_file); // open the Dag file
+  CHECK_ERR(rval);
+  rval = DAG->init_OBBTree();
+  CHECK_ERR(rval);
+
+  int num_vols = DAG->num_entities(3); 
+  EntityHandle vol;
+  for ( int i = 0 ; i < num_vols ; i++ )
+    {
+      vol = DAG->entity_by_index(3,i);
+    }
+  //EntityHandle volume = 12682136550675316765;
+  //CHECK_EQUAL(volume,vol);
+}
+
+void dagmc_point_in()
+{
+  int result = 0;
+  int expected_result=1;
+  double xyz[3]={0.0,0.0,0.0};
+  int vol_idx=1;
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+  ErrorCode rval = DAG->point_in_volume(vol_h,xyz,result);
+  CHECK_ERR(rval);
+  CHECK_EQUAL(expected_result,result);
+}
+
+int dagmc_point_in_vol_dir(double origin[3],double dir[3],int vol_idx)
+{
+  int result = 0;
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+  double xyz[3];
+  double next_surf_dist;
+  EntityHandle next_surf;
+
+  // normalise the vector
+  double dir_norm = (dir[0]*dir[0])+(dir[1]*dir[1])+(dir[2]*dir[2]);
+
+  dir[0]=dir[0]/sqrt(dir_norm);
+  dir[1]=dir[1]/sqrt(dir_norm);
+  dir[2]=dir[2]/sqrt(dir_norm);
+
+  ErrorCode rval = DAG->ray_fire(vol_h,origin,dir,next_surf,next_surf_dist);
+  
+  xyz[0]=origin[0]+(next_surf_dist*dir[0]);
+  xyz[1]=origin[1]+(next_surf_dist*dir[1]);
+  xyz[2]=origin[2]+(next_surf_dist*dir[2]);
+
+  std::cout << xyz[0] << " " << xyz[1] << " " << xyz[2] << std::endl;
+
+  rval = DAG->point_in_volume(vol_h,xyz,result,dir);
+  CHECK_ERR(rval);
+  return result;
+}
+
+void dagmc_point_in_vol_1()
+{
+  double dir[3]={ -1.0,0.0,0.0};
+  double origin[3]={0.0,0.0,0.0};
+  int vol_idx=1;
+  int expected_result=1;
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+  CHECK_EQUAL(expected_result,result);
+
+}
+
+void dagmc_point_in_vol_2()
+{
+  int expected_result=1;
+  int vol_idx=1;
+  double dir[3]={ 1.0,0.0,0.0};
+  double origin[3]={0.0,0.0,0.0};
+  
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+}
+
+void dagmc_point_in_vol_3()
+{
+  int expected_result=1;
+  int vol_idx=1;
+  double dir[3]={ 0.0,-1.0,0.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+}
+
+void dagmc_point_in_vol_4()
+{
+  int expected_result=1;
+  int vol_idx=1;
+  double dir[3]={ 0.0,1.0,0.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+
+}
+  
+void dagmc_point_in_vol_5()
+{
+  int expected_result=1;
+  int vol_idx=1;
+  double dir[3]={ 0.0,0.0,-1.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+}
+
+void dagmc_point_in_vol_6()
+{
+  int expected_result=1;
+  int vol_idx=1;
+  double dir[3]={ 0.0,0.0,1.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+
+}
+
+void dagmc_point_on_corner_1()
+{
+  int expected_result=1;
+  int vol_idx=1;
+  double dir[3]={ 1.0,1.0,1.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+}
+
+void dagmc_point_on_corner_2()
+{
+  int expected_result=1;
+  int vol_idx=1;
+  double dir[3]={ -1.0,1.0,1.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+}
+
+void dagmc_point_on_corner_3()
+{
+  int expected_result = 1;
+  int vol_idx=1;
+  double dir[3]={ 1.0,1.0,-1.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+}
+
+void dagmc_point_on_corner_4()
+{
+  int expected_result = 1;
+  int vol_idx=1;
+  double dir[3]={ -1.0,1.0,-1.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+}
+
+void dagmc_point_on_corner_5()
+{
+  int expected_result = 1;
+  int vol_idx=1;
+  double dir[3]={ 1.0,-1.0,1.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+}
+
+void dagmc_point_on_corner_6()
+{
+  int expected_result = 1;
+  int vol_idx=1;
+  double dir[3]={ -1.0,-1.0,1.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+}
+
+void dagmc_point_on_corner_7()
+{
+  int expected_result = 1;
+  int vol_idx=1;
+  double dir[3]={ 1.0,-1.0,-1.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+}
+
+void dagmc_point_on_corner_8()
+{
+  int expected_result = 1;
+  int vol_idx=1;
+  double dir[3]={ -1.0,-1.0,-1.0};
+  double origin[3]={0.0,0.0,0.0};
+
+  int result = dagmc_point_in_vol_dir(origin,dir,vol_idx);
+
+  CHECK_EQUAL(expected_result,result);
+}
+
+int main(int /* argc */, char** /* argv */)
+{
+  int result = 0;
+  result += RUN_TEST( dagmc_setup_test );     // setup problem
+  result += RUN_TEST( dagmc_point_in );       // point in centre
+  // rays fired along cardinal directions 
+  result += RUN_TEST( dagmc_point_in_vol_1);       // point in centre
+  result += RUN_TEST( dagmc_point_in_vol_2);       // point in centre
+  result += RUN_TEST( dagmc_point_in_vol_3);       // point in centre
+  result += RUN_TEST( dagmc_point_in_vol_4);       // point in centre
+  result += RUN_TEST( dagmc_point_in_vol_5);       // point in centre
+  result += RUN_TEST( dagmc_point_in_vol_6);       // point in centre
+  // rays fired at nodes
+  result += RUN_TEST( dagmc_point_on_corner_1); 
+  result += RUN_TEST( dagmc_point_on_corner_2); 
+  result += RUN_TEST( dagmc_point_on_corner_3); 
+  result += RUN_TEST( dagmc_point_on_corner_4); 
+
+		      //  result += RUN_TEST( dagmc_point_in({0.0,0.0,5.0});       // point in centre
+		      //  result += RUN_TEST( dagmc_point_in({0.0,0.0,-5.0});       // point in centre
+		      //  result += RUN_TEST( dagmc_point_in({0.0,5.0,0.0});       // point in centre
+		      //  result += RUN_TEST( dagmc_point_in({0.0,-5.0,0.0});       // point in centre
+		      //  result += RUN_TEST( dagmc_point_in({5.0,0.0,0.0});       // point in centre
+		      //  result += RUN_TEST( dagmc_point_in({-5.0,0.0,0.0});       // point in centre
+
+  return result;
+}

diff --git a/test/dagmc/dagmc_rayfire_test.cpp b/test/dagmc/dagmc_rayfire_test.cpp
new file mode 100644
index 0000000..57aa625
--- /dev/null
+++ b/test/dagmc/dagmc_rayfire_test.cpp
@@ -0,0 +1,180 @@
+#include <iostream>
+#include "moab/Interface.hpp"
+#ifndef IS_BUILDING_MB
+#define IS_BUILDING_MB
+#endif
+#include "TestUtil.hpp"
+#include "Internals.hpp"
+#include "moab/Core.hpp"
+
+#include "DagMC.hpp"
+
+using namespace moab;
+
+using moab::DagMC;
+
+#define DAG DagMC::instance()
+
+#define CHKERR(A) do { if (MB_SUCCESS != (A)) { \
+  std::cerr << "Failure (error code " << (A) << ") at " __FILE__ ":" \
+            << __LINE__ << std::endl; \
+  return A; } } while(false)
+
+#ifdef MESHDIR
+static const char input_file[] = STRINGIFY(MESHDIR) "/dagmc/test_geom.h5m";
+#else
+static const char input_file[] = STRINGIFY(MESHDIR) "/dagmc/test_geom.h5m";
+#endif
+
+double eps = 1.0e-6;
+
+void dagmc_setup_test() 
+{
+  ErrorCode rval = DAG->load_file(input_file); // open the Dag file
+  CHECK_ERR(rval);
+  rval = DAG->init_OBBTree();
+  CHECK_ERR(rval);
+
+  int num_vols = DAG->num_entities(3); 
+  EntityHandle vol_h;
+  for ( int i = 0 ; i < num_vols ; i++ )
+    {
+      vol_h = DAG->entity_by_index(3,i);
+    }
+  // EntityHandle volume = 12682136550675316765;
+  // CHECK_EQUAL(volume,vol);
+}
+
+void dagmc_origin_face_rayfire()
+{
+  int vol_idx = 1;
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+  double dir[3]={-1.0,0.0,0.0};
+  double origin[3]={0.0,0.0,0.0};
+  double next_surf_dist;
+  EntityHandle next_surf;
+  DAG->ray_fire(vol_h,origin,dir,next_surf,next_surf_dist);
+  double expected_next_surf_dist=5.0;
+  CHECK_REAL_EQUAL(expected_next_surf_dist,next_surf_dist,eps);
+}
+
+void dagmc_outside_face_rayfire()
+{
+  int vol_idx = 1;
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+  double dir[3]={1.0,0.0,0.0}; // ray along x direction
+  double origin[3]={-10.0,0.0,0.0}; // origin at -10 0 0 
+  double next_surf_dist;
+  EntityHandle next_surf;
+  DAG->ray_fire(vol_h,origin,dir,next_surf,next_surf_dist);
+  std::cout << next_surf_dist << std::endl;
+  double expected_next_surf_dist=15.0;
+  CHECK_REAL_EQUAL(expected_next_surf_dist,next_surf_dist,eps);
+}
+
+void dagmc_outside_face_rayfire_orient_exit()
+{
+  DagMC::RayHistory history;
+  int vol_idx = 1;
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+  double dir[3]={1.0,0.0,0.0}; // ray along x direction
+  double origin[3]={-10.0,0.0,0.0}; // origin at -10 0 0 
+  double next_surf_dist;
+  EntityHandle next_surf;
+  DAG->ray_fire(vol_h,origin,dir,next_surf,next_surf_dist,&history,0,1);
+  std::cout << next_surf_dist << std::endl;
+  double expected_next_surf_dist=15.0;
+  CHECK_REAL_EQUAL(expected_next_surf_dist,next_surf_dist,eps);
+}
+
+void dagmc_outside_face_rayfire_orient_entrance()
+{
+  DagMC::RayHistory history;
+  int vol_idx = 1;
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+  double dir[3]={1.0,0.0,0.0}; // ray along x direction
+  double origin[3]={-10.0,0.0,0.0}; // origin at -10 0 0 
+  double next_surf_dist;
+  EntityHandle next_surf;
+  DAG->ray_fire(vol_h,origin,dir,next_surf,next_surf_dist,&history,0.0,-1);
+  std::cout << next_surf_dist << std::endl;
+  double expected_next_surf_dist=5.0;
+  CHECK_REAL_EQUAL(expected_next_surf_dist,next_surf_dist,eps);
+}
+
+void dagmc_outside_face_rayfire_history_fail()
+{
+  DagMC::RayHistory history;
+  int vol_idx = 1;
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+  double dir[3]={1.0,0.0,0.0}; // ray along x direction
+  double origin[3]={-10.0,0.0,0.0}; // origin at -10 0 0 
+  double xyz[3];
+  double next_surf_dist;
+  EntityHandle next_surf;
+
+  history.reset(); 
+
+  // ray fired exactly along boundary shared by 2 facets on a single surface,
+  // needs two ray_fires to cross, this is expected and ok
+
+  // first ray fire with history
+  DAG->ray_fire(vol_h,origin,dir,next_surf,next_surf_dist,&history,0,1);
+  // second ray fire with history
+  DAG->ray_fire(vol_h,xyz,dir,next_surf,next_surf_dist,&history,0,1);
+  // this fire should hit graveyard, i.e. next_surf = 0
+  DAG->ray_fire(vol_h,xyz,dir,next_surf,next_surf_dist,&history,0,1);
+
+  // using history with this geom, there should be no next surface, i.e. 0
+  EntityHandle ZERO = 0;
+  CHECK_EQUAL(ZERO ,next_surf);
+}
+
+void dagmc_outside_face_rayfire_history()
+{
+  DagMC::RayHistory history;
+  int vol_idx = 1;
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+  double dir[3]={1.0,0.0,0.0}; // ray along x direction
+  double origin[3]={-10.0,0.0,0.0}; // origin at -10 0 0 
+  double xyz[3];
+  double next_surf_dist;
+  EntityHandle next_surf;
+
+  history.reset(); 
+  // first ray fire with history
+  DAG->ray_fire(vol_h,origin,dir,next_surf,next_surf_dist,&history,0,1);
+  std::cout << next_surf << " " << history.size() << std::endl;
+  // second ray fire with history
+
+  xyz[0]=origin[0]+(next_surf_dist*dir[0]);
+  xyz[1]=origin[1]+(next_surf_dist*dir[1]);
+  xyz[2]=origin[2]+(next_surf_dist*dir[2]);
+
+  // ray fired execacyl
+
+  DAG->ray_fire(vol_h,xyz,dir,next_surf,next_surf_dist,&history,0,1);
+
+  DAG->ray_fire(vol_h,xyz,dir,next_surf,next_surf_dist,&history,0,1);
+
+
+  // using history with this geom, there should be no next surface, i.e. 0
+  EntityHandle ZERO = 0;
+  CHECK_EQUAL(ZERO ,next_surf);
+}
+
+
+int main(int /* argc */, char** /* argv */)
+{
+  int result = 0;
+  result += RUN_TEST( dagmc_setup_test );     // setup problem
+  // rays fired along cardinal directions 
+  result += RUN_TEST( dagmc_origin_face_rayfire );       // point in centre
+  result += RUN_TEST( dagmc_outside_face_rayfire );
+  result += RUN_TEST( dagmc_outside_face_rayfire_orient_exit ); // fire ray from point outside volume looking for exit intersections
+  result += RUN_TEST( dagmc_outside_face_rayfire_orient_entrance ); // fire ray from point outside volume looking for entrance intersection
+  result += RUN_TEST( dagmc_outside_face_rayfire_history_fail ); // fire ray from point outside geometry using ray history
+  result += RUN_TEST( dagmc_outside_face_rayfire_history ); // fire ray from point outside geometry using ray history
+
+  return result;
+}

diff --git a/test/dagmc/dagmc_simple_test.cpp b/test/dagmc/dagmc_simple_test.cpp
new file mode 100644
index 0000000..bf253f6
--- /dev/null
+++ b/test/dagmc/dagmc_simple_test.cpp
@@ -0,0 +1,137 @@
+#include <iostream>
+#include "moab/Interface.hpp"
+#ifndef IS_BUILDING_MB
+#define IS_BUILDING_MB
+#endif
+#include "TestUtil.hpp"
+#include "Internals.hpp"
+#include "moab/Core.hpp"
+
+#include "DagMC.hpp"
+
+using namespace moab;
+
+using moab::DagMC;
+
+#define DAG DagMC::instance()
+
+#define CHKERR(A) do { if (MB_SUCCESS != (A)) { \
+  std::cerr << "Failure (error code " << (A) << ") at " __FILE__ ":" \
+            << __LINE__ << std::endl; \
+  return A; } } while(false)
+
+#ifdef MESHDIR
+static const char input_file[] = STRINGIFY(MESHDIR) "/dagmc/test_geom.h5m";
+#else
+static const char input_file[] = STRINGIFY(MESHDIR) "/dagmc/test_geom.h5m";
+#endif
+
+
+void dagmc_load_file() 
+{
+  ErrorCode rval = DAG->load_file(input_file); // open the Dag file
+  CHECK_ERR(rval);
+}
+
+void dagmc_build_obb() 
+{
+  ErrorCode rval = DAG->init_OBBTree();
+  CHECK_ERR(rval);
+}
+
+void dagmc_num_vols()
+{
+  int expect_num_vols=2;
+  int num_vols = DAG->num_entities(3); 
+  CHECK_EQUAL(expect_num_vols,num_vols);
+}
+
+void dagmc_entity_handle()
+{
+  int num_vols = DAG->num_entities(3); 
+  EntityHandle vol_h;
+  for ( int i = 0 ; i < num_vols ; i++ )
+    {
+      vol_h = DAG->entity_by_index(3,i);
+    }
+  //EntityHandle expect_vol_h = 12682136550675316765;
+  //CHECK_EQUAL(expect_vol_h,vol_h);
+}
+
+void dagmc_point_in()
+{
+  int result = 0;
+  int expect_result=1;
+  int vol_idx=1;
+  double xyz[3]={0.0,0.0,0.0};
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+  ErrorCode rval = DAG->point_in_volume(vol_h,xyz,result);
+  CHECK_EQUAL(expect_result,result);
+}
+
+void dagmc_rayfire()
+{
+  const double eps = 1e-6; // epsilon for test, faceting tol?
+
+  int vol_idx=1;
+  // note model is cube of side 10, centred at 0,0,0, so ray fire along
+  // any unit direction should be exactly 5.0
+  double xyz[3]={0.0,0.0,0.0};
+  double dir[3]={0.0,0.0,1.0}; 
+  EntityHandle next_surf;
+  double next_surf_dist;
+  double expect_next_surf_dist=5.0;
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+
+  ErrorCode rval = DAG->ray_fire(vol_h,xyz,dir,next_surf,next_surf_dist);
+  CHECK_REAL_EQUAL(expect_next_surf_dist,next_surf_dist,eps); 
+}
+
+void dagmc_closest_to()
+{
+  const double eps = 1e-6; // epsilon for test, faceting tol?
+
+  int vol_idx=1;
+  // note model is cube of side 10, centred at 0,0,0, so ray fire along
+  // any unit direction should be exactly 5.0
+  double xyz[3]={-6.0,0.0,0.0};
+  double distance; // distance from point to nearest surface
+  double expect_distance=1.0;
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+
+  ErrorCode rval = DAG->closest_to_location(vol_h,xyz,distance);
+  // distance should be 1.0 cm
+  CHECK_REAL_EQUAL(expect_distance,distance,eps); 
+}
+
+void dagmc_test_boundary()
+{
+  int vol_idx=1;
+  EntityHandle vol_h = DAG->entity_by_index(3,vol_idx);
+  int surf_idx=1;
+  EntityHandle surf_h = DAG->entity_by_index(2,surf_idx);
+
+  double xyz[3]={0.0,0.0,5.0};
+  double dir[3]={0.0,0.0,1.0}; 
+  int result;
+  int expect_result=0;
+
+  ErrorCode rval = DAG->test_volume_boundary(vol_h,surf_h,xyz,dir,result);
+  // check ray leaving volume
+  CHECK_EQUAL(expect_result,result);  
+}
+  
+int main(int /* argc */, char** /* argv */)
+{
+  int result = 0;
+  result += RUN_TEST( dagmc_load_file );     // test ray fire
+  result += RUN_TEST( dagmc_build_obb );     // build the obb
+  result += RUN_TEST( dagmc_num_vols  );     // make sure the num of vols correct
+  // result += RUN_TEST( dagmc_entity_handle);  // check the entity handle correct
+  result += RUN_TEST( dagmc_point_in);       // check entity by point
+  result += RUN_TEST( dagmc_rayfire ) ;      // ensure ray fire distance is correct
+  result += RUN_TEST( dagmc_closest_to );    // check the distance to surface nearest point
+  result += RUN_TEST( dagmc_test_boundary ); // check particle entering leaving
+
+  return result;
+}

diff --git a/tools/dagmc/DagMC.cpp b/tools/dagmc/DagMC.cpp
index 87f84cb..6e2260a 100755
--- a/tools/dagmc/DagMC.cpp
+++ b/tools/dagmc/DagMC.cpp
@@ -536,6 +536,7 @@ ErrorCode DagMC::ray_fire(const EntityHandle vol,
                           const double point[3], const double dir[3],
                           EntityHandle& next_surf, double& next_surf_dist,
                           RayHistory* history, double user_dist_limit,
+			  int ray_orientation, 
                           OrientedBoxTreeTool::TrvStats* stats ) { 
 
   // take some stats that are independent of nps
@@ -591,9 +592,6 @@ ErrorCode DagMC::ray_fire(const EntityHandle vol,
   // min_tolerance_intersections is passed but not used in this call
   const int min_tolerance_intersections = 0;
 
-  // only get exit intersections
-  const int desired_orientation = 1;
-
   // numericalPrecision is used for box.intersect_ray and find triangles in the
   // neighborhood of edge/node intersections.
   rval = obbTree.ray_intersect_sets( dists, surfs, facets,
@@ -601,7 +599,7 @@ ErrorCode DagMC::ray_fire(const EntityHandle vol,
                                      min_tolerance_intersections,
                                      point, dir, &nonneg_ray_len,
                                      stats, &neg_ray_len, &vol, &senseTag, 
-                                     &desired_orientation, 
+                                     &ray_orientation, 
                                      history ? &(history->prev_facets) : NULL );
   assert( MB_SUCCESS == rval );
   if(MB_SUCCESS != rval) return rval;

diff --git a/tools/dagmc/DagMC.hpp b/tools/dagmc/DagMC.hpp
index 9e71601..fe39082 100755
--- a/tools/dagmc/DagMC.hpp
+++ b/tools/dagmc/DagMC.hpp
@@ -170,6 +170,9 @@ public:
    *                by this query will also be added to the history.
    * @param dist_limit Optional distance limit.  If provided and > 0, no intersections at a 
    *                distance further than this value will be returned.
+   * @param ray_orientation Optional ray orientation. If provided determines intersections 
+   *                along the normal provided, e.g. if -1 allows intersections back along the
+   *                the ray direction, Default is 1, i.e. exit intersections
    * @param stats Optional TrvStats object used to measure performance of underlying OBB
    *              ray-firing query.  See OrientedBoxTreeTool.hpp for details.
    * 
@@ -178,6 +181,7 @@ public:
                      const double ray_start[3], const double ray_dir[3],
                      EntityHandle& next_surf, double& next_surf_dist,
                      RayHistory* history = NULL, double dist_limit = 0,
+		     int ray_orientation = 1, 
                      OrientedBoxTreeTool::TrvStats* stats = NULL );
   
   /**\brief Test if a point is inside or outside a volume 

diff --git a/tools/dagmc/ray_fire_test.cc b/tools/dagmc/ray_fire_test.cc
index 7e5ce30..cc73a38 100644
--- a/tools/dagmc/ray_fire_test.cc
+++ b/tools/dagmc/ray_fire_test.cc
@@ -277,7 +277,8 @@ int main( int argc, char* argv[] )
       ray_t ray = rays[i];
       std::cout << " Ray: point = " << ray.p << " dir = " << ray.v << std::endl;
 
-      rval = dagmc.ray_fire( vol, ray.p.array(), ray.v.array(), surf, dist, NULL, 0, trv_stats );
+      // added ray orientation
+      rval = dagmc.ray_fire( vol, ray.p.array(), ray.v.array(), surf, dist, NULL, 0, 1, trv_stats );
 
       if(MB_SUCCESS != rval) {
         std::cerr << "ERROR: ray_fire() failed!" << std::endl;
@@ -326,8 +327,8 @@ int main( int argc, char* argv[] )
               << " " << uvw << " " << uvw%uvw << std::endl;
     uavg += uvw[0]; vavg += uvw[1]; wavg += uvw[2];
 #endif
-    
-    dagmc.ray_fire(vol, xyz.array(), uvw.array(), surf, dist, NULL, 0, trv_stats );
+    // added ray orientation
+    dagmc.ray_fire(vol, xyz.array(), uvw.array(), surf, dist, NULL, 0, 1, trv_stats );
 
     if( surf == 0){ random_rays_missed++; }

Repository URL: https://bitbucket.org/fathomteam/moab/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the moab-dev mailing list