Intrepid
Intrepid_ArrayToolsDefCloneScale.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  template<class Scalar, class ArrayOutFields, class ArrayInFields>
51 void ArrayTools::cloneFields(ArrayOutFields & outputFields,
52  const ArrayInFields & inputFields) {
53 
54 #ifdef HAVE_INTREPID_DEBUG
55  TEUCHOS_TEST_FOR_EXCEPTION( ( (getrank(inputFields) < 2) || (getrank(inputFields) > 4) ), std::invalid_argument,
56  ">>> ERROR (ArrayTools::cloneFields): Input fields container must have rank 2, 3, or 4.");
57  TEUCHOS_TEST_FOR_EXCEPTION( (getrank(outputFields) != getrank(inputFields)+1), std::invalid_argument,
58  ">>> ERROR (ArrayTools::cloneFields): The rank of the input fields container must be one less than the rank of the output fields container.");
59  for (size_t i=0; i<getrank(inputFields); i++) {
60  std::string errmsg = ">>> ERROR (ArrayTools::cloneFields): Dimensions ";
61  errmsg += (char)(48+i);
62  errmsg += " and ";
63  errmsg += (char)(48+i+1);
64  errmsg += " of the input and output fields containers must agree!";
65  TEUCHOS_TEST_FOR_EXCEPTION( (inputFields.dimension(i) != outputFields.dimension(i+1)), std::invalid_argument, errmsg );
66  }
67 #endif
68  ArrayWrapper<Scalar,ArrayOutFields, Rank<ArrayOutFields >::value,false>outputFieldsWrap(outputFields);
70 
71 
72  // get sizes
73  size_t invalRank = getrank(inputFields);
74  size_t outvalRank = getrank(outputFields);
75  int numCells = outputFields.dimension(0);
76  int numFields = outputFields.dimension(1);
77  int numPoints = outputFields.dimension(2);
78  int dim1Tens = 0;
79  int dim2Tens = 0;
80  if (outvalRank > 3) {
81  dim1Tens = outputFields.dimension(3);
82  if (outvalRank > 4) {
83  dim2Tens = outputFields.dimension(4);
84  }
85  }
86 
87  switch(invalRank) {
88  case 2: {
89  for(int cl = 0; cl < numCells; cl++) {
90  for(int bf = 0; bf < numFields; bf++) {
91  for(int pt = 0; pt < numPoints; pt++) {
92  outputFieldsWrap(cl, bf, pt) = inputFieldswrap(bf, pt);
93  } // P-loop
94  } // F-loop
95  } // C-loop
96  }// case 2
97  break;
98 
99  case 3: {
100  for(int cl = 0; cl < numCells; cl++) {
101  for(int bf = 0; bf < numFields; bf++) {
102  for(int pt = 0; pt < numPoints; pt++) {
103  for( int iVec = 0; iVec < dim1Tens; iVec++) {
104  outputFieldsWrap(cl, bf, pt, iVec) = inputFieldswrap(bf, pt, iVec);
105  } // D1-loop
106  } // P-loop
107  } // F-loop
108  } // C-loop
109  }// case 3
110  break;
111 
112  case 4: {
113  for(int cl = 0; cl < numCells; cl++) {
114  for(int bf = 0; bf < numFields; bf++) {
115  for(int pt = 0; pt < numPoints; pt++) {
116  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
117  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
118  outputFieldsWrap(cl, bf, pt, iTens1, iTens2) = inputFieldswrap(bf, pt, iTens1, iTens2);
119  } // D2-loop
120  } // D1-loop
121  } // P-loop
122  } // F-loop
123  } // C-loop
124  }// case 4
125  break;
126 
127  default:
128  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 2) || (invalRank == 3) || (invalRank == 4) ), std::invalid_argument,
129  ">>> ERROR (ArrayTools::cloneFields): This method is defined only for rank-2, 3 or 4 input containers.");
130  }// invalRank
131 
132 } // cloneFields
133 
134 
135 template<class Scalar, class ArrayOutFields, class ArrayInFactors, class ArrayInFields>
136 void ArrayTools::cloneScaleFields(ArrayOutFields & outputFields,
137  const ArrayInFactors & inputFactors,
138  const ArrayInFields & inputFields) {
139 
140 #ifdef HAVE_INTREPID_DEBUG
141  TEUCHOS_TEST_FOR_EXCEPTION( (getrank(inputFactors) != 2), std::invalid_argument,
142  ">>> ERROR (ArrayTools::cloneScaleFields): The rank of the input factors container must be 2.");
143  TEUCHOS_TEST_FOR_EXCEPTION( ( (getrank(inputFields) < 2) || (getrank(inputFields) > 4) ), std::invalid_argument,
144  ">>> ERROR (ArrayTools::cloneScaleFields): Input fields container must have rank 2, 3, or 4.");
145  TEUCHOS_TEST_FOR_EXCEPTION( (getrank(outputFields) != getrank(inputFields)+1), std::invalid_argument,
146  ">>> ERROR (ArrayTools::cloneScaleFields): The rank of the input fields container must be one less than the rank of the output fields container.");
147  TEUCHOS_TEST_FOR_EXCEPTION( ( inputFactors.dimension(0) != outputFields.dimension(0) ), std::invalid_argument,
148  ">>> ERROR (ArrayTools::cloneScaleFields): Zeroth dimensions of input factors container and output fields container (numbers of integration domains) must agree!");
149  TEUCHOS_TEST_FOR_EXCEPTION( ( inputFactors.dimension(1) != outputFields.dimension(1) ), std::invalid_argument,
150  ">>> ERROR (ArrayTools::cloneScaleFields): First dimensions of input factors container and output fields container (numbers of fields) must agree!");
151  for (size_t i=0; i<getrank(inputFields); i++) {
152  std::string errmsg = ">>> ERROR (ArrayTools::cloneScaleFields): Dimensions ";
153  errmsg += (char)(48+i);
154  errmsg += " and ";
155  errmsg += (char)(48+i+1);
156  errmsg += " of the input and output fields containers must agree!";
157  TEUCHOS_TEST_FOR_EXCEPTION( (inputFields.dimension(i) != outputFields.dimension(i+1)), std::invalid_argument, errmsg );
158  }
159 #endif
160  ArrayWrapper<Scalar,ArrayOutFields, Rank<ArrayOutFields >::value,false>outputFieldsWrap(outputFields);
161  ArrayWrapper<Scalar,ArrayInFactors, Rank<ArrayInFactors >::value,true>inputFactorswrap(inputFactors);
162  ArrayWrapper<Scalar,ArrayInFields, Rank<ArrayInFields >::value,true>inputFieldsWrap(inputFields);
163 
164  // get sizes
165  size_t invalRank = getrank(inputFields);
166  size_t outvalRank = getrank(outputFields);
167  int numCells = outputFields.dimension(0);
168  int numFields = outputFields.dimension(1);
169  int numPoints = outputFields.dimension(2);
170  int dim1Tens = 0;
171  int dim2Tens = 0;
172  if (outvalRank > 3) {
173  dim1Tens = outputFields.dimension(3);
174  if (outvalRank > 4) {
175  dim2Tens = outputFields.dimension(4);
176  }
177  }
178 
179  switch(invalRank) {
180  case 2: {
181  for(int cl = 0; cl < numCells; cl++) {
182  for(int bf = 0; bf < numFields; bf++) {
183  for(int pt = 0; pt < numPoints; pt++) {
184  outputFieldsWrap(cl, bf, pt) = inputFieldsWrap(bf, pt) * inputFactorswrap(cl, bf);
185  } // P-loop
186  } // F-loop
187  } // C-loop
188  }// case 2
189  break;
190 
191  case 3: {
192  for(int cl = 0; cl < numCells; cl++) {
193  for(int bf = 0; bf < numFields; bf++) {
194  for(int pt = 0; pt < numPoints; pt++) {
195  for( int iVec = 0; iVec < dim1Tens; iVec++) {
196  outputFieldsWrap(cl, bf, pt, iVec) = inputFieldsWrap(bf, pt, iVec) * inputFactorswrap(cl, bf);
197  } // D1-loop
198  } // P-loop
199  } // F-loop
200  } // C-loop
201  }// case 3
202  break;
203 
204  case 4: {
205  for(int cl = 0; cl < numCells; cl++) {
206  for(int bf = 0; bf < numFields; bf++) {
207  for(int pt = 0; pt < numPoints; pt++) {
208  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
209  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
210  outputFieldsWrap(cl, bf, pt, iTens1, iTens2) = inputFieldsWrap(bf, pt, iTens1, iTens2) * inputFactorswrap(cl, bf);
211  } // D2-loop
212  } // D1-loop
213  } // P-loop
214  } // F-loop
215  } // C-loop
216  }// case 4
217  break;
218 
219  default:
220  TEUCHOS_TEST_FOR_EXCEPTION( !( (invalRank == 2) || (invalRank == 3) || (invalRank == 4) ), std::invalid_argument,
221  ">>> ERROR (ArrayTools::cloneScaleFields): This method is defined only for rank-2, 3 or 4 input containers.");
222  }// invalRank
223 
224 } // cloneScaleFields
225 
226 
227 template<class Scalar, class ArrayInOutFields, class ArrayInFactors>
228 void ArrayTools::scaleFields(ArrayInOutFields & inoutFields,
229  const ArrayInFactors & inputFactors) {
230 
231 #ifdef HAVE_INTREPID_DEBUG
232  TEUCHOS_TEST_FOR_EXCEPTION( (getrank(inputFactors) != 2), std::invalid_argument,
233  ">>> ERROR (ArrayTools::scaleFields): The rank of the input factors container must be 2.");
234  TEUCHOS_TEST_FOR_EXCEPTION( ( (getrank(inoutFields) < 3) || (getrank(inoutFields) > 5) ), std::invalid_argument,
235  ">>> ERROR (ArrayTools::scaleFields): Input/output fields container must have rank 3, 4, or 5.");
236  TEUCHOS_TEST_FOR_EXCEPTION( ( inputFactors.dimension(0) != inoutFields.dimension(0) ), std::invalid_argument,
237  ">>> ERROR (ArrayTools::scaleFields): Zeroth dimensions of input factors container and input/output fields container (numbers of integration domains) must agree!");
238  TEUCHOS_TEST_FOR_EXCEPTION( ( inputFactors.dimension(1) != inoutFields.dimension(1) ), std::invalid_argument,
239  ">>> ERROR (ArrayTools::scaleFields): First dimensions (number of fields) of input factors and input/output fields containers must agree!");
240 #endif
242  ArrayWrapper<Scalar,ArrayInFactors, Rank<ArrayInFactors >::value,true>inputFactorsWrap(inputFactors);
243  // get sizes
244  size_t inoutRank = getrank(inoutFields);
245  int numCells = inoutFields.dimension(0);
246  int numFields = inoutFields.dimension(1);
247  int numPoints = inoutFields.dimension(2);
248  int dim1Tens = 0;
249  int dim2Tens = 0;
250  if (inoutRank > 3) {
251  dim1Tens = inoutFields.dimension(3);
252  if (inoutRank > 4) {
253  dim2Tens = inoutFields.dimension(4);
254  }
255  }
256 
257  switch(inoutRank) {
258  case 3: {
259  for(int cl = 0; cl < numCells; cl++) {
260  for(int bf = 0; bf < numFields; bf++) {
261  for(int pt = 0; pt < numPoints; pt++) {
262  inoutFieldsWrap(cl, bf, pt) = inoutFieldsWrap(cl, bf, pt) * inputFactorsWrap(cl, bf);
263  } // P-loop
264  } // F-loop
265  } // C-loop
266  }// case 2
267  break;
268 
269  case 4: {
270  for(int cl = 0; cl < numCells; cl++) {
271  for(int bf = 0; bf < numFields; bf++) {
272  for(int pt = 0; pt < numPoints; pt++) {
273  for( int iVec = 0; iVec < dim1Tens; iVec++) {
274  inoutFieldsWrap(cl, bf, pt, iVec) = inoutFieldsWrap(cl, bf, pt, iVec) * inputFactorsWrap(cl, bf);
275  } // D1-loop
276  }// P-loop
277  } // F-loop
278  } // C-loop
279  }// case 3
280  break;
281 
282  case 5: {
283  for(int cl = 0; cl < numCells; cl++) {
284  for(int bf = 0; bf < numFields; bf++) {
285  for(int pt = 0; pt < numPoints; pt++) {
286  for( int iTens1 = 0; iTens1 < dim1Tens; iTens1++) {
287  for( int iTens2 = 0; iTens2 < dim2Tens; iTens2++) {
288  inoutFieldsWrap(cl, bf, pt, iTens1, iTens2) = inoutFieldsWrap(cl, bf, pt, iTens1, iTens2) * inputFactorsWrap(cl, bf);
289  } // D2-loop
290  } // D1-loop
291  } // P-loop
292  } // F-loop
293  } // C-loop
294  }// case 4
295  break;
296 
297  default:
298  TEUCHOS_TEST_FOR_EXCEPTION( !( (inoutRank == 3) || (inoutRank == 4) || (inoutRank == 5) ), std::invalid_argument,
299  ">>> ERROR (ArrayTools::cloneScaleFields): This method is defined only for rank-3, 4 or 5 input/output containers.");
300  }// inoutRank
301 
302 } // scaleFields
303 
304 
305 } // end namespace Intrepid
306 
307 #if defined(Intrepid_SHOW_DEPRECATED_WARNINGS)
308 #ifdef __GNUC__
309 #warning "The Intrepid package is deprecated"
310 #endif
311 #endif
312 
static void cloneScaleFields(ArrayOutFields &outputFields, const ArrayInFactors &inputFactors, const ArrayInFields &inputFields)
Multiplies a rank-2, 3, or 4 container with dimensions (F,P), (F,P,D1) or (F,P,D1,D2), representing the values of a scalar, vector or a tensor field, F-componentwise with a scalar container indexed by (C,F), and stores the result in an output value container of size (C,F,P), (C,F,P,D1) or (C,F,P,D1,D2).
static void cloneFields(ArrayOutFields &outputFields, const ArrayInFields &inputFields)
Replicates a rank-2, 3, or 4 container with dimensions (F,P), (F,P,D1) or (F,P,D1,D2), representing the values of a scalar, vector or a tensor field, into an output value container of size (C,F,P), (C,F,P,D1) or (C,F,P,D1,D2).
static void scaleFields(ArrayInOutFields &inoutFields, const ArrayInFactors &inputFactors)
Multiplies, in place, a rank-2, 3, or 4 container with dimensions (C,F,P), (C,F,P,D1) or (C,F,P,D1,D2), representing the values of a scalar, vector or a tensor field, F-componentwise with a scalar container indexed by (C,F).