Intrepid
Intrepid_Utils.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 #ifndef INTREPID_UTILS_HPP
50 #define INTREPID_UTILS_HPP
51 
52 #include "Intrepid_ConfigDefs.hpp"
53 #include "Intrepid_Types.hpp"
54 #include "Teuchos_Array.hpp"
55 #include "Teuchos_oblackholestream.hpp"
56 #include "Teuchos_RCP.hpp"
57 
58 namespace Intrepid {
59 
60 /***************************************************************************************************
61  ***************************************************************************************************
62  ** **
63  ** Declarations of non-templated utility functions for order and cardinality of operators **
64  ** **
65  ***************************************************************************************************
66  ***************************************************************************************************/
67 
68 
80  int getFieldRank(const EFunctionSpace spaceType);
81 
82 
83 
119  int getOperatorRank(const EFunctionSpace spaceType,
120  const EOperator operatorType,
121  const int spaceDim);
122 
123 
124 
130  int getOperatorOrder(const EOperator operatorType);
131 
132 
133 
158  int getDkEnumeration(const int xMult,
159  const int yMult = -1,
160  const int zMult = -1);
161 
162 
163 
172  void getDkMultiplicities(Teuchos::Array<int>& partialMult,
173  const int derivativeEnum,
174  const EOperator operatorType,
175  const int spaceDim);
176 
177 
178 
197  int getDkCardinality(const EOperator operatorType,
198  const int spaceDim);
199 
200 
201 
202 /***************************************************************************************************
203  ***************************************************************************************************
204  ** **
205  ** Declarations of helper functions for the basis class **
206  ** **
207  ***************************************************************************************************
208  ***************************************************************************************************/
209 
221  void setOrdinalTagData(std::vector<std::vector<std::vector<int> > > &tagToOrdinal,
222  std::vector<std::vector<int> > &ordinalToTag,
223  const int *tags,
224  const int basisCard,
225  const int tagSize,
226  const int posScDim,
227  const int posScOrd,
228  const int posDfOrd);
229 
230 
231 
232 /***************************************************************************************************
233  ***************************************************************************************************
234  ** **
235  ** Declarations of templated utility functions **
236  ** **
237  ***************************************************************************************************
238  ***************************************************************************************************/
239 
240  enum TypeOfExactData{
241  INTREPID_UTILS_FRACTION=0,
242  INTREPID_UTILS_SCALAR
243  };
244 
245 /***************************************************************************************************
246  * *
247  * Utility functions for handling external data in tests *
248  * *
249  ***************************************************************************************************/
250 
263 template<class Scalar>
264 int compareToAnalytic(const Teuchos::Array< Teuchos::Array<Scalar> > testMat,
265  std::ifstream & inputFile,
266  Scalar reltol,
267  int iprint,
268  TypeOfExactData analyticDataType = INTREPID_UTILS_FRACTION);
269 
283 template<class Scalar>
284 int compareToAnalytic(const Scalar * testMat,
285  std::ifstream & inputFile,
286  Scalar reltol,
287  int iprint,
288  TypeOfExactData analyticDataType = INTREPID_UTILS_FRACTION);
289 
290 
291 
301 template<class Scalar>
302 void getAnalytic(Teuchos::Array< Teuchos::Array<Scalar> > & testMat,
303  std::ifstream & inputFile,
304  TypeOfExactData analyticDataType = INTREPID_UTILS_FRACTION);
305 
315 template<class Scalar>
316 void getAnalytic(Scalar * testMat,
317  std::ifstream & inputFile,
318  TypeOfExactData analyticDataType = INTREPID_UTILS_FRACTION);
319 
320 
321 
322 /***************************************************************************************************
323  * *
324  * Utility functions for checking requirements on ranks and dimensions of array arguments *
325  * *
326  ***************************************************************************************************/
327 
328 
338  template<class Array>
339  bool requireRankRange(std::string& errmsg,
340  const Array& array,
341  const int lowerBound,
342  const int upperBound);
343 
344 
345 
354  template<class Array1, class Array2>
355  bool requireRankMatch(std::string& errmsg,
356  const Array1& array1,
357  const Array2& array2);
358 
359 
360 
371  template<class Array>
372  bool requireDimensionRange(std::string& errmsg,
373  const Array& array,
374  const int dim,
375  const int lowerBound,
376  const int upperBound);
377 
378 
379 
390  template<class Array1, class Array2>
391  bool requireDimensionMatch(std::string& errmsg,
392  const Array1& array1,
393  const int a1_dim0,
394  const Array2& array2,
395  const int a2_dim0);
396 
397 
398 
411  template<class Array1, class Array2>
412  bool requireDimensionMatch(std::string& errmsg,
413  const Array1& array1,
414  const int a1_dim0, const int a1_dim1,
415  const Array2& array2,
416  const int a2_dim0, const int a2_dim1);
417 
418 
419 
434  template<class Array1, class Array2>
435  bool requireDimensionMatch(std::string& errmsg,
436  const Array1& array1,
437  const int a1_dim0, const int a1_dim1, const int a1_dim2,
438  const Array2& array2,
439  const int a2_dim0, const int a2_dim1, const int a2_dim2);
440 
441 
442 
459  template<class Array1, class Array2>
460  bool requireDimensionMatch(std::string& errmsg,
461  const Array1& array1,
462  const int a1_dim0, const int a1_dim1, const int a1_dim2, const int a1_dim3,
463  const Array2& array2,
464  const int a2_dim0, const int a2_dim1, const int a2_dim2, const int a2_dim3);
465 
466 
467 
486  template<class Array1, class Array2>
487  bool requireDimensionMatch(std::string& errmsg,
488  const Array1& array1,
489  const int a1_dim0, const int a1_dim1,
490  const int a1_dim2, const int a1_dim3, const int a1_dim4,
491  const Array2& array2,
492  const int a2_dim0, const int a2_dim1,
493  const int a2_dim2, const int a2_dim3, const int a2_dim4);
494 
495 
496 
505  template<class Array1, class Array2>
506  bool requireDimensionMatch(std::string& errmsg,
507  const Array1& array1,
508  const Array2& array2);
509 
510 
511 
512 /***************************************************************************************************
513  ***************************************************************************************************
514  ** **
515  ** Definitions of templated functions **
516  ** **
517  ***************************************************************************************************
518  ***************************************************************************************************/
519 
520 
521 /***************************************************************************************************
522  * *
523  * Utility functions for handling external data in tests *
524  * *
525  ***************************************************************************************************/
526 
527 template<class Scalar>
528 int compareToAnalytic(const Teuchos::Array< Teuchos::Array<Scalar> > testMat,
529  std::ifstream & inputFile,
530  Scalar reltol,
531  int iprint,
532  TypeOfExactData analyticDataType ) {
533 
534  // This little trick lets us print to std::cout only if
535  // iprint > 0.
536  Teuchos::RCP<std::ostream> outStream;
537  Teuchos::oblackholestream bhs; // outputs nothing
538  if (iprint > 0)
539  outStream = Teuchos::rcp(&std::cout, false);
540  else
541  outStream = Teuchos::rcp(&bhs, false);
542 
543  // Save the format state of the original std::cout.
544  Teuchos::oblackholestream oldFormatState;
545  oldFormatState.copyfmt(std::cout);
546 
547  std::string line;
548  std::string chunk;
549  Scalar testentry;
550  Scalar abstol;
551  Scalar absdiff;
552  int i=0, j=0;
553  int err = 0;
554 
555  while (! inputFile.eof() )
556  {
557  std::getline (inputFile,line);
558  std::istringstream linestream(line);
559  std::string chunk;
560  j = 0;
561  while( linestream >> chunk ) {
562  int num1;
563  int num2;
564  std::string::size_type loc = chunk.find( "/", 0);
565  if( loc != std::string::npos ) {
566  chunk.replace( loc, 1, " ");
567  std::istringstream chunkstream(chunk);
568  chunkstream >> num1;
569  chunkstream >> num2;
570  testentry = (Scalar)(num1)/(Scalar)(num2);
571  abstol = ( std::fabs(testentry) < reltol ? reltol : std::fabs(reltol*testentry) );
572  absdiff = std::fabs(testentry - testMat[i][j]);
573  if (absdiff > abstol) {
574  err++;
575  *outStream << "FAILURE --> ";
576  }
577  *outStream << "entry[" << i << "," << j << "]:" << " "
578  << testMat[i][j] << " " << num1 << "/" << num2 << " "
579  << absdiff << " " << "<?" << " " << abstol << "\n";
580  }
581  else {
582  std::istringstream chunkstream(chunk);
583  if (analyticDataType == INTREPID_UTILS_FRACTION) {
584  chunkstream >> num1;
585  testentry = (Scalar)(num1);
586  }
587  else if (analyticDataType == INTREPID_UTILS_SCALAR)
588  chunkstream >> testentry;
589  abstol = ( std::fabs(testentry) < reltol ?reltol : std::fabs(reltol*testentry) );
590  absdiff = std::fabs(testentry - testMat[i][j]);
591  if (absdiff > abstol) {
592  err++;
593  *outStream << "FAILURE --> ";
594  }
595  *outStream << "entry[" << i << "," << j << "]:" << " "
596  << testMat[i][j] << " " << testentry << " "
597  << absdiff << " " << "<?" << " " << abstol << "\n";
598  }
599  j++;
600  }
601  i++;
602  }
603 
604  // reset format state of std::cout
605  std::cout.copyfmt(oldFormatState);
606 
607  return err;
608 } // end compareToAnalytic
609 
610 
611 
612 template<class Scalar>
613 int compareToAnalytic(const Scalar * testMat,
614  std::ifstream & inputFile,
615  Scalar reltol,
616  int iprint,
617  TypeOfExactData analyticDataType ) {
618 
619  // This little trick lets us print to std::cout only if
620  // iprint > 0.
621  Teuchos::RCP<std::ostream> outStream;
622  Teuchos::oblackholestream bhs; // outputs nothing
623  if (iprint > 0)
624  outStream = Teuchos::rcp(&std::cout, false);
625  else
626  outStream = Teuchos::rcp(&bhs, false);
627 
628  // Save the format state of the original std::cout.
629  Teuchos::oblackholestream oldFormatState;
630  oldFormatState.copyfmt(std::cout);
631 
632  std::string line;
633  std::string chunk;
634  Scalar testentry;
635  Scalar abstol;
636  Scalar absdiff;
637  int i=0, j=0, offset=0;
638  int err = 0;
639 
640  while (! inputFile.eof() )
641  {
642  std::getline (inputFile,line);
643  std::istringstream linestream(line);
644  std::string chunk;
645  j = 0;
646  while( linestream >> chunk ) {
647  int num1;
648  int num2;
649  std::string::size_type loc = chunk.find( "/", 0);
650  if( loc != std::string::npos ) {
651  chunk.replace( loc, 1, " ");
652  std::istringstream chunkstream(chunk);
653  chunkstream >> num1;
654  chunkstream >> num2;
655  testentry = (Scalar)(num1)/(Scalar)(num2);
656  abstol = ( std::fabs(testentry) < reltol ? reltol : std::fabs(reltol*testentry) );
657  absdiff = std::fabs(testentry - testMat[i*offset+j]);
658  if (absdiff > abstol) {
659  err++;
660  *outStream << "FAILURE --> ";
661  }
662  *outStream << "entry[" << i << "," << j << "]:" << " "
663  << testMat[i*offset+j] << " " << num1 << "/" << num2 << " "
664  << absdiff << " " << "<?" << " " << abstol << "\n";
665  }
666  else {
667  std::istringstream chunkstream(chunk);
668  if (analyticDataType == INTREPID_UTILS_FRACTION) {
669  chunkstream >> num1;
670  testentry = (Scalar)(num1);
671  }
672  else if (analyticDataType == INTREPID_UTILS_SCALAR)
673  chunkstream >> testentry;
674  abstol = ( std::fabs(testentry) < reltol ?reltol : std::fabs(reltol*testentry) );
675  absdiff = std::fabs(testentry - testMat[i*offset+j]);
676  if (absdiff > abstol) {
677  err++;
678  *outStream << "FAILURE --> ";
679  }
680  *outStream << "entry[" << i << "," << j << "]:" << " "
681  << testMat[i*offset+j] << " " << testentry << " "
682  << absdiff << " " << "<?" << " " << abstol << "\n";
683  }
684  j++;
685  }
686  i++;
687  offset = j;
688  }
689 
690  // reset format state of std::cout
691  std::cout.copyfmt(oldFormatState);
692 
693  return err;
694 } // end compareToAnalytic
695 
696 
697 
698 template<class Scalar>
699 void getAnalytic(Teuchos::Array< Teuchos::Array<Scalar> > & testMat,
700  std::ifstream & inputFile,
701  TypeOfExactData analyticDataType ) {
702 
703  // Save the format state of the original std::cout.
704  Teuchos::oblackholestream oldFormatState;
705  oldFormatState.copyfmt(std::cout);
706 
707  std::string line;
708  std::string chunk;
709  Scalar testentry;
710  int i=0, j=0;
711 
712  while (! inputFile.eof() )
713  {
714  std::getline (inputFile,line);
715  std::istringstream linestream(line);
716  std::string chunk;
717  j = 0;
718  while( linestream >> chunk ) {
719  int num1;
720  int num2;
721  std::string::size_type loc = chunk.find( "/", 0);
722  if( loc != std::string::npos ) {
723  chunk.replace( loc, 1, " ");
724  std::istringstream chunkstream(chunk);
725  chunkstream >> num1;
726  chunkstream >> num2;
727  testentry = (Scalar)(num1)/(Scalar)(num2);
728  testMat[i][j] = testentry;
729  }
730  else {
731  std::istringstream chunkstream(chunk);
732  if (analyticDataType == INTREPID_UTILS_FRACTION) {
733  chunkstream >> num1;
734  testentry = (Scalar)(num1);
735  }
736  else if (analyticDataType == INTREPID_UTILS_SCALAR)
737  chunkstream >> testentry;
738  testMat[i][j] = testentry;
739  }
740  j++;
741  }
742  i++;
743  }
744 
745  // reset format state of std::cout
746  std::cout.copyfmt(oldFormatState);
747 } // end getAnalytic
748 
749 
750 
751 template<class Scalar>
752 void getAnalytic(Scalar * testMat,
753  std::ifstream & inputFile,
754  TypeOfExactData analyticDataType) {
755 
756  // Save the format state of the original std::cout.
757  Teuchos::oblackholestream oldFormatState;
758  oldFormatState.copyfmt(std::cout);
759 
760  std::string line;
761  std::string chunk;
762  Scalar testentry;
763  int i=0, j=0, offset=0;
764 
765  while (! inputFile.eof() )
766  {
767  std::getline (inputFile,line);
768  std::istringstream linestream(line);
769  std::string chunk;
770  j = 0;
771  while( linestream >> chunk ) {
772  int num1;
773  int num2;
774  std::string::size_type loc = chunk.find( "/", 0);
775  if( loc != std::string::npos ) {
776  chunk.replace( loc, 1, " ");
777  std::istringstream chunkstream(chunk);
778  chunkstream >> num1;
779  chunkstream >> num2;
780  testentry = (Scalar)(num1)/(Scalar)(num2);
781  testMat[i*offset+j] = testentry;
782  }
783  else {
784  std::istringstream chunkstream(chunk);
785  if (analyticDataType == INTREPID_UTILS_FRACTION) {
786  chunkstream >> num1;
787  testentry = (Scalar)(num1);
788  }
789  else if (analyticDataType == INTREPID_UTILS_SCALAR)
790  chunkstream >> testentry;
791  testMat[i*offset+j] = testentry;
792  }
793  j++;
794  }
795  i++;
796  offset = j;
797  }
798 
799  // reset format state of std::cout
800  std::cout.copyfmt(oldFormatState);
801 } // end getAnalytic
802 
803 
804 /***************************************************************************************************
805  * *
806  * Utility functions for checking requirements on ranks and dimensions of array arguments *
807  * *
808  ***************************************************************************************************/
809 
810 
811 template<class Array>
812 bool requireRankRange(std::string& errmsg,
813  const Array& array,
814  const int lowerBound,
815  const int upperBound){
816 
817  TEUCHOS_TEST_FOR_EXCEPTION( (lowerBound > upperBound) , std::invalid_argument,
818  ">>> ERROR (Intrepid_Utils::requireRankRange): lowerBound <= upperBound required!");
819 
820  bool OK = true;
821  if( (lowerBound == upperBound) && !(array.rank() == lowerBound) ) {
822  errmsg += "\n>>> Array rank = ";
823  errmsg += (char)(48 + array.rank() );
824  errmsg += " while rank-";
825  errmsg += (char) (48 + lowerBound);
826  errmsg += " array required.";
827  OK = false;
828  }
829  else if ( (lowerBound < upperBound) && !( (lowerBound <= array.rank() ) && (array.rank() <= upperBound) ) ){
830  errmsg += "\n>>> Array rank = ";
831  errmsg += (char)(48 + array.rank() );
832  errmsg += " while a rank between ";
833  errmsg += (char) (48 + lowerBound);
834  errmsg += " and ";
835  errmsg += (char) (48 + upperBound);
836  errmsg += " is required.";
837  OK = false;
838  }
839  return OK;
840 }
841 
842 
843 template<class Array1, class Array2>
844 bool requireRankMatch(std::string& errmsg,
845  const Array1& array1,
846  const Array2& array2){
847  bool OK = true;
848  if(array1.rank() != array2.rank() ) {
849  errmsg += "\n>>> Array ranks are required to match.";
850  OK = false;
851  }
852  return OK;
853 }
854 
855 
856 template<class Array>
857 bool requireDimensionRange(std::string& errmsg,
858  const Array& array,
859  const int dim,
860  const int lowerBound,
861  const int upperBound){
862 
863  TEUCHOS_TEST_FOR_EXCEPTION( (lowerBound > upperBound) , std::invalid_argument,
864  ">>> ERROR (Intrepid_Utils::requireDimensionRange): lowerBound <= upperBound required!");
865  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= dim) && (dim < array.rank() ) ),
866  std::invalid_argument,
867  ">>> ERROR (Intrepid_Utils::requireDimensionRange): 0 <= dim < array.rank() required!");
868 
869  bool OK = true;
870  if( (lowerBound > upperBound) || ( dim >= array.rank() ) ) {
871  errmsg += "\n>>> Unexpected error: ";
872  OK = false;
873  }
874  if( (lowerBound == upperBound) && !(array.dimension(dim) == lowerBound) ) {
875  errmsg += "\n>>> dimension(";
876  errmsg += (char)(48 + dim);
877  errmsg += ") = ";
878  errmsg += (char)(48 + array.dimension(dim) );
879  errmsg += " while dimension(";
880  errmsg += (char)(48 + dim);
881  errmsg += ") = ";
882  errmsg += (char)(48 + lowerBound);
883  errmsg += " required.";
884  OK = false;
885  }
886  else if( (lowerBound < upperBound) &&
887  !( (lowerBound <= array.dimension(dim) ) && (array.dimension(dim) <= upperBound) ) ){
888  errmsg += "\n>>> dimension(";
889  errmsg += (char)(48 + dim);
890  errmsg += ") = ";
891  errmsg += (char)(48 + array.dimension(dim) );
892  errmsg += " while ";
893  errmsg += (char)(48 + lowerBound);
894  errmsg += " <= dimension(";
895  errmsg += (char)(48 + dim);
896  errmsg += ") <= ";
897  errmsg +=(char)(48 + upperBound);
898  errmsg +=" required.";
899  OK = false;
900  }
901  return OK;
902 }
903 
904 
905 
906 template<class Array1, class Array2>
907 bool requireDimensionMatch(std::string& errmsg,
908  const Array1& array1,
909  const int a1_dim0,
910  const Array2& array2,
911  const int a2_dim0){
912 
913  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim0) && (a1_dim0 < array1.rank() ) ),
914  std::invalid_argument,
915  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim0 < array1.rank() required!");
916  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim0) && (a2_dim0 < array2.rank() ) ),
917  std::invalid_argument,
918  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim0 < array2.rank() required!");
919 
920  bool OK = true;
921  if(array1.dimension(a1_dim0) != array2.dimension(a2_dim0) ){
922  errmsg += "\n>>> dimension(";
923  errmsg += (char)(48 + a1_dim0);
924  errmsg += ") of 1st array and dimension(";
925  errmsg += (char)(48 + a2_dim0);
926  errmsg += ") of 2nd array are required to match.";
927  OK = false;
928  }
929  return OK;
930 }
931 
932 
933 
934 template<class Array1, class Array2>
935 bool requireDimensionMatch(std::string& errmsg,
936  const Array1& array1,
937  const int a1_dim0, const int a1_dim1,
938  const Array2& array2,
939  const int a2_dim0, const int a2_dim1){
940 
941  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim0) && (a1_dim0 < array1.rank() ) ),
942  std::invalid_argument,
943  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim0 < array1.rank() required!");
944  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim1) && (a1_dim1 < array1.rank() ) ),
945  std::invalid_argument,
946  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim1 < array1.rank() required!");
947  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim0) && (a2_dim0 < array2.rank() ) ),
948  std::invalid_argument,
949  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim0 < array2.rank() required!");
950  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim1) && (a2_dim1 < array2.rank() ) ),
951  std::invalid_argument,
952  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim1 < array2.rank() required!");
953 
954  bool OK = true;
955  if( !requireDimensionMatch(errmsg, array1, a1_dim0, array2, a2_dim0) ){
956  OK = false;
957  }
958  if( !requireDimensionMatch(errmsg, array1, a1_dim1, array2, a2_dim1) ){
959  OK = false;
960  }
961  return OK;
962 }
963 
964 
965 
966 template<class Array1, class Array2>
967 bool requireDimensionMatch(std::string& errmsg,
968  const Array1& array1,
969  const int a1_dim0, const int a1_dim1, const int a1_dim2,
970  const Array2& array2,
971  const int a2_dim0, const int a2_dim1, const int a2_dim2){
972 
973  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim0) && (a1_dim0 < array1.rank() ) ),
974  std::invalid_argument,
975  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim0 < array1.rank() required!");
976  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim1) && (a1_dim1 < array1.rank() ) ),
977  std::invalid_argument,
978  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim1 < array1.rank() required!");
979  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim2) && (a1_dim2 < array1.rank() ) ),
980  std::invalid_argument,
981  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim2 < array1.rank() required!");
982  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim0) && (a2_dim0 < array2.rank() ) ),
983  std::invalid_argument,
984  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim0 < array2.rank() required!");
985  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim1) && (a2_dim1 < array2.rank() ) ),
986  std::invalid_argument,
987  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim1 < array2.rank() required!");
988  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim2) && (a2_dim2 < array2.rank() ) ),
989  std::invalid_argument,
990  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim2 < array2.rank() required!");
991 
992 
993  bool OK = true;
994  if( !requireDimensionMatch(errmsg, array1, a1_dim0, array2, a2_dim0) ){
995  OK = false;
996  }
997  if( !requireDimensionMatch(errmsg, array1, a1_dim1, array2, a2_dim1) ){
998  OK = false;
999  }
1000  if( !requireDimensionMatch(errmsg, array1, a1_dim2, array2, a2_dim2) ){
1001  OK = false;
1002  }
1003  return OK;
1004 }
1005 
1006 
1007 
1008 template<class Array1, class Array2>
1009 bool requireDimensionMatch(std::string& errmsg,
1010  const Array1& array1,
1011  const int a1_dim0, const int a1_dim1, const int a1_dim2, const int a1_dim3,
1012  const Array2& array2,
1013  const int a2_dim0, const int a2_dim1, const int a2_dim2, const int a2_dim3){
1014 
1015  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim0) && (a1_dim0 < array1.rank() ) ),
1016  std::invalid_argument,
1017  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim0 < array1.rank() required!");
1018  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim1) && (a1_dim1 < array1.rank() ) ),
1019  std::invalid_argument,
1020  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim1 < array1.rank() required!");
1021  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim2) && (a1_dim2 < array1.rank() ) ),
1022  std::invalid_argument,
1023  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim2 < array1.rank() required!");
1024  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim3) && (a1_dim3 < array1.rank() ) ),
1025  std::invalid_argument,
1026  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim3 < array1.rank() required!");
1027  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim0) && (a2_dim0 < array2.rank() ) ),
1028  std::invalid_argument,
1029  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim0 < array2.rank() required!");
1030  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim1) && (a2_dim1 < array2.rank() ) ),
1031  std::invalid_argument,
1032  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim1 < array2.rank() required!");
1033  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim2) && (a2_dim2 < array2.rank() ) ),
1034  std::invalid_argument,
1035  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim2 < array2.rank() required!");
1036  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim3) && (a2_dim3 < array2.rank() ) ),
1037  std::invalid_argument,
1038  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim3 < array2.rank() required!");
1039  bool OK = true;
1040  if( !requireDimensionMatch(errmsg, array1, a1_dim0, array2, a2_dim0) ){
1041  OK = false;
1042  }
1043  if( !requireDimensionMatch(errmsg, array1, a1_dim1, array2, a2_dim1) ){
1044  OK = false;
1045  }
1046  if( !requireDimensionMatch(errmsg, array1, a1_dim2, array2, a2_dim2) ){
1047  OK = false;
1048  }
1049  if( !requireDimensionMatch(errmsg, array1, a1_dim3, array2, a2_dim3) ){
1050  OK = false;
1051  }
1052  return OK;
1053 }
1054 
1055 
1056 
1057 template<class Array1, class Array2>
1058 bool requireDimensionMatch(std::string& errmsg,
1059  const Array1& array1,
1060  const int a1_dim0, const int a1_dim1, const int a1_dim2,
1061  const int a1_dim3, const int a1_dim4,
1062  const Array2& array2,
1063  const int a2_dim0, const int a2_dim1, const int a2_dim2,
1064  const int a2_dim3, const int a2_dim4){
1065 
1066  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim0) && (a1_dim0 < array1.rank() ) ),
1067  std::invalid_argument,
1068  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim0 < array1.rank() required!");
1069  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim1) && (a1_dim1 < array1.rank() ) ),
1070  std::invalid_argument,
1071  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim1 < array1.rank() required!");
1072  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim2) && (a1_dim2 < array1.rank() ) ),
1073  std::invalid_argument,
1074  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim2 < array1.rank() required!");
1075  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim3) && (a1_dim3 < array1.rank() ) ),
1076  std::invalid_argument,
1077  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim3 < array1.rank() required!");
1078  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a1_dim4) && (a1_dim4 < array1.rank() ) ),
1079  std::invalid_argument,
1080  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a1_dim4 < array1.rank() required!");
1081  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim0) && (a2_dim0 < array2.rank() ) ),
1082  std::invalid_argument,
1083  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim0 < array2.rank() required!");
1084  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim1) && (a2_dim1 < array2.rank() ) ),
1085  std::invalid_argument,
1086  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim1 < array2.rank() required!");
1087  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim2) && (a2_dim2 < array2.rank() ) ),
1088  std::invalid_argument,
1089  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim2 < array2.rank() required!");
1090  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim3) && (a2_dim3 < array2.rank() ) ),
1091  std::invalid_argument,
1092  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim3 < array2.rank() required!");
1093  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= a2_dim4) && (a2_dim4 < array2.rank() ) ),
1094  std::invalid_argument,
1095  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): 0 <= a2_dim4 < array2.rank() required!");
1096 
1097  bool OK = true;
1098  if( !requireDimensionMatch(errmsg, array1, a1_dim0, array2, a2_dim0) ){
1099  OK = false;
1100  }
1101  if( !requireDimensionMatch(errmsg, array1, a1_dim1, array2, a2_dim1) ){
1102  OK = false;
1103  }
1104  if( !requireDimensionMatch(errmsg, array1, a1_dim2, array2, a2_dim2) ){
1105  OK = false;
1106  }
1107  if( !requireDimensionMatch(errmsg, array1, a1_dim3, array2, a2_dim3) ){
1108  OK = false;
1109  }
1110  if( !requireDimensionMatch(errmsg, array1, a1_dim4, array2, a2_dim4) ){
1111  OK = false;
1112  }
1113  return OK;
1114 }
1115 
1116 
1117 
1118 template<class Array1, class Array2>
1119 bool requireDimensionMatch(std::string& errmsg,
1120  const Array1& array1,
1121  const Array2& array2){
1122 
1123  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankMatch(errmsg, array1, array2 ), std::invalid_argument,
1124  ">>> ERROR (Intrepid_Utils::requireDimensionMatch): Arrays with equal ranks are required to test for all dimensions match." )
1125 
1126  bool OK = true;
1127  for(int dim = 0; dim < array1.rank(); dim++){
1128  if( !requireDimensionMatch(errmsg, array1, dim, array2, dim) ){
1129  OK = false;
1130  break;
1131  }
1132  }
1133  return OK;
1134 }
1135 
1136 
1137 } // end namespace Intrepid
1138 
1139 #endif
int compareToAnalytic(const Teuchos::Array< Teuchos::Array< Scalar > > testMat, std::ifstream &inputFile, Scalar reltol, int iprint, TypeOfExactData analyticDataType=INTREPID_UTILS_FRACTION)
Compares the values in the test matrix testMat to precomputed analytic values stored in a file...
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.
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.
void setOrdinalTagData(std::vector< std::vector< std::vector< int > > > &tagToOrdinal, std::vector< std::vector< int > > &ordinalToTag, const int *tags, const int basisCard, const int tagSize, const int posScDim, const int posScOrd, const int posDfOrd)
Fills ordinalToTag_ and tagToOrdinal_ by basis-specific tag data.
Contains definitions of custom data types in Intrepid.
int getOperatorOrder(const EOperator operatorType)
Returns order of an operator.
int getOperatorRank(const EFunctionSpace spaceType, const EOperator operatorType, const int spaceDim)
Returns rank of an operator.
int getFieldRank(const EFunctionSpace spaceType)
Returns the rank of fields in a function space of the specified type.
int getDkCardinality(const EOperator operatorType, const int spaceDim)
Returns cardinality of Dk, i.e., the number of all derivatives of order k.
int getDkEnumeration(const int xMult, const int yMult, const int zMult)
Returns the ordinal of a partial derivative of order k based on the multiplicities of the partials dx...
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.
void getDkMultiplicities(Teuchos::Array< int > &partialMult, const int derivativeEnum, const EOperator operatorType, const int spaceDim)
Returns multiplicities of dx, dy, and dz based on the enumeration of the partial derivative, its order and the space dimension. Inverse of the getDkEnumeration() method.
bool requireRankMatch(std::string &errmsg, const Array1 &array1, const Array2 &array2)
Checks if two arrays have matching ranks.
void getAnalytic(Teuchos::Array< Teuchos::Array< Scalar > > &testMat, std::ifstream &inputFile, TypeOfExactData analyticDataType=INTREPID_UTILS_FRACTION)
Loads analytic values stored in a file into the matrix testMat, where the output matrix is an array o...