00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
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 
00040 private:
00041     FieldExchanger(const FieldExchanger &);
00042     const FieldExchanger & operator=(const FieldExchanger &);
00043    
00044 private:
00045     
00046     std::vector<int>        _importedNodeIDs;
00047 
00048     
00049     pico::DomainCoupler     *_coupler;
00050 };
00051 
00052 
00053 
00054 
00055 namespace pico {
00056 
00057     template <int NVAR, typename FT, template <typename> class OP>
00058     void FieldExchanger::exchange(FT *field, int fsize) 
00059     {    
00060         
00061         
00062         
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