[MOAB-dev] r1946 - MOAB/trunk/tools/mbcoupler

acaceres at mcs.anl.gov acaceres at mcs.anl.gov
Fri Jun 27 17:17:16 CDT 2008


Author: acaceres
Date: 2008-06-27 17:17:16 -0500 (Fri, 27 Jun 2008)
New Revision: 1946

Modified:
   MOAB/trunk/tools/mbcoupler/MBCoupler.cpp
   MOAB/trunk/tools/mbcoupler/MBCoupler.hpp
   MOAB/trunk/tools/mbcoupler/mbcoupler_test.cpp
Log:
Added an "interpolation" method, for cases where the source field is defined on elements.

Just looks at the value of the field in the element that the target vertex lies in and uses that.

Tried not to break anything, but was rushing to commit... sorry in advance if anything broke!


Modified: MOAB/trunk/tools/mbcoupler/MBCoupler.cpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/MBCoupler.cpp	2008-06-27 19:20:15 UTC (rev 1945)
+++ MOAB/trunk/tools/mbcoupler/MBCoupler.cpp	2008-06-27 22:17:16 UTC (rev 1946)
@@ -316,7 +316,8 @@
                                    tuple_list *tl,
                                    bool normalize)
 {
-  if (LINEAR_FE != method) return MB_FAILURE;
+  if (!((LINEAR_FE == method) || (PLAIN_FE == method)))
+    return MB_FAILURE;
 
   tuple_list *tl_tmp = (tl ? tl : targetPts);
 
@@ -328,11 +329,20 @@
     // perform interpolation on local source mesh; put results into
     // tl_tmp->vr[i]
   MBErrorCode result;
+
   for (unsigned int i = 0; i < tl_tmp->n; i++) {
     int mindex = tl_tmp->vi[3*i+2];
-    result = interp_field_for_hex(mappedPts->vul[mindex],
-                                  MBCartVect(mappedPts->vr+3*mindex), 
-                                              tag, tl_tmp->vr[i]);
+
+    result = MB_FAILURE;
+    if(LINEAR_FE == method){
+      result = interp_field_for_hex(mappedPts->vul[mindex],
+				    MBCartVect(mappedPts->vr+3*mindex), 
+				    tag, tl_tmp->vr[i]);
+    }else if (PLAIN_FE == method){
+      result = plain_field_map(mappedPts->vul[mindex],
+			       tag, tl_tmp->vr[i]);
+    }
+
     if (MB_SUCCESS != result) return result;
   }
   
@@ -348,10 +358,19 @@
     for (std::vector<unsigned int>::iterator vit = localMappedPts.begin();
          vit != localMappedPts.end(); vit += 2) {
       int mindex = *(vit+1);
-      result = interp_field_for_hex(mappedPts->vul[mindex],
-                                    MBCartVect(mappedPts->vr+3*mindex), 
-                                    tag, interp_vals[*vit]);
+
+      result = MB_FAILURE;
+      if(LINEAR_FE == method){
+	result = interp_field_for_hex(mappedPts->vul[mindex],
+				      MBCartVect(mappedPts->vr+3*mindex), 
+				      tag, interp_vals[*vit]);
+      }else if (PLAIN_FE == method){
+	result = plain_field_map(mappedPts->vul[mindex],
+				 tag, interp_vals[*vit]);
+      }
+
       if (MB_SUCCESS != result) return result;
+
     }
   }
   
@@ -456,3 +475,21 @@
 
   return MB_SUCCESS;
 }
+
+
+//Simplest "interpolation" for element-based source fields. Set the value of the field
+//at the target point to that of the field in the source element it lies in.
+MBErrorCode MBCoupler::plain_field_map(MBEntityHandle elem,
+				       MBTag tag,
+				       double &field)
+{
+  double tempField;
+
+  // get the tag values at the vertices
+  MBErrorCode result = mbImpl->tag_get_data(tag, &elem, 1, &tempField);
+  if (MB_SUCCESS != result) return result;
+
+  field = tempField;
+
+  return MB_SUCCESS;
+}

Modified: MOAB/trunk/tools/mbcoupler/MBCoupler.hpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/MBCoupler.hpp	2008-06-27 19:20:15 UTC (rev 1945)
+++ MOAB/trunk/tools/mbcoupler/MBCoupler.hpp	2008-06-27 22:17:16 UTC (rev 1946)
@@ -41,7 +41,7 @@
 {
 public:
 
-  enum Method {LINEAR_FE};
+  enum Method {LINEAR_FE, PLAIN_FE};
 
     /* constructor
      * Constructor, which also optionally initializes the coupler
@@ -140,6 +140,10 @@
                                    MBCartVect nat_coord, 
                                    MBTag tag,
                                    double &field);
+
+  MBErrorCode plain_field_map(MBEntityHandle elem,
+			      MBTag tag,
+			      double &field);
   
   MBErrorCode test_local_box(double *xyz, 
                              int from_proc, int remote_index, int index, 

Modified: MOAB/trunk/tools/mbcoupler/mbcoupler_test.cpp
===================================================================
--- MOAB/trunk/tools/mbcoupler/mbcoupler_test.cpp	2008-06-27 19:20:15 UTC (rev 1945)
+++ MOAB/trunk/tools/mbcoupler/mbcoupler_test.cpp	2008-06-27 22:17:16 UTC (rev 1946)
@@ -107,14 +107,17 @@
               << pointloc_time << ", "
               << interp_time << std::endl;
   }
-  
+
+
     // output mesh
   const char *outfile = "output.h5m";
   result = mbImpl->write_file(outfile, NULL, "PARALLEL=FORMAT",
-                              pcs[1]->partition_sets());
+			      pcs[1]->partition_sets());
+
   PRINT_LAST_ERROR;
   std::cout << "Wrote " << outfile << std::endl;
 
+
   std::cout << "Success." << std::endl;
   err = MPI_Finalize();
 
@@ -261,7 +264,15 @@
 
     // now interpolate tag onto target points
   std::vector<double> field(targ_verts.size());
-  result = mbc.interpolate(MBCoupler::LINEAR_FE, interp_tag, &field[0]);
+
+  if(interp_tag == "vertex_field"){
+    result = mbc.interpolate(MBCoupler::LINEAR_FE, interp_tag, &field[0]);
+  }else if(interp_tag == "element_field"){
+    result = mbc.interpolate(MBCoupler::PLAIN_FE, interp_tag, &field[0]);
+  }else{
+    std::cout << "Using tag name to determine type of sourge field at the moment... Use either vertex_field or element_field\n";
+    result = MB_FAILURE;
+  }
   PRINT_LAST_ERROR;
   
   interp_time = MPI_Wtime();




More information about the moab-dev mailing list