18#include "../abbrevi.h"
19#include "../myAssert.h"
20#include "../indices/index.h"
22#include "../primes/prime.h"
23#include "../sgrid/depth.h"
24#include "../sgrid/sparseGrid.h"
28#include "../sgrid/ListOfDepthOrderedGrids.h"
29#include "../sgrid/multilevelSparseGrid.h"
34#include "../sgrid/multiDepthHashGrid.h"
95class ExprSparseG_Restriction_SubgridDepth {
98 ExprSparseG_Restriction_SubgridDepth(
const ExprSparseG<A> &a,
const SubgridFixedDepth &iterObj_)
99 : a_(a), iterObj(iterObj_) {}
101 inline double getValue(
int i,
const IndexDimension &I)
const {
103 return a_.getValue(i, I);
106 ExpressionDescription getDescription()
const {
107 return a_.getDescription();
121inline ExprSparseG_Restriction_SubgridDepth<A> operator|(
const ExprSparseG<A> &a,
const SubgridFixedDepth &iterObj) {
123 return ExprSparseG_Restriction_SubgridDepth<A>(a, iterObj);
130class ExprSparseG_Restriction_FixedIndex {
133 ExprSparseG_Restriction_FixedIndex(
const ExprSparseG<A> &a,
const IndexDimension &iterObj_)
134 : a_(a), iterObj(iterObj_) {}
136 inline double getValue(
int i,
const IndexDimension &I)
const {
137 return a_.getValue(i, I);
140 ExpressionDescription getDescription()
const {
141 return a_.getDescription();
146 IndexDimension getIndex()
const {
return iterObj; }
151 const IndexDimension iterObj;
164class DoubleSubgridExpr {
167 DoubleSubgridExpr(
double d_,
SubgridFixedDepth itObj_) : d(d_), itObj(itObj_) {};
171 double getValue()
const {
return d; };
179class DoubleDepthExpr {
182 DoubleDepthExpr(
double d_, Depth itObj_) : d(d_), itObj(itObj_) {};
184 Depth getDepth()
const {
return itObj; };
186 double getValue()
const {
return d; };
194inline DoubleSubgridExpr
196 return DoubleSubgridExpr(d, itObj);
200inline DoubleDepthExpr
201operator|(
double d,
const Depth &itObj) {
202 return DoubleDepthExpr(d, itObj);
206class DoubleIndexExpr {
209 DoubleIndexExpr(
double d_, IndexDimension itObj_) : d(d_), itObj(itObj_) {};
211 IndexDimension getIndex()
const {
return itObj; };
213 double getValue()
const {
return d; };
216 IndexDimension itObj;
221inline DoubleIndexExpr
222operator|(
double d,
const IndexDimension &itObj) {
223 return DoubleIndexExpr(d, itObj);
247 class VectorSparseG :
public ExprSparseG<VectorSparseG> {
261 VectorSparseG(VectorSparseG &u);
269 double *getDatatableVector() {
return dataTableVector; }
273 void operator=(
const ExprSparseG<A> &a);
277 void operator=(
const ExprSparseG_Restriction_SubgridDepth<A> &a);
280 void operator=(
const ExprSparseG_Restriction_FixedIndex<A> &a);
282 void operator=(
const VectorSparseG &v);
284 void operator=(VectorSparseG &v);
286 inline void operator=(
double x);
288 bool operator==(
const VectorSparseG &v);
290 void setMultiLevelValues2(MultiLevelVector &a, Depth &T);
292 void addMultiLevelValues2(MultiLevelVector &a, Depth &T);
293 void setMultiLevelValues(MultiLevelVector &a, Depth &T);
295 inline void operator=(
const DoubleSubgridExpr &a);
297 inline void operator=(
const DoubleIndexExpr &a);
299 inline bool workonindex(
unsigned long i) {
301 if ((sparseGrid->WorkOnHangingNodes) || (!(sparseGrid->WorkOnHangingNodes) && sparseGrid->getActiveTable()[i]))
307 ExpressionDescription getDescription()
const {
return ExpressionDescription(
false); }
323 void Print(
int level);
325 void PrintDouble(
int level);
327 void PrintDoubleTwoD(
int level, Depth T);
330 void PrintIntTwoD(
int level);
332 void PrintDoubleTwoD(
int level);
335 void PrintDoubleOneD(
int level);
337 void PrintIntOneD(
int level);
339 void Print_vtk(std::ostream &Datei);
341 void Print_gnu(
string name);
343 void PrintIndexTwoD(
int d,
int level);
346 inline double getValue(
int i,
const IndexDimension &I)
const {
return dataTableVector[i]; };
348 inline double getValue(IndexDimension &I)
const {
350 if (sparseGrid->occupied(k, I))
return dataTableVector[k];
355 inline double getValue(
unsigned long k)
const {
357 return dataTableVector[k];
362 inline double getValue(
const IndexDimension &I)
const {
364 if (sparseGrid->occupied(k, I))
return dataTableVector[k];
369 inline double getValue(
unsigned long k) {
370 return dataTableVector[k];
373 inline double getValue(
const IndexDimension &I,
const SingleDepthHashGrid *singleDepthHashGrid)
const {
375 if (singleDepthHashGrid->occupied(k, I))
return dataTableVector[k];
380 inline bool setValue(IndexDimension &I,
double x)
const {
382 if (sparseGrid->occupied(k, I)) {
383 dataTableVector[k] = x;
390 inline bool setValue(
unsigned long k,
double x)
const {
392 dataTableVector[k] = x;
398 inline bool addToValue(
unsigned long k,
double x)
const {
400 dataTableVector[k] += x;
404 inline bool addToValueNoOMP(
unsigned long k,
double x)
const {
405 dataTableVector[k] += x;
408 inline bool addToValue(IndexDimension &I,
double x)
const {
410 if (sparseGrid->occupied(k, I)) {
411 dataTableVector[k] += x;
422 void Broadcast(
int rank);
426 void sendTo(
int torank);
428 void ReduceSum(
int rank);
431 Process *getProcess() {
return sparseGrid->mpi; }
435 double *dataTableVector;
438 bool constructed=
false;
451template <
class A,
class B>
452double product(
const ExprSparseG<A>& a,
const ExprSparseG<B>& b );
456double Maximum (
const ExprSparseG<A>& a );
460double Minimum (
const ExprSparseG<A>& a );
466template<
typename A,
typename B>
double product(
const ExprSparseG<A>& a,
const ExprSparseG<B>& b)
476 unsigned long endIndex = sparseGridA->maximalOccupiedSecondTable;
478 dataInteger* secondTable = sparseGridA->
secondTable;
483 if(ao.getDescription().isIndexNeeded()|| bo.getDescription().isIndexNeeded()) {
485 for(
unsigned long i = 0;i < endIndex; ++i) {
486 if(secondTable[i]!=0) {
492 value = value + ax*bx;
499 IndexDimension Idummy;
500 for(
unsigned long i = 0;i < endIndex; ++i) {
501 if(secondTable[i]!=0) {
502 double ax = ao.getValue(i,Idummy);
503 double bx = bo.getValue(i,Idummy);
505 value = value + ax*bx;
526void VectorSparseG::operator=(
const ExprSparseG<A>& a) {
531 unsigned long endIndex = sparseGrid->maximalOccupiedSecondTable;
533 dataInteger* secondTable = sparseGrid->secondTable;
536 if(ao.getDescription().isIndexNeeded()) {
538 for(
unsigned long i = 0;i < endIndex; ++i) {
541 dataTableVector[i] = ao.getValue(i, sparseGrid->getIndexOfTable(i));
547 IndexDimension Idummy;
548 for(
unsigned long i = 0;i < endIndex; ++i) {
549 if(secondTable[i]!=0)
552 dataTableVector[i]=ao.getValue(i,Idummy);
572void VectorSparseG::operator=(
const ExprSparseG_Restriction_SubgridDepth<A>& a) {
577 dataInteger *secondTable = sparseGrid->secondTable;
584 for (
bool weiter =
true; weiter; weiter = itobj.next()) {
586 unsigned long i = itobj.geti();
587 if (a.getDescription().isIndexNeeded()) {
588 if (secondTable[i] != 0)
590 dataTableVector[i] = a.getValue(i, itobj.getPoint());
592 IndexDimension Idummy;
593 if (secondTable[i] != 0)
595 dataTableVector[i] = a.getValue(i, Idummy);
603void VectorSparseG::operator=(
const ExprSparseG_Restriction_FixedIndex<A> &a) {
612 IndexDimension Index = a.getIndex();
614 if (sparseGrid->occupied(k, Index)) {
616 dataTableVector[k] = a.getValue(k, Index);
637void VectorSparseG::operator=(
const DoubleSubgridExpr &a) {
643 double value = a.getValue();
645 for (
bool weiter =
true; weiter; weiter = itobj.next()) {
646 unsigned long i = itobj.geti();
648 dataTableVector[i] = value;
654void VectorSparseG::operator=(
const DoubleIndexExpr &a) {
658 IndexDimension Index = a.getIndex();
660 if (sparseGrid->occupied(k, Index)) {
662 dataTableVector[k] = a.getValue();
684inline void VectorSparseG::operator=(
double x) {
687 unsigned long endIndex = sparseGrid->maximalOccupiedSecondTable;
689 dataInteger *secondTable = sparseGrid->secondTable;
694 for (
unsigned long i = 0; i <= endIndex; ++i) {
695 if (secondTable[i] != 0) {
696 if (sparseGrid->workonindex(i))
697 dataTableVector[i] = x;
Definition sparseGrid.h:86
IndexDimension getIndexOfTable(unsigned long i)
Definition sparseGrid.h:566
unsigned long * secondTable
0 means empty; v>0 means v-1 is array index
Definition sparseGrid.h:232
Definition sparseGrid.h:277
Definition ListOfDepthOrderedGrids.h:82
Definition ListOfDepthOrderedGrids.h:31