CG  Version 25
kkcdefs.h
Go to the documentation of this file.
1 // 100525 macros and other stuff Kyle likes to use
2 
3 // in common/src/getBounds.C : (should use new version in ParallelGridUtility.h)
4 // 101102, now using ParallelGridUtility
5 //extern void
6 //getLocalBoundsAndBoundaryConditions( const realMappedGridFunction & a,
7 // IntegerArray & gidLocal,
8 // IntegerArray & dimensionLocal,
9 // IntegerArray & bcLocal );
10 
11 
12 // Macros that hide the use of PPP when getting local data
13 #ifdef USE_PPP
14 
15 #define OV_GET_LOCAL_ARRAY(TYPE,UU) TYPE ## SerialArray UU ## Local; getLocalArrayWithGhostBoundaries(UU,UU ## Local);
16 #define OV_GET_LOCAL_ARRAY_CONST(TYPE,UU) TYPE ## SerialArray UU ## Local; getLocalArrayWithGhostBoundaries(UU,UU ## Local);
17 #define OV_GET_LOCAL_ARRAY_FROM(TYPE,UU,FROM) TYPE ## SerialArray UU ## Local; getLocalArrayWithGhostBoundaries(FROM,UU ## Local);
18 #define OV_GET_LOCAL_ARRAY_CONDITIONAL(TYPE,UU,boolExp,isTrue, isFalse) TYPE ## SerialArray UU ## Local; \
19  if ( boolExp ) { isTrue; } \
20  else { getLocalArrayWithGhostBoundaries( isFalse, UU ## Local ); }
21 
22 #else
23 
24 #define OV_GET_LOCAL_ARRAY(TYPE,UU) TYPE ## SerialArray & UU ## Local = UU;
25 #define OV_GET_LOCAL_ARRAY_CONST(TYPE,UU) const TYPE ## SerialArray & UU ## Local = UU;
26 #define OV_GET_LOCAL_ARRAY_FROM(TYPE,UU,FROM) TYPE ## SerialArray & UU ## Local = FROM;
27 #define OV_GET_LOCAL_ARRAY_CONDITIONAL(TYPE,UU,boolExp,isTrue, isFalse) TYPE ## SerialArray & UU ## Local = ( boolExp ) ? isTrue : isFalse;
28 
29 #endif
30 
31 // Macros that help extract and use data pointers from A++P++ arrays
32 #define OV_APP_TO_PTR_3D(TYPE,ARRAY, PNAME) TYPE *PNAME = ARRAY.Array_Descriptor.Array_View_Pointer2; \
33  const int PNAME ## _d0 = ARRAY.getRawDataSize(0); \
34  const int PNAME ## _d1 = ARRAY.getRawDataSize(1);
35 
36 #define A_3D(PNAME,i0,i1,i2) PNAME[i0+(PNAME ## _d0)*(i1+(PNAME ## _d1)*(i2))]
37 
38 #define OV_APP_TO_PTR_4D(TYPE,ARRAY, PNAME) TYPE *PNAME = ARRAY.Array_Descriptor.Array_View_Pointer3; \
39  const int PNAME ## _d0 = ARRAY.getRawDataSize(0); \
40  const int PNAME ## _d1 = ARRAY.getRawDataSize(1); \
41  const int PNAME ## _d2 = ARRAY.getRawDataSize(2);
42 
43 #define A_4D(PNAME,i0,i1,i2,i3) PNAME[i0+(PNAME ## _d0)*(i1+(PNAME ## _d1)*(i2+(PNAME ## _d2)*(i3)))]
44 
45 #define OV_APP_TO_PTR_5D(TYPE,ARRAY, PNAME) TYPE *PNAME = ARRAY.Array_Descriptor.Array_View_Pointer4; \
46  const int PNAME ## _d0 = ARRAY.getRawDataSize(0); \
47  const int PNAME ## _d1 = ARRAY.getRawDataSize(1); \
48  const int PNAME ## _d2 = ARRAY.getRawDataSize(2); \
49  const int PNAME ## _d3 = ARRAY.getRawDataSize(3);
50 
51 #define A_5D(PNAME,i0,i1,i2,i3,i4) PNAME[i0+(PNAME ## _d0)*(i1+(PNAME ## _d1)*(i2+(PNAME ## _d2)*(i3+(PNAME ## _d3)*(i4))))]
52 
53 #define OV_RGF_TO_PTR_5D(TYPE,ARRAY, PNAME, ND) TYPE *PNAME = ARRAY.Array_Descriptor.Array_View_Pointer3; \
54  const int PNAME ## _d0 = ARRAY.getRawDataSize(0); \
55  const int PNAME ## _d1 = ARRAY.getRawDataSize(1); \
56  const int PNAME ## _d2 = ARRAY.getRawDataSize(2); \
57  const int PNAME ## _d3 = ND;
58 
59 // use A_5D to access RGF array pointers
60 
61 
62 inline void solveSmallSystem(const int &nd,
63  const ArraySimpleFixed<real,3,3,1,1> &A,
64  const ArraySimpleFixed<real,3,1,1,1> &f,
65  ArraySimpleFixed<real,3,1,1,1> &u)
66 {
67  // solve Au=f for 2 and 3D systems. Because how many times do I have to implement this?
68 
69  real det = nd==3 ?
70  ( A(0,0)*(A(1,1)*A(2,2)-A(1,2)*A(2,1)) - // 3D
71  A(0,1)*(A(1,0)*A(2,2)-A(1,2)*A(2,0)) +
72  A(0,2)*(A(1,0)*A(2,1)-A(2,0)*A(1,2)) ) :
73  ( A(0,0)*A(1,1) - A(0,1)*A(1,0) ); // 2D
74 
75  assert(fabs(det)>10*REAL_EPSILON);
76 
77  real deti=1./det;
78 
79  if ( nd==2 )
80  {
81  u[0] = ( A(1,1)*f[0] - A(0,1)*f[1])*deti;
82  u[1] = (-A(1,0)*f[0] + A(0,0)*f[1])*deti;
83  u[2] = 0.;
84  }
85  else
86  {
87  u[0] = ( (A(1,1)*A(2,2)-A(1,2)*A(2,1))*f(0) -
88  (A(0,1)*A(2,2)-A(0,2)*A(2,1))*f(1) +
89  (A(0,1)*A(1,2)-A(0,2)*A(1,1))*f(2) )*deti;
90 
91  u[1] = (-(A(1,0)*A(2,2)-A(1,2)*A(2,0))*f(0)+
92  (A(0,0)*A(2,2)-A(2,0)*A(0,2))*f(1)-
93  (A(0,0)*A(1,2)-A(0,2)*A(1,0))*f(2) )*deti;
94 
95  u[2] = ( (A(1,0)*A(2,1)-A(1,1)*A(2,0))*f(0) -
96  (A(0,0)*A(2,1)-A(0,1)*A(2,0))*f(1) +
97  (A(0,0)*A(1,1)-A(0,1)*A(1,0))*f(2) )*deti;
98  }
99 }