This file is indexed.

/usr/include/dune/grid/uggrid/ugmessagebuffer.hh is in libdune-grid-dev 2.5.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef UG_MESSAGE_BUFFER_HH
#define UG_MESSAGE_BUFFER_HH

#include <algorithm>

#include <dune/common/parallel/mpihelper.hh>

#include <dune/grid/common/gridenums.hh>

namespace Dune {

  /** converts the UG speak message buffers to DUNE speak and vice-versa */
  template <class DataHandle, int GridDim, int codim>
  class UGMessageBufferBase {
  protected:
    typedef UGMessageBufferBase<DataHandle, GridDim, codim>  ThisType;
    typedef UGGrid<GridDim>                              GridType;
    typedef typename DataHandle::DataType DataType;

    enum {
      dim = GridDim
    };

    UGMessageBufferBase(void *ugData)
    {
      ugData_ = static_cast<char*>(ugData);
    };

  public:
    void write(const DataType &t)
    { this->writeRaw_<DataType>(t);  }

    void read(DataType &t)
    { this->readRaw_<DataType>(t);  }

  protected:
    friend class Dune::UGGrid<dim>;

    template <class ValueType>
    void writeRaw_(const ValueType &v)
    {
      *reinterpret_cast<ValueType*>(ugData_) = v;
      ugData_ += sizeof(ValueType);
    }

    template <class ValueType>
    void readRaw_(ValueType &v)
    {
      v = *reinterpret_cast<ValueType*>(ugData_);
      ugData_ += sizeof(ValueType);
    }

    // called by DDD_IFOneway to serialize the data structure to
    // be send
    static int ugGather_(typename UG_NS<dim>::DDD_OBJ obj, void* data)
    {
      // cast the DDD object to a UG entity pointer
      typedef typename Dune::UG_NS<dim>::template Entity<codim>::T* UGEntityPointer;
      UGEntityPointer ugEP = reinterpret_cast<typename Dune::UG_NS<dim>::template Entity<codim>::T*>(obj);

      // construct a DUNE makeable entity from the UG entity pointer
      /** \bug The nullptr argument should actually the UGGrid object.  But that is hard to obtain here,
       * and the argument is (currently) only used for the boundarySegmentIndex method, which we don't call. */
      typedef UGMakeableEntity<codim, dim, UGGrid<dim> > DuneMakeableEntity;
      DuneMakeableEntity entity(ugEP, nullptr);

      // safety check to only communicate what is needed
      if ((level == -1 && UG_NS<dim>::isLeaf(ugEP)) || entity.level() == level)
      {
        ThisType msgBuf(static_cast<DataType*>(data));
        if (!duneDataHandle_->fixedSize(dim, codim))
          msgBuf.template writeRaw_<unsigned>(duneDataHandle_->size(entity));
        duneDataHandle_->gather(msgBuf, entity);
      }

      return 0;
    }

    // called by DDD_IFOneway to deserialize the data structure
    // that has been received
    static int ugScatter_(typename UG_NS<dim>::DDD_OBJ obj, void* data)
    {
      // cast the DDD object to a UG entity pointer
      typedef typename Dune::UG_NS<dim>::template Entity<codim>::T* UGEntityPointer;
      UGEntityPointer ugEP = reinterpret_cast<typename Dune::UG_NS<dim>::template Entity<codim>::T*>(obj);

      // construct a DUNE makeable entity from the UG entity pointer
      /** \bug The nullptr argument should actually the UGGrid object.  But that is hard to obtain here,
       * and the argument is (currently) only used for the boundarySegmentIndex method, which we don't call. */
      typedef UGMakeableEntity<codim, dim, UGGrid<dim> > DuneMakeableEntity;
      DuneMakeableEntity entity(ugEP, nullptr);

      // safety check to only communicate what is needed
      if ((level == -1 && UG_NS<dim>::isLeaf(ugEP)) || entity.level() == level)
      {
        ThisType msgBuf(static_cast<DataType*>(data));
        int size;
        if (!duneDataHandle_->fixedSize(dim, codim))
          msgBuf.readRaw_(size);
        else
          size = duneDataHandle_->template size<DuneMakeableEntity>(entity);
        if (size > 0)
          duneDataHandle_->template scatter<ThisType, DuneMakeableEntity>(msgBuf, entity, size);

      }

      return 0;
    }

    static DataHandle *duneDataHandle_;
    static int level;
    char *ugData_;
  };

  template <class DataHandle, int GridDim, int codim>
  class UGMessageBuffer
    : public UGMessageBufferBase<DataHandle, GridDim, codim>
  {
    typedef typename DataHandle::DataType DataType;
    typedef UGMessageBufferBase<DataHandle, GridDim, codim> Base;
    enum { dim = GridDim };

  protected:
    friend class Dune::UGGrid<dim>;

    UGMessageBuffer(void *ugData)
      : Base(ugData)
    {}

    // returns number of bytes required for the UG message buffer
    template <class GridView>
    static unsigned ugBufferSize_(const GridView &gv)
    {
      if (Base::duneDataHandle_->fixedSize(dim, codim)) {
        return sizeof(DataType)
               * Base::duneDataHandle_->size(*gv.template begin<codim,InteriorBorder_Partition>());
      }

      // iterate over all entities, find the maximum size for
      // the current rank
      int maxSize = 0;
      typedef typename
      GridView
      ::template Codim<codim>
      ::template Partition<Dune::All_Partition>
      ::Iterator Iterator;
      Iterator it = gv.template begin<codim, Dune::All_Partition>();
      const Iterator endIt = gv.template end<codim, Dune::All_Partition>();
      for (; it != endIt; ++it) {
        maxSize = std::max((int) maxSize,
                           (int) Base::duneDataHandle_->size(*it));
      }

      // find maximum size for all ranks
      maxSize = MPIHelper::getCollectiveCommunication().max(maxSize);
      if (!maxSize)
        return 0;

      // add the size of an unsigned integer to the actual
      // buffer size. (we somewhere have to store the actual
      // number of objects for each entity.)
      return sizeof(unsigned) + sizeof(DataType)*maxSize;
    }
  };

  template <class DataHandle, int GridDim, int codim>
  class UGEdgeAndFaceMessageBuffer
    : public UGMessageBufferBase<DataHandle, GridDim, codim>
  {
    enum {dim = GridDim};
    typedef typename DataHandle::DataType DataType;
    typedef UGMessageBufferBase<DataHandle, GridDim, codim> Base;
  protected:
    friend class Dune::UGGrid<dim>;

    UGEdgeAndFaceMessageBuffer(void *ugData)
      : Base(ugData)
    {}

    // returns number of bytes required for the UG message buffer
    template <class GridView>
    static unsigned ugBufferSize_(const GridView &gv)
    {
      if (Base::duneDataHandle_->fixedSize(dim, codim)) {
        typedef typename GridView::template Codim<0>::template Partition<InteriorBorder_Partition>::Iterator ElementIterator;
        ElementIterator element = gv.template begin<0, InteriorBorder_Partition>();
        return sizeof(DataType)
               * Base::duneDataHandle_->size(element->template subEntity<codim>(0));
      }

      // iterate over all entities, find the maximum size for
      // the current rank
      int maxSize = 0;
      typedef typename
      GridView
      ::template Codim<0>
      ::template Partition<Dune::All_Partition>
      ::Iterator Iterator;
      Iterator it = gv.template begin<0, Dune::All_Partition>();
      const Iterator endIt = gv.template end<0, Dune::All_Partition>();
      for (; it != endIt; ++it) {
        int numberOfSubentities = it->subEntities(codim);
        for (int k = 0; k < numberOfSubentities; k++)
        {
          typedef typename GridView::template Codim<0>::Entity Element;
          typedef typename Element::template Codim<codim>::Entity SubEntity;
          const SubEntity subEntity(it->template subEntity<codim>(k));

          maxSize = std::max((int) maxSize,
                             (int) Base::duneDataHandle_->size(subEntity));
        }
      }

      // find maximum size for all ranks
      maxSize = MPIHelper::getCollectiveCommunication().max(maxSize);
      if (!maxSize)
        return 0;

      // add the size of an unsigned integer to the actual
      // buffer size. (we somewhere have to store the actual
      // number of objects for each entity.)
      return sizeof(unsigned) + sizeof(DataType)*maxSize;
    }
  };

  template <class DataHandle>
  class UGMessageBuffer<DataHandle, 2, 1>
    : public UGEdgeAndFaceMessageBuffer<DataHandle, 2, 1>
  {};

  template <class DataHandle>
  class UGMessageBuffer<DataHandle, 3, 2>
    : public UGEdgeAndFaceMessageBuffer<DataHandle, 3, 2>
  {};

  template <class DataHandle>
  class UGMessageBuffer<DataHandle, 3, 1>
    : public UGEdgeAndFaceMessageBuffer<DataHandle, 3, 1>
  {};

}   // end namespace Dune

#endif  // UG_MESSAGE_BUFFER_HH