MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
matvectest.cc File Reference
#include "mbconfig.h"
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <typeinfo>
#include "ac/f2c.h"
#include "clock_time.h"
#include "matvec.h"
#include "matvec3.h"
#include "Rot.hh"
#include "matvecass.h"
Include dependency graph for matvectest.cc:

Go to the source code of this file.

Classes

struct  testMatVecProductGradient_testData::test_b
 
struct  testMatVecProductGradient_testData::test_c
 
struct  testMatVecProductGradient_testData::test_d
 
struct  testMatVecProductGradient_testData::test_e
 
struct  testMatVecProductGradient_testData::test_f
 
struct  testMatVecProductGradient_testData::test_g
 
struct  testMatVecProductGradient_testData::test_i
 
struct  testMatVecProductGradient_testData::test_j
 
struct  testMatVecProductGradient_testData::test_l
 
struct  testMatVecProductGradient_testData::test_m
 
struct  testMatVecProductGradient_testData::test_r
 
struct  testMatVecProductGradient_testData::test_s
 
struct  testMatVecProductGradient_testData::test_t
 
struct  testMatVecProductGradient_testData::test_norm_g
 

Namespaces

 testMatVecProductGradient_testData
 
 gradVecAssTest
 

Macros

#define MATVEC_DEBUG   1
 
#define GRADIENT_DEBUG   1
 

Functions

void tic ()
 
void tic (doublereal &dTime)
 
doublereal toc ()
 
doublereal random1 ()
 
void testScalarTypeTraits ()
 
template<typename T , index_type N>
void func (const Vector< T, N > &a, const Vector< T, N > &b, Vector< T, N > &c)
 
template<typename T >
void func (const T a[], const T b[], T c[], index_type N)
 
template<typename T , index_type N>
void func2 (const Matrix< T, N, N > &A, const Vector< T, N > &b, const Vector< T, N > &c, Vector< T, N > &d, doublereal e, doublereal &dt)
 
template<typename T >
void func2 (const T *A, const T *b, const T *c__, T *d__, const doublereal &e, doublereal &dt)
 
void func2ad (const doublereal A[3][3], const doublereal b[3], const doublereal c[3], doublereal d[3], const doublereal &e)
 
void func2ad_dv (const doublereal A[3][3], const doublereal Ad[3][3][nbdirsmax], const doublereal b[3], const doublereal bd[3][nbdirsmax], const doublereal c[3], const doublereal cd[3][nbdirsmax], doublereal d[3], doublereal dd[3][nbdirsmax], const doublereal &e, const integer &nbdirs)
 
void func2ad (const Matrix< doublereal, 3, 3 > &A, const Vector< doublereal, 3 > &b, const Vector< doublereal, 3 > &c, Vector< doublereal, 3 > &d, const doublereal &e, LocalDofMap *, doublereal &dt)
 
template<index_type N_SIZE>
void func2ad (const Matrix< Gradient< N_SIZE >, 3, 3 > &A, const Vector< Gradient< N_SIZE >, 3 > &b, const Vector< Gradient< N_SIZE >, 3 > &c, Vector< Gradient< N_SIZE >, 3 > &d, const doublereal &e, LocalDofMap *pDofMap, doublereal &dt)
 
template<typename T >
void func3 (const Matrix< T, 3, 3 > &R1, const Matrix< T, 3, 3 > &R2, const Vector< T, 3 > &a, const Vector< T, 3 > &b, Vector< T, 3 > &c, doublereal e)
 
template void func3< doublereal > (const Matrix< doublereal, 3, 3 > &R1, const Matrix< doublereal, 3, 3 > &R2, const Vector< doublereal, 3 > &a, const Vector< doublereal, 3 > &b, Vector< doublereal, 3 > &c, doublereal e)
 
template void func3< Gradient< 0 > > (const Matrix< Gradient< 0 >, 3, 3 > &R1, const Matrix< Gradient< 0 >, 3, 3 > &R2, const Vector< Gradient< 0 >, 3 > &a, const Vector< Gradient< 0 >, 3 > &b, Vector< Gradient< 0 >, 3 > &c, doublereal e)
 
template<typename T >
bool bCompare (const T &a, const T &b, doublereal dTolRel=0.)
 
template<index_type N_SIZE>
bool bCompare (const Gradient< N_SIZE > &a, const Gradient< N_SIZE > &b, doublereal dTolRel=0.)
 
template<typename T , index_type N>
void callFunc (LocalDofMap *pDofMap, const Vector< T, N > &a, const Vector< T, N > &b, Vector< T, N > &c, Vector< T, N > &c1)
 
template<typename T >
void callFunc2 (LocalDofMap *pDofMap, const Matrix< T, 3, 3 > &A, const Vector< T, 3 > &b, const Vector< T, 3 > &c, Vector< T, 3 > &d, Vector< T, 3 > &d_C, Vector< T, 3 > &d_F)
 
template<index_type N>
void testMatVecGradient (doublereal c_C[N], doublereal cd_C[N][N])
 
template<index_type N>
void testMatVecDouble (doublereal c_C[N])
 
template<index_type N_SIZE>
void testMatVecGradient2 ()
 
void testMatVecDouble2 ()
 
void testMatVecProduct ()
 
template<typename S , index_type N_rows, index_type N_SIZE>
void testMatVecProductGradient_testData::testGradient (const S &ref, const Vector< Gradient< N_SIZE >, N_rows > &v, doublereal dTol)
 
template<typename S , index_type N_SIZE>
void testMatVecProductGradient_testData::testGradient (const S &ref, const Gradient< N_SIZE > &g, doublereal dTol)
 
template<typename T , index_type N_rows>
Norm_1 (const Vector< T, N_rows > &u)
 
void func2addad_dv (const doublereal x[], const doublereal xd[], const doublereal y[], const doublereal yd[], doublereal z[], doublereal zd[], const integer &n, const integer &nbdirs)
 
void func2mulad_dv (const doublereal x[], const doublereal xd[], const doublereal y[], const doublereal yd[], doublereal z[], doublereal zd[], const integer &n, const integer &nbdirs)
 
template<typename T , index_type iRowCount>
void doVecAdd (const Vector< T, iRowCount > &x, const Vector< T, iRowCount > &y, Vector< T, iRowCount > &z)
 
template<typename T , index_type iRowCount>
void doVecMul (const Vector< T, iRowCount > &x, const Vector< T, iRowCount > &y, Vector< T, iRowCount > &z)
 
template<index_type iRowCount, index_type iMaxDeriv, typename Function , typename FunctionF77 >
void testVecOp (const int M, const int N, Function f, FunctionF77 f77, const char *function)
 
void testMatVecProductGradient ()
 
template<index_type N_SIZE>
void testMatVecProductGradient2 (index_type iNumDeriv, int N)
 
template<index_type N_rows>
void testMatVecCopy ()
 
template<typename T >
Matrix< T, 3, 3 > & gradVecAssTest::Euler123ToMatR (const Vector< T, 3 > &v, Matrix< T, 3, 3 > &R)
 
void testMatVec3 ()
 
void testSubVecAss ()
 
void testSubVecAssMatVec ()
 
void testInv ()
 
void testSolve ()
 
template<index_type N>
void testMatVec ()
 
template<int iNumDofMax>
void cppad_benchmark1 (const int N)
 
template<int iNumDofMax>
void cppad_benchmark2 (const int N)
 
template<int iNumDofMax>
void cppad_benchmark3 (const int N)
 
void Mat3xN_test (int N, int M)
 
void MatNxN_test (int N, int M)
 
void MatDynamic_test (index_type iNumRows, index_type iNumCols, index_type iNumLoops)
 
template<index_type N_SIZE>
void Mat3xN_test_grad (int iNumDeriv, int N, int M)
 
template<index_type N_SIZE>
void Mat3xNT_test_grad (int iNumDeriv, int N, int M)
 
template<index_type N_SIZE>
void MatNxNT_test_grad (int iNumDeriv, int N, int M)
 
template<index_type N_SIZE>
void MatNxN_test_grad (int iNumDeriv, int N, int M)
 
template<index_type N_SIZE>
void MatDynamic_test_grad (index_type iNumDeriv, index_type iNumRows, index_type iNumCols, int iNumLoops)
 
template<index_type N_ROWS, index_type N_COLS>
void MatDynamicT_test (index_type iNumRows, index_type iNumCols, int iNumLoops)
 
template<index_type N_DERIV, index_type N_ROWS, index_type N_COLS>
void MatDynamicT_test_grad (index_type iNumDeriv, index_type iNumRows, index_type iNumCols, int iNumLoops)
 
void MatManip_test (int NLoops)
 
int main (int argc, char *argv[])
 

Variables

int NLoops = 1
 
int NLoopsAss = 1
 
const integer nbdirsmax = 12
 
static const struct
testMatVecProductGradient_testData::test_b 
testMatVecProductGradient_testData::oct_b
 
static const struct
testMatVecProductGradient_testData::test_c 
testMatVecProductGradient_testData::oct_c
 
static const struct
testMatVecProductGradient_testData::test_d 
testMatVecProductGradient_testData::oct_d
 
static const struct
testMatVecProductGradient_testData::test_e 
testMatVecProductGradient_testData::oct_e
 
static const struct
testMatVecProductGradient_testData::test_f 
testMatVecProductGradient_testData::oct_f
 
static const struct
testMatVecProductGradient_testData::test_g 
testMatVecProductGradient_testData::oct_g
 
static const struct
testMatVecProductGradient_testData::test_i 
testMatVecProductGradient_testData::oct_i
 
static const struct
testMatVecProductGradient_testData::test_j 
testMatVecProductGradient_testData::oct_j
 
static const struct
testMatVecProductGradient_testData::test_l 
testMatVecProductGradient_testData::oct_l
 
static const struct
testMatVecProductGradient_testData::test_m 
testMatVecProductGradient_testData::oct_m
 
static const struct
testMatVecProductGradient_testData::test_r 
testMatVecProductGradient_testData::oct_r
 
static const struct
testMatVecProductGradient_testData::test_s 
testMatVecProductGradient_testData::oct_s
 
static const struct
testMatVecProductGradient_testData::test_t 
testMatVecProductGradient_testData::oct_t
 
static const struct
testMatVecProductGradient_testData::test_norm_g 
testMatVecProductGradient_testData::oct_norm_g
 
const int gradVecAssTest::I1 = 1
 
const int gradVecAssTest::I2 = 2
 
const int gradVecAssTest::I3 = 3
 
doublereal dStartTime
 

Macro Definition Documentation

#define GRADIENT_DEBUG   1

Definition at line 70 of file matvectest.cc.

Referenced by main().

#define MATVEC_DEBUG   1

Definition at line 66 of file matvectest.cc.

Referenced by main().

Function Documentation

template<typename T >
bool bCompare ( const T &  a,
const T &  b,
doublereal  dTolRel = 0. 
)

Definition at line 367 of file matvectest.cc.

Referenced by callFunc(), callFunc2(), Mat3xN_test(), Mat3xN_test_grad(), Mat3xNT_test_grad(), MatDynamic_test(), MatDynamic_test_grad(), MatDynamicT_test(), MatDynamicT_test_grad(), MatManip_test(), MatNxN_test(), MatNxN_test_grad(), MatNxNT_test_grad(), testMatVecProductGradient_testData::testGradient(), testInv(), testMatVec(), testMatVecDouble(), testMatVecGradient(), testMatVecGradient2(), testMatVecProduct(), and testMatVecProductGradient().

367  {
368  assert(!std::isnan(a));
369  assert(!std::isnan(b));
370  doublereal dTolAbs = std::max<T>(1., std::max<T>(std::abs(a), std::abs(b))) * dTolRel;
371  return std::abs(a - b) <= dTolAbs;
372 }
static const doublereal a
Definition: hfluid_.h:289
double doublereal
Definition: colamd.c:52
template<index_type N_SIZE>
bool bCompare ( const Gradient< N_SIZE > &  a,
const Gradient< N_SIZE > &  b,
doublereal  dTolRel = 0. 
)

Definition at line 375 of file matvectest.cc.

References grad::Gradient< N_SIZE >::dGetDerivativeLocal(), grad::Gradient< N_SIZE >::dGetValue(), grad::Gradient< N_SIZE >::iGetEndIndexLocal(), and grad::Gradient< N_SIZE >::iGetStartIndexLocal().

375  {
376  assert(!std::isnan(a.dGetValue()));
377  assert(!std::isnan(b.dGetValue()));
378  doublereal dTolAbs = std::max(1., std::max(std::abs(a.dGetValue()), std::abs(b.dGetValue()))) * dTolRel;
379 
380  if (std::abs(a.dGetValue() - b.dGetValue()) > dTolAbs) {
381  std::cerr << "a = " << a.dGetValue() << " != b = " << b.dGetValue() << std::endl;
382  return false;
383  }
384 
385  index_type iStart = std::min(a.iGetStartIndexLocal(), b.iGetStartIndexLocal());
386  index_type iEnd = std::max(a.iGetEndIndexLocal(), b.iGetEndIndexLocal());
387 
388  for (index_type i = iStart; i < iEnd; ++i) {
389  doublereal dTolAbs = std::max<scalar_deriv_type>(1., std::max<scalar_deriv_type>(std::abs(a.dGetDerivativeLocal(i)), std::abs(b.dGetDerivativeLocal(i)))) * dTolRel;
390  assert(!std::isnan(a.dGetDerivativeLocal(i)));
391  assert(!std::isnan(b.dGetDerivativeLocal(i)));
392  if (std::abs(a.dGetDerivativeLocal(i) - b.dGetDerivativeLocal(i)) > dTolAbs) {
393  std::cerr << "ad(" << i << ") = " << a.dGetDerivativeLocal(i) << " != bd(" << i << ") = " << b.dGetDerivativeLocal(i) << std::endl;
394  return false;
395  }
396  }
397 
398  return true;
399 }
index_type iGetStartIndexLocal() const
Definition: gradient.h:2576
integer index_type
Definition: gradient.h:104
scalar_func_type dGetValue() const
Definition: gradient.h:2502
scalar_deriv_type dGetDerivativeLocal(index_type iLocalDof) const
Definition: gradient.h:2516
double doublereal
Definition: colamd.c:52
index_type iGetEndIndexLocal() const
Definition: gradient.h:2580

Here is the call graph for this function:

template<typename T , index_type N>
void callFunc ( LocalDofMap pDofMap,
const Vector< T, N > &  a,
const Vector< T, N > &  b,
Vector< T, N > &  c,
Vector< T, N > &  c1 
)

Definition at line 402 of file matvectest.cc.

References bCompare(), c, func(), NLoops, grad::Vector< T, N_rows >::pGetVec(), grad::sqrt(), tic(), and toc().

Referenced by testMatVecDouble(), and testMatVecGradient().

402  {
403  srand(0);
404  tic();
405  for (int i = 0; i < NLoops; ++i) {
406  func(a, b, c);
407  }
408 
409  std::cerr << "Vector (" << typeid(T).name() << "): " << toc() << "s" << std::endl;
410 
411  srand(0);
412  tic();
413  for (int i = 0; i < NLoops; ++i) {
414  func(a.pGetVec(), b.pGetVec(), c1.pGetVec(), N);
415  }
416 
417  std::cerr << "Array (" << typeid(T).name() << "): " << toc() << "s" << std::endl;
418 
419  std::cout << "a=" << std::endl << a << std::endl;
420  std::cout << "b=" << std::endl << b << std::endl;
421  std::cout << "c=" << std::endl << c << std::endl;
422  std::cout << "c1=" << std::endl << c1 << std::endl;
423 
424  const doublereal dTol = sqrt(std::numeric_limits<doublereal>::epsilon());
425 
426  for (int i = 1; i <= N; ++i) {
427  assert(bCompare(c(i), c1(i), dTol));
428  }
429 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
void func(const Vector< T, N > &a, const Vector< T, N > &b, Vector< T, N > &c)
Definition: matvectest.cc:200
void tic()
Definition: matvectest.cc:2874
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
ScalarType * pGetVec()
Definition: matvec.h:2488
static std::stack< cleanup * > c
Definition: cleanup.cc:59
doublereal toc()
Definition: matvectest.cc:2878
double doublereal
Definition: colamd.c:52
int NLoops
Definition: matvectest.cc:82

Here is the call graph for this function:

template<typename T >
void callFunc2 ( LocalDofMap pDofMap,
const Matrix< T, 3, 3 > &  A,
const Vector< T, 3 > &  b,
const Vector< T, 3 > &  c,
Vector< T, 3 > &  d,
Vector< T, 3 > &  d_C,
Vector< T, 3 > &  d_F 
)

Definition at line 432 of file matvectest.cc.

References bCompare(), func2(), func2ad(), NLoops, grad::Matrix< T, N_rows, N_cols >::pGetMat(), grad::Vector< T, N_rows >::pGetVec(), and random1().

Referenced by testMatVecDouble2(), and testMatVecGradient2().

432  {
433  srand(0);
434  doublereal dtMatVec = 0., dtC = 0., dtF = 0.;
435  for (int i = 0; i < NLoops; ++i) {
436  func2(A, b, c, d, random1(), dtMatVec);
437  }
438 
439  std::cerr << "matvec (" << typeid(T).name() << "): " << dtMatVec << "s" << std::endl;
440 
441  srand(0);
442  for (int i = 0; i < NLoops; ++i) {
443  func2(A.pGetMat(), b.pGetVec(), c.pGetVec(), d_C.pGetVec(), random1(), dtC);
444  }
445 
446  std::cerr << "C (" << typeid(T).name() << "): " << dtC << "s" << std::endl;
447 
448  srand(0);
449  for (int i = 0; i < NLoops; ++i) {
450  func2ad(A, b, c, d_F, random1(), pDofMap, dtF);
451  }
452 
453  std::cerr << "F77 (" << typeid(T).name() << "): " << dtF << "s" << std::endl;
454 
455  std::cerr << "overhead matvec:" << dtMatVec / std::max(std::numeric_limits<double>::epsilon(), dtF) << std::endl;
456  std::cerr << "overhead C:" << dtC / std::max(std::numeric_limits<double>::epsilon(), dtF) << std::endl;
457 
458  std::cout << "A=" << std::endl << A << std::endl;
459  std::cout << "b=" << std::endl << b << std::endl;
460  std::cout << "c=" << std::endl << c << std::endl;
461  std::cout << "d=" << std::endl << d << std::endl;
462  std::cout << "d_C=" << std::endl << d_C << std::endl;
463  std::cout << "d_F=" << std::endl << d_F << std::endl;
464 
465  const doublereal dTol = 10 * std::numeric_limits<scalar_deriv_type>::epsilon();
466 
467  for (int i = 1; i <= 3; ++i) {
468  assert(bCompare(d(i), d_C(i), dTol));
469  assert(bCompare(d(i), d_F(i), dTol));
470  }
471 }
doublereal random1()
Definition: matvectest.cc:88
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
void func2(const Matrix< T, N, N > &A, const Vector< T, N > &b, const Vector< T, N > &c, Vector< T, N > &d, doublereal e, doublereal &dt)
Definition: matvectest.cc:228
const ScalarType * pGetMat() const
Definition: matvec.h:2120
void func2ad(const doublereal A[3][3], const doublereal b[3], const doublereal c[3], doublereal d[3], const doublereal &e)
ScalarType * pGetVec()
Definition: matvec.h:2488
double doublereal
Definition: colamd.c:52
int NLoops
Definition: matvectest.cc:82

Here is the call graph for this function:

template<int iNumDofMax>
void cppad_benchmark1 ( const int  N)

Definition at line 2919 of file matvectest.cc.

References dof, gradVecAssTest::Euler123ToMatR(), grad::MapVectorBase::GLOBAL, mbdyn_clock_time(), and R.

2919  {
2920  const int iNumDof = 6;
2921 
2922  assert(iNumDofMax == 0 || iNumDofMax >= iNumDof);
2923 
2925  Vector<Gradient<iNumDofMax>, 3> X, Y, Phi;
2927  LocalDofMap dof;
2928 
2929  o(1) = 1.;
2930  o(2) = 2.;
2931  o(3) = 3.;
2932 
2934 
2935  const double start = mbdyn_clock_time();
2936  double calc = 0.;
2937 
2938  for (int loop = 0; loop < N; ++loop) {
2939  for (int i = 0; i < 3; ++i) {
2940  X(i + 1).SetValuePreserve(0.);
2941  X(i + 1).DerivativeResizeReset(&dof, i, MapVectorBase::GLOBAL, 1.);
2942  Phi(i + 1).SetValuePreserve(0.);
2943  Phi(i + 1).DerivativeResizeReset(&dof, i + 3, MapVectorBase::GLOBAL, 1.);
2944  }
2945 
2946  const double start_calc = mbdyn_clock_time();
2947 
2949 
2950  Y = X + R * o;
2951 
2952  calc += mbdyn_clock_time() - start_calc;
2953 
2954  for (int i = 0; i < 3; ++i) {
2955  for (int j = 0; j < iNumDof; ++j) {
2956  jac(i + 1, j + 1) = Y(i + 1).dGetDerivativeGlobal(j);
2957  }
2958  }
2959  }
2960 
2961  std::cout << "calculation time: " << calc/N << "s\n";
2962  std::cout << "elapsed time: " << (mbdyn_clock_time() - start)/N << "s\n";
2963 
2964  std::cout << "x=" << X << std::endl;
2965  std::cout << "y=" << Y << std::endl;
2966  std::cout << "jac=\n";
2967 
2968  for (int i = 0; i < 3; ++i) {
2969  for (int j = 0; j < iNumDof; ++j) {
2970  std::cout << jac(i + 1, j + 1) << '\t';
2971  }
2972  std::cout << std::endl;
2973  }
2974 }
double mbdyn_clock_time()
Definition: clock_time.cc:51
static const char * dof[]
Definition: drvdisp.cc:195
Matrix< T, 3, 3 > & Euler123ToMatR(const Vector< T, 3 > &v, Matrix< T, 3, 3 > &R)
Definition: matvectest.cc:1790
Mat3x3 R

Here is the call graph for this function:

template<int iNumDofMax>
void cppad_benchmark2 ( const int  N)

Definition at line 2977 of file matvectest.cc.

References dof, gradVecAssTest::Euler123ToMatR(), grad::MapVectorBase::GLOBAL, and mbdyn_clock_time().

2977  {
2978  const int iNumDof = 12;
2979 
2980  assert(iNumDofMax == 0 || iNumDofMax >= iNumDof);
2981 
2982  Matrix<Gradient<iNumDofMax>, 3, 3> R1, R2;
2983  Vector<Gradient<iNumDofMax>, 3> X1, X2, Y, Phi1, Phi2;
2984  Vector<doublereal, 3> o1, o2;
2985  LocalDofMap dof;
2986 
2987  o1(1) = 1.;
2988  o1(2) = 2.;
2989  o1(3) = 3.;
2990 
2991  o2(1) = 1.;
2992  o2(2) = 2.;
2993  o2(3) = 3.;
2994 
2996 
2997  const double start = mbdyn_clock_time();
2998  double calc = 0.;
2999 
3000  for (int loop = 0; loop < N; ++loop) {
3001  for (int i = 0; i < 3; ++i) {
3002  X1(i + 1).SetValuePreserve(0.);
3003  X1(i + 1).DerivativeResizeReset(&dof, i, MapVectorBase::GLOBAL, 1.);
3004  Phi1(i + 1).SetValuePreserve(0.);
3005  Phi1(i + 1).DerivativeResizeReset(&dof, i + 3, MapVectorBase::GLOBAL, 1.);
3006  X2(i + 1).SetValuePreserve(0.);
3007  X2(i + 1).DerivativeResizeReset(&dof, i + 6, MapVectorBase::GLOBAL, 1.);
3008  Phi2(i + 1).SetValuePreserve(0.);
3009  Phi2(i + 1).DerivativeResizeReset(&dof, i + 9, MapVectorBase::GLOBAL, 1.);
3010  }
3011 
3012  const double start_calc = mbdyn_clock_time();
3013 
3016 
3017  Y = X1 + R1 * o1 - X2 - R2 * o2;
3018 
3019  calc += mbdyn_clock_time() - start_calc;
3020 
3021  for (int i = 0; i < 3; ++i) {
3022  for (int j = 0; j < iNumDof; ++j) {
3023  jac(i + 1, j + 1) = Y(i + 1).dGetDerivativeGlobal(j);
3024  }
3025  }
3026  }
3027 
3028  std::cout << "calculation time: " << calc/N << "s\n";
3029  std::cout << "elapsed time: " << (mbdyn_clock_time() - start)/N << "s\n";
3030 
3031  std::cout << "X1=" << X1 << std::endl;
3032  std::cout << "X2=" << X2 << std::endl;
3033  std::cout << "Y=" << Y << std::endl;
3034  std::cout << "jac=\n";
3035 
3036  for (int i = 0; i < 3; ++i) {
3037  for (int j = 0; j < iNumDof; ++j) {
3038  std::cout << jac(i + 1, j + 1) << '\t';
3039  }
3040  std::cout << std::endl;
3041  }
3042 }
double mbdyn_clock_time()
Definition: clock_time.cc:51
static const char * dof[]
Definition: drvdisp.cc:195
Matrix< T, 3, 3 > & Euler123ToMatR(const Vector< T, 3 > &v, Matrix< T, 3, 3 > &R)
Definition: matvectest.cc:1790

Here is the call graph for this function:

template<int iNumDofMax>
void cppad_benchmark3 ( const int  N)

Definition at line 3045 of file matvectest.cc.

References dof, gradVecAssTest::Euler123ToMatR(), grad::MapVectorBase::GLOBAL, mbdyn_clock_time(), and grad::Transpose().

3045  {
3046  const int iNumDof = 12;
3047 
3048  assert(iNumDofMax == 0 || iNumDofMax >= iNumDof);
3049 
3050  typedef Matrix<Gradient<iNumDofMax>, 3, 3> Mat3x3;
3051  typedef Vector<Gradient<iNumDofMax>, 3> Vec3;
3052  typedef Vector<doublereal, 3> CVec3;
3053 
3054  Mat3x3 R1, R2;
3055  Vec3 X1, X2, Y, Phi1, Phi2;
3056  CVec3 o1, o2;
3057  LocalDofMap dof;
3058 
3059  o1(1) = 1.;
3060  o1(2) = 2.;
3061  o1(3) = 3.;
3062 
3063  o2(1) = 1.;
3064  o2(2) = 2.;
3065  o2(3) = 3.;
3066 
3068 
3069  const double start = mbdyn_clock_time();
3070  double calc = 0.;
3071 
3072  for (int loop = 0; loop < N; ++loop) {
3073  for (int i = 0; i < 3; ++i) {
3074  X1(i + 1).SetValuePreserve(0.);
3075  X1(i + 1).DerivativeResizeReset(&dof, i, MapVectorBase::GLOBAL, 1.);
3076  Phi1(i + 1).SetValuePreserve(0.);
3077  Phi1(i + 1).DerivativeResizeReset(&dof, i + 3, MapVectorBase::GLOBAL, 1.);
3078  X2(i + 1).SetValuePreserve(0.);
3079  X2(i + 1).DerivativeResizeReset(&dof, i + 6, MapVectorBase::GLOBAL, 1.);
3080  Phi2(i + 1).SetValuePreserve(0.);
3081  Phi2(i + 1).DerivativeResizeReset(&dof, i + 9, MapVectorBase::GLOBAL, 1.);
3082  }
3083 
3084  const double start_calc = mbdyn_clock_time();
3085 
3088 
3089  Y = Transpose(R2) * Vec3(X1 + R1 * o1 - X2) - o2;
3090 
3091  calc += mbdyn_clock_time() - start_calc;
3092 
3093  for (int i = 0; i < 3; ++i) {
3094  for (int j = 0; j < iNumDof; ++j) {
3095  jac(i + 1, j + 1) = Y(i + 1).dGetDerivativeGlobal(j);
3096  }
3097  }
3098  }
3099 
3100  std::cout << "calculation time: " << calc/N << "s\n";
3101  std::cout << "elapsed time: " << (mbdyn_clock_time() - start)/N << "s\n";
3102 
3103  std::cout << "X1=" << X1 << std::endl;
3104  std::cout << "X2=" << X2 << std::endl;
3105  std::cout << "Y=" << Y << std::endl;
3106  std::cout << "jac=\n";
3107 
3108  for (int i = 0; i < 3; ++i) {
3109  for (int j = 0; j < iNumDof; ++j) {
3110  std::cout << jac(i + 1, j + 1) << '\t';
3111  }
3112  std::cout << std::endl;
3113  }
3114 }
MatrixExpression< TransposedMatrix< MatrixDirectExpr< Matrix< T, N_rows, N_cols > > >, N_cols, N_rows > Transpose(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2206
Definition: matvec3.h:98
double mbdyn_clock_time()
Definition: clock_time.cc:51
static const char * dof[]
Definition: drvdisp.cc:195
Matrix< T, 3, 3 > & Euler123ToMatR(const Vector< T, 3 > &v, Matrix< T, 3, 3 > &R)
Definition: matvectest.cc:1790

Here is the call graph for this function:

template<typename T , index_type iRowCount>
void doVecAdd ( const Vector< T, iRowCount > &  x,
const Vector< T, iRowCount > &  y,
Vector< T, iRowCount > &  z 
)

Definition at line 1297 of file matvectest.cc.

1298 {
1299  z = x + y;
1300 }
template<typename T , index_type iRowCount>
void doVecMul ( const Vector< T, iRowCount > &  x,
const Vector< T, iRowCount > &  y,
Vector< T, iRowCount > &  z 
)

Definition at line 1303 of file matvectest.cc.

References grad::Vector< T, N_rows >::iGetNumRows().

1304 {
1305  for (index_type i = 1; i <= z.iGetNumRows(); ++i)
1306  {
1307  z(i) = x(i) * y(i);
1308  }
1309 }
integer index_type
Definition: gradient.h:104
index_type iGetNumRows() const
Definition: matvec.h:2480

Here is the call graph for this function:

template<typename T , index_type N>
void func ( const Vector< T, N > &  a,
const Vector< T, N > &  b,
Vector< T, N > &  c 
)

Definition at line 200 of file matvectest.cc.

References grad::Dot(), and random1().

Referenced by callFunc().

200  {
201  doublereal r1, r2, r3;
202  r1 = random1();
203  r2 = random1();
204  r3 = random1();
205  const T d1 = Dot(a, b) * (2. / 1.5);
206  c = (a * (r1 / 2) + b * (r2 / 2.)) - (a * (r3 * r1) - b * r1) + b * d1;
207 }
doublereal random1()
Definition: matvectest.cc:88
DotTraits< VectorExprLhs, VectorExprRhs, N_rows, N_rows >::ExpressionType Dot(const VectorExpression< VectorExprLhs, N_rows > &u, const VectorExpression< VectorExprRhs, N_rows > &v)
Definition: matvec.h:3133
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<typename T >
void func ( const T  a[],
const T  b[],
c[],
index_type  N 
)

Definition at line 210 of file matvectest.cc.

References random1().

210  {
211  doublereal r1, r2, r3;
212  r1 = random1();
213  r2 = random1();
214  r3 = random1();
215 
216  T d1 = T(0.);
217 
218  for (int i = 0; i < N; ++i) {
219  d1 += a[i] * b[i] * (2. / 1.5);
220  }
221 
222  for (int i = 0; i < N; ++i) {
223  c[i] = (a[i] * r1 + b[i] * r2) / 2. - (a[i] * r3 - b[i]) * r1 + b[i] * d1;
224  }
225 }
doublereal random1()
Definition: matvectest.cc:88
static std::stack< cleanup * > c
Definition: cleanup.cc:59
static const doublereal a
Definition: hfluid_.h:289
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<typename T , index_type N>
void func2 ( const Matrix< T, N, N > &  A,
const Vector< T, N > &  b,
const Vector< T, N > &  c,
Vector< T, N > &  d,
doublereal  e,
doublereal dt 
)

Definition at line 228 of file matvectest.cc.

References c, tic(), and grad::Transpose().

Referenced by callFunc2().

228  {
229  doublereal start, stop;
230  tic(start);
231  d = (Transpose(A) * Vector<T, N>(A * Vector<T, N>((b - c) * e)));
232  tic(stop);
233  dt += stop - start;
234 }
MatrixExpression< TransposedMatrix< MatrixDirectExpr< Matrix< T, N_rows, N_cols > > >, N_cols, N_rows > Transpose(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2206
void tic()
Definition: matvectest.cc:2874
static std::stack< cleanup * > c
Definition: cleanup.cc:59
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<typename T >
void func2 ( const T *  A,
const T *  b,
const T *  c__,
T *  d__,
const doublereal e,
doublereal dt 
)

Definition at line 237 of file matvectest.cc.

References tic().

237  {
238  doublereal start, stop;
239  tic(start);
240  /* Parameter adjustments */
241  --d__;
242  --c__;
243  --b;
244  A -= 4;
245  const T tmp1 = b[3] - c__[3];
246  const T tmp2 = b[2] - c__[2];
247  const T tmp3 = b[1] - c__[1];
248  const T tmp4 = tmp3 * A[7];
249  const T tmp5 = tmp1 * A[9];
250  const T tmp6 = tmp1 * A[12];
251  const T tmp7 = tmp1 * A[6];
252  const T tmp8 = tmp2 * A[11];
253  const T tmp10 = tmp3 * A[10];
254  const T tmp11 = tmp6 + tmp8 + tmp10;
255  const T tmp13 = tmp5 + tmp2 * A[8] + tmp4;
256  const T tmp14 = tmp7 + tmp2 * A[5] + tmp3 * A[4];
257  /* Function Body */
258  d__[1] = (A[10] * tmp11 + A[7] * tmp13 + A[4] * tmp14) * e;
259  d__[2] = (A[11] * tmp11 + A[8] * tmp13 + A[5] * tmp14) * e;
260  d__[3] = (A[12] * tmp11 + A[9] * tmp13 + A[6] * tmp14) * e;
261 
262  tic(stop);
263  dt += stop - start;
264 } /* func2_ */
void tic()
Definition: matvectest.cc:2874
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

void func2ad ( const doublereal  A[3][3],
const doublereal  b[3],
const doublereal  c[3],
doublereal  d[3],
const doublereal e 
)

Referenced by callFunc2().

void func2ad ( const Matrix< doublereal, 3, 3 > &  A,
const Vector< doublereal, 3 > &  b,
const Vector< doublereal, 3 > &  c,
Vector< doublereal, 3 > &  d,
const doublereal e,
LocalDofMap ,
doublereal dt 
)
inline

Definition at line 297 of file matvectest.cc.

References grad::Vector< T, N_rows >::pGetVec(), and tic().

297  {
298 
299  doublereal A_F[3][3];
300 
301  for (int i = 0; i < 3; ++i) {
302  for (int j = 0; j < 3; ++j) {
303  A_F[j][i] = A(i + 1, j + 1);
304  }
305  }
306 
307  doublereal start, stop;
308 
309  tic(start);
310  func2ad_(A_F, b.pGetVec(), c.pGetVec(), d.pGetVec(), e);
311  tic(stop);
312 
313  dt += stop - start;
314 }
void tic()
Definition: matvectest.cc:2874
ScalarType * pGetVec()
Definition: matvec.h:2488
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<index_type N_SIZE>
void func2ad ( const Matrix< Gradient< N_SIZE >, 3, 3 > &  A,
const Vector< Gradient< N_SIZE >, 3 > &  b,
const Vector< Gradient< N_SIZE >, 3 > &  c,
Vector< Gradient< N_SIZE >, 3 > &  d,
const doublereal e,
LocalDofMap pDofMap,
doublereal dt 
)
inline

Definition at line 317 of file matvectest.cc.

References c, grad::Gradient< N_SIZE >::dGetDerivativeGlobal(), grad::Gradient< N_SIZE >::dGetValue(), grad::MapVectorBase::GLOBAL, nbdirsmax, and tic().

317  {
318  typedef typename MaxSizeCheck<N_SIZE <= index_type(nbdirsmax)>::CheckType check_nbdirsmax;
319 
320  doublereal A_F[3][3], Ad_F[3][3][nbdirsmax], b_F[3], bd_F[3][nbdirsmax], c_F[3], cd_F[3][nbdirsmax], d_F[3], dd_F[3][nbdirsmax];
321 
322  for (int i = 0; i < 3; ++i) {
323  for (int j = 0; j < 3; ++j) {
324  const Gradient<N_SIZE>& A_ij = A(i + 1, j + 1);
325  A_F[j][i] = A_ij.dGetValue();
326  for (index_type k = 0; k < N_SIZE; ++k) {
327  Ad_F[j][i][k] = A_ij.dGetDerivativeGlobal(k);
328  }
329  }
330 
331  b_F[i] = b(i + 1).dGetValue();
332  c_F[i] = c(i + 1).dGetValue();
333 
334  for (index_type k = 0; k < N_SIZE; ++k) {
335  bd_F[i][k] = b(i + 1).dGetDerivativeGlobal(k);
336  cd_F[i][k] = c(i + 1).dGetDerivativeGlobal(k);
337  }
338  }
339 
340  doublereal start, stop;
341  tic(start);
342  func2ad_dv_(A_F, Ad_F, b_F, bd_F, c_F, cd_F, d_F, dd_F, e, N_SIZE);
343  tic(stop);
344  dt += stop - start;
345 
346  for (int i = 0; i < 3; ++i) {
347  d(i + 1).SetValuePreserve(d_F[i]);
348  d(i + 1).DerivativeResizeReset(pDofMap, 0L, N_SIZE, MapVectorBase::GLOBAL, 0.);
349  for (index_type k = 0; k < N_SIZE; ++k) {
350  d(i + 1).SetDerivativeGlobal(k, dd_F[i][k]);
351  }
352  }
353 }
scalar_deriv_type dGetDerivativeGlobal(index_type iGlobalDof) const
Definition: gradient.h:2532
integer index_type
Definition: gradient.h:104
void tic()
Definition: matvectest.cc:2874
static std::stack< cleanup * > c
Definition: cleanup.cc:59
const integer nbdirsmax
Definition: matvectest.cc:277
scalar_func_type dGetValue() const
Definition: gradient.h:2502
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

void func2ad_dv ( const doublereal  A[3][3],
const doublereal  Ad[3][3][nbdirsmax],
const doublereal  b[3],
const doublereal  bd[3][nbdirsmax],
const doublereal  c[3],
const doublereal  cd[3][nbdirsmax],
doublereal  d[3],
doublereal  dd[3][nbdirsmax],
const doublereal e,
const integer nbdirs 
)
void func2addad_dv ( const doublereal  x[],
const doublereal  xd[],
const doublereal  y[],
const doublereal  yd[],
doublereal  z[],
doublereal  zd[],
const integer n,
const integer nbdirs 
)

Referenced by main().

void func2mulad_dv ( const doublereal  x[],
const doublereal  xd[],
const doublereal  y[],
const doublereal  yd[],
doublereal  z[],
doublereal  zd[],
const integer n,
const integer nbdirs 
)

Referenced by main().

template<typename T >
void func3 ( const Matrix< T, 3, 3 > &  R1,
const Matrix< T, 3, 3 > &  R2,
const Vector< T, 3 > &  a,
const Vector< T, 3 > &  b,
Vector< T, 3 > &  c,
doublereal  e 
)

Definition at line 356 of file matvectest.cc.

References grad::Cross().

356  {
357  c = (Cross(R1 * a, R2 * b) + Cross(R2 * a, R1 * b)) * e;
358 }
VectorExpression< VectorCrossExpr< VectorLhsExpr, VectorRhsExpr >, 3 > Cross(const VectorExpression< VectorLhsExpr, 3 > &u, const VectorExpression< VectorRhsExpr, 3 > &v)
Definition: matvec.h:3248

Here is the call graph for this function:

template void func3< doublereal > ( const Matrix< doublereal, 3, 3 > &  R1,
const Matrix< doublereal, 3, 3 > &  R2,
const Vector< doublereal, 3 > &  a,
const Vector< doublereal, 3 > &  b,
Vector< doublereal, 3 > &  c,
doublereal  e 
)
template void func3< Gradient< 0 > > ( const Matrix< Gradient< 0 >, 3, 3 > &  R1,
const Matrix< Gradient< 0 >, 3, 3 > &  R2,
const Vector< Gradient< 0 >, 3 > &  a,
const Vector< Gradient< 0 >, 3 > &  b,
Vector< Gradient< 0 >, 3 > &  c,
doublereal  e 
)
int main ( int  argc,
char *  argv[] 
)

Definition at line 3746 of file matvectest.cc.

References func2addad_dv(), func2mulad_dv(), GRADIENT_DEBUG, Mat3xN_test(), MatDynamic_test(), MatManip_test(), MatNxN_test(), MATVEC_DEBUG, NLoops, testInv(), testMatVec3(), testMatVecDouble2(), testMatVecProduct(), testMatVecProductGradient(), testScalarTypeTraits(), testSolve(), testSubVecAss(), and testSubVecAssMatVec().

3746  {
3747 #ifdef HAVE_FEENABLEEXCEPT
3748  feenableexcept(FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
3749 #endif
3750  if (argc > 1) {
3751  NLoops = atol(argv[1]);
3752  }
3753 
3754  if (argc > 2) {
3755  NLoopsAss = atol(argv[2]);
3756  }
3757 
3758  if (NLoops < 1) {
3759  NLoops = 1;
3760  }
3761 
3762  if (NLoopsAss < 1) {
3763  NLoopsAss = 1;
3764  }
3765 
3766  std::cerr << "MatManip_test()\n";
3767 
3769 
3770  std::cerr << "---------------------------\ntestScalarTypeTraits()\n";
3772 
3773  testMatVec<3>();
3774  testMatVec<6>();
3775  testMatVec<8>();
3776  testMatVec<12>();
3777  testMatVec<24>();
3778 
3779  std::cerr << "---------------------------\ntestMatVecGradient2<1>()\n";
3780  testMatVecGradient2<1>();
3781 
3782  std::cerr << "---------------------------\ntestMatVecGradient2<2>()\n";
3783  testMatVecGradient2<2>();
3784 
3785  std::cerr << "---------------------------\ntestMatVecGradient2<3>()\n";
3786  testMatVecGradient2<3>();
3787 
3788  std::cerr << "---------------------------\ntestMatVecGradient2<4>()\n";
3789  testMatVecGradient2<4>();
3790 
3791  std::cerr << "---------------------------\ntestMatVecGradient2<5>()\n";
3792  testMatVecGradient2<5>();
3793 
3794  std::cerr << "---------------------------\ntestMatVecGradient2<6>()\n";
3795  testMatVecGradient2<6>();
3796 
3797  std::cerr << "---------------------------\ntestMatVecGradient2<8>()\n";
3798  testMatVecGradient2<8>();
3799 
3800  std::cerr << "---------------------------\ntestMatVecGradient2<10>()\n";
3801  testMatVecGradient2<10>();
3802 
3803  std::cerr << "---------------------------\ntestMatVecGradient2<12>()\n";
3804  testMatVecGradient2<12>();
3805 
3806  std::cerr << "---------------------------\ntestMatVecDouble2()\n";
3808 
3809  std::cerr << "---------------------------\ntestMatVecProduct()\n";
3811  std::cerr << "---------------------------\ntestMatVecProductGradient()\n";
3813 
3814  std::cerr << "---------------------------\ntestMatVecProductGradient2()\n";
3815  testMatVecProductGradient2<1>(1, NLoops);
3816  testMatVecProductGradient2<4>(4, NLoops);
3817  testMatVecProductGradient2<8>(8, NLoops);
3818  testMatVecProductGradient2<12>(12, NLoops);
3819  testMatVecProductGradient2<32>(32, NLoops);
3820  testMatVecProductGradient2<64>(64, NLoops);
3821  testMatVecProductGradient2<0>(256, NLoops);
3822 
3823  std::cerr << "---------------------------\ntestMatVecCopy()\n";
3824  testMatVecCopy<1>();
3825  testMatVecCopy<3>();
3826  testMatVecCopy<5>();
3827  testMatVecCopy<9>();
3828 
3829 #ifdef HAVE_BLITZ
3830  std::cerr << "---------------------------\ntestAssembly()\n";
3831  gradVecAssTest::testAssembly();
3832 #endif
3833 
3834  std::cerr << "---------------------------\ntestMatVec3()\n";
3835  testMatVec3();
3836 
3837  std::cerr << "---------------------------\ntestSubVecAss()\n";
3838  testSubVecAss();
3839 
3840  std::cerr << "---------------------------\ntestSubVecAssMatVec()\n";
3842 
3843  std::cerr << "---------------------------\ntestInv()\n";
3844  testInv();
3845 
3846  std::cerr << "----------------------------\ntestSolve()\n";
3847  testSolve();
3848 
3849  {
3850  const int N = argc > 3 ? atoi(argv[3]) : 1;
3851  const int nr = 4, nc = 4;
3853 
3854  for (int i = 1; i <= nr; ++i)
3855  {
3856  for (int j = 1; j <= nc; ++j)
3857  {
3858  B(i, j) = rand();
3859  C(i, j) = rand();
3860  }
3861  }
3862 
3863  clock_t start = clock();
3864 
3865  for (int i = 0; i < N; ++i)
3866  {
3867  A = B * C;
3868  }
3869 
3870  std::cerr << "time: " << double(clock()-start)/N/CLOCKS_PER_SEC << std::endl;
3871  }
3872 
3873  std::cerr << "----------------------------\ncppad_benchmark1<0>()\n";
3874  cppad_benchmark1<0>(NLoops);
3875 
3876  std::cerr << "----------------------------\ncppad_benchmark1<6>()\n";
3877  cppad_benchmark1<6>(NLoops);
3878 
3879  std::cerr << "----------------------------\ncppad_benchmark2<0>()\n";
3880  cppad_benchmark2<0>(NLoops);
3881 
3882  std::cerr << "----------------------------\ncppad_benchmark2<12>()\n";
3883  cppad_benchmark2<12>(NLoops);
3884 
3885  std::cerr << "----------------------------\ncppad_benchmark3<0>()\n";
3886  cppad_benchmark3<0>(NLoops);
3887 
3888  std::cerr << "----------------------------\ncppad_benchmark3<12>()\n";
3889  cppad_benchmark3<12>(NLoops);
3890 
3891 
3892  testVecOp<3, 2>(NLoops, 2, doVecAdd<Gradient<2>, 3>, __FC_DECL__(func2addad_dv), "add");
3893  testVecOp<3, 4>(NLoops, 4, doVecAdd<Gradient<4>, 3>, __FC_DECL__(func2addad_dv), "add");
3894  testVecOp<3, 8>(NLoops, 8, doVecAdd<Gradient<8>, 3>, __FC_DECL__(func2addad_dv), "add");
3895  testVecOp<3, 16>(NLoops, 16, doVecAdd<Gradient<16>, 3>, __FC_DECL__(func2addad_dv), "add");
3896 
3897  testVecOp<12, 2>(NLoops, 2, doVecAdd<Gradient<2>, 12>, __FC_DECL__(func2addad_dv), "add");
3898  testVecOp<12, 4>(NLoops, 4, doVecAdd<Gradient<4>, 12>, __FC_DECL__(func2addad_dv), "add");
3899  testVecOp<12, 8>(NLoops, 8, doVecAdd<Gradient<8>, 12>, __FC_DECL__(func2addad_dv), "add");
3900  testVecOp<12, 16>(NLoops, 16, doVecAdd<Gradient<16>, 12>, __FC_DECL__(func2addad_dv), "add");
3901 
3902  testVecOp<3, 2>(NLoops, 2, doVecMul<Gradient<2>, 3>, __FC_DECL__(func2mulad_dv), "mul");
3903  testVecOp<3, 4>(NLoops, 4, doVecMul<Gradient<4>, 3>, __FC_DECL__(func2mulad_dv), "mul");
3904  testVecOp<3, 8>(NLoops, 8, doVecMul<Gradient<8>, 3>, __FC_DECL__(func2mulad_dv), "mul");
3905  testVecOp<3, 16>(NLoops, 16, doVecMul<Gradient<16>, 3>, __FC_DECL__(func2mulad_dv), "mul");
3906 
3907  testVecOp<12, 2>(NLoops, 2, doVecAdd<Gradient<2>, 12>, __FC_DECL__(func2addad_dv), "add");
3908  testVecOp<12, 4>(NLoops, 4, doVecAdd<Gradient<4>, 12>, __FC_DECL__(func2addad_dv), "add");
3909  testVecOp<12, 8>(NLoops, 8, doVecAdd<Gradient<8>, 12>, __FC_DECL__(func2addad_dv), "add");
3910  testVecOp<12, 16>(NLoops, 16, doVecAdd<Gradient<16>, 12>, __FC_DECL__(func2addad_dv), "add");
3911 
3912  testVecOp<3, 0>(NLoops, 2, doVecAdd<Gradient<0>, 3>, __FC_DECL__(func2addad_dv), "add");
3913  testVecOp<3, 0>(NLoops, 4, doVecAdd<Gradient<0>, 3>, __FC_DECL__(func2addad_dv), "add");
3914  testVecOp<3, 0>(NLoops, 8, doVecAdd<Gradient<0>, 3>, __FC_DECL__(func2addad_dv), "add");
3915  testVecOp<3, 0>(NLoops, 16, doVecAdd<Gradient<0>, 3>, __FC_DECL__(func2addad_dv), "add");
3916  testVecOp<3, 0>(NLoops, 256, doVecAdd<Gradient<0>, 3>, __FC_DECL__(func2addad_dv), "add");
3917  testVecOp<3, 0>(NLoops, 512, doVecAdd<Gradient<0>, 3>, __FC_DECL__(func2addad_dv), "add");
3918  testVecOp<3, 0>(NLoops, 1024, doVecAdd<Gradient<0>, 3>, __FC_DECL__(func2addad_dv), "add");
3919 
3920  testVecOp<12, 0>(NLoops, 2, doVecAdd<Gradient<0>, 12>, __FC_DECL__(func2addad_dv), "add");
3921  testVecOp<12, 0>(NLoops, 4, doVecAdd<Gradient<0>, 12>, __FC_DECL__(func2addad_dv), "add");
3922  testVecOp<12, 0>(NLoops, 8, doVecAdd<Gradient<0>, 12>, __FC_DECL__(func2addad_dv), "add");
3923  testVecOp<12, 0>(NLoops, 16, doVecAdd<Gradient<0>, 12>, __FC_DECL__(func2addad_dv), "add");
3924  testVecOp<12, 0>(NLoops, 256, doVecAdd<Gradient<0>, 12>, __FC_DECL__(func2addad_dv), "add");
3925  testVecOp<12, 0>(NLoops, 512, doVecAdd<Gradient<0>, 12>, __FC_DECL__(func2addad_dv), "add");
3926  testVecOp<12, 0>(NLoops, 1024, doVecAdd<Gradient<0>, 12>, __FC_DECL__(func2addad_dv), "add");
3927 
3928  testVecOp<3, 0>(NLoops, 2, doVecMul<Gradient<0>, 3>, __FC_DECL__(func2mulad_dv), "mul");
3929  testVecOp<3, 0>(NLoops, 4, doVecMul<Gradient<0>, 3>, __FC_DECL__(func2mulad_dv), "mul");
3930  testVecOp<3, 0>(NLoops, 8, doVecMul<Gradient<0>, 3>, __FC_DECL__(func2mulad_dv), "mul");
3931  testVecOp<3, 0>(NLoops, 16, doVecMul<Gradient<0>, 3>, __FC_DECL__(func2mulad_dv), "mul");
3932  testVecOp<3, 0>(NLoops, 256, doVecMul<Gradient<0>, 3>, __FC_DECL__(func2mulad_dv), "mul");
3933  testVecOp<3, 0>(NLoops, 512, doVecMul<Gradient<0>, 3>, __FC_DECL__(func2mulad_dv), "mul");
3934  testVecOp<3, 0>(NLoops, 1024, doVecMul<Gradient<0>, 3>, __FC_DECL__(func2mulad_dv), "mul");
3935 
3936  testVecOp<12, 0>(NLoops, 2, doVecMul<Gradient<0>, 12>, __FC_DECL__(func2mulad_dv), "mul");
3937  testVecOp<12, 0>(NLoops, 4, doVecMul<Gradient<0>, 12>, __FC_DECL__(func2mulad_dv), "mul");
3938  testVecOp<12, 0>(NLoops, 8, doVecMul<Gradient<0>, 12>, __FC_DECL__(func2mulad_dv), "mul");
3939  testVecOp<12, 0>(NLoops, 16, doVecMul<Gradient<0>, 12>, __FC_DECL__(func2mulad_dv), "mul");
3940  testVecOp<12, 0>(NLoops, 256, doVecMul<Gradient<0>, 12>, __FC_DECL__(func2mulad_dv), "mul");
3941  testVecOp<12, 0>(NLoops, 512, doVecMul<Gradient<0>, 12>, __FC_DECL__(func2mulad_dv), "mul");
3942  testVecOp<12, 0>(NLoops, 1024, doVecMul<Gradient<0>, 12>, __FC_DECL__(func2mulad_dv), "mul");
3943 
3944  Mat3xN_test(3, NLoops);
3945  Mat3xN_test(10, NLoops);
3946  Mat3xN_test(100, NLoops);
3947 
3948  MatNxN_test(3, NLoops);
3949  MatNxN_test(10, NLoops);
3950  MatNxN_test(100, NLoops);
3951 
3952  Mat3xN_test_grad<4>(4, 3, NLoops);
3953  Mat3xN_test_grad<5>(5, 10, NLoops);
3954  Mat3xN_test_grad<0>(20, 100, NLoops);
3955 
3956  Mat3xNT_test_grad<4>(4, 3, NLoops);
3957  Mat3xNT_test_grad<5>(5, 10, NLoops);
3958  Mat3xNT_test_grad<0>(20, 100, NLoops);
3959 
3960  MatNxN_test_grad<4>(4, 3, NLoops);
3961  MatNxN_test_grad<5>(5, 10, NLoops);
3962  MatNxN_test_grad<0>(20, 100, NLoops);
3963 
3964  MatNxNT_test_grad<4>(4, 3, NLoops);
3965  MatNxNT_test_grad<5>(5, 10, NLoops);
3966  MatNxNT_test_grad<0>(20, 100, NLoops);
3967 
3968  MatDynamic_test(3, 4, NLoops);
3969  MatDynamic_test(10, 20, NLoops);
3970 
3971  MatDynamic_test_grad<3>(3, 4, 5, NLoops);
3972  MatDynamic_test_grad<5>(5, 10, 20, NLoops);
3973  MatDynamic_test_grad<0>(15, 20, 30, NLoops);
3974 
3975  MatDynamicT_test<10, 20>(10, 20, NLoops);
3976  MatDynamicT_test<DYNAMIC_SIZE, 20>(10, 20, NLoops);
3977  MatDynamicT_test<10, DYNAMIC_SIZE>(10, 20, NLoops);
3978  MatDynamicT_test<DYNAMIC_SIZE, DYNAMIC_SIZE>(10, 20, NLoops);
3979 
3980  MatDynamicT_test_grad<5, 10, 20>(5, 10, 20, NLoops);
3981  MatDynamicT_test_grad<5, DYNAMIC_SIZE, 20>(5, 10, 20, NLoops);
3982  MatDynamicT_test_grad<5, 10, DYNAMIC_SIZE>(5, 10, 20, NLoops);
3983  MatDynamicT_test_grad<5, DYNAMIC_SIZE, DYNAMIC_SIZE>(5, 10, 20, NLoops);
3984  MatDynamicT_test_grad<0, 10, 20>(5, 10, 20, NLoops);
3985  MatDynamicT_test_grad<0, DYNAMIC_SIZE, 20>(5, 10, 20, NLoops);
3986  MatDynamicT_test_grad<0, 10, DYNAMIC_SIZE>(5, 10, 20, NLoops);
3987  MatDynamicT_test_grad<0, DYNAMIC_SIZE, DYNAMIC_SIZE>(5, 10, 20, NLoops);
3988 
3989 #ifdef NDEBUG
3990  std::cerr << "\nNo tests have been done" << std::endl;
3991 #else
3992  std::cerr << "\nAll tests passed" << std::endl;
3993 #endif
3994 
3995  std::cerr << "MATVEC_DEBUG=" << MATVEC_DEBUG << std::endl;
3996  std::cerr << "GRADIENT_DEBUG=" << GRADIENT_DEBUG << std::endl;
3997 
3998  return 0;
3999 }
void testMatVec3()
Definition: matvectest.cc:2632
int NLoopsAss
Definition: matvectest.cc:83
void MatManip_test(int NLoops)
Definition: matvectest.cc:3645
#define MATVEC_DEBUG
Definition: matvectest.cc:66
void testSubVecAssMatVec()
Definition: matvectest.cc:2748
void testScalarTypeTraits()
Definition: matvectest.cc:92
void func2mulad_dv(const doublereal x[], const doublereal xd[], const doublereal y[], const doublereal yd[], doublereal z[], doublereal zd[], const integer &n, const integer &nbdirs)
void testMatVecDouble2()
Definition: matvectest.cc:832
void func2addad_dv(const doublereal x[], const doublereal xd[], const doublereal y[], const doublereal yd[], doublereal z[], doublereal zd[], const integer &n, const integer &nbdirs)
void testSubVecAss()
Definition: matvectest.cc:2705
void testMatVecProductGradient()
Definition: matvectest.cc:1383
#define GRADIENT_DEBUG
Definition: matvectest.cc:70
void testSolve()
Definition: matvectest.cc:2843
void MatDynamic_test(index_type iNumRows, index_type iNumCols, index_type iNumLoops)
Definition: matvectest.cc:3196
void testMatVecProduct()
Definition: matvectest.cc:850
void testInv()
Definition: matvectest.cc:2807
void Mat3xN_test(int N, int M)
Definition: matvectest.cc:3116
int NLoops
Definition: matvectest.cc:82
void MatNxN_test(int N, int M)
Definition: matvectest.cc:3156

Here is the call graph for this function:

void Mat3xN_test ( int  N,
int  M 
)

Definition at line 3116 of file matvectest.cc.

References bCompare(), Mat3xN::iGetNumCols(), Mat3xN::iGetNumRows(), mbdyn_clock_time(), and grad::sqrt().

Referenced by main().

3116  {
3117  Mat3xN A(N, 0.);
3118 
3119  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3120  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3121  A(i, j) = 100 * i + j;
3122  }
3123  }
3124 
3125  Vector<doublereal, DYNAMIC_SIZE> x1(A.iGetNumCols()), x2(A.iGetNumCols()), x(A.iGetNumCols());
3126 
3127  for (index_type i = 1; i <= x.iGetNumRows(); ++i) {
3128  x1(i) = i;
3129  x2(i) = 10 * i;
3130  }
3131 
3132  Vector<doublereal, 3> b = A * x;
3133 
3134  const double start = mbdyn_clock_time();
3135 
3136  for (int i = 0; i < M; ++i) {
3137  x = x1 * 3. + x2 * 5.;
3138  b = A * x;
3139  }
3140 
3141  std::cerr << "Mat3xN: " << (mbdyn_clock_time() - start) / M << "s\n";
3142 
3143  const doublereal tol = sqrt(std::numeric_limits<doublereal>::epsilon());
3144 
3145  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3146  doublereal b_i = 0.;
3147 
3148  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3149  b_i += A(i, j) * (3. * x1(j) + 5. * x2(j));
3150  }
3151 
3152  assert(bCompare(b_i, b(i), tol));
3153  }
3154 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
double mbdyn_clock_time()
Definition: clock_time.cc:51
integer index_type
Definition: gradient.h:104
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<index_type N_SIZE>
void Mat3xN_test_grad ( int  iNumDeriv,
int  N,
int  M 
)

Definition at line 3238 of file matvectest.cc.

References bCompare(), dof, grad::DYNAMIC_SIZE, Mat3xN::iGetNumCols(), Mat3xN::iGetNumRows(), grad::MapVectorBase::LOCAL, mbdyn_clock_time(), and grad::sqrt().

3238  {
3239  assert((N_SIZE == 0) || (N_SIZE >= iNumDeriv));
3240 
3241  LocalDofMap dof;
3242 
3243  Mat3xN A(N, 0.);
3244 
3245  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3246  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3247  A(i, j) = 100 * i + j;
3248  }
3249  }
3250 
3251  Vector<Gradient<N_SIZE>, DYNAMIC_SIZE> x1(A.iGetNumCols()), x2(A.iGetNumCols()), x(A.iGetNumCols());
3252 
3253  for (index_type i = 1; i <= x.iGetNumRows(); ++i) {
3254  x1(i).SetValuePreserve(i);
3255  x1(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3256 
3257  for (index_type k = 0; k < iNumDeriv; ++k) {
3258  x1(i).SetDerivativeLocal(k, -1. * k);
3259  }
3260 
3261  x2(i).SetValuePreserve(10 * i);
3262  x2(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3263 
3264  for (index_type k = 0; k < iNumDeriv; ++k) {
3265  x2(i).SetDerivativeLocal(k, 10. * k);
3266  }
3267  }
3268 
3269  Vector<Gradient<N_SIZE>, 3> b = A * x;
3270 
3271  const double start = mbdyn_clock_time();
3272 
3273  for (int i = 0; i < M; ++i) {
3274  x = x1 * 3. + x2 * 5.;
3275  b = A * x;
3276  }
3277 
3278  std::cerr << "Mat3xN * Gradient: " << (mbdyn_clock_time() - start) / M << "s\n";
3279 
3280  const doublereal tol = sqrt(std::numeric_limits<doublereal>::epsilon());
3281 
3282  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3283  Gradient<N_SIZE> b_i;
3284 
3285  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3286  b_i += A(i, j) * (3. * x1(j) + 5. * x2(j));
3287  }
3288 
3289  assert(bCompare(b_i, b(i), tol));
3290  }
3291 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
static const index_type DYNAMIC_SIZE
Definition: gradient.h:141
double mbdyn_clock_time()
Definition: clock_time.cc:51
integer index_type
Definition: gradient.h:104
static const char * dof[]
Definition: drvdisp.cc:195
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<index_type N_SIZE>
void Mat3xNT_test_grad ( int  iNumDeriv,
int  N,
int  M 
)

Definition at line 3294 of file matvectest.cc.

References bCompare(), dof, grad::DYNAMIC_SIZE, Mat3xN::iGetNumCols(), Mat3xN::iGetNumRows(), grad::MapVectorBase::LOCAL, mbdyn_clock_time(), grad::sqrt(), and grad::Transpose().

3294  {
3295  assert((N_SIZE == 0) || (N_SIZE >= iNumDeriv));
3296 
3297  LocalDofMap dof;
3298 
3299  Mat3xN A(N, 0.);
3300 
3301  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3302  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3303  A(i, j) = 100 * i + j;
3304  }
3305  }
3306 
3307  Vector<Gradient<N_SIZE>, 3> x1(A.iGetNumRows()), x2(A.iGetNumRows());
3308 
3309  for (index_type i = 1; i <= x1.iGetNumRows(); ++i) {
3310  x1(i).SetValuePreserve(i);
3311  x1(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3312 
3313  for (index_type k = 0; k < iNumDeriv; ++k) {
3314  x1(i).SetDerivativeLocal(k, -1. * k);
3315  }
3316 
3317  x2(i).SetValuePreserve(10 * i);
3318  x2(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3319 
3320  for (index_type k = 0; k < iNumDeriv; ++k) {
3321  x2(i).SetDerivativeLocal(k, 10. * k);
3322  }
3323  }
3324 
3326 
3327  const double start = mbdyn_clock_time();
3328 
3329  for (int i = 0; i < M; ++i) {
3330  b = Transpose(A) * (x1 * 3. + x2 * 5.);
3331  }
3332 
3333  std::cerr << "Transpose(Mat3xN) * Gradient: " << (mbdyn_clock_time() - start) / M << "s\n";
3334 
3335  const doublereal tol = sqrt(std::numeric_limits<doublereal>::epsilon());
3336 
3337  for (index_type i = 1; i <= A.iGetNumCols(); ++i) {
3338  Gradient<N_SIZE> b_i;
3339 
3340  for (index_type j = 1; j <= A.iGetNumRows(); ++j) {
3341  b_i += A(j, i) * (3. * x1(j) + 5. * x2(j));
3342  }
3343 
3344  assert(bCompare(b_i, b(i), tol));
3345  }
3346 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
MatrixExpression< TransposedMatrix< MatrixDirectExpr< Matrix< T, N_rows, N_cols > > >, N_cols, N_rows > Transpose(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2206
static const index_type DYNAMIC_SIZE
Definition: gradient.h:141
double mbdyn_clock_time()
Definition: clock_time.cc:51
integer index_type
Definition: gradient.h:104
static const char * dof[]
Definition: drvdisp.cc:195
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

void MatDynamic_test ( index_type  iNumRows,
index_type  iNumCols,
index_type  iNumLoops 
)

Definition at line 3196 of file matvectest.cc.

References bCompare(), grad::Matrix< T, N_rows, N_cols >::iGetNumCols(), grad::Matrix< T, N_rows, N_cols >::iGetNumRows(), mbdyn_clock_time(), and grad::sqrt().

Referenced by main().

3196  {
3197  Matrix<doublereal, DYNAMIC_SIZE, DYNAMIC_SIZE> A(iNumRows, iNumCols);
3198 
3199  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3200  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3201  A(i, j) = 100 * i + j;
3202  }
3203  }
3204 
3205  Vector<doublereal, DYNAMIC_SIZE> x1(A.iGetNumCols()), x2(A.iGetNumCols()), x(A.iGetNumCols());
3206 
3207  for (index_type i = 1; i <= x.iGetNumRows(); ++i) {
3208  x1(i) = i;
3209  x2(i) = 10 * i;
3210  }
3211 
3213 
3214  const double start = mbdyn_clock_time();
3215 
3216  for (int i = 0; i < iNumLoops; ++i) {
3217  x = x1 * 3. + x2 * 5.;
3218  b = A * x;
3219  }
3220 
3221  std::cerr << "Matrix<DYNAMIC_SIZE, DYNAMIC_SIZE>: " << (mbdyn_clock_time() - start) / iNumLoops << "s\n";
3222 
3223  const doublereal tol = sqrt(std::numeric_limits<doublereal>::epsilon());
3224 
3225  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3226  doublereal b_i = 0.;
3227 
3228  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3229  b_i += A(i, j) * (3. * x1(j) + 5. * x2(j));
3230  }
3231 
3232  assert(bCompare(b_i, b(i), tol));
3233  }
3234 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
double mbdyn_clock_time()
Definition: clock_time.cc:51
integer index_type
Definition: gradient.h:104
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<index_type N_SIZE>
void MatDynamic_test_grad ( index_type  iNumDeriv,
index_type  iNumRows,
index_type  iNumCols,
int  iNumLoops 
)

Definition at line 3461 of file matvectest.cc.

References bCompare(), dof, grad::DYNAMIC_SIZE, grad::Matrix< T, N_rows, N_cols >::iGetNumCols(), grad::Matrix< T, N_rows, N_cols >::iGetNumRows(), grad::MapVectorBase::LOCAL, mbdyn_clock_time(), and grad::sqrt().

3462 {
3463  assert((N_SIZE == 0) || (N_SIZE >= iNumDeriv));
3464 
3465  LocalDofMap dof;
3466 
3467  Matrix<Gradient<N_SIZE>, DYNAMIC_SIZE, DYNAMIC_SIZE> A(iNumRows, iNumCols);
3468 
3469  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3470  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3471  A(i, j).SetValuePreserve(100 * i + j);
3472  A(i, j).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3473 
3474  for (index_type k = 0; k < iNumDeriv; ++k) {
3475  A(i, j).SetDerivativeLocal(k, 1000. * i + 100. * j + k + 1);
3476  }
3477  }
3478  }
3479 
3480  Vector<Gradient<N_SIZE>, DYNAMIC_SIZE> x1(A.iGetNumCols()), x2(A.iGetNumCols()), x(A.iGetNumCols());
3481 
3482  for (index_type i = 1; i <= x.iGetNumRows(); ++i) {
3483  x1(i).SetValuePreserve(i);
3484  x1(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3485 
3486  for (index_type k = 0; k < iNumDeriv; ++k) {
3487  x1(i).SetDerivativeLocal(k, -1. * k);
3488  }
3489 
3490  x2(i).SetValuePreserve(10 * i);
3491  x2(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3492 
3493  for (index_type k = 0; k < iNumDeriv; ++k) {
3494  x2(i).SetDerivativeLocal(k, 10. * k);
3495  }
3496  }
3497 
3498  Vector<Gradient<N_SIZE>, DYNAMIC_SIZE> b = A * x;
3499 
3500  const double start = mbdyn_clock_time();
3501 
3502  for (int i = 0; i < iNumLoops; ++i) {
3503  x = x1 * 3. + x2 * 5.;
3504  b = A * x;
3505  }
3506 
3507  std::cerr << "Matrix<Gradient,DYNAMIC_SIZE,DYNAMIC_SIZE> * Gradient: " << (mbdyn_clock_time() - start) / iNumLoops << "s\n";
3508 
3509  const doublereal tol = sqrt(std::numeric_limits<doublereal>::epsilon());
3510 
3511  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3512  Gradient<N_SIZE> b_i;
3513 
3514  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3515  b_i += A(i, j) * (3. * x1(j) + 5. * x2(j));
3516  }
3517 
3518  assert(bCompare(b_i, b(i), tol));
3519  }
3520 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
static const index_type DYNAMIC_SIZE
Definition: gradient.h:141
double mbdyn_clock_time()
Definition: clock_time.cc:51
integer index_type
Definition: gradient.h:104
static const char * dof[]
Definition: drvdisp.cc:195
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<index_type N_ROWS, index_type N_COLS>
void MatDynamicT_test ( index_type  iNumRows,
index_type  iNumCols,
int  iNumLoops 
)

Definition at line 3523 of file matvectest.cc.

References bCompare(), grad::DYNAMIC_SIZE, grad::Matrix< T, N_rows, N_cols >::iGetNumCols(), grad::Matrix< T, N_rows, N_cols >::iGetNumRows(), mbdyn_clock_time(), grad::sqrt(), and grad::Transpose().

3524 {
3525  assert((N_ROWS == iNumRows) || (N_ROWS == DYNAMIC_SIZE));
3526  assert((N_COLS == iNumCols) || (N_COLS == DYNAMIC_SIZE));
3527 
3528  Matrix<doublereal, N_ROWS, N_COLS> A(iNumRows, iNumCols);
3529 
3530  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3531  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3532  A(i, j) = 100 * i + j;
3533  }
3534  }
3535 
3536  Vector<doublereal, N_ROWS> x1(A.iGetNumRows()), x2(A.iGetNumRows());
3537 
3538  for (index_type i = 1; i <= x1.iGetNumRows(); ++i) {
3539  x1(i) = i;
3540  x2(i) = 10 * i;
3541  }
3542 
3544 
3545  const double start = mbdyn_clock_time();
3546 
3547  for (int i = 0; i < iNumLoops; ++i) {
3548  b = Transpose(A) * (x1 * 3. + x2 * 5.);
3549  }
3550 
3551  std::cerr << "Transpose(Matrix<doublereal>,"
3552  << iNumRows << "(" << N_ROWS << ")," << iNumCols << "(" << N_COLS << ")"
3553  << ">) * Vector<doublereal>,"
3554  << iNumRows << "(" << N_ROWS << ")>: " << (mbdyn_clock_time() - start) / iNumLoops << "s\n";
3555 
3556  const doublereal tol = sqrt(std::numeric_limits<doublereal>::epsilon());
3557 
3558  for (index_type i = 1; i <= A.iGetNumCols(); ++i) {
3559  doublereal b_i = 0.;
3560 
3561  for (index_type j = 1; j <= A.iGetNumRows(); ++j) {
3562  b_i += A(j, i) * (3. * x1(j) + 5. * x2(j));
3563  }
3564 
3565  assert(bCompare(b_i, b(i), tol));
3566  }
3567 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
MatrixExpression< TransposedMatrix< MatrixDirectExpr< Matrix< T, N_rows, N_cols > > >, N_cols, N_rows > Transpose(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2206
static const index_type DYNAMIC_SIZE
Definition: gradient.h:141
double mbdyn_clock_time()
Definition: clock_time.cc:51
integer index_type
Definition: gradient.h:104
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<index_type N_DERIV, index_type N_ROWS, index_type N_COLS>
void MatDynamicT_test_grad ( index_type  iNumDeriv,
index_type  iNumRows,
index_type  iNumCols,
int  iNumLoops 
)

Definition at line 3570 of file matvectest.cc.

References bCompare(), dof, grad::DYNAMIC_SIZE, grad::Matrix< T, N_rows, N_cols >::GetCol(), grad::Matrix< T, N_rows, N_cols >::GetRow(), grad::Matrix< T, N_rows, N_cols >::iGetNumCols(), grad::Matrix< T, N_rows, N_cols >::iGetNumRows(), grad::MapVectorBase::LOCAL, mbdyn_clock_time(), grad::sqrt(), and grad::Transpose().

3571 {
3572  assert((N_DERIV == 0) || (N_DERIV >= iNumDeriv));
3573  assert((N_ROWS == iNumRows) || (N_ROWS == DYNAMIC_SIZE));
3574  assert((N_COLS == iNumCols) || (N_COLS == DYNAMIC_SIZE));
3575 
3576  LocalDofMap dof;
3577 
3578  Matrix<Gradient<N_DERIV>, N_ROWS, N_COLS> A(iNumRows, iNumCols);
3579 
3580  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3581  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3582  A(i, j).SetValuePreserve(100 * i + j);
3583  A(i, j).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3584 
3585  for (index_type k = 0; k < iNumDeriv; ++k) {
3586  A(i, j).SetDerivativeLocal(k, 1000. * i + 100. * j + k + 1);
3587  }
3588  }
3589  }
3590 
3591  Vector<Gradient<N_DERIV>, N_ROWS> x1(A.iGetNumRows()), x2(A.iGetNumRows());
3592 
3593  for (index_type i = 1; i <= x1.iGetNumRows(); ++i) {
3594  x1(i).SetValuePreserve(i);
3595  x1(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3596 
3597  for (index_type k = 0; k < iNumDeriv; ++k) {
3598  x1(i).SetDerivativeLocal(k, -1. * k);
3599  }
3600 
3601  x2(i).SetValuePreserve(10 * i);
3602  x2(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3603 
3604  for (index_type k = 0; k < iNumDeriv; ++k) {
3605  x2(i).SetDerivativeLocal(k, 10. * k);
3606  }
3607  }
3608 
3609  Vector<Gradient<N_DERIV>, N_COLS> b = Transpose(A) * x1;
3610 
3611  const double start = mbdyn_clock_time();
3612 
3613  for (int i = 0; i < iNumLoops; ++i) {
3614  b = Transpose(A) * (x1 * 3. + x2 * 5.);
3615  }
3616 
3617  std::cerr << "Transpose(Matrix<Gradient<" << iNumDeriv << "(" << N_DERIV << ")"
3618  << ">," << iNumRows << "(" << N_ROWS << ")," << iNumCols << "(" << N_COLS << ")"
3619  << ">) * Vector<Gradient<" << iNumDeriv << "(" << N_DERIV << ")"
3620  << ">," << iNumRows << "(" << N_ROWS << ")>: " << (mbdyn_clock_time() - start) / iNumLoops << "s\n";
3621 
3622  const doublereal tol = sqrt(std::numeric_limits<doublereal>::epsilon());
3623 
3624  for (index_type i = 1; i <= A.iGetNumCols(); ++i) {
3625  Gradient<N_DERIV> b_i;
3626 
3627  for (index_type j = 1; j <= A.iGetNumRows(); ++j) {
3628  b_i += A(j, i) * (3. * x1(j) + 5. * x2(j));
3629  }
3630 
3631  assert(bCompare(b_i, b(i), tol));
3632  }
3633 
3634  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3635  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3636  assert(bCompare(A(i, j), A.GetRow(i)(j), 0.));
3637  assert(bCompare(A(i, j), A.GetCol(j)(i), 0.));
3638  assert(bCompare(A(i, j), Transpose(A)(j, i), 0.));
3639  assert(bCompare(A(i, j), Transpose(A).GetCol(i)(j), 0.));
3640  assert(bCompare(A(i, j), Transpose(A).GetRow(j)(i), 0.));
3641  }
3642  }
3643 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
MatrixExpression< TransposedMatrix< MatrixDirectExpr< Matrix< T, N_rows, N_cols > > >, N_cols, N_rows > Transpose(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2206
static const index_type DYNAMIC_SIZE
Definition: gradient.h:141
double mbdyn_clock_time()
Definition: clock_time.cc:51
integer index_type
Definition: gradient.h:104
static const char * dof[]
Definition: drvdisp.cc:195
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

void MatManip_test ( int  NLoops)

Definition at line 3645 of file matvectest.cc.

References bCompare(), Eye3, grad::fabs(), M_PI, grad::MatCrossVec(), CGR_Rot::MatG, grad::MatGVec(), CGR_Rot::MatR, grad::MatRVec(), NLoops, Vec3::Norm(), grad::sqrt(), RotManip::VecRot(), and grad::VecRotMat().

Referenced by main().

3645  {
3646  const doublereal tol1 = 10. * std::numeric_limits<doublereal>::epsilon();
3647  const doublereal tol2 = 1e-4 * sqrt(tol1);
3648  const doublereal alpha = 1. - sqrt(tol2);
3649 
3650  srand(0);
3651 
3652  for (int k = 0; k < 3 * NLoops; ++k) {
3654  Vec3 g0_;
3655 
3656  for (int i = 1; i <= 3; ++i) {
3657  g0_(i) = (2. * rand() / RAND_MAX - 1.);
3658  }
3659 
3660  g0_ *= (2. * rand() / RAND_MAX - 1.) * alpha * M_PI / g0_.Norm();
3661 
3662  if (k >= NLoops && k < 2 * NLoops) {
3663  g0_ *= sqrt(std::numeric_limits<doublereal>::epsilon());
3664  } else if (k >= 2 * NLoops) {
3665  g0_ *= std::numeric_limits<doublereal>::epsilon();
3666  }
3667 
3668  g0 = g0_;
3669 
3670  const Mat3x3 G1(CGR_Rot::MatG, g0_);
3671  const Mat3x3 R1(CGR_Rot::MatR, g0_);
3672  const Mat3x3 X1(1., g0_);
3673  const Matrix<doublereal, 3, 3> G2(MatGVec(g0));
3675  const Matrix<doublereal, 3, 3> X2(MatCrossVec(g0, 1.));
3676 
3677  for (index_type i = 1; i <= 3; ++i) {
3678  for (index_type j = 1; j <= 3; ++j) {
3679  assert(bCompare(G1(i, j), G2(i, j), tol1));
3680  assert(bCompare(R1(i, j), R2(i, j), tol1));
3681  assert(bCompare(X1(i, j), X2(i, j), tol1));
3682  }
3683  }
3684 
3685  if (k == 0) {
3686  R2 = ::Eye3;
3687  } else if (k == 1) {
3688  R2(1, 1) = -1;
3689  R2(1, 2) = 0;
3690  R2(1, 3) = 0;
3691  R2(2, 1) = 0;
3692  R2(2, 2) = -1;
3693  R2(2, 3) = 0;
3694  R2(3, 1) = 0;
3695  R2(3, 2) = 0;
3696  R2(3, 3) = 1;
3697  } else if (k == 2) {
3698  R2(1, 1) = -1;
3699  R2(1, 2) = 0;
3700  R2(1, 3) = 0;
3701  R2(2, 1) = 0;
3702  R2(2, 2) = 1;
3703  R2(2, 3) = 0;
3704  R2(3, 1) = 0;
3705  R2(3, 2) = 0;
3706  R2(3, 3) = -1;
3707  } else if (k == 3) {
3708  R2(1, 1) = 1;
3709  R2(1, 2) = 0;
3710  R2(1, 3) = 0;
3711  R2(2, 1) = 0;
3712  R2(2, 2) = -1;
3713  R2(2, 3) = 0;
3714  R2(3, 1) = 0;
3715  R2(3, 2) = 0;
3716  R2(3, 3) = -1;
3717  } else if (k == 4) {
3718  R2(1,1)=-2.2841125213377644e-01;
3719  R2(1,2)=9.5997603033895429e-01;
3720  R2(1,3)=1.6209355654480440e-01;
3721  R2(2,1)=9.5997603033895418e-01;
3722  R2(2,2)=1.9435901751267337e-01;
3723  R2(2,3)=2.0166951551033063e-01;
3724  R2(3,1)=1.6209355654480423e-01;
3725  R2(3,2)=2.0166951551033083e-01;
3726  R2(3,3)=-9.6594776537889704e-01;
3727  }
3728 
3729  Mat3x3 R2_;
3730 
3731  for (index_type i = 1; i <= 3; ++i) {
3732  for (index_type j = 1; j <= 3; ++j) {
3733  R2_(i, j) = R2(i, j);
3734  }
3735  }
3736 
3737  const Vec3 g1(RotManip::VecRot(R2_));
3738  const Vector<doublereal, 3> g2(VecRotMat(R2));
3739 
3740  for (index_type i = 1; i <= 3; ++i) {
3741  assert(bCompare(g1(i), g2(i), std::numeric_limits<doublereal>::epsilon()) || bCompare(fabs(g1(i) - g2(i)), 2 * M_PI, std::numeric_limits<doublereal>::epsilon()));
3742  }
3743  }
3744 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
#define M_PI
Definition: gradienttest.cc:67
Definition: matvec3.h:98
doublereal Norm(void) const
Definition: matvec3.h:263
const Mat3x3 Eye3(1., 0., 0., 0., 1., 0., 0., 0., 1.)
integer index_type
Definition: gradient.h:104
GradientExpression< UnaryExpr< FuncFabs, Expr > > fabs(const GradientExpression< Expr > &u)
Definition: gradient.h:2973
MatrixInit< MatGInit< T, VectorDirectExpr< Vector< T, 3 > > >, T, 3, 3 > MatGVec(const Vector< T, 3 > &g)
Definition: matvec.h:2791
MatrixInit< MatRInit< T, VectorDirectExpr< Vector< T, 3 > > >, T, 3, 3 > MatRVec(const Vector< T, 3 > &g)
Definition: matvec.h:2803
Vec3 VecRot(const Mat3x3 &Phi)
Definition: Rot.cc:136
const MatG_Manip MatG
Definition: matvec3.cc:646
const MatR_Manip MatR
Definition: matvec3.cc:645
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
VectorInit< VecRotInit< T, MatrixDirectExpr< Matrix< T, 3, 3 > > >, T, 3 > VecRotMat(const Matrix< T, 3, 3 > &R)
Definition: matvec.h:2984
double doublereal
Definition: colamd.c:52
MatrixInit< MatCrossInit< T, VectorDirectExpr< Vector< T, 3 > > >, T, 3, 3 > MatCrossVec(const Vector< T, 3 > &v, doublereal d=0.)
Definition: matvec.h:2761
int NLoops
Definition: matvectest.cc:82

Here is the call graph for this function:

void MatNxN_test ( int  N,
int  M 
)

Definition at line 3156 of file matvectest.cc.

References bCompare(), MatNxN::iGetNumCols(), MatNxN::iGetNumRows(), mbdyn_clock_time(), and grad::sqrt().

Referenced by main().

3156  {
3157  MatNxN A(N, 0.);
3158 
3159  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3160  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3161  A(i, j) = 100 * i + j;
3162  }
3163  }
3164 
3165  Vector<doublereal, DYNAMIC_SIZE> x1(A.iGetNumCols()), x2(A.iGetNumCols()), x(A.iGetNumCols());
3166 
3167  for (index_type i = 1; i <= x.iGetNumRows(); ++i) {
3168  x1(i) = i;
3169  x2(i) = 10 * i;
3170  }
3171 
3173 
3174  const double start = mbdyn_clock_time();
3175 
3176  for (int i = 0; i < M; ++i) {
3177  x = x1 * 3. + x2 * 5.;
3178  b = A * x;
3179  }
3180 
3181  std::cerr << "MatNxN: " << (mbdyn_clock_time() - start) / M << "s\n";
3182 
3183  const doublereal tol = sqrt(std::numeric_limits<doublereal>::epsilon());
3184 
3185  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3186  doublereal b_i = 0.;
3187 
3188  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3189  b_i += A(i, j) * (3. * x1(j) + 5. * x2(j));
3190  }
3191 
3192  assert(bCompare(b_i, b(i), tol));
3193  }
3194 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
double mbdyn_clock_time()
Definition: clock_time.cc:51
integer index_type
Definition: gradient.h:104
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<index_type N_SIZE>
void MatNxN_test_grad ( int  iNumDeriv,
int  N,
int  M 
)

Definition at line 3404 of file matvectest.cc.

References bCompare(), dof, grad::DYNAMIC_SIZE, MatNxN::iGetNumCols(), MatNxN::iGetNumRows(), grad::MapVectorBase::LOCAL, mbdyn_clock_time(), and grad::sqrt().

3405 {
3406  assert((N_SIZE == 0) || (N_SIZE >= iNumDeriv));
3407 
3408  LocalDofMap dof;
3409 
3410  MatNxN A(N, 0.);
3411 
3412  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3413  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3414  A(i, j) = 100 * i + j;
3415  }
3416  }
3417 
3418  Vector<Gradient<N_SIZE>, DYNAMIC_SIZE> x1(A.iGetNumCols()), x2(A.iGetNumCols()), x(A.iGetNumCols());
3419 
3420  for (index_type i = 1; i <= x.iGetNumRows(); ++i) {
3421  x1(i).SetValuePreserve(i);
3422  x1(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3423 
3424  for (index_type k = 0; k < iNumDeriv; ++k) {
3425  x1(i).SetDerivativeLocal(k, -1. * k);
3426  }
3427 
3428  x2(i).SetValuePreserve(10 * i);
3429  x2(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3430 
3431  for (index_type k = 0; k < iNumDeriv; ++k) {
3432  x2(i).SetDerivativeLocal(k, 10. * k);
3433  }
3434  }
3435 
3437 
3438  const double start = mbdyn_clock_time();
3439 
3440  for (int i = 0; i < M; ++i) {
3441  x = x1 * 3. + x2 * 5.;
3442  b = A * x;
3443  }
3444 
3445  std::cerr << "MatNxN * Gradient: " << (mbdyn_clock_time() - start) / M << "s\n";
3446 
3447  const doublereal tol = sqrt(std::numeric_limits<doublereal>::epsilon());
3448 
3449  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3450  Gradient<N_SIZE> b_i;
3451 
3452  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3453  b_i += A(i, j) * (3. * x1(j) + 5. * x2(j));
3454  }
3455 
3456  assert(bCompare(b_i, b(i), tol));
3457  }
3458 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
static const index_type DYNAMIC_SIZE
Definition: gradient.h:141
double mbdyn_clock_time()
Definition: clock_time.cc:51
integer index_type
Definition: gradient.h:104
static const char * dof[]
Definition: drvdisp.cc:195
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<index_type N_SIZE>
void MatNxNT_test_grad ( int  iNumDeriv,
int  N,
int  M 
)

Definition at line 3349 of file matvectest.cc.

References bCompare(), dof, grad::DYNAMIC_SIZE, MatNxN::iGetNumCols(), MatNxN::iGetNumRows(), grad::MapVectorBase::LOCAL, mbdyn_clock_time(), grad::sqrt(), and grad::Transpose().

3349  {
3350  assert((N_SIZE == 0) || (N_SIZE >= iNumDeriv));
3351 
3352  LocalDofMap dof;
3353 
3354  MatNxN A(N, 0.);
3355 
3356  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
3357  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
3358  A(i, j) = 100 * i + j;
3359  }
3360  }
3361 
3362  Vector<Gradient<N_SIZE>, DYNAMIC_SIZE> x1(A.iGetNumRows()), x2(A.iGetNumRows());
3363 
3364  for (index_type i = 1; i <= x1.iGetNumRows(); ++i) {
3365  x1(i).SetValuePreserve(i);
3366  x1(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3367 
3368  for (index_type k = 0; k < iNumDeriv; ++k) {
3369  x1(i).SetDerivativeLocal(k, -1. * k);
3370  }
3371 
3372  x2(i).SetValuePreserve(10 * i);
3373  x2(i).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::LOCAL, 0.);
3374 
3375  for (index_type k = 0; k < iNumDeriv; ++k) {
3376  x2(i).SetDerivativeLocal(k, 10. * k);
3377  }
3378  }
3379 
3381 
3382  const double start = mbdyn_clock_time();
3383 
3384  for (int i = 0; i < M; ++i) {
3385  b = Transpose(A) * (x1 * 3. + x2 * 5.);
3386  }
3387 
3388  std::cerr << "Transpose(MatNxN) * Gradient: " << (mbdyn_clock_time() - start) / M << "s\n";
3389 
3390  const doublereal tol = sqrt(std::numeric_limits<doublereal>::epsilon());
3391 
3392  for (index_type i = 1; i <= A.iGetNumCols(); ++i) {
3393  Gradient<N_SIZE> b_i;
3394 
3395  for (index_type j = 1; j <= A.iGetNumRows(); ++j) {
3396  b_i += A(j, i) * (3. * x1(j) + 5. * x2(j));
3397  }
3398 
3399  assert(bCompare(b_i, b(i), tol));
3400  }
3401 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
MatrixExpression< TransposedMatrix< MatrixDirectExpr< Matrix< T, N_rows, N_cols > > >, N_cols, N_rows > Transpose(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2206
static const index_type DYNAMIC_SIZE
Definition: gradient.h:141
double mbdyn_clock_time()
Definition: clock_time.cc:51
integer index_type
Definition: gradient.h:104
static const char * dof[]
Definition: drvdisp.cc:195
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<typename T , index_type N_rows>
T Norm_1 ( const Vector< T, N_rows > &  u)
inline

Definition at line 1274 of file matvectest.cc.

References grad::Dot(), and grad::sqrt().

1274  {
1275  return sqrt(Dot(u, u));
1276 }
DotTraits< VectorExprLhs, VectorExprRhs, N_rows, N_rows >::ExpressionType Dot(const VectorExpression< VectorExprLhs, N_rows > &u, const VectorExpression< VectorExprRhs, N_rows > &v)
Definition: matvec.h:3133
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974

Here is the call graph for this function:

doublereal random1 ( )

Definition at line 88 of file matvectest.cc.

Referenced by callFunc2(), func(), and testMatVec3().

88  {
89  return 2 * (doublereal(rand()) / RAND_MAX) - 1;
90 }
double doublereal
Definition: colamd.c:52
void testInv ( )

Definition at line 2807 of file matvectest.cc.

References bCompare(), grad::Det(), grad::Inv(), grad::sqrt(), and grad::Tabular().

Referenced by main().

2807  {
2809 
2810  A(1, 1) = 0.658371336838182;
2811  A(1, 2) = 0.733036075010795;
2812  A(2, 1) = 0.483830962404444;
2813  A(2, 2) = 0.395950513263802;
2814 
2815  const doublereal detA = Det(A);
2816  const Matrix<doublereal, 2, 2> invA = Inv(A);
2817  const Matrix<doublereal, 2, 2> B1 = invA * A;
2818  const Matrix<doublereal, 2, 2> B2 = A * invA;
2819  std::cout << "A=" << Tabular(A) << std::endl;
2820  std::cout << "Inv(A)=" << Tabular(invA) << std::endl;
2821  std::cout << "Det(A)=" << detA << std::endl;
2822  std::cout << "Inv(A)*A=" << Tabular(B1) << std::endl;
2823  std::cout << "A * Inv(A)=" << Tabular(B2) << std::endl;
2824 
2825  const doublereal dTol = sqrt(std::numeric_limits<doublereal>::epsilon());
2826 
2827  assert(bCompare(B1(1, 1), 1., dTol));
2828  assert(bCompare(B2(1, 1), 1., dTol));
2829  assert(bCompare(B1(2, 2), 1., dTol));
2830  assert(bCompare(B2(2, 2), 1., dTol));
2831  assert(bCompare(B1(1, 2), 0., dTol));
2832  assert(bCompare(B2(1, 2), 0., dTol));
2833  assert(bCompare(B1(2, 1), 0., dTol));
2834  assert(bCompare(B2(2, 1), 0., dTol));
2835 
2836  assert(bCompare(invA(1, 1), -4.21299780160758, dTol));
2837  assert(bCompare(invA(2, 2), -7.00521126207687, dTol));
2838  assert(bCompare(invA(1, 2), 7.79965998039245, dTol));
2839  assert(bCompare(invA(2, 1), 5.14806449967026, dTol));
2840  assert(bCompare(detA, -0.0939830809103952, dTol));
2841 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
T Det(const Matrix< T, 2, 2 > &A)
Definition: matvec.h:3277
Matrix< T, 2, 2 > Inv(const Matrix< T, 2, 2 > &A)
Definition: matvec.h:3282
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
TabularMatrixView< T, N_rows, N_cols > Tabular(const Matrix< T, N_rows, N_cols > &A, int iColWidth=10)
Definition: matvec.h:3012
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<index_type N>
void testMatVec ( )

Definition at line 2883 of file matvectest.cc.

References bCompare().

2883  {
2884  doublereal c_MatVecGradient[N], cd_MatVecGradient[N][N];
2885  doublereal c_MatVecDouble[N];
2886 
2887  std::cerr << "---------------------------\ntestMatVecGradient<" << N << ">()\n";
2888  testMatVecGradient<N>(c_MatVecGradient, cd_MatVecGradient);
2889 
2890  std::cerr << "---------------------------\ntestMatVecDouble<" << N << ">()\n";
2891  testMatVecDouble<N>(c_MatVecDouble);
2892 
2893 #ifdef HAVE_BLITZ
2894  doublereal c_MatVecDoubleBlitz[N];
2895  doublereal c_MatVecGradientBlitz[N], cd_MatVecGradientBlitz[N][N];
2896  std::cerr << "---------------------------\ntestMatVecDoubleBlitz<" << N << ">()\n";
2897  testMatVecDoubleBlitz<N>(c_MatVecDoubleBlitz);
2898 
2899  std::cerr << "---------------------------\ntestMatVecGradientBlitz<" << N << ">()\n";
2900  testMatVecGradientBlitz<N>(c_MatVecGradientBlitz, cd_MatVecGradientBlitz);
2901 #endif // HAVE_BLITZ
2902 
2903  const doublereal dTol = 10 * std::numeric_limits<scalar_deriv_type>::epsilon();
2904 
2905  for (int i = 0; i < N; ++i) {
2906  assert(bCompare(c_MatVecGradient[i], c_MatVecDouble[i], dTol));
2907 #ifdef HAVE_BLITZ
2908  assert(bCompare(c_MatVecGradient[i], c_MatVecDoubleBlitz[i], dTol));
2909  assert(bCompare(c_MatVecGradient[i], c_MatVecGradientBlitz[i], dTol));
2910 
2911  for (int j = 0; j < N; ++j) {
2912  assert(bCompare(cd_MatVecGradient[i][j], cd_MatVecGradientBlitz[i][j]));
2913  }
2914 #endif
2915  }
2916 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

void testMatVec3 ( )

Definition at line 2632 of file matvectest.cc.

References MatCross, MatCrossCross, grad::MatCrossCrossVec(), grad::MatCrossVec(), CGR_Rot::MatG, grad::MatGVec(), NLoops, and random1().

Referenced by main().

2632  {
2633  srand(0);
2634 
2635  for (int n = 0; n < NLoops; ++n) {
2636  Vector<doublereal, 3> g1, v1;
2637  Vec3 g2, v2;
2638  for (index_type i = 1; i <= 3; ++i) {
2639  g2(i) = g1(i) = random1() * 1e-1;
2640  v2(i) = v1(i) = random1() * 1e1;
2641  }
2642 
2644  Mat3x3 R2(CGR_Rot::MatG, g2);
2646  Mat3x3 C2(MatCross, g2);
2648  Mat3x3 CC2(MatCrossCross, g2, g2);
2649  Vector<doublereal, 3> CCv1 = CC1 * v1;
2650  Vec3 CCv2 = CC2 * v2;
2651  Vector<doublereal, 3> CCv3 = CC1 * v2;
2652  Vector<doublereal, 3> CCv4 = CC2 * v1;
2653  Matrix<doublereal, 3, 3> A1 = R1 * C1;
2654  Mat3x3 A2 = R2 * C2;
2655  Matrix<doublereal, 3, 3> A3 = R1 * C2;
2656  Matrix<doublereal, 3, 3> A4 = R2 * C1;
2657  Vector<doublereal, 3> v3(v1(1), v1(2), v1(3));
2658  Vector<doublereal, 2> v4(v1(1), v1(2));
2660  Mat3x3 X2(1., g2);
2661 
2662  if (n == 0) {
2663  std::cout << "g1=" << std::endl << g1 << std::endl;
2664  std::cout << "g2=" << std::endl << g2 << std::endl;
2665  std::cout << "R1=" << std::endl << R1 << std::endl;
2666  std::cout << "R2=" << std::endl << R2 << std::endl;
2667  std::cout << "C1=" << std::endl << C1 << std::endl;
2668  std::cout << "C2=" << std::endl << C2 << std::endl;
2669  std::cout << "CC1=" << std::endl << CC1 << std::endl;
2670  std::cout << "CC2=" << std::endl << CC2 << std::endl;
2671  std::cout << "CCv1=" << std::endl << CCv1 << std::endl;
2672  std::cout << "CCv2=" << std::endl << CCv2 << std::endl;
2673  std::cout << "CCv3=" << std::endl << CCv3 << std::endl;
2674  std::cout << "CCv4=" << std::endl << CCv4 << std::endl;
2675  std::cout << "A1=" << std::endl << A1 << std::endl;
2676  std::cout << "A2=" << std::endl << A2 << std::endl;
2677  std::cout << "A3=" << std::endl << A3 << std::endl;
2678  std::cout << "A4=" << std::endl << A4 << std::endl;
2679  }
2680 
2681  const doublereal dTol = 10*std::numeric_limits<scalar_deriv_type>::epsilon();
2682 
2683  for (index_type i = 1; i <= 3; ++i) {
2684  for (index_type j = 1; j <= 3; ++j) {
2685  assert(std::abs(R1(i, j) - R2(i, j)) < dTol);
2686  assert(std::abs(C1(i, j) - C2(i, j)) < dTol);
2687  assert(std::abs(CC1(i, j) - CC2(i, j)) < dTol);
2688  assert(std::abs(A1(i, j) - A2(i, j)) < dTol);
2689  assert(std::abs(A1(i, j) - A3(i, j)) < dTol);
2690  assert(std::abs(A1(i, j) - A4(i, j)) < dTol);
2691  assert(std::abs(X1(i, j) - X2(i, j)) < dTol);
2692  }
2693  assert(std::abs(CCv1(i) - CCv2(i)) < dTol);
2694  assert(std::abs(CCv3(i) - CCv1(i)) < dTol);
2695  assert(std::abs(CCv4(i) - CCv1(i)) < dTol);
2696  assert(v3(i) == v1(i));
2697 
2698  if (i < 3) {
2699  assert(v4(i) == v1(i));
2700  }
2701  }
2702  }
2703 }
doublereal random1()
Definition: matvectest.cc:88
Definition: matvec3.h:98
const MatCross_Manip MatCross
Definition: matvec3.cc:639
integer index_type
Definition: gradient.h:104
MatrixInit< MatGInit< T, VectorDirectExpr< Vector< T, 3 > > >, T, 3, 3 > MatGVec(const Vector< T, 3 > &g)
Definition: matvec.h:2791
const MatG_Manip MatG
Definition: matvec3.cc:646
const MatCrossCross_Manip MatCrossCross
Definition: matvec3.cc:640
MatrixInit< MatCrossCrossInit< T, VectorDirectExpr< Vector< T, 3 > > >, T, 3, 3 > MatCrossCrossVec(const Vector< T, 3 > &v)
Definition: matvec.h:2779
double doublereal
Definition: colamd.c:52
MatrixInit< MatCrossInit< T, VectorDirectExpr< Vector< T, 3 > > >, T, 3, 3 > MatCrossVec(const Vector< T, 3 > &v, doublereal d=0.)
Definition: matvec.h:2761
int NLoops
Definition: matvectest.cc:82

Here is the call graph for this function:

template<index_type N_rows>
void testMatVecCopy ( )

Definition at line 1750 of file matvectest.cc.

References grad::Gradient< N_SIZE >::dGetDerivativeGlobal(), grad::Gradient< N_SIZE >::dGetValue(), grad::MapVectorBase::GLOBAL, grad::Vector< T, N_rows >::iGetNumRows(), and grad::Vector< T, N_rows >::Reset().

1750  {
1751  std::cerr << "---------------------------\ntestMatVecCopy<" << N_rows << ">()\n";
1752 
1753  LocalDofMap dofMap1;
1754  Vector<Gradient<0>, N_rows> v;
1755 
1756  for (int i = 1; i <= v.iGetNumRows(); ++i) {
1757  v(i).SetValuePreserve(i);
1758  v(i).DerivativeResizeReset(&dofMap1, i, MapVectorBase::GLOBAL, i);
1759  }
1760 
1761  std::cout << "v=" << std::endl << v << std::endl;
1762 
1763  for (int i = 2; i <= v.iGetNumRows() - 1; ++i) {
1764  LocalDofMap dofMap2;
1765  Gradient<4> g1(v(1), &dofMap2), gi(v(i), &dofMap2), gim1(v(i - 1), &dofMap2), gip1(v(i + 1), &dofMap2);
1766  Gradient<4> x = 1000 * g1 + 100 * gi + 10 * gip1 + gim1;
1767  std::cout << "x(" << i << ")=" << x << std::endl;
1768 
1769  assert(x.dGetValue() == 1000 + 100 * i + 10 * (i + 1) + i - 1);
1770 
1771  if (i == 2) {
1772  assert(x.dGetDerivativeGlobal(1) == 1001.);
1773  } else {
1774  assert(x.dGetDerivativeGlobal(1) == 1000.);
1775  assert(x.dGetDerivativeGlobal(i - 1) == i - 1);
1776  }
1777 
1778  assert(x.dGetDerivativeGlobal(i) == 100. * i);
1779  assert(x.dGetDerivativeGlobal(i + 1) == 10. * (i + 1));
1780  }
1781 
1782  v.Reset();
1783  std::cout << "v=" << v << std::endl;
1784 }
scalar_deriv_type dGetDerivativeGlobal(index_type iGlobalDof) const
Definition: gradient.h:2532
void Reset()
Definition: matvec.h:2356
index_type iGetNumRows() const
Definition: matvec.h:2480
scalar_func_type dGetValue() const
Definition: gradient.h:2502

Here is the call graph for this function:

template<index_type N>
void testMatVecDouble ( doublereal  c_C[N])

Definition at line 635 of file matvectest.cc.

References a, bCompare(), c, callFunc(), grad::Dot(), grad::sqrt(), and grad::Sum().

635  {
637 
638  for (index_type i = 0; i < N; ++i) {
639  a(i + 1) = 100*(i + 1);
640  b(i + 1) = 1000*(i + 10);
641  }
642 
644 
645  callFunc(0, a, b, c, c1);
646 
648 
649  const doublereal dTol = sqrt(std::numeric_limits<scalar_deriv_type>::epsilon());
650 
651  for (int i = 1; i <= N; ++i) {
652  assert(bCompare(c(i), c1(i), dTol));
653  assert(d(i) == -c(i));
654  }
655 
656  for (int i = 0; i < N; ++i) {
657  c_C[i] = c(i + 1);
658  }
659 
660  doublereal s1 = 0.;
661 
662  for (int i = 0; i < N; ++i) {
663  s1 += c(i + 1);
664  }
665 
666  doublereal s2 = Sum(c);
667 
668  assert(bCompare(s2, s1, dTol));
669 
670  doublereal s3 = Sum((a * 2 - b * 3) / 1.5 + c);
671 
672  doublereal s4 = 0.;
673 
674  for (int i = 1; i <= N; ++i) {
675  s4 += (a(i) * 2 - b(i) * 3) / 1.5 + c(i);
676  }
677 
678  assert(bCompare(s2, s1, dTol));
679  assert(bCompare(s4, s3, dTol));
680 
681  doublereal d1 = Dot(a, b);
682  doublereal d2 = 0.;
683 
684  for (int i = 1; i <= N; ++i) {
685  d2 += a(i) * b(i);
686  }
687 
688  assert(bCompare(d2, d1, std::numeric_limits<scalar_deriv_type>::epsilon()));
689 
690  std::cout << "s1=" << s1 << std::endl;
691  std::cout << "s2=" << s2 << std::endl;
692  std::cout << "s3=" << s3 << std::endl;
693  std::cout << "s4=" << s4 << std::endl;
694  std::cout << "d1=" << d1 << std::endl;
695  std::cout << "d2=" << d2 << std::endl;
696 
697  const Vector<doublereal, N> d5 = (d + c + c1) * (3.5 / (c(1) + c(2)) * c(1) / 2. * (c(1) - c(3)) / c(2));
698 
699  d += c + c1;
700 
701  d *= 3.5;
702 
703  d /= c(1) + c(2);
704 
705  d *= c(1);
706 
707  d /= 2.;
708 
709  d *= c(1) - c(3);
710 
711  d /= c(2);
712 
713  for (int i = 1; i <= N; ++i) {
714  assert(bCompare(d(i), d5(i), dTol));
715  }
716 
717  std::cout << "d=" << d << std::endl;
718  std::cout << "d5=" << d5 << std::endl;
719 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
integer index_type
Definition: gradient.h:104
void callFunc(LocalDofMap *pDofMap, const Vector< T, N > &a, const Vector< T, N > &b, Vector< T, N > &c, Vector< T, N > &c1)
Definition: matvectest.cc:402
DotTraits< VectorExprLhs, VectorExprRhs, N_rows, N_rows >::ExpressionType Dot(const VectorExpression< VectorExprLhs, N_rows > &u, const VectorExpression< VectorExprRhs, N_rows > &v)
Definition: matvec.h:3133
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
static std::stack< cleanup * > c
Definition: cleanup.cc:59
SumTraits< VectorExpressionType, N_rows, N_rows >::ExpressionType Sum(const VectorExpression< VectorExpressionType, N_rows > &v)
Definition: matvec.h:3076
static const doublereal a
Definition: hfluid_.h:289
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

void testMatVecDouble2 ( )

Definition at line 832 of file matvectest.cc.

References c, and callFunc2().

Referenced by main().

832  {
835 
836  for (index_type i = 0; i < 3; ++i) {
837  b(i + 1)=(100*(i + 1));
838  c(i + 1)=(1000*(i + 10));
839 
840  for (index_type j = 0; j < 3; ++j) {
841  A(i + 1, j + 1) = (100*(i + 1) + j + 1);
842  }
843  }
844 
845  Vector<doublereal, 3> d, d_C, d_F;
846 
847  callFunc2(0, A, b, c, d, d_C, d_F);
848 }
void callFunc2(LocalDofMap *pDofMap, const Matrix< T, 3, 3 > &A, const Vector< T, 3 > &b, const Vector< T, 3 > &c, Vector< T, 3 > &d, Vector< T, 3 > &d_C, Vector< T, 3 > &d_F)
Definition: matvectest.cc:432
integer index_type
Definition: gradient.h:104
static std::stack< cleanup * > c
Definition: cleanup.cc:59

Here is the call graph for this function:

template<index_type N>
void testMatVecGradient ( doublereal  c_C[N],
doublereal  cd_C[N][N] 
)

Definition at line 474 of file matvectest.cc.

References a, bCompare(), grad::Gradient< N_SIZE >::bIsEqual(), c, callFunc(), dof, grad::Dot(), grad::MapVectorBase::GLOBAL, grad::Gradient< N_SIZE >::SetValue(), grad::sqrt(), and grad::Sum().

474  {
476  Vector<Gradient<N>, N> a, b;
477 
478  for (index_type i = 0; i < N; ++i) {
479  a(i + 1).SetValuePreserve(100*(i + 1));
480  b(i + 1).SetValuePreserve(1000*(i + 10));
481 
482  a(i + 1).DerivativeResizeReset(&dof, i, MapVectorBase::GLOBAL, 0.);
483  a(i + 1).SetDerivativeGlobal(i, -1. - 10.);
484  b(i + 1).DerivativeResizeReset(&dof, i, MapVectorBase::GLOBAL, 0.);
485  b(i + 1).SetDerivativeGlobal(i, -2. - 20.);
486  }
487 
488  Vector<Gradient<N>, N> c, c1;
489 
490  callFunc(&dof, a, b, c, c1);
491 
492  Vector<Gradient<N>, N> d = -c;
493 
494  std::cout << "c=" << std::endl << c << std::endl;
495  std::cout << "d=" << std::endl << d << std::endl;
496 
497  const doublereal dTol = sqrt(std::numeric_limits<scalar_deriv_type>::epsilon());
498 
499  for (int i = 1; i <= N; ++i) {
500  assert(bCompare(c(i), c1(i), dTol));
501  assert(bCompare(d(i), Gradient<N>(-c(i))));
502  }
503 
504  for (int i = 0; i < N; ++i) {
505  c_C[i] = c(i + 1).dGetValue();
506 
507  for (int j = 0; j < N; ++j) {
508  cd_C[i][j] = c(i + 1).dGetDerivativeGlobal(j);
509  }
510  }
511 
512  Gradient<N> s1;
513 
514  for (int i = 1; i <= N; ++i) {
515  s1 += c(i);
516  }
517 
518  Gradient<N> s2 = Sum(c);
519 
520  Gradient<N> s4;
521 
522  for (int i = 1; i <= N; ++i) {
523  s4 += (a(i) * 2 - b(i) * 3) / 1.5 + c(i);
524  }
525 
526  Gradient<N> s3 = Sum((a * 2 - b * 3) / 1.5 + c);
527 
528  Gradient<N> d1 = Dot(a, b);
529  Gradient<N> d2;
530 
531  for (int i = 1; i <= N; ++i) {
532  d2 += a(i) * b(i);
533  }
534 
535  Gradient<N> d3 = Dot(a + b, a - b);
536  Gradient<N> d4;
537 
538  for (int i = 1; i <= N; ++i) {
539  d4 += (a(i) + b(i)) * (a(i) - b(i));
540  }
541 
542  assert(d3.bIsEqual(d4));
543 
544  d3 = Dot(a + b, b);
545 
546  d4.SetValue(0.);
547 
548  for (int i = 1; i <= N; ++i) {
549  d4 += (a(i) + b(i)) * b(i);
550  }
551 
552  assert(d3.bIsEqual(d4));
553 
554  d3 = Dot(b, a + b);
555 
556  std::cout << "s1=" << s1 << std::endl;
557  std::cout << "s2=" << s2 << std::endl;
558  std::cout << "s3=" << s3 << std::endl;
559  std::cout << "s4=" << s4 << std::endl;
560  std::cout << "d1=" << d1 << std::endl;
561  std::cout << "d2=" << d2 << std::endl;
562  std::cout << "d3=" << d3 << std::endl;
563  std::cout << "d4=" << d4 << std::endl;
564 
565  assert(bCompare(d3, d4, dTol));
566  assert(bCompare(s2, s1, dTol));
567  assert(bCompare(s4, s3, dTol));
568  assert(bCompare(d2, d1, dTol));
569 
570  const Vector<Gradient<N>, N> d5 = (d + c + c1) * (3.5 / (c(1) + c(2)) * c(1) / 2. * (c(1) - c(3)) / c(2));
571 
572  d += c + c1;
573 
574  d *= 3.5;
575 
576  d /= c(1) + c(2);
577 
578  d *= c(1);
579 
580  d /= 2.;
581 
582  d *= c(1) - c(3);
583 
584  d /= c(2);
585 
586  std::cout << "d=" << d << std::endl;
587  std::cout << "d5=" << d5 << std::endl;
588 
589  for (int i = 1; i <= N; ++i) {
590  assert(bCompare(d(i), d5(i), dTol));
591  }
592 }
void SetValue(scalar_func_type dVal)
Definition: gradient.h:2506
bool bIsEqual(const Gradient &g) const
Definition: gradient.h:2604
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
integer index_type
Definition: gradient.h:104
static const char * dof[]
Definition: drvdisp.cc:195
void callFunc(LocalDofMap *pDofMap, const Vector< T, N > &a, const Vector< T, N > &b, Vector< T, N > &c, Vector< T, N > &c1)
Definition: matvectest.cc:402
DotTraits< VectorExprLhs, VectorExprRhs, N_rows, N_rows >::ExpressionType Dot(const VectorExpression< VectorExprLhs, N_rows > &u, const VectorExpression< VectorExprRhs, N_rows > &v)
Definition: matvec.h:3133
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
static std::stack< cleanup * > c
Definition: cleanup.cc:59
SumTraits< VectorExpressionType, N_rows, N_rows >::ExpressionType Sum(const VectorExpression< VectorExpressionType, N_rows > &v)
Definition: matvec.h:3076
static const doublereal a
Definition: hfluid_.h:289
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<index_type N_SIZE>
void testMatVecGradient2 ( )

Definition at line 722 of file matvectest.cc.

References grad::Alias(), bCompare(), c, callFunc2(), dof, grad::Dot(), grad::MapVectorBase::GLOBAL, grad::sqrt(), and grad::Transpose().

722  {
724  Matrix<Gradient<N_SIZE>, 3, 3> A;
725  Vector<Gradient<N_SIZE>, 3> b, c;
726 
727  for (index_type i = 0; i < 3; ++i) {
728  b(i + 1).SetValuePreserve(100*(i + 1));
729  b(i + 1).DerivativeResizeReset(&dof, 0L, N_SIZE, MapVectorBase::GLOBAL, 0.);
730  c(i + 1).SetValuePreserve(1000*(i + 10));
731  c(i + 1).DerivativeResizeReset(&dof, 0L, N_SIZE, MapVectorBase::GLOBAL, 0.);
732 
733  for (index_type k = 0; k < N_SIZE; ++k) {
734  c(i + 1).SetDerivativeGlobal(k, 3.5 * (k + 1) + 3.2 * (i + 1));
735  b(i + 1).SetDerivativeGlobal(k, -17.4 * (k + 1) + 7.5 *(i + 1));
736  }
737 
738  for (index_type j = 0; j < 3; ++j) {
739  A(i + 1, j + 1).SetValuePreserve(100*(i + 1) + j + 1);
740  A(i + 1, j + 1).DerivativeResizeReset(&dof, 0L, N_SIZE, MapVectorBase::GLOBAL, 0.);
741  for (index_type k = 0; k < N_SIZE; ++k) {
742  A(i + 1, j + 1).SetDerivativeGlobal(k, -9.2 * (k + 1.) + 10.5 * (i + 1) + 3.2 * (j + 1) + 7.5);
743  }
744  }
745  }
746 
747  Vector<Gradient<N_SIZE>, 3> d, d_C, d_F;
748 
749  callFunc2(&dof, A, b, c, d, d_C, d_F);
750 
751  Matrix<Gradient<N_SIZE>, 3, 3> A_2 = A * 2.;
752  Vector<Gradient<N_SIZE>, 3> b_2 = b * 2.;
753 
754  A = Alias(A) * 2.; // Test self assignment
755  b = Alias(b) * 2.;
756 
757  for (index_type i = 1; i < 3; ++i) {
758  assert(bCompare(b(i), b_2(i)));
759 
760  for (index_type j = 1; j < 3; ++j) {
761  assert(bCompare(A(i, j), A_2(i, j)));
762  }
763  }
764 
765  const doublereal dTol = sqrt(std::numeric_limits<scalar_deriv_type>::epsilon());
766 
767  Matrix<Gradient<N_SIZE>, 3, 3> A_3 = (A + Transpose(A) * 0.75) * (2. / b(1));
768 
769  A += Transpose(Alias(A)) * 0.75;
770  A *= 2.;
771  A /= b(1);
772 
773  for (index_type i = 1; i < 3; ++i) {
774  for (index_type j = 1; j < 3; ++j) {
775  assert(bCompare(A(i, j), A_3(i, j), dTol));
776  }
777  }
778 
779  Matrix<Gradient<N_SIZE>, 3, 3> A_4 = A * A(2, 3);
780  A *= Alias(A(2, 3));
781 
782  for (index_type i = 1; i < 3; ++i) {
783  for (index_type j = 1; j < 3; ++j) {
784  assert(bCompare(A(i, j), A_4(i, j), dTol));
785  }
786  }
787 
788  Vector<Gradient<N_SIZE>, 3> b_3 = b * b(2);
789 
790  b *= Alias(b(2));
791 
792  for (index_type i = 1; i <= 3; ++i) {
793  assert(bCompare(b(i), b_3(i), dTol));
794  }
795 
796  Vector<Gradient<N_SIZE>, 3> b_4 = b / sqrt(Dot(b, b));
797 
798  b /= sqrt(Dot(Alias(b), b));
799 
800  for (index_type i = 1; i <= 3; ++i) {
801  assert(bCompare(b(i), b_4(i), dTol));
802  }
803 
804  Vector<Gradient<N_SIZE>, 3> b_5 = ((b + b * 0.75 / b(1)) * (2. / (A(1, 3) + A(2, 3))) * A(2, 1) + Transpose(A).GetCol(3)) / A(1, 1) / 3.8;
805 
806  b += b * 0.75 / Alias(b(1));
807  b *= 2.;
808  b /= (A(1, 3) + A(2, 3));
809  b *= A(2, 1);
810  b += Transpose(A).GetCol(3);
811  b /= A(1, 1);
812  b /= 3.8;
813 
814  for (index_type i = 1; i <= 3; ++i) {
815  assert(bCompare(b(i), b_5(i), dTol));
816  }
817 
818  Vector<Gradient<N_SIZE>, 2> b23 = SubVector<2, 3>(b);
819  Vector<Gradient<N_SIZE>, 2> b12 = SubVector<1, 2>(b);
820  assert(bCompare(b23(1), b(2)));
821  assert(bCompare(b23(2), b(3)));
822  assert(bCompare(b12(1), b(1)));
823  assert(bCompare(b12(2), b(2)));
824  Vector<Gradient<N_SIZE>, 2> e = SubVector<2, 3>(b / 2.) + SubVector<1, 2>(b * 3.);
825  assert(bCompare(e(1), Gradient<N_SIZE>(b(2) / 2. + b(1) * 3), dTol));
826  assert(bCompare(e(2), Gradient<N_SIZE>(b(3) / 2. + b(2) * 3), dTol));
827 
828  A = Alias(A) * 0.5 + Transpose(A) * 3.5;
829  b = Alias(b) * 2.3 + c * 5.0;
830 }
void callFunc2(LocalDofMap *pDofMap, const Matrix< T, 3, 3 > &A, const Vector< T, 3 > &b, const Vector< T, 3 > &c, Vector< T, 3 > &d, Vector< T, 3 > &d_C, Vector< T, 3 > &d_F)
Definition: matvectest.cc:432
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
MatrixExpression< TransposedMatrix< MatrixDirectExpr< Matrix< T, N_rows, N_cols > > >, N_cols, N_rows > Transpose(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2206
integer index_type
Definition: gradient.h:104
static const char * dof[]
Definition: drvdisp.cc:195
DotTraits< VectorExprLhs, VectorExprRhs, N_rows, N_rows >::ExpressionType Dot(const VectorExpression< VectorExprLhs, N_rows > &u, const VectorExpression< VectorExprRhs, N_rows > &v)
Definition: matvec.h:3133
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
static std::stack< cleanup * > c
Definition: cleanup.cc:59
GradientExpression< DirectExpr< Gradient< N_SIZE >, true > > Alias(const Gradient< N_SIZE > &g)
Definition: gradient.h:2866
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

void testMatVecProduct ( )

Definition at line 850 of file matvectest.cc.

References bCompare(), c, grad::Direct(), grad::Dot(), grad::Matrix< T, N_rows, N_cols >::GetCol(), grad::Matrix< T, N_rows, N_cols >::GetRow(), grad::Matrix< T, N_rows, N_cols >::iGetNumCols(), grad::VectorExpression< Expression, N_rows >::iGetNumRows(), grad::Matrix< T, N_rows, N_cols >::iGetNumRows(), grad::Vector< T, N_rows >::iGetNumRows(), R, grad::Tabular(), and grad::Transpose().

Referenced by main().

850  {
854 
855  for (index_type i = 0; i < A.iGetNumRows(); ++i) {
856  for (index_type j = 0; j < A.iGetNumCols(); ++j) {
857  A(i + 1, j + 1) = 10 * (i + 1) + j + 1;
858  }
859  }
860 
861  for (index_type i = 0; i < R.iGetNumRows(); ++i) {
862  for (index_type j = 0; j < R.iGetNumCols(); ++j) {
863  R(i + 1, j + 1) = 10 * (i + 1) + j + 1;
864  }
865  }
866 
867  for (index_type i = 0; i < B.iGetNumRows(); ++i) {
868  for (index_type j = 0; j < B.iGetNumCols(); ++j) {
869  B(i + 1, j + 1) = (10 * (i + 1) + j + 1);
870  }
871  }
872 
873  std::cout << "A=" << std::endl << A << std::endl;
874 
876 
877  std::cout << "A^T=" << std::endl << A_T << std::endl;
878 
880 
881  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
882  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
883  assert(bCompare(A(i, j), A_T(j, i)));
884  assert(bCompare(A(i, j), A_T2(j, i)));
885  }
886  }
887 
889 
890  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
891  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
892  assert(bCompare(A2(i, j), A(i, j)));
893  }
894  }
895 
896  std::cout << "\nrows of A:" << std::endl;
897 
898  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
900  std::cout << i - 1 << ": ";
901 
902  for (index_type j = 1; j <= r.iGetNumRows(); ++j) {
903  assert(r(j) == A(i, j));
904  std::cout << r(j) << " ";
905  }
906 
907  std::cout << std::endl;
908  }
909 
910  std::cout << "\ncolumns of A:" << std::endl;
911 
912  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
914  std::cout << j - 1 << ": ";
915 
916  for (index_type i = 1; i <= c.iGetNumRows(); ++i) {
917  assert(c(i) == A(i, j));
918  std::cout << c(i) << " ";
919  }
920 
921  std::cout << std::endl;
922  }
923 
925  Matrix<doublereal, 3, 3> E = -(A * Transpose(A));
926 
927 
928  for (int i = 1; i <= 3; ++i) {
929  for (int j = 1; j <= 3; ++j) {
930  assert(bCompare(D(i, j), -A(i, j)));
931  }
932  }
933 
934  assert(E(1, 1) == -630);
935  assert(E(1, 2) == -1130);
936  assert(E(1, 3) == -1630);
937  assert(E(2, 1) == -1130);
938  assert(E(2, 2) == -2030);
939  assert(E(2, 3) == -2930);
940  assert(E(3, 1) == -1630);
941  assert(E(3, 2) == -2930);
942  assert(E(3, 3) == -4230);
943 
946 
947  for (index_type i = 0; i < x.iGetNumRows(); ++i) {
948  x(i + 1) = 100 * (i + 1);
949  }
950 
951  for (index_type i = 1; i <= b.iGetNumRows(); ++i) {
952  b(i) = Dot(A.GetRow(i), x);
953  }
954 
955  Vector<Gradient<0>, 3> grad_b = Direct(b);
956  Vector<doublereal, 3> b2 = A * x;
957  Vector<doublereal, 3> b3 = b + A * x + b;
958  Vector<doublereal, 3> b4 = Direct(A) * Direct(x);
959  Vector<doublereal, 3> b5 = Direct(A) * x;
960  Vector<doublereal, 3> b6 = A * Direct(x);
961  Vector<doublereal, 3> c = R * (A * x);
962  Vector<doublereal, 4> d = Transpose(A) * b;
963  Vector<doublereal, 4> e = Transpose(A) * (A * x);
964  Vector<doublereal, 3> f = A * (Transpose(A) * (A * (x + x)));
965 
966  for (index_type i = 1; i <= d.iGetNumRows(); ++i) {
967  assert(d(i) == e(i));
968  }
969 
972  g(1) = 523;
973  g(2) = -786;
974  Vector<doublereal, 3> h = A * (B * g);
975  Vector<doublereal, 3> h2 = (Direct(A) * Direct(B)) * g;
976  Vector<doublereal, 3> h3 = (Direct(A) * B) * g;
977  Vector<doublereal, 3> h4 = (A * Direct(B)) * g;
978  Vector<doublereal, 3> h5 = (A * B) * g;
979  Vector<doublereal, 3> h6 = (A * B) * Direct(g);
980 
981  for (index_type i = 1; i <= h.iGetNumRows(); ++i) {
982  assert(h(i) == h2(i));
983  assert(h(i) == h3(i));
984  assert(h(i) == h4(i));
985  assert(h(i) == h5(i));
986  assert(h(i) == h6(i));
987  }
988 
989  std::cout << "B=" << std::endl << B << std::endl;
990  std::cout << "A * B = C" << std::endl << C << std::endl;
991 
992  std::cout << "R=" << std::endl << R << std::endl;
993  std::cout << "x = " << std::endl << x << std::endl;
994  std::cout << "A * x = b" << std::endl << b << std::endl;
995  std::cout << "R * A * x = c" << std::endl << c << std::endl;
996  std::cout << "A^T * b = d" << std::endl << d << std::endl;
997  std::cout << "A^T * A * x = e" << std::endl << e << std::endl;
998  std::cout << "A * A^T * A * 2 * x = f" << std::endl << f << std::endl;
999  std::cout << "A * B * g = h" << std::endl << h << std::endl;
1000 
1001  for (index_type i = 1; i <= b2.iGetNumRows(); ++i) {
1002  assert(b2(i) == b(i));
1003  assert(b3(i) == 3 * b(i));
1004  assert(b4(i) == b(i));
1005  assert(b5(i) == b(i));
1006  assert(b6(i) == b(i));
1007  }
1008 
1009  assert(b(1) == 13000);
1010  assert(b(2) == 23000);
1011  assert(b(3) == 33000);
1012 
1013  assert(c(1) == 848000);
1014  assert(c(2) == 1538000);
1015  assert(c(3) == 2228000);
1016 
1017  assert(d(1) == 1649000.00);
1018  assert(d(2) == 1718000.00);
1019  assert(d(3) == 1787000.00);
1020  assert(d(4) == 1856000.00);
1021 
1022  assert(C(1, 1) == 1.35e3);
1023  assert(C(2, 1) == 2.39e3);
1024  assert(C(3, 1) == 3.43e3);
1025  assert(C(1, 2) == 1.4e3);
1026  assert(C(2, 2) == 2.48e3);
1027  assert(C(3, 2) == 3.56e3);
1028 
1029  assert(h(1) == -394350);
1030  assert(h(2) == -699310);
1031  assert(h(3) == -1004270);
1032 
1033  Vector<doublereal, 2> b23 = SubVector<2, 3>(b);
1034  Vector<doublereal, 2> b12 = SubVector<1, 2>(b);
1035  assert(bCompare(b23(1), b(2)));
1036  assert(bCompare(b23(2), b(3)));
1037  assert(bCompare(b12(1), b(1)));
1038  assert(bCompare(b12(2), b(2)));
1039  Vector<doublereal, 2> e123 = SubVector<2, 3>(b / 2.) + SubVector<1, 2>(b * 3.);
1040  assert(bCompare(e123(1), (b(2) / 2. + b(1) * 3)));
1041  assert(bCompare(e123(2), (b(3) / 2. + b(2) * 3)));
1042 
1044 
1045  for (index_type i = 1; i <= 5; ++i) {
1046  for (index_type j = 1; j <= 7; ++j) {
1047  F(i, j) = i * 10 + j;
1048  }
1049  }
1050 
1051  Matrix<doublereal, 2, 3> G = SubMatrix<3, 4, 5, 7>(F);
1052 
1053  for (index_type i = 1; i <= 2; ++i) {
1054  for (index_type j = 1; j <= 3; ++j) {
1055  assert(bCompare(G(i, j), F(i + 2, j + 4)));
1056  }
1057  }
1058 
1059  Vector<doublereal, 3> G1 = SubMatrix<4, 4, 2, 4>(F).GetRow(1);
1060 
1061  assert(bCompare(G1(1), F(4, 2)));
1062  assert(bCompare(G1(2), F(4, 3)));
1063  assert(bCompare(G1(3), F(4, 4)));
1064 
1065  Vector<doublereal, 2> G2 = SubMatrix<1, 2, 5, 7>(F).GetCol(1);
1066 
1067  assert(bCompare(G2(1), F(1, 5)));
1068  assert(bCompare(G2(2), F(2, 5)));
1069 
1070  Vector<doublereal, 2> G3 = SubMatrix<1, 2, 5, 7>(F).GetCol(2);
1071 
1072  assert(bCompare(G3(1), F(1, 6)));
1073  assert(bCompare(G3(2), F(2, 6)));
1074 
1075 
1076  Vector<doublereal, 2> G4 = SubMatrix<1, 2, 5, 7>(F).GetCol(3);
1077 
1078  assert(bCompare(G4(1), F(1, 7)));
1079  assert(bCompare(G4(2), F(2, 7)));
1080 
1081  Matrix<doublereal, 3, 4> M = SubMatrix<2, 4, 2, 5>(F) * SubMatrix<2, 5, 4, 7>(F);
1082 
1083  assert(bCompare(M(1, 1), 3716.));
1084  assert(bCompare(M(1, 2), 3810.));
1085  assert(bCompare(M(1, 3), 3904.));
1086  assert(bCompare(M(1, 4), 3998.));
1087  assert(bCompare(M(2, 1), 5276.));
1088  assert(bCompare(M(2, 2), 5410.));
1089  assert(bCompare(M(2, 3), 5544.));
1090  assert(bCompare(M(2, 4), 5678.));
1091  assert(bCompare(M(3, 1), 6836.));
1092  assert(bCompare(M(3, 2), 7010.));
1093  assert(bCompare(M(3, 3), 7184.));
1094  assert(bCompare(M(3, 4), 7358.));
1095 
1096  std::cout << "F=\n" << Tabular(F, 5) << std::endl;
1097  std::cout << "G=\n" << Tabular(G, 5) << std::endl;
1098  std::cout << "G1=\n" << G1 << std::endl;
1099  std::cout << "G2=\n" << G2 << std::endl;
1100  std::cout << "G3=\n" << G3 << std::endl;
1101  std::cout << "G4=\n" << G4 << std::endl;
1102  std::cout << "M=\n" << Tabular(M, 5) << std::endl;
1103 }
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
MatrixExpression< TransposedMatrix< MatrixDirectExpr< Matrix< T, N_rows, N_cols > > >, N_cols, N_rows > Transpose(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2206
index_type iGetNumRows() const
Definition: matvec.h:2118
integer index_type
Definition: gradient.h:104
index_type iGetNumCols() const
Definition: matvec.h:2119
index_type iGetNumRows() const
Definition: matvec.h:623
ColumnVectorType GetCol(index_type iCol) const
Definition: matvec.h:2112
MatrixExpression< MatrixDirectExpr< Matrix< T, N_rows, N_cols > >, N_rows, N_cols > Direct(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2185
DotTraits< VectorExprLhs, VectorExprRhs, N_rows, N_rows >::ExpressionType Dot(const VectorExpression< VectorExprLhs, N_rows > &u, const VectorExpression< VectorExprRhs, N_rows > &v)
Definition: matvec.h:3133
index_type iGetNumRows() const
Definition: matvec.h:2480
static std::stack< cleanup * > c
Definition: cleanup.cc:59
RowVectorType GetRow(index_type iRow) const
Definition: matvec.h:2105
TabularMatrixView< T, N_rows, N_cols > Tabular(const Matrix< T, N_rows, N_cols > &A, int iColWidth=10)
Definition: matvec.h:3012
Mat3x3 R

Here is the call graph for this function:

void testMatVecProductGradient ( )

Definition at line 1383 of file matvectest.cc.

References bCompare(), grad::Gradient< N_SIZE >::bIsEqual(), c, grad::Cross(), grad::dGetValue(), grad::Direct(), dof, grad::Dot(), grad::exp(), grad::Matrix< T, N_rows, N_cols >::GetCol(), grad::Matrix< T, N_rows, N_cols >::GetRow(), grad::MapVectorBase::GLOBAL, gradVecAssTest::I1, grad::Matrix< T, N_rows, N_cols >::iGetNumCols(), grad::Matrix< T, N_rows, N_cols >::iGetNumRows(), grad::Vector< T, N_rows >::iGetNumRows(), grad::MatCrossVec(), grad::Norm(), testMatVecProductGradient_testData::oct_b, testMatVecProductGradient_testData::oct_c, testMatVecProductGradient_testData::oct_d, testMatVecProductGradient_testData::oct_e, testMatVecProductGradient_testData::oct_f, testMatVecProductGradient_testData::oct_g, testMatVecProductGradient_testData::oct_i, testMatVecProductGradient_testData::oct_j, testMatVecProductGradient_testData::oct_l, testMatVecProductGradient_testData::oct_m, testMatVecProductGradient_testData::oct_norm_g, testMatVecProductGradient_testData::oct_r, testMatVecProductGradient_testData::oct_s, testMatVecProductGradient_testData::oct_t, grad::pow(), grad::Matrix< T, N_rows, N_cols >::Reset(), grad::Vector< T, N_rows >::Reset(), testGradient(), and grad::Transpose().

Referenced by main().

1383  {
1384  Matrix<Gradient<0>, 3, 4> A;
1385  LocalDofMap dof;
1386 
1387  for (index_type i = 0; i < A.iGetNumRows(); ++i) {
1388  for (index_type j = 0; j < A.iGetNumCols(); ++j) {
1389  A(i + 1, j + 1).SetValue(10 * (i + 1) + j + 1);
1390  A(i + 1, j + 1).DerivativeResizeReset(&dof, j * A.iGetNumRows() + i + 1, MapVectorBase::GLOBAL, 0.);
1391  A(i + 1, j + 1).SetDerivativeGlobal(j * A.iGetNumRows() + i + 1, 1.);
1392  }
1393  }
1394 
1395  Matrix<Gradient<0>, 3, 4> B1;
1397 
1398  for (int i = 1; i <= 3; ++i) {
1399  for (int j = 1; j <= 4; ++j) {
1400  B1(i, j) = 3.5 * A(i, j);
1401  Ad(i, j) = A(i, j).dGetValue();
1402  }
1403  }
1404 
1405  Matrix<Gradient<0>, 3, 4> C1 = A + B1;
1406  Matrix<Gradient<0>, 3, 4> D1 = (A + B1) - (C1 + B1);
1407  Matrix<Gradient<0>, 3, 4> E1 = A + (C1 - B1);
1408  Matrix<Gradient<0>, 3, 4> F1 = (C1 - B1) - A;
1409  Matrix<Gradient<0>, 3, 4> G1 = A - B1;
1410  Matrix<Gradient<0>, 3, 4> H1 = A * 3.5 + B1 / 4.;
1411  Matrix<Gradient<0>, 3, 4> I1 = (A * 2. - B1 / 5.) * 3.5;
1412  Matrix<Gradient<0>, 3, 4> J1 = A * B1(1, 1) + I1 * H1(2, 2);
1413  Matrix<Gradient<0>, 3, 4> K1 = (I1 + J1) * H1(3, 4);
1414 
1415  const doublereal dTol = 10 * std::numeric_limits<scalar_deriv_type>::epsilon();
1416 
1417  for (int i = 1; i <= 3; ++i) {
1418  for (int j = 1; j <= 4; ++j) {
1419  assert(bCompare(C1(i, j), Gradient<0>(A(i, j) + B1(i, j)), dTol));
1420  assert(bCompare(D1(i, j), Gradient<0>(A(i, j) + B1(i, j) - C1(i, j) - B1(i, j)), dTol));
1421  assert(bCompare(E1(i, j), Gradient<0>(A(i, j) + C1(i, j) - B1(i, j)), dTol));
1422  assert(bCompare(F1(i, j), Gradient<0>(C1(i, j) - B1(i, j) - A(i, j)), dTol));
1423  assert(bCompare(G1(i, j), Gradient<0>(A(i, j) - B1(i, j)), dTol));
1424  assert(bCompare(H1(i, j), Gradient<0>(A(i, j) * 3.5 + B1(i, j) / 4.), dTol));
1425  assert(bCompare(I1(i, j), Gradient<0>((A(i, j) * 2. - B1(i, j) / 5.) * 3.5), dTol));
1426  assert(bCompare(J1(i, j), Gradient<0>(A(i, j) * B1(1, 1) + I1(i, j) * H1(2, 2)), dTol));
1427  assert(bCompare(K1(i, j), Gradient<0>((I1(i, j) + J1(i, j)) * H1(3, 4)), dTol));
1428  }
1429  }
1430 
1431  std::cout << "A=" << std::endl << A << std::endl;
1432 
1433  std::cout << "A=" << std::endl << A << std::endl;
1434 
1435  Matrix<Gradient<0>, 4, 3> A_T = Transpose(A);
1436 
1437  std::cout << "A^T=" << std::endl << A_T << std::endl;
1438 
1439  Matrix<Gradient<0>, 4, 3> A_T2 = Transpose(Direct(A));
1440 
1441  Matrix<Gradient<0>, 3, 4> B = -A;
1442 
1443  Matrix<Gradient<0>, 3, 3> D = -(A * Transpose(A));
1444 
1445  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
1446  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
1447  assert(bCompare(A(i, j), A_T(j, i)));
1448  assert(bCompare(A(i, j), A_T2(j, i)));
1449  assert(bCompare(B(i, j), Gradient<0>(-A(i, j))));
1450  }
1451  }
1452 
1453  Matrix<Gradient<0>, 3, 4> A2 = Transpose(Transpose(A));
1454 
1455  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
1456  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
1457  assert(bCompare(A2(i, j), A(i, j)));
1458  }
1459  }
1460 
1461  std::cout << "\nrows of A:" << std::endl;
1462 
1463  for (index_type i = 1; i <= A.iGetNumRows(); ++i) {
1464  Matrix<Gradient<0>, 3, 4>::RowVectorType r = A.GetRow(i);
1465  std::cout << i - 1 << ": ";
1466 
1467  for (index_type j = 1; j <= r.iGetNumRows(); ++j) {
1468  assert(bCompare(r(j), A(i, j), std::numeric_limits<scalar_deriv_type>::epsilon()));
1469  std::cout << r(j) << " ";
1470  }
1471 
1472  std::cout << std::endl;
1473  }
1474 
1475  std::cout << "\ncolumns of A:" << std::endl;
1476 
1477  for (index_type j = 1; j <= A.iGetNumCols(); ++j) {
1478  Matrix<Gradient<0>, 3, 4>::ColumnVectorType c = A.GetCol(j);
1479  std::cout << j - 1 << ": ";
1480 
1481  for (index_type i = 1; i <= c.iGetNumRows(); ++i) {
1482  assert(bCompare(c(i), A(i, j), std::numeric_limits<scalar_deriv_type>::epsilon()));
1483  std::cout << c(i) << " ";
1484  }
1485 
1486  std::cout << std::endl;
1487  }
1488 
1489  Vector<Gradient<0>, 4> x;
1490  Vector<Gradient<0>, 3> b;
1492 
1493  for (index_type i = 1; i <= x.iGetNumRows(); ++i) {
1494  x(i) = A(1, i) * 10.;
1495  v(i) = x(i).dGetValue();
1496  }
1497 
1498  Vector<Gradient<0>, 3> b_1;
1499  Gradient<0> b1_2;
1500  b1_2 = A(1, 1) * x(1);
1501  b1_2 += A(1, 2) * x(2);
1502  b1_2 += A(1, 3) * x(3);
1503  b1_2 += A(1, 4) * x(4);
1504 
1505  b_1(1) = A(1, 1) * x(1) + A(1, 2) * x(2) + A(1, 3) * x(3) + A(1, 4) * x(4);
1506 
1507  assert(b1_2.bIsEqual(b_1(1)));
1508 
1509  b_1(2) = A(2, 1) * x(1) + A(2, 2) * x(2) + A(2, 3) * x(3) + A(2, 4) * x(4);
1510  b_1(3) = A(3, 1) * x(1) + A(3, 2) * x(2) + A(3, 3) * x(3) + A(3, 4) * x(4);
1511 
1512 
1513  using namespace testMatVecProductGradient_testData;
1514  testGradient(oct_b, b_1, dTol);
1515 
1516  for (index_type i = 1; i <= b.iGetNumRows(); ++i) {
1517  b(i) = Dot(A.GetRow(i), x);
1518  }
1519 
1520  testGradient(oct_b, b, dTol);
1521 
1522  Vector<Gradient<0>, 3> b2 = A * x;
1523  Vector<Gradient<0>, 3> b2d = Ad * x;
1524  Vector<Gradient<0>, 3> b2d1 = -Ad * x - Ad * x;
1525  Vector<Gradient<0>, 3> b3 = b + A * x + b2;
1526  Vector<Gradient<0>, 3> b4 = A * (x + x);
1527  Vector<Gradient<0>, 3> b5 = Direct(A) * Direct(x);
1528  Vector<Gradient<0>, 3> b6 = Direct(A) * x;
1529  Vector<Gradient<0>, 3> b7 = A * Direct(x);
1530  Vector<Gradient<0>, 3> b8 = A * v;
1531  Vector<Gradient<0>, 3> c = -(A * x);
1532  Vector<Gradient<0>, 3> d = Cross(c, b) * 5.;
1533  Vector<Gradient<0>, 3> e = Cross(c + d, b) / 2.;
1534  Vector<Gradient<0>, 3> f = Cross(e, d + c) - e;
1535  Vector<Gradient<0>, 3> g = Cross(d + e, f - c) + b;
1536  Matrix<Gradient<0>, 3, 3> skew_g(MatCrossVec(g));
1537  Matrix<Gradient<0>, 3, 3> skew_gmf(MatCrossVec(g - f));
1538  Vector<Gradient<0>, 3> gmf = g - f;
1539  Gradient<0> norm_Ax = Norm(A * x);
1540  Gradient<0> z = Norm(A * x) / Norm(Ad * x) + (Norm(A * x) / Norm(Ad * x) - Norm(A * x) / Norm(Ad * x)) * exp(-pow(Norm(x) / 5., 3./2.));
1541  doublereal zd = Norm(Ad * v) / Norm(Ad * v) + (Norm(Ad * v) / Norm(Ad * v) - Norm(Ad * v) / Norm(Ad * v)) * exp(-pow(Norm(v) / 5., 3./2.));
1542 
1543  for (int i = 1; i <= 3; ++i) {
1544  for (int j = 1; j <= 3; ++j) {
1545  if (i == j) {
1546  assert(skew_g(i, j).bIsEqual(Gradient<0>()));
1547  assert(skew_gmf(i, j).bIsEqual(Gradient<0>()));
1548  } else {
1549  assert(skew_g(i, j).bIsEqual(-skew_g(j, i)));
1550  assert(skew_gmf(i, j).bIsEqual(-skew_gmf(j, i)));
1551  }
1552  }
1553  }
1554 
1555  assert(skew_g(1, 2).bIsEqual(-g(3)));
1556  assert(skew_g(2, 1).bIsEqual(g(3)));
1557  assert(skew_g(1, 3).bIsEqual(g(2)));
1558  assert(skew_g(3, 1).bIsEqual(-g(2)));
1559  assert(skew_g(2, 3).bIsEqual(-g(1)));
1560  assert(skew_g(3, 2).bIsEqual(g(1)));
1561 
1562  assert(skew_gmf(1, 2).bIsEqual(-gmf(3)));
1563  assert(skew_gmf(2, 1).bIsEqual(gmf(3)));
1564  assert(skew_gmf(1, 3).bIsEqual(gmf(2)));
1565  assert(skew_gmf(3, 1).bIsEqual(-gmf(2)));
1566  assert(skew_gmf(2, 3).bIsEqual(-gmf(1)));
1567  assert(skew_gmf(3, 2).bIsEqual(gmf(1)));
1568 
1570  h(1) = 15.7;
1571  h(2) = -7.3;
1572  h(3) = 12.4;
1573 
1574  Vector<Gradient<0>, 3> i = Cross(d, h) * 5.7;
1575  Vector<Gradient<0>, 3> j = Cross(h, g) / 3.5;
1576  Vector<doublereal, 3> k = Cross(h, h) + h * 3.;
1577  Vector<Gradient<0>, 3> l = Cross(h + h, j) / 2.;
1578  Vector<Gradient<0>, 3> m = Cross(h, j - i) * 5.;
1579  Vector<doublereal, 3> n = Cross(h + h, h) + h;
1580  Vector<doublereal, 3> o = Cross(h, h + h) * 2.;
1581  Vector<doublereal, 3> p = Cross(h * 2.5, h/3.) - h;
1582  Gradient<0> r = Dot(h, g);
1583  Gradient<0> s = Dot(g, h);
1584  Gradient<0> t = Dot(g, g);
1585  doublereal u = Dot(h, h);
1586  Gradient<0> r1 = Dot(Direct(h), g);
1587  Gradient<0> r2 = Dot(h, Direct(g));
1588  Gradient<0> r3 = Dot(Direct(h), Direct(g));
1589  Gradient<0> norm_g1 = Norm(g);
1590  Gradient<0> norm_g2 = Norm(Cross(d + e, f - c) + b);
1591 
1592  assert(r.bIsEqual(r1));
1593  assert(r.bIsEqual(r2));
1594  assert(r.bIsEqual(r3));
1595 
1596  std::cout << "x = " << std::endl << x << std::endl;
1597  std::cout << "b = A * x" << std::endl << b << std::endl;
1598  std::cout << "c = -A * x" << std::endl << c << std::endl;
1599  std::cout << "d = cross(c, b) * 5" << std::endl << d << std::endl;
1600  std::cout << "e = cross(c + d, b) / 2" << std::endl << e << std::endl;
1601  std::cout << "f = cross(e, d + c) - e" << std::endl << f << std::endl;
1602  std::cout << "g = cross(d + e, f - c) + b" << std::endl << g << std::endl;
1603  std::cout << "h = " << std::endl << h << std::endl;
1604  std::cout << "i = cross(d, h) * 5.7" << std::endl << i << std::endl;
1605  std::cout << "j = cross(h, g) / 3.5" << std::endl << j << std::endl;
1606  std::cout << "k = cross(h, h) + h * 3" << std::endl << k << std::endl;
1607  std::cout << "l = cross(h + h, j) / 2" << std::endl << l << std::endl;
1608  std::cout << "m = cross(h, j - i) * 5" << std::endl << m << std::endl;
1609  std::cout << "n = cross(h + h, h) + h" << std::endl << n << std::endl;
1610  std::cout << "o = cross(h, h + h) * 2" << std::endl << o << std::endl;
1611  std::cout << "p = cross(h * 2.5, h / 3) - h" << std::endl << p << std::endl;
1612  std::cout << "r = Dot(h, g) = " << r << std::endl;
1613  std::cout << "s = Dot(g, h) = " << s << std::endl;
1614  std::cout << "t = Dot(g, g) = " << t << std::endl;
1615  std::cout << "u = Dot(h, h) = " << u << std::endl;
1616  std::cout << "norm_g1 = Norm(g) = " << norm_g1 << std::endl;
1617  std::cout << "norm_g2 = Norm(Cross(d + e, f - c) + b) = " << norm_g2 << std::endl;
1618  std::cout << "z=" << z << std::endl;
1619  std::cout << "zd=" << zd << std::endl;
1620 
1621  for (index_type i = 1; i <= b2.iGetNumRows(); ++i) {
1622  assert(bCompare(b2d(i).dGetValue(), b2(i).dGetValue(), dTol));
1623  assert(bCompare(b2d1(i).dGetValue(), -2 * b2(i).dGetValue(), dTol));
1624  assert(bCompare(b2(i), b(i), dTol));
1625  assert(bCompare(b3(i), Gradient<0>(3 * b(i)), dTol));
1626  assert(bCompare(b4(i), Gradient<0>(2 * b(i)), dTol));
1627  assert(bCompare(b5(i), b(i), dTol));
1628  assert(bCompare(b6(i), b(i), dTol));
1629  assert(bCompare(b7(i), b(i), dTol));
1630  assert(bCompare<scalar_deriv_type>(b8(i).dGetValue(), b(i).dGetValue(), dTol));
1631  assert(bCompare(c(i), Gradient<0>(-b(i)), dTol));
1632  }
1633 
1634 
1635  assert(bCompare(b(1).dGetValue(), 6300., dTol));
1636  assert(bCompare(b(2).dGetValue(), 11300., dTol));
1637  assert(bCompare(b(3).dGetValue(), 16300., dTol));
1638 
1639  assert(bCompare(D(1, 1).dGetValue(), -630., dTol));
1640  assert(bCompare(D(1, 2).dGetValue(), -1130., dTol));
1641  assert(bCompare(D(1, 3).dGetValue(), -1630., dTol));
1642  assert(bCompare(D(2, 1).dGetValue(), -1130., dTol));
1643  assert(bCompare(D(2, 2).dGetValue(), -2030., dTol));
1644  assert(bCompare(D(2, 3).dGetValue(), -2930., dTol));
1645  assert(bCompare(D(3, 1).dGetValue(), -1630., dTol));
1646  assert(bCompare(D(3, 2).dGetValue(), -2930., dTol));
1647  assert(bCompare(D(3, 3).dGetValue(), -4230., dTol));
1648 
1649  testGradient(oct_b, b, dTol);
1650  testGradient(oct_c, c, dTol);
1651  testGradient(oct_d, d, dTol);
1652  testGradient(oct_e, e, dTol);
1653  testGradient(oct_f, f, dTol);
1654  testGradient(oct_g, g, dTol);
1655  testGradient(oct_i, i, dTol);
1656  testGradient(oct_j, j, dTol);
1657  testGradient(oct_l, l, dTol);
1658  testGradient(oct_m, m, dTol);
1659  testGradient(oct_r, r, dTol);
1660  testGradient(oct_s, s, dTol);
1661  testGradient(oct_t, t, dTol);
1662  testGradient(oct_norm_g, norm_g1, dTol);
1663  testGradient(oct_norm_g, norm_g2, dTol);
1664 
1665  A.Reset();
1666  x.Reset();
1667  b.Reset();
1668  std::cout << "after reset ...\n";
1669  std::cout << "A=" << A << std::endl;
1670  std::cout << "x=" << x << std::endl;
1671  std::cout << "b=" << b << std::endl;
1672 }
GradientExpression< UnaryExpr< FuncExp, Expr > > exp(const GradientExpression< Expr > &u)
Definition: gradient.h:2975
bool bIsEqual(const Gradient &g) const
Definition: gradient.h:2604
scalar_func_type dGetValue(scalar_func_type d)
Definition: gradient.h:2845
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: matvectest.cc:367
MatrixExpression< TransposedMatrix< MatrixDirectExpr< Matrix< T, N_rows, N_cols > > >, N_cols, N_rows > Transpose(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2206
GradientExpression< BinaryExpr< FuncPow, LhsExpr, RhsExpr > > pow(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2961
static const struct testMatVecProductGradient_testData::test_s oct_s
static const struct testMatVecProductGradient_testData::test_l oct_l
static const struct testMatVecProductGradient_testData::test_m oct_m
index_type iGetNumRows() const
Definition: matvec.h:2118
static const struct testMatVecProductGradient_testData::test_c oct_c
integer index_type
Definition: gradient.h:104
index_type iGetNumCols() const
Definition: matvec.h:2119
static const struct testMatVecProductGradient_testData::test_e oct_e
static const struct testMatVecProductGradient_testData::test_j oct_j
void Reset()
Definition: matvec.h:2356
ColumnVectorType GetCol(index_type iCol) const
Definition: matvec.h:2112
MatrixExpression< MatrixDirectExpr< Matrix< T, N_rows, N_cols > >, N_rows, N_cols > Direct(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2185
static const struct testMatVecProductGradient_testData::test_d oct_d
static const struct testMatVecProductGradient_testData::test_f oct_f
void Reset()
Definition: matvec.h:1981
static const char * dof[]
Definition: drvdisp.cc:195
static const struct testMatVecProductGradient_testData::test_g oct_g
static const struct testMatVecProductGradient_testData::test_i oct_i
DotTraits< VectorExprLhs, VectorExprRhs, N_rows, N_rows >::ExpressionType Dot(const VectorExpression< VectorExprLhs, N_rows > &u, const VectorExpression< VectorExprRhs, N_rows > &v)
Definition: matvec.h:3133
static const struct testMatVecProductGradient_testData::test_b oct_b
VectorExpression< VectorCrossExpr< VectorLhsExpr, VectorRhsExpr >, 3 > Cross(const VectorExpression< VectorLhsExpr, 3 > &u, const VectorExpression< VectorRhsExpr, 3 > &v)
Definition: matvec.h:3248
void testGradient(const S &ref, const Vector< Gradient< N_SIZE >, N_rows > &v, doublereal dTol)
Definition: matvectest.cc:1108
index_type iGetNumRows() const
Definition: matvec.h:2480
VectorExpression< VectorExpr, N_rows >::ScalarType Norm(const VectorExpression< VectorExpr, N_rows > &u)
Definition: matvec.h:3163
static std::stack< cleanup * > c
Definition: cleanup.cc:59
RowVectorType GetRow(index_type iRow) const
Definition: matvec.h:2105
static const struct testMatVecProductGradient_testData::test_r oct_r
static const struct testMatVecProductGradient_testData::test_norm_g oct_norm_g
double doublereal
Definition: colamd.c:52
MatrixInit< MatCrossInit< T, VectorDirectExpr< Vector< T, 3 > > >, T, 3, 3 > MatCrossVec(const Vector< T, 3 > &v, doublereal d=0.)
Definition: matvec.h:2761
static const struct testMatVecProductGradient_testData::test_t oct_t
const int I1
Definition: matvectest.cc:1787

Here is the call graph for this function:

template<index_type N_SIZE>
void testMatVecProductGradient2 ( index_type  iNumDeriv,
int  N 
)

Definition at line 1675 of file matvectest.cc.

References dof, grad::MapVectorBase::GLOBAL, grad::Matrix< T, N_rows, N_cols >::iGetNumCols(), grad::Matrix< T, N_rows, N_cols >::iGetNumRows(), and mbdyn_clock_time().

1675  {
1676  Matrix<Gradient<N_SIZE>, 3, 5> A;
1677  Matrix<Gradient<N_SIZE>, 5, 7> B;
1678  LocalDofMap dof;
1679 
1680  srand(0);
1681 
1682  for (index_type i = 0; i < A.iGetNumRows(); ++i) {
1683  for (index_type j = 0; j < A.iGetNumCols(); ++j) {
1684  A(i + 1, j + 1).SetValue(10. * (i + 1) + j + 1 + rand());
1685  A(i + 1, j + 1).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::GLOBAL, 0.);
1686  for (int k = 0; k < iNumDeriv; ++k) {
1687  A(i + 1, j + 1).SetDerivativeGlobal(k, 1000. * (i + 1) + 100. * (j + 1) + k + 1 + rand());
1688  }
1689  }
1690  }
1691 
1692  for (index_type i = 0; i < B.iGetNumRows(); ++i) {
1693  for (index_type j = 0; j < B.iGetNumCols(); ++j) {
1694  B(i + 1, j + 1).SetValue(1000. * (i + 1) + 100. * (j + 1) + rand());
1695  B(i + 1, j + 1).DerivativeResizeReset(&dof, 0, iNumDeriv, MapVectorBase::GLOBAL, 0.);
1696  for (int k = 0; k < iNumDeriv; ++k) {
1697  B(i + 1, j + 1).SetDerivativeGlobal(k, 10000. * (i + 1) + 1000. * (j + 1) + 10. * (k + 1) + rand());
1698  }
1699  }
1700  }
1701 
1702  Matrix<Gradient<N_SIZE>, 3, 7> C;
1703 
1704  double start = mbdyn_clock_time();
1705 
1706  for (int i = 0; i < N; ++i) {
1707  C = A * B;
1708  }
1709 
1710  double dt = (mbdyn_clock_time() - start) / N;
1711 
1712  std::cerr << "iMaxDerivatives=" << iNumDeriv << std::endl;
1713  std::cerr << "dt=" << dt << std::endl;
1714  std::cout << "A=\n" << A << std::endl;
1715  std::cout << "B=\n" << B << std::endl;
1716  std::cout << "C=\n" << C << std::endl;
1717 }
double mbdyn_clock_time()
Definition: clock_time.cc:51
index_type iGetNumRows() const
Definition: matvec.h:2118
integer index_type
Definition: gradient.h:104
index_type iGetNumCols() const
Definition: matvec.h:2119
static const char * dof[]
Definition: drvdisp.cc:195

Here is the call graph for this function:

void testScalarTypeTraits ( )

Definition at line 92 of file matvectest.cc.

References grad::Gradient< N_SIZE >::iGetMaxDerivatives(), grad::RangeVector< T, N_SIZE >::iGetMaxSize(), and v0.

Referenced by main().

92  {
94  typedef ScalarBinaryExpressionTraits<FuncPlus, Gradient<0>, Gradient<0>, Gradient<0> >::ExpressionType Expr002;
95  typedef ScalarBinaryExpressionTraits<FuncPlus, Gradient<0>, doublereal, Gradient<0> >::ExpressionType Expr003;
96  typedef ScalarBinaryExpressionTraits<FuncPlus, Gradient<0>, Gradient<0>, doublereal>::ExpressionType Expr004;
97  typedef ScalarBinaryExpressionTraits<FuncPlus, Gradient<0>, Expr003, Expr004>::ExpressionType Expr005;
98  typedef ScalarBinaryExpressionTraits<FuncPlus, Gradient<0>, Expr005, Expr001>::ExpressionType Expr006;
99  typedef ScalarBinaryExpressionTraits<FuncPlus, Gradient<0>, Expr005, Expr006>::ExpressionType Expr007;
103  typedef ScalarBinaryExpressionTraits<FuncPlus, Gradient<0>, Expr010, Expr007>::ExpressionType Expr011;
117  std::cout << "Expr001=" << typeid(Expr001).name() << std::endl;
118  std::cout << "Expr002=" << typeid(Expr002).name() << std::endl;
119  std::cout << "Expr003=" << typeid(Expr003).name() << std::endl;
120  std::cout << "Expr004=" << typeid(Expr004).name() << std::endl;
121  std::cout << "Expr005=" << typeid(Expr005).name() << std::endl;
122  std::cout << "Expr006=" << typeid(Expr006).name() << std::endl;
123  std::cout << "Expr007=" << typeid(Expr007).name() << std::endl;
124  std::cout << "T001=" << typeid(T001).name() << std::endl;
125  std::cout << "T002=" << typeid(T002).name() << std::endl;
126  std::cout << "T003=" << typeid(T003).name() << std::endl;
127  std::cout << "T004=" << typeid(T004).name() << std::endl;
128  std::cout << "T005=" << typeid(T005).name() << std::endl;
129  std::cout << "T006=" << typeid(T006).name() << std::endl;
130  std::cout << "T007=" << typeid(T007).name() << std::endl;
131  std::cout << "T008=" << typeid(T008).name() << std::endl;
132  std::cout << "T009=" << typeid(T009).name() << std::endl;
133  std::cout << "T010=" << typeid(T010).name() << std::endl;
134  std::cout << "T011=" << typeid(T011).name() << std::endl;
135  assert(typeid(T001) == typeid(doublereal));
136  assert(typeid(T002) == typeid(Gradient<0>));
137  assert(typeid(T003) == typeid(Gradient<0>));
138  assert(typeid(T004) == typeid(Gradient<0>));
139  assert(typeid(T005) == typeid(Gradient<0>));
140  assert(typeid(T006) == typeid(Gradient<0>));
141  assert(typeid(T007) == typeid(Gradient<0>));
142  assert(typeid(T008) == typeid(doublereal));
143  assert(typeid(T009) == typeid(doublereal));
144  assert(typeid(T010) == typeid(doublereal));
145  assert(typeid(T011) == typeid(Gradient<0>));
146 
147  const index_type N_rows = 3;
148  typedef VectorExpression<VectorVectorVectorBinaryExpr<ScalarBinaryOperation<FuncPlus, ScalarTypeTraits<Gradient<3> >::DirectExpressionType, ScalarTypeTraits<Gradient<3> >::DirectExpressionType>, VectorDirectExpr<Vector<Gradient<3>, N_rows> >, VectorDirectExpr<Vector<Gradient<3>, N_rows> > >, N_rows> V001;
149  typedef SumTraits<V001, N_rows, 2> Sum003;
150  Sum003 s003;
151  std::cout << typeid(s003).name() << std::endl;
152 
153  std::cout << "sizeof(Matrix<Gradient<12>, 3, 3>())="
154  << sizeof(Matrix<Gradient<12>, 3, 3>) << std::endl;
155 
156  std::cout << "sizeof(Vector<Gradient<12> >())="
157  << sizeof(Vector<Gradient<12>, 3>) << std::endl;
158 
159  std::cout << "sizeof(Matrix<Gradient<12>, 3, 3>() * Vector<Gradient<12>, 3>())="
160  << sizeof(Matrix<Gradient<12>, 3, 3>() * Vector<Gradient<12>, 3>()) << std::endl;
161 
163  std::cout << "v3.iGetMaxSize()=" << v3.iGetMaxSize() << std::endl;
165  std::cout << "v0.iGetMaxSize()=" << v0.iGetMaxSize() << std::endl;
166 
167  std::cout << typeid(C001).name() << std::endl;
168  std::cout << typeid(C002).name() << std::endl;
169 
170  Gradient<0> g0;
171  std::cout << "g0 max derivatives: " << g0.iGetMaxDerivatives() << std::endl;
172 }
integer index_type
Definition: gradient.h:104
static index_type iGetMaxSize()
Definition: gradient.h:496
static const std::vector< doublereal > v0
Definition: fixedstep.cc:45
double doublereal
Definition: colamd.c:52
index_type iGetMaxDerivatives() const
Definition: gradient.h:2596

Here is the call graph for this function:

void testSolve ( )

Definition at line 2843 of file matvectest.cc.

References Mat3x3::LDLSolve(), grad::Norm(), Mat3x3::Solve(), grad::sqrt(), and grad::Tabular().

Referenced by main().

2843  {
2844  const Mat3x3 A(1.32972137393521, 0.61849905020148, 0.709385530146435,
2845  0.61849905020148, 0.290559435134808, 0.344471283014357,
2846  0.709385530146435, 0.344471283014357, 0.752776020323268);
2847 
2848  const Vec3 b(0.815664130323409,
2849  0.255816061333836,
2850  0.416955203644826);
2851 
2852  const doublereal dTol = sqrt(std::numeric_limits<doublereal>::epsilon());
2853 
2854  const Vec3 x1 = A.Solve(b);
2855  const Vec3 x2 = A.LDLSolve(b);
2856  const doublereal f1 = (A * x1 - b).Norm();
2857  const doublereal f2 = (A * x2 - b).Norm();
2858  std::cout << "A=" << Tabular(Matrix<doublereal, 3, 3>(A)) << std::endl;
2859  std::cout << "b=" << b << std::endl;
2860  std::cout << "x1=" << x1 << std::endl;
2861  std::cout << "x2=" << x2 << std::endl;
2862  std::cout << "f1=" << f1 << std::endl;
2863  std::cout << "f2=" << f2 << std::endl;
2864  assert(f1 < dTol);
2865  assert(f2 < dTol);
2866 }
Definition: matvec3.h:98
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
VectorExpression< VectorExpr, N_rows >::ScalarType Norm(const VectorExpression< VectorExpr, N_rows > &u)
Definition: matvec.h:3163
TabularMatrixView< T, N_rows, N_cols > Tabular(const Matrix< T, N_rows, N_cols > &A, int iColWidth=10)
Definition: matvec.h:3012
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

void testSubVecAss ( )

Definition at line 2705 of file matvectest.cc.

References grad::GradientAssVec< doublereal >::AddItem(), grad::Gradient< N_SIZE >::DerivativeResizeReset(), SparseSubMatrixHandler::dGetCoef(), MySubVectorHandler::dGetCoef(), dof, grad::MapVectorBase::GLOBAL, SparseSubMatrixHandler::iGetColIndex(), SparseSubMatrixHandler::iGetNumRows(), SparseSubMatrixHandler::iGetRowIndex(), MySubVectorHandler::iGetSize(), grad::Gradient< N_SIZE >::SetDerivativeGlobal(), and grad::Gradient< N_SIZE >::SetValue().

Referenced by main().

2705  {
2706  LocalDofMap dof;
2707  const integer N = 3;
2708  MySubVectorHandler vh(N);
2709 
2710  GradientAssVec<doublereal> WorkVec(vh);
2711 
2712  for (integer i = 1; i <= N; ++i) {
2713  WorkVec.AddItem(i, i * 10.);
2714  }
2715 
2716  SparseSubMatrixHandler mh(4*N);
2717  GradientAssVec<Gradient<4> > WorkMat(mh);
2718 
2719  for (integer i = 1; i <= N; ++i) {
2720  Gradient<4> g;
2721  g.SetValue(i * 10.);
2722  g.DerivativeResizeReset(&dof, 1, 5, MapVectorBase::GLOBAL, 0.);
2723  for (integer k = 1; k <= 4; ++k) {
2724  g.SetDerivativeGlobal(k, i + k * 0.1);
2725  }
2726 
2727  WorkMat.AddItem(i, g);
2728  }
2729 
2730  std::cout << "WorkVec=" << std::endl;
2731  for (integer i = 1; i <= vh.iGetSize(); ++i) {
2732  std::cout << " " << vh.dGetCoef(i) << std::endl;
2733  }
2734 
2735  std::cout << std::endl;
2736 
2737  std::cout << "WorkMat=" << std::endl;
2738 
2739  for (integer i = 1; i <= mh.iGetNumRows(); ++i) {
2740  std::cout << " " << mh.iGetRowIndex(i)
2741  << " " << mh.iGetColIndex(i)
2742  << " " << mh.dGetCoef(i, 0) << std::endl;
2743  }
2744 
2745  std::cout << std::endl;
2746 }
void SetValue(scalar_func_type dVal)
Definition: gradient.h:2506
void SetDerivativeGlobal(index_type iGlobalDof, scalar_deriv_type dCoef)
Definition: gradient.h:2566
static const char * dof[]
Definition: drvdisp.cc:195
void DerivativeResizeReset(LocalDofMap *pMap, index_type iStartGlobal, index_type iEndGlobal, MapVectorBase::GlobalScope s, scalar_deriv_type dVal)
Definition: gradient.h:2538
long int integer
Definition: colamd.c:51

Here is the call graph for this function:

void testSubVecAssMatVec ( )

Definition at line 2748 of file matvectest.cc.

References grad::GradientAssVec< doublereal >::AddItem(), grad::GradientAssVecBase::APPEND, SparseSubMatrixHandler::dGetCoef(), MySubVectorHandler::dGetCoef(), dof, grad::MapVectorBase::GLOBAL, SparseSubMatrixHandler::iGetColIndex(), SparseSubMatrixHandler::iGetNumRows(), SparseSubMatrixHandler::iGetRowIndex(), MySubVectorHandler::iGetRowIndex(), and MySubVectorHandler::iGetSize().

Referenced by main().

2748  {
2749  LocalDofMap dof;
2750  const integer N = 3;
2751  MySubVectorHandler vh(2*N);
2752 
2754 
2755  for (integer i = 1; i <= 3; ++i) {
2756  v(i) = i * 10;
2757  }
2758 
2759  GradientAssVec<doublereal> WorkVec(vh);
2760 
2761  WorkVec.AddItem(1, v);
2762 
2763  SparseSubMatrixHandler mh(2*4*N);
2764  GradientAssVec<Gradient<4> > WorkMat(mh);
2765 
2766  Vector<Gradient<4>, 3> g;
2767 
2768  for (integer i = 1; i <= 3; ++i) {
2769  g(i).SetValue(i * 10.);
2770  g(i).DerivativeResizeReset(&dof, 1, 5, MapVectorBase::GLOBAL, 0.);
2771  for (integer k = 1; k <= 4; ++k) {
2772  g(i).SetDerivativeGlobal(k, i + k * 0.1);
2773  }
2774  }
2775 
2776  WorkMat.AddItem(1, g);
2777 
2778  GradientAssVec<doublereal> WorkVec2(vh, GradientAssVecBase::APPEND);
2779  Vector<doublereal, 3> v2 = v * 2.;
2780  WorkVec2.AddItem(4, v2);
2781 
2782  GradientAssVec<Gradient<4> > WorkMat2(mh, GradientAssVecBase::APPEND);
2783  Vector<Gradient<4>, 3> g2 = g * 2.;
2784  WorkMat2.AddItem(4, g2);
2785 
2786  std::cout << "v=" << std::endl << v << std::endl;
2787  std::cout << "WorkVec=" << std::endl;
2788  for (integer i = 1; i <= vh.iGetSize(); ++i) {
2789  std::cout << " " << vh.iGetRowIndex(i) << " " << vh.dGetCoef(i) << std::endl;
2790  }
2791 
2792  std::cout << std::endl;
2793 
2794  std::cout << "g=" << std::endl << g << std::endl;
2795 
2796  std::cout << "WorkMat=" << std::endl;
2797 
2798  for (integer i = 1; i <= mh.iGetNumRows(); ++i) {
2799  std::cout << " " << mh.iGetRowIndex(i)
2800  << " " << mh.iGetColIndex(i)
2801  << " " << mh.dGetCoef(i, 0) << std::endl;
2802  }
2803 
2804  std::cout << std::endl;
2805 }
static const char * dof[]
Definition: drvdisp.cc:195
long int integer
Definition: colamd.c:51

Here is the call graph for this function:

template<index_type iRowCount, index_type iMaxDeriv, typename Function , typename FunctionF77 >
void testVecOp ( const int  M,
const int  N,
Function  f,
FunctionF77  f77,
const char *  function 
)

Definition at line 1312 of file matvectest.cc.

References grad::dGetValue(), dof, grad::MapVectorBase::GLOBAL, grad::Vector< T, N_rows >::iGetNumRows(), and mbdyn_clock_time().

1312  {
1313  Vector<Gradient<iMaxDeriv>, iRowCount> x, y, z;
1314  LocalDofMap dof;
1315 
1316  for (index_type i = 1; i <= x.iGetNumRows(); ++i) {
1317  x(i).SetValuePreserve(i * 100);
1318  x(i).DerivativeResizeReset(&dof, 0, N, MapVectorBase::GLOBAL, 0.);
1319  y(i).SetValuePreserve(i);
1320  y(i).DerivativeResizeReset(&dof, 0, N, MapVectorBase::GLOBAL, 0.);
1321 
1322  for (int j = 0; j < N; ++j) {
1323  x(i).SetDerivativeGlobal(j, (j + 1));
1324  y(i).SetDerivativeGlobal(j, (j + 1));
1325  }
1326  }
1327 
1328  double start = mbdyn_clock_time();
1329 
1330  for (int i = 0; i < M; ++i) {
1331  f(x, y, z);
1332  }
1333 
1334  const double dt = mbdyn_clock_time() - start;
1335 
1336  std::cerr << "C++: testVecAdd<" << iRowCount << "," << iMaxDeriv << ">(" << M << ", " << N << ", \"" << function << "\"):" << dt << std::endl;
1337 
1338  doublereal xF[iRowCount], yF[iRowCount], zF[iRowCount];
1339  doublereal *xdF = new doublereal[iRowCount*N];
1340  doublereal *ydF = new doublereal[iRowCount*N];
1341  doublereal *zdF = new doublereal[iRowCount*N];
1342 
1343  for (int i = 0; i < iRowCount; ++i) {
1344  xF[i] = x(i + 1).dGetValue();
1345  yF[i] = y(i + 1).dGetValue();
1346  zF[i] = 0.;
1347 
1348  for (int j = 0; j < N; ++j) {
1349  xdF[i * N + j] = x(i + 1).dGetDerivativeLocal(j);
1350  ydF[i * N + j] = y(i + 1).dGetDerivativeLocal(j);
1351  zdF[i * N + j] = 0.;
1352  }
1353  }
1354 
1355  start = mbdyn_clock_time();
1356 
1357  for (int i = 0; i < M; ++i) {
1358  f77(xF, xdF, yF, ydF, zF, zdF, iRowCount, N);
1359  }
1360 
1361  const double dtF77 = mbdyn_clock_time() - start;
1362 
1363  std::cerr << "F77: testVecAdd<" << iRowCount << "," << iMaxDeriv << ">(" << M << ", " << N << ", \"" << function << "\"):" << dtF77 << std::endl;
1364  std::cerr << "overhead=" << dt/std::max(std::numeric_limits<doublereal>::epsilon(), dtF77) << std::endl;
1365 
1366  for (int i = 0; i < iRowCount; ++i) {
1367  assert(xF[i] == x(i + 1).dGetValue());
1368  assert(yF[i] == y(i + 1).dGetValue());
1369  assert(zF[i] == z(i + 1).dGetValue());
1370 
1371  for (int j = 0; j < N; ++j) {
1372  assert(xdF[i * N + j] == x(i + 1).dGetDerivativeLocal(j));
1373  assert(ydF[i * N + j] == y(i + 1).dGetDerivativeLocal(j));
1374  assert(zdF[i * N + j] == z(i + 1).dGetDerivativeLocal(j));
1375  }
1376  }
1377 
1378  delete [] xdF;
1379  delete [] ydF;
1380  delete [] zdF;
1381 }
scalar_func_type dGetValue(scalar_func_type d)
Definition: gradient.h:2845
double mbdyn_clock_time()
Definition: clock_time.cc:51
integer index_type
Definition: gradient.h:104
static const char * dof[]
Definition: drvdisp.cc:195
index_type iGetNumRows() const
Definition: matvec.h:2480
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

void tic ( )

Definition at line 2874 of file matvectest.cc.

References mbdyn_clock_time().

Referenced by callFunc(), func2(), and func2ad().

2874  {
2876 }
double mbdyn_clock_time()
Definition: clock_time.cc:51
doublereal dStartTime
Definition: matvectest.cc:2868

Here is the call graph for this function:

void tic ( doublereal dTime)

Definition at line 2870 of file matvectest.cc.

References mbdyn_clock_time().

2870  {
2871  dTime = mbdyn_clock_time();
2872 }
double mbdyn_clock_time()
Definition: clock_time.cc:51

Here is the call graph for this function:

doublereal toc ( )

Definition at line 2878 of file matvectest.cc.

References dStartTime, and mbdyn_clock_time().

Referenced by callFunc().

2878  {
2879  return mbdyn_clock_time() - dStartTime;
2880 }
double mbdyn_clock_time()
Definition: clock_time.cc:51
doublereal dStartTime
Definition: matvectest.cc:2868

Here is the call graph for this function:

Variable Documentation

doublereal dStartTime

Definition at line 2868 of file matvectest.cc.

Referenced by toc().

const integer nbdirsmax = 12

Definition at line 277 of file matvectest.cc.

Referenced by func2ad().

int NLoops = 1

Definition at line 82 of file matvectest.cc.

Referenced by callFunc(), callFunc2(), main(), MatManip_test(), and testMatVec3().

int NLoopsAss = 1

Definition at line 83 of file matvectest.cc.