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