moab
DataCoupler.hpp
Go to the documentation of this file.
00001 
00024 #ifndef DATACOUPLER_HPP
00025 #define DATACOUPLER_HPP
00026 
00027 #include "moab/Range.hpp"
00028 #include "moab/Interface.hpp"
00029 
00030 #include <sstream>
00031 
00032 namespace moab {
00033 
00034 class ParallelComm;
00035 class SpatialLocator;
00036 class Error;
00037 
00038 class DataCoupler
00039 {
00040 public:
00041 
00042   enum Method {CONSTANT, LINEAR_FE, QUADRATIC_FE, SPECTRAL} ;
00043 
00044   enum IntegType {VOLUME};
00045 
00046     /* constructor
00047      * Constructor, which also optionally initializes the coupler
00048      * \param source_ents Elements in the source mesh
00049      * \param coupler_id Id of this coupler, should be the same over all procs
00050      * \param pc ParallelComm object to be used with this coupler, representing the union
00051      *    of processors containing source and target meshes
00052      * \param init_locator If true, initializes a spatial locator inside the constructor
00053      * \param dim Dimension of entities to be coupled; if -1, get from source_elems
00054      */
00055   DataCoupler(Interface *impl,
00056               Range &source_ents,
00057               int coupler_id,
00058               ParallelComm *pc = NULL,
00059               bool init_locator = true,
00060               int dim = -1);
00061 
00062     /* destructor
00063      */
00064   virtual ~DataCoupler();
00065   
00066     /* \brief Locate points on the source mesh
00067      * This is a pass-through function to SpatialLocator::locate_points
00068      * \param xyz Point locations (interleaved) being located
00069      * \param num_points Number of points in xyz
00070      * \param rel_iter_tol Relative tolerance for non-linear iteration
00071      * \param abs_iter_tol Relative tolerance for non-linear iteration, usually 10^-10 or so
00072      * \param inside_tol Tolerance of is_inside evaluation, usually 10^-6 or so
00073      * \param loc_results Tuple list containing the results; two types of results are possible,
00074      *      controlled by value of store_local parameter:
00075      *      store_local = true: each tuple T[j] consists of (p, i), p = proc with src element containing
00076      *        point j (or 0 if serial), i = index in stored list (in SpatialLocator) on src proc
00077      *      store_local = false: each tuple T[j] consists of (p, ht, hs, pr[3]), where ht = target mesh entity
00078      *        handle, hs = source mesh entity containing point (0 if not found), pr = parameters in hs
00079      * \param store_local If true, stores the located points on SpatialLocator
00080      */
00081   ErrorCode locate_points(double *xyz, int num_points,
00082                           const double rel_iter_tol = 1.0e-10, const double abs_iter_tol = 1.0e-10,
00083                           const double inside_tol = 1.0e-6);
00084   
00085     /* \brief Locate points on the source mesh
00086      * This is a pass-through function to SpatialLocator::locate_points
00087      * \param ents Target entities being located
00088      * \param rel_iter_tol Relative tolerance for non-linear iteration
00089      * \param abs_iter_tol Relative tolerance for non-linear iteration, usually 10^-10 or so
00090      * \param inside_tol Tolerance of is_inside evaluation, usually 10^-6 or so
00091      * \param loc_results Tuple list containing the results; two types of results are possible,
00092      *      controlled by value of store_local parameter:
00093      *      store_local = true: each tuple T[j] consists of (p, i), p = proc with src element containing
00094      *        point j (or 0 if serial), i = index in stored list (in SpatialLocator) on src proc
00095      *      store_local = false: each tuple T[j] consists of (p, ht, hs, pr[3]), where ht = target mesh entity
00096      *        handle, hs = source mesh entity containing point (0 if not found), pr = parameters in hs
00097      * \param store_local If true, stores the located points on SpatialLocator
00098      */
00099   ErrorCode locate_points(Range &ents,
00100                           const double rel_iter_tol = 1.0e-10, const double abs_iter_tol = 1.0e-10,
00101                           const double inside_tol = 1.0e-6);
00102   
00103     /* \brief Interpolate data from the source mesh onto points
00104      * All entities/points or, if tuple_list is input, only those points
00105      * are interpolated from the source mesh.  Application should
00106      * allocate enough memory in interp_vals to hold interpolation results.
00107      * 
00108      * If normalization is requested, technique used depends on the coupling
00109      * method.
00110      *
00111      * \param method Interpolation/normalization method
00112      * \param tag Tag on source mesh holding data to be interpolated
00113      * \param interp_vals Memory holding interpolated data; if NULL, data is written to same tag on target ents
00114      * \param point_indices If non-NULL, a set of indices of points input to 
00115      *        locate_points at which to interpolate; if NULL, interpolates at all points
00116      *        input to locate_points
00117      * \param normalize If true, normalization is done according to method
00118      */
00119   ErrorCode interpolate(/*DataCoupler::Method*/ int method,
00120                         Tag tag,
00121                         double *interp_vals = NULL,
00122                         std::vector<int> *point_indices = NULL,
00123                         bool normalize = true);
00124 
00125     /* \brief Interpolate data from the source mesh onto points
00126      * All entities/points or, if tuple_list is input, only those points
00127      * are interpolated from the source mesh.  Application should
00128      * allocate enough memory in interp_vals to hold interpolation results.
00129      * 
00130      * If normalization is requested, technique used depends on the coupling
00131      * method.
00132      *
00133      * \param method Interpolation/normalization method
00134      * \param tag_name Tag name on source mesh holding data to be interpolated
00135      * \param interp_vals Memory holding interpolated data; if NULL, data is written to same tag on target ents
00136      * \param point_indices If non-NULL, a set of indices of points input to 
00137      *        locate_points at which to interpolate; if NULL, interpolates at all points
00138      *        input to locate_points
00139      * \param normalize If true, normalization is done according to method
00140      */
00141   ErrorCode interpolate(/*DataCoupler::Method*/ int method,
00142                         const std::string &tag_name,
00143                         double *interp_vals = NULL,
00144                         std::vector<int> *point_indices = NULL,
00145                         bool normalize = true);
00146 
00147     /* \brief Interpolate data from multiple tags
00148      * All entities/points or, if tuple_list is input, only those points
00149      * are interpolated from the source mesh.  Application should
00150      * allocate enough memory in interp_vals to hold interpolation results.
00151      * 
00152      * In this variant, multiple tags, possibly with multiple interpolation
00153      * methods, are specified.  Sum of values in points_per_method should be
00154      * the number of points in tl or, if NULL, targetPts.
00155      *
00156      * If normalization is requested, technique used depends on the coupling
00157      * method.
00158      *
00159      * \param methods Vector of Interpolation/normalization methods
00160      * \param tag_names Names of tag being interpolated for each method
00161      * \param points_per_method Number of points for each method
00162      * \param num_methods Length of vectors in previous 3 arguments
00163      * \param interp_vals Memory holding interpolated data; if NULL, data is written to same tag on target ents
00164      * \param point_indices If non-NULL, a set of indices of points input to 
00165      *        locate_points at which to interpolate; if NULL, interpolates at all points
00166      *        input to locate_points
00167      * \param normalize If true, normalization is done according to method
00168      */
00169   ErrorCode interpolate(/*DataCoupler::Method*/ int *methods,
00170                         const std::string *tag_names,
00171                         int *points_per_method,
00172                         int num_methods,
00173                         double *interp_vals = NULL,
00174                         std::vector<int> *point_indices = NULL,
00175                         bool normalize = true);
00176 
00177 
00178     /* \brief Interpolate data from multiple tags
00179      * All entities/points or, if tuple_list is input, only those points
00180      * are interpolated from the source mesh.  Application should
00181      * allocate enough memory in interp_vals to hold interpolation results.
00182      * 
00183      * In this variant, multiple tags, possibly with multiple interpolation
00184      * methods, are specified.  Sum of values in points_per_method should be
00185      * the number of points in tl or, if NULL, targetPts.
00186      *
00187      * If normalization is requested, technique used depends on the coupling
00188      * method.
00189      *
00190      * \param methods Vector of Interpolation/normalization methods
00191      * \param tag_names Names of tag being interpolated for each method
00192      * \param points_per_method Number of points for each method
00193      * \param num_methods Length of vectors in previous 3 arguments
00194      * \param interp_vals Memory holding interpolated data; if NULL, data is written to same tag on target ents
00195      * \param point_indices If non-NULL, a set of indices of points input to 
00196      *        locate_points at which to interpolate; if NULL, interpolates at all points
00197      *        input to locate_points
00198      * \param normalize If true, normalization is done according to method
00199      */
00200   ErrorCode interpolate(/*DataCoupler::Method*/ int *methods,
00201                         Tag *tag_names,
00202                         int *points_per_method,
00203                         int num_methods,
00204                         double *interp_vals = NULL,
00205                         std::vector<int> *point_indices = NULL,
00206                         bool normalize = true);
00207 
00208     /* Get functions */
00209   inline SpatialLocator *spatial_locator() {return myLocator;}
00210   inline int my_id() const {return myId;}
00211   inline const Range &target_ents() const {return targetEnts;}
00212   inline Range &target_ents() {return targetEnts;}
00213   inline int get_dim() const {return myDim;}
00214         
00215 private:
00216 
00217     /* \brief MOAB instance
00218      */
00219   Interface *mbImpl;
00220   
00221     /* \brief ParallelComm object for this coupler
00222      */
00223   ParallelComm *myPcomm;
00224   
00225     /* \brief SpatialLocator for local mesh
00226      */
00227   SpatialLocator *myLocator;
00228   
00229     /* \brief error object used to set last error on interface
00230      */
00231   Error *mError;
00232 
00233     /* \brief Id of this coupler
00234      */
00235   int myId;
00236   
00237     /* \brief Range of target entities
00238      */
00239   Range targetEnts;
00240 
00241   // entity dimension
00242   int myDim;
00243 
00244 };
00245 
00246     inline ErrorCode DataCoupler::interpolate(/*DataCoupler::Method*/ int method,
00247                                           Tag tag,
00248                                           double *interp_vals,
00249                                           std::vector<int> *point_indices,
00250                                           bool normalize)
00251 {
00252     // no point indices input, 
00253   int num_pts = (point_indices ? point_indices->size() : targetEnts.size());
00254   return interpolate(&method, &tag, &num_pts, 1,
00255                      interp_vals, point_indices, normalize);
00256 }
00257 
00258 } // namespace moab
00259 
00260 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines