Intrepid
Intrepid_ArrayToolsDefTensor.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Pavel Bochev (pbboche@sandia.gov)
38 // Denis Ridzal (dridzal@sandia.gov), or
39 // Kara Peterson (kjpeter@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
49 namespace Intrepid {
50 
51  template<class Scalar,
52  class ArrayOutFields,
53  class ArrayInData,
54  class ArrayInFields>
55  void ArrayTools::crossProductDataField(ArrayOutFields & outputFields,
56  const ArrayInData & inputData,
57  const ArrayInFields & inputFields){
58 
59 #ifdef HAVE_INTREPID_DEBUG
60  std::string errmsg = ">>> ERROR (ArrayTools::crossProductDataField):";
61  /*
62  * Check array rank and spatial dimension range (if applicable)
63  * (1) inputData(C,P,D);
64  * (2) inputFields(C,F,P,D) or (F,P,D);
65  * (3) outputFields(C,F,P,D) in 3D, or (C,F,P) in 2D
66  */
67  // (1) inputData is (C, P, D) and 2 <= D <= 3 is required
68  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputData, 3, 3),
69  std::invalid_argument, errmsg);
70  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputData, 2, 2,3),
71  std::invalid_argument, errmsg);
72  // (2) inputFields is (C, F, P, D) or (F, P, D) and 2 <= (D=dimension(rank - 1)) <= 3 is required.
73  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputFields, 3,4), std::invalid_argument, errmsg);
74  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputFields, inputFields.rank()-1, 2,3),
75  std::invalid_argument, errmsg);
76  // (3) outputFields is (C,F,P,D) in 3D and (C,F,P) in 2D => rank = inputData.dimension(2) + 1
77  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, outputFields, inputData.dimension(2)+1, inputData.dimension(2)+1),
78  std::invalid_argument, errmsg);
79  /*
80  * Dimension cross-checks:
81  * (1) inputData vs. inputFields
82  * (2) outputFields vs. inputData
83  * (3) outputFields vs. inputFields
84  *
85  * Cross-check (1):
86  */
87  if( inputFields.rank() == 4) {
88  // inputData(C,P,D) vs. inputFields(C,F,P,D): dimensions C, P, D must match
89  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, inputData, 0,1,2, inputFields, 0,2,3),
90  std::invalid_argument, errmsg);
91  }
92  else{
93  // inputData(C,P,D) vs. inputFields(F,P,D): dimensions P, D must match
94  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, inputData, 1,2, inputFields, 1,2),
95  std::invalid_argument, errmsg);
96  }
97  /*
98  * Cross-check (2):
99  */
100  if(inputData.dimension(2) == 2) {
101  // in 2D: outputFields(C,F,P) vs. inputData(C,P,D): dimensions C,P must match
102  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputFields, 0,2, inputData, 0,1),
103  std::invalid_argument, errmsg);
104  }
105  else{
106  // in 3D: outputFields(C,F,P,D) vs. inputData(C,P,D): dimensions C,P,D must match
107  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputFields, 0,2,3, inputData, 0,1,2),
108  std::invalid_argument, errmsg);
109  }
110  /*
111  * Cross-check (3):
112  */
113  if(inputData.dimension(2) == 2) {
114  // In 2D:
115  if(inputFields.rank() == 4){
116  // and rank-4 inputFields: outputFields(C,F,P) vs. inputFields(C,F,P,D): dimensions C,F,P must match
117  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputFields, 0,1,2, inputFields, 0,1,2),
118  std::invalid_argument, errmsg);
119  }
120  else{
121  // and rank-3 inputFields: outputFields(C,F,P) vs. inputFields(F,P,D): dimensions F,P must match
122  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputFields, 1,2, inputFields, 0,1),
123  std::invalid_argument, errmsg);
124  }
125  }
126  else{
127  // In 3D:
128  if(inputFields.rank() == 4){
129  // and rank-4 inputFields: outputFields(C,F,P,D) vs. inputFields(C,F,P,D): all dimensions C,F,P,D must match
130  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputFields, inputFields),
131  std::invalid_argument, errmsg);
132  }
133  else{
134  // and rank-3 inputFields: outputFields(C,F,P,D) vs. inputFields(F,P,D): dimensions F,P,D must match
135  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputFields, 1,2,3, inputFields, 0,1,2),
136  std::invalid_argument, errmsg);
137  }
138  }
139 #endif
140  // 3D cross product
141  if(inputData.dimension(2) == 3) {
142 
143  // inputFields is (C,F,P,D)
144  if(inputFields.rank() == 4){
145 
146  for(int cell = 0; cell < outputFields.dimension(0); cell++){
147  for(int field = 0; field < outputFields.dimension(1); field++){
148  for(int point = 0; point < outputFields.dimension(2); point++){
149  //
150  outputFields(cell, field, point, 0) = \
151  inputData(cell, point, 1)*inputFields(cell, field, point, 2) -
152  inputData(cell, point, 2)*inputFields(cell, field, point, 1);
153  //
154  outputFields(cell, field, point, 1) = \
155  inputData(cell, point, 2)*inputFields(cell, field, point, 0) -
156  inputData(cell, point, 0)*inputFields(cell, field, point, 2);
157  //
158  outputFields(cell, field, point, 2) = \
159  inputData(cell, point, 0)*inputFields(cell, field, point, 1) -
160  inputData(cell, point, 1)*inputFields(cell, field, point, 0);
161  }// point
162  }// field
163  } // cell
164  }// rank = 4
165  // inputFields is (F,P,D)
166  else if(inputFields.rank() == 3){
167 
168  for(int cell = 0; cell < outputFields.dimension(0); cell++){
169  for(int field = 0; field < outputFields.dimension(1); field++){
170  for(int point = 0; point < outputFields.dimension(2); point++){
171  //
172  outputFields(cell, field, point, 0) = \
173  inputData(cell, point, 1)*inputFields(field, point, 2) -
174  inputData(cell, point, 2)*inputFields(field, point, 1);
175  //
176  outputFields(cell, field, point, 1) = \
177  inputData(cell, point, 2)*inputFields(field, point, 0) -
178  inputData(cell, point, 0)*inputFields(field, point, 2);
179  //
180  outputFields(cell, field, point, 2) = \
181  inputData(cell, point, 0)*inputFields(field, point, 1) -
182  inputData(cell, point, 1)*inputFields(field, point, 0);
183  }// point
184  }// field
185  } // cell
186  }// rank = 3
187  else{
188  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
189  ">>> ERROR (ArrayTools::crossProductDataField): inputFields rank 3 or 4 required.")
190  }
191  }
192  // 2D cross product
193  else if(inputData.dimension(2) == 2){
194 
195  // inputFields is (C,F,P,D)
196  if(inputFields.rank() == 4){
197 
198  for(int cell = 0; cell < outputFields.dimension(0); cell++){
199  for(int field = 0; field < outputFields.dimension(1); field++){
200  for(int point = 0; point < outputFields.dimension(2); point++){
201  outputFields(cell, field, point) = \
202  inputData(cell, point, 0)*inputFields(cell, field, point, 1) -
203  inputData(cell, point, 1)*inputFields(cell, field, point, 0);
204  }// point
205  }// field
206  } // cell
207  }// rank = 4
208  // inputFields is (F,P,D)
209  else if(inputFields.rank() == 3) {
210 
211  for(int cell = 0; cell < outputFields.dimension(0); cell++){
212  for(int field = 0; field < outputFields.dimension(1); field++){
213  for(int point = 0; point < outputFields.dimension(2); point++){
214  outputFields(cell, field, point) = \
215  inputData(cell, point, 0)*inputFields(field, point, 1) -
216  inputData(cell, point, 1)*inputFields(field, point, 0);
217  }// point
218  }// field
219  } // cell
220  }// rank = 3
221  }
222  // Error: wrong dimension
223  else {
224  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
225  ">>> ERROR (ArrayTools::crossProductDataField): spatial dimension 2 or 3 required.")
226  }
227  }
228 
229 
230 
231  template<class Scalar,
232  class ArrayOutData,
233  class ArrayInDataLeft,
234  class ArrayInDataRight>
235  void ArrayTools::crossProductDataData(ArrayOutData & outputData,
236  const ArrayInDataLeft & inputDataLeft,
237  const ArrayInDataRight & inputDataRight){
238 #ifdef HAVE_INTREPID_DEBUG
239  std::string errmsg = ">>> ERROR (ArrayTools::crossProductDataData):";
240  /*
241  * Check array rank and spatial dimension range (if applicable)
242  * (1) inputDataLeft(C,P,D);
243  * (2) inputDataRight(C,P,D) or (P,D);
244  * (3) outputData(C,P,D) in 3D, or (C,P) in 2D
245  */
246  // (1) inputDataLeft is (C, P, D) and 2 <= D <= 3 is required
247  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputDataLeft, 3,3),
248  std::invalid_argument, errmsg);
249  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputDataLeft, 2, 2,3),
250  std::invalid_argument, errmsg);
251  // (2) inputDataRight is (C, P, D) or (P, D) and 2 <= (D=dimension(rank - 1)) <= 3 is required.
252  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputDataRight, 2,3),
253  std::invalid_argument, errmsg);
254  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputDataRight, inputDataRight.rank()-1, 2,3),
255  std::invalid_argument, errmsg);
256  // (3) outputData is (C,P,D) in 3D and (C,P) in 2D => rank = inputDataLeft.dimension(2)
257  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, outputData, inputDataLeft.dimension(2), inputDataLeft.dimension(2)),
258  std::invalid_argument, errmsg);
259  /*
260  * Dimension cross-checks:
261  * (1) inputDataLeft vs. inputDataRight
262  * (2) outputData vs. inputDataLeft
263  * (3) outputData vs. inputDataRight
264  *
265  * Cross-check (1):
266  */
267  if( inputDataRight.rank() == 3) {
268  // inputDataLeft(C,P,D) vs. inputDataRight(C,P,D): all dimensions C, P, D must match
269  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, inputDataLeft, inputDataRight),
270  std::invalid_argument, errmsg);
271  }
272  // inputDataLeft(C, P,D) vs. inputDataRight(P,D): dimensions P, D must match
273  else{
274  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, inputDataLeft, 1,2, inputDataRight, 0,1),
275  std::invalid_argument, errmsg);
276  }
277  /*
278  * Cross-check (2):
279  */
280  if(inputDataLeft.dimension(2) == 2){
281  // in 2D: outputData(C,P) vs. inputDataLeft(C,P,D): dimensions C, P must match
282  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, inputDataLeft, 0,1, outputData, 0,1),
283  std::invalid_argument, errmsg);
284  }
285  else{
286  // in 3D: outputData(C,P,D) vs. inputDataLeft(C,P,D): all dimensions C, P, D must match
287  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, inputDataLeft, outputData),
288  std::invalid_argument, errmsg);
289  }
290  /*
291  * Cross-check (3):
292  */
293  if(inputDataLeft.dimension(2) == 2) {
294  // In 2D:
295  if(inputDataRight.rank() == 3){
296  // and rank-3 inputDataRight: outputData(C,P) vs. inputDataRight(C,P,D): dimensions C,P must match
297  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputData, 0,1, inputDataRight, 0,1),
298  std::invalid_argument, errmsg);
299  }
300  else{
301  // and rank-2 inputDataRight: outputData(C,P) vs. inputDataRight(P,D): dimension P must match
302  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputData, 1, inputDataRight, 0),
303  std::invalid_argument, errmsg);
304  }
305  }
306  else{
307  // In 3D:
308  if(inputDataRight.rank() == 3){
309  // and rank-3 inputDataRight: outputData(C,P,D) vs. inputDataRight(C,P,D): all dimensions C,P,D must match
310  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputData, inputDataRight),
311  std::invalid_argument, errmsg);
312  }
313  else{
314  // and rank-2 inputDataRight: outputData(C,P,D) vs. inputDataRight(P,D): dimensions P, D must match
315  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputData, 1,2, inputDataRight, 0,1),
316  std::invalid_argument, errmsg);
317  }
318  }
319 #endif
320  // 3D cross product
321  if(inputDataLeft.dimension(2) == 3) {
322 
323  // inputDataRight is (C,P,D)
324  if(inputDataRight.rank() == 3){
325 
326  for(int cell = 0; cell < inputDataLeft.dimension(0); cell++){
327  for(int point = 0; point < inputDataLeft.dimension(1); point++){
328  //
329  outputData(cell, point, 0) = \
330  inputDataLeft(cell, point, 1)*inputDataRight(cell, point, 2) -
331  inputDataLeft(cell, point, 2)*inputDataRight(cell, point, 1);
332  //
333  outputData(cell, point, 1) = \
334  inputDataLeft(cell, point, 2)*inputDataRight(cell, point, 0) -
335  inputDataLeft(cell, point, 0)*inputDataRight(cell, point, 2);
336  //
337  outputData(cell, point, 2) = \
338  inputDataLeft(cell, point, 0)*inputDataRight(cell, point, 1) -
339  inputDataLeft(cell, point, 1)*inputDataRight(cell, point, 0);
340  }// point
341  } // cell
342  }// rank = 3
343  // inputDataRight is (P,D)
344  else if(inputDataRight.rank() == 2){
345 
346  for(int cell = 0; cell < inputDataLeft.dimension(0); cell++){
347  for(int point = 0; point < inputDataLeft.dimension(1); point++){
348  //
349  outputData(cell, point, 0) = \
350  inputDataLeft(cell, point, 1)*inputDataRight(point, 2) -
351  inputDataLeft(cell, point, 2)*inputDataRight(point, 1);
352  //
353  outputData(cell, point, 1) = \
354  inputDataLeft(cell, point, 2)*inputDataRight(point, 0) -
355  inputDataLeft(cell, point, 0)*inputDataRight(point, 2);
356  //
357  outputData(cell, point, 2) = \
358  inputDataLeft(cell, point, 0)*inputDataRight(point, 1) -
359  inputDataLeft(cell, point, 1)*inputDataRight(point, 0);
360  }// point
361  } // cell
362  }// rank = 2
363  else{
364  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
365  ">>> ERROR (ArrayTools::crossProductDataData): inputDataRight rank 2 or 3 required.")
366  }
367  }
368  // 2D cross product
369  else if(inputDataLeft.dimension(2) == 2){
370 
371  // inputDataRight is (C,P,D)
372  if(inputDataRight.rank() == 3){
373 
374  for(int cell = 0; cell < inputDataLeft.dimension(0); cell++){
375  for(int point = 0; point < inputDataLeft.dimension(1); point++){
376  outputData(cell, point) = \
377  inputDataLeft(cell, point, 0)*inputDataRight(cell, point, 1) -
378  inputDataLeft(cell, point, 1)*inputDataRight(cell, point, 0);
379  }// point
380  } // cell
381  }// rank = 3
382  // inputDataRight is (P,D)
383  else if(inputDataRight.rank() == 2) {
384 
385  for(int cell = 0; cell < inputDataLeft.dimension(0); cell++){
386  for(int point = 0; point < inputDataLeft.dimension(1); point++){
387  outputData(cell, point) = \
388  inputDataLeft(cell, point, 0)*inputDataRight(point, 1) -
389  inputDataLeft(cell, point, 1)*inputDataRight(point, 0);
390  }// point
391  } // cell
392  }// rank = 2
393  }
394  // Error: wrong dimension
395  else {
396  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
397  ">>> ERROR (ArrayTools::crossProductDataData): spatial dimension 2 or 3 required.")
398  }
399  }
400 
401 
402 
403  template<class Scalar,
404  class ArrayOutFields,
405  class ArrayInData,
406  class ArrayInFields>
407  void ArrayTools::outerProductDataField(ArrayOutFields & outputFields,
408  const ArrayInData & inputData,
409  const ArrayInFields & inputFields){
410 #ifdef HAVE_INTREPID_DEBUG
411  std::string errmsg = ">>> ERROR (ArrayTools::outerProductDataField):";
412  /*
413  * Check array rank and spatial dimension range (if applicable)
414  * (1) inputData(C,P,D);
415  * (2) inputFields(C,F,P,D) or (F,P,D);
416  * (3) outputFields(C,F,P,D,D)
417  */
418  // (1) inputData is (C, P, D) and 2 <= D <= 3 is required
419  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputData, 3,3),
420  std::invalid_argument, errmsg);
421  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputData, 2, 2,3),
422  std::invalid_argument, errmsg);
423  // (2) inputFields is (C, F, P, D) or (F, P, D) and 2 <= (D=dimension(rank - 1)) <= 3 is required.
424  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputFields, 3,4), std::invalid_argument, errmsg);
425  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputFields, inputFields.rank()-1, 2,3),
426  std::invalid_argument, errmsg);
427  // (3) outputFields is (C,F,P,D,D)
428  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, outputFields, 5,5), std::invalid_argument, errmsg);
429  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, outputFields, 3, 2,3),
430  std::invalid_argument, errmsg);
431  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, outputFields, 4, 2,3),
432  std::invalid_argument, errmsg);
433  /*
434  * Dimension cross-checks:
435  * (1) inputData vs. inputFields
436  * (2) outputFields vs. inputData
437  * (3) outputFields vs. inputFields
438  *
439  * Cross-check (2): outputFields(C,F,P,D,D) vs. inputData(C,P,D): dimensions C, P, D must match
440  */
441  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
442  outputFields, 0,2,3,4,
443  inputData, 0,1,2,2),
444  std::invalid_argument, errmsg);
445  /*
446  * Cross-checks (1,3):
447  */
448  if( inputFields.rank() == 4) {
449  // Cross-check (1): inputData(C,P,D) vs. inputFields(C,F,P,D): dimensions C, P, D must match
450  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
451  inputData, 0,1,2,
452  inputFields, 0,2,3),
453  std::invalid_argument, errmsg);
454  // Cross-check (3): outputFields(C,F,P,D,D) vs. inputFields(C,F,P,D): dimensions C, F, P, D must match
455  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
456  outputFields, 0,1,2,3,4,
457  inputFields, 0,1,2,3,3),
458  std::invalid_argument, errmsg);
459  }
460  else{
461  // Cross-check (1): inputData(C,P,D) vs. inputFields(F,P,D): dimensions P, D must match
462  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
463  inputData, 1,2,
464  inputFields, 1,2),
465  std::invalid_argument, errmsg);
466  // Cross-check (3): outputFields(C,F,P,D,D) vs. inputFields(F,P,D): dimensions F, P, D must match
467  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
468  outputFields, 1,2,3,4,
469  inputFields, 0,1,2,2),
470  std::invalid_argument, errmsg);
471  }
472 #endif
473 
474  // inputFields is (C,F,P,D)
475  if(inputFields.rank() == 4){
476 
477  for(int cell = 0; cell < outputFields.dimension(0); cell++){
478  for(int field = 0; field < outputFields.dimension(1); field++){
479  for(int point = 0; point < outputFields.dimension(2); point++){
480  for(int row = 0; row < outputFields.dimension(3); row++){
481  for(int col = 0; col < outputFields.dimension(4); col++){
482  outputFields(cell, field, point, row, col) = \
483  inputData(cell, point, row)*inputFields(cell, field, point, col);
484  }// col
485  }// row
486  }// point
487  }// field
488  } // cell
489  }// rank = 4
490  // inputFields is (F,P,D)
491  else if(inputFields.rank() == 3){
492 
493  for(int cell = 0; cell < outputFields.dimension(0); cell++){
494  for(int field = 0; field < outputFields.dimension(1); field++){
495  for(int point = 0; point < outputFields.dimension(2); point++){
496  for(int row = 0; row < outputFields.dimension(3); row++){
497  for(int col = 0; col < outputFields.dimension(4); col++){
498  outputFields(cell, field, point, row, col) = \
499  inputData(cell, point, row)*inputFields(field, point, col);
500  }// col
501  }// row
502  }// point
503  }// field
504  } // cell
505  }// rank = 3
506  else{
507  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
508  ">>> ERROR (ArrayTools::outerProductDataField): inputFields rank 3 or 4 required.")
509  }
510  }
511 
512 
513 
514  template<class Scalar,
515  class ArrayOutData,
516  class ArrayInDataLeft,
517  class ArrayInDataRight>
518  void ArrayTools::outerProductDataData(ArrayOutData & outputData,
519  const ArrayInDataLeft & inputDataLeft,
520  const ArrayInDataRight & inputDataRight){
521 #ifdef HAVE_INTREPID_DEBUG
522  std::string errmsg = ">>> ERROR (ArrayTools::outerProductDataData):";
523  /*
524  * Check array rank and spatial dimension range (if applicable)
525  * (1) inputDataLeft(C,P,D);
526  * (2) inputDataRight(C,P,D) or (P,D);
527  * (3) outputData(C,P,D,D)
528  */
529  // (1) inputDataLeft is (C, P, D) and 2 <= D <= 3 is required
530  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputDataLeft, 3,3),
531  std::invalid_argument, errmsg);
532  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputDataLeft, 2, 2,3),
533  std::invalid_argument, errmsg);
534  // (2) inputDataRight is (C, P, D) or (P, D) and 2 <= (D=dimension(rank - 1)) <= 3 is required.
535  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputDataRight, 2,3),
536  std::invalid_argument, errmsg);
537  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputDataRight, inputDataRight.rank()-1, 2,3),
538  std::invalid_argument, errmsg);
539  // (3) outputData is (C,P,D,D)
540  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, outputData, 4, 4), std::invalid_argument, errmsg);
541  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, outputData, 2, 2,3),
542  std::invalid_argument, errmsg);
543  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, outputData, 3, 2,3),
544  std::invalid_argument, errmsg);
545  /*
546  * Dimension cross-checks:
547  * (1) inputDataLeft vs. inputDataRight
548  * (2) outputData vs. inputDataLeft
549  * (3) outputData vs. inputDataRight
550  *
551  * Cross-check (2): outputData(C,P,D,D) vs. inputDataLeft(C,P,D): dimensions C, P, D must match
552  */
553  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
554  outputData, 0,1,2,3,
555  inputDataLeft, 0,1,2,2),
556  std::invalid_argument, errmsg);
557  /*
558  * Cross-checks (1,3):
559  */
560  if( inputDataRight.rank() == 3) {
561  // Cross-check (1): inputDataLeft(C,P,D) vs. inputDataRight(C,P,D): all dimensions C, P, D must match
562  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, inputDataLeft, inputDataRight),
563  std::invalid_argument, errmsg);
564  // Cross-check (3): outputData(C,P,D,D) vs. inputDataRight(C,P,D): dimensions C, P, D must match
565  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
566  outputData, 0,1,2,3,
567  inputDataRight, 0,1,2,2),
568  std::invalid_argument, errmsg);
569  }
570  else{
571  // Cross-check (1): inputDataLeft(C,P,D) vs. inputDataRight(P,D): dimensions P, D must match
572  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
573  inputDataLeft, 1,2,
574  inputDataRight, 0,1),
575  std::invalid_argument, errmsg);
576  // Cross-check (3): outputData(C,P,D,D) vs. inputDataRight(P,D): dimensions P, D must match
577  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
578  outputData, 1,2,3,
579  inputDataRight, 0,1,1),
580  std::invalid_argument, errmsg);
581  }
582 #endif
583  // inputDataRight is (C,P,D)
584  if(inputDataRight.rank() == 3){
585 
586  for(int cell = 0; cell < inputDataLeft.dimension(0); cell++){
587  for(int point = 0; point < inputDataLeft.dimension(1); point++){
588  for(int row = 0; row < inputDataLeft.dimension(2); row++){
589  for(int col = 0; col < inputDataLeft.dimension(2); col++){
590 
591  outputData(cell, point, row, col) = \
592  inputDataLeft(cell, point, row)*inputDataRight(cell, point, col);
593  }// col
594  }// row
595  }// point
596  } // cell
597  }// rank = 3
598  // inputDataRight is (P,D)
599  else if(inputDataRight.rank() == 2){
600 
601  for(int cell = 0; cell < inputDataLeft.dimension(0); cell++){
602  for(int point = 0; point < inputDataLeft.dimension(1); point++){
603  for(int row = 0; row < inputDataLeft.dimension(2); row++){
604  for(int col = 0; col < inputDataLeft.dimension(2); col++){
605  //
606  outputData(cell, point, row, col) = \
607  inputDataLeft(cell, point, row)*inputDataRight(point, col);
608  } // col
609  } // row
610  } // point
611  } // cell
612  }// rank = 2
613  else{
614  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
615  ">>> ERROR (ArrayTools::crossProductDataData): inputDataRight rank 2 or 3 required.")
616  }
617  }
618 
619 
620 
621  template<class Scalar,
622  class ArrayOutFields,
623  class ArrayInData,
624  class ArrayInFields>
625  void ArrayTools::matvecProductDataField(ArrayOutFields & outputFields,
626  const ArrayInData & inputData,
627  const ArrayInFields & inputFields,
628  const char transpose){
629 #ifdef HAVE_INTREPID_DEBUG
630  std::string errmsg = ">>> ERROR (ArrayTools::matvecProductDataField):";
631  /*
632  * Check array rank and spatial dimension range (if applicable)
633  * (1) inputData(C,P), (C,P,D) or (C,P,D,D); P=1 is admissible to allow multiply by const. data
634  * (2) inputFields(C,F,P,D) or (F,P,D);
635  * (3) outputFields(C,F,P,D)
636  */
637  // (1) inputData is (C,P), (C, P, D) or (C, P, D, D) and 1 <= D <= 3 is required
638  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputData, 2,4),
639  std::invalid_argument, errmsg);
640  if(inputData.rank() > 2) {
641  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputData, 2, 1,3),
642  std::invalid_argument, errmsg);
643  }
644  if(inputData.rank() == 4) {
645  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputData, 3, 1,3),
646  std::invalid_argument, errmsg);
647  }
648  // (2) inputFields is (C, F, P, D) or (F, P, D) and 1 <= (D=dimension(rank - 1)) <= 3 is required.
649  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputFields, 3,4), std::invalid_argument, errmsg);
650  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputFields, inputFields.rank()-1, 1,3),
651  std::invalid_argument, errmsg);
652  // (3) outputFields is (C,F,P,D)
653  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, outputFields, 4,4), std::invalid_argument, errmsg);
654  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, outputFields, 3, 1,3),
655  std::invalid_argument, errmsg);
656  /*
657  * Dimension cross-checks:
658  * (1) inputData vs. inputFields
659  * (2) outputFields vs. inputData
660  * (3) outputFields vs. inputFields
661  *
662  * Cross-check (2): outputFields(C,F,P,D) vs. inputData(C,P), (C,P,D) or (C,P,D,D):
663  * dimensions C, and D must match in all cases, dimension P must match only when non-constant
664  * data is specified (P>1). Do not check P dimensions with constant data, i.e., when P=1 in
665  * inputData(C,1,...)
666  */
667  if(inputData.dimension(1) > 1){ // check P dimension if P>1 in inputData
668  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
669  outputFields, 2,
670  inputData, 1),
671  std::invalid_argument, errmsg);
672  }
673  if(inputData.rank() == 2) { // inputData(C,P) -> C match
674  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
675  outputFields, 0,
676  inputData, 0),
677  std::invalid_argument, errmsg);
678  }
679  if(inputData.rank() == 3){ // inputData(C,P,D) -> C, D match
680  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
681  outputFields, 0,3,
682  inputData, 0,2),
683  std::invalid_argument, errmsg);
684 
685  }
686  if(inputData.rank() == 4){ // inputData(C,P,D,D) -> C, D, D match
687  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
688  outputFields, 0,3,3,
689  inputData, 0,2,3),
690  std::invalid_argument, errmsg);
691  }
692  /*
693  * Cross-checks (1,3):
694  */
695  if(inputFields.rank() == 4) {
696  // Cross-check (1): inputData(C,P), (C,P,D) or (C,P,D,D) vs. inputFields(C,F,P,D): dimensions C, P, D must match
697  if(inputData.dimension(1) > 1){ // check P dimension if P>1 in inputData
698  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
699  inputFields, 2,
700  inputData, 1),
701  std::invalid_argument, errmsg);
702  }
703  if(inputData.rank() == 2){ // inputData(C,P) -> C match
704  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
705  inputData, 0,
706  inputFields, 0),
707  std::invalid_argument, errmsg);
708  }
709  if(inputData.rank() == 3){ // inputData(C,P,D) -> C, D match
710  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
711  inputData, 0,2,
712  inputFields, 0,3),
713  std::invalid_argument, errmsg);
714  }
715  if(inputData.rank() == 4){ // inputData(C,P,D,D) -> C, D, D match
716  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
717  inputData, 0,2,3,
718  inputFields, 0,3,3),
719  std::invalid_argument, errmsg);
720  }
721  // Cross-check (3): outputFields(C,F,P,D) vs. inputFields(C,F,P,D): all dimensions C, F, P, D must match
722  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputFields, inputFields),
723  std::invalid_argument, errmsg);
724  }
725  else{
726  // Cross-check (1): inputData(C,P), (C,P,D) or (C,P,D,D) vs. inputFields(F,P,D): dimensions P, D must match
727  if(inputData.dimension(1) > 1){ // check P if P>1 in inputData
728  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
729  inputData, 1,
730  inputFields, 1),
731  std::invalid_argument, errmsg);
732  }
733  if(inputData.rank() == 3){
734  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
735  inputData, 2,
736  inputFields, 2),
737  std::invalid_argument, errmsg);
738  }
739  if(inputData.rank() == 4){
740  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
741  inputData, 2,3,
742  inputFields, 2,2),
743  std::invalid_argument, errmsg);
744  }
745  // Cross-check (3): outputFields(C,F,P,D) vs. inputFields(F,P,D): dimensions F, P, D must match
746  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
747  outputFields, 1,2,3,
748  inputFields, 0,1,2),
749  std::invalid_argument, errmsg);
750  }
751 #endif
752  int dataRank = inputData.rank();
753  int numDataPts = inputData.dimension(1);
754  int inRank = inputFields.rank();
755  int numCells = outputFields.dimension(0);
756  int numFields = outputFields.dimension(1);
757  int numPoints = outputFields.dimension(2);
758  int matDim = outputFields.dimension(3);
759  /*********************************************************************************************
760  * inputFields is (C,F,P,D) *
761  *********************************************************************************************/
762  if(inRank == 4){
763  if(numDataPts != 1){ // non-constant data
764 
765  switch(dataRank){
766  case 2:
767  for(int cell = 0; cell < numCells; cell++) {
768  for(int field = 0; field < numFields; field++) {
769  for(int point = 0; point < numPoints; point++) {
770  for( int row = 0; row < matDim; row++) {
771  outputFields(cell, field, point, row) = \
772  inputData(cell, point)*inputFields(cell, field, point, row);
773  } // Row-loop
774  } // P-loop
775  } // F-loop
776  }// C-loop
777  break;
778 
779  case 3:
780  for(int cell = 0; cell < numCells; cell++) {
781  for(int field = 0; field < numFields; field++) {
782  for(int point = 0; point < numPoints; point++) {
783  for( int row = 0; row < matDim; row++) {
784  outputFields(cell, field, point, row) = \
785  inputData(cell, point, row)*inputFields(cell, field, point, row);
786  } // Row-loop
787  } // P-loop
788  } // F-loop
789  }// C-loop
790  break;
791 
792  case 4:
793  if ((transpose == 'n') || (transpose == 'N')) {
794  for(int cell = 0; cell < numCells; cell++){
795  for(int field = 0; field < numFields; field++){
796  for(int point = 0; point < numPoints; point++){
797  for(int row = 0; row < matDim; row++){
798  outputFields(cell, field, point, row) = 0.0;
799  for(int col = 0; col < matDim; col++){
800  outputFields(cell, field, point, row) += \
801  inputData(cell, point, row, col)*inputFields(cell, field, point, col);
802  }// col
803  } //row
804  }// point
805  }// field
806  }// cell
807  } // no transpose
808  else if ((transpose == 't') || (transpose == 'T')) {
809  for(int cell = 0; cell < numCells; cell++){
810  for(int field = 0; field < numFields; field++){
811  for(int point = 0; point < numPoints; point++){
812  for(int row = 0; row < matDim; row++){
813  outputFields(cell, field, point, row) = 0.0;
814  for(int col = 0; col < matDim; col++){
815  outputFields(cell, field, point, row) += \
816  inputData(cell, point, col, row)*inputFields(cell, field, point, col);
817  }// col
818  } //row
819  }// point
820  }// field
821  }// cell
822  } //transpose
823  else {
824  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
825  ">>> ERROR (ArrayTools::matvecProductDataField): The transpose flag must be 'n', 'N', 't' or 'T'.");
826  }
827  break;
828 
829  default:
830  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataRank == 2) || (dataRank == 3) || (dataRank == 4) ), std::invalid_argument,
831  ">>> ERROR (ArrayTools::matvecProductDataField): inputData rank 2, 3 or 4 required.")
832  } // switch inputData rank
833  }
834  else{ // constant data case
835  switch(dataRank){
836  case 2:
837  for(int cell = 0; cell < numCells; cell++) {
838  for(int field = 0; field < numFields; field++) {
839  for(int point = 0; point < numPoints; point++) {
840  for( int row = 0; row < matDim; row++) {
841  outputFields(cell, field, point, row) = \
842  inputData(cell, 0)*inputFields(cell, field, point, row);
843  } // Row-loop
844  } // P-loop
845  } // F-loop
846  }// C-loop
847  break;
848 
849  case 3:
850  for(int cell = 0; cell < numCells; cell++) {
851  for(int field = 0; field < numFields; field++) {
852  for(int point = 0; point < numPoints; point++) {
853  for( int row = 0; row < matDim; row++) {
854  outputFields(cell, field, point, row) = \
855  inputData(cell, 0, row)*inputFields(cell, field, point, row);
856  } // Row-loop
857  } // P-loop
858  } // F-loop
859  }// C-loop
860  break;
861 
862  case 4:
863  if ((transpose == 'n') || (transpose == 'N')) {
864  for(int cell = 0; cell < numCells; cell++){
865  for(int field = 0; field < numFields; field++){
866  for(int point = 0; point < numPoints; point++){
867  for(int row = 0; row < matDim; row++){
868  outputFields(cell, field, point, row) = 0.0;
869  for(int col = 0; col < matDim; col++){
870  outputFields(cell, field, point, row) += \
871  inputData(cell, 0, row, col)*inputFields(cell, field, point, col);
872  }// col
873  } //row
874  }// point
875  }// field
876  }// cell
877  } // no transpose
878  else if ((transpose == 't') || (transpose == 'T')) {
879  for(int cell = 0; cell < numCells; cell++){
880  for(int field = 0; field < numFields; field++){
881  for(int point = 0; point < numPoints; point++){
882  for(int row = 0; row < matDim; row++){
883  outputFields(cell, field, point, row) = 0.0;
884  for(int col = 0; col < matDim; col++){
885  outputFields(cell, field, point, row) += \
886  inputData(cell, 0, col, row)*inputFields(cell, field, point, col);
887  }// col
888  } //row
889  }// point
890  }// field
891  }// cell
892  } //transpose
893  else {
894  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
895  ">>> ERROR (ArrayTools::matvecProductDataField): The transpose flag must be 'n', 'N', 't' or 'T'.");
896  }
897  break;
898 
899  default:
900  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataRank == 2) || (dataRank == 3) || (dataRank == 4) ), std::invalid_argument,
901  ">>> ERROR (ArrayTools::matvecProductDataField): inputData rank 2, 3 or 4 required.")
902  } // switch inputData rank
903  } // end constant data case
904  } // inputFields rank 4
905  /*********************************************************************************************
906  * inputFields is (F,P,D) *
907  *********************************************************************************************/
908  else if(inRank == 3) {
909  if(numDataPts != 1){ // non-constant data
910 
911  switch(dataRank){
912  case 2:
913  for(int cell = 0; cell < numCells; cell++) {
914  for(int field = 0; field < numFields; field++) {
915  for(int point = 0; point < numPoints; point++) {
916  for( int row = 0; row < matDim; row++) {
917  outputFields(cell, field, point, row) = \
918  inputData(cell, point)*inputFields(field, point, row);
919  } // Row-loop
920  } // P-loop
921  } // F-loop
922  }// C-loop
923  break;
924 
925  case 3:
926  for(int cell = 0; cell < numCells; cell++) {
927  for(int field = 0; field < numFields; field++) {
928  for(int point = 0; point < numPoints; point++) {
929  for( int row = 0; row < matDim; row++) {
930  outputFields(cell, field, point, row) = \
931  inputData(cell, point, row)*inputFields(field, point, row);
932  } // Row-loop
933  } // P-loop
934  } // F-loop
935  }// C-loop
936  break;
937 
938  case 4:
939  if ((transpose == 'n') || (transpose == 'N')) {
940  for(int cell = 0; cell < numCells; cell++){
941  for(int field = 0; field < numFields; field++){
942  for(int point = 0; point < numPoints; point++){
943  for(int row = 0; row < matDim; row++){
944  outputFields(cell, field, point, row) = 0.0;
945  for(int col = 0; col < matDim; col++){
946  outputFields(cell, field, point, row) += \
947  inputData(cell, point, row, col)*inputFields(field, point, col);
948  }// col
949  } //row
950  }// point
951  }// field
952  }// cell
953  } // no transpose
954  else if ((transpose == 't') || (transpose == 'T')) {
955  for(int cell = 0; cell < numCells; cell++){
956  for(int field = 0; field < numFields; field++){
957  for(int point = 0; point < numPoints; point++){
958  for(int row = 0; row < matDim; row++){
959  outputFields(cell, field, point, row) = 0.0;
960  for(int col = 0; col < matDim; col++){
961  outputFields(cell, field, point, row) += \
962  inputData(cell, point, col, row)*inputFields(field, point, col);
963  }// col
964  } //row
965  }// point
966  }// field
967  }// cell
968  } //transpose
969  else {
970  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
971  ">>> ERROR (ArrayTools::matvecProductDataField): The transpose flag must be 'n', 'N', 't' or 'T'.");
972  }
973  break;
974 
975  default:
976  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataRank == 2) || (dataRank == 3) || (dataRank == 4) ), std::invalid_argument,
977  ">>> ERROR (ArrayTools::matvecProductDataField): inputData rank 2, 3 or 4 required.")
978  } // switch inputData rank
979  }
980  else{ // constant data case
981  switch(dataRank){
982  case 2:
983  for(int cell = 0; cell < numCells; cell++) {
984  for(int field = 0; field < numFields; field++) {
985  for(int point = 0; point < numPoints; point++) {
986  for( int row = 0; row < matDim; row++) {
987  outputFields(cell, field, point, row) = \
988  inputData(cell, 0)*inputFields(field, point, row);
989  } // Row-loop
990  } // P-loop
991  } // F-loop
992  }// C-loop
993  break;
994 
995  case 3:
996  for(int cell = 0; cell < numCells; cell++) {
997  for(int field = 0; field < numFields; field++) {
998  for(int point = 0; point < numPoints; point++) {
999  for( int row = 0; row < matDim; row++) {
1000  outputFields(cell, field, point, row) = \
1001  inputData(cell, 0, row)*inputFields(field, point, row);
1002  } // Row-loop
1003  } // P-loop
1004  } // F-loop
1005  }// C-loop
1006  break;
1007 
1008  case 4:
1009  if ((transpose == 'n') || (transpose == 'N')) {
1010  for(int cell = 0; cell < numCells; cell++){
1011  for(int field = 0; field < numFields; field++){
1012  for(int point = 0; point < numPoints; point++){
1013  for(int row = 0; row < matDim; row++){
1014  outputFields(cell, field, point, row) = 0.0;
1015  for(int col = 0; col < matDim; col++){
1016  outputFields(cell, field, point, row) += \
1017  inputData(cell, 0, row, col)*inputFields(field, point, col);
1018  }// col
1019  } //row
1020  }// point
1021  }// field
1022  }// cell
1023  } // no transpose
1024  else if ((transpose == 't') || (transpose == 'T')) {
1025  for(int cell = 0; cell < numCells; cell++){
1026  for(int field = 0; field < numFields; field++){
1027  for(int point = 0; point < numPoints; point++){
1028  for(int row = 0; row < matDim; row++){
1029  outputFields(cell, field, point, row) = 0.0;
1030  for(int col = 0; col < matDim; col++){
1031  outputFields(cell, field, point, row) += \
1032  inputData(cell, 0, col, row)*inputFields(field, point, col);
1033  }// col
1034  } //row
1035  }// point
1036  }// field
1037  }// cell
1038  } //transpose
1039  else {
1040  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
1041  ">>> ERROR (ArrayTools::matvecProductDataField): The transpose flag must be 'n', 'N', 't' or 'T'.");
1042  }
1043  break;
1044 
1045  default:
1046  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataRank == 2) || (dataRank == 3) || (dataRank == 4) ), std::invalid_argument,
1047  ">>> ERROR (ArrayTools::matvecProductDataField): inputData rank 2, 3 or 4 required.")
1048  } // switch inputData rank
1049  } // end constant data case
1050  } // inputFields rank 3
1051  else {
1052  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
1053  ">>> ERROR (ArrayTools::matvecProductDataField): inputFields rank 3 or 4 required.")
1054  }// rank error
1055  }
1056 
1057 
1058 
1059  template<class Scalar,
1060  class ArrayOutData,
1061  class ArrayInDataLeft,
1062  class ArrayInDataRight>
1063  void ArrayTools::matvecProductDataData(ArrayOutData & outputData,
1064  const ArrayInDataLeft & inputDataLeft,
1065  const ArrayInDataRight & inputDataRight,
1066  const char transpose){
1067 #ifdef HAVE_INTREPID_DEBUG
1068  std::string errmsg = ">>> ERROR (ArrayTools::matvecProductDataData):";
1069  /*
1070  * Check array rank and spatial dimension range (if applicable)
1071  * (1) inputDataLeft(C,P), (C,P,D) or (C,P,D,D); P=1 is admissible to allow multiply by const. left data
1072  * (2) inputDataRight(C,P,D) or (P,D);
1073  * (3) outputData(C,P,D)
1074  */
1075  // (1) inputDataLeft is (C,P), (C,P,D) or (C,P,D,D) and 1 <= D <= 3 is required
1076  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputDataLeft, 2,4),
1077  std::invalid_argument, errmsg);
1078  if(inputDataLeft.rank() > 2) {
1079  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputDataLeft, 2, 1,3),
1080  std::invalid_argument, errmsg);
1081  }
1082  if(inputDataLeft.rank() == 4) {
1083  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputDataLeft, 3, 1,3),
1084  std::invalid_argument, errmsg);
1085  }
1086  // (2) inputDataRight is (C, P, D) or (P, D) and 1 <= (D=dimension(rank - 1)) <= 3 is required.
1087  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputDataRight, 2,3),
1088  std::invalid_argument, errmsg);
1089  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputDataRight, inputDataRight.rank()-1, 1,3),
1090  std::invalid_argument, errmsg);
1091  // (3) outputData is (C,P,D)
1092  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, outputData, 3,3), std::invalid_argument, errmsg);
1093  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, outputData, 2, 1,3),
1094  std::invalid_argument, errmsg);
1095  /*
1096  * Dimension cross-checks:
1097  * (1) inputDataLeft vs. inputDataRight
1098  * (2) outputData vs. inputDataLeft
1099  * (3) outputData vs. inputDataRight
1100  *
1101  * Cross-check (2): outputData(C,P,D) vs. inputDataLeft(C,P), (C,P,D) or (C,P,D,D):
1102  * dimensions C, and D must match in all cases, dimension P must match only when non-constant
1103  * data is specified (P>1). Do not check P dimensions with constant left data, i.e., when P=1 in
1104  * inputDataLeft(C,1,...)
1105  */
1106  if(inputDataLeft.dimension(1) > 1){ // check P dimension if P>1 in inputDataLeft
1107  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1108  outputData, 1,
1109  inputDataLeft, 1),
1110  std::invalid_argument, errmsg);
1111  }
1112  if(inputDataLeft.rank() == 2){ // inputDataLeft(C,P): check C
1113  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1114  outputData, 0,
1115  inputDataLeft, 0),
1116  std::invalid_argument, errmsg);
1117  }
1118  if(inputDataLeft.rank() == 3){ // inputDataLeft(C,P,D): check C and D
1119  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1120  outputData, 0,2,
1121  inputDataLeft, 0,2),
1122  std::invalid_argument, errmsg);
1123  }
1124  if(inputDataLeft.rank() == 4){ // inputDataLeft(C,P,D,D): check C and D
1125  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1126  outputData, 0,2,2,
1127  inputDataLeft, 0,2,3),
1128  std::invalid_argument, errmsg);
1129  }
1130  /*
1131  * Cross-checks (1,3):
1132  */
1133  if( inputDataRight.rank() == 3) {
1134  // Cross-check (1): inputDataLeft(C,P), (C,P,D), or (C,P,D,D) vs. inputDataRight(C,P,D): dimensions C, P, D must match
1135  if(inputDataLeft.dimension(1) > 1){ // check P dimension if P>1 in inputDataLeft
1136  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1137  inputDataLeft, 1,
1138  inputDataRight, 1),
1139  std::invalid_argument, errmsg);
1140  }
1141  if(inputDataLeft.rank() == 2){ // inputDataLeft(C,P): check C
1142  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1143  inputDataLeft, 0,
1144  inputDataRight, 0),
1145  std::invalid_argument, errmsg);
1146  }
1147  if(inputDataLeft.rank() == 3){ // inputDataLeft(C,P,D): check C and D
1148  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1149  inputDataLeft, 0,2,
1150  inputDataRight, 0,2),
1151  std::invalid_argument, errmsg);
1152  }
1153  if(inputDataLeft.rank() == 4){ // inputDataLeft(C,P,D,D): check C and D
1154  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1155  inputDataLeft, 0,2,3,
1156  inputDataRight, 0,2,2),
1157  std::invalid_argument, errmsg);
1158  }
1159 
1160  // Cross-check (3): outputData(C,P,D) vs. inputDataRight(C,P,D): all dimensions C, P, D must match
1161  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputData, inputDataRight),
1162  std::invalid_argument, errmsg);
1163  }
1164  else{
1165  // Cross-check (1): inputDataLeft(C,P), (C,P,D), or (C,P,D,D) vs. inputDataRight(P,D): dimensions P, D must match
1166  if(inputDataLeft.dimension(1) > 1){ // check P if P>1 in inputData
1167  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1168  inputDataLeft, 1,
1169  inputDataRight, 0),
1170  std::invalid_argument, errmsg);
1171  }
1172  if(inputDataLeft.rank() == 3){ // inputDataLeft(C,P,D): check D
1173  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1174  inputDataLeft, 2,
1175  inputDataRight, 1),
1176  std::invalid_argument, errmsg);
1177  }
1178  if(inputDataLeft.rank() == 4){ // inputDataLeft(C,P,D,D): check D
1179  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1180  inputDataLeft, 2,3,
1181  inputDataRight, 1,1),
1182  std::invalid_argument, errmsg);
1183  }
1184  // Cross-check (3): outputData(C,P,D) vs. inputDataRight(P,D): dimensions P, D must match
1185  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1186  outputData, 1,2,
1187  inputDataRight, 0,1),
1188  std::invalid_argument, errmsg);
1189  }
1190 #endif
1191  int dataLeftRank = inputDataLeft.rank();
1192  int numDataLeftPts = inputDataLeft.dimension(1);
1193  int dataRightRank = inputDataRight.rank();
1194  int numCells = outputData.dimension(0);
1195  int numPoints = outputData.dimension(1);
1196  int matDim = outputData.dimension(2);
1197 
1198  /*********************************************************************************************
1199  * inputDataRight is (C,P,D) *
1200  *********************************************************************************************/
1201  if(dataRightRank == 3){
1202  if(numDataLeftPts != 1){ // non-constant left data
1203 
1204  switch(dataLeftRank){
1205  case 2:
1206  for(int cell = 0; cell < numCells; cell++) {
1207  for(int point = 0; point < numPoints; point++) {
1208  for( int row = 0; row < matDim; row++) {
1209  outputData(cell, point, row) = \
1210  inputDataLeft(cell, point)*inputDataRight(cell, point, row);
1211  } // Row-loop
1212  } // P-loop
1213  }// C-loop
1214  break;
1215 
1216  case 3:
1217  for(int cell = 0; cell < numCells; cell++) {
1218  for(int point = 0; point < numPoints; point++) {
1219  for( int row = 0; row < matDim; row++) {
1220  outputData(cell, point, row) = \
1221  inputDataLeft(cell, point, row)*inputDataRight(cell, point, row);
1222  } // Row-loop
1223  } // P-loop
1224  }// C-loop
1225  break;
1226 
1227  case 4:
1228  if ((transpose == 'n') || (transpose == 'N')) {
1229  for(int cell = 0; cell < numCells; cell++){
1230  for(int point = 0; point < numPoints; point++){
1231  for(int row = 0; row < matDim; row++){
1232  outputData(cell, point, row) = 0.0;
1233  for(int col = 0; col < matDim; col++){
1234  outputData(cell, point, row) += \
1235  inputDataLeft(cell, point, row, col)*inputDataRight(cell, point, col);
1236  }// col
1237  } //row
1238  }// point
1239  }// cell
1240  } // no transpose
1241  else if ((transpose == 't') || (transpose == 'T')) {
1242  for(int cell = 0; cell < numCells; cell++){
1243  for(int point = 0; point < numPoints; point++){
1244  for(int row = 0; row < matDim; row++){
1245  outputData(cell, point, row) = 0.0;
1246  for(int col = 0; col < matDim; col++){
1247  outputData(cell, point, row) += \
1248  inputDataLeft(cell, point, col, row)*inputDataRight(cell, point, col);
1249  }// col
1250  } //row
1251  }// point
1252  }// cell
1253  } //transpose
1254  else {
1255  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
1256  ">>> ERROR (ArrayTools::matvecProductDataData): The transpose flag must be 'n', 'N', 't' or 'T'.");
1257  }
1258  break;
1259 
1260  default:
1261  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataLeftRank == 2) || (dataLeftRank == 3) || (dataLeftRank == 4) ), std::invalid_argument,
1262  ">>> ERROR (ArrayTools::matvecProductDataData): inputDataLeft rank 2, 3 or 4 required.")
1263  } // switch inputDataLeft rank
1264  }
1265  else{ // constant data case
1266  switch(dataLeftRank){
1267  case 2:
1268  for(int cell = 0; cell < numCells; cell++) {
1269  for(int point = 0; point < numPoints; point++) {
1270  for( int row = 0; row < matDim; row++) {
1271  outputData(cell, point, row) = \
1272  inputDataLeft(cell, 0)*inputDataRight(cell, point, row);
1273  } // Row-loop
1274  } // F-loop
1275  }// C-loop
1276  break;
1277 
1278  case 3:
1279  for(int cell = 0; cell < numCells; cell++) {
1280  for(int point = 0; point < numPoints; point++) {
1281  for( int row = 0; row < matDim; row++) {
1282  outputData(cell, point, row) = \
1283  inputDataLeft(cell, 0, row)*inputDataRight(cell, point, row);
1284  } // Row-loop
1285  } // P-loop
1286  }// C-loop
1287  break;
1288 
1289  case 4:
1290  if ((transpose == 'n') || (transpose == 'N')) {
1291  for(int cell = 0; cell < numCells; cell++){
1292  for(int point = 0; point < numPoints; point++){
1293  for(int row = 0; row < matDim; row++){
1294  outputData(cell, point, row) = 0.0;
1295  for(int col = 0; col < matDim; col++){
1296  outputData(cell, point, row) += \
1297  inputDataLeft(cell, 0, row, col)*inputDataRight(cell, point, col);
1298  }// col
1299  } //row
1300  }// point
1301  }// cell
1302  } // no transpose
1303  else if ((transpose == 't') || (transpose == 'T')) {
1304  for(int cell = 0; cell < numCells; cell++){
1305  for(int point = 0; point < numPoints; point++){
1306  for(int row = 0; row < matDim; row++){
1307  outputData(cell, point, row) = 0.0;
1308  for(int col = 0; col < matDim; col++){
1309  outputData(cell, point, row) += \
1310  inputDataLeft(cell, 0, col, row)*inputDataRight(cell, point, col);
1311  }// col
1312  } //row
1313  }// point
1314  }// cell
1315  } //transpose
1316  else {
1317  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
1318  ">>> ERROR (ArrayTools::matvecProductDataData): The transpose flag must be 'n', 'N', 't' or 'T'.");
1319  }
1320  break;
1321 
1322  default:
1323  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataLeftRank == 2) || (dataLeftRank == 3) || (dataLeftRank == 4) ), std::invalid_argument,
1324  ">>> ERROR (ArrayTools::matvecProductDataData): inputDataLeft rank 2, 3 or 4 required.")
1325  } // switch inputDataLeft rank
1326  } // end constant data case
1327  } // inputDataRight rank 4
1328  /*********************************************************************************************
1329  * inputDataRight is (P,D) *
1330  *********************************************************************************************/
1331  else if(dataRightRank == 2) {
1332  if(numDataLeftPts != 1){ // non-constant data
1333 
1334  switch(dataLeftRank){
1335  case 2:
1336  for(int cell = 0; cell < numCells; cell++) {
1337  for(int point = 0; point < numPoints; point++) {
1338  for( int row = 0; row < matDim; row++) {
1339  outputData(cell, point, row) = \
1340  inputDataLeft(cell, point)*inputDataRight(point, row);
1341  } // Row-loop
1342  } // P-loop
1343  }// C-loop
1344  break;
1345 
1346  case 3:
1347  for(int cell = 0; cell < numCells; cell++) {
1348  for(int point = 0; point < numPoints; point++) {
1349  for( int row = 0; row < matDim; row++) {
1350  outputData(cell, point, row) = \
1351  inputDataLeft(cell, point, row)*inputDataRight(point, row);
1352  } // Row-loop
1353  } // P-loop
1354  }// C-loop
1355  break;
1356 
1357  case 4:
1358  if ((transpose == 'n') || (transpose == 'N')) {
1359  for(int cell = 0; cell < numCells; cell++){
1360  for(int point = 0; point < numPoints; point++){
1361  for(int row = 0; row < matDim; row++){
1362  outputData(cell, point, row) = 0.0;
1363  for(int col = 0; col < matDim; col++){
1364  outputData(cell, point, row) += \
1365  inputDataLeft(cell, point, row, col)*inputDataRight(point, col);
1366  }// col
1367  } //row
1368  }// point
1369  }// cell
1370  } // no transpose
1371  else if ((transpose == 't') || (transpose == 'T')) {
1372  for(int cell = 0; cell < numCells; cell++){
1373  for(int point = 0; point < numPoints; point++){
1374  for(int row = 0; row < matDim; row++){
1375  outputData(cell, point, row) = 0.0;
1376  for(int col = 0; col < matDim; col++){
1377  outputData(cell, point, row) += \
1378  inputDataLeft(cell, point, col, row)*inputDataRight(point, col);
1379  }// col
1380  } //row
1381  }// point
1382  }// cell
1383  } //transpose
1384  else {
1385  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
1386  ">>> ERROR (ArrayTools::matvecProductDataData): The transpose flag must be 'n', 'N', 't' or 'T'.");
1387  }
1388  break;
1389 
1390  default:
1391  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataLeftRank == 2) || (dataLeftRank == 3) || (dataLeftRank == 4) ), std::invalid_argument,
1392  ">>> ERROR (ArrayTools::matvecProductDataData): inputDataLeft rank 2, 3 or 4 required.")
1393  } // switch inputDataLeft rank
1394  }
1395  else{ // constant data case
1396  switch(dataLeftRank){
1397  case 2:
1398  for(int cell = 0; cell < numCells; cell++) {
1399  for(int point = 0; point < numPoints; point++) {
1400  for( int row = 0; row < matDim; row++) {
1401  outputData(cell, point, row) = \
1402  inputDataLeft(cell, 0)*inputDataRight(point, row);
1403  } // Row-loop
1404  } // P-loop
1405  }// C-loop
1406  break;
1407 
1408  case 3:
1409  for(int cell = 0; cell < numCells; cell++) {
1410  for(int point = 0; point < numPoints; point++) {
1411  for( int row = 0; row < matDim; row++) {
1412  outputData(cell, point, row) = \
1413  inputDataLeft(cell, 0, row)*inputDataRight(point, row);
1414  } // Row-loop
1415  } // P-loop
1416  }// C-loop
1417  break;
1418 
1419  case 4:
1420  if ((transpose == 'n') || (transpose == 'N')) {
1421  for(int cell = 0; cell < numCells; cell++){
1422  for(int point = 0; point < numPoints; point++){
1423  for(int row = 0; row < matDim; row++){
1424  outputData(cell, point, row) = 0.0;
1425  for(int col = 0; col < matDim; col++){
1426  outputData(cell, point, row) += \
1427  inputDataLeft(cell, 0, row, col)*inputDataRight(point, col);
1428  }// col
1429  } //row
1430  }// point
1431  }// cell
1432  } // no transpose
1433  else if ((transpose == 't') || (transpose == 'T')) {
1434  for(int cell = 0; cell < numCells; cell++){
1435  for(int point = 0; point < numPoints; point++){
1436  for(int row = 0; row < matDim; row++){
1437  outputData(cell, point, row) = 0.0;
1438  for(int col = 0; col < matDim; col++){
1439  outputData(cell, point, row) += \
1440  inputDataLeft(cell, 0, col, row)*inputDataRight(point, col);
1441  }// col
1442  } //row
1443  }// point
1444  }// cell
1445  } //transpose
1446  else {
1447  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
1448  ">>> ERROR (ArrayTools::matvecProductDataData): The transpose flag must be 'n', 'N', 't' or 'T'.");
1449  }
1450  break;
1451 
1452  default:
1453  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataLeftRank == 2) || (dataLeftRank == 3) || (dataLeftRank == 4) ), std::invalid_argument,
1454  ">>> ERROR (ArrayTools::matvecProductDataData): inputDataLeft rank 2, 3 or 4 required.")
1455  } // switch inputDataLeft rank
1456  } // end constant inputDataLeft case
1457  } // inputDataRight rank 2
1458  else {
1459  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
1460  ">>> ERROR (ArrayTools::matvecProductDataData): inputDataRight rank 2 or 3 required.")
1461  }// rank error
1462  }
1463 
1464 
1465 
1466  template<class Scalar,
1467  class ArrayOutFields,
1468  class ArrayInData,
1469  class ArrayInFields>
1470  void ArrayTools::matmatProductDataField(ArrayOutFields & outputFields,
1471  const ArrayInData & inputData,
1472  const ArrayInFields & inputFields,
1473  const char transpose){
1474 #ifdef HAVE_INTREPID_DEBUG
1475  std::string errmsg = ">>> ERROR (ArrayTools::matmatProductDataField):";
1476  /*
1477  * Check array rank and spatial dimension range (if applicable)
1478  * (1) inputData(C,P), (C,P,D) or (C,P,D,D); P=1 is admissible to allow multiply by const. data
1479  * (2) inputFields(C,F,P,D,D) or (F,P,D,D);
1480  * (3) outputFields(C,F,P,D,D)
1481  */
1482  // (1) inputData is (C,P), (C, P, D) or (C, P, D, D) and 1 <= D <= 3 is required
1483  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputData, 2,4),
1484  std::invalid_argument, errmsg);
1485  if(inputData.rank() > 2) {
1486  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputData, 2, 1,3),
1487  std::invalid_argument, errmsg);
1488  }
1489  if(inputData.rank() == 4) {
1490  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputData, 3, 1,3),
1491  std::invalid_argument, errmsg);
1492  }
1493  // (2) inputFields is (C,F,P,D,D) or (F,P,D,D) and 1 <= (dimension(rank-1), (rank-2)) <= 3 is required.
1494  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputFields, 4,5), std::invalid_argument, errmsg);
1495  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputFields, inputFields.rank()-1, 1,3),
1496  std::invalid_argument, errmsg);
1497  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputFields, inputFields.rank()-2, 1,3),
1498  std::invalid_argument, errmsg);
1499  // (3) outputFields is (C,F,P,D,D)
1500  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, outputFields, 5,5), std::invalid_argument, errmsg);
1501  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, outputFields, 3, 1,3),
1502  std::invalid_argument, errmsg);
1503  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, outputFields, 4, 1,3),
1504  std::invalid_argument, errmsg);
1505  /*
1506  * Dimension cross-checks:
1507  * (1) inputData vs. inputFields
1508  * (2) outputFields vs. inputData
1509  * (3) outputFields vs. inputFields
1510  *
1511  * Cross-check (2): outputFields(C,F,P,D,D) vs. inputData(C,P), (C,P,D) or (C,P,D,D):
1512  * dimensions C, and D must match in all cases, dimension P must match only when non-constant
1513  * data is specified (P>1). Do not check P dimensions with constant data, i.e., when P=1 in
1514  * inputData(C,1,...)
1515  */
1516  if(inputData.dimension(1) > 1){ // check P dimension if P>1 in inputData
1517  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1518  outputFields, 2,
1519  inputData, 1),
1520  std::invalid_argument, errmsg);
1521  }
1522  if(inputData.rank() == 2) { // inputData(C,P) -> C match
1523  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1524  outputFields, 0,
1525  inputData, 0),
1526  std::invalid_argument, errmsg);
1527  }
1528  if(inputData.rank() == 3){ // inputData(C,P,D) -> C, D match
1529  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1530  outputFields, 0,3,4,
1531  inputData, 0,2,2),
1532  std::invalid_argument, errmsg);
1533 
1534  }
1535  if(inputData.rank() == 4){ // inputData(C,P,D,D) -> C, D, D match
1536  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1537  outputFields, 0,3,4,
1538  inputData, 0,2,3),
1539  std::invalid_argument, errmsg);
1540  }
1541  /*
1542  * Cross-checks (1,3):
1543  */
1544  if( inputFields.rank() == 5) {
1545  // Cross-check (1): inputData(C,P), (C,P,D) or (C,P,D,D) vs. inputFields(C,F,P,D,D): dimensions C, P, D must match
1546  if(inputData.dimension(1) > 1){ // check P dimension if P>1 in inputData
1547  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1548  inputData, 1,
1549  inputFields, 2),
1550  std::invalid_argument, errmsg);
1551  }
1552  if(inputData.rank() == 2){ // inputData(C,P) -> C match
1553  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1554  inputData, 0,
1555  inputFields, 0),
1556  std::invalid_argument, errmsg);
1557  }
1558  if(inputData.rank() == 3){ // inputData(C,P,D) -> C, D match
1559  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1560  inputData, 0,2,2,
1561  inputFields, 0,3,4),
1562  std::invalid_argument, errmsg);
1563  }
1564  if(inputData.rank() == 4){ // inputData(C,P,D,D) -> C, D, D match
1565  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1566  inputData, 0,2,3,
1567  inputFields, 0,3,4),
1568  std::invalid_argument, errmsg);
1569  }
1570  // Cross-check (3): outputFields(C,F,P,D,D) vs. inputFields(C,F,P,D,D): all dimensions C, F, P, D must match
1571  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputFields, inputFields),
1572  std::invalid_argument, errmsg);
1573  }
1574  else{
1575  // Cross-check (1): inputData(C,P), (C,P,D) or (C,P,D,D) vs. inputFields(F,P,D,D): dimensions P, D must match
1576  if(inputData.dimension(1) > 1){ // check P if P>1 in inputData
1577  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1578  inputData, 1,
1579  inputFields, 1),
1580  std::invalid_argument, errmsg);
1581  }
1582  if(inputData.rank() == 3){
1583  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1584  inputData, 2,2,
1585  inputFields, 2,3),
1586  std::invalid_argument, errmsg);
1587  }
1588  if(inputData.rank() == 4){
1589  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1590  inputData, 2,3,
1591  inputFields, 2,3),
1592  std::invalid_argument, errmsg);
1593  }
1594  // Cross-check (3): outputFields(C,F,P,D,D) vs. inputFields(F,P,D,D): dimensions F, P, D must match
1595  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1596  outputFields, 1,2,3,4,
1597  inputFields, 0,1,2,3),
1598  std::invalid_argument, errmsg);
1599  }
1600 #endif
1601  int dataRank = inputData.rank();
1602  int numDataPts = inputData.dimension(1);
1603  int inRank = inputFields.rank();
1604  int numCells = outputFields.dimension(0);
1605  int numFields = outputFields.dimension(1);
1606  int numPoints = outputFields.dimension(2);
1607  int matDim = outputFields.dimension(3);
1608 
1609  /*********************************************************************************************
1610  * inputFields is (C,F,P,D,D) *
1611  *********************************************************************************************/
1612  if(inRank == 5){
1613  if(numDataPts != 1){ // non-constant data
1614 
1615  switch(dataRank){
1616  case 2:
1617  for(int cell = 0; cell < numCells; cell++) {
1618  for(int field = 0; field < numFields; field++) {
1619  for(int point = 0; point < numPoints; point++) {
1620  for( int row = 0; row < matDim; row++) {
1621  for( int col = 0; col < matDim; col++) {
1622  outputFields(cell, field, point, row, col) = \
1623  inputData(cell, point)*inputFields(cell, field, point, row, col);
1624  }// Col-loop
1625  } // Row-loop
1626  } // P-loop
1627  } // F-loop
1628  }// C-loop
1629  break;
1630 
1631  case 3:
1632  for(int cell = 0; cell < numCells; cell++) {
1633  for(int field = 0; field < numFields; field++) {
1634  for(int point = 0; point < numPoints; point++) {
1635  for( int row = 0; row < matDim; row++) {
1636  for( int col = 0; col < matDim; col++) {
1637  outputFields(cell, field, point, row, col) = \
1638  inputData(cell, point, row)*inputFields(cell, field, point, row, col);
1639  }// Col-loop
1640  } // Row-loop
1641  } // P-loop
1642  } // F-loop
1643  }// C-loop
1644  break;
1645 
1646  case 4:
1647  if ((transpose == 'n') || (transpose == 'N')) {
1648  for(int cell = 0; cell < numCells; cell++){
1649  for(int field = 0; field < numFields; field++){
1650  for(int point = 0; point < numPoints; point++){
1651  for(int row = 0; row < matDim; row++){
1652  for(int col = 0; col < matDim; col++){
1653  outputFields(cell, field, point, row, col) = 0.0;
1654  for(int i = 0; i < matDim; i++){
1655  outputFields(cell, field, point, row, col) += \
1656  inputData(cell, point, row, i)*inputFields(cell, field, point, i, col);
1657  }// i
1658  } // col
1659  } //row
1660  }// point
1661  }// field
1662  }// cell
1663  } // no transpose
1664  else if ((transpose == 't') || (transpose == 'T')) {
1665  for(int cell = 0; cell < numCells; cell++){
1666  for(int field = 0; field < numFields; field++){
1667  for(int point = 0; point < numPoints; point++){
1668  for(int row = 0; row < matDim; row++){
1669  for(int col = 0; col < matDim; col++){
1670  outputFields(cell, field, point, row, col) = 0.0;
1671  for(int i = 0; i < matDim; i++){
1672  outputFields(cell, field, point, row, col) += \
1673  inputData(cell, point, i, row)*inputFields(cell, field, point, i, col);
1674  }// i
1675  } // col
1676  } //row
1677  }// point
1678  }// field
1679  }// cell
1680  } //transpose
1681  else {
1682  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
1683  ">>> ERROR (ArrayTools::matmatProductDataField): The transpose flag must be 'n', 'N', 't' or 'T'.");
1684  }
1685  break;
1686 
1687  default:
1688  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataRank == 2) || (dataRank == 3) || (dataRank == 4) ), std::invalid_argument,
1689  ">>> ERROR (ArrayTools::matmatProductDataField): inputData rank 2, 3 or 4 required.")
1690  } // switch inputData rank
1691  }
1692  else{ // constant data case
1693  switch(dataRank){
1694  case 2:
1695  for(int cell = 0; cell < numCells; cell++) {
1696  for(int field = 0; field < numFields; field++) {
1697  for(int point = 0; point < numPoints; point++) {
1698  for( int row = 0; row < matDim; row++) {
1699  for( int col = 0; col < matDim; col++) {
1700  outputFields(cell, field, point, row, col) = \
1701  inputData(cell, 0)*inputFields(cell, field, point, row, col);
1702  }// Col-loop
1703  } // Row-loop
1704  } // P-loop
1705  } // F-loop
1706  }// C-loop
1707  break;
1708 
1709  case 3:
1710  for(int cell = 0; cell < numCells; cell++) {
1711  for(int field = 0; field < numFields; field++) {
1712  for(int point = 0; point < numPoints; point++) {
1713  for( int row = 0; row < matDim; row++) {
1714  for( int col = 0; col < matDim; col++) {
1715  outputFields(cell, field, point, row, col) = \
1716  inputData(cell, 0, row)*inputFields(cell, field, point, row, col);
1717  }// Col-loop
1718  } // Row-loop
1719  } // P-loop
1720  } // F-loop
1721  }// C-loop
1722  break;
1723 
1724  case 4:
1725  if ((transpose == 'n') || (transpose == 'N')) {
1726  for(int cell = 0; cell < numCells; cell++){
1727  for(int field = 0; field < numFields; field++){
1728  for(int point = 0; point < numPoints; point++){
1729  for(int row = 0; row < matDim; row++){
1730  for(int col = 0; col < matDim; col++){
1731  outputFields(cell, field, point, row, col) = 0.0;
1732  for(int i = 0; i < matDim; i++){
1733  outputFields(cell, field, point, row, col) += \
1734  inputData(cell, 0, row, i)*inputFields(cell, field, point, i, col);
1735  }// i
1736  } // col
1737  } //row
1738  }// point
1739  }// field
1740  }// cell
1741  } // no transpose
1742  else if ((transpose == 't') || (transpose == 'T')) {
1743  for(int cell = 0; cell < numCells; cell++){
1744  for(int field = 0; field < numFields; field++){
1745  for(int point = 0; point < numPoints; point++){
1746  for(int row = 0; row < matDim; row++){
1747  for(int col = 0; col < matDim; col++){
1748  outputFields(cell, field, point, row, col) = 0.0;
1749  for(int i = 0; i < matDim; i++){
1750  outputFields(cell, field, point, row, col) += \
1751  inputData(cell, 0, i, row)*inputFields(cell, field, point, i, col);
1752  }// i
1753  } // col
1754  } //row
1755  }// point
1756  }// field
1757  }// cell
1758  } //transpose
1759  else {
1760  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
1761  ">>> ERROR (ArrayTools::matmatProductDataField): The transpose flag must be 'n', 'N', 't' or 'T'.");
1762  }
1763  break;
1764 
1765  default:
1766  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataRank == 2) || (dataRank == 3) || (dataRank == 4) ), std::invalid_argument,
1767  ">>> ERROR (ArrayTools::matmatProductDataField): inputData rank 2, 3 or 4 required.")
1768  } // switch inputData rank
1769  } // end constant data case
1770  } // inputFields rank 5
1771  /**********************************************************************************************
1772  * inputFields is (F,P,D,D) *
1773  *********************************************************************************************/
1774  else if(inRank == 4) {
1775  if(numDataPts != 1){ // non-constant data
1776 
1777  switch(dataRank){
1778  case 2:
1779  for(int cell = 0; cell < numCells; cell++) {
1780  for(int field = 0; field < numFields; field++) {
1781  for(int point = 0; point < numPoints; point++) {
1782  for( int row = 0; row < matDim; row++) {
1783  for( int col = 0; col < matDim; col++) {
1784  outputFields(cell, field, point, row, col) = \
1785  inputData(cell, point)*inputFields(field, point, row, col);
1786  }// Col-loop
1787  } // Row-loop
1788  } // P-loop
1789  } // F-loop
1790  }// C-loop
1791  break;
1792 
1793  case 3:
1794  for(int cell = 0; cell < numCells; cell++) {
1795  for(int field = 0; field < numFields; field++) {
1796  for(int point = 0; point < numPoints; point++) {
1797  for( int row = 0; row < matDim; row++) {
1798  for( int col = 0; col < matDim; col++) {
1799  outputFields(cell, field, point, row, col) = \
1800  inputData(cell, point, row)*inputFields(field, point, row, col);
1801  }// Col-loop
1802  } // Row-loop
1803  } // P-loop
1804  } // F-loop
1805  }// C-loop
1806  break;
1807 
1808  case 4:
1809  if ((transpose == 'n') || (transpose == 'N')) {
1810  for(int cell = 0; cell < numCells; cell++){
1811  for(int field = 0; field < numFields; field++){
1812  for(int point = 0; point < numPoints; point++){
1813  for(int row = 0; row < matDim; row++){
1814  for(int col = 0; col < matDim; col++){
1815  outputFields(cell, field, point, row, col) = 0.0;
1816  for(int i = 0; i < matDim; i++){
1817  outputFields(cell, field, point, row, col) += \
1818  inputData(cell, point, row, i)*inputFields(field, point, i, col);
1819  }// i
1820  } // col
1821  } //row
1822  }// point
1823  }// field
1824  }// cell
1825  } // no transpose
1826  else if ((transpose == 't') || (transpose == 'T')) {
1827  for(int cell = 0; cell < numCells; cell++){
1828  for(int field = 0; field < numFields; field++){
1829  for(int point = 0; point < numPoints; point++){
1830  for(int row = 0; row < matDim; row++){
1831  for(int col = 0; col < matDim; col++){
1832  outputFields(cell, field, point, row, col) = 0.0;
1833  for(int i = 0; i < matDim; i++){
1834  outputFields(cell, field, point, row, col) += \
1835  inputData(cell, point, i, row)*inputFields(field, point, i, col);
1836  }// i
1837  } // col
1838  } //row
1839  }// point
1840  }// field
1841  }// cell
1842  } //transpose
1843  else {
1844  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
1845  ">>> ERROR (ArrayTools::matmatProductDataField): The transpose flag must be 'n', 'N', 't' or 'T'.");
1846  }
1847  break;
1848 
1849  default:
1850  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataRank == 2) || (dataRank == 3) || (dataRank == 4) ), std::invalid_argument,
1851  ">>> ERROR (ArrayTools::matmatProductDataField): inputData rank 2, 3 or 4 required.")
1852  } // switch inputData rank
1853  }
1854  else{ // constant data case
1855  switch(dataRank){
1856  case 2:
1857  for(int cell = 0; cell < numCells; cell++) {
1858  for(int field = 0; field < numFields; field++) {
1859  for(int point = 0; point < numPoints; point++) {
1860  for( int row = 0; row < matDim; row++) {
1861  for( int col = 0; col < matDim; col++) {
1862  outputFields(cell, field, point, row, col) = \
1863  inputData(cell, 0)*inputFields(field, point, row, col);
1864  }// Col-loop
1865  } // Row-loop
1866  } // P-loop
1867  } // F-loop
1868  }// C-loop
1869  break;
1870 
1871  case 3:
1872  for(int cell = 0; cell < numCells; cell++) {
1873  for(int field = 0; field < numFields; field++) {
1874  for(int point = 0; point < numPoints; point++) {
1875  for( int row = 0; row < matDim; row++) {
1876  for( int col = 0; col < matDim; col++) {
1877  outputFields(cell, field, point, row, col) = \
1878  inputData(cell, 0, row)*inputFields(field, point, row, col);
1879  }// Col-loop
1880  } // Row-loop
1881  } // P-loop
1882  } // F-loop
1883  }// C-loop
1884  break;
1885 
1886  case 4:
1887  if ((transpose == 'n') || (transpose == 'N')) {
1888  for(int cell = 0; cell < numCells; cell++){
1889  for(int field = 0; field < numFields; field++){
1890  for(int point = 0; point < numPoints; point++){
1891  for(int row = 0; row < matDim; row++){
1892  for(int col = 0; col < matDim; col++){
1893  outputFields(cell, field, point, row, col) = 0.0;
1894  for(int i = 0; i < matDim; i++){
1895  outputFields(cell, field, point, row, col) += \
1896  inputData(cell, 0, row, i)*inputFields(field, point, i, col);
1897  }// i
1898  } // col
1899  } //row
1900  }// point
1901  }// field
1902  }// cell
1903  } // no transpose
1904  else if ((transpose == 't') || (transpose == 'T')) {
1905  for(int cell = 0; cell < numCells; cell++){
1906  for(int field = 0; field < numFields; field++){
1907  for(int point = 0; point < numPoints; point++){
1908  for(int row = 0; row < matDim; row++){
1909  for(int col = 0; col < matDim; col++){
1910  outputFields(cell, field, point, row, col) = 0.0;
1911  for(int i = 0; i < matDim; i++){
1912  outputFields(cell, field, point, row, col) += \
1913  inputData(cell, 0, i, row)*inputFields(field, point, i, col);
1914  }// i
1915  } // col
1916  } //row
1917  }// point
1918  }// field
1919  }// cell
1920  } //transpose
1921  else {
1922  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
1923  ">>> ERROR (ArrayTools::matmatProductDataField): The transpose flag must be 'n', 'N', 't' or 'T'.");
1924  }
1925  break;
1926 
1927  default:
1928  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataRank == 2) || (dataRank == 3) || (dataRank == 4) ), std::invalid_argument,
1929  ">>> ERROR (ArrayTools::matmatProductDataField): inputData rank 2, 3 or 4 required.")
1930  } // switch inputData rank
1931  } // end constant data case
1932  } // inputFields rank 4
1933  else {
1934  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
1935  ">>> ERROR (ArrayTools::matmatProductDataField): inputFields rank 4 or 5 required.")
1936  }// rank error
1937  }
1938 
1939 
1940 
1941  template<class Scalar,
1942  class ArrayOutData,
1943  class ArrayInDataLeft,
1944  class ArrayInDataRight>
1945  void ArrayTools::matmatProductDataData(ArrayOutData & outputData,
1946  const ArrayInDataLeft & inputDataLeft,
1947  const ArrayInDataRight & inputDataRight,
1948  const char transpose){
1949 #ifdef HAVE_INTREPID_DEBUG
1950  std::string errmsg = ">>> ERROR (ArrayTools::matmatProductDataData):";
1951  /*
1952  * Check array rank and spatial dimension range (if applicable)
1953  * (1) inputDataLeft(C,P), (C,P,D) or (C,P,D,D); P=1 is admissible to allow multiply by const. left data
1954  * (2) inputDataRight(C,P,D,D) or (P,D,D);
1955  * (3) outputData(C,P,D,D)
1956  */
1957  // (1) inputDataLeft is (C,P), (C,P,D) or (C,P,D,D) and 1 <= D <= 3 is required
1958  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputDataLeft, 2,4),
1959  std::invalid_argument, errmsg);
1960  if(inputDataLeft.rank() > 2) {
1961  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputDataLeft, 2, 1,3),
1962  std::invalid_argument, errmsg);
1963  }
1964  if(inputDataLeft.rank() == 4) {
1965  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputDataLeft, 3, 1,3),
1966  std::invalid_argument, errmsg);
1967  }
1968  // (2) inputDataRight is (C,P,D,D) or (P,D,D) and 1 <= (D=dimension(rank-1),(rank-2)) <= 3 is required.
1969  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, inputDataRight, 3,4),
1970  std::invalid_argument, errmsg);
1971  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputDataRight, inputDataRight.rank()-1, 1,3),
1972  std::invalid_argument, errmsg);
1973  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, inputDataRight, inputDataRight.rank()-2, 1,3),
1974  std::invalid_argument, errmsg);
1975  // (3) outputData is (C,P,D,D)
1976  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, outputData, 4, 4), std::invalid_argument, errmsg);
1977  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, outputData, 2, 1,3),
1978  std::invalid_argument, errmsg);
1979  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, outputData, 3, 1,3),
1980  std::invalid_argument, errmsg);
1981  /*
1982  * Dimension cross-checks:
1983  * (1) inputDataLeft vs. inputDataRight
1984  * (2) outputData vs. inputDataLeft
1985  * (3) outputData vs. inputDataRight
1986  *
1987  * Cross-check (2): outputData(C,P,D,D) vs. inputDataLeft(C,P), (C,P,D) or (C,P,D,D):
1988  * dimensions C, and D must match in all cases, dimension P must match only when non-constant
1989  * data is specified (P>1). Do not check P dimensions with constant left data, i.e., when P=1 in
1990  * inputDataLeft(C,1,...)
1991  */
1992  if(inputDataLeft.dimension(1) > 1){ // check P dimension if P>1 in inputDataLeft
1993  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
1994  outputData, 1,
1995  inputDataLeft, 1),
1996  std::invalid_argument, errmsg);
1997  }
1998  if(inputDataLeft.rank() == 2){ // inputDataLeft(C,P): check C
1999  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
2000  outputData, 0,
2001  inputDataLeft, 0),
2002  std::invalid_argument, errmsg);
2003  }
2004  if(inputDataLeft.rank() == 3){ // inputDataLeft(C,P,D): check C and D
2005  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
2006  outputData, 0,2,3,
2007  inputDataLeft, 0,2,2),
2008  std::invalid_argument, errmsg);
2009  }
2010  if(inputDataLeft.rank() == 4){ // inputDataLeft(C,P,D,D): check C and D
2011  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
2012  outputData, 0,2,3,
2013  inputDataLeft, 0,2,3),
2014  std::invalid_argument, errmsg);
2015  }
2016  /*
2017  * Cross-checks (1,3):
2018  */
2019  if( inputDataRight.rank() == 4) {
2020  // Cross-check (1): inputDataLeft(C,P), (C,P,D), or (C,P,D,D) vs. inputDataRight(C,P,D,D): dimensions C, P, D must match
2021  if(inputDataLeft.dimension(1) > 1){ // check P dimension if P>1 in inputDataLeft
2022  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
2023  inputDataLeft, 1,
2024  inputDataRight, 1),
2025  std::invalid_argument, errmsg);
2026  }
2027  if(inputDataLeft.rank() == 2){ // inputDataLeft(C,P): check C
2028  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
2029  inputDataLeft, 0,
2030  inputDataRight, 0),
2031  std::invalid_argument, errmsg);
2032  }
2033  if(inputDataLeft.rank() == 3){ // inputDataLeft(C,P,D): check C and D
2034  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
2035  inputDataLeft, 0,2,2,
2036  inputDataRight, 0,2,3),
2037  std::invalid_argument, errmsg);
2038  }
2039  if(inputDataLeft.rank() == 4){ // inputDataLeft(C,P,D,D): check C and D
2040  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
2041  inputDataLeft, 0,2,3,
2042  inputDataRight, 0,2,3),
2043  std::invalid_argument, errmsg);
2044  }
2045  // Cross-check (3): outputData(C,P,D,D) vs. inputDataRight(C,P,D,D): all dimensions C, P, D must match
2046  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, outputData, inputDataRight),
2047  std::invalid_argument, errmsg);
2048  }
2049  else{
2050  // Cross-check (1): inputDataLeft(C,P), (C,P,D), or (C,P,D,D) vs. inputDataRight(P,D,D): dimensions P, D must match
2051  if(inputDataLeft.dimension(1) > 1){ // check P if P>1 in inputData
2052  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
2053  inputDataLeft, 1,
2054  inputDataRight, 0),
2055  std::invalid_argument, errmsg);
2056  }
2057  if(inputDataLeft.rank() == 3){ // inputDataLeft(C,P,D): check D
2058  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
2059  inputDataLeft, 2,2,
2060  inputDataRight, 1,2),
2061  std::invalid_argument, errmsg);
2062  }
2063  if(inputDataLeft.rank() == 4){ // inputDataLeft(C,P,D,D): check D
2064  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
2065  inputDataLeft, 2,3,
2066  inputDataRight, 1,2),
2067  std::invalid_argument, errmsg);
2068  }
2069  // Cross-check (3): outputData(C,P,D,D) vs. inputDataRight(P,D,D): dimensions P, D must match
2070  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg,
2071  outputData, 1,2,3,
2072  inputDataRight, 0,1,2),
2073  std::invalid_argument, errmsg);
2074  }
2075 #endif
2076  int dataLeftRank = inputDataLeft.rank();
2077  int numDataLeftPts = inputDataLeft.dimension(1);
2078  int dataRightRank = inputDataRight.rank();
2079  int numCells = outputData.dimension(0);
2080  int numPoints = outputData.dimension(1);
2081  int matDim = outputData.dimension(2);
2082 
2083  /*********************************************************************************************
2084  * inputDataRight is (C,P,D,D) *
2085  *********************************************************************************************/
2086  if(dataRightRank == 4){
2087  if(numDataLeftPts != 1){ // non-constant data
2088 
2089  switch(dataLeftRank){
2090  case 2:
2091  for(int cell = 0; cell < numCells; cell++) {
2092  for(int point = 0; point < numPoints; point++) {
2093  for( int row = 0; row < matDim; row++) {
2094  for( int col = 0; col < matDim; col++) {
2095  outputData(cell, point, row, col) = \
2096  inputDataLeft(cell, point)*inputDataRight(cell, point, row, col);
2097  }// Col-loop
2098  } // Row-loop
2099  } // P-loop
2100  }// C-loop
2101  break;
2102 
2103  case 3:
2104  for(int cell = 0; cell < numCells; cell++) {
2105  for(int point = 0; point < numPoints; point++) {
2106  for( int row = 0; row < matDim; row++) {
2107  for( int col = 0; col < matDim; col++) {
2108  outputData(cell, point, row, col) = \
2109  inputDataLeft(cell, point, row)*inputDataRight(cell, point, row, col);
2110  }// Col-loop
2111  } // Row-loop
2112  } // P-loop
2113  }// C-loop
2114  break;
2115 
2116  case 4:
2117  if ((transpose == 'n') || (transpose == 'N')) {
2118  for(int cell = 0; cell < numCells; cell++){
2119  for(int point = 0; point < numPoints; point++){
2120  for(int row = 0; row < matDim; row++){
2121  for(int col = 0; col < matDim; col++){
2122  outputData(cell, point, row, col) = 0.0;
2123  for(int i = 0; i < matDim; i++){
2124  outputData(cell, point, row, col) += \
2125  inputDataLeft(cell, point, row, i)*inputDataRight(cell, point, i, col);
2126  }// i
2127  } // col
2128  } //row
2129  }// point
2130  }// cell
2131  } // no transpose
2132  else if ((transpose == 't') || (transpose == 'T')) {
2133  for(int cell = 0; cell < numCells; cell++){
2134  for(int point = 0; point < numPoints; point++){
2135  for(int row = 0; row < matDim; row++){
2136  for(int col = 0; col < matDim; col++){
2137  outputData(cell, point, row, col) = 0.0;
2138  for(int i = 0; i < matDim; i++){
2139  outputData(cell, point, row, col) += \
2140  inputDataLeft(cell, point, i, row)*inputDataRight(cell, point, i, col);
2141  }// i
2142  } // col
2143  } //row
2144  }// point
2145  }// cell
2146  } //transpose
2147  else {
2148  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
2149  ">>> ERROR (ArrayTools::matmatProductDataData): The transpose flag must be 'n', 'N', 't' or 'T'.");
2150  }
2151  break;
2152 
2153  default:
2154  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataLeftRank == 2) || (dataLeftRank == 3) || (dataLeftRank == 4) ), std::invalid_argument,
2155  ">>> ERROR (ArrayTools::matmatProductDataData): inputDataLeft rank 2, 3 or 4 required.")
2156  } // switch inputData rank
2157  }
2158  else{ // constant data case
2159  switch(dataLeftRank){
2160  case 2:
2161  for(int cell = 0; cell < numCells; cell++) {
2162  for(int point = 0; point < numPoints; point++) {
2163  for( int row = 0; row < matDim; row++) {
2164  for( int col = 0; col < matDim; col++) {
2165  outputData(cell, point, row, col) = \
2166  inputDataLeft(cell, 0)*inputDataRight(cell, point, row, col);
2167  }// Col-loop
2168  } // Row-loop
2169  } // P-loop
2170  }// C-loop
2171  break;
2172 
2173  case 3:
2174  for(int cell = 0; cell < numCells; cell++) {
2175  for(int point = 0; point < numPoints; point++) {
2176  for( int row = 0; row < matDim; row++) {
2177  for( int col = 0; col < matDim; col++) {
2178  outputData(cell, point, row, col) = \
2179  inputDataLeft(cell, 0, row)*inputDataRight(cell, point, row, col);
2180  }// Col-loop
2181  } // Row-loop
2182  } // P-loop
2183  }// C-loop
2184  break;
2185 
2186  case 4:
2187  if ((transpose == 'n') || (transpose == 'N')) {
2188  for(int cell = 0; cell < numCells; cell++){
2189  for(int point = 0; point < numPoints; point++){
2190  for(int row = 0; row < matDim; row++){
2191  for(int col = 0; col < matDim; col++){
2192  outputData(cell, point, row, col) = 0.0;
2193  for(int i = 0; i < matDim; i++){
2194  outputData(cell, point, row, col) += \
2195  inputDataLeft(cell, 0, row, i)*inputDataRight(cell, point, i, col);
2196  }// i
2197  } // col
2198  } //row
2199  }// point
2200  }// cell
2201  } // no transpose
2202  else if ((transpose == 't') || (transpose == 'T')) {
2203  for(int cell = 0; cell < numCells; cell++){
2204  for(int point = 0; point < numPoints; point++){
2205  for(int row = 0; row < matDim; row++){
2206  for(int col = 0; col < matDim; col++){
2207  outputData(cell, point, row, col) = 0.0;
2208  for(int i = 0; i < matDim; i++){
2209  outputData(cell, point, row, col) += \
2210  inputDataLeft(cell, 0, i, row)*inputDataRight(cell, point, i, col);
2211  }// i
2212  } // col
2213  } //row
2214  }// point
2215  }// cell
2216  } //transpose
2217  else {
2218  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
2219  ">>> ERROR (ArrayTools::matmatProductDataData): The transpose flag must be 'n', 'N', 't' or 'T'.");
2220  }
2221  break;
2222 
2223  default:
2224  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataLeftRank == 2) || (dataLeftRank == 3) || (dataLeftRank == 4) ), std::invalid_argument,
2225  ">>> ERROR (ArrayTools::matmatProductDataData): inputDataLeft rank 2, 3 or 4 required.")
2226  } // switch inputDataLeft rank
2227  } // end constant data case
2228  } // inputDataRight rank 4
2229  /**********************************************************************************************
2230  * inputDataRight is (P,D,D) *
2231  *********************************************************************************************/
2232  else if(dataRightRank == 3) {
2233  if(numDataLeftPts != 1){ // non-constant data
2234 
2235  switch(dataLeftRank){
2236  case 2:
2237  for(int cell = 0; cell < numCells; cell++) {
2238  for(int point = 0; point < numPoints; point++) {
2239  for( int row = 0; row < matDim; row++) {
2240  for( int col = 0; col < matDim; col++) {
2241  outputData(cell, point, row, col) = \
2242  inputDataLeft(cell, point)*inputDataRight(point, row, col);
2243  }// Col-loop
2244  } // Row-loop
2245  } // P-loop
2246  }// C-loop
2247  break;
2248 
2249  case 3:
2250  for(int cell = 0; cell < numCells; cell++) {
2251  for(int point = 0; point < numPoints; point++) {
2252  for( int row = 0; row < matDim; row++) {
2253  for( int col = 0; col < matDim; col++) {
2254  outputData(cell, point, row, col) = \
2255  inputDataLeft(cell, point, row)*inputDataRight(point, row, col);
2256  }// Col-loop
2257  } // Row-loop
2258  } // P-loop
2259  }// C-loop
2260  break;
2261 
2262  case 4:
2263  if ((transpose == 'n') || (transpose == 'N')) {
2264  for(int cell = 0; cell < numCells; cell++){
2265  for(int point = 0; point < numPoints; point++){
2266  for(int row = 0; row < matDim; row++){
2267  for(int col = 0; col < matDim; col++){
2268  outputData(cell, point, row, col) = 0.0;
2269  for(int i = 0; i < matDim; i++){
2270  outputData(cell, point, row, col) += \
2271  inputDataLeft(cell, point, row, i)*inputDataRight(point, i, col);
2272  }// i
2273  } // col
2274  } //row
2275  }// point
2276  }// cell
2277  } // no transpose
2278  else if ((transpose == 't') || (transpose == 'T')) {
2279  for(int cell = 0; cell < numCells; cell++){
2280  for(int point = 0; point < numPoints; point++){
2281  for(int row = 0; row < matDim; row++){
2282  for(int col = 0; col < matDim; col++){
2283  outputData(cell, point, row, col) = 0.0;
2284  for(int i = 0; i < matDim; i++){
2285  outputData(cell, point, row, col) += \
2286  inputDataLeft(cell, point, i, row)*inputDataRight(point, i, col);
2287  }// i
2288  } // col
2289  } //row
2290  }// point
2291  }// cell
2292  } //transpose
2293  else {
2294  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
2295  ">>> ERROR (ArrayTools::matmatProductDataData): The transpose flag must be 'n', 'N', 't' or 'T'.");
2296  }
2297  break;
2298 
2299  default:
2300  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataLeftRank == 2) || (dataLeftRank == 3) || (dataLeftRank == 4) ), std::invalid_argument,
2301  ">>> ERROR (ArrayTools::matmatProductDataData): inputDataLeft rank 2, 3 or 4 required.")
2302  } // switch inputDataLeft rank
2303  }
2304  else{ // constant data case
2305  switch(dataLeftRank){
2306  case 2:
2307  for(int cell = 0; cell < numCells; cell++) {
2308  for(int point = 0; point < numPoints; point++) {
2309  for( int row = 0; row < matDim; row++) {
2310  for( int col = 0; col < matDim; col++) {
2311  outputData(cell, point, row, col) = \
2312  inputDataLeft(cell, 0)*inputDataRight(point, row, col);
2313  }// Col-loop
2314  } // Row-loop
2315  } // P-loop
2316  }// C-loop
2317  break;
2318 
2319  case 3:
2320  for(int cell = 0; cell < numCells; cell++) {
2321  for(int point = 0; point < numPoints; point++) {
2322  for( int row = 0; row < matDim; row++) {
2323  for( int col = 0; col < matDim; col++) {
2324  outputData(cell, point, row, col) = \
2325  inputDataLeft(cell, 0, row)*inputDataRight(point, row, col);
2326  }// Col-loop
2327  } // Row-loop
2328  } // P-loop
2329  }// C-loop
2330  break;
2331 
2332  case 4:
2333  if ((transpose == 'n') || (transpose == 'N')) {
2334  for(int cell = 0; cell < numCells; cell++){
2335  for(int point = 0; point < numPoints; point++){
2336  for(int row = 0; row < matDim; row++){
2337  for(int col = 0; col < matDim; col++){
2338  outputData(cell, point, row, col) = 0.0;
2339  for(int i = 0; i < matDim; i++){
2340  outputData(cell, point, row, col) += \
2341  inputDataLeft(cell, 0, row, i)*inputDataRight(point, i, col);
2342  }// i
2343  } // col
2344  } //row
2345  }// point
2346  }// cell
2347  } // no transpose
2348  else if ((transpose == 't') || (transpose == 'T')) {
2349  for(int cell = 0; cell < numCells; cell++){
2350  for(int point = 0; point < numPoints; point++){
2351  for(int row = 0; row < matDim; row++){
2352  for(int col = 0; col < matDim; col++){
2353  outputData(cell, point, row, col) = 0.0;
2354  for(int i = 0; i < matDim; i++){
2355  outputData(cell, point, row, col) += \
2356  inputDataLeft(cell, 0, i, row)*inputDataRight(point, i, col);
2357  }// i
2358  } // col
2359  } //row
2360  }// point
2361  }// cell
2362  } //transpose
2363  else {
2364  TEUCHOS_TEST_FOR_EXCEPTION( !( (transpose == 'n') || (transpose == 'N') || (transpose == 't') || (transpose == 'T') ), std::invalid_argument,
2365  ">>> ERROR (ArrayTools::matmatProductDataData): The transpose flag must be 'n', 'N', 't' or 'T'.");
2366  }
2367  break;
2368 
2369  default:
2370  TEUCHOS_TEST_FOR_EXCEPTION( !( (dataLeftRank == 2) || (dataLeftRank == 3) || (dataLeftRank == 4) ), std::invalid_argument,
2371  ">>> ERROR (ArrayTools::matmatProductDataData): inputDataLeft rank 2, 3 or 4 required.")
2372  } // switch inputDataLeft rank
2373  } // end constant data case
2374  } // inputDataRight rank 3
2375  else {
2376  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
2377  ">>> ERROR (ArrayTools::matmatProductDataData): inputDataRight rank 3 or 4 required.")
2378  }// rank error
2379  }
2380 
2381 
2382 
2383 
2384 
2385 } // end namespace Intrepid
2386 
2387 
2388 
2389 
2390 
2391 
2392 
2393 
2394 
2395 
2396 
2397 
2398 
2399 
2400 
2401 
2402 
2403 
2404 
2405 
2406 
bool requireDimensionMatch(std::string &errmsg, const Array1 &array1, const int a1_dim0, const Array2 &array2, const int a2_dim0)
Checks arrays for a single matching dimension.
static void matmatProductDataData(ArrayOutData &outputData, const ArrayInDataLeft &inputDataLeft, const ArrayInDataRight &inputDataRight, const char transpose= 'N')
There are two use cases: (1) matrix-matrix product of a rank-4 container inputDataRight with dimensio...
bool requireDimensionRange(std::string &errmsg, const Array &array, const int dim, const int lowerBound, const int upperBound)
Checks if the specified array dimension is in the required range.
static void crossProductDataField(ArrayOutFields &outputFields, const ArrayInData &inputData, const ArrayInFields &inputFields)
There are two use cases: (1) cross product of a rank-4 container inputFields with dimensions (C...
bool requireRankRange(std::string &errmsg, const Array &array, const int lowerBound, const int upperBound)
Checks if the rank of the array argument is in the required range.
static void crossProductDataData(ArrayOutData &outputData, const ArrayInDataLeft &inputDataLeft, const ArrayInDataRight &inputDataRight)
There are two use cases: (1) cross product of a rank-3 container inputDataRight with dimensions (C...
static void matmatProductDataField(ArrayOutFields &outputFields, const ArrayInData &inputData, const ArrayInFields &inputFields, const char transpose= 'N')
There are two use cases: (1) matrix-matrix product of a rank-5 container inputFields with dimensions ...
static void outerProductDataData(ArrayOutData &outputData, const ArrayInDataLeft &inputDataLeft, const ArrayInDataRight &inputDataRight)
There are two use cases: (1) outer product of a rank-3 container inputDataRight with dimensions (C...
static void outerProductDataField(ArrayOutFields &outputFields, const ArrayInData &inputData, const ArrayInFields &inputFields)
There are two use cases: (1) outer product of a rank-4 container inputFields with dimensions (C...
static void matvecProductDataData(ArrayOutData &outputData, const ArrayInDataLeft &inputDataLeft, const ArrayInDataRight &inputDataRight, const char transpose= 'N')
There are two use cases: (1) matrix-vector product of a rank-3 container inputDataRight with dimensio...
static void matvecProductDataField(ArrayOutFields &outputFields, const ArrayInData &inputData, const ArrayInFields &inputFields, const char transpose= 'N')
There are two use cases: (1) matrix-vector product of a rank-4 container inputFields with dimensions ...