[MOAB-dev] r1489 - MOAB/trunk/refiner

dcthomp at mcs.anl.gov dcthomp at mcs.anl.gov
Thu Dec 27 02:30:35 CST 2007


Author: dcthomp
Date: 2007-12-27 02:30:31 -0600 (Thu, 27 Dec 2007)
New Revision: 1489

Modified:
   MOAB/trunk/refiner/MBEntityRefiner.cpp
   MOAB/trunk/refiner/MBEntityRefiner.hpp
   MOAB/trunk/refiner/MBSimplexTemplateRefiner.cpp
   MOAB/trunk/refiner/MBSimplexTemplateRefiner.hpp
Log:
ENH: Checkpoint on refiner work.


Modified: MOAB/trunk/refiner/MBEntityRefiner.cpp
===================================================================
--- MOAB/trunk/refiner/MBEntityRefiner.cpp	2007-12-27 04:28:59 UTC (rev 1488)
+++ MOAB/trunk/refiner/MBEntityRefiner.cpp	2007-12-27 08:30:31 UTC (rev 1489)
@@ -61,6 +61,31 @@
   * @retval A pointer to an edge size evaluator object or NULL.
   */
 
+/**\brief Set the functor through which output entities are streamed.
+  *
+  * Any previously assigned functor will be deleted when a new functor is set.
+  * 
+  * @retvalReturns true if the value was changed and false otherwise.
+  */
+bool MBEntityRefiner::set_output_functor( MBEntityRefinerOutputFunctor* func_obj )
+{
+  if ( ! func_obj || func_obj == this->output_functor )
+    return false;
+
+  if ( this->output_functor )
+    {
+    delete this->output_functor;
+    }
+  this->output_functor = func_obj;
+  return true;
+}
+
+/**\fn MBEntityRefinerOutputFunctor* MBEntityRefiner::get_output_functor()
+  *\brief Return the functor used to stream output.
+  *
+  * @retval A pointer to the functor. This may be NULL.
+  */
+
 /**\brief Set the minimum number of recursive subdivisions that should occur, regardless of the edge_size_evaluator's response.
   *
   * This is useful for forcing global refinement.
@@ -164,12 +189,12 @@
   * The returned pointer references enough bytes to store all the tags for a vertex as reported by the
   * current edge size evaluator's MBEdgeSizeEvaluator::get_vertex_tag_size().
   */
-char* MBEntityRefiner::heap_tag_storage()
+void* MBEntityRefiner::heap_tag_storage()
 {
-  char* rval;
+  void* rval;
   if ( this->edge_size_evaluator && this->current_tag != this->tag_heap.end() )
     {
-    rval = &(*this->current_tag);
+    rval = (void*) &(*this->current_tag);
     this->current_tag += this->edge_size_evaluator->get_vertex_tag_size();
     }
   else
@@ -179,3 +204,16 @@
   return rval;
 }
 
+/**\brief Given endpoint coordinates and tag values plus midpoint coordinates, compute midpoint tag values.
+  *
+  * @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 MBEntityRefiner::evaluate_tags_at_midpoint(
+  const double* c0, const void* t0, double* cm, void* tm, const double* c1, const void* t1 ) const
+{
+}

Modified: MOAB/trunk/refiner/MBEntityRefiner.hpp
===================================================================
--- MOAB/trunk/refiner/MBEntityRefiner.hpp	2007-12-27 04:28:59 UTC (rev 1488)
+++ MOAB/trunk/refiner/MBEntityRefiner.hpp	2007-12-27 08:30:31 UTC (rev 1489)
@@ -42,8 +42,20 @@
   * \author David Thompson
   * \author Philippe Pebay
   *
-  * \date 19 November 2007
+  * \date 24 December 2007
   */
+/** \class MBEntityRefinerOutputFunctor
+  *
+  * This is an abstract class used by MBEntityRefiner to output entities that are the product of refinement.
+  * The parenthesis operator is overloaded with two forms:
+  * one used for appending a vertex to an entity,
+  * the other used to finalize the creation of the entity by specifying its type.
+  *
+  * \author David Thompson
+  * \author Philippe Pebay
+  *
+  * \date 26 December 2007
+  */
 #ifndef MB_ENTITYREFINER_H
 #define MB_ENTITYREFINER_H
 
@@ -54,6 +66,13 @@
 class MBInterface;
 class MBEdgeSizeEvaluator;
 
+class MB_DLL_EXPORT MBEntityRefinerOutputFunctor
+{
+public:
+  virtual void operator () ( const double* vcoords, const void* vtags ) = 0;
+  virtual void operator () ( MBEntityType etyp ) = 0;
+};
+
 class MB_DLL_EXPORT MBEntityRefiner
 {
 public:
@@ -66,6 +85,9 @@
   virtual bool set_edge_size_evaluator( MBEdgeSizeEvaluator* );
   MBEdgeSizeEvaluator* get_edge_size_evaluator() { return this->edge_size_evaluator; }
 
+  virtual bool set_output_functor( MBEntityRefinerOutputFunctor* func_obj );
+  MBEntityRefinerOutputFunctor* get_output_functor() { return this->output_functor; }
+
   virtual bool set_minimum_number_of_subdivisions( int mn );
   int get_minimum_number_of_subdivisions() const { return this->minimum_number_of_subdivisions; }
 
@@ -75,6 +97,7 @@
 protected:
   MBInterface* mesh;
   MBEdgeSizeEvaluator* edge_size_evaluator;
+  MBEntityRefinerOutputFunctor* output_functor;
   int minimum_number_of_subdivisions;
   int maximum_number_of_subdivisions;
   std::vector<double> coord_heap;
@@ -85,7 +108,8 @@
   void update_heap_size();
   void reset_heap_pointers();
   double* heap_coord_storage();
-  char* heap_tag_storage();
+  void* heap_tag_storage();
+  void evaluate_tags_at_midpoint( const double* c0, const void* t0, double* cm, void* tm, const double* c1, const void* t1 ) const;
 };
 
 #endif // MB_ENTITYREFINER_H

Modified: MOAB/trunk/refiner/MBSimplexTemplateRefiner.cpp
===================================================================
--- MOAB/trunk/refiner/MBSimplexTemplateRefiner.cpp	2007-12-27 04:28:59 UTC (rev 1488)
+++ MOAB/trunk/refiner/MBSimplexTemplateRefiner.cpp	2007-12-27 08:30:31 UTC (rev 1489)
@@ -1,5 +1,6 @@
 #include "MBSimplexTemplateRefiner.hpp"
 
+#include "MBEdgeSizeEvaluator.hpp"
 #include "MBInterface.hpp"
 
 #include <iostream>
@@ -19,14 +20,32 @@
 {
   this->reset_heap_pointers();
   bool rval = true;
+  const MBEntityHandle* conn;
+  int num_nodes;
+  if ( this->mesh->get_connectivity( entity, conn, num_nodes ) != MB_SUCCESS )
+    {
+    return false;
+    }
+  std::vector<double> entity_coords;
+  entity_coords.resize( 6 * num_nodes );
+  // Have to make num_nodes calls to get_coords() because we need xyz interleaved with rst coords.
+  for ( int n = 0; n < num_nodes; ++n )
+    {
+    if ( this->mesh->get_coords( &conn[n], 1, &entity_coords[3 * n + 3] ) != MB_SUCCESS )
+      {
+      return false;
+      }
+    }
+  // Still need to get tags.
+
   switch ( this->mesh->type_from_handle( entity ) )
     {
     case MBVERTEX:
-      this->refine_0_simplex();
+      this->refine_0_simplex( &entity_coords[0], 0 ); // FIXME
       rval = false;
       break;
     case MBEDGE:
-      rval = this->refine_1_simplex();
+      rval = this->refine_1_simplex( 0,  &entity_coords[0], 0,  &entity_coords[6], 0 ); // FIXME
       break;
     case MBTRI:
       rval = this->refine_2_simplex();
@@ -90,15 +109,52 @@
   * in space and vertices as degrees-of-freedom in a mesh (i.e. a vertex that is
   * treated as a lumped-parameter model).
   */
-void MBSimplexTemplateRefiner::refine_0_simplex()
+void MBSimplexTemplateRefiner::refine_0_simplex( double* v0, const void* t0 )
 {
+  (*this->output_functor)( v0, t0 );
+  (*this->output_functor)( MBVERTEX );
 }
 
 /**\brief Refine an edge.
   */
-bool MBSimplexTemplateRefiner::refine_1_simplex()
+bool MBSimplexTemplateRefiner::refine_1_simplex( int max_depth, double* v0, void* t0, double* v1, void* t1 )
 {
-  return true;
+  bool edge_code = false;
+
+  double* midptc;
+  void* midptt;
+
+  if ( max_depth-- > 0 )
+    {
+    midptc = this->heap_coord_storage();
+    midptt = this->heap_tag_storage();
+    int i;
+    // make valgrind happy
+    //vtkstd::fill( midpt0, midpt0 + 6, 0. );
+    for ( i = 0; i < 6; i++ )
+      midptc[i] = ( v0[i] + v1[i] ) / 2.;
+
+    this->evaluate_tags_at_midpoint( v0, t0, midptc, midptt, v1, t1 );
+    edge_code = this->edge_size_evaluator->evaluate_edge( v0, t0, midptc, midptt, v1, t1 );
+    }
+
+  switch ( edge_code )
+    {
+    // No edges to subdivide
+  case 0:
+    (*this->output_functor)( v0, t0 );
+    (*this->output_functor)( v1, t1 );
+    (*this->output_functor)( MBEDGE );
+    break ;
+
+    // One edge to subdivide
+  case 1:
+    this->refine_1_simplex( max_depth, v0, t0, midptc, midptt );
+    this->refine_1_simplex( max_depth, midptc, midptt, v1, t1 );
+    break;
+    }
+
+  return edge_code;
 }
 
 /**\brief Refine a triangle.

Modified: MOAB/trunk/refiner/MBSimplexTemplateRefiner.hpp
===================================================================
--- MOAB/trunk/refiner/MBSimplexTemplateRefiner.hpp	2007-12-27 04:28:59 UTC (rev 1488)
+++ MOAB/trunk/refiner/MBSimplexTemplateRefiner.hpp	2007-12-27 08:30:31 UTC (rev 1489)
@@ -44,8 +44,8 @@
   static int* template_index;
   static int* templates;
 
-  void refine_0_simplex();
-  bool refine_1_simplex();
+  void refine_0_simplex( double* v0, const void* t0 );
+  bool refine_1_simplex( int max_depth, double* v0, void* t0, double* v1, void* t1 );
   bool refine_2_simplex();
   bool refine_3_simplex();
 };




More information about the moab-dev mailing list