[MOAB-dev] r1531 - in MOAB/trunk: . refiner

pebay at mcs.anl.gov pebay at mcs.anl.gov
Wed Jan 16 19:43:10 CST 2008


Author: pebay
Date: 2008-01-16 19:43:10 -0600 (Wed, 16 Jan 2008)
New Revision: 1531

Modified:
   MOAB/trunk/CMakeLists.txt
   MOAB/trunk/refiner/MBEdgeSizeEvaluator.cpp
   MOAB/trunk/refiner/MBEdgeSizeEvaluator.hpp
   MOAB/trunk/refiner/MBEntityRefiner.hpp
   MOAB/trunk/refiner/MBSimplexTemplateRefiner.cpp
   MOAB/trunk/refiner/MBSimplexTemplateRefiner.hpp
   MOAB/trunk/refiner/MBSimplexTemplateTagAssigner.cpp
   MOAB/trunk/refiner/MBSimplexTemplateTagAssigner.hpp
Log:
ENH: update CMakeLists in order to support template specialization when available.
ENH: refiner progress


Modified: MOAB/trunk/CMakeLists.txt
===================================================================
--- MOAB/trunk/CMakeLists.txt	2008-01-17 01:41:29 UTC (rev 1530)
+++ MOAB/trunk/CMakeLists.txt	2008-01-17 01:43:10 UTC (rev 1531)
@@ -23,6 +23,9 @@
     LIBRARY_OUTPUT_PATH
   )
 
+  # Compiler defines... this should really be in a config file.
+  set( MOAB_DEFINES "" )
+
   include ( CheckIncludeFile )
   include ( CheckFunctionExists )
   include ( CheckTypeSize )
@@ -70,6 +73,11 @@
     set ( MOAB_HAVE_PTRDIFF_T ${HAVE_PTRDIFF_T} )
   endif ( NOT MOAB_FORCE_64_BIT_HANDLES AND NOT MOAB_FORCE_32_BIT_HANDLES )
 
+  try_compile( TEMPLATE_DEFS_INCLUDED ${MOAB_BINARY_DIR} ${MOAB_SOURCE_DIR}/cmake/TemplateSpecialization.cxx OUTPUT_VARIABLE BLORT )
+  if ( TEMPLATE_DEFS_INCLUDED )
+    set ( MOAB_DEFINES "${MOAB_DEFINES} -DTEMPLATE_DEFS_INCLUDED" )
+  endif ( TEMPLATE_DEFS_INCLUDED )
+
   # find Verdict
   find_package( verdict REQUIRED )
 
@@ -96,9 +104,6 @@
   # iMesh
   option ( MOAB_BUILD_IMESH        "Build the iMesh interface?"           ON )
 
-  # Compiler defines... this should really be in a config file.
-  set( MOAB_DEFINES "" )
-
   # MOAB Library
   set ( MOAB_LIB_SRCS
     AEntityFactory.cpp
@@ -145,6 +150,7 @@
     SequenceManager.cpp
     SparseTagCollections.cpp
     StructuredElementSeq.cpp
+    TagInfo.cpp
     TagServer.cpp
     TagInfo.cpp
     Tqdcfr.cpp

Modified: MOAB/trunk/refiner/MBEdgeSizeEvaluator.cpp
===================================================================
--- MOAB/trunk/refiner/MBEdgeSizeEvaluator.cpp	2008-01-17 01:41:29 UTC (rev 1530)
+++ MOAB/trunk/refiner/MBEdgeSizeEvaluator.cpp	2008-01-17 01:43:10 UTC (rev 1531)
@@ -78,29 +78,19 @@
   *\brief Return the number of bytes to allocate for tag data per point.
   */
 
-/**\brief Given endpoint coordinates and tag values plus midpoint coordinates, compute midpoint tag values.
+/**\fn int MBEdgeSizeEvaluator::get_number_of_vertex_tags() const
+  *\brief Return the number of tags that will be output with each new vertex.
+  */
+
+/**\brief Return the tag handle and its offset in the array of tag data of each vertex.
   *
-  * Normally, this function will be invoked by the MBEntityRefiner before evaluate_edge is called.
-  * However, if evaluate_edge() changes the parametric coordinates of the midpoint,
-  * it should call evaluate_tags_at_midpoint() again to update any tag values;
-  * that is why this function is a member of MBEdgeSizeEvaluator and not MBEntityRefiner.
-  *
-  * @param[in] c0 Pointer to endpoint 0 coordinates. The parametric coordinates (3) are followed by world coordinates (3).
-  * @param[in] t0 Pointer to endpoint 0 tag values.
-  * @param[in] cm Pointer to midpoint coordinates. The parametric coordinates (3) are followed by world coordinates (3).
-  * @param[out] tm Pointer to midpoint tag values.
-  * @param[in] c1 Pointer to endpoint 1 coordinates. The parametric coordinates (3) are followed by world coordinates (3).
-  * @param[in] t1 Pointer to endpoint 1 tag values.
+  * @param[in] i An index into the list of tags for the vertex.
+  * @param[out] tag The tag handle for the $i$-th vertex tag.
+  * @param[out] byte_offset The offset (in bytes) of the start of this tag's data in a vertex tag record.
   */
-void MBEdgeSizeEvaluator::evaluate_tags_at_midpoint( const double* c0, const void* t0, 
-                                                     const double* cm, void* tm, 
-                                                     const double* c1, const void* t1 ) const
+void MBEdgeSizeEvaluator::get_vertex_tag( int i, MBTag& tag, int& byte_offset )
 {
-  (void)c0;
-  (void)t0;
-  (void)cm;
-  (void)tm;
-  (void)c1;
-  (void)t1;
+  std::vector< std::pair< MBTag, int > >::iterator it = this->vertex_tags.begin() + i;
+  tag = it->first;
+  byte_offset = it->second;
 }
-

Modified: MOAB/trunk/refiner/MBEdgeSizeEvaluator.hpp
===================================================================
--- MOAB/trunk/refiner/MBEdgeSizeEvaluator.hpp	2008-01-17 01:41:29 UTC (rev 1530)
+++ MOAB/trunk/refiner/MBEdgeSizeEvaluator.hpp	2008-01-17 01:43:10 UTC (rev 1531)
@@ -45,12 +45,11 @@
 
   void reset_vertex_tags();
   int add_vertex_tag( MBTag tag_handle );
-  int get_vertex_tag_size() { return this->vertex_size; }
-  void evaluate_tags_at_midpoint(
-    const double* c0, const void* t0,
-    const double* cm, void* tm,
-    const double* c1, const void* t1 ) const;
+  int get_vertex_tag_size() const { return this->vertex_size; }
 
+  int get_number_of_vertex_tags() const { return this->vertex_tags.size(); }
+  void get_vertex_tag( int i, MBTag& tag, int& byte_offset );
+
 protected:
   std::vector< std::pair< MBTag, int > > vertex_tags;
   int vertex_size;

Modified: MOAB/trunk/refiner/MBEntityRefiner.hpp
===================================================================
--- MOAB/trunk/refiner/MBEntityRefiner.hpp	2008-01-17 01:41:29 UTC (rev 1530)
+++ MOAB/trunk/refiner/MBEntityRefiner.hpp	2008-01-17 01:43:10 UTC (rev 1531)
@@ -80,6 +80,8 @@
   MBEntityRefiner( MBInterface* );
   virtual ~MBEntityRefiner();
 
+  MBInterface* get_mesh() { return this->mesh; }
+
   virtual bool refine_entity( MBEntityHandle ) = 0;
   virtual unsigned long get_heap_size_bound( int max_recursions ) const = 0;
 

Modified: MOAB/trunk/refiner/MBSimplexTemplateRefiner.cpp
===================================================================
--- MOAB/trunk/refiner/MBSimplexTemplateRefiner.cpp	2008-01-17 01:41:29 UTC (rev 1530)
+++ MOAB/trunk/refiner/MBSimplexTemplateRefiner.cpp	2008-01-17 01:43:10 UTC (rev 1531)
@@ -24,6 +24,7 @@
 MBSimplexTemplateRefiner::MBSimplexTemplateRefiner( MBInterface* mesh )
   : MBEntityRefiner( mesh )
 {
+  this->tag_assigner = new MBSimplexTemplateTagAssigner( this );
 }
 
 /// Empty destructor for good form.
@@ -124,6 +125,30 @@
   return rval;
 }
 
+bool MBSimplexTemplateRefiner::set_tag_assigner( MBSimplexTemplateTagAssigner* ta )
+{ 
+  if ( ta == this->tag_assigner )
+    return false;
+  this->tag_assigner = ta; 
+  if ( ta )
+    this->tag_assigner->set_edge_size_evaluator( this->edge_size_evaluator );
+  return true;
+}
+
+
+bool MBSimplexTemplateRefiner::set_edge_size_evaluator( MBEdgeSizeEvaluator* es ) 
+{ 
+  if ( this->MBEntityRefiner::set_edge_size_evaluator( es ) )
+    {
+    if ( this->tag_assigner )
+      {
+      this->tag_assigner->set_edge_size_evaluator( es );
+      }
+    return true;
+    }
+  return false;
+}
+
 /**\fn unsigned long MBSimplexTemplateRefiner::get_heap_size_bound( int max_recursions ) const
   *\brief Bound on the number of new vertices used to allocate the heap.
   *
@@ -154,6 +179,7 @@
 
   double* midptc;
   void* midptt;
+  int i0, i1;
 
   if ( max_depth-- > 0 )
     {
@@ -165,7 +191,7 @@
     for ( i = 0; i < 6; i++ )
       midptc[i] = ( v0[i] + v1[i] ) / 2.;
 
-    this->edge_size_evaluator->evaluate_tags_at_midpoint( v0, t0, midptc, midptt, v1, t1 );
+    (*this->tag_assigner)( v0, t0, i0, midptc, midptt, v1, t1, i1 );
     edge_code = this->edge_size_evaluator->evaluate_edge( v0, t0, midptc, midptt, v1, t1 );
     }
 
@@ -201,6 +227,7 @@
   void* midpt0t;
   void* midpt1t;
   void* midpt2t;
+  int i0, i1, i2;
 
   if ( max_depth-- > 0 )
     {
@@ -217,9 +244,9 @@
       midpt1c[i] = ( v1[i] + v2[i] ) / 2.;
       midpt2c[i] = ( v2[i] + v0[i] ) / 2.;
       }
-    this->edge_size_evaluator->evaluate_tags_at_midpoint( v0, t0, midpt0c, midpt0t, v1, t1 );
-    this->edge_size_evaluator->evaluate_tags_at_midpoint( v1, t1, midpt1c, midpt1t, v2, t2 );
-    this->edge_size_evaluator->evaluate_tags_at_midpoint( v2, t2, midpt2c, midpt2t, v0, t0 );
+    (*this->tag_assigner)( v0, t0, i0, midpt0c, midpt0t, v1, t1, i1 );
+    (*this->tag_assigner)( v1, t1, i1, midpt1c, midpt1t, v2, t2, i2 );
+    (*this->tag_assigner)( v2, t2, i2, midpt2c, midpt2t, v0, t0, i0 );
     if ( ( move & 1 ) && this->edge_size_evaluator->evaluate_edge( v0, t0, midpt0c, midpt0t, v1, t1 ) )
       edge_code += 1;
     if ( ( move & 2 ) && this->edge_size_evaluator->evaluate_edge( v1, t1, midpt1c, midpt1t, v2, t2 ) )
@@ -329,6 +356,8 @@
   void* midpt4t;
   void* midpt5t;
 
+  int i0, i1, i2, i3;
+
   if ( max_depth-- > 0 )
     {
     midpt0c = this->heap_coord_storage();
@@ -355,12 +384,12 @@
       midpt5c[i] = ( v2[i] + v3[i] ) * .5;
       }
 
-    this->edge_size_evaluator->evaluate_tags_at_midpoint( v0, t0, midpt0c, midpt0t, v1, t1 );
-    this->edge_size_evaluator->evaluate_tags_at_midpoint( v1, t1, midpt1c, midpt1t, v2, t2 );
-    this->edge_size_evaluator->evaluate_tags_at_midpoint( v2, t2, midpt2c, midpt2t, v0, t0 );
-    this->edge_size_evaluator->evaluate_tags_at_midpoint( v0, t0, midpt3c, midpt3t, v3, t3 );
-    this->edge_size_evaluator->evaluate_tags_at_midpoint( v1, t1, midpt4c, midpt4t, v3, t3 );
-    this->edge_size_evaluator->evaluate_tags_at_midpoint( v2, t2, midpt5c, midpt5t, v3, t3 );
+    (*this->tag_assigner)( v0, t0, i0, midpt0c, midpt0t, v1, t1, i1 );
+    (*this->tag_assigner)( v1, t1, i1, midpt1c, midpt1t, v2, t2, i2 );
+    (*this->tag_assigner)( v2, t2, i2, midpt2c, midpt2t, v0, t0, i0 );
+    (*this->tag_assigner)( v0, t0, i0, midpt3c, midpt3t, v3, t3, i3 );
+    (*this->tag_assigner)( v1, t1, i1, midpt4c, midpt4t, v3, t3, i3 );
+    (*this->tag_assigner)( v2, t2, i2, midpt5c, midpt5t, v3, t3, i3 );
 
     if ( this->edge_size_evaluator->evaluate_edge( v0, t0, midpt0c, midpt0t, v1, t1 ) )
       edge_code |=  1;

Modified: MOAB/trunk/refiner/MBSimplexTemplateRefiner.hpp
===================================================================
--- MOAB/trunk/refiner/MBSimplexTemplateRefiner.hpp	2008-01-17 01:41:29 UTC (rev 1530)
+++ MOAB/trunk/refiner/MBSimplexTemplateRefiner.hpp	2008-01-17 01:43:10 UTC (rev 1531)
@@ -32,6 +32,8 @@
 #include "MBEntityRefiner.hpp"
 #include "MBSimplexTemplateTagAssigner.hpp"
 
+#include "MBTypes.h" // for MB_DLL_EXPORT
+
 class MB_DLL_EXPORT MBSimplexTemplateRefiner : public MBEntityRefiner
 {
 public:
@@ -41,9 +43,11 @@
   virtual bool refine_entity( MBEntityHandle entity );
   virtual unsigned long get_heap_size_bound( int max_recursions ) const { return 48 * 4 * ( 1 << max_recursions ); }
 
-  virtual void set_tag_assigner( MBSimplexTemplateTagAssigner* ta ) { this->tag_assigner = ta; }
+  virtual bool set_tag_assigner( MBSimplexTemplateTagAssigner* ta );
   MBSimplexTemplateTagAssigner* get_tag_assigner() const { return this->tag_assigner; }
 
+  virtual bool set_edge_size_evaluator( MBEdgeSizeEvaluator* );
+
 protected:
   MBSimplexTemplateTagAssigner* tag_assigner;
   static int template_index[64][2];
@@ -52,9 +56,12 @@
 
   void refine_0_simplex( const double* v0, const void* t0 );
   bool refine_1_simplex( int max_depth,
-    const double* v0, const void* t0, const double* v1, const void* t1 );
+                         const double* v0, const void* t0, 
+                         const double* v1, const void* t1 );
   bool refine_2_simplex( int max_depth, int move,
-    const double* v0, const void* t0, const double* v1, const void* t1, const double* v2, const void* t2 );
+                         const double* v0, const void* t0, 
+                         const double* v1, const void* t1, 
+                         const double* v2, const void* t2 );
   bool refine_3_simplex( int max_depth,
                          double* v0, void* t0, 
                          double* v1, void* t1, 

Modified: MOAB/trunk/refiner/MBSimplexTemplateTagAssigner.cpp
===================================================================
--- MOAB/trunk/refiner/MBSimplexTemplateTagAssigner.cpp	2008-01-17 01:41:29 UTC (rev 1530)
+++ MOAB/trunk/refiner/MBSimplexTemplateTagAssigner.cpp	2008-01-17 01:43:10 UTC (rev 1531)
@@ -1,10 +1,20 @@
 #include "MBSimplexTemplateTagAssigner.hpp"
 
-#include "MBMeshRefiner.hpp"
+#include "MBEdgeSizeEvaluator.hpp"
+#include "MBInterface.hpp"
+#include "MBSimplexTemplateRefiner.hpp"
 
+#include <vector>
+
+#include <math.h>
+
+using namespace std;
+
 /// Construct a template tag assigner.
-MBSimplexTemplateTagAssigner::MBSimplexTemplateTagAssigner( MBMeshRefiner* )
+MBSimplexTemplateTagAssigner::MBSimplexTemplateTagAssigner( MBSimplexTemplateRefiner* r )
 {
+  this->mesh_refiner = r;
+  this->edge_size_evaluator = r->get_edge_size_evaluator();
 }
 
 /// Empty destructor for good form.
@@ -12,17 +22,74 @@
 {
 }
 
-void MBSimplexTemplateTagAssigner::operator()( const void* ta, const void* tb, void* tp )
+/**\brief Given endpoint coordinates and tag values plus midpoint coordinates, compute midpoint tag values.
+  *
+  * Normally, this function will be invoked by the MBEntityRefiner before evaluate_edge is called.
+  * However, if evaluate_edge() changes the parametric coordinates of the midpoint,
+  * it should call evaluate_tags_at_midpoint() again to update any tag values;
+  * that is why this function is a member of MBEdgeSizeEvaluator and not MBEntityRefiner.
+  *
+  * @param[in] c0 Pointer to endpoint 0 coordinates. The parametric coordinates (3) are followed by world coordinates (3).
+  * @param[in] t0 Pointer to endpoint 0 tag values.
+  * @param[in] cm Pointer to midpoint coordinates. The parametric coordinates (3) are followed by world coordinates (3).
+  * @param[out] tm Pointer to midpoint tag values.
+  * @param[in] c1 Pointer to endpoint 1 coordinates. The parametric coordinates (3) are followed by world coordinates (3).
+  * @param[in] t1 Pointer to endpoint 1 tag values.
+  */
+void MBSimplexTemplateTagAssigner::operator () ( const double* c0, const void* t0, int i0,
+						 const double* cm, void* tm, 
+						 const double* c1, const void* t1, int i1 )
 {
-  (void)ta;
-  (void)tb;
-  (void)tp;
+  double c0m_squared = 0.;
+  double c01_squared = 0.;
+  for ( int i = 0; i < 3; ++i )
+    {
+    double tmp = cm[i] - c0[i];
+    c0m_squared += tmp * tmp;
+    tmp = c1[i] - c0[i];
+    c01_squared += tmp * tmp;
+    }
+  double lambda = sqrt( c0m_squared / c01_squared );
+  double one_minus_lambda = 1. - lambda;
+
+  MBDataType data_type;
+  int tag_size;
+  int num_components;
+  int num_tags = this->edge_size_evaluator->get_number_of_vertex_tags();
+  MBTag tag_handle;
+  int tag_offset;
+  for ( int i = 0; i < num_tags; ++i )
+    {
+    this->edge_size_evaluator->get_vertex_tag( i, tag_handle, tag_offset );
+    this->mesh_refiner->get_mesh()->tag_get_data_type( tag_handle, data_type );
+    this->mesh_refiner->get_mesh()->tag_get_size( tag_handle, tag_size );
+    
+    switch ( data_type )
+      {
+      case MB_TYPE_DOUBLE:
+        {
+        num_components = tag_size / sizeof( double );
+        double* t0i = (double*) ( (char*)t0 + tag_offset );
+        double* tmi = (double*) ( (char*)tm + tag_offset );
+        double* t1i = (double*) ( (char*)t1 + tag_offset );
+        for ( int i = 0; i < num_components; ++ i )
+          tmi[i] = one_minus_lambda * t0i[i] + lambda * t1i[i];
+        }
+        break;
+      default:
+        memcpy( (char*)tm + tag_offset, (char*)( i0 < i1 ? t0 : t1 ) + tag_offset, tag_size );
+        break;
+      }
+    }
 }
 
-void MBSimplexTemplateTagAssigner::operator()( const void* ta, const void* tb, const void* tc, void* tp )
+void MBSimplexTemplateTagAssigner::operator () ( const void* t0,
+                                                 const void* t1,
+                                                 const void* t2,
+                                                 void* tp )
 {
-  (void)ta;
-  (void)tb;
-  (void)tc;
+  (void)t0;
+  (void)t1;
+  (void)t2;
   (void)tp;
 }

Modified: MOAB/trunk/refiner/MBSimplexTemplateTagAssigner.hpp
===================================================================
--- MOAB/trunk/refiner/MBSimplexTemplateTagAssigner.hpp	2008-01-17 01:41:29 UTC (rev 1530)
+++ MOAB/trunk/refiner/MBSimplexTemplateTagAssigner.hpp	2008-01-17 01:43:10 UTC (rev 1531)
@@ -27,19 +27,29 @@
 #ifndef MB_SIMPLEXTEMPLATETAGASSIGNER_H
 #define MB_SIMPLEXTEMPLATETAGASSIGNER_H
 
-#include "MBMeshRefiner.hpp"
+#include "MBTypes.h" // for MB_DLL_EXPORT
 
+class MBEdgeSizeEvaluator;
+class MBSimplexTemplateRefiner;
+
 class MB_DLL_EXPORT MBSimplexTemplateTagAssigner
 {
 public:
-  MBSimplexTemplateTagAssigner( MBMeshRefiner* );
+  MBSimplexTemplateTagAssigner( MBSimplexTemplateRefiner* );
   virtual ~MBSimplexTemplateTagAssigner();
+  
+  virtual void operator () ( const double* c0, const void* t0, int i0,
+                             const double* cm, void* tm,
+                             const double* c1, const void* t1, int i1 );
+  virtual void operator () ( const void* t0,
+                             const void* t1,
+                             const void* t2,
+                             void* tp );
+  virtual void set_edge_size_evaluator( MBEdgeSizeEvaluator* es ) { this->edge_size_evaluator = es; }
 
-  virtual void operator()( const void* ta, const void* tb, void* tp );
-  virtual void operator()( const void* ta, const void* tb, const void* tc, void* tp );
-
 protected:
-  MBMeshRefiner* mesh_refiner;
+  MBSimplexTemplateRefiner* mesh_refiner;
+  MBEdgeSizeEvaluator* edge_size_evaluator;
 };
 
 #endif // MB_SIMPLEXTEMPLATETAGASSIGNER_H




More information about the moab-dev mailing list