00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00035 #include "Intrepid_FieldContainer.hpp"
00036 #include "Teuchos_GlobalMPISession.hpp"
00037
00038 using namespace std;
00039 using namespace Intrepid;
00040
00041 int main(int argc, char *argv[]) {
00042
00043 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00044
00045 cout \
00046 << "===============================================================================\n" \
00047 << "| |\n" \
00048 << "| Example use of the FieldContainer class |\n" \
00049 << "| |\n" \
00050 << "| 1) using FieldContainer in DEBUG mode: |\n" \
00051 << "| requires intrepid to be configured with --enable-intrepid-debug |\n" \
00052 << "| See /test/FieldContainer/test_02.cpp for more examples |\n" \
00053 << "| |\n" \
00054 << "| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
00055 << "| Denis Ridzal (dridzal@sandia.gov). |\n" \
00056 << "| |\n" \
00057 << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
00058 << "| Trilinos website: http://trilinos.sandia.gov |\n" \
00059 << "| |\n" \
00060 << "===============================================================================\n\n";
00061
00062
00063 Teuchos::Array<int> dimensions;
00064 Teuchos::Array<int> multiIndex;
00065
00066
00067 dimensions.resize(4);
00068 dimensions[0] = 5;
00069 dimensions[1] = 3;
00070 dimensions[2] = 2;
00071 dimensions[3] = 7;
00072
00073
00074 FieldContainer<double> myContainer(dimensions);
00075
00076 cout << "\n" \
00077 << "===============================================================================\n"\
00078 << "| EXAMPLE 1: Debug mode |\n"\
00079 << "===============================================================================\n\n";
00080
00081
00082
00083 cout \
00084 << "===============================================================================\n"\
00085 << " Trying to get enumeration using multi-index with the wrong rank: \n\n";
00086 try{
00087 multiIndex.resize(5);
00088 multiIndex[0] = 3;
00089 multiIndex[1] = 1;
00090 multiIndex[2] = 2;
00091 multiIndex[3] = 2;
00092 multiIndex[4] = 6;
00093 myContainer.getEnumeration(multiIndex);
00094 }
00095 catch(std::logic_error err){
00096 cout << err.what() << "\n";
00097 }
00098
00099
00100 cout \
00101 << "===============================================================================\n"\
00102 << " Trying to get enumeration using multi-index that is out of bounds: \n\n";
00103 try{
00104 multiIndex.resize(4);
00105 multiIndex[0] = 3;
00106 multiIndex[1] = 1;
00107 multiIndex[2] = 4;
00108 multiIndex[3] = 2;
00109 myContainer.getEnumeration(multiIndex);
00110 }
00111 catch(std::logic_error err){
00112 cout << err.what() << "\n\n";
00113 }
00114
00115
00116 cout \
00117 << "===============================================================================\n"\
00118 << " Trying to set values from array whose size is less than FieldContainer's size: \n\n";
00119
00120
00121 dimensions[0] = 4;
00122
00123
00124 Teuchos::Array<double> dataTeuchosArray(4*3*2*7);
00125
00126
00127 int counter = 0;
00128 for(int i=0; i < dimensions[0]; i++){
00129 for(int j=0; j < dimensions[1]; j++){
00130 for(int k=0; k < dimensions[2]; k++){
00131 for(int l = 0; l < dimensions[3]; l++){
00132 dataTeuchosArray[counter] = (double)counter;
00133 counter++;
00134 }
00135 }
00136 }
00137 }
00138
00139
00140 try{
00141 myContainer.setValues(dataTeuchosArray);
00142 }
00143 catch(std::logic_error err){
00144 cout << err.what() << "\n";
00145 }
00146
00147
00148 cout \
00149 << "===============================================================================\n"\
00150 << " Trying to set values from array whose size is greater than FieldContainer's size: \n\n";
00151
00152
00153 dimensions[0] = 5;
00154 dimensions[2] = 3;
00155
00156
00157 dataTeuchosArray.resize(5*3*3*7);
00158
00159
00160 counter = 0;
00161 for(int i=0; i < dimensions[0]; i++){
00162 for(int j=0; j < dimensions[1]; j++){
00163 for(int k=0; k < dimensions[2]; k++){
00164 for(int l = 0; l < dimensions[3]; l++){
00165 dataTeuchosArray[counter] = (double)counter;
00166 counter++;
00167 }
00168 }
00169 }
00170 }
00171
00172
00173 try{
00174 myContainer.setValues(dataTeuchosArray);
00175 }
00176 catch(std::logic_error err){
00177 cout << err.what() << "\n";
00178 }
00179
00180
00181
00182 cout \
00183 << "===============================================================================\n"\
00184 << " Trying to use [] with enumeration that is out of range: \n\n";
00185 try{
00186 myContainer[1000];
00187 }
00188 catch(std::logic_error err){
00189 cout << err.what() << "\n\n";
00190 }
00191
00192
00193
00194
00195
00196
00197 cout \
00198 << "===============================================================================\n"\
00199 << " Trying to create FieldContainer using incompatible data array and dimensions: \n\n";
00200 try{
00201 dimensions[0] = 5;
00202 dimensions[1] = 3;
00203 dimensions[2] = 3;
00204 dimensions[3] = 8;
00205
00206 FieldContainer<double> myOtherContainer(dimensions, dataTeuchosArray);
00207 }
00208 catch(std::logic_error err){
00209 cout << err.what() << endl;
00210 }
00211
00212 return 0;
00213 }