vtf-logo

pico/pico/FieldExchanger.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 //  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00004 //
00005 //                                   Fehmi Cirak
00006 //                        California Institute of Technology
00007 //                           (C) 2003 All Rights Reserved
00008 //
00009 //  <LicenseText>
00010 //
00011 //  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00012 //
00013 
00014 #ifndef _FieldExchanger_h_
00015 #define _FieldExchanger_h_
00016 
00017 #include "definitions.h"
00018 #include "DomainCoupler.h"
00019 
00020 #include <vector>
00021 #include <functional>
00022 #include <cassert>
00023 
00024 
00025 namespace pico {
00026     class FieldExchanger;
00027 }
00028 
00029 
00030 class pico::FieldExchanger{
00031 public:    
00032     FieldExchanger(pico::DomainCoupler* coupler, 
00033                    std::vector<int>::iterator lGBegin, int nodes);
00034     ~FieldExchanger() {}
00035    
00036     template <int NVAR, typename FT, template <typename> class OP>
00037     void exchange(FT *field, int fsize);
00038  
00039 // copy and equality constructor
00040 private:
00041     FieldExchanger(const FieldExchanger &);
00042     const FieldExchanger & operator=(const FieldExchanger &);
00043    
00044 private:
00045     // mapping from imported node id's to local node id's
00046     std::vector<int>        _importedNodeIDs;
00047 
00048     // domain coupler instance which handles the communication
00049     pico::DomainCoupler     *_coupler;
00050 };
00051 
00052 
00053 
00054 // templated function
00055 namespace pico {
00056 
00057     template <int NVAR, typename FT, template <typename> class OP>
00058     void FieldExchanger::exchange(FT *field, int fsize) 
00059     {    
00060         // NVAR - number of variables for each node
00061         // FT - type of the field (double/int)
00062         // OP - operation to be performend, e.g. std::plus<FT>
00063         
00064         _coupler->registerSendBuffer(pico::RED, field, fsize);
00065         _coupler->exchangeSubdomainDataIntra(pico::RED); 
00066         
00067         const FT notUsed(0);
00068         FT *tmp = _coupler->recvBuffer(pico::RED, notUsed);
00069         
00070         OP<FT> operation;
00071         std::vector<int>::iterator it = _importedNodeIDs.begin();
00072         std::vector<int>::iterator ite = _importedNodeIDs.end();    
00073         for (int i=0; it!=ite; ++it, ++i) {
00074             if (*it==-1) continue;
00075             for (int j=0; j<NVAR; ++j) {
00076                 assert((NVAR*(*it)+j)<fsize);
00077                 field[NVAR*(*it)+j] = operation(field[NVAR*(*it)+j], tmp[NVAR*i+j]);
00078             }
00079         }       
00080         return;
00081     }
00082 }
00083 
00084 #endif
00085 
00086 //  End of file

Generated on Fri Aug 24 13:00:24 2007 for SFC Thin-Shell Finite Element Solver by  doxygen 1.4.7