⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 leveldata.h

📁 自适应网格划分通用程序包
💻 H
字号:
// This software is copyright (C) by the Lawrence Berkeley
// National Laboratory.  Permission is granted to reproduce
// this software for non-commercial purposes provided that
// this notice is left intact.
//
// It is acknowledged that the U.S. Government has rights to
// this software under Contract DE-AC03-765F00098 between
// the U.S.  Department of Energy and the University of
// California.
//
// This software is provided as a professional and academic
// contribution for joint exchange. Thus it is experimental,
// is provided ``as is'', with no warranties of any kind
// whatsoever, no support, no promise of updates, or printed
// documentation. By using this software, you acknowledge
// that the Lawrence Berkeley National Laboratory and
// Regents of the University of California shall have no
// liability with respect to the infringement of other
// copyrights by any part of this software.
//

#ifndef _LEVELDATA_H_
#define _LEVELDATA_H_

#include "IntVect.H"
#include "BoxLayoutData.H"
#include "DisjointBoxLayout.H"
#include "Copier.H"
#include "SPMD.H"

template <class T>
class LDOperator
{
public:
  virtual int size(const T& arg, const Box& b, const Interval& comps) const
  {
        return arg.size(b, comps);
  }
  virtual void linearOut(const T& arg, void* buf, const Box& R, 
                         const Interval& comps) const
  {
        arg.linearOut(buf, R, comps);
  }
  virtual void linearIn(T& arg,  void* buf, const Box& R, 
                        const Interval& comps)const
  {
        arg.linearIn(buf, R, comps);
  }
  virtual void op(T& dest, 
                  const Box& RegionFrom, 
                  const Interval& Cdest, 
                  const Box& RegionTo,
                  const T& src, 
                  const Interval& Csrc) const
  {
        dest.copy(RegionFrom, Cdest,RegionTo, src, Csrc);
  }
}; 


template<class T> class LevelData : public BoxLayoutData<T>
{
public:

  LevelData();

  LevelData(const DisjointBoxLayout& dp, int comps,
            const IntVect& ghost = IntVect::TheZeroVector(),
            const DataFactory<T>& a_factory = DefaultDataFactory<T>());

  virtual ~LevelData();


  virtual void define(const DisjointBoxLayout& dp, int comps,
                      const IntVect& ghost = IntVect::TheZeroVector(),
                      const DataFactory<T>& a_factory = DefaultDataFactory<T>());



  virtual void define(const LevelData<T>& da,
                      const DataFactory<T>& a_factory = DefaultDataFactory<T>());


  virtual void define(const LevelData<T>& da, const Interval& comps,
                      const DataFactory<T>& a_factory = DefaultDataFactory<T>());

  virtual void copyTo(const Interval& srcComps,
                      BoxLayoutData<T>& dest,
                      const Interval& destComps) const;

  virtual void copyTo(const Interval& srcComps,
                      BoxLayoutData<T>& dest,
                      const Interval& destComps,
                      const Copier& copier) const;

  virtual void copyTo(const Interval& srcComps,
                      LevelData<T>& dest,
                      const Interval& destComps) const;


  virtual void copyTo(const Interval& srcComps,
                      LevelData<T>& dest,
                      const Interval& destComps,
                      const Copier& copier,
                      const LDOperator<T>& a_op = LDOperator<T>()) const;

  virtual void exchange(const Interval& comps);

  virtual void exchange(const Interval& comps,
                        const Copier& copier);

  const IntVect& ghostVect() const { return m_ghost;}

  virtual void define(const BoxLayout& dp, int comps,
                      const DataFactory<T>& factory);

  virtual void define(const BoxLayoutData<T>& da,
                      const DataFactory<T>& factory = DefaultDataFactory<T>());

  virtual void define(const BoxLayoutData<T>& da, const Interval& comps,
                      const DataFactory<T>& factory = DefaultDataFactory<T>());

  virtual void define(const BoxLayout& deadFunction);

  const DisjointBoxLayout& getBoxes() const
  {
    return m_disjointBoxLayout;
  }

  const DisjointBoxLayout& disjointBoxLayout() const
  {
    return m_disjointBoxLayout;
  }


  virtual void apply(void (*a_Function)(const Box& box, int comps, T& t));

protected:

  void makeItSo(const Interval&     a_srcComps,
                const LevelData<T>& a_src,
                BoxLayoutData<T>&   a_dest,
                const Interval&     a_destComps,
                const Copier&       a_copier,
                const LDOperator<T>& a_op = LDOperator<T>()) const;

  DisjointBoxLayout m_disjointBoxLayout;

  IntVect   m_ghost;

  // attempt to speed up the periodic code
  //Copier m_exchangeCopier;

  //========================================================================
  //
  // data structures used by makeItSo when we have some
  // data that needs to be moved (ie. there are entries
  // in the 'FROM' or 'TO' CopyIterators)
  //
  void completePendingSends() const;

  void allocateBuffers(const LevelData<T>& a_src,
                       const Interval& a_srcComps,
                       const BoxLayoutData<T>& a_dest,
                       const Interval& a_destComps,
                       const Copier&   a_copier,
                       const LDOperator<T>& a_op) const;

  void writeSendDataFromMeIntoBuffers(const LevelData<T>& a_src,
                                      const Interval& a_srcComps,
                                      const LDOperator<T>& a_op) const;

  void postSendsFromMe() const ;

  void postReceivesToMe() const ;

  void unpackReceivesToMe(BoxLayoutData<T>& a_dest,
                          const Interval&   a_destComps,
                          const LDOperator<T>& a_op) const ;

  mutable void*  m_sendbuffer; // pointer member OK here,
                               // since LevelData<T> has no copy
  mutable size_t m_sendcapacity;
  mutable void*  m_recbuffer;  // pointer member OK here,
                               // since LevelData<T> has no copy
  mutable size_t m_reccapacity;

#ifdef CH_MPI

#ifndef DOXYGEN

  struct bufEntry
  {
    void* bufPtr; // pointer into contiguous m_buffer
    size_t size;
    const MotionItem* item;
    unsigned int procID;
    bool operator < (const bufEntry& rhs) const
      {
        if(procID == rhs.procID)
          {
            const Box& left = item->toRegion;
            const Box& right= rhs.item->toRegion;
            if(left.smallEnd() == right.smallEnd())
              {
                return left.bigEnd().lexLT(right.bigEnd());
              }
            else
              {
                return item->toRegion < rhs.item->toRegion;
              }
          }
        //else
        return procID < rhs.procID;
      }
  };

#endif
  mutable std::vector<bufEntry> m_fromMe;
  mutable std::vector<bufEntry> m_toMe;

  mutable MPI_Request  *m_sendRequests, *m_receiveRequests;
  mutable MPI_Status   *m_sendStatus,   *m_receiveStatus;
  mutable int numSends, numReceives;

#endif

#ifdef DOXYGEN
  friend void aliasLevelData<T>(LevelData<T>& a_alias,
                                LevelData<T>* a_original,
                                const Interval& a_interval);
#endif

};


template <class T>
void aliasLevelData(LevelData<T>& a_alias, LevelData<T>* a_original,
                    const Interval& a_interval)
{
  AliasDataFactory<T> factory(a_original, a_interval);
  a_alias.define(a_original->disjointBoxLayout(), a_interval.size(), a_original->ghostVect(), factory);
}


// ====== inlined function definitions ================

// As with the BoxLayoutData implementation file.  This file
// just gives the interface and the inline implmentations
// are given in LevelDataI.H

#include "LevelDataI.H"



#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -