LoAdSG
PoissonStencil.h
1//
2// Created by to35jepo on 2/16/23.
3//
4
5#ifndef SGRUN_POISSONSTENCIL_H
6#define SGRUN_POISSONSTENCIL_H
7
8#include "../extemp/vector.h"
9#include "../myMath/myMath.h"
10#include "../cells/celldimension.h"
11enum TypeMatrixVectorMultiplication { StencilOnTheFly, StoreLocalStiffnessMatrix};
12
13
14class PoissonStencil {
15public:
16 virtual inline void applyStencilOnCell_MPI_OMP(CellDimension& cell,VectorSparseG& input, VectorSparseG& output) {
17 cout << " PoissonStencil::applyStencilOnCell_MPI_OMP NOT IMPLEMENTED YET!" << endl;
18 exit(1);
19 }
20 virtual inline void applyStencilOnCell_MPI_OMP_nosymmetry(CellDimension& cell,VectorSparseG& input, VectorSparseG& output) {
21 cout << " PoissonStencil::applyStencilOnCell_MPI_OMP_nosymmetry NOT IMPLEMENTED YET!" << endl;
22 exit(1);
23 }
24 virtual inline void applyStencilOnCell(CellDimension& cell,VectorSparseG& input, VectorSparseG& output){
25 cout << " PoissonStencil::applyStencilOnCell NOT IMPLEMENTED YET!" << endl;
26 exit(1);
27 }
28 virtual inline void applyStencilOnCell_BinaryIterator(CellDimension& cell,VectorSparseG& input, VectorSparseG& output){
29 cout << " PoissonStencil::applyStencilOnCell_BinaryIterator NOT IMPLEMENTED YET!" << endl;
30 exit(1);
31 }
32 void initialize(Depth &T_);
33 inline double returnValue(const IndexDimension &Index,const MultiDimCompass &mc) const {
34
35 double factors[DimensionSparseGrid];
36 for (int j = 0; j < DimensionSparseGrid; ++j) {
37 double h = meshwidth[j];
38 Richtung r = mc.getRichtung(j);
39 factors[j] = (1.0 / 6.0) * h;
40 if(r == Mitte) {
41 if((!Index.isAtLeftBoundary(j)) && (!Index.isAtRightBoundary(j)))factors[j] *= 4.0;
42 else factors[j] *= 2.0;
43 }
44 }
45
46 // Stencil == Stiffness
47 double sum = 0.0;
48 for (int i = 0; i < DimensionSparseGrid; i++) {
49 // int du/dxi * dv/dxi d(x1...xd)
50 double prod = 1.0;
51 for (int j = 0; j < DimensionSparseGrid; ++j) {
52 // integral factor in direction j
53 if (i == j) {
54 double h = meshwidth[j];
55 Richtung r = mc.getRichtung(j);
56 // factor: int du/dxi * dv/dxi dxi
57 prod *= (1.0 / h);
58 if (r != Mitte) {
59 prod *= -1.0;
60 } else if((!Index.isAtLeftBoundary(j)) && (!Index.isAtRightBoundary(j))){
61 prod *= 2.0;
62 }
63 } else {
64 // factor int du/dxi*dv/dxi dxj = int u*v*xj
65 prod *= factors[j];
66 }
67 }
68 sum += prod;
69 }
70 return sum;
71 }
72
73 TypeMatrixVectorMultiplication getTypeMatrixVectorMultiplication(){return typeMatrixVectorMultiplication;};
74
75
76private:
77 double meshwidth[DimensionSparseGrid];
78
79 TypeMatrixVectorMultiplication typeMatrixVectorMultiplication = StencilOnTheFly;
80};
81
82
83#endif //SGRUN_POISSONSTENCIL_H
Definition index.h:356