Intrepid
Intrepid_ArrayToolsDefScalar_Kokkos.hpp
1 
2 namespace ArrayToolsKokkos{
3 template<class Scalar, class ArrayOutData, class ArrayInDataLeft, class ArrayInDataRight>
4 void ArrayTools::scalarMultiplyDataData2(ArrayOutData & outputData,
5  ArrayInDataLeft & inputDataLeft,
6  ArrayInDataRight & inputDataRight,
7  const bool reciprocal) {
8 
9 #ifdef HAVE_INTREPID_DEBUG
10  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataLeft.rank() != 2), std::invalid_argument,
11  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Left input data container must have rank 2.");
12  if (outputData.rank() <= inputDataRight.rank()) {
13  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.rank() < 2) || (inputDataRight.rank() > 4) ), std::invalid_argument,
14  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input data container must have rank 2, 3, or 4.");
15  TEUCHOS_TEST_FOR_EXCEPTION( (outputData.rank() != inputDataRight.rank()), std::invalid_argument,
16  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input and output data containers must have the same rank.");
17  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(0) != inputDataLeft.dimension(0) ), std::invalid_argument,
18  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimensions (number of integration domains) of the left and right data input containers must agree!");
19  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.dimension(1) != inputDataLeft.dimension(1)) && (inputDataLeft.dimension(1) != 1) ), std::invalid_argument,
20  ">>> ERROR (ArrayTools::scalarMultiplyDataData): First dimensions of the left and right data input containers (number of integration points) must agree or first dimension of the left data input container must be 1!");
21  for (int i=0; i<inputDataRight.rank(); i++) {
22  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataData): Dimension ";
23  errmsg += (char)(48+i);
24  errmsg += " of the right input and output data containers must agree!";
25  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(i) != outputData.dimension(i)), std::invalid_argument, errmsg );
26  }
27  }
28  else {
29  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.rank() < 1) || (inputDataRight.rank() > 3) ), std::invalid_argument,
30  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input data container must have rank 1, 2, or 3.");
31  TEUCHOS_TEST_FOR_EXCEPTION( (outputData.rank() != inputDataRight.rank()+1), std::invalid_argument,
32  ">>> ERROR (ArrayTools::scalarMultiplyDataData): The rank of the right input data container must be one less than the rank of the output data container.");
33  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.dimension(0) != inputDataLeft.dimension(1)) && (inputDataLeft.dimension(1) != 1) ), std::invalid_argument,
34  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimension of the right input data container and first dimension of the left data input container (number of integration points) must agree or first dimension of the left data input container must be 1!");
35  TEUCHOS_TEST_FOR_EXCEPTION( ( inputDataLeft.dimension(0) != outputData.dimension(0) ), std::invalid_argument,
36  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimensions of data output and left data input containers (number of integration domains) must agree!");
37  for (int i=0; i<inputDataRight.rank(); i++) {
38  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataData): Dimensions ";
39  errmsg += (char)(48+i);
40  errmsg += " and ";
41  errmsg += (char)(48+i+1);
42  errmsg += " of the right input and output data containers must agree!";
43  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(i) != outputData.dimension(i+1)), std::invalid_argument, errmsg );
44  }
45  }
46 #endif
47 
48  // get sizes
49  int invalRank = inputDataRight.rank();
50  int outvalRank = outputData.rank();
51  int numCells = outputData.dimension(0);
52  int numPoints = outputData.dimension(1);
53  int numDataPoints = inputDataLeft.dimension(1);
54  int dim1Tens = 0;
55  int dim2Tens = 0;
56  if (outvalRank > 2) {
57  dim1Tens = outputData.dimension(2);
58  if (outvalRank > 3) {
59  dim2Tens = outputData.dimension(3);
60  }
61  }
62 
63  if (outvalRank == invalRank) {
64 
65  if (numDataPoints != 1) { // nonconstant data
66 
67  if (reciprocal) {
68  for(int cl = 0; cl < numCells; cl++) {
69  for(int pt = 0; pt < numPoints; pt++) {
70  outputData(cl, pt) = inputDataRight(cl, pt)/inputDataLeft(cl, pt);
71  } // P-loop
72  } // C-loop
73  }
74  else {
75  for(int cl = 0; cl < numCells; cl++) {
76  for(int pt = 0; pt < numPoints; pt++) {
77  outputData(cl, pt) = inputDataRight(cl, pt)*inputDataLeft(cl, pt);
78  } // P-loop
79  } // C-loop
80  }
81  }// case 2
82 
83 
84  /* default:
85  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 2) || (invalRank == 3) || (invalRank == 4) ), std::invalid_argument,
86  ">>> ERROR (ArrayTools::scalarMultiplyDataData): This branch of the method is defined only for rank-2, 3 or 4 containers.");*/
87  }// invalRank
88 
89  }
90  else { // constant left data
91 
92  if (reciprocal) {
93  for(int cl = 0; cl < numCells; cl++) {
94  for(int pt = 0; pt < numPoints; pt++) {
95  outputData(cl, pt) = inputDataRight(cl, pt)/inputDataLeft(cl, 0);
96  } // P-loop
97  } // C-loop
98  }
99  else {
100  for(int cl = 0; cl < numCells; cl++) {
101  for(int pt = 0; pt < numPoints; pt++) {
102  outputData(cl, pt) = inputDataRight(cl, pt)*inputDataLeft(cl, 0);
103  } // P-loop
104  } // C-loop
105  }
106  }// case 2
107 
108 
109 
110 
111  /* default:
112  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 2) || (invalRank == 3) || (invalRank == 4) ), std::invalid_argument,
113  ">>> ERROR (ArrayTools::scalarMultiplyDataData): This branch of the method is defined only for rank-2, 3 or 4 input containers.");*/
114 
115  } // invalRank
116  } // numDataPoints
117 
118  }
119  else {
120 
121  if (numDataPoints != 1) { // nonconstant data
122 
123  if (reciprocal) {
124  for(int cl = 0; cl < numCells; cl++) {
125  for(int pt = 0; pt < numPoints; pt++) {
126  for( int iVec = 0; iVec < dim1Tens; iVec++) {
127  outputData(cl, pt, iVec) = inputDataRight(pt, iVec)/inputDataLeft(cl, pt);
128  } // D1-loop
129  } // P-loop
130  } // C-loop
131  }
132  else {
133  for(int cl = 0; cl < numCells; cl++) {
134  for(int pt = 0; pt < numPoints; pt++) {
135  for( int iVec = 0; iVec < dim1Tens; iVec++) {
136  outputData(cl, pt, iVec) = inputDataRight(pt, iVec)*inputDataLeft(cl, pt);
137  } // D1-loop
138  } // P-loop
139  } // C-loop
140  }
141  }// case 2
142 
143 
144 
145  // default:
146  // TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 1) || (invalRank == 2) || (invalRank == 3) ), std::invalid_argument,
147  // ">>> ERROR (ArrayTools::scalarMultiplyDataData): This branch of the method is defined only for rank-1, 2 or 3 input containers.");
148  }// invalRank
149 
150  }
151  else { //constant data
152 
153 if (reciprocal) {
154  for(int cl = 0; cl < numCells; cl++) {
155  for(int pt = 0; pt < numPoints; pt++) {
156  for( int iVec = 0; iVec < dim1Tens; iVec++) {
157  outputData(cl, pt, iVec) = inputDataRight(pt, iVec)/inputDataLeft(cl, 0);
158  } // D1-loop
159  } // P-loop
160  } // C-loop
161  }
162  else {
163  for(int cl = 0; cl < numCells; cl++) {
164  for(int pt = 0; pt < numPoints; pt++) {
165  for( int iVec = 0; iVec < dim1Tens; iVec++) {
166  outputData(cl, pt, iVec) = inputDataRight(pt, iVec)*inputDataLeft(cl, 0);
167  } // D1-loop
168  } // P-loop
169  } // C-loop
170  }
171  }// case 2
172 
173 
174 
175 
176  /* default:
177  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 1) || (invalRank == 2) || (invalRank == 3) ), std::invalid_argument,
178  ">>> ERROR (ArrayTools::scalarMultiplyDataData): This branch of the method is defined only for rank-1, 2 or 3 input containers.");*/
179 
180  } // invalRank
181  } // numDataPoints
182 
183  } // end if (outvalRank = invalRank)
184 
185 } // scalarMultiplyDataData
186 
187 } //ArrayToolsKokkos