escript  Revision_
escriptcore/src/IndexList.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2018 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 #ifndef __ESCRIPT_INDEXLIST_H__
18 #define __ESCRIPT_INDEXLIST_H__
19 
20 #include <escript/DataTypes.h>
21 
22 // pre-reserving saves time under OpenMP. The 85 is a value taken over
23 // from revision ~101 by jgs.
24 #define ESYS_INDEXLIST_LENGTH 85
25 
26 namespace escript {
27 
28 struct IndexList {
29  IndexList() : n(0), extension(NULL) {}
30  ~IndexList() { delete extension; }
31 
35 
37  inline void insertIndex(DataTypes::index_t index)
38  {
39  for (DataTypes::dim_t i=0; i<n; i++) {
40  if (m_list[i] == index)
41  return;
42  }
43  if (n < ESYS_INDEXLIST_LENGTH) {
44  m_list[n++] = index;
45  } else {
46  if (extension == NULL)
47  extension = new IndexList();
48  extension->insertIndex(index);
49  }
50  }
51 
53  inline DataTypes::dim_t count(DataTypes::index_t range_min,
54  DataTypes::index_t range_max) const
55  {
56  DataTypes::dim_t out=0;
57  for (DataTypes::dim_t i=0; i < n; i++) {
58  if (m_list[i] >= range_min && range_max > m_list[i])
59  ++out;
60  }
61  if (extension)
62  out += extension->count(range_min, range_max);
63  return out;
64  }
65 
67  inline void toArray(DataTypes::index_t* array,
68  DataTypes::index_t range_min, DataTypes::index_t range_max,
69  DataTypes::index_t index_offset) const
70  {
71  DataTypes::index_t idx = 0;
72  for (DataTypes::dim_t i=0; i < n; i++) {
73  if (m_list[i] >= range_min && range_max > m_list[i]) {
74  array[idx] = m_list[i]+index_offset;
75  ++idx;
76  }
77  }
78  if (extension)
79  extension->toArray(&array[idx], range_min, range_max, index_offset);
80  }
81 };
82 
83 } // namespace escript
84 
85 #endif // __ESCRIPT_INDEXLIST_H__
86 
escript::IndexList::toArray
void toArray(DataTypes::index_t *array, DataTypes::index_t range_min, DataTypes::index_t range_max, DataTypes::index_t index_offset) const
index list to array
Definition: escriptcore/src/IndexList.h:66
INDEX2
#define INDEX2(_X1_, _X2_, _N1_)
Definition: index.h:21
escript::IndexList::insertIndex
void insertIndex(DataTypes::index_t index)
inserts row index into the IndexList in if it does not exist
Definition: escriptcore/src/IndexList.h:36
dudley::IndexList_insertElementsWithRowRangeNoMainDiagonal
void IndexList_insertElementsWithRowRangeNoMainDiagonal(IndexList *indexList, index_t firstRow, index_t lastRow, const ElementFile *elements, const index_t *map)
Definition: dudley/src/IndexList.cpp:74
IndexList.h
finley::const_ReferenceElement_ptr
boost::shared_ptr< const ReferenceElement > const_ReferenceElement_ptr
Definition: ReferenceElements.h:211
dudley::IndexList_insertElements
void IndexList_insertElements(IndexList *index_list, const ElementFile *elements, const index_t *map)
Definition: dudley/src/IndexList.cpp:46
escript::IndexList::count
DataTypes::dim_t count(DataTypes::index_t range_min, DataTypes::index_t range_max) const
counts the number of row indices in the IndexList in
Definition: escriptcore/src/IndexList.h:52
dudley
A suite of factory methods for creating 2D and 3D dudley domains.
Definition: dudley/src/Assemble.h:31
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:87
escript::IndexList::m_list
DataTypes::index_t m_list[85]
Definition: escriptcore/src/IndexList.h:31
ElementFile.h
ElementFile.h
IndexList.h
escript::IndexList::extension
IndexList * extension
Definition: escriptcore/src/IndexList.h:33
escript::IndexList::n
DataTypes::dim_t n
Definition: escriptcore/src/IndexList.h:32
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:82
escript
Definition: AbstractContinuousDomain.cpp:22
escript::IndexList::IndexList
IndexList()
Definition: escriptcore/src/IndexList.h:28
escript::IndexList::~IndexList
~IndexList()
Definition: escriptcore/src/IndexList.h:29
finley::IndexList_insertElementsWithRowRangeNoMainDiagonal
void IndexList_insertElementsWithRowRangeNoMainDiagonal(IndexList *index_list, index_t firstRow, index_t lastRow, ElementFile *elements, index_t *row_map, index_t *col_map)
Definition: finley/src/IndexList.cpp:101
finley::IndexList_insertElements
void IndexList_insertElements(IndexList *index_list, ElementFile *elements, bool reduce_row_order, const index_t *row_map, bool reduce_col_order, const index_t *col_map)
Definition: finley/src/IndexList.cpp:48
ESYS_INDEXLIST_LENGTH
#define ESYS_INDEXLIST_LENGTH
Definition: escriptcore/src/IndexList.h:23
escript::IndexList
Definition: escriptcore/src/IndexList.h:27
finley
A suite of factory methods for creating various finley domains.
Definition: finley/src/Assemble.h:31