5#ifndef GRUN_MULTILEVELVECTOR_H
6#define GRUN_MULTILEVELVECTOR_H
9#include "../sgrid/multilevelSparseGrid.h"
12class GetNextSmallerDepthsIterator{
17 GetNextSmallerDepthsIterator(
const Depth& T):startDepth(T),lastDepth(T){
20 Depth operator*()
const{
24 for (
size_t i = 0; i < DimensionSparseGrid; i++)
26 if(lastDepth.at(i)==0)lastDepth.set(startDepth.at(i),i);
28 lastDepth.set(lastDepth.at(i)-1,i);
41class GetNextSmallerDepthsIteratorInner{
46 GetNextSmallerDepthsIteratorInner(
const Depth& T):startDepth(T),lastDepth(T){
49 Depth operator*()
const{
53 for (
size_t i = 0; i < DimensionSparseGrid; i++)
55 if(lastDepth.at(i)==1)lastDepth.set(startDepth.at(i),i);
57 lastDepth.set(lastDepth.at(i)-1,i);
72class MultiLevelVector {
76 MultiLevelVector(MultiLevelAdaptiveSparseGrid &grid);
81 double getValue(
unsigned long i) {
82 return dataTableVector[i];
85 void setValue(
unsigned long i,
double val) {
86 dataTableVector[i]=val;
90 inline void setMultiLevelValues(VectorSparseG &vector, Depth &T);
92 inline void setMultiLevelValues2(VectorSparseG &vector, Depth &T);
94 inline void setMultiLevelValuesOMP(VectorSparseG &vector, Depth &T, MultiDepthHashGrid& multiDepthHashGrid);
98 inline void addMultiLevelValues(VectorSparseG &vector, Depth &T);
102 MultiLevelAdaptiveSparseGrid *getSparseGrid() {
return sparseGrid; };
107 inline void operator=(
double x) {
108 for (
unsigned long i = 0; i < sparseGrid->getMaximalOccupiedSecondTable(); i++)
109 dataTableVector[i] = x;
112 void operator+=(MultiLevelVector &vector) {
113 for (
unsigned long i = 0; i < sparseGrid->getMaximalOccupiedSecondTable(); i++) {
114 dataTableVector[i] = vector.getValue(i);
122 void Broadcast(
int rank);
126 void sendTo(
int torank);
128 void ReduceSum(
int rank);
132 void PrintDoubleTwoD(
int level);
134 void PrintDoubleTwoD(
int level, Depth T);
137 bool workonindex(
unsigned long i);
140 MultiLevelAdaptiveSparseGrid *sparseGrid;
141 double *dataTableVector;
146inline void MultiLevelVector::setMultiLevelValues(VectorSparseG &vector, Depth &T) {
148 double *data2 = vector.getDatatableVector();
152 auto iter = GetNextSmallerDepthsIterator(T);
154 Depth Tlocal = *iter;
155 SingleDepthHashGrid& depthGrid = grid->getMultiDepthHashGrid()->getGridForDepth(Tlocal);
156 const auto& mapping = depthGrid._mapPosToGridPos;
158 for (
size_t i = 0; i < mapping.size(); i++)
161 IndexDimension I = depthGrid._map.getIndexOfTable(i);
162 if (sparseGrid->occupied(k, I, T))
163 dataTableVector[k] = data2[mapping[i]];
172inline void MultiLevelVector::setMultiLevelValues2(VectorSparseG &vector, Depth &T) {
174double *data2 = vector.getDatatableVector();
178 auto iter = GetNextSmallerDepthsIterator(T);
180 Depth Tlocal = *iter;
181 SingleDepthHashGrid& depthGrid = grid->getMultiDepthHashGrid()->getGridForDepth(Tlocal);
182 const auto& mapping = depthGrid._mapPosToGridPos;
184 if(depthGrid.getNumberOfEntries()>0) {
185 int end = mapping.size();
186 for (
size_t i = 0; i < end; i++) {
188 IndexDimension I = depthGrid._map.getIndexOfTable(i);
189 if (sparseGrid->occupied(k, I, T))
190 dataTableVector[k] = data2[mapping[i]];
200inline void MultiLevelVector::setMultiLevelValuesOMP(VectorSparseG &vector, Depth &T, MultiDepthHashGrid& multiDepthHashGrid) {
202 double *data2 = vector.getDatatableVector();
204 auto iter = GetNextSmallerDepthsIterator(T);
206 Depth Tlocal = *iter;
207 SingleDepthHashGrid& depthGrid = multiDepthHashGrid.getGridForDepth(Tlocal);
208 const auto& mapping = depthGrid._mapPosToGridPos;
210 if(depthGrid.getNumberOfEntries()>0) {
211 auto end = mapping.size();
212 for (
size_t i = 0; i < end; i++) {
214 IndexDimension I = depthGrid._map.getIndexOfTable(i);
215 if (sparseGrid->occupied(k, I, T))
216 dataTableVector[k] = data2[mapping[i]];
228 double *data2 = vector.getDatatableVector();
229 ListOfDepthOrderedSubgrids::iterator iter(list);
231 Depth T_new = iter.getDepth();
235 unsigned long i = iter_inner.geti();
236 IndexDimension I = iter_inner.getPoint();
237 if (sparseGrid->occupied(k, I, T))
238 dataTableVector[k] = data2[i];
240 }
while (iter_inner.next());
245 }
while (iter.next());
266inline void MultiLevelVector::addMultiLevelValues(VectorSparseG &vector, Depth &T) {
269 double *data2 = vector.getDatatableVector();
274 auto iter = GetNextSmallerDepthsIterator(T);
276 Depth Tlocal = *iter;
278 SingleDepthHashGrid& depthGrid = grid->getMultiDepthHashGrid()->getGridForDepth(Tlocal);
279 const auto& mapping = depthGrid._mapPosToGridPos;
281 if(depthGrid.getNumberOfEntries()>0) {
282 for (
size_t i = 0; i < mapping.size(); i++) {
284 IndexDimension I = depthGrid._map.getIndexOfTable(i);
285 if (sparseGrid->occupied(k, I, T))
286 dataTableVector[k] = dataTableVector[k] + data2[mapping[i]];
301 ListOfDepthOrderedSubgrids::iterator iter(list);
304 Depth Tlocal = iter.getDepth();
307 inneriter.gotobegin();
309 IndexDimension Index = inneriter.getPoint();
311 if (sparseGrid->occupied(k, Index, T))
312 vector.setValue(Index, dataTableVector[k]);
314 }
while (inneriter.next());
316 }
while (iter.next());
Definition sparseGrid.h:86
Definition ListOfDepthOrderedGrids.h:115
Definition ListOfDepthOrderedGrids.h:82