[MOAB-dev] r1901 - in MOAB/trunk: parallel tools/mbcoupler

tautges at mcs.anl.gov tautges at mcs.anl.gov
Mon Jun 16 14:42:43 CDT 2008


Author: tautges
Date: 2008-06-16 14:42:43 -0500 (Mon, 16 Jun 2008)
New Revision: 1901

Added:
   MOAB/trunk/tools/mbcoupler/MBCoupler.cpp
   MOAB/trunk/tools/mbcoupler/MBCoupler.hpp
Modified:
   MOAB/trunk/parallel/MBParallelComm.hpp
   MOAB/trunk/parallel/MBProcConfig.hpp
   MOAB/trunk/tools/mbcoupler/Makefile.am
Log:
Adding skeleton of coupling code.


Modified: MOAB/trunk/parallel/MBParallelComm.hpp
===================================================================
--- MOAB/trunk/parallel/MBParallelComm.hpp	2008-06-16 19:31:25 UTC (rev 1900)
+++ MOAB/trunk/parallel/MBParallelComm.hpp	2008-06-16 19:42:43 UTC (rev 1901)
@@ -31,6 +31,7 @@
 #include "MBProcConfig.hpp"
 #include <map>
 #include "math.h"
+#include "mpi.h"
 
 extern "C" {
   struct tuple_list;

Modified: MOAB/trunk/parallel/MBProcConfig.hpp
===================================================================
--- MOAB/trunk/parallel/MBProcConfig.hpp	2008-06-16 19:31:25 UTC (rev 1900)
+++ MOAB/trunk/parallel/MBProcConfig.hpp	2008-06-16 19:42:43 UTC (rev 1901)
@@ -77,7 +77,7 @@
   crystal_data *crystal_router(bool construct_if_missing = true);
 
     //! get/set the communicator for this proc config
-  MPI_Comm proc_comm() {return procComm;}
+  const MPI_Comm proc_comm() const {return procComm;}
   void proc_comm(MPI_Comm this_comm) {procComm = this_comm;}
   
 private:

Added: MOAB/trunk/tools/mbcoupler/MBCoupler.cpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/MBCoupler.cpp	                        (rev 0)
+++ MOAB/trunk/tools/mbcoupler/MBCoupler.cpp	2008-06-16 19:42:43 UTC (rev 1901)
@@ -0,0 +1,123 @@
+#include "MBCoupler.hpp"
+#include "MBParallelComm.hpp"
+
+#include "assert.h"
+
+MBCoupler::MBCoupler(MBInterface *impl,
+                     MBParallelComm *pc,
+                     MBRange &local_elems,
+                     int coupler_id,
+                     bool init_tree) 
+    : mbImpl(impl), myPc(pc), myId(coupler_id)
+{
+  assert(NULL != impl && NULL != myPc);
+  
+    // keep track of the local points, at least for now
+  myRange = local_elems;
+  
+    // now initialize the tree
+  if (init_tree) initialize_tree();
+}
+
+  /* destructor
+   */
+MBCoupler::~MBCoupler() 
+{}
+
+
+MBErrorCode MBCoupler::locate_points(double *xyz, int num_points,
+                                     tuple_list *tl,
+                                     bool store_local) 
+{
+    // for each point, find box(es) containing the point, 
+    // appending results to vector
+
+    // allocate tuple_list to hold these points, procs
+
+    // perform scatter/gather, to gather points to source mesh procs
+
+    // find leaf node(s) in local kdtree containing point
+
+    // find natural coordinates of point in element(s) in that leaf
+
+    // for any point/element with nat coords within bounds, store
+    // handle/nat coords in vector, and proc/index in outgoing tuple
+    // (-1 for index if no elements containing that point)
+
+    // perform scatter/gather to send proc/index tuples back to procs
+
+    // store proc/index tuples locally, and/or pass back to application
+
+    // done
+  return MB_SUCCESS;
+}
+
+MBErrorCode MBCoupler::interpolate(MBCoupler::Method method,
+                                   MBTag tag,
+                                   double *interp_vals,
+                                   tuple_list *tl,
+                                   bool normalize) 
+{
+  if (LINEAR_FE != method) return MB_FAILURE;
+  
+    // if no tl, gather procs/indices of locations being interpolated
+
+    // scatter/gather interpolation points
+
+    // perform interpolation on local source mesh
+
+    // normalize interpolation
+
+    // scatter/gather interpolation data
+
+    // done
+  return MB_SUCCESS;
+}
+
+MBErrorCode MBCoupler::interpolate(MBCoupler::Method method,
+                                   const char *tag_name,
+                                   double *interp_vals,
+                                   tuple_list *tl,
+                                   bool normalize) 
+{
+  MBTag this_tag;
+  MBErrorCode result = mbImpl->tag_get_handle(tag_name, this_tag);
+  if (MB_SUCCESS != result) return result;
+  
+  return interpolate(method, this_tag, interp_vals, tl, normalize);
+}
+
+MBErrorCode MBCoupler::locate_points(MBRange &ents,
+                                     tuple_list *tl,
+                                     bool store_local) 
+{
+    // only do vertices for now
+  MBRange verts = ents.subset_by_type(MBVERTEX);
+  if (verts.size() != ents.size()) return MB_FAILURE;
+  
+    // get coordinates
+  std::vector<double> coords(3*verts.size());
+  MBErrorCode result = mbImpl->get_coords(verts, &coords[0]);
+  if (MB_SUCCESS != result) return result;
+  
+  return locate_points(&coords[0], verts.size(), tl, store_local);
+}
+  
+MBErrorCode MBCoupler::initialize_tree() 
+{
+    // initialize the tree for the local mesh
+
+    // allocate box extents storage array
+  allBoxes = new double[6*myPc->proc_config().proc_size()];
+  
+    // read local tree minimum/maximum vectors into array starting at
+    // allBoxes[6*myPc->proc_rank()], allBoxes[6*myPc->proc_rank()+3]
+
+    // now allgather so each proc has copy of box minima/maxima
+  int mpi_err = MPI_Allgather(allBoxes+6*myPc->proc_config().proc_rank(), 6, MPI_DOUBLE,
+                              allBoxes, 6, MPI_DOUBLE, myPc->proc_config().proc_comm());
+  if (MPI_SUCCESS == mpi_err) return MB_SUCCESS;
+  else return MB_FAILURE;
+}
+
+  

Added: MOAB/trunk/tools/mbcoupler/MBCoupler.hpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/MBCoupler.hpp	                        (rev 0)
+++ MOAB/trunk/tools/mbcoupler/MBCoupler.hpp	2008-06-16 19:42:43 UTC (rev 1901)
@@ -0,0 +1,154 @@
+/** 
+ * \class MBCoupler
+ * \author Tim Tautges
+ *
+ * \brief This class couples data between meshes.
+ *
+ * The coupler interpolates solution data at a set of points.  Data
+ * being interpolated resides on a source mesh, in a tag.
+ * Applications calling this coupler send in entities, usually points
+ * or vertices, and receive back the tag value interpolated at those
+ * points.  Entities in the source mesh containing those points 
+ * do not have to reside on the same processor.
+ *
+ * To use, an application should:
+ * - instantiate this coupler by calling the constructor collectively
+ *   on all processors in the communicator
+ * - call locate_points, which locates the points to be interpolated and
+ *   (optionally) caches the results in this object
+ * - call interpolate, which does the interpolation
+ *
+ * Multiple interpolations can be done after locating the points.
+ *
+ */
+#ifndef MBCOUPLER_HPP
+#define MBCOUPLER_HPP
+
+class MBParallelComm;
+extern "C" {
+  struct tuple_list;
+}
+
+#include "MBRange.hpp"
+#include "MBInterface.hpp"
+
+class MBCoupler
+{
+public:
+
+  enum Method {LINEAR_FE};
+
+    /* constructor
+     * Constructor, which also optionally initializes the coupler
+     * \param pc MBParallelComm object to be used with this coupler
+     * \param local_elems Local elements in the source mesh
+     * \param coupler_id Id of this coupler, should be the same over all procs
+     * \param init_tree If true, initializes kdtree inside the constructor
+     */
+  MBCoupler(MBInterface *impl,
+            MBParallelComm *pc,
+            MBRange &local_elems,
+            int coupler_id,
+            bool init_tree = true);
+
+    /* destructor
+     */
+  virtual ~MBCoupler();
+  
+    /* \brief Locate points on the source mesh
+     * This function finds the element/processor/natural coordinates 
+     * containing each point, optionally storing the results locally.
+     * \param xyz Point locations (interleaved) being located
+     * \param tl Tuple list containing the results, with each tuple
+     *           consisting of (p, i), p = proc, i = index on that proc
+     * \param store_local If true, stores the tuple list on the MBCoupler instance
+     *
+     */
+  MBErrorCode locate_points(double *xyz, int num_points,
+                            tuple_list *tl = NULL,
+                            bool store_local = true);
+  
+    /* \brief Locate entities on the source mesh
+     * This function finds the element/processor/natural coordinates 
+     * containing each entity, optionally storing the results locally.
+     * \param ents Entities being located
+     * \param tl Tuple list containing the results, with each tuple
+     *           consisting of (p, i), p = proc, i = index on that proc
+     * \param store_local If true, stores the tuple list on the MBCoupler instance
+     *
+     */
+  MBErrorCode locate_points(MBRange &ents,
+                            tuple_list *tl = NULL,
+                            bool store_local = true);
+  
+    /* \brief Interpolate data from the source mesh onto points
+     * All entities/points or, if tuple_list is input, only those points
+     * are interpolated from the source mesh.  Application should
+     * allocate enough memory in interp_vals to hold interpolation results.
+     * 
+     * If normalization is requested, technique used depends on the coupling
+     * method.
+     *
+     * \param method Interpolation/normalization method
+     * \param tag Tag on source mesh holding data to be interpolated
+     * \param interp_vals Memory holding interpolated data
+     * \param tl Tuple list of points to be interpolated; if NULL, all locations
+     *       stored in this object are interpolated
+     * \param normalize If true, normalization is done according to method
+     */
+  MBErrorCode interpolate(MBCoupler::Method method,
+                          MBTag tag,
+                          double *interp_vals,
+                          tuple_list *tl = NULL,
+                          bool normalize = true);
+
+    /* \brief Interpolate data from the source mesh onto points
+     * All entities/points or, if tuple_list is input, only those points
+     * are interpolated from the source mesh.  Application should
+     * allocate enough memory in interp_vals to hold interpolation results.
+     * 
+     * If normalization is requested, technique used depends on the coupling
+     * method.
+     *
+     * \param method Interpolation/normalization method
+     * \param tag_name Name of tag on source mesh holding data to be interpolated
+     * \param interp_vals Memory holding interpolated data
+     * \param tl Tuple list of points to be interpolated; if NULL, all locations
+     *       stored in this object are interpolated
+     * \param normalize If true, normalization is done according to method
+     */
+  MBErrorCode interpolate(MBCoupler::Method method,
+                          const char* tag_name,
+                          double *interp_vals,
+                          tuple_list *tl = NULL,
+                          bool normalize = true);
+
+private:
+
+    /* \brief MOAB instance
+     */
+  MBInterface *mbImpl;
+  
+    /* \brief Initialize the kdtree, locally and across communicator
+     */
+  MBErrorCode initialize_tree();
+
+    /* \brief Min/max bounding boxes for all proc tree roots
+     */
+  double *allBoxes;
+  
+    /* \brief MBParallelComm object for this coupler
+     */
+  MBParallelComm *myPc;
+  
+    /* \brief Id of this coupler
+     */
+  int myId;
+  
+    /* \brief Range of locations interpolated onto
+     */
+  MBRange myRange;
+  
+};
+
+#endif

Modified: MOAB/trunk/tools/mbcoupler/Makefile.am
===================================================================
--- MOAB/trunk/tools/mbcoupler/Makefile.am	2008-06-16 19:31:25 UTC (rev 1900)
+++ MOAB/trunk/tools/mbcoupler/Makefile.am	2008-06-16 19:42:43 UTC (rev 1901)
@@ -3,7 +3,7 @@
 @CGM_CONFIG_OPTIONS@
 
 DEFS = $(DEFINES)
-INCLUDES += -I$(top_srcdir) -I$(top_builddir) 
+INCLUDES += -I$(top_srcdir) -I$(top_builddir) -I$(top_srcdir)/parallel
 
 lib_LTLIBRARIES = libmbcoupler.la
 
@@ -19,10 +19,12 @@
    findpt.c \
    findpt.h \
    minmax.h \
-   types.h
+   types.h \
+   MBCoupler.cpp
 
 libmbcoupler_la_include_HEADERS = \
-   MBElemUtil.hpp
+   MBElemUtil.hpp \
+   MBCoupler.hpp
 
 libmbcoupler_la_includedir = $(includedir)
 




More information about the moab-dev mailing list