parallel/pico/SubDomain.cpp

00001 // -*- C++ -*-
00002 //
00003 //  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00004 //
00005 //                                   Fehmi Cirak
00006 //                        California Institute of Technology
00007 //                           (C) 2004 All Rights Reserved
00008 //
00009 //  <LicenseText>
00010 //
00011 //  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00012 //
00013 // EDITED BY MATT GALLOWAY FOR USE WITH DAPTA
00014 
00015 #include "DAPTA.hpp"
00016 
00017 #include <limits>
00018 #include <cassert>
00019 #include <cstdlib>
00020 #include <algorithm>
00021 
00022 #include <mpi.h>
00023 
00024 namespace DAPTA { // Define namespace DAPTA
00025 
00026 namespace pico { // Define namespace pico
00027 
00028 template <typename V>
00029 SubDomain<V>::SubDomain(const V& p, const V& q, double maxElemSize) {
00030    for (int i=0; i<V::dimension; ++i) {
00031       _low.coords[i] = std::min(p.coords[i], q.coords[i]);
00032       _upp.coords[i] = std::max(p.coords[i], q.coords[i]);
00033    }
00034    
00035    _maxElemSize = maxElemSize;
00036    
00037    // initialize Buffers
00038    _sendMsgSize = 0;
00039    _sBuf=NULL;
00040    _rBuf=NULL;
00041 }
00042 
00043 template <typename V>
00044 SubDomain<V>::~SubDomain(){
00045    if (_sBuf) delete _sBuf;
00046    if (_rBuf) delete _rBuf;
00047 }
00048 
00049 template <typename V>
00050 bool SubDomain<V>::checkOverlap (const SubDomain * const b) const {
00051    VertexType lp = b->lowerPoint();
00052    VertexType up = b->upperPoint();
00053    
00054    if ( lp.coords[0] > _upp.coords[0] ||
00055        lp.coords[1] > _upp.coords[1] ||
00056        lp.coords[2] > _upp.coords[2] ||
00057        up.coords[0] < _low.coords[0] ||
00058        up.coords[1] < _low.coords[1] ||
00059        up.coords[2] < _low.coords[2] ) return false;
00060    
00061    return true;    
00062 }
00063 
00064 template <typename V>
00065 bool SubDomain<V>::isIn (const V& point) const {
00066    for (int i=0; i<V::dimension; ++i) 
00067       if (point.coords[i] < _low.coords[i] || _upp.coords[i] < point.coords[i]) 
00068          return false;
00069    
00070    return true;    
00071 }
00072 
00073 template <typename V>
00074 void SubDomain<V>::registerSendBuffer(const char * const start, const size_t&  size) {
00075    if (!_sBuf) _sBuf = new CBuffer();
00076    _sendMsgSize = size;
00077    _sBuf->copyToBuffer(start, size);
00078    
00079    return;
00080 }
00081 
00082 template <typename V>
00083 void SubDomain<V>::allocateReceiveBuffer(const size_t& size) {    
00084    if (!_rBuf) _rBuf = new CBuffer();
00085    assert(_rBuf != NULL);
00086    assert(size>0);
00087    _rBuf->allocateBuffer(size);
00088    
00089    return;
00090 }
00091    
00092 } // namespace pico
00093 
00094 } // namespace DAPTA

Generated on Tue May 29 17:13:49 2007 for DAPTA by  doxygen 1.5.1