50 #include "Teuchos_Time.hpp"
51 #include "Teuchos_GlobalMPISession.hpp"
54 using namespace Intrepid;
56 int main(
int argc,
char *argv[]) {
58 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
61 <<
"===============================================================================\n" \
63 <<
"| Example use of the FieldContainer class |\n" \
65 <<
"| 1) Creating and filling FieldContainer objects |\n" \
66 <<
"| 2) Accessing elements in FieldContainer objects |\n" \
68 <<
"| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
69 <<
"| Denis Ridzal (dridzal@sandia.gov). |\n" \
71 <<
"| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
72 <<
"| Trilinos website: http://trilinos.sandia.gov |\n" \
74 <<
"===============================================================================\n\n";
77 Teuchos::Array<int> dimension;
78 Teuchos::Array<int> multiIndex;
81 <<
"===============================================================================\n"\
82 <<
"| EXAMPLE 1: rank 2 multi-index: {u(p,i) | 0 <= p < 5; 0 <= i < 3 } |\n"\
83 <<
"===============================================================================\n\n";
99 for(
int p = 0; p < dimension[0]; p++){
102 for(
int i = 0; i < dimension[1]; i++){
106 myContainer.setValue((
double)(i+p), multiIndex);
111 std::cout << myContainer;
116 int enumeration = myContainer.getEnumeration(multiIndex);
118 std::cout <<
"Access by (): myContainer(" << 3 <<
"," << 1 <<
") = " << myContainer(3,1) <<
"\n";
119 std::cout <<
"Access by multi-index: myContainer{" << multiIndex[0] << multiIndex[1] <<
"} = "<< myContainer.getValue(multiIndex) <<
"\n";
120 std::cout <<
"Access by enumeration: myContainer[" << enumeration <<
"] = " << myContainer[enumeration] <<
"\n";
122 std::cout <<
"Assigning value by (): \n old value at (3,1) = " << myContainer(3,1) <<
"\n";
123 myContainer(3,1) = 999.99;
124 std::cout <<
" new value at (3,1) = " << myContainer(3,1) <<
"\n";
128 <<
"===============================================================================\n"\
129 <<
"| EXAMPLE 2: rank 3 multi-index: {u(p,i,j) | 0 <=p< 5; 0 <= i<2, 0<=j<3 |\n"\
130 <<
"===============================================================================\n\n";
136 multiIndex.resize(3);
144 myContainer.resize(dimension);
147 for(
int p = 0; p < dimension[0]; p++){
149 for(
int i = 0; i < dimension[1]; i++){
151 for(
int j = 0; j < dimension[2]; j++){
155 myContainer.setValue((
double)(p+i+j), multiIndex);
161 std::cout << myContainer;
167 enumeration = myContainer.getEnumeration(multiIndex);
169 std::cout <<
"Access by (): myContainer(" << 3 <<
"," << 1 <<
"," << 2 <<
") = " << myContainer(3,1,2) <<
"\n";
170 std::cout <<
"Access by multi-index: myContainer{" << multiIndex[0] << multiIndex[1] << multiIndex[2] <<
"} = "<< myContainer.getValue(multiIndex) <<
"\n";
171 std::cout <<
"Access by enumeration: myContainer[" << enumeration <<
"] = " << myContainer[enumeration] <<
"\n";
173 std::cout <<
"Assigning value by (): \n old value at (3,1,2) = " << myContainer(3,1,2) <<
"\n";
174 myContainer(3,1,2) = -999.999;
175 std::cout <<
" new value at (3,1,2) = " << myContainer(3,1,2) <<
"\n";
179 <<
"===============================================================================\n"\
180 <<
"| EXAMPLE 4: making rank-5 FieldContainer from data array and index range array |\n"\
181 <<
"===============================================================================\n\n";
191 Teuchos::Array<double> dataTeuchosArray(5*2*3*4*6);
195 for(
int i=0; i < dimension[0]; i++){
196 for(
int j=0; j < dimension[1]; j++){
197 for(
int k=0; k < dimension[2]; k++){
198 for(
int l = 0; l < dimension[3]; l++){
199 for(
int m = 0; m < dimension[4]; m++){
200 dataTeuchosArray[counter] = (double)counter;
210 std::cout << myNewContainer;
213 multiIndex.resize(myNewContainer.rank());
219 enumeration = myNewContainer.getEnumeration(multiIndex);
221 std::cout <<
"Access by (): myNewContainer(" << 3 <<
"," << 1 <<
"," << 2 <<
"," << 2 <<
"," << 5 <<
") = " << myNewContainer(3,1,2,2,5) <<
"\n";
222 std::cout <<
"Access by multi-index: myNewContainer{" << multiIndex[0] << multiIndex[1] << multiIndex[2] << multiIndex[3] << multiIndex[4] <<
"} = "<< myNewContainer.getValue(multiIndex) <<
"\n";
223 std::cout <<
"Access by enumeration: myNewContainer[" << enumeration <<
"] = " << myNewContainer[enumeration] <<
"\n";
225 std::cout <<
"Assigning value by (): \n old value at (3,1,2,2,5) = " << myNewContainer(3,1,2,2,5) <<
"\n";
226 myNewContainer(3,1,2,2,5) = -888.888;
227 std::cout <<
" new value at (3,1,2,2,5) = " << myNewContainer(3,1,2,2,5) <<
"\n";
231 <<
"===============================================================================\n"\
232 <<
"| EXAMPLE 5: making trivial FieldContainers and storing a single zero |\n"\
233 <<
"===============================================================================\n\n";
238 myContainer.resize(dimension);
239 std::cout << myContainer;
242 myNewContainer.clear();
243 std::cout << myNewContainer;
246 myNewContainer.initialize();
247 std::cout << myNewContainer;
251 <<
"===============================================================================\n"\
252 <<
"| EXAMPLE 6: Timing read and write operations using () and getValue |\n"\
253 <<
"===============================================================================\n\n";
263 multiIndex.resize(myTensorContainer.rank());
266 Teuchos::Time timerGetValue(
"Reading and writing from rank-5 container using getValue");
267 timerGetValue.start();
268 for(
int i0 = 0; i0 < dim0; i0++){
270 for(
int i1 = 0; i1 < dim1; i1++){
272 for(
int i2 = 0; i2 < dim2; i2++) {
274 for(
int i3 = 0; i3 < dim3; i3++) {
276 for(
int i4 =0; i4 < dim4; i4++) {
280 myTensorContainer.getValue(multiIndex);
281 myTensorContainer.setValue(999.999,multiIndex);
288 timerGetValue.stop();
289 std::cout <<
" Time to read and write from container using getValue: " << timerGetValue.totalElapsedTime() <<
"\n";
291 Teuchos::Time timerRound(
"Reading and writing from rank-5 container using ()");
293 for(
int i0 = 0; i0 < dim0; i0++){
294 for(
int i1 = 0; i1 < dim1; i1++) {
295 for(
int i2 = 0; i2 < dim2; i2++) {
296 for(
int i3 = 0; i3 < dim3; i3++) {
297 for(
int i4 =0; i4 < dim4; i4++) {
300 myTensorContainer(i0,i1,i2,i3,i4) = 999.999;
308 std::cout <<
" Time to read and write from container using (): " << timerRound.totalElapsedTime() <<
"\n";
311 <<
"===============================================================================\n"\
312 <<
"| EXAMPLE 6: Specialized methods of FieldContainer |\n"\
313 <<
"===============================================================================\n\n";
Header file for utility class to provide multidimensional containers.