MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
gradienttest.cc File Reference
#include "mbconfig.h"
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <functional>
#include <typeinfo>
#include <cmath>
#include "clock_time.h"
#include "gradient.h"
Include dependency graph for gradienttest.cc:

Go to the source code of this file.

Macros

#define M_PI   3.14159265358979
 
#define GRADIENT_DEBUG   1
 

Functions

void tic ()
 
void tic (doublereal &dTime)
 
doublereal toc ()
 
doublereal random1 ()
 
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<int N_SIZE>
void testRangeVector ()
 
template<int N_SIZE>
void testMapVector ()
 
template<typename T >
void func (const T &u, const T &v, const T &w, doublereal e, T &f)
 
template<typename T >
void func_tmp (const T &u, const T &v, const T &w, doublereal e, T &f)
 
doublereal sec (doublereal x)
 
void funcDeriv (index_type N, doublereal u, const doublereal ud[], doublereal v, const doublereal vd[], doublereal w, const doublereal wd[], doublereal e, doublereal &f, doublereal fd[])
 
template<int N_SIZE>
void testGradient (index_type N)
 
template<index_type N_SIZE>
void testGradient2 ()
 
void testGradientCopy (int N)
 
template<index_type N_SIZE>
void testDifferentDofMaps (index_type N)
 
template<index_type N_SIZE>
void testGradientLin (int N)
 
int main (int argc, char *argv[])
 

Variables

int NLoops = 1
 
int NLoopsAss = 1
 
doublereal dStartTime
 

Macro Definition Documentation

#define GRADIENT_DEBUG   1

Definition at line 71 of file gradienttest.cc.

Referenced by main().

#define M_PI   3.14159265358979

Definition at line 67 of file gradienttest.cc.

Referenced by PlaneHingeJoint::AfterConvergence(), PlaneRotationJoint::AfterConvergence(), Wheel4::AfterConvergence(), AxialRotationJoint::AfterConvergence(), PlanePinJoint::AfterConvergence(), CyclocopterPolimi::AfterConvergence(), ModLugreFriction::alpha(), ModLugreFriction::alphad_v(), ModLugreFriction::alphad_z(), TheodorsenAeroData::AssJac(), RotorTrimBase::AssRes(), DynamicInflowRotor::AssRes(), PetersHeRotor::AssRes(), CyclocopterPolimi::AssRes(), c81_aerod2(), c81_aerod2_u(), ScrewJointSh_c::ComputePitchAngle(), Control_valve::Control_valve(), CosineDriveCaller::CosineDriveCaller(), Motor::dGetPhiElectric(), PlaneHingeJoint::dGetPrivData(), PlaneRotationJoint::dGetPrivData(), AxialRotationJoint::dGetPrivData(), PlanePinJoint::dGetPrivData(), do_eig(), Dynamic_control_valve::Dynamic_control_valve(), Mat3x3::EigSym(), FourierSeriesDriveCaller::FourierSeriesDriveCaller(), getbladeparams(), GlauertRotor::GetInducedVelocity(), ManglerRotor::GetInducedVelocity(), CyclocopterPolimi::GetInducedVelocity(), MBDynParser::GetMatR2vec(), getrotorparams(), UniformRotor::Init(), GlauertRotor::Init(), ManglerRotor::Init(), DynamicInflowRotor::Init(), PetersHeRotor::Init(), main(), MatManip_test(), mp_ctg_t(), mp_tan_t(), Wheel2::Output(), GenericAerodynamicForce::Output(), Wheel4::Output(), Pressure_flow_control_valve::Pressure_flow_control_valve(), ReadGenericAerodynamicForce(), AerodynamicOutput::SetData(), SineDriveCaller::SineDriveCaller(), Unwrap(), and Wheel2::Wheel2().

Function Documentation

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

Definition at line 91 of file gradienttest.cc.

Referenced by func_tmp(), testGradient(), and testGradient2().

91  {
92  doublereal dTolAbs = std::max<T>(1., std::max<T>(std::abs(a), std::abs(b))) * dTolRel;
93 
94  if (!(std::abs(a - b) <= dTolAbs)) {
95  std::cerr << "a = " << a << " != b = " << b << std::endl;
96  return false;
97  }
98 
99  return true;
100 }
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 103 of file gradienttest.cc.

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

103  {
104  doublereal dTolAbs = std::max(1., std::max(std::abs(a.dGetValue()), std::abs(b.dGetValue()))) * dTolRel;
105 
106  if (std::abs(a.dGetValue() - b.dGetValue()) > dTolAbs) {
107  std::cerr << "a = " << a.dGetValue() << " != b = " << b.dGetValue() << std::endl;
108  return false;
109  }
110 
111  index_type iStart = std::min(a.iGetStartIndexLocal(), b.iGetStartIndexLocal());
112  index_type iEnd = std::max(a.iGetEndIndexLocal(), b.iGetEndIndexLocal());
113 
114  for (index_type i = iStart; i < iEnd; ++i) {
115  doublereal dTolAbs = std::max(1., std::max(std::abs(a.dGetDerivativeLocal(i)), std::abs(b.dGetDerivativeLocal(i)))) * dTolRel;
116 
117  if (std::abs(a.dGetDerivativeLocal(i) - b.dGetDerivativeLocal(i)) > dTolAbs) {
118  std::cerr << "ad(" << i << ") = " << a.dGetDerivativeLocal(i) << " != bd(" << i << ") = " << b.dGetDerivativeLocal(i) << std::endl;
119  return false;
120  }
121  }
122 
123  return true;
124 }
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 >
void func ( const T &  u,
const T &  v,
const T &  w,
doublereal  e,
T &  f 
)

Definition at line 309 of file gradienttest.cc.

References grad::cos(), grad::pow(), grad::sin(), and grad::tan().

Referenced by MathParser::StaticNameSpace::GetFunc(), MathParser::StaticNameSpace::IsFunc(), MBDynErrBase::MBDynErrBase(), ParseScalarFunction(), ReadCL1D(), ReadCL3D(), ReadCL6D(), ReadDC1D(), ReadDC3D(), ReadDC3x3D(), ReadDC6D(), ReadDC6x6D(), ReadDescription(), ReadDriveCallerData(), ReadDriveData(), ReadGustData(), ReadTimeStepData(), grad::LocalDofMap::Reset(), testGradient(), testGradient2(), ErrIndexOutOfRange::WriteMsg(), and MathParser::StaticNameSpace::~StaticNameSpace().

309  {
310  f = ((((3 * u + 2 * v) * (u - v) / (1 - w) * pow(u/w, v - 1) * sin(v) * cos(w) * (1 - tan(-w + v))) * e + 1. - 11. + 4.5 - 1.) * 3.5 / 2.8 + u - v) * w / u;
311 }
GradientExpression< BinaryExpr< FuncPow, LhsExpr, RhsExpr > > pow(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2961
GradientExpression< UnaryExpr< FuncSin, Expr > > sin(const GradientExpression< Expr > &u)
Definition: gradient.h:2977
GradientExpression< UnaryExpr< FuncCos, Expr > > cos(const GradientExpression< Expr > &u)
Definition: gradient.h:2978
GradientExpression< UnaryExpr< FuncTan, Expr > > tan(const GradientExpression< Expr > &u)
Definition: gradient.h:2979

Here is the call graph for this function:

template<typename T >
void func_tmp ( const T &  u,
const T &  v,
const T &  w,
doublereal  e,
T &  f 
)

Definition at line 314 of file gradienttest.cc.

References bCompare(), grad::cos(), GRADIENT_ASSERT, grad::pow(), grad::sin(), and grad::tan().

314  {
315  f = u;
316  f *= 3;
317  f += 2 * v;
318  f *= (u - v);
319  f /= (1 - w);
320  f *= pow(u/w, v - 1);
321  f *= sin(v);
322  f *= cos(w);
323  f *= (1 - tan(-w + v));
324  f *= e;
325 
326 #if GRADIENT_DEBUG > 0
327  const T tmp1 =
328 #endif
329  f++;
330 
331  GRADIENT_ASSERT(tmp1 == f - 1);
332 
333  f -= 11.;
334  f += 4.5;
335 
336 #if GRADIENT_DEBUG > 0
337  const T tmp2 =
338 #endif
339  --f;
340 
341  GRADIENT_ASSERT(tmp2 == f);
342 
343 #if GRADIENT_DEBUG > 0
344  const T tmp3 = f;
345  f += f;
346  GRADIENT_ASSERT(bCompare(f, 2 * tmp3));
347  f -= f;
348  GRADIENT_ASSERT(bCompare(f, T()));
349  f = tmp3;
350 #endif
351 
352  f *= 3.5;
353  f /= 2.8;
354  f += u;
355  f -= v;
356  f *= w;
357  f /= u;
358 }
GradientExpression< BinaryExpr< FuncPow, LhsExpr, RhsExpr > > pow(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2961
GradientExpression< UnaryExpr< FuncSin, Expr > > sin(const GradientExpression< Expr > &u)
Definition: gradient.h:2977
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: gradienttest.cc:91
GradientExpression< UnaryExpr< FuncCos, Expr > > cos(const GradientExpression< Expr > &u)
Definition: gradient.h:2978
GradientExpression< UnaryExpr< FuncTan, Expr > > tan(const GradientExpression< Expr > &u)
Definition: gradient.h:2979
#define GRADIENT_ASSERT(expr)
Definition: gradient.h:74

Here is the call graph for this function:

void funcDeriv ( index_type  N,
doublereal  u,
const doublereal  ud[],
doublereal  v,
const doublereal  vd[],
doublereal  w,
const doublereal  wd[],
doublereal  e,
doublereal f,
doublereal  fd[] 
)

Definition at line 364 of file gradienttest.cc.

References grad::cos(), grad::log(), grad::pow(), sec(), grad::sin(), and grad::tan().

Referenced by testGradient(), and testGradient2().

364  {
365  const doublereal tmp1 = sin(v);
366  const doublereal tmp2 = cos(w);
367  const doublereal tmp3 = u/w;
368  const doublereal tmp6 = pow(tmp3, v-1);
369  const doublereal tmp4 = tmp1*tmp6*tmp2;
370  const doublereal tmp5 = (tan(w-v)+1);
371  const doublereal tmp7 = ((2*v+3*u)*tmp4*tmp5);
372  const doublereal tmp8 = pow(sec(w-v),2);
373  const doublereal tmp9 = (u-v);
374  const doublereal tmp10 = (1-w);
375  const doublereal tmp11 = (v-1);
376  const doublereal tmp12 = (2*v+3*u);
377  const doublereal tmp13 = tmp9*tmp4*tmp5;
378  const doublereal tmp14 = tmp12*tmp4*tmp5;
379  const doublereal tmp15 = (tmp9*tmp12*tmp4*tmp8);
380  const doublereal tmp16 = (tmp9*tmp11*tmp14);
381  const doublereal tmp17 = tmp15/tmp10;
382  const doublereal tmp18 = tmp6*tmp2*tmp5;
383  const doublereal tmp19 = tmp9*tmp12*tmp1;
384  const doublereal tmp20 = tmp7/tmp10;
385  const doublereal tmp21 = 3.5 / 2.8;
386  const doublereal tmp22 = e * tmp21;
387  const doublereal tmp23 = ((((tmp9*tmp14)/tmp10) * e + 1. - 11. + 4.5 - 1.) * tmp21 + u - v);
388 
389  f = tmp23 * w / u;
390 
391  doublereal df_du = ((tmp16/(u*tmp10)+tmp20+(3*tmp13)/tmp10)*tmp22 + 1.) * w / u - tmp23 * w / (u * u);
392 
393  doublereal df_dv = (((tmp19*log(tmp3)*tmp18)/tmp10-tmp20+(2*tmp13)/tmp10+(tmp9*tmp12*cos(v)*tmp18)/tmp10-tmp17)*tmp22 - 1.) * w / u;
394 
395  doublereal df_dw = (-(tmp19*tmp6*sin(w)*tmp5)/tmp10-tmp16/(tmp10*w)+(tmp9*tmp14)/pow(1-w,2)+tmp17)*tmp22 * w / u + tmp23 / u;
396 
397  for (index_type i = 0; i < N; ++i) {
398  fd[i] = df_du * ud[i] + df_dv * vd[i] + df_dw * wd[i];
399  }
400 }
GradientExpression< BinaryExpr< FuncPow, LhsExpr, RhsExpr > > pow(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2961
GradientExpression< UnaryExpr< FuncSin, Expr > > sin(const GradientExpression< Expr > &u)
Definition: gradient.h:2977
doublereal sec(doublereal x)
integer index_type
Definition: gradient.h:104
GradientExpression< UnaryExpr< FuncLog, Expr > > log(const GradientExpression< Expr > &u)
Definition: gradient.h:2976
GradientExpression< UnaryExpr< FuncCos, Expr > > cos(const GradientExpression< Expr > &u)
Definition: gradient.h:2978
double doublereal
Definition: colamd.c:52
GradientExpression< UnaryExpr< FuncTan, Expr > > tan(const GradientExpression< Expr > &u)
Definition: gradient.h:2979

Here is the call graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 1817 of file gradienttest.cc.

References GRADIENT_DEBUG, NLoops, and testGradientCopy().

1817  {
1818 #ifdef HAVE_FEENABLEEXCEPT
1819  feenableexcept(FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
1820 #endif
1821 
1822  if (argc > 1) {
1823  NLoops = atol(argv[1]);
1824  }
1825 
1826  if (argc > 2) {
1827  NLoopsAss = atol(argv[2]);
1828  }
1829 
1830  testRangeVector<0>();
1831  testRangeVector<6>();
1832  testMapVector<0>();
1833  testMapVector<19>();
1834 
1835  for (index_type i = 1; i <= 12; ++i) {
1836  testGradient<0>(i);
1837  }
1838 
1839  testGradient<1>(1);
1840  testGradient<2>(2);
1841  testGradient<4>(4);
1842  testGradient<6>(6);
1843  testGradient<8>(8);
1844  testGradient<10>(10);
1845  testGradient<12>(12);
1846  testGradient2<0>();
1847  testGradient2<3>();
1848 
1849  testGradientCopy(0);
1850  testGradientCopy(1);
1851  testGradientCopy(2);
1852  testGradientCopy(4);
1853  testGradientCopy(6);
1854  testGradientCopy(8);
1855  testGradientCopy(10);
1856  testGradientCopy(15);
1857  testGradientLin<4>(4);
1858  testGradientLin<0>(4);
1859 
1860 #ifdef HAVE_BLITZ
1861  gradAssTest::testAssembly();
1862 #endif
1863 
1864  testDifferentDofMaps<3>(1);
1865  testDifferentDofMaps<4>(2);
1866  testDifferentDofMaps<5>(3);
1867  testDifferentDofMaps<6>(4);
1868  testDifferentDofMaps<7>(5);
1869  testDifferentDofMaps<8>(6);
1870 
1871  for (integer i = 1; i <= 10; ++i) {
1872  testDifferentDofMaps<0>(i);
1873  testDifferentDofMaps<12>(i);
1874  testDifferentDofMaps<14>(i);
1875  testDifferentDofMaps<16>(i);
1876  }
1877 
1878 #ifndef NDEBUG
1879  std::cerr << "All tests passed" << std::endl;
1880 #else
1881  std::cerr << "No tests have been done" << std::endl;
1882 #endif
1883 
1884  std::cerr << "GRADIENT_DEBUG=" << GRADIENT_DEBUG << std::endl;
1885 
1886  return 0;
1887 }
integer index_type
Definition: gradient.h:104
#define GRADIENT_DEBUG
Definition: gradienttest.cc:71
void testGradientCopy(int N)
int NLoopsAss
Definition: gradienttest.cc:80
long int integer
Definition: colamd.c:51
int NLoops
Definition: gradienttest.cc:79

Here is the call graph for this function:

doublereal random1 ( )

Definition at line 86 of file gradienttest.cc.

Referenced by testGradient(), and testGradient2().

86  {
87  return 2 * (doublereal(rand()) / RAND_MAX) - 1;
88 }
double doublereal
Definition: colamd.c:52
doublereal sec ( doublereal  x)

Definition at line 360 of file gradienttest.cc.

References grad::cos().

Referenced by funcDeriv().

360  {
361  return 1./cos(x);
362 }
GradientExpression< UnaryExpr< FuncCos, Expr > > cos(const GradientExpression< Expr > &u)
Definition: gradient.h:2978

Here is the call graph for this function:

template<index_type N_SIZE>
void testDifferentDofMaps ( index_type  N)

Definition at line 730 of file gradienttest.cc.

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

730  {
731  {
732  LocalDofMap dofMap1, dofMap2;
733 
734  Gradient<N_SIZE> g1(1000., MapVector<N_SIZE>(&dofMap1, 100, 100 + N, MapVectorBase::GLOBAL, 1.));
735  Gradient<N_SIZE> g2(2000., MapVector<N_SIZE>(&dofMap2, 102, 102 + N, MapVectorBase::GLOBAL, 2.));
736 
737  std::cerr << "testDifferentDofMaps<" << N_SIZE << ">(" << N << "): operator+=()\n";
738  std::cerr << "g1=" << g1 << std::endl;
739  std::cerr << "g2=" << g2 << std::endl;
740 
741  g1 += g2;
742 
743  std::cerr << "g1=" << g1 << std::endl;
744 
745  assert(g1.dGetValue() == 3000.);
746 
747  for (index_type i = 100; i < 102 + N; ++i) {
748  if (i < 100 + N || i >= 102) {
749  const doublereal d = g1.dGetDerivativeGlobal(i);
750  if (i >= 102 && i < 100 + N) {
751  assert(d == 3.);
752  } else if (i < 100 + N) {
753  assert(d == 1.);
754  } else {
755  assert(d == 2.);
756  }
757  }
758  }
759  }
760  {
761  LocalDofMap dofMap1, dofMap2;
762 
763  const doublereal u = 3, v = 4, du = 5., dv = 6.;
764  Gradient<N_SIZE> g1(u, MapVector<N_SIZE>(&dofMap1, 100, 100 + N, MapVectorBase::GLOBAL, du));
765  Gradient<N_SIZE> g2(v, MapVector<N_SIZE>(&dofMap2, 102, 102 + N, MapVectorBase::GLOBAL, dv));
766 
767  std::cerr << "testDifferentDofMaps<" << N_SIZE << ">(" << N << "): operator*=()\n";
768  std::cerr << "g1=" << g1 << std::endl;
769  std::cerr << "g2=" << g2 << std::endl;
770 
771  g1 *= g2;
772 
773  std::cerr << "g1=" << g1 << std::endl;
774 
775  assert(g1.dGetValue() == u * v);
776 
777  for (index_type i = 100; i < 102 + N; ++i) {
778  if (i < 100 + N || i >= 102) {
779  const doublereal d = g1.dGetDerivativeGlobal(i);
780  if (i >= 102 && i < 100 + N) {
781  assert(d == du * v + u * dv);
782  } else if (i < 100 + N) {
783  assert(d == du * v);
784  } else {
785  assert(d == u * dv);
786  }
787  }
788  }
789  }
790 }
integer index_type
Definition: gradient.h:104
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<int N_SIZE>
void testGradient ( index_type  N)

Definition at line 403 of file gradienttest.cc.

References bCompare(), grad::Gradient< N_SIZE >::DerivativeResizeReset(), grad::Gradient< N_SIZE >::dGetDerivativeGlobal(), grad::Gradient< N_SIZE >::dGetValue(), dof, grad::fabs(), func(), funcDeriv(), grad::MapVectorBase::GLOBAL, NLoops, random1(), grad::Gradient< N_SIZE >::SetDerivativeGlobal(), grad::Gradient< N_SIZE >::SetValuePreserve(), grad::sqrt(), and tic().

Referenced by testMatVecProductGradient().

403  {
404  assert(N_SIZE == 0 || N_SIZE == N);
405 
406  srand(0);
407 
409  Gradient<N_SIZE> u, v, w, f, f_tmp;
410  doublereal f_d;
411 
412  u.SetValuePreserve(fabs(random1()) * 10);
413  v.SetValuePreserve(random1() * 3);
414  w.SetValuePreserve(random1() * 0.01);
415 
416  u.DerivativeResizeReset(&dof, 0, N, MapVectorBase::GLOBAL, 0.);
417  v.DerivativeResizeReset(&dof, 0, N, MapVectorBase::GLOBAL, 0.);
418  w.DerivativeResizeReset(&dof, 0, N, MapVectorBase::GLOBAL, 0.);
419 
420  for (index_type i = 0; i < N; ++i) {
421  u.SetDerivativeGlobal(i, random1() * 0.01);
422  v.SetDerivativeGlobal(i, random1() * 3);
423  w.SetDerivativeGlobal(i, random1() * 10);
424  }
425 
426  doublereal* ud_C = new doublereal[N];
427  doublereal* vd_C = new doublereal[N];
428  doublereal* wd_C = new doublereal[N];
429  doublereal f_C;
430  doublereal* fd_C = new doublereal[N];
431 
432  for (index_type i = 0; i < N; ++i) {
433  ud_C[i] = u.dGetDerivativeGlobal(i);
434  vd_C[i] = v.dGetDerivativeGlobal(i);
435  wd_C[i] = w.dGetDerivativeGlobal(i);
436  }
437 
438  doublereal t_AD = 0., t_AD_tmp = 0., t_C = 0., t_d = 0.;
439 
440  for (int i = 0; i < NLoops; ++i) {
441  const doublereal e = random1();
442  doublereal start, stop;
443 
444  tic(start);
445  func(u, v, w, e, f);
446  tic(stop);
447 
448  t_AD += stop - start;
449 
450  tic(start);
451  func(u.dGetValue(), v.dGetValue(), w.dGetValue(), e, f_d);
452  tic(stop);
453 
454  t_d += stop - start;
455 
456  tic(start);
457  func(u, v, w, e, f_tmp);
458  tic(stop);
459 
460  t_AD_tmp += stop - start;
461 
462  tic(start);
463  funcDeriv(N,
464  u.dGetValue(),
465  ud_C,
466  v.dGetValue(),
467  vd_C,
468  w.dGetValue(),
469  wd_C,
470  e,
471  f_C,
472  fd_C);
473  tic(stop);
474 
475  t_C += stop - start;
476 
477  assert(bCompare(f, f_tmp, std::numeric_limits<doublereal>::epsilon()));
478  assert(bCompare(f.dGetValue(), f_C, sqrt(std::numeric_limits<doublereal>::epsilon())));
479  assert(bCompare(f.dGetValue(), f_d, std::numeric_limits<doublereal>::epsilon()));
480 
481  for (index_type j = 0; j < N; ++j) {
482  doublereal err = std::abs(f.dGetDerivativeGlobal(j) / fd_C[j] - 1.);
483  assert(err < sqrt(std::numeric_limits<scalar_deriv_type>::epsilon()));
484  }
485  }
486 
487  std::cerr << "testGradient<" << N_SIZE << ">(" << N << ")" << std::endl;
488 
489  std::cout << "dof map:" << std::endl << dof << std::endl;
490  std::cout << "u=" << u << std::endl;
491  std::cout << "v=" << v << std::endl;
492  std::cout << "w=" << w << std::endl;
493  std::cout << "f=" << f << std::endl;
494  std::cout << "f_tmp=" << f_tmp << std::endl;
495 
496  std::cout << "f_C=" << f_C << std::endl;
497  std::cout << "fd_C=" << std::endl;
498 
499  for (int i = 0; i < N; ++i) {
500  std::cout << " " << fd_C[i] << std::endl;
501  }
502 
503  std::cout << std::endl;
504 
505  std::cerr << "t_AD=" << t_AD << "s" << std::endl;
506  std::cerr << "t_d=" << t_d << "s" << std::endl;
507  std::cerr << "t_AD_tmp=" << t_AD_tmp << "s" << std::endl;
508  std::cerr << "t_C=" << t_C << "s" << std::endl;
509  std::cerr << "overhead:" << t_AD / t_C << std::endl;
510  std::cerr << "overhead tmp:" << t_AD_tmp / t_C << std::endl;
511 
512  delete [] ud_C;
513  delete [] vd_C;
514  delete [] wd_C;
515  delete [] fd_C;
516 }
scalar_deriv_type dGetDerivativeGlobal(index_type iGlobalDof) const
Definition: gradient.h:2532
integer index_type
Definition: gradient.h:104
GradientExpression< UnaryExpr< FuncFabs, Expr > > fabs(const GradientExpression< Expr > &u)
Definition: gradient.h:2973
void tic()
void func(const T &u, const T &v, const T &w, doublereal e, T &f)
void SetDerivativeGlobal(index_type iGlobalDof, scalar_deriv_type dCoef)
Definition: gradient.h:2566
doublereal random1()
Definition: gradienttest.cc:86
static const char * dof[]
Definition: drvdisp.cc:195
void funcDeriv(index_type N, doublereal u, const doublereal ud[], doublereal v, const doublereal vd[], doublereal w, const doublereal wd[], doublereal e, doublereal &f, doublereal fd[])
void SetValuePreserve(scalar_func_type dVal)
Definition: gradient.h:2511
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: gradienttest.cc:91
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
void DerivativeResizeReset(LocalDofMap *pMap, index_type iStartGlobal, index_type iEndGlobal, MapVectorBase::GlobalScope s, scalar_deriv_type dVal)
Definition: gradient.h:2538
scalar_func_type dGetValue() const
Definition: gradient.h:2502
double doublereal
Definition: colamd.c:52
int NLoops
Definition: gradienttest.cc:79

Here is the call graph for this function:

template<index_type N_SIZE>
void testGradient2 ( )

Definition at line 519 of file gradienttest.cc.

References grad::Alias(), bCompare(), grad::Gradient< N_SIZE >::DerivativeResizeReset(), grad::Gradient< N_SIZE >::dGetDerivativeGlobal(), grad::Gradient< N_SIZE >::dGetValue(), dof, grad::fabs(), func(), funcDeriv(), grad::MapVectorBase::GLOBAL, GRADIENT_ASSERT, NLoops, random1(), grad::Gradient< N_SIZE >::SetValuePreserve(), grad::sqrt(), and tic().

519  {
520  assert(N_SIZE == 0 || N_SIZE == 3);
521 
522  const doublereal dTol = sqrt(std::numeric_limits<doublereal>::epsilon());
523 
524  srand(0);
525 
527  Gradient<N_SIZE> u, v, w, f;
528 
529  u.SetValuePreserve(fabs(random1()) * 10);
530  v.SetValuePreserve(fabs(random1()) * 3);
531  w.SetValuePreserve(fabs(random1()) * 0.01);
532 
533  u.DerivativeResizeReset(&dof, 0, MapVectorBase::GLOBAL, random1() * 0.01);
534  v.DerivativeResizeReset(&dof, 1, MapVectorBase::GLOBAL, random1() * 3);
535  w.DerivativeResizeReset(&dof, 2, MapVectorBase::GLOBAL, random1() * 10);
536 
537  doublereal ud_C[3];
538  doublereal vd_C[3];
539  doublereal wd_C[3];
540  doublereal f_C;
541  doublereal fd_C[3];
542 
543  for (index_type i = 0; i < 3; ++i) {
544  ud_C[i] = u.dGetDerivativeGlobal(i);
545  vd_C[i] = v.dGetDerivativeGlobal(i);
546  wd_C[i] = w.dGetDerivativeGlobal(i);
547  }
548 
549  doublereal t_AD = 0., t_C = 0.;
550 
551  for (int i = 0; i < NLoops; ++i) {
552  const doublereal e = random1();
553  doublereal start, stop;
554 
555  tic(start);
556  func(u, v, w, e, f);
557  tic(stop);
558 
559  t_AD += stop - start;
560 
561  tic(start);
562  funcDeriv(3,
563  u.dGetValue(),
564  ud_C,
565  v.dGetValue(),
566  vd_C,
567  w.dGetValue(),
568  wd_C,
569  e,
570  f_C,
571  fd_C);
572  tic(stop);
573 
574  t_C += stop - start;
575 
576  assert(bCompare(f.dGetValue(), f_C, dTol));
577  //assert(bCompare(Y[0], f_C, dTol));
578 
579  for (index_type j = 0; j < 3; ++j) {
580  assert(bCompare<scalar_deriv_type>(f.dGetDerivativeGlobal(j), fd_C[j], sqrt(std::numeric_limits<scalar_deriv_type>::epsilon())));
581  // assert(bCompare(jac[j], fd_C[j], dTol));
582  }
583  }
584 
585  std::cerr << "testGradient2<" << N_SIZE << ">(3)" << std::endl;
586 
587  std::cout << "dof map:" << std::endl << dof << std::endl;
588  std::cout << "u=" << u << std::endl;
589  std::cout << "v=" << v << std::endl;
590  std::cout << "w=" << w << std::endl;
591  std::cout << "f=" << f << std::endl;
592 
593  std::cout << "f_C=" << f_C << std::endl;
594  std::cout << "fd_C=" << std::endl;
595 
596  for (int i = 0; i < 3; ++i) {
597  std::cout << " " << fd_C[i] << std::endl;
598  }
599 
600  std::cout << std::endl;
601 
602  std::cerr << "t_AD=" << t_AD << "s" << std::endl;
603  std::cerr << "t_C=" << t_C << "s" << std::endl;
604  std::cerr << "overhead:" << t_AD / t_C << std::endl;
605 
606  Gradient<N_SIZE> w2 = 3 * u + 2 * v + 0.5 * w;
607 
608  w = 3 * u + 2 * v + 0.5 * Alias(w);
609 
610  GRADIENT_ASSERT(bCompare(w, w2));
611 
612  std::cout << "w=" << w << std::endl;
613  std::cout << "w2=" << w2 << std::endl;
614 }
scalar_deriv_type dGetDerivativeGlobal(index_type iGlobalDof) const
Definition: gradient.h:2532
integer index_type
Definition: gradient.h:104
GradientExpression< UnaryExpr< FuncFabs, Expr > > fabs(const GradientExpression< Expr > &u)
Definition: gradient.h:2973
void tic()
void func(const T &u, const T &v, const T &w, doublereal e, T &f)
doublereal random1()
Definition: gradienttest.cc:86
static const char * dof[]
Definition: drvdisp.cc:195
void funcDeriv(index_type N, doublereal u, const doublereal ud[], doublereal v, const doublereal vd[], doublereal w, const doublereal wd[], doublereal e, doublereal &f, doublereal fd[])
void SetValuePreserve(scalar_func_type dVal)
Definition: gradient.h:2511
bool bCompare(const T &a, const T &b, doublereal dTolRel=0.)
Definition: gradienttest.cc:91
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
void DerivativeResizeReset(LocalDofMap *pMap, index_type iStartGlobal, index_type iEndGlobal, MapVectorBase::GlobalScope s, scalar_deriv_type dVal)
Definition: gradient.h:2538
GradientExpression< DirectExpr< Gradient< N_SIZE >, true > > Alias(const Gradient< N_SIZE > &g)
Definition: gradient.h:2866
scalar_func_type dGetValue() const
Definition: gradient.h:2502
double doublereal
Definition: colamd.c:52
#define GRADIENT_ASSERT(expr)
Definition: gradient.h:74
int NLoops
Definition: gradienttest.cc:79

Here is the call graph for this function:

void testGradientCopy ( int  N)

Definition at line 646 of file gradienttest.cc.

References grad::MapVectorBase::GLOBAL, NLoops, tic(), and toc().

Referenced by main().

646  {
647  LocalDofMap map1, map2;
648  bool bFirst = true;
649 
650  std::cerr << "testGradientCopy(" << N << ")\n";
651 
652  tic();
653 
654  for (int i = 0; i < NLoops; ++i) {
655  MapVector<0> ud(&map1, 100, 102, MapVectorBase::GLOBAL, 1.);
656 
657  for (int i = 0; i < N; ++i) {
658  MapVector<0> dummy(&map1, 102 + i, MapVectorBase::GLOBAL, 1.5);
659  }
660 
661  MapVector<0> vd(&map1, 200, 203, MapVectorBase::GLOBAL, 2.);
662 
663  for (int i = 0; i < N; ++i) {
664  MapVector<0> dummy(&map1, 203 + i, MapVectorBase::GLOBAL, 2.5);
665  }
666 
667  MapVector<0> wd(&map1, 300, 302, MapVectorBase::GLOBAL, 3.);
668 
669  for (int i = 0; i < N; ++i) {
670  MapVector<0> dummy(&map1, 302 + i, MapVectorBase::GLOBAL, 3.5);
671  }
672 
673  Gradient<0> u(100., ud);
674  Gradient<0> v(200., vd);
675  Gradient<0> w(300., wd);
676 
677  assert(u != 100.001);
678  assert(u >= 100.);
679  assert(u <= 100.);
680  assert(u == 100.);
681  assert(u > 99.999);
682  assert(u < 100.001);
683  assert(100. == u);
684  assert(100.001 != u);
685  assert(100. <= u);
686  assert(100. >= u);
687  assert(99.999 < u);
688  assert(100.001 > u);
689 
690  assert(v != 200.001);
691  assert(v >= 200.);
692  assert(v <= 200.);
693  assert(v == 200.);
694  assert(v > 199.999);
695  assert(v < 200.001);
696  assert(200. == v);
697  assert(200.001 != v);
698  assert(200. <= v);
699  assert(200. >= v);
700  assert(199.999 < v);
701  assert(200.001 > v);
702 
703  Gradient<0> x = v + w;
704 
705  if (bFirst) {
706  std::cout << std::endl;
707  std::cout << "map1=" << std::endl << map1 << std::endl;
708  std::cout << "u=" << u << std::endl;
709  std::cout << "v=" << v << std::endl;
710  std::cout << "w=" << w << std::endl;
711  std::cout << "x=" << x << std::endl;
712  std::cout << std::endl;
713  }
714 
715  Gradient<5> y(x, &map2);
716 
717  if (bFirst) {
718  std::cout << "map2=" << std::endl << map2 << std::endl;
719  std::cout << "y=" << y << std::endl;
720  std::cout << std::endl;
721  }
722 
723  bFirst = false;
724  }
725 
726  std::cerr << "t=" << toc() << "s" << std::endl;
727 }
void tic()
doublereal toc()
int NLoops
Definition: gradienttest.cc:79

Here is the call graph for this function:

template<index_type N_SIZE>
void testGradientLin ( int  N)

Definition at line 793 of file gradienttest.cc.

References grad::Gradient< N_SIZE >::bIsEqual(), grad::Gradient< N_SIZE >::DerivativeResizeReset(), grad::Gradient< N_SIZE >::dGetDerivativeGlobal(), grad::Gradient< N_SIZE >::dGetValue(), grad::MapVectorBase::GLOBAL, and grad::Gradient< N_SIZE >::SetValuePreserve().

793  {
794  Gradient<N_SIZE> A11, A12, A13, A14;
795  Gradient<N_SIZE> x1, x2, x3, x4;
796  LocalDofMap oDof;
797 
798  A11.SetValuePreserve(1);
799  A12.SetValuePreserve(2);
800  A13.SetValuePreserve(3);
801  A14.SetValuePreserve(4);
802 
803  A11.DerivativeResizeReset(&oDof, 0, MapVectorBase::GLOBAL, 1);
804  A12.DerivativeResizeReset(&oDof, 1, MapVectorBase::GLOBAL, 1);
805  A13.DerivativeResizeReset(&oDof, 2, MapVectorBase::GLOBAL, 1);
806  A14.DerivativeResizeReset(&oDof, 3, MapVectorBase::GLOBAL, 1);
807 
808  std::cout << "A11=" << A11 << std::endl;
809  std::cout << "A12=" << A12 << std::endl;
810  std::cout << "A13=" << A13 << std::endl;
811  std::cout << "A14=" << A14 << std::endl;
812 
813  x1.SetValuePreserve(1);
814  x2.SetValuePreserve(1);
815  x3.SetValuePreserve(1);
816  x4.SetValuePreserve(1);
817 
818  x1.DerivativeResizeReset(&oDof, 0, MapVectorBase::GLOBAL, 1);
819  x2.DerivativeResizeReset(&oDof, 1, MapVectorBase::GLOBAL, 1);
820  x3.DerivativeResizeReset(&oDof, 2, MapVectorBase::GLOBAL, 1);
821  x4.DerivativeResizeReset(&oDof, 3, MapVectorBase::GLOBAL, 1);
822 
823  std::cout << "x1=" << x1 << std::endl;
824  std::cout << "x2=" << x2 << std::endl;
825  std::cout << "x3=" << x3 << std::endl;
826  std::cout << "x4=" << x4 << std::endl;
827 
828  Gradient<N_SIZE> y1 = A11 * x1;
829  Gradient<N_SIZE> y2 = A12 * x2;
830  Gradient<N_SIZE> y3 = A13 * x3;
831  Gradient<N_SIZE> y4 = A14 * x4;
832 
833  std::cout << "y1=" << y1 << std::endl;
834  std::cout << "y2=" << y2 << std::endl;
835  std::cout << "y3=" << y3 << std::endl;
836  std::cout << "y4=" << y4 << std::endl;
837 
838  Gradient<N_SIZE> y_2 = y1 + y2;
839  Gradient<N_SIZE> y_3 = y_2 + y3;
840  Gradient<N_SIZE> y_4 = y_3 + y4;
841 
842  Gradient<N_SIZE> y_1 = y1 + y2 + y3 + y4;
843  Gradient<N_SIZE> y = A11 * x1 + A12 * x2 + A13 * x3 + A14 * x4;
844 
845  std::cout << "y=" << y << std::endl;
846  std::cout << "y_1=" << y_1 << std::endl;
847  std::cout << "y_2=" << y_2 << std::endl;
848  std::cout << "y_3=" << y_3 << std::endl;
849  std::cout << "y_4=" << y_4 << std::endl;
850 
851  assert(y.bIsEqual(y_1));
852  assert(y.bIsEqual(y_4));
853  assert(y.dGetValue() == 10);
854  assert(y.dGetDerivativeGlobal(0) == 2);
855  assert(y.dGetDerivativeGlobal(1) == 3);
856  assert(y.dGetDerivativeGlobal(2) == 4);
857  assert(y.dGetDerivativeGlobal(3) == 5);
858 }
scalar_deriv_type dGetDerivativeGlobal(index_type iGlobalDof) const
Definition: gradient.h:2532
bool bIsEqual(const Gradient &g) const
Definition: gradient.h:2604
void SetValuePreserve(scalar_func_type dVal)
Definition: gradient.h:2511
void DerivativeResizeReset(LocalDofMap *pMap, index_type iStartGlobal, index_type iEndGlobal, MapVectorBase::GlobalScope s, scalar_deriv_type dVal)
Definition: gradient.h:2538
scalar_func_type dGetValue() const
Definition: gradient.h:2502

Here is the call graph for this function:

template<int N_SIZE>
void testMapVector ( )

Definition at line 267 of file gradienttest.cc.

References grad::MapVector< N_SIZE >::dGetLocalVector(), dof, grad::MapVector< N_SIZE >::iGetEndIndexLocal(), grad::LocalDofMap::iGetGlobalDof(), grad::MapVector< N_SIZE >::iGetStartIndexLocal(), and grad::LocalDofMap::Size().

267  {
268  assert(N_SIZE == 0 || N_SIZE == 19);
270 
271  const int iCount = 4;
272 
273  MapVector<N_SIZE> v[iCount] = { MapVector<N_SIZE>(&dof, 501, 506+1, MapVector<N_SIZE>::GLOBAL, 1.),
276  MapVector<N_SIZE>(&dof, 801, 801+1, MapVector<N_SIZE>::GLOBAL, 4.) };
277 
278  MapVector<N_SIZE> v1(&dof, 0, 1+1, MapVector<N_SIZE>::LOCAL, 5.);
279  MapVector<N_SIZE> v2(&dof, 1, 2+1, MapVector<N_SIZE>::LOCAL, 6.);
280 
281  for (index_type j = 0; j < dof.Size(); ++j) {
282  for (int i = 0; i < iCount; ++i) {
283  if (j >= v[i].iGetStartIndexLocal() && j < v[i].iGetEndIndexLocal()) {
284  doublereal dVal = v[i].dGetLocalVector(j);
285 
286  std::cout << "v[" << i << "][" << j << "->" << dof.iGetGlobalDof(j) << "]=" << dVal << std::endl;
287  }
288  }
289  }
290 
291  for (index_type j = 0; j < dof.Size(); ++j) {
292  if (j >= v1.iGetStartIndexLocal() && j < v1.iGetEndIndexLocal()) {
293  doublereal dVal = v1.dGetLocalVector(j);
294 
295  std::cout << "v1[" << j << "->" << dof.iGetGlobalDof(j) << "]=" << dVal << std::endl;
296  }
297  }
298 
299  for (index_type j = 0; j < dof.Size(); ++j) {
300  if (j >= v2.iGetStartIndexLocal() && j < v2.iGetEndIndexLocal()) {
301  doublereal dVal = v2.dGetLocalVector(j);
302 
303  std::cout << "v2[" << j << "->" << dof.iGetGlobalDof(j) << "]=" << dVal << std::endl;
304  }
305  }
306 }
integer index_type
Definition: gradient.h:104
static const char * dof[]
Definition: drvdisp.cc:195
index_type iGetGlobalDof(index_type iLocalDof) const
Definition: gradient.h:1254
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<int N_SIZE>
void testRangeVector ( )

Definition at line 127 of file gradienttest.cc.

References grad::RangeVector< T, N_SIZE >::GetValue(), grad::RangeVector< T, N_SIZE >::GetVectorValue(), grad::RangeVector< T, N_SIZE >::iGetEndIndex(), grad::RangeVector< T, N_SIZE >::iGetEndIndexVector(), grad::RangeVector< T, N_SIZE >::iGetStartIndex(), grad::RangeVector< T, N_SIZE >::iGetStartIndexVector(), grad::RangeVector< T, N_SIZE >::Reserve(), grad::RangeVector< T, N_SIZE >::Reset(), grad::RangeVector< T, N_SIZE >::ResizePreserve(), grad::RangeVector< T, N_SIZE >::ResizeReset(), grad::RangeVector< T, N_SIZE >::SetValue(), and grad::RangeVector< T, N_SIZE >::SetVectorValue().

127  {
128  std::cout << "testRangeVector<" << N_SIZE << ">();\n";
129  assert(N_SIZE == 0 || N_SIZE >= 6);
130  index_type start = 3;
131  index_type end = 6;
132  RangeVector<doublereal, N_SIZE> v(start, end, 0.);
135 
136  int k = 0;
137 
138  for (index_type i = start; i < end; ++i) {
139  v.SetValue(i, ++k);
140  }
141 
142  v2 = v;
143  vf = v;
144  vf.Reset();
145  vf.Reserve(N_SIZE == 0 ? vf.iGetEndIndex() * 2 : 2 * N_SIZE);
146  vf = v2;
147  const RangeVector<float, N_SIZE> v3(v2);
148  v2.Reset();
149  v2 = v3;
150  v2.Reserve(N_SIZE == 0 ? v2.iGetEndIndex() * 2 : N_SIZE);
151 
152  std::cout << "v(" << v.iGetStartIndex() << ":" << v.iGetEndIndex() - 1 << ")\n";
153 
154  for (index_type i = v.iGetStartIndex(); i < v.iGetEndIndex(); ++i) {
155  std::cout << "v[" << i << "]=" << v.GetValue(i) << std::endl;
156  }
157 
158  for (index_type i = vf.iGetStartIndex(); i < vf.iGetEndIndex(); ++i) {
159  std::cout << "vf[" << i << "]=" << vf.GetValue(i) << std::endl;
160  }
161 
162  for (index_type i = v2.iGetStartIndex(); i < v2.iGetEndIndex(); ++i) {
163  std::cout << "v2[" << i << "]=" << v2.GetValue(i) << std::endl;
164  }
165 
166  for (index_type i = v3.iGetStartIndex(); i < v3.iGetEndIndex(); ++i) {
167  std::cout << "v3[" << i << "]=" << v3.GetValue(i) << std::endl;
168  }
169 
170  std::cout << std::endl;
171 
172  for (index_type i = 0; i < v.iGetEndIndex(); ++i)
173  {
174  assert(v.GetValue(i) == vf.GetValue(i));
175  assert(v2.GetValue(i) == v.GetValue(i));
176  }
177 
178  v2.ResizeReset(v.iGetStartIndex(), v.iGetEndIndex(), 0.);
179 
180  for (index_type i = v.iGetStartIndexVector(); i < v.iGetEndIndexVector(); ++i)
181  {
182  v2.SetVectorValue(i, v.GetVectorValue(i));
183  }
184 
185  for (index_type i = v.iGetStartIndex(); i < v.iGetEndIndex(); ++i)
186  {
187  assert(v2.GetValue(i) == v.GetValue(i));
188  }
189 
190  vf.ResizeReset(0, 12, 0.0f);
191 
192  for (index_type i = vf.iGetStartIndex(); i < vf.iGetEndIndex(); ++i)
193  {
194  vf.SetValue(i, float(i + 1));
195  }
196 
197  vf2.ResizeReset(vf.iGetStartIndex(), vf.iGetEndIndex(), 0.0f);
198 
199  for (index_type i = vf.iGetStartIndexVector(); i < vf.iGetEndIndexVector(); ++i)
200  {
201  vf2.SetVectorValue(i, vf.GetVectorValue(i));
202  }
203 
204  for (index_type i = vf.iGetStartIndex(); i < vf.iGetEndIndex(); ++i)
205  {
206  assert(vf.GetValue(i) == vf2.GetValue(i));
207  }
208 
209  for (index_type i = vf2.iGetStartIndex(); i < vf2.iGetEndIndex(); ++i) {
210  std::cout << "vf2[" << i << "]=" << vf2.GetValue(i) << std::endl;
211  }
212 
213  std::cout << std::endl;
214 
215  v.ResizePreserve(1, 6);
216 
217  std::cout << "v(" << v.iGetStartIndex() << ":" << v.iGetEndIndex() - 1 << ")\n";
218 
219  for (index_type i = v.iGetStartIndex(); i < v.iGetEndIndex(); ++i) {
220  std::cout << "v[" << i << "]=" << v.GetValue(i) << std::endl;
221  }
222 
223  std::cout << std::endl;
224 
225  v.ResizePreserve(1, 5);
226 
227  std::cout << "v(" << v.iGetStartIndex() << ":" << v.iGetEndIndex() - 1 << ")\n";
228 
229  for (index_type i = v.iGetStartIndex(); i < v.iGetEndIndex(); ++i) {
230  std::cout << "v[" << i << "]=" << v.GetValue(i) << std::endl;
231  }
232 
233  std::cout << std::endl;
234 
235  v.ResizePreserve(0, 6);
236 
237  std::cout << "v(" << v.iGetStartIndex() << ":" << v.iGetEndIndex() - 1 << ")\n";
238 
239  for (index_type i = v.iGetStartIndex(); i < v.iGetEndIndex(); ++i) {
240  std::cout << "v[" << i << "]=" << v.GetValue(i) << std::endl;
241  }
242 
243  std::cout << std::endl;
244 
245  v.ResizePreserve(4, 5);
246 
247  std::cout << "v(" << v.iGetStartIndex() << ":" << v.iGetEndIndex() - 1 << ")\n";
248 
249  for (index_type i = v.iGetStartIndex(); i < v.iGetEndIndex(); ++i) {
250  std::cout << "v[" << i << "]=" << v.GetValue(i) << std::endl;
251  }
252 
253  std::cout << std::endl;
254 
255  v.ResizePreserve(0, 6);
256 
257  std::cout << "v(" << v.iGetStartIndex() << ":" << v.iGetEndIndex() - 1 << ")\n";
258 
259  for (index_type i = v.iGetStartIndex(); i < v.iGetEndIndex(); ++i) {
260  std::cout << "v[" << i << "]=" << v.GetValue(i) << std::endl;
261  }
262 
263  std::cout << std::endl;
264 }
void SetVectorValue(index_type i, const vector_type &d)
Definition: gradient.h:529
integer index_type
Definition: gradient.h:104
void ResizeReset(index_type iStartNew, index_type iEndNew, const T &dVal)
Definition: gradient.h:451
index_type iGetStartIndex() const
Definition: gradient.h:493
scalar_type GetValue(index_type i) const
Definition: gradient.h:502
index_type iGetEndIndex() const
Definition: gradient.h:494

Here is the call graph for this function:

void tic ( )

Definition at line 866 of file gradienttest.cc.

References dStartTime, and mbdyn_clock_time().

Referenced by testGradient(), testGradient2(), and testGradientCopy().

866  {
868 }
double mbdyn_clock_time()
Definition: clock_time.cc:51
doublereal dStartTime

Here is the call graph for this function:

void tic ( doublereal dTime)

Definition at line 862 of file gradienttest.cc.

References mbdyn_clock_time().

862  {
863  dTime = mbdyn_clock_time();
864 }
double mbdyn_clock_time()
Definition: clock_time.cc:51

Here is the call graph for this function:

doublereal toc ( )

Definition at line 870 of file gradienttest.cc.

References dStartTime, and mbdyn_clock_time().

Referenced by testGradientCopy().

870  {
871  return mbdyn_clock_time() - dStartTime;
872 }
double mbdyn_clock_time()
Definition: clock_time.cc:51
doublereal dStartTime

Here is the call graph for this function:

Variable Documentation

doublereal dStartTime

Definition at line 860 of file gradienttest.cc.

Referenced by tic(), and toc().

int NLoops = 1

Definition at line 79 of file gradienttest.cc.

Referenced by main(), testGradient(), testGradient2(), and testGradientCopy().

int NLoopsAss = 1

Definition at line 80 of file gradienttest.cc.