Intrepid
Intrepid_ArrayToolsDefScalar.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, class ArrayOutFields, class ArrayInData, class ArrayInFields>
52 void ArrayTools::scalarMultiplyDataField(ArrayOutFields & outputFields,
53  const ArrayInData & inputData,
54  ArrayInFields & inputFields,
55  const bool reciprocal) {
56 
57 #ifdef HAVE_INTREPID_DEBUG
58  TEUCHOS_TEST_FOR_EXCEPTION( (inputData.rank() != 2), std::invalid_argument,
59  ">>> ERROR (ArrayTools::scalarMultiplyDataField): Input data container must have rank 2.");
60  if (outputFields.rank() <= inputFields.rank()) {
61  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputFields.rank() < 3) || (inputFields.rank() > 5) ), std::invalid_argument,
62  ">>> ERROR (ArrayTools::scalarMultiplyDataField): Input fields container must have rank 3, 4, or 5.");
63  TEUCHOS_TEST_FOR_EXCEPTION( (outputFields.rank() != inputFields.rank()), std::invalid_argument,
64  ">>> ERROR (ArrayTools::scalarMultiplyDataField): Input and output fields containers must have the same rank.");
65  TEUCHOS_TEST_FOR_EXCEPTION( (inputFields.dimension(0) != inputData.dimension(0) ), std::invalid_argument,
66  ">>> ERROR (ArrayTools::scalarMultiplyDataField): Zeroth dimensions (number of integration domains) of the fields and data input containers must agree!");
67  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputFields.dimension(2) != inputData.dimension(1)) && (inputData.dimension(1) != 1) ), std::invalid_argument,
68  ">>> ERROR (ArrayTools::scalarMultiplyDataField): Second dimension of the fields input container and first dimension of data input container (number of integration points) must agree or first data dimension must be 1!");
69  for (int i=0; i<inputFields.rank(); i++) {
70  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataField): Dimension ";
71  errmsg += (char)(48+i);
72  errmsg += " of the input and output fields containers must agree!";
73  TEUCHOS_TEST_FOR_EXCEPTION( (inputFields.dimension(i) != outputFields.dimension(i)), std::invalid_argument, errmsg );
74  }
75  }
76  else {
77  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputFields.rank() < 2) || (inputFields.rank() > 4) ), std::invalid_argument,
78  ">>> ERROR (ArrayTools::scalarMultiplyDataField): Input fields container must have rank 2, 3, or 4.");
79  TEUCHOS_TEST_FOR_EXCEPTION( (outputFields.rank() != inputFields.rank()+1), std::invalid_argument,
80  ">>> ERROR (ArrayTools::scalarMultiplyDataField): The rank of the input fields container must be one less than the rank of the output fields container.");
81  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputFields.dimension(1) != inputData.dimension(1)) && (inputData.dimension(1) != 1) ), std::invalid_argument,
82  ">>> ERROR (ArrayTools::scalarMultiplyDataField): First dimensions of fields input container and data input container (number of integration points) must agree or first data dimension must be 1!");
83  TEUCHOS_TEST_FOR_EXCEPTION( ( inputData.dimension(0) != outputFields.dimension(0) ), std::invalid_argument,
84  ">>> ERROR (ArrayTools::scalarMultiplyDataField): Zeroth dimensions of fields output container and data input containers (number of integration domains) must agree!");
85  for (int i=0; i<inputFields.rank(); i++) {
86  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataField): Dimensions ";
87  errmsg += (char)(48+i);
88  errmsg += " and ";
89  errmsg += (char)(48+i+1);
90  errmsg += " of the input and output fields containers must agree!";
91  TEUCHOS_TEST_FOR_EXCEPTION( (inputFields.dimension(i) != outputFields.dimension(i+1)), std::invalid_argument, errmsg );
92  }
93  }
94 #endif
95 
96  // get sizes
97  int invalRank = inputFields.rank();
98  int outvalRank = outputFields.rank();
99  int numCells = outputFields.dimension(0);
100  int numFields = outputFields.dimension(1);
101  int numPoints = outputFields.dimension(2);
102  int numDataPoints = inputData.dimension(1);
103  int dim1Tens = 0;
104  int dim2Tens = 0;
105  if (outvalRank > 3) {
106  dim1Tens = outputFields.dimension(3);
107  if (outvalRank > 4) {
108  dim2Tens = outputFields.dimension(4);
109  }
110  }
111 
112  if (outvalRank == invalRank) {
113 
114  if (numDataPoints != 1) { // nonconstant data
115 
116  switch(invalRank) {
117  case 3: {
118  if (reciprocal) {
119  for(int cl = 0; cl < numCells; cl++) {
120  for(int bf = 0; bf < numFields; bf++) {
121  for(int pt = 0; pt < numPoints; pt++) {
122  outputFields(cl, bf, pt) = inputFields(cl, bf, pt)/inputData(cl, pt);
123  } // P-loop
124  } // F-loop
125  } // C-loop
126  }
127  else {
128  for(int cl = 0; cl < numCells; cl++) {
129  for(int bf = 0; bf < numFields; bf++) {
130  for(int pt = 0; pt < numPoints; pt++) {
131  outputFields(cl, bf, pt) = inputFields(cl, bf, pt)*inputData(cl, pt);
132  } // P-loop
133  } // F-loop
134  } // C-loop
135  }
136  }// case 3
137  break;
138 
139  case 4: {
140  if (reciprocal) {
141  for(int cl = 0; cl < numCells; cl++) {
142  for(int bf = 0; bf < numFields; bf++) {
143  for(int pt = 0; pt < numPoints; pt++) {
144  for( int iVec = 0; iVec < dim1Tens; iVec++) {
145  outputFields(cl, bf, pt, iVec) = inputFields(cl, bf, pt, iVec)/inputData(cl, pt);
146  } // D1-loop
147  } // P-loop
148  } // F-loop
149  } // C-loop
150  }
151  else {
152  for(int cl = 0; cl < numCells; cl++) {
153  for(int bf = 0; bf < numFields; bf++) {
154  for(int pt = 0; pt < numPoints; pt++) {
155  for( int iVec = 0; iVec < dim1Tens; iVec++) {
156  outputFields(cl, bf, pt, iVec) = inputFields(cl, bf, pt, iVec)*inputData(cl, pt);
157  } // D1-loop
158  } // P-loop
159  } // F-loop
160  } // C-loop
161  }
162  }// case 4
163  break;
164 
165  case 5: {
166  if (reciprocal) {
167  for(int cl = 0; cl < numCells; cl++) {
168  for(int bf = 0; bf < numFields; bf++) {
169  for(int pt = 0; pt < numPoints; pt++) {
170  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
171  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
172  outputFields(cl, bf, pt, iTens1, iTens2) = inputFields(cl, bf, pt, iTens1, iTens2)/inputData(cl, pt);
173  } // D2-loop
174  } // D1-loop
175  } // F-loop
176  } // P-loop
177  } // C-loop
178  }
179  else {
180  for(int cl = 0; cl < numCells; cl++) {
181  for(int bf = 0; bf < numFields; bf++) {
182  for(int pt = 0; pt < numPoints; pt++) {
183  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
184  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
185  outputFields(cl, bf, pt, iTens1, iTens2) = inputFields(cl, bf, pt, iTens1, iTens2)*inputData(cl, pt);
186  } // D2-loop
187  } // D1-loop
188  } // F-loop
189  } // P-loop
190  } // C-loop
191  }
192  }// case 5
193  break;
194 
195  default:
196  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 3) || (invalRank == 4) || (invalRank == 5) ), std::invalid_argument,
197  ">>> ERROR (ArrayTools::scalarMultiplyDataField): This branch of the method is defined only for rank-3,4 or 5 containers.");
198  }// invalRank
199 
200  }
201  else { //constant data
202 
203  switch(invalRank) {
204  case 3: {
205  if (reciprocal) {
206  for(int cl = 0; cl < numCells; cl++) {
207  for(int bf = 0; bf < numFields; bf++) {
208  for(int pt = 0; pt < numPoints; pt++) {
209  outputFields(cl, bf, pt) = inputFields(cl, bf, pt)/inputData(cl, 0);
210  } // P-loop
211  } // F-loop
212  } // C-loop
213  }
214  else {
215  for(int cl = 0; cl < numCells; cl++) {
216  for(int bf = 0; bf < numFields; bf++) {
217  for(int pt = 0; pt < numPoints; pt++) {
218  outputFields(cl, bf, pt) = inputFields(cl, bf, pt)*inputData(cl, 0);
219  } // P-loop
220  } // F-loop
221  } // C-loop
222  }
223  }// case 3
224  break;
225 
226  case 4: {
227  if (reciprocal) {
228  for(int cl = 0; cl < numCells; cl++) {
229  for(int bf = 0; bf < numFields; bf++) {
230  for(int pt = 0; pt < numPoints; pt++) {
231  for( int iVec = 0; iVec < dim1Tens; iVec++) {
232  outputFields(cl, bf, pt, iVec) = inputFields(cl, bf, pt, iVec)/inputData(cl, 0);
233  } // D1-loop
234  } // P-loop
235  } // F-loop
236  } // C-loop
237  }
238  else {
239  for(int cl = 0; cl < numCells; cl++) {
240  for(int bf = 0; bf < numFields; bf++) {
241  for(int pt = 0; pt < numPoints; pt++) {
242  for( int iVec = 0; iVec < dim1Tens; iVec++) {
243  outputFields(cl, bf, pt, iVec) = inputFields(cl, bf, pt, iVec)*inputData(cl, 0);
244  } // D1-loop
245  } // P-loop
246  } // F-loop
247  } // C-loop
248  }
249  }// case 4
250  break;
251 
252  case 5: {
253  if (reciprocal) {
254  for(int cl = 0; cl < numCells; cl++) {
255  for(int bf = 0; bf < numFields; bf++) {
256  for(int pt = 0; pt < numPoints; pt++) {
257  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
258  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
259  outputFields(cl, bf, pt, iTens1, iTens2) = inputFields(cl, bf, pt, iTens1, iTens2)/inputData(cl, 0);
260  } // D2-loop
261  } // D1-loop
262  } // F-loop
263  } // P-loop
264  } // C-loop
265  }
266  else {
267  for(int cl = 0; cl < numCells; cl++) {
268  for(int bf = 0; bf < numFields; bf++) {
269  for(int pt = 0; pt < numPoints; pt++) {
270  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
271  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
272  outputFields(cl, bf, pt, iTens1, iTens2) = inputFields(cl, bf, pt, iTens1, iTens2)*inputData(cl, 0);
273  } // D2-loop
274  } // D1-loop
275  } // F-loop
276  } // P-loop
277  } // C-loop
278  }
279  }// case 5
280  break;
281 
282  default:
283  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 3) || (invalRank == 4) || (invalRank == 5) ), std::invalid_argument,
284  ">>> ERROR (ArrayTools::scalarMultiplyDataField): This branch of the method is defined only for rank-3, 4 or 5 input containers.");
285 
286  } // invalRank
287  } // numDataPoints
288 
289  }
290  else {
291 
292  if (numDataPoints != 1) { // nonconstant data
293 
294  switch(invalRank) {
295  case 2: {
296  if (reciprocal) {
297  for(int cl = 0; cl < numCells; cl++) {
298  for(int bf = 0; bf < numFields; bf++) {
299  for(int pt = 0; pt < numPoints; pt++) {
300  outputFields(cl, bf, pt) = inputFields(bf, pt)/inputData(cl, pt);
301  } // P-loop
302  } // F-loop
303  } // C-loop
304  }
305  else {
306  for(int cl = 0; cl < numCells; cl++) {
307  for(int bf = 0; bf < numFields; bf++) {
308  for(int pt = 0; pt < numPoints; pt++) {
309  outputFields(cl, bf, pt) = inputFields(bf, pt)*inputData(cl, pt);
310  } // P-loop
311  } // F-loop
312  } // C-loop
313  }
314  }// case 2
315  break;
316 
317  case 3: {
318  if (reciprocal) {
319  for(int cl = 0; cl < numCells; cl++) {
320  for(int bf = 0; bf < numFields; bf++) {
321  for(int pt = 0; pt < numPoints; pt++) {
322  for( int iVec = 0; iVec < dim1Tens; iVec++) {
323  outputFields(cl, bf, pt, iVec) = inputFields(bf, pt, iVec)/inputData(cl, pt);
324  } // D1-loop
325  } // P-loop
326  } // F-loop
327  } // C-loop
328  }
329  else {
330  for(int cl = 0; cl < numCells; cl++) {
331  for(int bf = 0; bf < numFields; bf++) {
332  for(int pt = 0; pt < numPoints; pt++) {
333  for( int iVec = 0; iVec < dim1Tens; iVec++) {
334  outputFields(cl, bf, pt, iVec) = inputFields(bf, pt, iVec)*inputData(cl, pt);
335  } // D1-loop
336  } // P-loop
337  } // F-loop
338  } // C-loop
339  }
340  }// case 3
341  break;
342 
343  case 4: {
344  if (reciprocal) {
345  for(int cl = 0; cl < numCells; cl++) {
346  for(int bf = 0; bf < numFields; bf++) {
347  for(int pt = 0; pt < numPoints; pt++) {
348  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
349  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
350  outputFields(cl, bf, pt, iTens1, iTens2) = inputFields(bf, pt, iTens1, iTens2)/inputData(cl, pt);
351  } // D2-loop
352  } // D1-loop
353  } // F-loop
354  } // P-loop
355  } // C-loop
356  }
357  else {
358  for(int cl = 0; cl < numCells; cl++) {
359  for(int bf = 0; bf < numFields; bf++) {
360  for(int pt = 0; pt < numPoints; pt++) {
361  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
362  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
363  outputFields(cl, bf, pt, iTens1, iTens2) = inputFields(bf, pt, iTens1, iTens2)*inputData(cl, pt);
364  } // D2-loop
365  } // D1-loop
366  } // F-loop
367  } // P-loop
368  } // C-loop
369  }
370  }// case 4
371  break;
372 
373  default:
374  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 2) || (invalRank == 3) || (invalRank == 4) ), std::invalid_argument,
375  ">>> ERROR (ArrayTools::scalarMultiplyDataField): This branch of the method is defined only for rank-2, 3 or 4 input containers.");
376  }// invalRank
377 
378  }
379  else { //constant data
380 
381  switch(invalRank) {
382  case 2: {
383  if (reciprocal) {
384  for(int cl = 0; cl < numCells; cl++) {
385  for(int bf = 0; bf < numFields; bf++) {
386  for(int pt = 0; pt < numPoints; pt++) {
387  outputFields(cl, bf, pt) = inputFields(bf, pt)/inputData(cl, 0);
388  } // P-loop
389  } // F-loop
390  } // C-loop
391  }
392  else {
393  for(int cl = 0; cl < numCells; cl++) {
394  for(int bf = 0; bf < numFields; bf++) {
395  for(int pt = 0; pt < numPoints; pt++) {
396  outputFields(cl, bf, pt) = inputFields(bf, pt)*inputData(cl, 0);
397  } // P-loop
398  } // F-loop
399  } // C-loop
400  }
401  }// case 2
402  break;
403 
404  case 3: {
405  if (reciprocal) {
406  for(int cl = 0; cl < numCells; cl++) {
407  for(int bf = 0; bf < numFields; bf++) {
408  for(int pt = 0; pt < numPoints; pt++) {
409  for( int iVec = 0; iVec < dim1Tens; iVec++) {
410  outputFields(cl, bf, pt, iVec) = inputFields(bf, pt, iVec)/inputData(cl, 0);
411  } // D1-loop
412  } // P-loop
413  } // F-loop
414  } // C-loop
415  }
416  else {
417  for(int cl = 0; cl < numCells; cl++) {
418  for(int bf = 0; bf < numFields; bf++) {
419  for(int pt = 0; pt < numPoints; pt++) {
420  for( int iVec = 0; iVec < dim1Tens; iVec++) {
421  outputFields(cl, bf, pt, iVec) = inputFields(bf, pt, iVec)*inputData(cl, 0);
422  } // D1-loop
423  } // P-loop
424  } // F-loop
425  } // C-loop
426  }
427  }// case 3
428  break;
429 
430  case 4: {
431  if (reciprocal) {
432  for(int cl = 0; cl < numCells; cl++) {
433  for(int bf = 0; bf < numFields; bf++) {
434  for(int pt = 0; pt < numPoints; pt++) {
435  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
436  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
437  outputFields(cl, bf, pt, iTens1, iTens2) = inputFields(bf, pt, iTens1, iTens2)/inputData(cl, 0);
438  } // D2-loop
439  } // D1-loop
440  } // F-loop
441  } // P-loop
442  } // C-loop
443  }
444  else {
445  for(int cl = 0; cl < numCells; cl++) {
446  for(int bf = 0; bf < numFields; bf++) {
447  for(int pt = 0; pt < numPoints; pt++) {
448  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
449  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
450  outputFields(cl, bf, pt, iTens1, iTens2) = inputFields(bf, pt, iTens1, iTens2)*inputData(cl, 0);
451  } // D2-loop
452  } // D1-loop
453  } // F-loop
454  } // P-loop
455  } // C-loop
456  }
457  }// case 4
458  break;
459 
460  default:
461  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 2) || (invalRank == 3) || (invalRank == 3) ), std::invalid_argument,
462  ">>> ERROR (ArrayTools::scalarMultiplyDataField): This branch of the method is defined only for rank-2, 3 or 4 input containers.");
463 
464  } // invalRank
465  } // numDataPoints
466 
467  } // end if (outvalRank = invalRank)
468 
469 } // scalarMultiplyDataField
470 
471 
472 
473 template<class Scalar, class ArrayOutData, class ArrayInDataLeft, class ArrayInDataRight>
474 void ArrayTools::scalarMultiplyDataData(ArrayOutData & outputData,
475  ArrayInDataLeft & inputDataLeft,
476  ArrayInDataRight & inputDataRight,
477  const bool reciprocal) {
478 
479 #ifdef HAVE_INTREPID_DEBUG
480  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataLeft.rank() != 2), std::invalid_argument,
481  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Left input data container must have rank 2.");
482  if (outputData.rank() <= inputDataRight.rank()) {
483  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.rank() < 2) || (inputDataRight.rank() > 4) ), std::invalid_argument,
484  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input data container must have rank 2, 3, or 4.");
485  TEUCHOS_TEST_FOR_EXCEPTION( (outputData.rank() != inputDataRight.rank()), std::invalid_argument,
486  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input and output data containers must have the same rank.");
487  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(0) != inputDataLeft.dimension(0) ), std::invalid_argument,
488  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimensions (number of integration domains) of the left and right data input containers must agree!");
489  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.dimension(1) != inputDataLeft.dimension(1)) && (inputDataLeft.dimension(1) != 1) ), std::invalid_argument,
490  ">>> ERROR (ArrayTools::scalarMultiplyDataData): First dimensions of the left and right data input containers (number of integration points) must agree or first dimension of the left data input container must be 1!");
491  for (int i=0; i<inputDataRight.rank(); i++) {
492  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataData): Dimension ";
493  errmsg += (char)(48+i);
494  errmsg += " of the right input and output data containers must agree!";
495  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(i) != outputData.dimension(i)), std::invalid_argument, errmsg );
496  }
497  }
498  else {
499  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.rank() < 1) || (inputDataRight.rank() > 3) ), std::invalid_argument,
500  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input data container must have rank 1, 2, or 3.");
501  TEUCHOS_TEST_FOR_EXCEPTION( (outputData.rank() != inputDataRight.rank()+1), std::invalid_argument,
502  ">>> ERROR (ArrayTools::scalarMultiplyDataData): The rank of the right input data container must be one less than the rank of the output data container.");
503  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.dimension(0) != inputDataLeft.dimension(1)) && (inputDataLeft.dimension(1) != 1) ), std::invalid_argument,
504  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimension of the right input data container and first dimension of the left data input container (number of integration points) must agree or first dimension of the left data input container must be 1!");
505  TEUCHOS_TEST_FOR_EXCEPTION( ( inputDataLeft.dimension(0) != outputData.dimension(0) ), std::invalid_argument,
506  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimensions of data output and left data input containers (number of integration domains) must agree!");
507  for (int i=0; i<inputDataRight.rank(); i++) {
508  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataData): Dimensions ";
509  errmsg += (char)(48+i);
510  errmsg += " and ";
511  errmsg += (char)(48+i+1);
512  errmsg += " of the right input and output data containers must agree!";
513  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(i) != outputData.dimension(i+1)), std::invalid_argument, errmsg );
514  }
515  }
516 #endif
517 
518  // get sizes
519  int invalRank = inputDataRight.rank();
520  int outvalRank = outputData.rank();
521  int numCells = outputData.dimension(0);
522  int numPoints = outputData.dimension(1);
523  int numDataPoints = inputDataLeft.dimension(1);
524  int dim1Tens = 0;
525  int dim2Tens = 0;
526  if (outvalRank > 2) {
527  dim1Tens = outputData.dimension(2);
528  if (outvalRank > 3) {
529  dim2Tens = outputData.dimension(3);
530  }
531  }
532 
533  if (outvalRank == invalRank) {
534 
535  if (numDataPoints != 1) { // nonconstant data
536 
537  switch(invalRank) {
538  case 2: {
539  if (reciprocal) {
540  for(int cl = 0; cl < numCells; cl++) {
541  for(int pt = 0; pt < numPoints; pt++) {
542  outputData(cl, pt) = inputDataRight(cl, pt)/inputDataLeft(cl, pt);
543  } // P-loop
544  } // C-loop
545  }
546  else {
547  for(int cl = 0; cl < numCells; cl++) {
548  for(int pt = 0; pt < numPoints; pt++) {
549  outputData(cl, pt) = inputDataRight(cl, pt)*inputDataLeft(cl, pt);
550  } // P-loop
551  } // C-loop
552  }
553  }// case 2
554  break;
555 
556  case 3: {
557  if (reciprocal) {
558  for(int cl = 0; cl < numCells; cl++) {
559  for(int pt = 0; pt < numPoints; pt++) {
560  for( int iVec = 0; iVec < dim1Tens; iVec++) {
561  outputData(cl, pt, iVec) = inputDataRight(cl, pt, iVec)/inputDataLeft(cl, pt);
562  } // D1-loop
563  } // P-loop
564  } // C-loop
565  }
566  else {
567  for(int cl = 0; cl < numCells; cl++) {
568  for(int pt = 0; pt < numPoints; pt++) {
569  for( int iVec = 0; iVec < dim1Tens; iVec++) {
570  outputData(cl, pt, iVec) = inputDataRight(cl, pt, iVec)*inputDataLeft(cl, pt);
571  } // D1-loop
572  } // P-loop
573  } // C-loop
574  }
575  }// case 3
576  break;
577 
578  case 4: {
579  if (reciprocal) {
580  for(int cl = 0; cl < numCells; cl++) {
581  for(int pt = 0; pt < numPoints; pt++) {
582  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
583  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
584  outputData(cl, pt, iTens1, iTens2) = inputDataRight(cl, pt, iTens1, iTens2)/inputDataLeft(cl, pt);
585  } // D2-loop
586  } // D1-loop
587  } // P-loop
588  } // C-loop
589  }
590  else {
591  for(int cl = 0; cl < numCells; cl++) {
592  for(int pt = 0; pt < numPoints; pt++) {
593  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
594  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
595  outputData(cl, pt, iTens1, iTens2) = inputDataRight(cl, pt, iTens1, iTens2)*inputDataLeft(cl, pt);
596  } // D2-loop
597  } // D1-loop
598  } // P-loop
599  } // C-loop
600  }
601  }// case 4
602  break;
603 
604  default:
605  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 2) || (invalRank == 3) || (invalRank == 4) ), std::invalid_argument,
606  ">>> ERROR (ArrayTools::scalarMultiplyDataData): This branch of the method is defined only for rank-2, 3 or 4 containers.");
607  }// invalRank
608 
609  }
610  else { // constant left data
611 
612  switch(invalRank) {
613  case 2: {
614  if (reciprocal) {
615  for(int cl = 0; cl < numCells; cl++) {
616  for(int pt = 0; pt < numPoints; pt++) {
617  outputData(cl, pt) = inputDataRight(cl, pt)/inputDataLeft(cl, 0);
618  } // P-loop
619  } // C-loop
620  }
621  else {
622  for(int cl = 0; cl < numCells; cl++) {
623  for(int pt = 0; pt < numPoints; pt++) {
624  outputData(cl, pt) = inputDataRight(cl, pt)*inputDataLeft(cl, 0);
625  } // P-loop
626  } // C-loop
627  }
628  }// case 2
629  break;
630 
631  case 3: {
632  if (reciprocal) {
633  for(int cl = 0; cl < numCells; cl++) {
634  for(int pt = 0; pt < numPoints; pt++) {
635  for( int iVec = 0; iVec < dim1Tens; iVec++) {
636  outputData(cl, pt, iVec) = inputDataRight(cl, pt, iVec)/inputDataLeft(cl, 0);
637  } // D1-loop
638  } // P-loop
639  } // C-loop
640  }
641  else {
642  for(int cl = 0; cl < numCells; cl++) {
643  for(int pt = 0; pt < numPoints; pt++) {
644  for( int iVec = 0; iVec < dim1Tens; iVec++) {
645  outputData(cl, pt, iVec) = inputDataRight(cl, pt, iVec)*inputDataLeft(cl, 0);
646  } // D1-loop
647  } // P-loop
648  } // C-loop
649  }
650  }// case 3
651  break;
652 
653  case 4: {
654  if (reciprocal) {
655  for(int cl = 0; cl < numCells; cl++) {
656  for(int pt = 0; pt < numPoints; pt++) {
657  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
658  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
659  outputData(cl, pt, iTens1, iTens2) = inputDataRight(cl, pt, iTens1, iTens2)/inputDataLeft(cl, 0);
660  } // D2-loop
661  } // D1-loop
662  } // P-loop
663  } // C-loop
664  }
665  else {
666  for(int cl = 0; cl < numCells; cl++) {
667  for(int pt = 0; pt < numPoints; pt++) {
668  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
669  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
670  outputData(cl, pt, iTens1, iTens2) = inputDataRight(cl, pt, iTens1, iTens2)*inputDataLeft(cl, 0);
671  } // D2-loop
672  } // D1-loop
673  } // P-loop
674  } // C-loop
675  }
676  }// case 4
677  break;
678 
679  default:
680  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 2) || (invalRank == 3) || (invalRank == 4) ), std::invalid_argument,
681  ">>> ERROR (ArrayTools::scalarMultiplyDataData): This branch of the method is defined only for rank-2, 3 or 4 input containers.");
682 
683  } // invalRank
684  } // numDataPoints
685 
686  }
687  else {
688 
689  if (numDataPoints != 1) { // nonconstant data
690 
691  switch(invalRank) {
692  case 1: {
693  if (reciprocal) {
694  for(int cl = 0; cl < numCells; cl++) {
695  for(int pt = 0; pt < numPoints; pt++) {
696  outputData(cl, pt) = inputDataRight(pt)/inputDataLeft(cl, pt);
697  } // P-loop
698  } // C-loop
699  }
700  else {
701  for(int cl = 0; cl < numCells; cl++) {
702  for(int pt = 0; pt < numPoints; pt++) {
703  outputData(cl, pt) = inputDataRight(pt)*inputDataLeft(cl, pt);
704  } // P-loop
705  } // C-loop
706  }
707  }// case 1
708  break;
709 
710  case 2: {
711  if (reciprocal) {
712  for(int cl = 0; cl < numCells; cl++) {
713  for(int pt = 0; pt < numPoints; pt++) {
714  for( int iVec = 0; iVec < dim1Tens; iVec++) {
715  outputData(cl, pt, iVec) = inputDataRight(pt, iVec)/inputDataLeft(cl, pt);
716  } // D1-loop
717  } // P-loop
718  } // C-loop
719  }
720  else {
721  for(int cl = 0; cl < numCells; cl++) {
722  for(int pt = 0; pt < numPoints; pt++) {
723  for( int iVec = 0; iVec < dim1Tens; iVec++) {
724  outputData(cl, pt, iVec) = inputDataRight(pt, iVec)*inputDataLeft(cl, pt);
725  } // D1-loop
726  } // P-loop
727  } // C-loop
728  }
729  }// case 2
730  break;
731 
732  case 3: {
733  if (reciprocal) {
734  for(int cl = 0; cl < numCells; cl++) {
735  for(int pt = 0; pt < numPoints; pt++) {
736  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
737  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
738  outputData(cl, pt, iTens1, iTens2) = inputDataRight(pt, iTens1, iTens2)/inputDataLeft(cl, pt);
739  } // D2-loop
740  } // D1-loop
741  } // P-loop
742  } // C-loop
743  }
744  else {
745  for(int cl = 0; cl < numCells; cl++) {
746  for(int pt = 0; pt < numPoints; pt++) {
747  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
748  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
749  outputData(cl, pt, iTens1, iTens2) = inputDataRight(pt, iTens1, iTens2)*inputDataLeft(cl, pt);
750  } // D2-loop
751  } // D1-loop
752  } // P-loop
753  } // C-loop
754  }
755  }// case 3
756  break;
757 
758  default:
759  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 1) || (invalRank == 2) || (invalRank == 3) ), std::invalid_argument,
760  ">>> ERROR (ArrayTools::scalarMultiplyDataData): This branch of the method is defined only for rank-1, 2 or 3 input containers.");
761  }// invalRank
762 
763  }
764  else { //constant data
765 
766  switch(invalRank) {
767  case 1: {
768  if (reciprocal) {
769  for(int cl = 0; cl < numCells; cl++) {
770  for(int pt = 0; pt < numPoints; pt++) {
771  outputData(cl, pt) = inputDataRight(pt)/inputDataLeft(cl, 0);
772  } // P-loop
773  } // C-loop
774  }
775  else {
776  for(int cl = 0; cl < numCells; cl++) {
777  for(int pt = 0; pt < numPoints; pt++) {
778  outputData(cl, pt) = inputDataRight(pt)*inputDataLeft(cl, 0);
779  } // P-loop
780  } // C-loop
781  }
782  }// case 1
783  break;
784 
785  case 2: {
786  if (reciprocal) {
787  for(int cl = 0; cl < numCells; cl++) {
788  for(int pt = 0; pt < numPoints; pt++) {
789  for( int iVec = 0; iVec < dim1Tens; iVec++) {
790  outputData(cl, pt, iVec) = inputDataRight(pt, iVec)/inputDataLeft(cl, 0);
791  } // D1-loop
792  } // P-loop
793  } // C-loop
794  }
795  else {
796  for(int cl = 0; cl < numCells; cl++) {
797  for(int pt = 0; pt < numPoints; pt++) {
798  for( int iVec = 0; iVec < dim1Tens; iVec++) {
799  outputData(cl, pt, iVec) = inputDataRight(pt, iVec)*inputDataLeft(cl, 0);
800  } // D1-loop
801  } // P-loop
802  } // C-loop
803  }
804  }// case 2
805  break;
806 
807  case 3: {
808  if (reciprocal) {
809  for(int cl = 0; cl < numCells; cl++) {
810  for(int pt = 0; pt < numPoints; pt++) {
811  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
812  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
813  outputData(cl, pt, iTens1, iTens2) = inputDataRight(pt, iTens1, iTens2)/inputDataLeft(cl, 0);
814  } // D2-loop
815  } // D1-loop
816  } // P-loop
817  } // C-loop
818  }
819  else {
820  for(int cl = 0; cl < numCells; cl++) {
821  for(int pt = 0; pt < numPoints; pt++) {
822  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
823  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
824  outputData(cl, pt, iTens1, iTens2) = inputDataRight(pt, iTens1, iTens2)*inputDataLeft(cl, 0);
825  } // D2-loop
826  } // D1-loop
827  } // P-loop
828  } // C-loop
829  }
830  }// case 3
831  break;
832 
833  default:
834  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 1) || (invalRank == 2) || (invalRank == 3) ), std::invalid_argument,
835  ">>> ERROR (ArrayTools::scalarMultiplyDataData): This branch of the method is defined only for rank-1, 2 or 3 input containers.");
836 
837  } // invalRank
838  } // numDataPoints
839 
840  } // end if (outvalRank = invalRank)
841 
842 } // scalarMultiplyDataData
843 
844 } // end namespace Intrepid
static void scalarMultiplyDataData(ArrayOutData &outputData, ArrayInDataLeft &inputDataLeft, ArrayInDataRight &inputDataRight, const bool reciprocal=false)
There are two use cases: (1) multiplies a rank-2, 3, or 4 container inputDataRight with dimensions (C...
static void scalarMultiplyDataField(ArrayOutFields &outputFields, const ArrayInData &inputData, ArrayInFields &inputFields, const bool reciprocal=false)
There are two use cases: (1) multiplies a rank-3, 4, or 5 container inputFields with dimensions (C...