00001
00026 #ifndef GLOBALVEC_H_
00027 #define GLOBALVEC_H_
00028
00029 #include "AuxDefs.h"
00030
00031 #include <vector>
00032
00033 #include <cstdio>
00034 #include <cmath>
00035
00036 struct GlobalVec {
00037
00038
00043 VecDouble vecQ;
00044 VecDouble vecV;
00045 VecDouble vecV_b;
00046 VecDouble vecT;
00047 VecDouble vecLUpdate;
00048
00050 GlobalVec (unsigned int totalNDOF) {
00051 vecQ = VecDouble (totalNDOF, 0.0);
00052
00053 vecV = VecDouble (vecQ);
00054 vecV_b = VecDouble (vecQ);
00055 vecT = VecDouble (vecQ);
00056 vecLUpdate = VecDouble (vecQ);
00057 }
00058
00059 private:
00060 static bool computeDiff (const VecDouble& vecA, const char* nameA, const VecDouble& vecB, const char* nameB, bool printDiff) {
00061 bool result = false;
00062 if (vecA.size () != vecB.size ()) {
00063 if (printDiff) {
00064 fprintf (stderr, "Arrays of different length %s.size () = %zd, %s.size () = %zd\n", nameA, vecA.size (), nameB, vecB.size ());
00065 }
00066 result = false;
00067 }
00068 else {
00069 result = true;
00070 for (size_t i = 0; i < vecA.size (); ++i) {
00071 double diff = fabs (vecA[i] - vecB[i]);
00072 if ( diff > TOLERANCE) {
00073 result = false;
00074 if (printDiff) {
00075 fprintf (stderr, "(%s[%zd] = %g) != (%s[%zd] = %g), diff=%g\n",
00076 nameA, i, vecA[i], nameB, i, vecB[i], diff);
00077 }
00078 else {
00079 break;
00080 }
00081 }
00082 }
00083 }
00084
00085 return result;
00086 }
00087
00088 bool computeDiffInternal (const GlobalVec& that, bool printDiff) const {
00089 return true
00090 && computeDiff (this->vecQ, "this->vecQ", that.vecQ, "that.vecQ", printDiff)
00091 && computeDiff (this->vecV, "this->vecV", that.vecV, "that.vecV", printDiff)
00092 && computeDiff (this->vecV_b, "this->vecV_b", that.vecV_b, "that.vecV_b", printDiff)
00093 && computeDiff (this->vecT, "this->vecT", that.vecT, "that.vecT", printDiff)
00094 && computeDiff (this->vecLUpdate, "this->vecLUpdate", that.vecLUpdate, "that.vecLUpdate", printDiff);
00095 }
00096
00097 public:
00103 bool cmpState (const GlobalVec& that) const {
00104 return computeDiffInternal (that, false);
00105 }
00106
00112 void printDiff (const GlobalVec& that) const {
00113 computeDiffInternal (that, true);
00114 }
00115 };
00116
00117 #endif